_CarbonAE.patch+__mBINs*** /Users/has/PythonDev/AEM_dev/CarbonAE/_AEmodule-old.c Fri Dec 24 23:54:00 2004 --- /Users/has/PythonDev/AEM_dev/CarbonAE/_AEmodule.c Tue Sep 7 11:58:55 2004 *************** *** 32,37 **** --- 32,45 ---- AEEventHandlerUPP upp_GenericEventHandler; + /* BEGIN NEW CODE */ + + static pascal OSErr GenericCoercionHandler(const AEDesc *fromDesc, DescType toType, refcontype refcon, AEDesc *toDesc); /* Forward */ + + AECoercionHandlerUPP upp_GenericCoercionHandler; + + /* END NEW CODE */ + static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) { if ( PyOS_InterruptOccurred() ) *************** *** 754,762 **** --- 762,800 ---- _self->ob_owned = onoff; _res = Py_BuildValue("i", old); return _res; + } + + /* BEGIN NEW CODE */ + + static PyObject *AEDesc_AEReplaceDescData(AEDescObject *_self, PyObject *_args) + { + PyObject *_res = NULL; + OSErr _err; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + int dataPtr__in_len__; + #ifndef AEReplaceDescData + PyMac_PRECHECK(AEReplaceDescData); + #endif + if (!PyArg_ParseTuple(_args, "O&s#", + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__in_len__)) + return NULL; + dataPtr__len__ = dataPtr__in_len__; + _err = AEReplaceDescData(typeCode, + dataPtr__in__, dataPtr__len__, + &_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_None; + return _res; } + /* END NEW CODE */ + + + static PyMethodDef AEDesc_methods[] = { {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1, PyDoc_STR("(DescType toType) -> (AEDesc result)")}, *************** *** 816,821 **** --- 854,868 ---- PyDoc_STR("(short callbackFlags) -> (AEDesc theToken)")}, {"AutoDispose", (PyCFunction)AEDesc_AutoDispose, 1, PyDoc_STR("(int)->int. Automatically AEDisposeDesc the object on Python object cleanup")}, + + /* BEGIN NEW CODE */ + + {"AEReplaceDescData", (PyCFunction)AEDesc_AEReplaceDescData, 1, + PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> None")}, + + /* END NEW CODE */ + + {NULL, NULL, 0} }; *************** *** 1038,1068 **** return _res; } ! static PyObject *AE_AEReplaceDescData(PyObject *_self, PyObject *_args) ! { ! PyObject *_res = NULL; ! OSErr _err; ! DescType typeCode; ! char *dataPtr__in__; ! long dataPtr__len__; ! int dataPtr__in_len__; ! AEDesc theAEDesc; ! #ifndef AEReplaceDescData ! PyMac_PRECHECK(AEReplaceDescData); ! #endif ! if (!PyArg_ParseTuple(_args, "O&s#", ! PyMac_GetOSType, &typeCode, ! &dataPtr__in__, &dataPtr__in_len__)) ! return NULL; ! dataPtr__len__ = dataPtr__in_len__; ! _err = AEReplaceDescData(typeCode, ! dataPtr__in__, dataPtr__len__, ! &theAEDesc); ! if (_err != noErr) return PyMac_Error(_err); ! _res = Py_BuildValue("O&", ! AEDesc_New, &theAEDesc); ! return _res; ! } static PyObject *AE_AEProcessAppleEvent(PyObject *_self, PyObject *_args) { --- 1085,1095 ---- return _res; } ! ! ! /* DELETED CODE */ ! ! static PyObject *AE_AEProcessAppleEvent(PyObject *_self, PyObject *_args) { *************** *** 1213,1218 **** --- 1240,1327 ---- return _res; } + + /* BEGIN NEW CODE */ + + static PyObject *AE_AEInstallCoercionHandler(PyObject *_self, PyObject *_args) + { + PyObject *_res = NULL; + OSErr _err; + DescType fromType, toType; + AECoercionHandlerUPP handler__proc__ = upp_GenericCoercionHandler; + PyObject *handler; + #ifndef AEInstallCoercionHandler + PyMac_PRECHECK(AEInstallCoercionHandler); + #endif + if (!PyArg_ParseTuple(_args, "O&O&O", + PyMac_GetOSType, &fromType, + PyMac_GetOSType, &toType, + &handler)) + return NULL; + _err = AEInstallCoercionHandler(fromType, + toType, + handler__proc__, (long)handler, + 1, 0); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + Py_INCREF(handler); /* XXX leak, but needed */ + return _res; + } + + static PyObject *AE_AERemoveCoercionHandler(PyObject *_self, PyObject *_args) + { + PyObject *_res = NULL; + OSErr _err; + DescType fromType, toType; + #ifndef AERemoveCoercionHandler + PyMac_PRECHECK(AERemoveCoercionHandler); + #endif + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &fromType, + PyMac_GetOSType, &toType)) + return NULL; + _err = AERemoveCoercionHandler(fromType, + toType, + upp_GenericCoercionHandler, + 0); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; + } + + static PyObject *AE_AEGetCoercionHandler(PyObject *_self, PyObject *_args) + { + PyObject *_res = NULL; + OSErr _err; + DescType fromType, toType; + AECoercionHandlerUPP handler__proc__ = upp_GenericCoercionHandler; + PyObject *handler; + Boolean fromTypeIsDesc; + #ifndef AEGetCoercionHandler + PyMac_PRECHECK(AEGetCoercionHandler); + #endif + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &fromType, + PyMac_GetOSType, &toType)) + return NULL; + _err = AEGetCoercionHandler(fromType, + toType, + &handler__proc__, (long *)&handler, + &fromTypeIsDesc, + 0); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("Ob", + handler, + fromTypeIsDesc); + Py_INCREF(handler); /* XXX leak, but needed */ + return _res; + } + /* END NEW CODE */ + + + static PyObject *AE_AEInstallSpecialHandler(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; *************** *** 1347,1354 **** PyDoc_STR("(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)")}, {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1, PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)")}, ! {"AEReplaceDescData", (PyCFunction)AE_AEReplaceDescData, 1, ! PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)")}, {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1, PyDoc_STR("(EventRecord theEventRecord) -> None")}, {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1, --- 1456,1464 ---- PyDoc_STR("(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)")}, {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1, PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)")}, ! ! /* DELETED CODE */ ! {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1, PyDoc_STR("(EventRecord theEventRecord) -> None")}, {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1, *************** *** 1363,1368 **** --- 1473,1490 ---- PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None")}, {"AEGetEventHandler", (PyCFunction)AE_AEGetEventHandler, 1, PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)")}, + + /* BEGIN NEW CODE */ + + {"AEInstallCoercionHandler", (PyCFunction)AE_AEInstallCoercionHandler, 1, + PyDoc_STR("(DescType fromType, DescType toType, CoercionHandler handler) -> None")}, + {"AERemoveCoercionHandler", (PyCFunction)AE_AERemoveCoercionHandler, 1, + PyDoc_STR("(DescType fromType, DescType toType) -> None")}, + {"AEGetCoercionHandler", (PyCFunction)AE_AEGetCoercionHandler, 1, + PyDoc_STR("(DescType fromType, DescType toType) -> (CoercionHandler handler, Boolean fromTypeIsDesc)")}, + + /* END NEW CODE */ + {"AEInstallSpecialHandler", (PyCFunction)AE_AEInstallSpecialHandler, 1, PyDoc_STR("(AEKeyword functionClass) -> None")}, {"AERemoveSpecialHandler", (PyCFunction)AE_AERemoveSpecialHandler, 1, *************** *** 1413,1418 **** --- 1535,1580 ---- return noErr; } + + /* BEGIN NEW CODE */ + + static pascal OSErr + GenericCoercionHandler(const AEDesc *fromDesc, DescType toType, refcontype refcon, AEDesc *toDesc) + { + PyObject *handler = (PyObject *)refcon; + AEDescObject *fromObject; + PyObject *args, *res; + if ((fromObject = (AEDescObject *)AEDesc_New((AEDesc *)fromDesc)) == NULL) { + return -1; + } + if ((args = Py_BuildValue("OO&", fromObject, PyMac_BuildOSType, &toType)) == NULL) { + Py_DECREF(fromObject); + return -1; + } + res = PyEval_CallObject(handler, args); + fromObject->ob_itself.descriptorType = 'null'; + fromObject->ob_itself.dataHandle = NULL; + Py_DECREF(args); + if (res == NULL) { + PySys_WriteStderr("Exception in AE coercion handler function\n"); + PyErr_Print(); + return -1; + } + if (!AEDesc_Check(res)) { + Py_DECREF(res); + return errAECoercionFail; + } + if (AEDuplicateDesc(&((AEDescObject *)res)->ob_itself, toDesc)) { + Py_DECREF(res); + return -1; + } + Py_DECREF(res); + return noErr; + } + /* END NEW CODE */ + + + PyObject *AEDesc_NewBorrowed(AEDesc *itself) { PyObject *it; *************** *** 1434,1439 **** --- 1596,1606 ---- upp_AEIdleProc = NewAEIdleUPP(AEIdleProc); upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler); + + /* BEGIN NEW CODE */ + upp_GenericCoercionHandler = NewAECoerceDescUPP(GenericCoercionHandler); + /* END NEW CODE */ + PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New); PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed); PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);