Author: thomas.heller
Date: Fri Jan 25 20:32:20 2008
New Revision: 60292

Modified:
   python/branches/py3k-ctypes-pep3118/Modules/_ctypes/stgdict.c
Log:
Only structures with native packing implement the pep.  Unions, or
packed structures do not.


Modified: python/branches/py3k-ctypes-pep3118/Modules/_ctypes/stgdict.c
==============================================================================
--- python/branches/py3k-ctypes-pep3118/Modules/_ctypes/stgdict.c       
(original)
+++ python/branches/py3k-ctypes-pep3118/Modules/_ctypes/stgdict.c       Fri Jan 
25 20:32:20 2008
@@ -408,11 +408,13 @@
                ffi_ofs = 0;
        }
 
-       if (isStruct) {
+       if (isStruct && !isPacked) {
                stgdict->format = alloc_format_string(NULL, "T{");
        } else {
-               /* PEP3118 doesn't support unions. Invent our own character... 
*/
-               stgdict->format = alloc_format_string(NULL, "#{");
+               /* PEP3118 doesn't support union, or packed structures (well,
+                  only standard packing, but we dont support the pep for
+                  that). Use 'B' for bytes. */
+               stgdict->format = alloc_format_string(NULL, "B");
        }
 
 #define realdict ((PyObject *)&stgdict->dict)
@@ -473,12 +475,13 @@
                        }
                } else
                        bitsize = 0;
-               {
+               if (isStruct && !isPacked) {
                        char *fieldfmt = dict->format ? dict->format : "XXX";
                        char *fieldname = PyUnicode_AsString(name);
                        char *ptr;
                        Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
                        char *buf = alloca(len + 2 + 1);
+
                        sprintf(buf, "%s:%s:", fieldfmt, fieldname);
 
                        ptr = stgdict->format;
@@ -521,9 +524,11 @@
        }
 #undef realdict
 
-       stgdict->format = alloc_format_string(stgdict->format, "}");
-       if (stgdict->format == NULL)
-               return -1;
+       if (isStruct && !isPacked) {
+               stgdict->format = alloc_format_string(stgdict->format, "}");
+               if (stgdict->format == NULL)
+                       return -1;
+       }
 
        if (!isStruct)
                size = union_size;
_______________________________________________
Python-3000-checkins mailing list
Python-3000-checkins@python.org
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to