summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-06-11 05:26:20 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-06-11 05:26:20 (GMT)
commit1a21451b1d73b65af949193208372e86bf308411 (patch)
tree8e98d7be9e249b011ae9380479656e5284ec0234 /Include
parentcdf94635d7e364f9ce1905bafa5b540f4d16147c (diff)
downloadcpython-1a21451b1d73b65af949193208372e86bf308411.zip
cpython-1a21451b1d73b65af949193208372e86bf308411.tar.gz
cpython-1a21451b1d73b65af949193208372e86bf308411.tar.bz2
Implement PEP 3121: new module initialization and finalization API.
Diffstat (limited to 'Include')
-rw-r--r--Include/import.h6
-rw-r--r--Include/modsupport.h36
-rw-r--r--Include/moduleobject.h24
-rw-r--r--Include/pyport.h12
-rw-r--r--Include/pystate.h3
-rw-r--r--Include/warnings.h2
6 files changed, 43 insertions, 40 deletions
diff --git a/Include/import.h b/Include/import.h
index 05ad7f0..e950d4b 100644
--- a/Include/import.h
+++ b/Include/import.h
@@ -33,17 +33,17 @@ PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr *);
PyAPI_FUNC(void) _PyImport_ReInitLock(void);
PyAPI_FUNC(PyObject *)_PyImport_FindExtension(char *, char *);
-PyAPI_FUNC(PyObject *)_PyImport_FixupExtension(char *, char *);
+PyAPI_FUNC(int)_PyImport_FixupExtension(PyObject*, char *, char *);
struct _inittab {
char *name;
- void (*initfunc)(void);
+ PyObject* (*initfunc)(void);
};
PyAPI_DATA(PyTypeObject) PyNullImporter_Type;
PyAPI_DATA(struct _inittab *) PyImport_Inittab;
-PyAPI_FUNC(int) PyImport_AppendInittab(char *name, void (*initfunc)(void));
+PyAPI_FUNC(int) PyImport_AppendInittab(char *name, PyObject* (*initfunc)(void));
PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);
struct _frozen {
diff --git a/Include/modsupport.h b/Include/modsupport.h
index d4dddef..41f9225 100644
--- a/Include/modsupport.h
+++ b/Include/modsupport.h
@@ -89,42 +89,18 @@ PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char
9-Jan-1995 GvR Initial version (incompatible with older API)
*/
-#ifdef MS_WINDOWS
-/* Special defines for Windows versions used to live here. Things
- have changed, and the "Version" is now in a global string variable.
- Reason for this is that this for easier branding of a "custom DLL"
- without actually needing a recompile. */
-#endif /* MS_WINDOWS */
-
-#if SIZEOF_SIZE_T != SIZEOF_INT
-/* On a 64-bit system, rename the Py_InitModule4 so that 2.4
- modules cannot get loaded into a 2.5 interpreter */
-#define Py_InitModule4 Py_InitModule4_64
-#endif
-
#ifdef Py_TRACE_REFS
- /* When we are tracing reference counts, rename Py_InitModule4 so
+ /* When we are tracing reference counts, rename PyModule_New2 so
modules compiled with incompatible settings will generate a
link-time error. */
- #if SIZEOF_SIZE_T != SIZEOF_INT
- #undef Py_InitModule4
- #define Py_InitModule4 Py_InitModule4TraceRefs_64
- #else
- #define Py_InitModule4 Py_InitModule4TraceRefs
- #endif
+ #define PyModule_New2 PyModule_Create2TraceRefs
#endif
-PyAPI_FUNC(PyObject *) Py_InitModule4(const char *name, PyMethodDef *methods,
- const char *doc, PyObject *self,
- int apiver);
-
-#define Py_InitModule(name, methods) \
- Py_InitModule4(name, methods, (char *)NULL, (PyObject *)NULL, \
- PYTHON_API_VERSION)
+PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
+ int apiver);
-#define Py_InitModule3(name, methods, doc) \
- Py_InitModule4(name, methods, doc, (PyObject *)NULL, \
- PYTHON_API_VERSION)
+#define PyModule_Create(module) \
+ PyModule_Create2(module, PYTHON_API_VERSION)
PyAPI_DATA(char *) _Py_PackageContext;
diff --git a/Include/moduleobject.h b/Include/moduleobject.h
index d643ce2..42eac82 100644
--- a/Include/moduleobject.h
+++ b/Include/moduleobject.h
@@ -17,6 +17,30 @@ PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
PyAPI_FUNC(const char *) PyModule_GetName(PyObject *);
PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *);
PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
+PyAPI_FUNC(struct PyModuleDef*) PyModule_GetDef(PyObject*);
+PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
+
+typedef struct PyModuleDef_Base {
+ PyObject_HEAD
+ PyObject* (*m_init)(void);
+ Py_ssize_t m_index;
+ PyObject* m_copy;
+} PyModuleDef_Base;
+
+#define PyModuleDef_HEAD_INIT {PyObject_HEAD_INIT(NULL)}
+
+typedef struct PyModuleDef{
+ PyModuleDef_Base m_base;
+ const char* m_name;
+ const char* m_doc;
+ Py_ssize_t m_size;
+ PyMethodDef *m_methods;
+ inquiry m_reload;
+ traverseproc m_traverse;
+ inquiry m_clear;
+ freefunc m_free;
+}PyModuleDef;
+
#ifdef __cplusplus
}
diff --git a/Include/pyport.h b/Include/pyport.h
index 0095cc4..d6fcf56 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -511,9 +511,9 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
/* module init functions inside the core need no external linkage */
/* except for Cygwin to handle embedding */
# if defined(__CYGWIN__)
-# define PyMODINIT_FUNC __declspec(dllexport) void
+# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
# else /* __CYGWIN__ */
-# define PyMODINIT_FUNC void
+# define PyMODINIT_FUNC PyObject*
# endif /* __CYGWIN__ */
# else /* Py_BUILD_CORE */
/* Building an extension module, or an embedded situation */
@@ -526,9 +526,9 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
/* module init functions outside the core must be exported */
# if defined(__cplusplus)
-# define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
+# define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject*
# else /* __cplusplus */
-# define PyMODINIT_FUNC __declspec(dllexport) void
+# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
# endif /* __cplusplus */
# endif /* Py_BUILD_CORE */
# endif /* HAVE_DECLSPEC */
@@ -543,9 +543,9 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
#endif
#ifndef PyMODINIT_FUNC
# if defined(__cplusplus)
-# define PyMODINIT_FUNC extern "C" void
+# define PyMODINIT_FUNC extern "C" PyObject*
# else /* __cplusplus */
-# define PyMODINIT_FUNC void
+# define PyMODINIT_FUNC PyObject*
# endif /* __cplusplus */
#endif
diff --git a/Include/pystate.h b/Include/pystate.h
index 0681e65..8508da0 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -19,6 +19,7 @@ typedef struct _is {
struct _ts *tstate_head;
PyObject *modules;
+ PyObject *modules_by_index;
PyObject *sysdict;
PyObject *builtins;
PyObject *modules_reloading;
@@ -107,6 +108,8 @@ typedef struct _ts {
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
+PyAPI_FUNC(int) _PyState_AddModule(PyObject*, struct PyModuleDef*);
+PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
diff --git a/Include/warnings.h b/Include/warnings.h
index 5d13431..f54eabd 100644
--- a/Include/warnings.h
+++ b/Include/warnings.h
@@ -4,7 +4,7 @@
extern "C" {
#endif
-PyAPI_FUNC(void) _PyWarnings_Init(void);
+PyAPI_FUNC(PyObject*) _PyWarnings_Init(void);
PyAPI_FUNC(int) PyErr_WarnEx(PyObject *, const char *, Py_ssize_t);
PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *, const char *, int,