summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/cf/cfsupport.py
diff options
context:
space:
mode:
Diffstat (limited to 'Mac/Modules/cf/cfsupport.py')
-rw-r--r--Mac/Modules/cf/cfsupport.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/Mac/Modules/cf/cfsupport.py b/Mac/Modules/cf/cfsupport.py
index e8fb710..7e0a5d9 100644
--- a/Mac/Modules/cf/cfsupport.py
+++ b/Mac/Modules/cf/cfsupport.py
@@ -58,6 +58,11 @@ includestuff = includestuff + """
#include "pycfbridge.h"
#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_CFObj_New(CFTypeRef);
+extern int _CFObj_Convert(PyObject *, CFTypeRef *);
+#define CFObj_New _CFObj_New
+#define CFObj_Convert _CFObj_Convert
+
extern PyObject *_CFTypeRefObj_New(CFTypeRef);
extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
#define CFTypeRefObj_New _CFTypeRefObj_New
@@ -142,7 +147,50 @@ OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
}
return CFURLRefObj_Convert(v, p_itself);
}
+"""
+
+finalstuff = finalstuff + """
+
+/* Routines to convert any CF type to/from the corresponding CFxxxObj */
+PyObject *CFObj_New(CFTypeRef itself)
+{
+ if (itself == NULL)
+ {
+ PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
+ return NULL;
+ }
+ if (CFGetTypeID(itself) == CFArrayGetTypeID()) return CFArrayRefObj_New((CFArrayRef)itself);
+ if (CFGetTypeID(itself) == CFDictionaryGetTypeID()) return CFDictionaryRefObj_New((CFDictionaryRef)itself);
+ if (CFGetTypeID(itself) == CFDataGetTypeID()) return CFDataRefObj_New((CFDataRef)itself);
+ if (CFGetTypeID(itself) == CFStringGetTypeID()) return CFStringRefObj_New((CFStringRef)itself);
+ if (CFGetTypeID(itself) == CFURLGetTypeID()) return CFURLRefObj_New((CFURLRef)itself);
+ /* XXXX Or should we use PyCF_CF2Python here?? */
+ return CFTypeRefObj_New(itself);
+}
+int CFObj_Convert(PyObject *v, CFTypeRef *p_itself)
+{
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFTypeRefObj_Check(v) &&
+ !CFArrayRefObj_Check(v) &&
+ !CFMutableArrayRefObj_Check(v) &&
+ !CFDictionaryRefObj_Check(v) &&
+ !CFMutableDictionaryRefObj_Check(v) &&
+ !CFDataRefObj_Check(v) &&
+ !CFMutableDataRefObj_Check(v) &&
+ !CFStringRefObj_Check(v) &&
+ !CFMutableStringRefObj_Check(v) &&
+ !CFURLRefObj_Check(v) )
+ {
+ /* XXXX Or should we use PyCF_Python2CF here?? */
+ PyErr_SetString(PyExc_TypeError, "CF object required");
+ return 0;
+ }
+ *p_itself = ((CFTypeRefObject *)v)->ob_itself;
+ return 1;
+}
"""
initstuff = initstuff + """