summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-05 22:31:58 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-05 22:31:58 (GMT)
commitb173f7853e4e3a4215a661d98174291e379cf6fb (patch)
tree02735987f20fc27277a82c14c5da5e043cc134aa /Include
parentc679fd8efcae2b5d1117fc09380d74f0000086b0 (diff)
downloadcpython-b173f7853e4e3a4215a661d98174291e379cf6fb.zip
cpython-b173f7853e4e3a4215a661d98174291e379cf6fb.tar.gz
cpython-b173f7853e4e3a4215a661d98174291e379cf6fb.tar.bz2
add a replacement API for PyCObject, PyCapsule #5630
All stdlib modules with C-APIs now use this. Patch by Larry Hastings
Diffstat (limited to 'Include')
-rw-r--r--Include/Python.h1
-rw-r--r--Include/cobject.h8
-rw-r--r--Include/datetime.h13
-rw-r--r--Include/py_curses.h15
-rw-r--r--Include/pycapsule.h57
-rw-r--r--Include/pyexpat.h1
-rw-r--r--Include/ucnhash.h4
7 files changed, 72 insertions, 27 deletions
diff --git a/Include/Python.h b/Include/Python.h
index 54058a5..969ef0f 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -89,6 +89,7 @@
#include "classobject.h"
#include "fileobject.h"
#include "cobject.h"
+#include "pycapsule.h"
#include "traceback.h"
#include "sliceobject.h"
#include "cellobject.h"
diff --git a/Include/cobject.h b/Include/cobject.h
index 4e24d7d..9efe4ce 100644
--- a/Include/cobject.h
+++ b/Include/cobject.h
@@ -1,10 +1,8 @@
-/* C objects to be exported from one extension module to another.
+/*
- C objects are used for communication between extension modules.
- They provide a way for an extension module to export a C interface
- to other extension modules, so that extension modules can use the
- Python import mechanism to link to one another.
+The CObject module is now *deprecated* as of Python 3.1.
+Please use the Capsule API instead; see "pycapsule.h".
*/
diff --git a/Include/datetime.h b/Include/datetime.h
index 0d310b4..4b506b2 100644
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -158,9 +158,8 @@ typedef struct {
} PyDateTime_CAPI;
+#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
-/* "magic" constant used to partially protect against developer mistakes. */
-#define DATETIME_API_MAGIC 0x414548d5
#ifdef Py_BUILD_CORE
@@ -186,15 +185,7 @@ typedef struct {
static PyDateTime_CAPI *PyDateTimeAPI;
#define PyDateTime_IMPORT \
- PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime", \
- "datetime_CAPI")
-
-/* This macro would be used if PyCObject_ImportEx() was created.
-#define PyDateTime_IMPORT \
- PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_ImportEx("datetime", \
- "datetime_CAPI", \
- DATETIME_API_MAGIC)
-*/
+ PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
/* Macros for type checking when not building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
diff --git a/Include/py_curses.h b/Include/py_curses.h
index b4ad8f7..ae7b12b 100644
--- a/Include/py_curses.h
+++ b/Include/py_curses.h
@@ -75,6 +75,9 @@ typedef struct {
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
+#define PyCurses_CAPSULE_NAME "_curses._C_API"
+
+
#ifdef CURSES_MODULE
/* This section is used when compiling _cursesmodule.c */
@@ -89,16 +92,8 @@ static void **PyCurses_API;
#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
#define import_curses() \
-{ \
- PyObject *module = PyImport_ImportModuleNoBlock("_curses"); \
- if (module != NULL) { \
- PyObject *module_dict = PyModule_GetDict(module); \
- PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
- if (PyCObject_Check(c_api_object)) { \
- PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
- } \
- } \
-}
+ PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
+
#endif
/* general error messages */
diff --git a/Include/pycapsule.h b/Include/pycapsule.h
new file mode 100644
index 0000000..17a509e
--- /dev/null
+++ b/Include/pycapsule.h
@@ -0,0 +1,57 @@
+
+/* Capsule objects let you wrap a C "void *" pointer in a Python
+ object. They're a way of passing data through the Python interpreter
+ without creating your own custom type.
+
+ Capsules are used for communication between extension modules.
+ They provide a way for an extension module to export a C interface
+ to other extension modules, so that extension modules can use the
+ Python import mechanism to link to one another.
+
+ For more information, please see "c-api/capsule.html" in the
+ documentation.
+*/
+
+#ifndef Py_CAPSULE_H
+#define Py_CAPSULE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_DATA(PyTypeObject) PyCapsule_Type;
+
+typedef void (*PyCapsule_Destructor)(PyObject *);
+
+#define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type)
+
+
+PyAPI_FUNC(PyObject *) PyCapsule_New(
+ void *pointer,
+ const char *name,
+ PyCapsule_Destructor destructor);
+
+PyAPI_FUNC(void *) PyCapsule_GetPointer(PyObject *capsule, const char *name);
+
+PyAPI_FUNC(PyCapsule_Destructor) PyCapsule_GetDestructor(PyObject *capsule);
+
+PyAPI_FUNC(const char *) PyCapsule_GetName(PyObject *capsule);
+
+PyAPI_FUNC(void *) PyCapsule_GetContext(PyObject *capsule);
+
+PyAPI_FUNC(int) PyCapsule_IsValid(PyObject *capsule, const char *name);
+
+PyAPI_FUNC(int) PyCapsule_SetPointer(PyObject *capsule, void *pointer);
+
+PyAPI_FUNC(int) PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor);
+
+PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name);
+
+PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context);
+
+PyAPI_FUNC(void *) PyCapsule_Import(const char *name, int no_block);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_CAPSULE_H */
diff --git a/Include/pyexpat.h b/Include/pyexpat.h
index 1e79f4e..5340ef5 100644
--- a/Include/pyexpat.h
+++ b/Include/pyexpat.h
@@ -4,6 +4,7 @@
/* note: you must import expat.h before importing this module! */
#define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.0"
+#define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI"
struct PyExpat_CAPI
{
diff --git a/Include/ucnhash.h b/Include/ucnhash.h
index 6231c98..69b7774 100644
--- a/Include/ucnhash.h
+++ b/Include/ucnhash.h
@@ -6,7 +6,9 @@
extern "C" {
#endif
-/* revised ucnhash CAPI interface (exported through a PyCObject) */
+/* revised ucnhash CAPI interface (exported through a "wrapper") */
+
+#define PyUnicodeData_CAPSULE_NAME "unicodedata.ucnhash_CAPI"
typedef struct {