]> granicus.if.org Git - python/commitdiff
Don't repeat yourself
authorChristian Heimes <christian@cheimes.de>
Tue, 22 Jan 2008 15:25:18 +0000 (15:25 +0000)
committerChristian Heimes <christian@cheimes.de>
Tue, 22 Jan 2008 15:25:18 +0000 (15:25 +0000)
Added the macros PyModule_AddIntMacro and PyModule_AddStringMacro. They shorten PyModule_AddIntConstant(m, "AF_INET", AF_INET) to PyModule_AddIntMacro(m, AF_INET)

Doc/c-api/module.rst
Include/modsupport.h

index 064c36563043531c294f990eae35e11420a87262..4008d1a43c02c35053608e6da9979c3c63b38dfd 100644 (file)
@@ -18,7 +18,7 @@ There are only a few functions special to module objects.
    is exposed to Python programs as ``types.ModuleType``.
 
 
-.. cfunction:: int PyModule_Check(PyObject *p)
+.. cmacro:: int PyModule_Check(PyObject *p)
 
    Return true if *p* is a module object, or a subtype of a module object.
 
@@ -26,7 +26,7 @@ There are only a few functions special to module objects.
       Allowed subtypes to be accepted.
 
 
-.. cfunction:: int PyModule_CheckExact(PyObject *p)
+.. cmacro:: int PyModule_CheckExact(PyObject *p)
 
    Return true if *p* is a module object, but not a subtype of
    :cdata:`PyModule_Type`.
@@ -103,3 +103,19 @@ There are only a few functions special to module objects.
    null-terminated.  Return ``-1`` on error, ``0`` on success.
 
    .. versionadded:: 2.0
+
+.. cmacro:: int PyModule_AddIntMacro(PyObject *module, macro)
+
+   Add an int constant to *module*. The name and the value are taken from 
+   *macro*. For example ``PyModule_AddConstant(module, AF_INET)`` adds the int
+   constant *AF_INET* with the value of *AF_INET* to *module*.
+   Return ``-1`` on error, ``0`` on success.
+
+   .. versionadded:: 2.6
+
+.. cmacro:: int PyModule_AddStringMacro(PyObject *module, macro)
+
+   Add a string constant to *module*.
+
+  .. versionadded:: 2.6
+
index 761d960991729f22e1429a46a465a945891843d6..d4dddef0b5902b6890e8a59219d90a77af564e12 100644 (file)
@@ -40,7 +40,8 @@ PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);
 PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);
 PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
 PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
-
+#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
+#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
 
 #define PYTHON_API_VERSION 1013
 #define PYTHON_API_STRING "1013"