Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r1396:2e0764ba0a2a
Date: 2013-11-09 09:17 +0100
http://bitbucket.org/cffi/cffi/changeset/2e0764ba0a2a/

Log:    Support "number + pointer" too, like in C

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2054,8 +2054,15 @@
     CDataObject *cd;
     CTypeDescrObject *ctptr;
 
-    if (!CData_Check(v))
-        goto not_implemented;
+    if (!CData_Check(v)) {
+        PyObject *swap;
+        assert(CData_Check(w));
+        if (sign != 1)
+            goto not_implemented;
+        swap = v;
+        v = w;
+        w = swap;
+    }
 
     i = PyNumber_AsSsize_t(w, PyExc_OverflowError);
     if (i == -1 && PyErr_Occurred())
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -553,6 +553,7 @@
     assert repr(a) == "<cdata 'int[3][5]' owning %d bytes>" % (
         3*5*size_of_int(),)
     assert repr(a + 0).startswith("<cdata 'int(*)[5]' 0x")
+    assert 0 + a == a + 0 != 1 + a == a + 1
     assert repr(a[0]).startswith("<cdata 'int[5]' 0x")
     assert repr((a + 0)[0]).startswith("<cdata 'int[5]' 0x")
     assert repr(a[0] + 0).startswith("<cdata 'int *' 0x")
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to