]> granicus.if.org Git - python/commitdiff
Capsule-related changes:
authorLarry Hastings <larry@hastings.org>
Fri, 2 Apr 2010 11:01:35 +0000 (11:01 +0000)
committerLarry Hastings <larry@hastings.org>
Fri, 2 Apr 2010 11:01:35 +0000 (11:01 +0000)
* 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.

Include/cobject.h
Misc/NEWS
Objects/cobject.c
PC/VC6/pythoncore.dsp
PC/os2emx/Makefile
PCbuild/pythoncore.vcproj

index e5e246b126d671b69267c88545f4893a532482ae..ad3cd9c98289b582af22c8d544aeb2be7f989135 100644 (file)
@@ -1,3 +1,29 @@
+/*
+   CObjects are marked Pending Deprecation as of Python 2.7.
+   The full schedule for 2.x is as follows:
+     - CObjects are marked Pending Deprecation in Python 2.7.
+     - CObjects will be marked Deprecated in Python 2.8
+       (if there is one).
+     - CObjects will be removed in Python 2.9 (if there is one).
+
+   Additionally, for the Python 3.x series:
+     - CObjects were marked Deprecated in Python 3.1.
+     - CObjects will be removed in Python 3.2.
+
+   You should switch all use of CObjects to capsules.  Capsules
+   have a safer and more consistent API.  For more information,
+   see Include/pycapsule.h, or read the "Capsules" topic in
+   the "Python/C API Reference Manual".
+
+   Python 2.7 no longer uses CObjects itself; all objects which
+   were formerly CObjects are now capsules.  Note that this change
+   does not by itself break binary compatibility with extensions
+   built for previous versions of Python--PyCObject_AsVoidPtr()
+   has been changed to also understand capsules.
+
+*/
+
+/* original file header comment follows: */
 
 /* C objects to be exported from one extension module to another.
  
@@ -6,8 +32,6 @@
    to other extension modules, so that extension modules can use the
    Python import mechanism to link to one another.
 
-   DEPRECATED - Use PyCapsule objects instead.
-                CObject will be removed in 2.8 (if there is one).
 */
 
 #ifndef Py_COBJECT_H
index 8f361090202beb0158cf7eed55163c7de4d49307..38c70836da9d149cf5709047e7289a79a891bdfb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -184,7 +184,9 @@ C-API
   is now removed (the macro was introduced in 1997!).
 
 - Issue #7992: A replacement PyCObject API, PyCapsule, has been backported
-  from Python 3.1.
+  from Python 3.1.  All existing Python CObjects in the main distribution
+  have been converted to capsules.  To address backwards-compatibility
+  concerns, PyCObject_AsVoidPtr() was changed to understand capsules.
 
 Tests
 -----
index c437491c27c26bc57aa60557b43abf0180bc8a84..72123f440a645440d93c6d9ae6c07bf892edb988 100644 (file)
@@ -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,
index 28ff8c889ad79872a8d69b7517a4639095d10e0f..937329839a58533b55930759e0a0b8fa16f6973c 100644 (file)
@@ -257,6 +257,10 @@ SOURCE=..\..\Objects\bytes_methods.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\Objects\capsule.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\Objects\cellobject.c\r
 # End Source File\r
 # Begin Source File\r
index 09ed1a71d2273aca5b6c05f364f0610a5cddbef5..bf2e4862d618ea5b09a22a11a77d026ac3d40e56 100644 (file)
@@ -384,6 +384,7 @@ SRC.OBJECT= $(addprefix $(TOP), \
                Objects/bytes_methods.c \
                Objects/cellobject.c \
                Objects/classobject.c \
+               Objects/capsule.c \
                Objects/cobject.c \
                Objects/codeobject.c \
                Objects/complexobject.c \
index ac3dc267e022db3881a6db446af9ca30dd2e05aa..02ed0b13361ef0e3fe9cf1972ad23c620251cf95 100644 (file)
                                RelativePath="..\Include\pyarena.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\Include\pycapsule.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\Include\pyctype.h"
                                >
                                RelativePath="..\Objects\stringobject.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\Objects\capsule.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\Objects\cellobject.c"
                                >