[Python-checkins] python/dist/src/Mac/Modules/ae _AEmodule.c,1.18,1.19 aesupport.py,1.29,1.30
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Fri, 17 Jan 2003 15:11:22 -0800
Update of /cvsroot/python/python/dist/src/Mac/Modules/ae
In directory sc8-pr-cvs1:/tmp/cvs-serv2704/Mac/Modules/ae
Modified Files:
_AEmodule.c aesupport.py
Log Message:
It turns out that some calls return AEDesc records that are "borrowed",
the AEDesc data shouldn't be disposed when the Python object is.
Added a C call AEDesc_NewBorrowed() to create these objects and a Python
method old=AEDesc.AutoDispose(onoff) to change auto-dispose state.
Index: _AEmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/ae/_AEmodule.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** _AEmodule.c 23 Dec 2002 23:16:20 -0000 1.18
--- _AEmodule.c 17 Jan 2003 23:11:17 -0000 1.19
***************
*** 36,39 ****
--- 36,40 ----
#define AEDesc_New _AEDesc_New
+ #define AEDesc_NewBorrowed _AEDesc_NewBorrowed
#define AEDesc_Convert _AEDesc_Convert
#endif
***************
*** 71,74 ****
--- 72,76 ----
PyObject_HEAD
AEDesc ob_itself;
+ int ob_owned;
} AEDescObject;
***************
*** 79,82 ****
--- 81,85 ----
if (it == NULL) return NULL;
it->ob_itself = *itself;
+ it->ob_owned = 1;
return (PyObject *)it;
}
***************
*** 94,98 ****
static void AEDesc_dealloc(AEDescObject *self)
{
! AEDisposeDesc(&self->ob_itself);
self->ob_type->tp_free((PyObject *)self);
}
--- 97,101 ----
static void AEDesc_dealloc(AEDescObject *self)
{
! if (self->ob_owned) AEDisposeDesc(&self->ob_itself);
self->ob_type->tp_free((PyObject *)self);
}
***************
*** 760,763 ****
--- 763,780 ----
}
+ static PyObject *AEDesc_AutoDispose(AEDescObject *_self, PyObject *_args)
+ {
+ PyObject *_res = NULL;
+
+ int onoff, old;
+ if (!PyArg_ParseTuple(_args, "i", &onoff))
+ return NULL;
+ old = _self->ob_owned;
+ _self->ob_owned = onoff;
+ _res = Py_BuildValue("i", old);
+ return _res;
+
+ }
+
static PyMethodDef AEDesc_methods[] = {
{"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1,
***************
*** 817,820 ****
--- 834,839 ----
{"AEResolve", (PyCFunction)AEDesc_AEResolve, 1,
PyDoc_STR("(short callbackFlags) -> (AEDesc theToken)")},
+ {"AutoDispose", (PyCFunction)AEDesc_AutoDispose, 1,
+ PyDoc_STR("(int)->int. Automatically AEDisposeDesc the object on Python object cleanup")},
{NULL, NULL, 0}
};
***************
*** 1414,1417 ****
--- 1433,1447 ----
}
+ PyObject *AEDesc_NewBorrowed(AEDesc *itself)
+ {
+ PyObject *it;
+
+ it = AEDesc_New(itself);
+ if (it)
+ ((AEDescObject *)it)->ob_owned = 0;
+ return (PyObject *)it;
+ }
+
+
void init_AE(void)
***************
*** 1425,1428 ****
--- 1455,1459 ----
upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
Index: aesupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/ae/aesupport.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** aesupport.py 13 Dec 2002 15:01:32 -0000 1.29
--- aesupport.py 17 Jan 2003 23:11:17 -0000 1.30
***************
*** 98,101 ****
--- 98,102 ----
#define AEDesc_New _AEDesc_New
+ #define AEDesc_NewBorrowed _AEDesc_NewBorrowed
#define AEDesc_Convert _AEDesc_Convert
#endif
***************
*** 156,159 ****
--- 157,171 ----
return noErr;
}
+
+ PyObject *AEDesc_NewBorrowed(AEDesc *itself)
+ {
+ PyObject *it;
+
+ it = AEDesc_New(itself);
+ if (it)
+ ((AEDescObject *)it)->ob_owned = 0;
+ return (PyObject *)it;
+ }
+
"""
***************
*** 162,165 ****
--- 174,178 ----
upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
"""
***************
*** 198,203 ****
self.argref = "*"
! def outputFreeIt(self, name):
! Output("AEDisposeDesc(&%s);", name)
aedescobject = AEDescDefinition('AEDesc')
--- 211,224 ----
self.argref = "*"
! def outputStructMembers(self):
! GlobalObjectDefinition.outputStructMembers(self)
! Output("int ob_owned;")
!
! def outputInitStructMembers(self):
! GlobalObjectDefinition.outputInitStructMembers(self)
! Output("it->ob_owned = 1;")
!
! def outputCleanupStructMembers(self):
! Output("if (self->ob_owned) AEDisposeDesc(&self->ob_itself);")
aedescobject = AEDescDefinition('AEDesc')
***************
*** 209,212 ****
--- 230,247 ----
execfile('aegen.py')
##execfile('aedatamodelgen.py')
+
+ # Manual generator
+ AutoDispose_body = """
+ int onoff, old;
+ if (!PyArg_ParseTuple(_args, "i", &onoff))
+ return NULL;
+ old = _self->ob_owned;
+ _self->ob_owned = onoff;
+ _res = Py_BuildValue("i", old);
+ return _res;
+ """
+ f = ManualGenerator("AutoDispose", AutoDispose_body)
+ f.docstring = lambda: "(int)->int. Automatically AEDisposeDesc the object on Python object cleanup"
+ aedescmethods.append(f)
for f in functions: module.add(f)