[Python-checkins] r60199 - in python/trunk: Doc/c-api/module.rst Include/modsupport.h

christian.heimes python-checkins at python.org
Tue Jan 22 16:25:18 CET 2008


Author: christian.heimes
Date: Tue Jan 22 16:25:18 2008
New Revision: 60199

Modified:
   python/trunk/Doc/c-api/module.rst
   python/trunk/Include/modsupport.h
Log:
Don't repeat yourself
Added the macros PyModule_AddIntMacro and PyModule_AddStringMacro. They shorten PyModule_AddIntConstant(m, "AF_INET", AF_INET) to PyModule_AddIntMacro(m, AF_INET)

Modified: python/trunk/Doc/c-api/module.rst
==============================================================================
--- python/trunk/Doc/c-api/module.rst	(original)
+++ python/trunk/Doc/c-api/module.rst	Tue Jan 22 16:25:18 2008
@@ -18,7 +18,7 @@
    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 @@
       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 @@
    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
+

Modified: python/trunk/Include/modsupport.h
==============================================================================
--- python/trunk/Include/modsupport.h	(original)
+++ python/trunk/Include/modsupport.h	Tue Jan 22 16:25:18 2008
@@ -40,7 +40,8 @@
 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"


More information about the Python-checkins mailing list