A rare race condition on finalization of Python objects can lead to "object has no ilu_Server" messages. This patch removes the race condition.
*** 1.263 1998/10/26 23:41:04
--- runtime/python/iluPrmodule.c 1998/11/07 02:40:38
***************
*** 1643,1659 ****
ilu_Class kclass;
if ((iv = iv_New()) == 0)
! return 0;
if ((kclass = getKernelClass(inst->in_class)) == 0)
! return 0;
((IvObject *) iv)->kclass = kclass;
if (PyDict_SetItemString(inst->in_dict,
! nameVarInstVars, iv) < 0)
! {
! Py_DECREF(iv);
! return 0;
! }
! Py_DECREF(iv); /* let dictionary have only reference */
}
else if (!iv_Check(iv))
{
--- 1643,1660 ----
ilu_Class kclass;
if ((iv = iv_New()) == 0)
! return 0;
if ((kclass = getKernelClass(inst->in_class)) == 0)
! return 0;
((IvObject *) iv)->kclass = kclass;
+ ((IvObject *) iv)->pyobj = (void *) inst;
if (PyDict_SetItemString(inst->in_dict,
! nameVarInstVars, iv) < 0)
! {
! Py_DECREF(iv);
! return 0;
! }
! Py_DECREF(iv); /* let dictionary have only reference */
}
else if (!iv_Check(iv))
{
***************
*** 1793,1799 ****
PyInstanceObject *inst = (PyInstanceObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex); /* non-blocking */
ilu_Class cl = ilu_ClassOfObject(kobj); /* non-blocking */
! if (inst != ILU_NIL && ((!ilu_TrueInstanceP(kobj)) || ilu_CollectibleP(cl))) /* non-blocking */
{
/*
fprintf (stderr, "*** ILU kernel is %s in <%s> (0x%x, %s, %d)\n", vi ? "interested" : "not interested",
--- 1794,1800 ----
PyInstanceObject *inst = (PyInstanceObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex); /* non-blocking */
ilu_Class cl = ilu_ClassOfObject(kobj); /* non-blocking */
! if (inst != ILU_NIL && (Py_COUNT(inst) > 0) && ((!ilu_TrueInstanceP(kobj)) || ilu_CollectibleP(cl))) /* non-blocking */
{
/*
fprintf (stderr, "*** ILU kernel is %s in <%s> (0x%x, %s, %d)\n", vi ? "interested" : "not interested",
***************
*** 2035,2041 ****
ilu_Server kserver = ilu_ServerOfObject(kobj);
PyObject * pyobj;
! if ((pyobj = (PyObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex)) == 0)
{
if ((pyobj = createSurrogateInstance(kobj)) == 0) {
ilu_ExitServer(kserver, kclass);
--- 2036,2043 ----
ilu_Server kserver = ilu_ServerOfObject(kobj);
PyObject * pyobj;
! if (((pyobj = (PyObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex)) == 0) ||
! (Py_COUNT(pyobj) < 1))
{
if ((pyobj = createSurrogateInstance(kobj)) == 0) {
ilu_ExitServer(kserver, kclass);
***************
*** 2107,2115 ****
Py_INCREF(Py_None);
return Py_None;
} else {
! if ((pyobj = (PyObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex)) == 0) { /* non-blocking */
! pyobj = Py_None;
! };
Py_INCREF(pyobj);
if ((pyobj != Py_None) && (NewObjects != ILU_NIL)) {
removeObjFromList (NewObjects, pyobj);
--- 2109,2119 ----
Py_INCREF(Py_None);
return Py_None;
} else {
! if (((pyobj = (PyObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex)) == 0) /* non-blocking */
! || (Py_COUNT(pyobj) < 1))
! {
! pyobj = Py_None;
! };
Py_INCREF(pyobj);
if ((pyobj != Py_None) && (NewObjects != ILU_NIL)) {
removeObjFromList (NewObjects, pyobj);
***************
*** 2151,2159 ****
ILU_HANDLED(kerr);
return 0;
} else {
! if ((pyobj = (PyObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex)) == 0) {
if ((pyobj = createSurrogateInstance(kobj)) == 0)
! return 0;
CALL_KERNEL(ilupython_threaded_operation,
ilu_RegisterLSO(kobj, kclass, (void *) pyobj, _ilupython_LangIndex, &kerr));
/* DM 24.4.97: although the Python reference is stored here away,
--- 2155,2164 ----
ILU_HANDLED(kerr);
return 0;
} else {
! if (((pyobj = (PyObject *) ilu_GetLanguageSpecificObject(kobj, _ilupython_LangIndex)) == 0) ||
! (Py_COUNT(pyobj) < 1)) {
if ((pyobj = createSurrogateInstance(kobj)) == 0)
! return 0;
CALL_KERNEL(ilupython_threaded_operation,
ilu_RegisterLSO(kobj, kclass, (void *) pyobj, _ilupython_LangIndex, &kerr));
/* DM 24.4.97: although the Python reference is stored here away,
*** 1.7 1998/10/09 21:44:37
--- runtime/python/ivobject.h 1998/11/07 02:40:34
***************
*** 40,45 ****
--- 40,46 ----
ilu_Object kobj;
char * publish_proof;
long creatorPid;
+ void * pyobj;
} IvObject;
extern PyTypeObject Iv_Type;
*** 1.18 1998/10/26 23:41:23
--- runtime/python/ivobject.c 1998/11/07 02:40:33
***************
*** 79,85 ****
CALL_KERNEL(ilupython_threaded_operation, ilu_EnterServer(iv->kserver, iv->kclass));
if (iv->kobj != 0)
{
! CALL_KERNEL(ilupython_threaded_operation, ilu_RegisterLanguageSpecificObject(iv->kobj, NULL, _ilupython_LangIndex));
iv->kobj = 0;
}
ilu_ExitServer(iv->kserver, iv->kclass);
--- 79,91 ----
CALL_KERNEL(ilupython_threaded_operation, ilu_EnterServer(iv->kserver, iv->kclass));
if (iv->kobj != 0)
{
! /* another thread may have already created a new Python object to replace this one,
! and registered it with the kernel. We don't want to overwrite the new Python object
! with a NULL accidentally, so we check the pointers before calling ilu_RegisterLanguageSpecificObject */
!
! void *inst = ilu_GetLanguageSpecificObject(iv->kobj, _ilupython_LangIndex); /* non-blocking */
! if ((inst == iv->pyobj) && (iv->pyobj != NULL))
! CALL_KERNEL(ilupython_threaded_operation, ilu_RegisterLanguageSpecificObject(iv->kobj, NULL, _ilupython_LangIndex));
iv->kobj = 0;
}
ilu_ExitServer(iv->kserver, iv->kclass);
***************
*** 98,103 ****
--- 104,110 ----
v->kserver = 0;
v->kobj = 0;
v->publish_proof = 0;
+ v->pyobj = 0;
#if defined(WIN32)
v->creatorPid = _getpid();
#else
ilusb can segfault when called with improper arguments, due to bad command-line argument error checking. Thanks to Andreas Jung (ajung@sz-sb.de) for pointing this out.
*** 1.14 1998/10/08 21:57:53
--- etc/sbserver/sbservice.c 1998/11/12 16:25:00
***************
*** 61,72 ****
ilu_GetSBServiceParms(realm_name, hostname, &port);
while (i < ac) {
if (strcmp(av[i], "-r") == 0) {
! if (i++ < ac)
! strcpy(realm_name, av[i++]), i++;
else
usage(av[0]);
} else if (strcmp(av[i], "-p") == 0) {
! if (i++ < ac) {
(rawport = strtoul(av[i], ILU_NIL, 0)), i++;
if (rawport >= 0 && rawport <= 0xFFFF)
port = rawport;
--- 61,72 ----
ilu_GetSBServiceParms(realm_name, hostname, &port);
while (i < ac) {
if (strcmp(av[i], "-r") == 0) {
! if (++i < ac)
! strcpy(realm_name, av[i]), i++;
else
usage(av[0]);
} else if (strcmp(av[i], "-p") == 0) {
! if (++i < ac) {
(rawport = strtoul(av[i], ILU_NIL, 0)), i++;
if (rawport >= 0 && rawport <= 0xFFFF)
port = rawport;
***************
*** 76,82 ****
else
usage(av[0]);
} else if (strcmp(av[i], "-h") == 0) {
! if (i++ < ac)
strcpy (hostname, av[i]), i++;
else
usage(av[0]);
--- 76,82 ----
else
usage(av[0]);
} else if (strcmp(av[i], "-h") == 0) {
! if (++i < ac)
strcpy (hostname, av[i]), i++;
else
usage(av[0]);
***************
*** 84,90 ****
protected = ilu_TRUE;
i++;
} else if (strcmp(av[i], "-f") == 0) {
! if (i++ < ac)
filename = av[i++];
else
usage(av[0]);
--- 84,90 ----
protected = ilu_TRUE;
i++;
} else if (strcmp(av[i], "-f") == 0) {
! if (++i < ac)
filename = av[i++];
else
usage(av[0]);