Skip to content

Commit a04e18c

Browse files
Anselm KruisAnselm Kruis
authored andcommitted
Stackless issue python#186: Make Stackless compatible with subinterpreters.
Make slp_register_execute() idempotent. It could be called more than once for the same type.
1 parent 6d32077 commit a04e18c

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Stackless/pickling/prickelpit.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ slp_register_execute(PyTypeObject *t, char *name, PyFrame_ExecFunc *good,
414414
{
415415
PyObject *g = NULL, *b = NULL, *nameobj = NULL;
416416
PyObject *tup = NULL, *dic = NULL;
417+
PyObject *o;
417418
proxyobject *dp = NULL;
418419
int ret = -1;
419420

@@ -446,20 +447,17 @@ slp_register_execute(PyTypeObject *t, char *name, PyFrame_ExecFunc *good,
446447
Py_INCREF(dp);
447448
}
448449
if (0
449-
|| PyDict_GetItem(dp->dict, nameobj) != NULL
450-
|| PyDict_GetItem(dp->dict, g) != NULL
451-
|| PyDict_GetItem(dp->dict, b) != NULL
450+
|| (o = PyDict_SetDefault(dp->dict, nameobj, tup)) == NULL
451+
|| !PyObject_RichCompareBool(o, tup, Py_EQ)
452+
|| (o = PyDict_SetDefault(dp->dict, g, nameobj)) == NULL
453+
|| !PyObject_RichCompareBool(o, nameobj, Py_EQ)
454+
|| (o = PyDict_SetDefault(dp->dict, b, nameobj)) == NULL
455+
|| !PyObject_RichCompareBool(o, nameobj, Py_EQ)
452456
) {
453-
PyErr_SetString(PyExc_SystemError,
454-
"duplicate/ambiguous exec func");
457+
if (! PyErr_Occurred())
458+
PyErr_SetString(PyExc_SystemError, "duplicate/ambiguous exec func");
455459
goto err_exit;
456460
}
457-
if (0
458-
|| PyDict_SetItem(dp->dict, nameobj, tup)
459-
|| PyDict_SetItem(dp->dict, g, nameobj)
460-
|| PyDict_SetItem(dp->dict, b, nameobj)
461-
)
462-
goto err_exit;
463461
PyErr_Clear();
464462
ret = 0;
465463
err_exit:

0 commit comments

Comments
 (0)