bpo-35059: Cast void* to PyObject* (GH-10650) · python/cpython@a42de74

4 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -1171,8 +1171,9 @@ This function is meant for internal and specialized purposes only.\n\

11711171

In most applications `threading.enumerate()` should be used instead.");

11721172
11731173

static void

1174-

release_sentinel(void *wr)

1174+

release_sentinel(void *wr_raw)

11751175

{

1176+

PyObject *wr = _PyObject_CAST(wr_raw);

11761177

/* Tricky: this function is called when the current thread state

11771178

is being deleted. Therefore, only simple C code can safely

11781179

execute here. */

Original file line numberDiff line numberDiff line change

@@ -1847,20 +1847,21 @@ _PyGC_Dump(PyGC_Head *g)

18471847

functions must always be available */

18481848
18491849

void

1850-

PyObject_GC_Track(void *op)

1850+

PyObject_GC_Track(void *op_raw)

18511851

{

1852-

PyObject *obj = (PyObject *)op;

1852+

PyObject *op = _PyObject_CAST(op_raw);

18531853

if (_PyObject_GC_IS_TRACKED(op)) {

18541854

_PyObject_ASSERT_FAILED_MSG(op,

18551855

"object already tracked "

18561856

"by the garbage collector");

18571857

}

1858-

_PyObject_GC_TRACK(obj);

1858+

_PyObject_GC_TRACK(op);

18591859

}

18601860
18611861

void

1862-

PyObject_GC_UnTrack(void *op)

1862+

PyObject_GC_UnTrack(void *op_raw)

18631863

{

1864+

PyObject *op = _PyObject_CAST(op_raw);

18641865

/* Obscure: the Py_TRASHCAN mechanism requires that we be able to

18651866

* call PyObject_GC_UnTrack twice on an object.

18661867

*/

Original file line numberDiff line numberDiff line change

@@ -1171,14 +1171,17 @@ unicode_kind_name(PyObject *unicode)

11711171
11721172

#ifdef Py_DEBUG

11731173

/* Functions wrapping macros for use in debugger */

1174-

char *_PyUnicode_utf8(void *unicode){

1174+

char *_PyUnicode_utf8(void *unicode_raw){

1175+

PyObject *unicode = _PyObject_CAST(unicode_raw);

11751176

return PyUnicode_UTF8(unicode);

11761177

}

11771178
1178-

void *_PyUnicode_compact_data(void *unicode) {

1179+

void *_PyUnicode_compact_data(void *unicode_raw) {

1180+

PyObject *unicode = _PyObject_CAST(unicode_raw);

11791181

return _PyUnicode_COMPACT_DATA(unicode);

11801182

}

1181-

void *_PyUnicode_data(void *unicode){

1183+

void *_PyUnicode_data(void *unicode_raw) {

1184+

PyObject *unicode = _PyObject_CAST(unicode_raw);

11821185

printf("obj %p\n", unicode);

11831186

printf("compact %d\n", PyUnicode_IS_COMPACT(unicode));

11841187

printf("compact ascii %d\n", PyUnicode_IS_COMPACT_ASCII(unicode));

Original file line numberDiff line numberDiff line change

@@ -373,10 +373,11 @@ hamt_node_collision_count(PyHamtNode_Collision *node);

373373
374374

#ifdef Py_DEBUG

375375

static void

376-

_hamt_node_array_validate(void *o)

376+

_hamt_node_array_validate(void *obj_raw)

377377

{

378-

assert(IS_ARRAY_NODE(o));

379-

PyHamtNode_Array *node = (PyHamtNode_Array*)(o);

378+

PyObject *obj = _PyObject_CAST(obj_raw);

379+

assert(IS_ARRAY_NODE(obj));

380+

PyHamtNode_Array *node = (PyHamtNode_Array*)obj;

380381

Py_ssize_t i = 0, count = 0;

381382

for (; i < HAMT_ARRAY_NODE_SIZE; i++) {

382383

if (node->a_array[i] != NULL) {