Commits

Armin Rigo committed 0ee2e05

Write down places that we would need to fix to add a debugging mode
to check for accesses-after-freeing-memory.

  • Participants
  • Parent commits 54b1cb9

Comments (0)

Files changed (1)

File c/_cffi_backend.c

 static PY_LONG_LONG
 read_raw_signed_data(char *target, int size)
 {
+    /*READ(target, size)*/
     if (size == sizeof(signed char))
         return *((signed char*)target);
     else if (size == sizeof(short))
 static unsigned PY_LONG_LONG
 read_raw_unsigned_data(char *target, int size)
 {
+    /*READ(target, size)*/
     if (size == sizeof(unsigned char))
         return *((unsigned char*)target);
     else if (size == sizeof(unsigned short))
 static void
 write_raw_integer_data(char *target, unsigned PY_LONG_LONG source, int size)
 {
+    /*WRITE(target, size)*/
     if (size == sizeof(unsigned char))
         *((unsigned char*)target) = (unsigned char)source;
     else if (size == sizeof(unsigned short))
 static double
 read_raw_float_data(char *target, int size)
 {
+    /*READ(target, size)*/
     if (size == sizeof(float))
         return *((float*)target);
     else if (size == sizeof(double))
 static long double
 read_raw_longdouble_data(char *target)
 {
+    /*READ(target, sizeof(long double))*/
     return *((long double*)target);
 }
 
 static void
 write_raw_float_data(char *target, double source, int size)
 {
+    /*WRITE(target, size)*/
     if (size == sizeof(float))
         *((float*)target) = (float)source;
     else if (size == sizeof(double))
 static void
 write_raw_longdouble_data(char *target, long double source)
 {
+    /*WRITE(target, sizeof(long double))*/
     *((long double*)target) = source;
 }
 
         /* non-primitive types (check done just for performance) */
         if (ct->ct_flags & (CT_POINTER|CT_FUNCTIONPTR)) {
             char *ptrdata = *(char **)data;
+            /*READ(data, sizeof(char *))*/
             return new_simple_cdata(ptrdata, ct);
         }
         else if (ct->ct_flags & CT_IS_OPAQUE) {
         }
     }
     else if (ct->ct_flags & CT_PRIMITIVE_CHAR) {
-        if (ct->ct_size == sizeof(char))
+        if (ct->ct_size == sizeof(char)) {
+            /*READ(data, 1)*/
             return PyBytes_FromStringAndSize(data, 1);
+        }
 #ifdef HAVE_WCHAR_H
-        else
+        else {
+            /*READ(data, sizeof(wchar_t))*/
             return _my_PyUnicode_FromWideChar((wchar_t *)data, 1);
+        }
 #endif
     }
 
     if (CData_Check(init) &&
            (((CDataObject *)init)->c_type->ct_flags & CT_PRIMITIVE_CHAR) &&
            (((CDataObject *)init)->c_type->ct_size == sizeof(char))) {
-        return *(unsigned char *)((CDataObject *)init)->c_data;
+        char *data = ((CDataObject *)init)->c_data;
+        /*READ(data, 1)*/
+        return *(unsigned char *)data;
     }
     PyErr_Format(PyExc_TypeError,
                  "initializer for ctype 'char' must be a "STR_OR_BYTES
     if (CData_Check(init) &&
            (((CDataObject *)init)->c_type->ct_flags & CT_PRIMITIVE_CHAR) &&
            (((CDataObject *)init)->c_type->ct_size == sizeof(wchar_t))) {
-        return *(wchar_t *)((CDataObject *)init)->c_data;
+        char *data = ((CDataObject *)init)->c_data;
+        /*READ(data, sizeof(wchar_t))*/
+        return *(wchar_t *)data;
     }
     PyErr_Format(PyExc_TypeError,
                  "initializer for ctype 'wchar_t' must be a unicode string "
     const char *expected;
     char buf[sizeof(PY_LONG_LONG)];
 
+    /*if (ct->ct_size >= 0)*/
+        /*WRITE(data, ct->ct_size)*/
+
     if (ct->ct_flags & CT_ARRAY) {
         return convert_array_from_object(data, ct, init);
     }
         return convert_to_object(cd->c_data, cd->c_type);
     }
     else if (cd->c_type->ct_flags & CT_PRIMITIVE_CHAR) {
-        if (cd->c_type->ct_size == sizeof(char))
+        if (cd->c_type->ct_size == sizeof(char)) {
+            /*READ(cd->c_data, 1)*/
             return PyInt_FromLong((unsigned char)cd->c_data[0]);
+        }
 #ifdef HAVE_WCHAR_H
-        else
+        else {
+            /*READ(cd->c_data, sizeof(wchar_t))*/
             return PyInt_FromLong((long)*(wchar_t *)cd->c_data);
+        }
 #endif
     }
     else if (cd->c_type->ct_flags & CT_PRIMITIVE_FLOAT) {
     }
 
     resultdata = buffer + cif_descr->exchange_offset_arg[0];
+    /*READ(cd->c_data, sizeof(void(*)(void)))*/
 
     Py_BEGIN_ALLOW_THREADS
     restore_errno();
         }
         if (cd->c_type->ct_itemdescr->ct_size == sizeof(char)) {
             const char *start = cd->c_data;
+            /*READ(start, ?)*/
             if (length < 0)
                 length = strlen(start);
             else {
 #ifdef HAVE_WCHAR_H
         else if (cd->c_type->ct_itemdescr->ct_flags & CT_PRIMITIVE_CHAR) {
             const wchar_t *start = (wchar_t *)cd->c_data;
+            /*READ(start, ?)*/
             assert(cd->c_type->ct_itemdescr->ct_size == sizeof(wchar_t));
             if (length < 0) {
                 length = 0;
                                      CT_PRIMITIVE_SIGNED |
                                      CT_PRIMITIVE_UNSIGNED)) {
         if (cd->c_type->ct_size == sizeof(char)) {
+            /*READ(cd->c_data, 1)*/
             return PyBytes_FromStringAndSize(cd->c_data, 1);
         }
 #ifdef HAVE_WCHAR_H
         else if (cd->c_type->ct_flags & CT_PRIMITIVE_CHAR) {
             assert(cd->c_type->ct_size == sizeof(wchar_t));
+            /*READ(cd->c_data, sizeof(wchar_t))*/
             return _my_PyUnicode_FromWideChar((wchar_t *)cd->c_data, 1);
         }
 #endif
                      cd->c_type->ct_name);
         return NULL;
     }
+    /*WRITE(cd->c_data, size)*/
 #if PY_MAJOR_VERSION < 3
     return PyBuffer_FromReadWriteMemory(cd->c_data, size);
 #else