Skip to content

Commit d1ae6a6

Browse files
authored
Merge branch 'main' into warnings-as-error-2
2 parents 774dd98 + 04d4aac commit d1ae6a6

File tree

14 files changed

+200
-135
lines changed

14 files changed

+200
-135
lines changed

Doc/c-api/type.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,6 @@ The following functions and structs are used to create
311311
312312
Metaclasses that override :c:member:`~PyTypeObject.tp_new` are not
313313
supported, except if ``tp_new`` is ``NULL``.
314-
(For backwards compatibility, other ``PyType_From*`` functions allow
315-
such metaclasses. They ignore ``tp_new``, which may result in incomplete
316-
initialization. This is deprecated and in Python 3.14+ such metaclasses will
317-
not be supported.)
318314
319315
The *bases* argument can be used to specify base classes; it can either
320316
be only one class or a tuple of classes.

Modules/_ctypes/_ctypes.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,11 @@ typedef struct {
410410
#define _StructParamObject_CAST(op) ((StructParamObject *)(op))
411411

412412
static int
413-
StructParam_traverse(PyObject *self, visitproc visit, void *arg)
413+
StructParam_traverse(PyObject *myself, visitproc visit, void *arg)
414414
{
415+
StructParamObject *self = _StructParamObject_CAST(myself);
415416
Py_VISIT(Py_TYPE(self));
417+
Py_VISIT(self->keep);
416418
return 0;
417419
}
418420

@@ -2378,6 +2380,7 @@ PyCSimpleType_init(PyObject *self, PyObject *args, PyObject *kwds)
23782380
}
23792381
StgInfo *sw_info;
23802382
if (PyStgInfo_FromType(st, swapped, &sw_info) < 0) {
2383+
Py_DECREF(swapped);
23812384
return -1;
23822385
}
23832386
assert(sw_info);
@@ -2674,6 +2677,7 @@ make_funcptrtype_dict(ctypes_state *st, PyObject *attrdict, StgInfo *stginfo)
26742677
if (ob) {
26752678
StgInfo *info;
26762679
if (PyStgInfo_FromType(st, ob, &info) < 0) {
2680+
Py_DECREF(ob);
26772681
return -1;
26782682
}
26792683
if (ob != Py_None && !info && !PyCallable_Check(ob)) {
@@ -5650,6 +5654,10 @@ Pointer_subscript(PyObject *myself, PyObject *item)
56505654

56515655
for (cur = start, i = 0; i < len; cur += step, i++) {
56525656
PyObject *v = Pointer_item(myself, cur);
5657+
if (!v) {
5658+
Py_DECREF(np);
5659+
return NULL;
5660+
}
56535661
PyList_SET_ITEM(np, i, v);
56545662
}
56555663
return np;
@@ -6062,6 +6070,18 @@ _ctypes_add_objects(PyObject *mod)
60626070
static int
60636071
_ctypes_mod_exec(PyObject *mod)
60646072
{
6073+
// See https://github.com/python/cpython/issues/128485
6074+
// This allocates some memory and then frees it to ensure that the
6075+
// the dlmalloc allocator initializes itself to avoid data races
6076+
// in free-threading.
6077+
void *codeloc = NULL;
6078+
void *ptr = Py_ffi_closure_alloc(sizeof(void *), &codeloc);
6079+
if (ptr == NULL) {
6080+
PyErr_NoMemory();
6081+
return -1;
6082+
}
6083+
Py_ffi_closure_free(ptr);
6084+
60656085
ctypes_state *st = get_module_state(mod);
60666086
st->_unpickle = PyObject_GetAttrString(mod, "_unpickle");
60676087
if (st->_unpickle == NULL) {
@@ -6189,9 +6209,3 @@ PyInit__ctypes(void)
61896209
{
61906210
return PyModuleDef_Init(&_ctypesmodule);
61916211
}
6192-
6193-
/*
6194-
Local Variables:
6195-
compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~"
6196-
End:
6197-
*/

Modules/_ctypes/stgdict.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct
225225
// They're cleared on error.
226226
PyObject *layout_func = NULL;
227227
PyObject *kwnames = NULL;
228-
PyObject* align = NULL;
229-
PyObject* size = NULL;
228+
PyObject *align_obj = NULL;
229+
PyObject *size_obj = NULL;
230230
PyObject *layout_fields_obj = NULL;
231231
PyObject *layout_fields = NULL;
232232
PyObject *layout = NULL;
@@ -291,12 +291,12 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct
291291
goto error;
292292
}
293293

294-
align = PyObject_GetAttr(layout, &_Py_ID(align));
295-
if (!align) {
294+
align_obj = PyObject_GetAttr(layout, &_Py_ID(align));
295+
if (!align_obj) {
296296
goto error;
297297
}
298-
Py_ssize_t total_align = PyLong_AsSsize_t(align);
299-
Py_CLEAR(align);
298+
Py_ssize_t total_align = PyLong_AsSsize_t(align_obj);
299+
Py_CLEAR(align_obj);
300300
if (total_align < 0) {
301301
if (!PyErr_Occurred()) {
302302
PyErr_SetString(PyExc_ValueError,
@@ -305,12 +305,12 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct
305305
goto error;
306306
}
307307

308-
size = PyObject_GetAttr(layout, &_Py_ID(size));
309-
if (!size) {
308+
size_obj = PyObject_GetAttr(layout, &_Py_ID(size));
309+
if (!size_obj) {
310310
goto error;
311311
}
312-
Py_ssize_t total_size = PyLong_AsSsize_t(size);
313-
Py_CLEAR(size);
312+
Py_ssize_t total_size = PyLong_AsSsize_t(size_obj);
313+
Py_CLEAR(size_obj);
314314
if (total_size < 0) {
315315
if (!PyErr_Occurred()) {
316316
PyErr_SetString(PyExc_ValueError,
@@ -669,8 +669,8 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct
669669
error:
670670
Py_XDECREF(layout_func);
671671
Py_XDECREF(kwnames);
672-
Py_XDECREF(align);
673-
Py_XDECREF(size);
672+
Py_XDECREF(align_obj);
673+
Py_XDECREF(size_obj);
674674
Py_XDECREF(layout_fields_obj);
675675
Py_XDECREF(layout_fields);
676676
Py_XDECREF(layout);

Modules/_testbuffer.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,9 @@ ptr_from_index(Py_buffer *base, Py_ssize_t index)
15861586
}
15871587

15881588
static PyObject *
1589-
ndarray_item(NDArrayObject *self, Py_ssize_t index)
1589+
ndarray_item(PyObject *op, Py_ssize_t index)
15901590
{
1591+
NDArrayObject *self = (NDArrayObject *)op;
15911592
ndbuf_t *ndbuf = self->head;
15921593
Py_buffer *base = &ndbuf->base;
15931594
char *ptr;
@@ -1801,7 +1802,7 @@ ndarray_subscript(PyObject *op, PyObject *key)
18011802
Py_ssize_t index = PyLong_AsSsize_t(key);
18021803
if (index == -1 && PyErr_Occurred())
18031804
return NULL;
1804-
return ndarray_item(self, index);
1805+
return ndarray_item(op, index);
18051806
}
18061807

18071808
nd = (NDArrayObject *)ndarray_new(&NDArray_Type, NULL, NULL);
@@ -1966,10 +1967,10 @@ static PyMappingMethods ndarray_as_mapping = {
19661967
};
19671968

19681969
static PySequenceMethods ndarray_as_sequence = {
1969-
0, /* sq_length */
1970-
0, /* sq_concat */
1971-
0, /* sq_repeat */
1972-
(ssizeargfunc)ndarray_item, /* sq_item */
1970+
0, /* sq_length */
1971+
0, /* sq_concat */
1972+
0, /* sq_repeat */
1973+
ndarray_item, /* sq_item */
19731974
};
19741975

19751976

@@ -2742,16 +2743,17 @@ staticarray_init(PyObject *self, PyObject *args, PyObject *kwds)
27422743
}
27432744

27442745
static void
2745-
staticarray_dealloc(StaticArrayObject *self)
2746+
staticarray_dealloc(PyObject *self)
27462747
{
27472748
PyObject_Free(self);
27482749
}
27492750

27502751
/* Return a buffer for a PyBUF_FULL_RO request. Flags are not checked,
27512752
which makes this object a non-compliant exporter! */
27522753
static int
2753-
staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags)
2754+
staticarray_getbuf(PyObject *op, Py_buffer *view, int flags)
27542755
{
2756+
StaticArrayObject *self = (StaticArrayObject *)op;
27552757
*view = static_buffer;
27562758

27572759
if (self->legacy_mode) {
@@ -2765,7 +2767,7 @@ staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags)
27652767
}
27662768

27672769
static PyBufferProcs staticarray_as_buffer = {
2768-
(getbufferproc)staticarray_getbuf, /* bf_getbuffer */
2770+
staticarray_getbuf, /* bf_getbuffer */
27692771
NULL, /* bf_releasebuffer */
27702772
};
27712773

@@ -2774,7 +2776,7 @@ static PyTypeObject StaticArray_Type = {
27742776
"staticarray", /* Name of this type */
27752777
sizeof(StaticArrayObject), /* Basic object size */
27762778
0, /* Item size for varobject */
2777-
(destructor)staticarray_dealloc, /* tp_dealloc */
2779+
staticarray_dealloc, /* tp_dealloc */
27782780
0, /* tp_vectorcall_offset */
27792781
0, /* tp_getattr */
27802782
0, /* tp_setattr */

Modules/_testcapi/buffer.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ typedef struct {
1111
Py_ssize_t references;
1212
} testBufObject;
1313

14+
#define testBufObject_CAST(op) ((testBufObject *)(op))
15+
1416
static PyObject *
1517
testbuf_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1618
{
@@ -29,30 +31,34 @@ testbuf_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2931
}
3032

3133
static int
32-
testbuf_traverse(testBufObject *self, visitproc visit, void *arg)
34+
testbuf_traverse(PyObject *op, visitproc visit, void *arg)
3335
{
36+
testBufObject *self = testBufObject_CAST(op);
3437
Py_VISIT(self->obj);
3538
return 0;
3639
}
3740

3841
static int
39-
testbuf_clear(testBufObject *self)
42+
testbuf_clear(PyObject *op)
4043
{
44+
testBufObject *self = testBufObject_CAST(op);
4145
Py_CLEAR(self->obj);
4246
return 0;
4347
}
4448

4549
static void
46-
testbuf_dealloc(testBufObject *self)
50+
testbuf_dealloc(PyObject *op)
4751
{
52+
testBufObject *self = testBufObject_CAST(op);
4853
PyObject_GC_UnTrack(self);
4954
Py_XDECREF(self->obj);
50-
Py_TYPE(self)->tp_free((PyObject *) self);
55+
Py_TYPE(self)->tp_free(self);
5156
}
5257

5358
static int
54-
testbuf_getbuf(testBufObject *self, Py_buffer *view, int flags)
59+
testbuf_getbuf(PyObject *op, Py_buffer *view, int flags)
5560
{
61+
testBufObject *self = testBufObject_CAST(op);
5662
int buf = PyObject_GetBuffer(self->obj, view, flags);
5763
if (buf == 0) {
5864
Py_SETREF(view->obj, Py_NewRef(self));
@@ -62,15 +68,16 @@ testbuf_getbuf(testBufObject *self, Py_buffer *view, int flags)
6268
}
6369

6470
static void
65-
testbuf_releasebuf(testBufObject *self, Py_buffer *view)
71+
testbuf_releasebuf(PyObject *op, Py_buffer *Py_UNUSED(view))
6672
{
73+
testBufObject *self = testBufObject_CAST(op);
6774
self->references--;
6875
assert(self->references >= 0);
6976
}
7077

7178
static PyBufferProcs testbuf_as_buffer = {
72-
.bf_getbuffer = (getbufferproc) testbuf_getbuf,
73-
.bf_releasebuffer = (releasebufferproc) testbuf_releasebuf,
79+
.bf_getbuffer = testbuf_getbuf,
80+
.bf_releasebuffer = testbuf_releasebuf,
7481
};
7582

7683
static struct PyMemberDef testbuf_members[] = {
@@ -84,9 +91,9 @@ static PyTypeObject testBufType = {
8491
.tp_basicsize = sizeof(testBufObject),
8592
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
8693
.tp_new = testbuf_new,
87-
.tp_dealloc = (destructor) testbuf_dealloc,
88-
.tp_traverse = (traverseproc) testbuf_traverse,
89-
.tp_clear = (inquiry) testbuf_clear,
94+
.tp_dealloc = testbuf_dealloc,
95+
.tp_traverse = testbuf_traverse,
96+
.tp_clear = testbuf_clear,
9097
.tp_as_buffer = &testbuf_as_buffer,
9198
.tp_members = testbuf_members
9299
};

Modules/_testcapi/monitoring.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ typedef struct {
1414
/* Other fields */
1515
} PyCodeLikeObject;
1616

17+
#define PyCodeLikeObject_CAST(op) ((PyCodeLikeObject *)(op))
1718

1819
static PyObject *
1920
CodeLike_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
@@ -40,17 +41,19 @@ CodeLike_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4041
}
4142

4243
static void
43-
CodeLike_dealloc(PyCodeLikeObject *self)
44+
CodeLike_dealloc(PyObject *op)
4445
{
46+
PyCodeLikeObject *self = PyCodeLikeObject_CAST(op);
4547
if (self->monitoring_states) {
4648
PyMem_Free(self->monitoring_states);
4749
}
4850
Py_TYPE(self)->tp_free((PyObject *) self);
4951
}
5052

5153
static PyObject *
52-
CodeLike_str(PyCodeLikeObject *self)
54+
CodeLike_str(PyObject *op)
5355
{
56+
PyCodeLikeObject *self = PyCodeLikeObject_CAST(op);
5457
PyObject *res = NULL;
5558
PyObject *sep = NULL;
5659
PyObject *parts = NULL;
@@ -101,8 +104,8 @@ static PyTypeObject PyCodeLike_Type = {
101104
.tp_itemsize = 0,
102105
.tp_flags = Py_TPFLAGS_DEFAULT,
103106
.tp_new = CodeLike_new,
104-
.tp_dealloc = (destructor) CodeLike_dealloc,
105-
.tp_str = (reprfunc) CodeLike_str,
107+
.tp_dealloc = CodeLike_dealloc,
108+
.tp_str = CodeLike_str,
106109
};
107110

108111
#define RAISE_UNLESS_CODELIKE(v) if (!Py_IS_TYPE((v), &PyCodeLike_Type)) { \

0 commit comments

Comments
 (0)