mirror of https://github.com/python/cpython
Fixed very nasty null-dereferencing bug in DisposeControl/destroy
object.
This commit is contained in:
parent
cc778ebd62
commit
cfb60ee1e8
|
@ -92,23 +92,10 @@ CtlObj_Convert(v, p_itself)
|
||||||
static void CtlObj_dealloc(self)
|
static void CtlObj_dealloc(self)
|
||||||
ControlObject *self;
|
ControlObject *self;
|
||||||
{
|
{
|
||||||
SetCRefCon(self->ob_itself, (long)0); /* Make it forget about us */
|
if (self->ob_itself) SetCRefCon(self->ob_itself, (long)0); /* Make it forget about us */
|
||||||
PyMem_DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *CtlObj_DisposeControl(_self, _args)
|
|
||||||
ControlObject *_self;
|
|
||||||
PyObject *_args;
|
|
||||||
{
|
|
||||||
PyObject *_res = NULL;
|
|
||||||
if (!PyArg_ParseTuple(_args, ""))
|
|
||||||
return NULL;
|
|
||||||
DisposeControl(_self->ob_itself);
|
|
||||||
Py_INCREF(Py_None);
|
|
||||||
_res = Py_None;
|
|
||||||
return _res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *CtlObj_ShowControl(_self, _args)
|
static PyObject *CtlObj_ShowControl(_self, _args)
|
||||||
ControlObject *_self;
|
ControlObject *_self;
|
||||||
PyObject *_args;
|
PyObject *_args;
|
||||||
|
@ -452,9 +439,26 @@ static PyObject *CtlObj_as_Resource(_self, _args)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *CtlObj_DisposeControl(_self, _args)
|
||||||
|
ControlObject *_self;
|
||||||
|
PyObject *_args;
|
||||||
|
{
|
||||||
|
PyObject *_res = NULL;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(_args, ""))
|
||||||
|
return NULL;
|
||||||
|
if ( _self->ob_itself ) {
|
||||||
|
SetCRefCon(_self->ob_itself, (long)0); /* Make it forget about us */
|
||||||
|
DisposeControl(_self->ob_itself);
|
||||||
|
_self->ob_itself = NULL;
|
||||||
|
}
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
_res = Py_None;
|
||||||
|
return _res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef CtlObj_methods[] = {
|
static PyMethodDef CtlObj_methods[] = {
|
||||||
{"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
|
|
||||||
"() -> None"},
|
|
||||||
{"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
|
{"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
|
||||||
"() -> None"},
|
"() -> None"},
|
||||||
{"HideControl", (PyCFunction)CtlObj_HideControl, 1,
|
{"HideControl", (PyCFunction)CtlObj_HideControl, 1,
|
||||||
|
@ -499,6 +503,8 @@ static PyMethodDef CtlObj_methods[] = {
|
||||||
"() -> (SInt32 _rv)"},
|
"() -> (SInt32 _rv)"},
|
||||||
{"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
|
{"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
|
||||||
"Return this Control as a Resource"},
|
"Return this Control as a Resource"},
|
||||||
|
{"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
|
||||||
|
"() -> None"},
|
||||||
{NULL, NULL, 0}
|
{NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -588,21 +594,6 @@ static PyObject *Ctl_GetNewControl(_self, _args)
|
||||||
return _res;
|
return _res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *Ctl_KillControls(_self, _args)
|
|
||||||
PyObject *_self;
|
|
||||||
PyObject *_args;
|
|
||||||
{
|
|
||||||
PyObject *_res = NULL;
|
|
||||||
WindowPtr theWindow;
|
|
||||||
if (!PyArg_ParseTuple(_args, "O&",
|
|
||||||
WinObj_Convert, &theWindow))
|
|
||||||
return NULL;
|
|
||||||
KillControls(theWindow);
|
|
||||||
Py_INCREF(Py_None);
|
|
||||||
_res = Py_None;
|
|
||||||
return _res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *Ctl_DrawControls(_self, _args)
|
static PyObject *Ctl_DrawControls(_self, _args)
|
||||||
PyObject *_self;
|
PyObject *_self;
|
||||||
PyObject *_args;
|
PyObject *_args;
|
||||||
|
@ -663,8 +654,6 @@ static PyMethodDef Ctl_methods[] = {
|
||||||
"(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, SInt16 value, SInt16 min, SInt16 max, SInt16 procID, SInt32 refCon) -> (ControlHandle _rv)"},
|
"(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, SInt16 value, SInt16 min, SInt16 max, SInt16 procID, SInt32 refCon) -> (ControlHandle _rv)"},
|
||||||
{"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
|
{"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
|
||||||
"(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
|
"(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
|
||||||
{"KillControls", (PyCFunction)Ctl_KillControls, 1,
|
|
||||||
"(WindowPtr theWindow) -> None"},
|
|
||||||
{"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
|
{"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
|
||||||
"(WindowPtr theWindow) -> None"},
|
"(WindowPtr theWindow) -> None"},
|
||||||
{"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
|
{"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
|
||||||
|
|
|
@ -6,3 +6,21 @@ f = ManualGenerator("as_Resource", as_resource_body)
|
||||||
f.docstring = lambda : "Return this Control as a Resource"
|
f.docstring = lambda : "Return this Control as a Resource"
|
||||||
|
|
||||||
methods.append(f)
|
methods.append(f)
|
||||||
|
|
||||||
|
DisposeControl_body = """
|
||||||
|
if (!PyArg_ParseTuple(_args, ""))
|
||||||
|
return NULL;
|
||||||
|
if ( _self->ob_itself ) {
|
||||||
|
SetCRefCon(_self->ob_itself, (long)0); /* Make it forget about us */
|
||||||
|
DisposeControl(_self->ob_itself);
|
||||||
|
_self->ob_itself = NULL;
|
||||||
|
}
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
_res = Py_None;
|
||||||
|
return _res;
|
||||||
|
"""
|
||||||
|
|
||||||
|
f = ManualGenerator("DisposeControl", DisposeControl_body)
|
||||||
|
f.docstring = lambda : "() -> None"
|
||||||
|
|
||||||
|
methods.append(f)
|
||||||
|
|
|
@ -30,7 +30,7 @@ class MyScanner(Scanner):
|
||||||
|
|
||||||
def makeblacklistnames(self):
|
def makeblacklistnames(self):
|
||||||
return [
|
return [
|
||||||
'DisposeControl' # Implied by deletion of control object
|
'DisposeControl', # Generated manually
|
||||||
'KillControls', # Implied by close of dialog
|
'KillControls', # Implied by close of dialog
|
||||||
'SetCtlAction',
|
'SetCtlAction',
|
||||||
]
|
]
|
||||||
|
|
|
@ -69,7 +69,7 @@ class MyObjectDefinition(GlobalObjectDefinition):
|
||||||
GlobalObjectDefinition.outputInitStructMembers(self)
|
GlobalObjectDefinition.outputInitStructMembers(self)
|
||||||
Output("SetCRefCon(itself, (long)it);")
|
Output("SetCRefCon(itself, (long)it);")
|
||||||
def outputCleanupStructMembers(self):
|
def outputCleanupStructMembers(self):
|
||||||
Output("SetCRefCon(self->ob_itself, (long)0); /* Make it forget about us */")
|
Output("if (self->ob_itself) SetCRefCon(self->ob_itself, (long)0); /* Make it forget about us */")
|
||||||
|
|
||||||
# Create the generator groups and link them
|
# Create the generator groups and link them
|
||||||
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
||||||
|
|
Loading…
Reference in New Issue