mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Implement PEP 3121: new module initialization and finalization API.
This commit is contained in:
parent
cdf94635d7
commit
1a21451b1d
113 changed files with 2230 additions and 855 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
|
||||
int apiver);
|
||||
|
||||
#define Py_InitModule(name, methods) \
|
||||
Py_InitModule4(name, methods, (char *)NULL, (PyObject *)NULL, \
|
||||
PYTHON_API_VERSION)
|
||||
|
||||
#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;
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 *);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue