]> granicus.if.org Git - python/commitdiff
bpo-35059: Cast void* to PyObject* (GH-10650)
authorVictor Stinner <vstinner@redhat.com>
Thu, 22 Nov 2018 09:25:22 +0000 (10:25 +0100)
committerGitHub <noreply@github.com>
Thu, 22 Nov 2018 09:25:22 +0000 (10:25 +0100)
Don't pass void* to Python macros: use _PyObject_CAST().

Modules/_threadmodule.c
Modules/gcmodule.c
Objects/unicodeobject.c
Python/hamt.c

index 72d044c08a10cae836d31d76b642d179d2c20ef2..a4ddb87e2b7f2597b0f7ca67d1badc715c8793af 100644 (file)
@@ -1171,8 +1171,9 @@ This function is meant for internal and specialized purposes only.\n\
 In most applications `threading.enumerate()` should be used instead.");
 
 static void
-release_sentinel(void *wr)
+release_sentinel(void *wr_raw)
 {
+    PyObject *wr = _PyObject_CAST(wr_raw);
     /* Tricky: this function is called when the current thread state
        is being deleted.  Therefore, only simple C code can safely
        execute here. */
index 506ae196d0d04894d03d5a687e108be10b700a63..64140c1b8899e241cb9f5827b4b6fc389a70bc5c 100644 (file)
@@ -1847,20 +1847,21 @@ _PyGC_Dump(PyGC_Head *g)
    functions must always be available */
 
 void
-PyObject_GC_Track(void *op)
+PyObject_GC_Track(void *op_raw)
 {
-    PyObject *obj = (PyObject *)op;
+    PyObject *op = _PyObject_CAST(op_raw);
     if (_PyObject_GC_IS_TRACKED(op)) {
         _PyObject_ASSERT_FAILED_MSG(op,
                                     "object already tracked "
                                     "by the garbage collector");
     }
-    _PyObject_GC_TRACK(obj);
+    _PyObject_GC_TRACK(op);
 }
 
 void
-PyObject_GC_UnTrack(void *op)
+PyObject_GC_UnTrack(void *op_raw)
 {
+    PyObject *op = _PyObject_CAST(op_raw);
     /* Obscure:  the Py_TRASHCAN mechanism requires that we be able to
      * call PyObject_GC_UnTrack twice on an object.
      */
index d22b277a51c8a77a9b37220b3b32329c13052562..01049f54e89826f0c8b17ea545e1c237708b32e4 100644 (file)
@@ -1171,14 +1171,17 @@ unicode_kind_name(PyObject *unicode)
 
 #ifdef Py_DEBUG
 /* Functions wrapping macros for use in debugger */
-char *_PyUnicode_utf8(void *unicode){
+char *_PyUnicode_utf8(void *unicode_raw){
+    PyObject *unicode = _PyObject_CAST(unicode_raw);
     return PyUnicode_UTF8(unicode);
 }
 
-void *_PyUnicode_compact_data(void *unicode) {
+void *_PyUnicode_compact_data(void *unicode_raw) {
+    PyObject *unicode = _PyObject_CAST(unicode_raw);
     return _PyUnicode_COMPACT_DATA(unicode);
 }
-void *_PyUnicode_data(void *unicode){
+void *_PyUnicode_data(void *unicode_raw) {
+    PyObject *unicode = _PyObject_CAST(unicode_raw);
     printf("obj %p\n", unicode);
     printf("compact %d\n", PyUnicode_IS_COMPACT(unicode));
     printf("compact ascii %d\n", PyUnicode_IS_COMPACT_ASCII(unicode));
index d734d6ed07fb27578cc09a5a07779eb6d8eedafc..aa90d37240a3e113aea9d08bbdf099966bf90708 100644 (file)
@@ -373,10 +373,11 @@ hamt_node_collision_count(PyHamtNode_Collision *node);
 
 #ifdef Py_DEBUG
 static void
-_hamt_node_array_validate(void *o)
+_hamt_node_array_validate(void *obj_raw)
 {
-    assert(IS_ARRAY_NODE(o));
-    PyHamtNode_Array *node = (PyHamtNode_Array*)(o);
+    PyObject *obj = _PyObject_CAST(obj_raw);
+    assert(IS_ARRAY_NODE(obj));
+    PyHamtNode_Array *node = (PyHamtNode_Array*)obj;
     Py_ssize_t i = 0, count = 0;
     for (; i < HAMT_ARRAY_NODE_SIZE; i++) {
         if (node->a_array[i] != NULL) {