diff options
author | Larry Hastings <larry@hastings.org> | 2010-04-02 11:01:35 +0000 |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2010-04-02 11:01:35 +0000 |
commit | 5ac006dfd3aacd50d43b8837ca71dff4288ce3df (patch) | |
tree | 5a7e5b7e34ec3801f9547266f891d4e5cbfecb4d /Objects/cobject.c | |
parent | f3eeca16cbadd7da5836ed781572343863b1a074 (diff) | |
download | cpython-git-5ac006dfd3aacd50d43b8837ca71dff4288ce3df.tar.gz |
Capsule-related changes:
* PyCObject_AsVoidPtr() can now open capsules. This addresses
most of the remaining backwards-compatibility concerns about
the conversion of Python 2.7 from CObjects to capsules.
* CObjects were marked Pending Deprecation.
* Documentation about this pending deprecation was added to
cobject.h.
* The capsule source files were added to the legacy PC build
processes.
Diffstat (limited to 'Objects/cobject.c')
-rw-r--r-- | Objects/cobject.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Objects/cobject.c b/Objects/cobject.c index c437491c27..72123f440a 100644 --- a/Objects/cobject.c +++ b/Objects/cobject.c @@ -9,11 +9,23 @@ typedef void (*destructor1)(void *); typedef void (*destructor2)(void *, void*); +static int cobject_deprecation_warning(void) +{ + return PyErr_WarnEx(PyExc_PendingDeprecationWarning, + "The CObject type is marked Pending Deprecation in Python 2.7. " + "Please use capsule objects instead.", 1); +} + + PyObject * PyCObject_FromVoidPtr(void *cobj, void (*destr)(void *)) { PyCObject *self; + if (cobject_deprecation_warning()) { + return NULL; + } + self = PyObject_NEW(PyCObject, &PyCObject_Type); if (self == NULL) return NULL; @@ -30,6 +42,10 @@ PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc, { PyCObject *self; + if (cobject_deprecation_warning()) { + return NULL; + } + if (!desc) { PyErr_SetString(PyExc_TypeError, "PyCObject_FromVoidPtrAndDesc called with null" @@ -50,6 +66,10 @@ void * PyCObject_AsVoidPtr(PyObject *self) { if (self) { + if (PyCapsule_CheckExact(self)) { + const char *name = PyCapsule_GetName(self); + return (void *)PyCapsule_GetPointer(self, name); + } if (self->ob_type == &PyCObject_Type) return ((PyCObject *)self)->cobject; PyErr_SetString(PyExc_TypeError, |