Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit175ed6e

Browse files
[3.11]gh-90763: Modernise xx template module initialisation (GH-93078) (#93681)
Use C APIs such as PyModule_AddType instead of PyModule_AddObject.Also remove incorrect module decrefs if module fails to initialise.(cherry picked from commita87c9b5)Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
1 parent927b5af commit175ed6e

File tree

2 files changed

+54
-43
lines changed

2 files changed

+54
-43
lines changed

‎Modules/xxlimited_35.c‎

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static PyType_Slot Xxo_Type_slots[] = {
124124
};
125125

126126
staticPyType_SpecXxo_Type_spec= {
127-
"xxlimited.Xxo",
127+
"xxlimited_35.Xxo",
128128
sizeof(XxoObject),
129129
0,
130130
Py_TPFLAGS_DEFAULT |Py_TPFLAGS_HAVE_GC,
@@ -189,7 +189,7 @@ static PyType_Slot Str_Type_slots[] = {
189189
};
190190

191191
staticPyType_SpecStr_Type_spec= {
192-
"xxlimited.Str",
192+
"xxlimited_35.Str",
193193
0,
194194
0,
195195
Py_TPFLAGS_DEFAULT |Py_TPFLAGS_BASETYPE,
@@ -212,7 +212,7 @@ static PyType_Slot Null_Type_slots[] = {
212212
};
213213

214214
staticPyType_SpecNull_Type_spec= {
215-
"xxlimited.Null",
215+
"xxlimited_35.Null",
216216
0,/* basicsize */
217217
0,/* itemsize */
218218
Py_TPFLAGS_DEFAULT |Py_TPFLAGS_BASETYPE,
@@ -248,40 +248,50 @@ xx_modexec(PyObject *m)
248248
Null_Type_slots[1].pfunc=PyType_GenericNew;
249249
Str_Type_slots[0].pfunc=&PyUnicode_Type;
250250

251-
Xxo_Type=PyType_FromSpec(&Xxo_Type_spec);
252-
if (Xxo_Type==NULL)
253-
gotofail;
254-
255251
/* Add some symbolic constants to the module */
256252
if (ErrorObject==NULL) {
257-
ErrorObject=PyErr_NewException("xxlimited.error",NULL,NULL);
258-
if (ErrorObject==NULL)
259-
gotofail;
253+
ErrorObject=PyErr_NewException("xxlimited_35.error",NULL,NULL);
254+
if (ErrorObject==NULL) {
255+
return-1;
256+
}
260257
}
261258
Py_INCREF(ErrorObject);
262-
PyModule_AddObject(m,"error",ErrorObject);
259+
if (PyModule_AddObject(m,"error",ErrorObject)<0) {
260+
Py_DECREF(ErrorObject);
261+
return-1;
262+
}
263263

264264
/* Add Xxo */
265-
o=PyType_FromSpec(&Xxo_Type_spec);
266-
if (o==NULL)
267-
gotofail;
268-
PyModule_AddObject(m,"Xxo",o);
265+
Xxo_Type=PyType_FromSpec(&Xxo_Type_spec);
266+
if (Xxo_Type==NULL) {
267+
return-1;
268+
}
269+
if (PyModule_AddObject(m,"Xxo",Xxo_Type)<0) {
270+
Py_DECREF(Xxo_Type);
271+
return-1;
272+
}
269273

270274
/* Add Str */
271275
o=PyType_FromSpec(&Str_Type_spec);
272-
if (o==NULL)
273-
gotofail;
274-
PyModule_AddObject(m,"Str",o);
276+
if (o==NULL) {
277+
return-1;
278+
}
279+
if (PyModule_AddObject(m,"Str",o)<0) {
280+
Py_DECREF(o);
281+
return-1;
282+
}
275283

276284
/* Add Null */
277285
o=PyType_FromSpec(&Null_Type_spec);
278-
if (o==NULL)
279-
gotofail;
280-
PyModule_AddObject(m,"Null",o);
286+
if (o==NULL) {
287+
return-1;
288+
}
289+
if (PyModule_AddObject(m,"Null",o)<0) {
290+
Py_DECREF(o);
291+
return-1;
292+
}
293+
281294
return0;
282-
fail:
283-
Py_XDECREF(m);
284-
return-1;
285295
}
286296

287297

‎Modules/xxmodule.c‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,31 +358,32 @@ xx_exec(PyObject *m)
358358

359359
/* Finalize the type object including setting type of the new type
360360
* object; doing it here is required for portability, too. */
361-
if (PyType_Ready(&Xxo_Type)<0)
362-
gotofail;
361+
if (PyType_Ready(&Xxo_Type)<0) {
362+
return-1;
363+
}
363364

364365
/* Add some symbolic constants to the module */
365366
if (ErrorObject==NULL) {
366367
ErrorObject=PyErr_NewException("xx.error",NULL,NULL);
367-
if (ErrorObject==NULL)
368-
gotofail;
368+
if (ErrorObject==NULL) {
369+
return-1;
370+
}
371+
}
372+
intrc=PyModule_AddType(m, (PyTypeObject*)ErrorObject);
373+
Py_DECREF(ErrorObject);
374+
if (rc<0) {
375+
return-1;
369376
}
370-
Py_INCREF(ErrorObject);
371-
PyModule_AddObject(m,"error",ErrorObject);
372-
373-
/* Add Str */
374-
if (PyType_Ready(&Str_Type)<0)
375-
gotofail;
376-
PyModule_AddObject(m,"Str", (PyObject*)&Str_Type);
377-
378-
/* Add Null */
379-
if (PyType_Ready(&Null_Type)<0)
380-
gotofail;
381-
PyModule_AddObject(m,"Null", (PyObject*)&Null_Type);
377+
378+
/* Add Str and Null types */
379+
if (PyModule_AddType(m,&Str_Type)<0) {
380+
return-1;
381+
}
382+
if (PyModule_AddType(m,&Null_Type)<0) {
383+
return-1;
384+
}
385+
382386
return0;
383-
fail:
384-
Py_XDECREF(m);
385-
return-1;
386387
}
387388

388389
staticstructPyModuleDef_Slotxx_slots[]= {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp