summaryrefslogtreecommitdiffstats
path: root/Objects/cobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/cobject.c')
-rw-r--r--Objects/cobject.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Objects/cobject.c b/Objects/cobject.c
index c437491..72123f4 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,