From 599ce9c6c2299b085011c426f0893d494cf9403d Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Tue, 20 Feb 2001 22:27:43 +0000 Subject: On OSX passing NULL to NewUniversalFilterProc() does not return NULL but a crashing UPP. This made ModalDialog (and, hence EditPythonPrefs and EasyDialogs and many others) crash. Fixed. --- Mac/Modules/dlg/Dlgmodule.c | 20 ++++++++++++-------- Mac/Modules/dlg/dlgsupport.py | 12 ++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Mac/Modules/dlg/Dlgmodule.c b/Mac/Modules/dlg/Dlgmodule.c index 070283e..2262b54 100644 --- a/Mac/Modules/dlg/Dlgmodule.c +++ b/Mac/Modules/dlg/Dlgmodule.c @@ -56,10 +56,12 @@ static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, return rv; } -static ModalFilterProcPtr +static ModalFilterUPP Dlg_PassFilterProc(PyObject *callback) { PyObject *tmp = Dlg_FilterProc_callback; + static ModalFilterUPP UnivFilterUpp = NULL; + Dlg_FilterProc_callback = NULL; if (callback == Py_None) { Py_XDECREF(tmp); @@ -68,7 +70,9 @@ Dlg_PassFilterProc(PyObject *callback) Py_INCREF(callback); Dlg_FilterProc_callback = callback; Py_XDECREF(tmp); - return &Dlg_UnivFilterProc; + if ( UnivFilterUpp == NULL ) + UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc); + return UnivFilterUpp; } static PyObject *Dlg_UserItemProc_callback = NULL; @@ -1077,7 +1081,7 @@ static PyObject *Dlg_ModalDialog(_self, _args) if (!PyArg_ParseTuple(_args, "O", &modalFilter)) return NULL; - ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)), + ModalDialog(Dlg_PassFilterProc(modalFilter), &itemHit); _res = Py_BuildValue("h", itemHit); @@ -1135,7 +1139,7 @@ static PyObject *Dlg_Alert(_self, _args) &modalFilter)) return NULL; _rv = Alert(alertID, - NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); + Dlg_PassFilterProc(modalFilter)); _res = Py_BuildValue("h", _rv); return _res; @@ -1154,7 +1158,7 @@ static PyObject *Dlg_StopAlert(_self, _args) &modalFilter)) return NULL; _rv = StopAlert(alertID, - NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); + Dlg_PassFilterProc(modalFilter)); _res = Py_BuildValue("h", _rv); return _res; @@ -1173,7 +1177,7 @@ static PyObject *Dlg_NoteAlert(_self, _args) &modalFilter)) return NULL; _rv = NoteAlert(alertID, - NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); + Dlg_PassFilterProc(modalFilter)); _res = Py_BuildValue("h", _rv); return _res; @@ -1192,7 +1196,7 @@ static PyObject *Dlg_CautionAlert(_self, _args) &modalFilter)) return NULL; _rv = CautionAlert(alertID, - NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); + Dlg_PassFilterProc(modalFilter)); _res = Py_BuildValue("h", _rv); return _res; @@ -1400,7 +1404,7 @@ static PyObject *Dlg_SetUserItemHandler(_self, _args) return NULL; } - if (new == Py_None) { + if (new == NULL || new == Py_None) { new = NULL; _res = Py_None; Py_INCREF(Py_None); diff --git a/Mac/Modules/dlg/dlgsupport.py b/Mac/Modules/dlg/dlgsupport.py index ab22e18..594b7a8 100644 --- a/Mac/Modules/dlg/dlgsupport.py +++ b/Mac/Modules/dlg/dlgsupport.py @@ -15,7 +15,7 @@ DialogRef = DialogPtr OptHandle = OpaqueByValueType("Handle", "OptResObj") ModalFilterProcPtr = InputOnlyType("PyObject*", "O") -ModalFilterProcPtr.passInput = lambda name: "NewModalFilterProc(Dlg_PassFilterProc(%s))" % name +ModalFilterProcPtr.passInput = lambda name: "Dlg_PassFilterProc(%s)" % name ModalFilterUPP = ModalFilterProcPtr RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") @@ -79,10 +79,12 @@ static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, return rv; } -static ModalFilterProcPtr +static ModalFilterUPP Dlg_PassFilterProc(PyObject *callback) { PyObject *tmp = Dlg_FilterProc_callback; + static ModalFilterUPP UnivFilterUpp = NULL; + Dlg_FilterProc_callback = NULL; if (callback == Py_None) { Py_XDECREF(tmp); @@ -91,7 +93,9 @@ Dlg_PassFilterProc(PyObject *callback) Py_INCREF(callback); Dlg_FilterProc_callback = callback; Py_XDECREF(tmp); - return &Dlg_UnivFilterProc; + if ( UnivFilterUpp == NULL ) + UnivFilterUpp = NewModalFilterUPP(&Dlg_UnivFilterProc); + return UnivFilterUpp; } static PyObject *Dlg_UserItemProc_callback = NULL; @@ -267,7 +271,7 @@ setuseritembody = """ return NULL; } - if (new == Py_None) { + if (new == NULL || new == Py_None) { new = NULL; _res = Py_None; Py_INCREF(Py_None); -- cgit v0.12