Armin Rigo avatar Armin Rigo committed 9dd27fd

Revert this case to a TypeError.

Comments (0)

Files changed (2)


             ct = ct->ct_itemdescr;
         if (!(ct->ct_flags & (CT_STRUCT|CT_UNION)))
             goto typeerror;
-        if (ct->ct_flags & CT_IS_OPAQUE)
-            cf = NULL;
-        else
-            cf = (CFieldObject *)PyDict_GetItem(ct->ct_stuff, fieldname);
+        if (ct->ct_stuff == NULL)
+            goto typeerror;
+        cf = (CFieldObject *)PyDict_GetItem(ct->ct_stuff, fieldname);
         if (cf == NULL) {
             PyErr_SetObject(PyExc_KeyError, fieldname);
             return NULL;
     return Py_BuildValue("(On)", res, offset);
-    PyErr_SetString(PyExc_TypeError, "expected a struct or union ctype");
+    PyErr_SetString(PyExc_TypeError,
+                    "expected an initialized struct or union ctype, "
+                    "or a pointer to it");
     return NULL;
     BInt = new_primitive_type("int")
     BStruct = new_struct_type("foo")
     py.test.raises(TypeError, offsetof, BInt, "abc")
-    py.test.raises(KeyError, offsetof, BStruct, "abc")
+    py.test.raises(TypeError, offsetof, BStruct, "abc")
     complete_struct_or_union(BStruct, [('abc', BInt, -1), ('def', BInt, -1)])
     assert offsetof(BStruct, 'abc') == 0
     assert offsetof(BStruct, 'def') == size_of_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.