[Python-checkins] python/dist/src/Mac/Modules/cf _CFmodule.c,1.20,1.21 cfsupport.py,1.21,1.22
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Tue, 27 May 2003 14:40:00 -0700
Update of /cvsroot/python/python/dist/src/Mac/Modules/cf
In directory sc8-pr-cvs1:/tmp/cvs-serv19773/Mac/Modules/cf
Modified Files:
_CFmodule.c cfsupport.py
Log Message:
Added functions CFObj_New and CFObj_Convert, general functions to convert
between CF objects and their Python representation. Fixes 734695.
Index: _CFmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/_CFmodule.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** _CFmodule.c 3 Mar 2003 13:12:58 -0000 1.20
--- _CFmodule.c 27 May 2003 21:39:58 -0000 1.21
***************
*** 37,40 ****
--- 37,45 ----
#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 *);
***************
*** 122,126 ****
}
-
static PyObject *CF_Error;
--- 127,130 ----
***************
*** 1458,1462 ****
if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyString_Check(v)) {
! char *cStr = PyString_AsString(v);
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
return 1;
--- 1462,1468 ----
if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyString_Check(v)) {
! char *cStr;
! if (!PyArg_Parse(v, "es", "ascii", &cStr))
! return NULL;
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
return 1;
***************
*** 4291,4294 ****
--- 4297,4342 ----
+
+
+ /* 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;
+ }
Index: cfsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/cfsupport.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** cfsupport.py 3 Mar 2003 13:19:43 -0000 1.21
--- cfsupport.py 27 May 2003 21:39:58 -0000 1.22
***************
*** 59,62 ****
--- 59,67 ----
#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 *);
***************
*** 143,147 ****
--- 148,195 ----
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;
+ }
"""