Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r1762:3fbd5a5e1309
Date: 2015-04-18 17:33 +0200
http://bitbucket.org/cffi/cffi/changeset/3fbd5a5e1309/

Log:    ffi.cast()

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -3062,13 +3062,9 @@
     return cd;
 }
 
-static PyObject *b_cast(PyObject *self, PyObject *args)
-{
-    CTypeDescrObject *ct;
+static PyObject *do_cast(CTypeDescrObject *ct, PyObject *ob)
+{
     CDataObject *cd;
-    PyObject *ob;
-    if (!PyArg_ParseTuple(args, "O!O:cast", &CTypeDescr_Type, &ct, &ob))
-        return NULL;
 
     if (ct->ct_flags & (CT_POINTER|CT_FUNCTIONPTR|CT_ARRAY) &&
         ct->ct_size >= 0) {
@@ -3185,6 +3181,16 @@
     return NULL;
 }
 
+static PyObject *b_cast(PyObject *self, PyObject *args)
+{
+    CTypeDescrObject *ct;
+    PyObject *ob;
+    if (!PyArg_ParseTuple(args, "O!O:cast", &CTypeDescr_Type, &ct, &ob))
+        return NULL;
+
+    return do_cast(ct, ob);
+}
+
 /************************************************************/
 
 typedef struct {
diff --git a/new/ffi_obj.c b/new/ffi_obj.c
--- a/new/ffi_obj.c
+++ b/new/ffi_obj.c
@@ -244,8 +244,7 @@
     return direct_newp(ct, init);
 }
 
-#if 0
-static PyObject *ffi_cast(ZefFFIObject *self, PyObject *args)
+static PyObject *ffi_cast(FFIObject *self, PyObject *args)
 {
     CTypeDescrObject *ct;
     PyObject *ob, *arg;
@@ -258,7 +257,6 @@
 
     return do_cast(ct, ob);
 }
-#endif
 
 PyDoc_STRVAR(ffi_string_doc,
 "Return a Python string (or unicode string) from the 'cdata'.  If\n"
@@ -522,7 +520,9 @@
 static PyMethodDef ffi_methods[] = {
 #if 0
     {"addressof",     (PyCFunction)ffi_addressof, METH_VARARGS},
+#endif
     {"cast",          (PyCFunction)ffi_cast,      METH_VARARGS},
+#if 0
     {"close_library", ffi_close_library,          METH_VARARGS | METH_STATIC},
     {"from_handle",   (PyCFunction)ffi_from_handle,METH_O},
     {"gc",            (PyCFunction)ffi_gc,        METH_VARARGS},
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to