Armin Rigo committed fd33636

Tweak the repr of cdata objects in an attempt to reduce a bit confusion.

Comments (0)

Files changed (2)


 static PyObject *cdata_repr(CDataObject *cd)
-    char *p;
+    char *p, *extra;
     PyObject *result, *s = NULL;
     if (cd->c_type->ct_flags & CT_PRIMITIVE_ANY) {
             p = "NULL";
-    result = PyString_FromFormat("<cdata '%s' %s>", cd->c_type->ct_name, p);
+    /* it's slightly confusing to get "<cdata 'struct foo' 0x...>" because the
+       struct foo is not owned.  Trying to make it clearer, write in this
+       case "<cdata 'struct foo &' 0x...>". */
+    if (cd->c_type->ct_flags & (CT_STRUCT|CT_UNION))
+        extra = " &";
+    else
+        extra = "";
+    result = PyString_FromFormat("<cdata '%s%s' %s>",
+                                 cd->c_type->ct_name, extra, p);
     return result;
     assert repr(q) == "<cdata 'struct foo' owning 12 bytes>"
     q.a1 = 123456
     assert p.a1 == 123456
+    r = cast(BStructPtr, p)
+    assert repr(r[0]).startswith("<cdata 'struct foo &' 0x")
     del p
     import gc; gc.collect()
     assert q.a1 == 123456
     pp = newp(BStructPtrPtr)
     pp[0] = p
     s = pp[0][0]
-    assert repr(s).startswith("<cdata 'struct foo' 0x")
+    assert repr(s).startswith("<cdata 'struct foo &' 0x")
 def test_owning_repr():
     BInt = new_primitive_type("int")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.