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

Commita64d3a0

Browse files
Allow fixup_slot_dispatchers fails
1 parentb870751 commita64d3a0

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

‎Objects/typeobject.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,7 +3621,7 @@ static void object_dealloc(PyObject *);
36213621
staticPyObject*object_new(PyTypeObject*,PyObject*,PyObject*);
36223622
staticintobject_init(PyObject*,PyObject*,PyObject*);
36233623
staticintupdate_slot(PyTypeObject*,PyObject*);
3624-
staticvoidfixup_slot_dispatchers(PyTypeObject*);
3624+
staticintfixup_slot_dispatchers(PyTypeObject*);
36253625
staticinttype_new_set_names(PyTypeObject*);
36263626
staticinttype_new_init_subclass(PyTypeObject*,PyObject*);
36273627

@@ -4577,7 +4577,9 @@ type_new_impl(type_new_ctx *ctx)
45774577
}
45784578

45794579
// Put the proper slots in place
4580-
fixup_slot_dispatchers(type);
4580+
if (fixup_slot_dispatchers(type)<0) {
4581+
gotoerror;
4582+
}
45814583

45824584
if (!_PyDict_HasOnlyStringKeys(type->tp_dict)) {
45834585
if (PyErr_WarnFormat(
@@ -11329,10 +11331,12 @@ update_slot(PyTypeObject *type, PyObject *name)
1132911331

1133011332
/* Store the proper functions in the slot dispatches at class (type)
1133111333
definition time, based upon which operations the class overrides in its
11332-
dict. */
11333-
staticvoid
11334+
dict.Returns -1 and exception set on error or 0 otherwise.*/
11335+
staticint
1133411336
fixup_slot_dispatchers(PyTypeObject*type)
1133511337
{
11338+
intres=0;
11339+
1133611340
// This lock isn't strictly necessary because the type has not been
1133711341
// exposed to anyone else yet, but update_ont_slot calls find_name_in_mro
1133811342
// where we'd like to assert that the type is locked.
@@ -11341,10 +11345,11 @@ fixup_slot_dispatchers(PyTypeObject *type)
1134111345
PyObject*mro=lookup_tp_mro(type);
1134211346
assert(mro);
1134311347

11344-
// Try to prebuild MRO dict. If we fails then clear mro_dict and
11345-
// reset error flag because we don't expect any exceptions. If
11346-
// fails to prebuild MRO dict then update_on_slot will use
11347-
// previous version of find_name_in_mro.
11348+
// Try to prebuild MRO dict. We build it in bottom-top manner,
11349+
// from bottom base to the top one, because the bottommost base
11350+
// has more items then other and copying it is preferable than
11351+
// merging.
11352+
// If we fails, then stop init type.
1134811353
PyObject*mro_dict=NULL;
1134911354
Py_ssize_tn=PyTuple_GET_SIZE(mro);
1135011355
for (Py_ssize_ti=0;i<n;i++) {
@@ -11355,26 +11360,31 @@ fixup_slot_dispatchers(PyTypeObject *type)
1135511360
if (i==0) {
1135611361
mro_dict=PyDict_Copy(dict);
1135711362
if (!mro_dict) {
11358-
PyErr_Clear();
11359-
break;
11363+
res=-1;
11364+
gotofinish;
1136011365
}
1136111366
}else {
1136211367
if (PyDict_Merge(mro_dict,dict,1)<0) {
11363-
Py_CLEAR(mro_dict);
11364-
PyErr_Clear();
11365-
break;
11368+
res=-1;
11369+
gotofinish;
1136611370
}
1136711371
}
1136811372
}
1136911373

11374+
assert(!res);
11375+
assert(mro_dict);
1137011376
assert(!PyErr_Occurred());
1137111377
for (pytype_slotdef*p=slotdefs;p->name; ) {
1137211378
p=update_one_slot(type,p,mro_dict);
1137311379
}
1137411380

11381+
assert(!PyErr_Occurred());
11382+
11383+
finish:
1137511384
Py_XDECREF(mro_dict);
1137611385

1137711386
END_TYPE_LOCK();
11387+
returnres;
1137811388
}
1137911389

1138011390
staticvoid

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp