diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2001-06-27 22:00:55 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2001-06-27 22:00:55 (GMT) |
commit | bc7c8960e0afe272a89b37607664819599e5572e (patch) | |
tree | a0412716365772d5e9e95b15efc88ea084957f8d /Mac/Modules | |
parent | 4f0f1584fb87aff70786fa479ed8ba1b7342dab8 (diff) | |
download | cpython-bc7c8960e0afe272a89b37607664819599e5572e.zip cpython-bc7c8960e0afe272a89b37607664819599e5572e.tar.gz cpython-bc7c8960e0afe272a89b37607664819599e5572e.tar.bz2 |
CFArray, CFData and CFDictonary are now covered, but mainly opaque.
CFStrings are in better shape, but Unicode support and automatic conversion to/from Python strings remains to be done.
Diffstat (limited to 'Mac/Modules')
-rw-r--r-- | Mac/Modules/cf/CFmodule.c | 2171 | ||||
-rw-r--r-- | Mac/Modules/cf/cfscan.py | 43 | ||||
-rw-r--r-- | Mac/Modules/cf/cfsupport.py | 167 |
3 files changed, 2372 insertions, 9 deletions
diff --git a/Mac/Modules/cf/CFmodule.c b/Mac/Modules/cf/CFmodule.c index ca2ce51..628373e 100644 --- a/Mac/Modules/cf/CFmodule.c +++ b/Mac/Modules/cf/CFmodule.c @@ -20,6 +20,7 @@ extern int CFTypeRefObj_Convert(PyObject *, CFTypeRef *); extern PyObject *CFStringRefObj_New(CFStringRef); extern int CFStringRefObj_Convert(PyObject *, CFStringRef *); +// ADD declarations #ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE //extern PyObject *_CFTypeRefObj_New(CFTypeRef); //extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *); @@ -28,6 +29,26 @@ extern int CFStringRefObj_Convert(PyObject *, CFStringRef *); //#define CFTypeRefObj_Convert _CFTypeRefObj_Convert #endif +/* +** Parse/generate RGB records +*/ +PyObject *CFRange_New(CFRange *itself) +{ + + return Py_BuildValue("ll", (long)itself->location, (long)itself->length); +} + +CFRange_Convert(PyObject *v, CFRange *p_itself) +{ + long location, length; + + if( !PyArg_ParseTuple(v, "ll", &location, &length) ) + return 0; + p_itself->location = (CFIndex)location; + p_itself->length = (CFIndex)length; + return 1; +} + static PyObject *CF_Error; @@ -164,6 +185,17 @@ static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject return _res; } +static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CFShow(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + static PyMethodDef CFTypeRefObj_methods[] = { {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1, "() -> (CFTypeID _rv)"}, @@ -179,6 +211,8 @@ static PyMethodDef CFTypeRefObj_methods[] = { "() -> (CFHashCode _rv)"}, {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1, "() -> (CFStringRef _rv)"}, + {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1, + "() -> None"}, {NULL, NULL, 0} }; @@ -234,6 +268,818 @@ PyTypeObject CFTypeRef_Type = { /* ------------------- End object type CFTypeRef -------------------- */ +/* --------------------- Object type CFArrayRef --------------------- */ + +PyTypeObject CFArrayRef_Type; + +#define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type) + +typedef struct CFArrayRefObject { + PyObject_HEAD + CFArrayRef ob_itself; + void (*ob_freeit)(CFTypeRef ptr); +} CFArrayRefObject; + +PyObject *CFArrayRefObj_New(CFArrayRef itself) +{ + CFArrayRefObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + CFRetain(itself); + it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = CFRelease; + return (PyObject *)it; +} +CFArrayRefObj_Convert(PyObject *v, CFArrayRef *p_itself) +{ + + if (v == Py_None) { *p_itself = NULL; return 1; } + /* Check for other CF objects here */ + + if (!CFArrayRefObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "CFArrayRef required"); + return 0; + } + *p_itself = ((CFArrayRefObject *)v)->ob_itself; + return 1; +} + +static void CFArrayRefObj_dealloc(CFArrayRefObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit((CFTypeRef)self->ob_itself); + } + PyMem_DEL(self); +} + +static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFArrayGetCount(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyMethodDef CFArrayRefObj_methods[] = { + {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1, + "() -> (CFIndex _rv)"}, + {NULL, NULL, 0} +}; + +PyMethodChain CFArrayRefObj_chain = { CFArrayRefObj_methods, NULL }; + +static PyObject *CFArrayRefObj_getattr(CFArrayRefObject *self, char *name) +{ + return Py_FindMethodInChain(&CFArrayRefObj_chain, (PyObject *)self, name); +} + +#define CFArrayRefObj_setattr NULL + +static int CFArrayRefObj_compare(CFArrayRefObject *self, CFArrayRefObject *other) +{ + /* XXXX Or should we use CFEqual?? */ + if ( self->ob_itself > other->ob_itself ) return 1; + if ( self->ob_itself < other->ob_itself ) return -1; + return 0; +} + +static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self) +{ + char buf[100]; + sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself); + return PyString_FromString(buf); +} + +static int CFArrayRefObj_hash(CFArrayRefObject *self) +{ + /* XXXX Or should we use CFHash?? */ + return (int)self->ob_itself; +} + +PyTypeObject CFArrayRef_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "CFArrayRef", /*tp_name*/ + sizeof(CFArrayRefObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CFArrayRefObj_getattr, /*tp_getattr*/ + (setattrfunc) CFArrayRefObj_setattr, /*tp_setattr*/ + (cmpfunc) CFArrayRefObj_compare, /*tp_compare*/ + (reprfunc) CFArrayRefObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) CFArrayRefObj_hash, /*tp_hash*/ +}; + +/* ------------------- End object type CFArrayRef ------------------- */ + + +/* ----------------- Object type CFMutableArrayRef ------------------ */ + +PyTypeObject CFMutableArrayRef_Type; + +#define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type) + +typedef struct CFMutableArrayRefObject { + PyObject_HEAD + CFMutableArrayRef ob_itself; + void (*ob_freeit)(CFTypeRef ptr); +} CFMutableArrayRefObject; + +PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef itself) +{ + CFMutableArrayRefObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + CFRetain(itself); + it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = CFRelease; + return (PyObject *)it; +} +CFMutableArrayRefObj_Convert(PyObject *v, CFMutableArrayRef *p_itself) +{ + + if (v == Py_None) { *p_itself = NULL; return 1; } + /* Check for other CF objects here */ + + if (!CFMutableArrayRefObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "CFMutableArrayRef required"); + return 0; + } + *p_itself = ((CFMutableArrayRefObject *)v)->ob_itself; + return 1; +} + +static void CFMutableArrayRefObj_dealloc(CFMutableArrayRefObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit((CFTypeRef)self->ob_itself); + } + PyMem_DEL(self); +} + +static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex idx; + if (!PyArg_ParseTuple(_args, "l", + &idx)) + return NULL; + CFArrayRemoveValueAtIndex(_self->ob_itself, + idx); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableArrayRefObj_CFArrayRemoveAllValues(CFMutableArrayRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CFArrayRemoveAllValues(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices(CFMutableArrayRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex idx1; + CFIndex idx2; + if (!PyArg_ParseTuple(_args, "ll", + &idx1, + &idx2)) + return NULL; + CFArrayExchangeValuesAtIndices(_self->ob_itself, + idx1, + idx2); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef CFMutableArrayRefObj_methods[] = { + {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1, + "(CFIndex idx) -> None"}, + {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1, + "() -> None"}, + {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1, + "(CFIndex idx1, CFIndex idx2) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain CFMutableArrayRefObj_chain = { CFMutableArrayRefObj_methods, NULL }; + +static PyObject *CFMutableArrayRefObj_getattr(CFMutableArrayRefObject *self, char *name) +{ + return Py_FindMethodInChain(&CFMutableArrayRefObj_chain, (PyObject *)self, name); +} + +#define CFMutableArrayRefObj_setattr NULL + +static int CFMutableArrayRefObj_compare(CFMutableArrayRefObject *self, CFMutableArrayRefObject *other) +{ + /* XXXX Or should we use CFEqual?? */ + if ( self->ob_itself > other->ob_itself ) return 1; + if ( self->ob_itself < other->ob_itself ) return -1; + return 0; +} + +static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self) +{ + char buf[100]; + sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself); + return PyString_FromString(buf); +} + +static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self) +{ + /* XXXX Or should we use CFHash?? */ + return (int)self->ob_itself; +} + +PyTypeObject CFMutableArrayRef_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "CFMutableArrayRef", /*tp_name*/ + sizeof(CFMutableArrayRefObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CFMutableArrayRefObj_getattr, /*tp_getattr*/ + (setattrfunc) CFMutableArrayRefObj_setattr, /*tp_setattr*/ + (cmpfunc) CFMutableArrayRefObj_compare, /*tp_compare*/ + (reprfunc) CFMutableArrayRefObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) CFMutableArrayRefObj_hash, /*tp_hash*/ +}; + +/* --------------- End object type CFMutableArrayRef ---------------- */ + + +/* ------------------ Object type CFDictionaryRef ------------------- */ + +PyTypeObject CFDictionaryRef_Type; + +#define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type) + +typedef struct CFDictionaryRefObject { + PyObject_HEAD + CFDictionaryRef ob_itself; + void (*ob_freeit)(CFTypeRef ptr); +} CFDictionaryRefObject; + +PyObject *CFDictionaryRefObj_New(CFDictionaryRef itself) +{ + CFDictionaryRefObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + CFRetain(itself); + it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = CFRelease; + return (PyObject *)it; +} +CFDictionaryRefObj_Convert(PyObject *v, CFDictionaryRef *p_itself) +{ + + if (v == Py_None) { *p_itself = NULL; return 1; } + /* Check for other CF objects here */ + + if (!CFDictionaryRefObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "CFDictionaryRef required"); + return 0; + } + *p_itself = ((CFDictionaryRefObject *)v)->ob_itself; + return 1; +} + +static void CFDictionaryRefObj_dealloc(CFDictionaryRefObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit((CFTypeRef)self->ob_itself); + } + PyMem_DEL(self); +} + +static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFDictionaryGetCount(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyMethodDef CFDictionaryRefObj_methods[] = { + {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1, + "() -> (CFIndex _rv)"}, + {NULL, NULL, 0} +}; + +PyMethodChain CFDictionaryRefObj_chain = { CFDictionaryRefObj_methods, NULL }; + +static PyObject *CFDictionaryRefObj_getattr(CFDictionaryRefObject *self, char *name) +{ + return Py_FindMethodInChain(&CFDictionaryRefObj_chain, (PyObject *)self, name); +} + +#define CFDictionaryRefObj_setattr NULL + +static int CFDictionaryRefObj_compare(CFDictionaryRefObject *self, CFDictionaryRefObject *other) +{ + /* XXXX Or should we use CFEqual?? */ + if ( self->ob_itself > other->ob_itself ) return 1; + if ( self->ob_itself < other->ob_itself ) return -1; + return 0; +} + +static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self) +{ + char buf[100]; + sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself); + return PyString_FromString(buf); +} + +static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self) +{ + /* XXXX Or should we use CFHash?? */ + return (int)self->ob_itself; +} + +PyTypeObject CFDictionaryRef_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "CFDictionaryRef", /*tp_name*/ + sizeof(CFDictionaryRefObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CFDictionaryRefObj_getattr, /*tp_getattr*/ + (setattrfunc) CFDictionaryRefObj_setattr, /*tp_setattr*/ + (cmpfunc) CFDictionaryRefObj_compare, /*tp_compare*/ + (reprfunc) CFDictionaryRefObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) CFDictionaryRefObj_hash, /*tp_hash*/ +}; + +/* ---------------- End object type CFDictionaryRef ----------------- */ + + +/* --------------- Object type CFMutableDictionaryRef --------------- */ + +PyTypeObject CFMutableDictionaryRef_Type; + +#define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type) + +typedef struct CFMutableDictionaryRefObject { + PyObject_HEAD + CFMutableDictionaryRef ob_itself; + void (*ob_freeit)(CFTypeRef ptr); +} CFMutableDictionaryRefObject; + +PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef itself) +{ + CFMutableDictionaryRefObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + CFRetain(itself); + it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = CFRelease; + return (PyObject *)it; +} +CFMutableDictionaryRefObj_Convert(PyObject *v, CFMutableDictionaryRef *p_itself) +{ + + if (v == Py_None) { *p_itself = NULL; return 1; } + /* Check for other CF objects here */ + + if (!CFMutableDictionaryRefObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "CFMutableDictionaryRef required"); + return 0; + } + *p_itself = ((CFMutableDictionaryRefObject *)v)->ob_itself; + return 1; +} + +static void CFMutableDictionaryRefObj_dealloc(CFMutableDictionaryRefObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit((CFTypeRef)self->ob_itself); + } + PyMem_DEL(self); +} + +static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CFDictionaryRemoveAllValues(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef CFMutableDictionaryRefObj_methods[] = { + {"CFDictionaryRemoveAllValues", (PyCFunction)CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues, 1, + "() -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain CFMutableDictionaryRefObj_chain = { CFMutableDictionaryRefObj_methods, NULL }; + +static PyObject *CFMutableDictionaryRefObj_getattr(CFMutableDictionaryRefObject *self, char *name) +{ + return Py_FindMethodInChain(&CFMutableDictionaryRefObj_chain, (PyObject *)self, name); +} + +#define CFMutableDictionaryRefObj_setattr NULL + +static int CFMutableDictionaryRefObj_compare(CFMutableDictionaryRefObject *self, CFMutableDictionaryRefObject *other) +{ + /* XXXX Or should we use CFEqual?? */ + if ( self->ob_itself > other->ob_itself ) return 1; + if ( self->ob_itself < other->ob_itself ) return -1; + return 0; +} + +static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *self) +{ + char buf[100]; + sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself); + return PyString_FromString(buf); +} + +static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self) +{ + /* XXXX Or should we use CFHash?? */ + return (int)self->ob_itself; +} + +PyTypeObject CFMutableDictionaryRef_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "CFMutableDictionaryRef", /*tp_name*/ + sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CFMutableDictionaryRefObj_getattr, /*tp_getattr*/ + (setattrfunc) CFMutableDictionaryRefObj_setattr, /*tp_setattr*/ + (cmpfunc) CFMutableDictionaryRefObj_compare, /*tp_compare*/ + (reprfunc) CFMutableDictionaryRefObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) CFMutableDictionaryRefObj_hash, /*tp_hash*/ +}; + +/* ------------- End object type CFMutableDictionaryRef ------------- */ + + +/* --------------------- Object type CFDataRef ---------------------- */ + +PyTypeObject CFDataRef_Type; + +#define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type) + +typedef struct CFDataRefObject { + PyObject_HEAD + CFDataRef ob_itself; + void (*ob_freeit)(CFTypeRef ptr); +} CFDataRefObject; + +PyObject *CFDataRefObj_New(CFDataRef itself) +{ + CFDataRefObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + CFRetain(itself); + it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = CFRelease; + return (PyObject *)it; +} +CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself) +{ + + if (v == Py_None) { *p_itself = NULL; return 1; } + /* Check for other CF objects here */ + + if (!CFDataRefObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "CFDataRef required"); + return 0; + } + *p_itself = ((CFDataRefObject *)v)->ob_itself; + return 1; +} + +static void CFDataRefObj_dealloc(CFDataRefObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit((CFTypeRef)self->ob_itself); + } + PyMem_DEL(self); +} + +static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFDataGetLength(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyMethodDef CFDataRefObj_methods[] = { + {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1, + "() -> (CFIndex _rv)"}, + {NULL, NULL, 0} +}; + +PyMethodChain CFDataRefObj_chain = { CFDataRefObj_methods, NULL }; + +static PyObject *CFDataRefObj_getattr(CFDataRefObject *self, char *name) +{ + return Py_FindMethodInChain(&CFDataRefObj_chain, (PyObject *)self, name); +} + +#define CFDataRefObj_setattr NULL + +static int CFDataRefObj_compare(CFDataRefObject *self, CFDataRefObject *other) +{ + /* XXXX Or should we use CFEqual?? */ + if ( self->ob_itself > other->ob_itself ) return 1; + if ( self->ob_itself < other->ob_itself ) return -1; + return 0; +} + +static PyObject * CFDataRefObj_repr(CFDataRefObject *self) +{ + char buf[100]; + sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself); + return PyString_FromString(buf); +} + +static int CFDataRefObj_hash(CFDataRefObject *self) +{ + /* XXXX Or should we use CFHash?? */ + return (int)self->ob_itself; +} + +PyTypeObject CFDataRef_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "CFDataRef", /*tp_name*/ + sizeof(CFDataRefObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CFDataRefObj_getattr, /*tp_getattr*/ + (setattrfunc) CFDataRefObj_setattr, /*tp_setattr*/ + (cmpfunc) CFDataRefObj_compare, /*tp_compare*/ + (reprfunc) CFDataRefObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) CFDataRefObj_hash, /*tp_hash*/ +}; + +/* ------------------- End object type CFDataRef -------------------- */ + + +/* ------------------ Object type CFMutableDataRef ------------------ */ + +PyTypeObject CFMutableDataRef_Type; + +#define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type) + +typedef struct CFMutableDataRefObject { + PyObject_HEAD + CFMutableDataRef ob_itself; + void (*ob_freeit)(CFTypeRef ptr); +} CFMutableDataRefObject; + +PyObject *CFMutableDataRefObj_New(CFMutableDataRef itself) +{ + CFMutableDataRefObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + CFRetain(itself); + it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = CFRelease; + return (PyObject *)it; +} +CFMutableDataRefObj_Convert(PyObject *v, CFMutableDataRef *p_itself) +{ + + if (v == Py_None) { *p_itself = NULL; return 1; } + /* Check for other CF objects here */ + + if (!CFMutableDataRefObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "CFMutableDataRef required"); + return 0; + } + *p_itself = ((CFMutableDataRefObject *)v)->ob_itself; + return 1; +} + +static void CFMutableDataRefObj_dealloc(CFMutableDataRefObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit((CFTypeRef)self->ob_itself); + } + PyMem_DEL(self); +} + +static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex length; + if (!PyArg_ParseTuple(_args, "l", + &length)) + return NULL; + CFDataSetLength(_self->ob_itself, + length); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableDataRefObj_CFDataIncreaseLength(CFMutableDataRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex extraLength; + if (!PyArg_ParseTuple(_args, "l", + &extraLength)) + return NULL; + CFDataIncreaseLength(_self->ob_itself, + extraLength); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableDataRefObj_CFDataAppendBytes(CFMutableDataRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + unsigned char *bytes__in__; + long bytes__len__; + int bytes__in_len__; + if (!PyArg_ParseTuple(_args, "s#", + &bytes__in__, &bytes__in_len__)) + return NULL; + bytes__len__ = bytes__in_len__; + CFDataAppendBytes(_self->ob_itself, + bytes__in__, bytes__len__); + Py_INCREF(Py_None); + _res = Py_None; + bytes__error__: ; + return _res; +} + +static PyObject *CFMutableDataRefObj_CFDataReplaceBytes(CFMutableDataRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFRange range; + unsigned char *newBytes__in__; + long newBytes__len__; + int newBytes__in_len__; + if (!PyArg_ParseTuple(_args, "O&s#", + CFRange_Convert, &range, + &newBytes__in__, &newBytes__in_len__)) + return NULL; + newBytes__len__ = newBytes__in_len__; + CFDataReplaceBytes(_self->ob_itself, + range, + newBytes__in__, newBytes__len__); + Py_INCREF(Py_None); + _res = Py_None; + newBytes__error__: ; + return _res; +} + +static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFRange range; + if (!PyArg_ParseTuple(_args, "O&", + CFRange_Convert, &range)) + return NULL; + CFDataDeleteBytes(_self->ob_itself, + range); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef CFMutableDataRefObj_methods[] = { + {"CFDataSetLength", (PyCFunction)CFMutableDataRefObj_CFDataSetLength, 1, + "(CFIndex length) -> None"}, + {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1, + "(CFIndex extraLength) -> None"}, + {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1, + "(Buffer bytes) -> None"}, + {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1, + "(CFRange range, Buffer newBytes) -> None"}, + {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1, + "(CFRange range) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain CFMutableDataRefObj_chain = { CFMutableDataRefObj_methods, NULL }; + +static PyObject *CFMutableDataRefObj_getattr(CFMutableDataRefObject *self, char *name) +{ + return Py_FindMethodInChain(&CFMutableDataRefObj_chain, (PyObject *)self, name); +} + +#define CFMutableDataRefObj_setattr NULL + +static int CFMutableDataRefObj_compare(CFMutableDataRefObject *self, CFMutableDataRefObject *other) +{ + /* XXXX Or should we use CFEqual?? */ + if ( self->ob_itself > other->ob_itself ) return 1; + if ( self->ob_itself < other->ob_itself ) return -1; + return 0; +} + +static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self) +{ + char buf[100]; + sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself); + return PyString_FromString(buf); +} + +static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self) +{ + /* XXXX Or should we use CFHash?? */ + return (int)self->ob_itself; +} + +PyTypeObject CFMutableDataRef_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "CFMutableDataRef", /*tp_name*/ + sizeof(CFMutableDataRefObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CFMutableDataRefObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CFMutableDataRefObj_getattr, /*tp_getattr*/ + (setattrfunc) CFMutableDataRefObj_setattr, /*tp_setattr*/ + (cmpfunc) CFMutableDataRefObj_compare, /*tp_compare*/ + (reprfunc) CFMutableDataRefObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) CFMutableDataRefObj_hash, /*tp_hash*/ +}; + +/* ---------------- End object type CFMutableDataRef ---------------- */ + + /* -------------------- Object type CFStringRef --------------------- */ PyTypeObject CFStringRef_Type; @@ -281,7 +1127,309 @@ static void CFStringRefObj_dealloc(CFStringRefObject *self) PyMem_DEL(self); } +static PyObject *CFStringRefObj_CFStringGetLength(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringGetLength(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringGetCString(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Boolean _rv; + char buffer; + CFIndex bufferSize; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "ll", + &bufferSize, + &encoding)) + return NULL; + _rv = CFStringGetCString(_self->ob_itself, + &buffer, + bufferSize, + encoding); + _res = Py_BuildValue("lc", + _rv, + buffer); + return _res; +} + +static PyObject *CFStringRefObj_CFStringGetBytes(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex _rv; + CFRange range; + CFStringEncoding encoding; + UInt8 lossByte; + Boolean isExternalRepresentation; + UInt8 buffer; + CFIndex maxBufLen; + CFIndex usedBufLen; + if (!PyArg_ParseTuple(_args, "O&lbll", + CFRange_Convert, &range, + &encoding, + &lossByte, + &isExternalRepresentation, + &maxBufLen)) + return NULL; + _rv = CFStringGetBytes(_self->ob_itself, + range, + encoding, + lossByte, + isExternalRepresentation, + &buffer, + maxBufLen, + &usedBufLen); + _res = Py_BuildValue("lbl", + _rv, + buffer, + usedBufLen); + return _res; +} + +static PyObject *CFStringRefObj_CFStringGetSmallestEncoding(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringEncoding _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringGetSmallestEncoding(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringGetFastestEncoding(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringEncoding _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringGetFastestEncoding(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringCompareWithOptions(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFComparisonResult _rv; + CFStringRef string2; + CFRange rangeToCompare; + CFOptionFlags compareOptions; + if (!PyArg_ParseTuple(_args, "O&O&l", + CFStringRefObj_Convert, &string2, + CFRange_Convert, &rangeToCompare, + &compareOptions)) + return NULL; + _rv = CFStringCompareWithOptions(_self->ob_itself, + string2, + rangeToCompare, + compareOptions); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringCompare(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFComparisonResult _rv; + CFStringRef string2; + CFOptionFlags compareOptions; + if (!PyArg_ParseTuple(_args, "O&l", + CFStringRefObj_Convert, &string2, + &compareOptions)) + return NULL; + _rv = CFStringCompare(_self->ob_itself, + string2, + compareOptions); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringFindWithOptions(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Boolean _rv; + CFStringRef stringToFind; + CFRange rangeToSearch; + CFOptionFlags searchOptions; + CFRange result; + if (!PyArg_ParseTuple(_args, "O&O&l", + CFStringRefObj_Convert, &stringToFind, + CFRange_Convert, &rangeToSearch, + &searchOptions)) + return NULL; + _rv = CFStringFindWithOptions(_self->ob_itself, + stringToFind, + rangeToSearch, + searchOptions, + &result); + _res = Py_BuildValue("lO&", + _rv, + CFRange_New, result); + return _res; +} + +static PyObject *CFStringRefObj_CFStringFind(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFRange _rv; + CFStringRef stringToFind; + CFOptionFlags compareOptions; + if (!PyArg_ParseTuple(_args, "O&l", + CFStringRefObj_Convert, &stringToFind, + &compareOptions)) + return NULL; + _rv = CFStringFind(_self->ob_itself, + stringToFind, + compareOptions); + _res = Py_BuildValue("O&", + CFRange_New, _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringHasPrefix(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Boolean _rv; + CFStringRef prefix; + if (!PyArg_ParseTuple(_args, "O&", + CFStringRefObj_Convert, &prefix)) + return NULL; + _rv = CFStringHasPrefix(_self->ob_itself, + prefix); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringHasSuffix(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Boolean _rv; + CFStringRef suffix; + if (!PyArg_ParseTuple(_args, "O&", + CFStringRefObj_Convert, &suffix)) + return NULL; + _rv = CFStringHasSuffix(_self->ob_itself, + suffix); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringGetLineBounds(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFRange range; + CFIndex lineBeginIndex; + CFIndex lineEndIndex; + CFIndex contentsEndIndex; + if (!PyArg_ParseTuple(_args, "O&", + CFRange_Convert, &range)) + return NULL; + CFStringGetLineBounds(_self->ob_itself, + range, + &lineBeginIndex, + &lineEndIndex, + &contentsEndIndex); + _res = Py_BuildValue("lll", + lineBeginIndex, + lineEndIndex, + contentsEndIndex); + return _res; +} + +static PyObject *CFStringRefObj_CFStringGetIntValue(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + SInt32 _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringGetIntValue(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringGetDoubleValue(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + double _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringGetDoubleValue(_self->ob_itself); + _res = Py_BuildValue("d", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFStringConvertIANACharSetNameToEncoding(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringEncoding _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringConvertIANACharSetNameToEncoding(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CFStringRefObj_CFShowStr(CFStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CFShowStr(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + static PyMethodDef CFStringRefObj_methods[] = { + {"CFStringGetLength", (PyCFunction)CFStringRefObj_CFStringGetLength, 1, + "() -> (CFIndex _rv)"}, + {"CFStringGetCString", (PyCFunction)CFStringRefObj_CFStringGetCString, 1, + "(CFIndex bufferSize, CFStringEncoding encoding) -> (Boolean _rv, char buffer)"}, + {"CFStringGetBytes", (PyCFunction)CFStringRefObj_CFStringGetBytes, 1, + "(CFRange range, CFStringEncoding encoding, UInt8 lossByte, Boolean isExternalRepresentation, CFIndex maxBufLen) -> (CFIndex _rv, UInt8 buffer, CFIndex usedBufLen)"}, + {"CFStringGetSmallestEncoding", (PyCFunction)CFStringRefObj_CFStringGetSmallestEncoding, 1, + "() -> (CFStringEncoding _rv)"}, + {"CFStringGetFastestEncoding", (PyCFunction)CFStringRefObj_CFStringGetFastestEncoding, 1, + "() -> (CFStringEncoding _rv)"}, + {"CFStringCompareWithOptions", (PyCFunction)CFStringRefObj_CFStringCompareWithOptions, 1, + "(CFStringRef string2, CFRange rangeToCompare, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"}, + {"CFStringCompare", (PyCFunction)CFStringRefObj_CFStringCompare, 1, + "(CFStringRef string2, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"}, + {"CFStringFindWithOptions", (PyCFunction)CFStringRefObj_CFStringFindWithOptions, 1, + "(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags searchOptions) -> (Boolean _rv, CFRange result)"}, + {"CFStringFind", (PyCFunction)CFStringRefObj_CFStringFind, 1, + "(CFStringRef stringToFind, CFOptionFlags compareOptions) -> (CFRange _rv)"}, + {"CFStringHasPrefix", (PyCFunction)CFStringRefObj_CFStringHasPrefix, 1, + "(CFStringRef prefix) -> (Boolean _rv)"}, + {"CFStringHasSuffix", (PyCFunction)CFStringRefObj_CFStringHasSuffix, 1, + "(CFStringRef suffix) -> (Boolean _rv)"}, + {"CFStringGetLineBounds", (PyCFunction)CFStringRefObj_CFStringGetLineBounds, 1, + "(CFRange range) -> (CFIndex lineBeginIndex, CFIndex lineEndIndex, CFIndex contentsEndIndex)"}, + {"CFStringGetIntValue", (PyCFunction)CFStringRefObj_CFStringGetIntValue, 1, + "() -> (SInt32 _rv)"}, + {"CFStringGetDoubleValue", (PyCFunction)CFStringRefObj_CFStringGetDoubleValue, 1, + "() -> (double _rv)"}, + {"CFStringConvertIANACharSetNameToEncoding", (PyCFunction)CFStringRefObj_CFStringConvertIANACharSetNameToEncoding, 1, + "() -> (CFStringEncoding _rv)"}, + {"CFShowStr", (PyCFunction)CFStringRefObj_CFShowStr, 1, + "() -> None"}, {NULL, NULL, 0} }; @@ -337,6 +1485,284 @@ PyTypeObject CFStringRef_Type = { /* ------------------ End object type CFStringRef ------------------- */ +/* ----------------- Object type CFMutableStringRef ----------------- */ + +PyTypeObject CFMutableStringRef_Type; + +#define CFMutableStringRefObj_Check(x) ((x)->ob_type == &CFMutableStringRef_Type) + +typedef struct CFMutableStringRefObject { + PyObject_HEAD + CFMutableStringRef ob_itself; + void (*ob_freeit)(CFTypeRef ptr); +} CFMutableStringRefObject; + +PyObject *CFMutableStringRefObj_New(CFMutableStringRef itself) +{ + CFMutableStringRefObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + CFRetain(itself); + it = PyObject_NEW(CFMutableStringRefObject, &CFMutableStringRef_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_freeit = CFRelease; + return (PyObject *)it; +} +CFMutableStringRefObj_Convert(PyObject *v, CFMutableStringRef *p_itself) +{ + + if (v == Py_None) { *p_itself = NULL; return 1; } + /* Check for other CF objects here */ + + if (!CFMutableStringRefObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "CFMutableStringRef required"); + return 0; + } + *p_itself = ((CFMutableStringRefObject *)v)->ob_itself; + return 1; +} + +static void CFMutableStringRefObj_dealloc(CFMutableStringRefObject *self) +{ + if (self->ob_freeit && self->ob_itself) + { + self->ob_freeit((CFTypeRef)self->ob_itself); + } + PyMem_DEL(self); +} + +static PyObject *CFMutableStringRefObj_CFStringAppend(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef appendedString; + if (!PyArg_ParseTuple(_args, "O&", + CFStringRefObj_Convert, &appendedString)) + return NULL; + CFStringAppend(_self->ob_itself, + appendedString); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringAppendPascalString(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + StringPtr pStr; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "O&l", + PyMac_GetStr255, &pStr, + &encoding)) + return NULL; + CFStringAppendPascalString(_self->ob_itself, + pStr, + encoding); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringAppendCString(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + char* cStr; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "sl", + &cStr, + &encoding)) + return NULL; + CFStringAppendCString(_self->ob_itself, + cStr, + encoding); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringInsert(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex idx; + CFStringRef insertedStr; + if (!PyArg_ParseTuple(_args, "lO&", + &idx, + CFStringRefObj_Convert, &insertedStr)) + return NULL; + CFStringInsert(_self->ob_itself, + idx, + insertedStr); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringDelete(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFRange range; + if (!PyArg_ParseTuple(_args, "O&", + CFRange_Convert, &range)) + return NULL; + CFStringDelete(_self->ob_itself, + range); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringReplace(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFRange range; + CFStringRef replacement; + if (!PyArg_ParseTuple(_args, "O&O&", + CFRange_Convert, &range, + CFStringRefObj_Convert, &replacement)) + return NULL; + CFStringReplace(_self->ob_itself, + range, + replacement); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringReplaceAll(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef replacement; + if (!PyArg_ParseTuple(_args, "O&", + CFStringRefObj_Convert, &replacement)) + return NULL; + CFStringReplaceAll(_self->ob_itself, + replacement); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringPad(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef padString; + CFIndex length; + CFIndex indexIntoPad; + if (!PyArg_ParseTuple(_args, "O&ll", + CFStringRefObj_Convert, &padString, + &length, + &indexIntoPad)) + return NULL; + CFStringPad(_self->ob_itself, + padString, + length, + indexIntoPad); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringTrim(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef trimString; + if (!PyArg_ParseTuple(_args, "O&", + CFStringRefObj_Convert, &trimString)) + return NULL; + CFStringTrim(_self->ob_itself, + trimString); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CFMutableStringRefObj_CFStringTrimWhitespace(CFMutableStringRefObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CFStringTrimWhitespace(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef CFMutableStringRefObj_methods[] = { + {"CFStringAppend", (PyCFunction)CFMutableStringRefObj_CFStringAppend, 1, + "(CFStringRef appendedString) -> None"}, + {"CFStringAppendPascalString", (PyCFunction)CFMutableStringRefObj_CFStringAppendPascalString, 1, + "(StringPtr pStr, CFStringEncoding encoding) -> None"}, + {"CFStringAppendCString", (PyCFunction)CFMutableStringRefObj_CFStringAppendCString, 1, + "(char* cStr, CFStringEncoding encoding) -> None"}, + {"CFStringInsert", (PyCFunction)CFMutableStringRefObj_CFStringInsert, 1, + "(CFIndex idx, CFStringRef insertedStr) -> None"}, + {"CFStringDelete", (PyCFunction)CFMutableStringRefObj_CFStringDelete, 1, + "(CFRange range) -> None"}, + {"CFStringReplace", (PyCFunction)CFMutableStringRefObj_CFStringReplace, 1, + "(CFRange range, CFStringRef replacement) -> None"}, + {"CFStringReplaceAll", (PyCFunction)CFMutableStringRefObj_CFStringReplaceAll, 1, + "(CFStringRef replacement) -> None"}, + {"CFStringPad", (PyCFunction)CFMutableStringRefObj_CFStringPad, 1, + "(CFStringRef padString, CFIndex length, CFIndex indexIntoPad) -> None"}, + {"CFStringTrim", (PyCFunction)CFMutableStringRefObj_CFStringTrim, 1, + "(CFStringRef trimString) -> None"}, + {"CFStringTrimWhitespace", (PyCFunction)CFMutableStringRefObj_CFStringTrimWhitespace, 1, + "() -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain CFMutableStringRefObj_chain = { CFMutableStringRefObj_methods, NULL }; + +static PyObject *CFMutableStringRefObj_getattr(CFMutableStringRefObject *self, char *name) +{ + return Py_FindMethodInChain(&CFMutableStringRefObj_chain, (PyObject *)self, name); +} + +#define CFMutableStringRefObj_setattr NULL + +static int CFMutableStringRefObj_compare(CFMutableStringRefObject *self, CFMutableStringRefObject *other) +{ + /* XXXX Or should we use CFEqual?? */ + if ( self->ob_itself > other->ob_itself ) return 1; + if ( self->ob_itself < other->ob_itself ) return -1; + return 0; +} + +static PyObject * CFMutableStringRefObj_repr(CFMutableStringRefObject *self) +{ + char buf[100]; + sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself); + return PyString_FromString(buf); +} + +static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self) +{ + /* XXXX Or should we use CFHash?? */ + return (int)self->ob_itself; +} + +PyTypeObject CFMutableStringRef_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "CFMutableStringRef", /*tp_name*/ + sizeof(CFMutableStringRefObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CFMutableStringRefObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CFMutableStringRefObj_getattr, /*tp_getattr*/ + (setattrfunc) CFMutableStringRefObj_setattr, /*tp_setattr*/ + (cmpfunc) CFMutableStringRefObj_compare, /*tp_compare*/ + (reprfunc) CFMutableStringRefObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) CFMutableStringRefObj_hash, /*tp_hash*/ +}; + +/* --------------- End object type CFMutableStringRef --------------- */ + + static PyObject *CF_CFAllocatorGetTypeID(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; @@ -381,6 +1807,645 @@ static PyObject *CF_CFCopyTypeIDDescription(PyObject *_self, PyObject *_args) return _res; } +static PyObject *CF_CFArrayGetTypeID(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFTypeID _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFArrayGetTypeID(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFArrayCreateCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFArrayRef _rv; + CFArrayRef srcArray; + if (!PyArg_ParseTuple(_args, "O&", + CFArrayRefObj_Convert, &srcArray)) + return NULL; + _rv = CFArrayCreateCopy((CFAllocatorRef)NULL, + srcArray); + _res = Py_BuildValue("O&", + CFArrayRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFArrayCreateMutable(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableArrayRef _rv; + CFIndex capacity; + if (!PyArg_ParseTuple(_args, "l", + &capacity)) + return NULL; + _rv = CFArrayCreateMutable((CFAllocatorRef)NULL, + capacity, + &kCFTypeArrayCallBacks); + _res = Py_BuildValue("O&", + CFMutableArrayRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFArrayCreateMutableCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableArrayRef _rv; + CFIndex capacity; + CFArrayRef srcArray; + if (!PyArg_ParseTuple(_args, "lO&", + &capacity, + CFArrayRefObj_Convert, &srcArray)) + return NULL; + _rv = CFArrayCreateMutableCopy((CFAllocatorRef)NULL, + capacity, + srcArray); + _res = Py_BuildValue("O&", + CFMutableArrayRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFDataGetTypeID(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFTypeID _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFDataGetTypeID(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFDataCreate(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFDataRef _rv; + unsigned char *bytes__in__; + long bytes__len__; + int bytes__in_len__; + if (!PyArg_ParseTuple(_args, "s#", + &bytes__in__, &bytes__in_len__)) + return NULL; + bytes__len__ = bytes__in_len__; + _rv = CFDataCreate((CFAllocatorRef)NULL, + bytes__in__, bytes__len__); + _res = Py_BuildValue("O&", + CFDataRefObj_New, _rv); + bytes__error__: ; + return _res; +} + +static PyObject *CF_CFDataCreateWithBytesNoCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFDataRef _rv; + unsigned char *bytes__in__; + long bytes__len__; + int bytes__in_len__; + if (!PyArg_ParseTuple(_args, "s#", + &bytes__in__, &bytes__in_len__)) + return NULL; + bytes__len__ = bytes__in_len__; + _rv = CFDataCreateWithBytesNoCopy((CFAllocatorRef)NULL, + bytes__in__, bytes__len__, + (CFAllocatorRef)NULL); + _res = Py_BuildValue("O&", + CFDataRefObj_New, _rv); + bytes__error__: ; + return _res; +} + +static PyObject *CF_CFDataCreateCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFDataRef _rv; + CFDataRef data; + if (!PyArg_ParseTuple(_args, "O&", + CFDataRefObj_Convert, &data)) + return NULL; + _rv = CFDataCreateCopy((CFAllocatorRef)NULL, + data); + _res = Py_BuildValue("O&", + CFDataRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFDataCreateMutable(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableDataRef _rv; + CFIndex capacity; + if (!PyArg_ParseTuple(_args, "l", + &capacity)) + return NULL; + _rv = CFDataCreateMutable((CFAllocatorRef)NULL, + capacity); + _res = Py_BuildValue("O&", + CFMutableDataRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFDataCreateMutableCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableDataRef _rv; + CFIndex capacity; + CFDataRef data; + if (!PyArg_ParseTuple(_args, "lO&", + &capacity, + CFDataRefObj_Convert, &data)) + return NULL; + _rv = CFDataCreateMutableCopy((CFAllocatorRef)NULL, + capacity, + data); + _res = Py_BuildValue("O&", + CFMutableDataRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFDictionaryGetTypeID(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFTypeID _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFDictionaryGetTypeID(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFDictionaryCreateCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFDictionaryRef _rv; + CFDictionaryRef dict; + if (!PyArg_ParseTuple(_args, "O&", + CFDictionaryRefObj_Convert, &dict)) + return NULL; + _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL, + dict); + _res = Py_BuildValue("O&", + CFDictionaryRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFDictionaryCreateMutable(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableDictionaryRef _rv; + CFIndex capacity; + if (!PyArg_ParseTuple(_args, "l", + &capacity)) + return NULL; + _rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL, + capacity, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + _res = Py_BuildValue("O&", + CFMutableDictionaryRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFDictionaryCreateMutableCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableDictionaryRef _rv; + CFIndex capacity; + CFDictionaryRef dict; + if (!PyArg_ParseTuple(_args, "lO&", + &capacity, + CFDictionaryRefObj_Convert, &dict)) + return NULL; + _rv = CFDictionaryCreateMutableCopy((CFAllocatorRef)NULL, + capacity, + dict); + _res = Py_BuildValue("O&", + CFMutableDictionaryRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringGetTypeID(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFTypeID _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringGetTypeID(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringCreateWithPascalString(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + StringPtr pStr; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "O&l", + PyMac_GetStr255, &pStr, + &encoding)) + return NULL; + _rv = CFStringCreateWithPascalString((CFAllocatorRef)NULL, + pStr, + encoding); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateWithCString(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + char* cStr; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "sl", + &cStr, + &encoding)) + return NULL; + _rv = CFStringCreateWithCString((CFAllocatorRef)NULL, + cStr, + encoding); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateWithPascalStringNoCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + StringPtr pStr; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "O&l", + PyMac_GetStr255, &pStr, + &encoding)) + return NULL; + _rv = CFStringCreateWithPascalStringNoCopy((CFAllocatorRef)NULL, + pStr, + encoding, + (CFAllocatorRef)NULL); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateWithCStringNoCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + char* cStr; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "sl", + &cStr, + &encoding)) + return NULL; + _rv = CFStringCreateWithCStringNoCopy((CFAllocatorRef)NULL, + cStr, + encoding, + (CFAllocatorRef)NULL); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateWithSubstring(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + CFStringRef str; + CFRange range; + if (!PyArg_ParseTuple(_args, "O&O&", + CFStringRefObj_Convert, &str, + CFRange_Convert, &range)) + return NULL; + _rv = CFStringCreateWithSubstring((CFAllocatorRef)NULL, + str, + range); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + CFStringRef theString; + if (!PyArg_ParseTuple(_args, "O&", + CFStringRefObj_Convert, &theString)) + return NULL; + _rv = CFStringCreateCopy((CFAllocatorRef)NULL, + theString); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateMutable(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableStringRef _rv; + CFIndex maxLength; + if (!PyArg_ParseTuple(_args, "l", + &maxLength)) + return NULL; + _rv = CFStringCreateMutable((CFAllocatorRef)NULL, + maxLength); + _res = Py_BuildValue("O&", + CFMutableStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateMutableCopy(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFMutableStringRef _rv; + CFIndex maxLength; + CFStringRef theString; + if (!PyArg_ParseTuple(_args, "lO&", + &maxLength, + CFStringRefObj_Convert, &theString)) + return NULL; + _rv = CFStringCreateMutableCopy((CFAllocatorRef)NULL, + maxLength, + theString); + _res = Py_BuildValue("O&", + CFMutableStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateWithBytes(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + unsigned char *bytes__in__; + long bytes__len__; + int bytes__in_len__; + CFStringEncoding encoding; + Boolean isExternalRepresentation; + if (!PyArg_ParseTuple(_args, "s#ll", + &bytes__in__, &bytes__in_len__, + &encoding, + &isExternalRepresentation)) + return NULL; + bytes__len__ = bytes__in_len__; + _rv = CFStringCreateWithBytes((CFAllocatorRef)NULL, + bytes__in__, bytes__len__, + encoding, + isExternalRepresentation); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + bytes__error__: ; + return _res; +} + +static PyObject *CF_CFStringCreateFromExternalRepresentation(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + CFDataRef data; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "O&l", + CFDataRefObj_Convert, &data, + &encoding)) + return NULL; + _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL, + data, + encoding); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateExternalRepresentation(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFDataRef _rv; + CFStringRef theString; + CFStringEncoding encoding; + UInt8 lossByte; + if (!PyArg_ParseTuple(_args, "O&lb", + CFStringRefObj_Convert, &theString, + &encoding, + &lossByte)) + return NULL; + _rv = CFStringCreateExternalRepresentation((CFAllocatorRef)NULL, + theString, + encoding, + lossByte); + _res = Py_BuildValue("O&", + CFDataRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringGetSystemEncoding(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringEncoding _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CFStringGetSystemEncoding(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringGetMaximumSizeForEncoding(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFIndex _rv; + CFIndex length; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "ll", + &length, + &encoding)) + return NULL; + _rv = CFStringGetMaximumSizeForEncoding(length, + encoding); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringCreateArrayWithFindResults(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFArrayRef _rv; + CFStringRef theString; + CFStringRef stringToFind; + CFRange rangeToSearch; + CFOptionFlags compareOptions; + if (!PyArg_ParseTuple(_args, "O&O&O&l", + CFStringRefObj_Convert, &theString, + CFStringRefObj_Convert, &stringToFind, + CFRange_Convert, &rangeToSearch, + &compareOptions)) + return NULL; + _rv = CFStringCreateArrayWithFindResults((CFAllocatorRef)NULL, + theString, + stringToFind, + rangeToSearch, + compareOptions); + _res = Py_BuildValue("O&", + CFArrayRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateByCombiningStrings(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + CFArrayRef theArray; + CFStringRef separatorString; + if (!PyArg_ParseTuple(_args, "O&O&", + CFArrayRefObj_Convert, &theArray, + CFStringRefObj_Convert, &separatorString)) + return NULL; + _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL, + theArray, + separatorString); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringCreateArrayBySeparatingStrings(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFArrayRef _rv; + CFStringRef theString; + CFStringRef separatorString; + if (!PyArg_ParseTuple(_args, "O&O&", + CFStringRefObj_Convert, &theString, + CFStringRefObj_Convert, &separatorString)) + return NULL; + _rv = CFStringCreateArrayBySeparatingStrings((CFAllocatorRef)NULL, + theString, + separatorString); + _res = Py_BuildValue("O&", + CFArrayRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringIsEncodingAvailable(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Boolean _rv; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "l", + &encoding)) + return NULL; + _rv = CFStringIsEncodingAvailable(encoding); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringGetNameOfEncoding(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "l", + &encoding)) + return NULL; + _rv = CFStringGetNameOfEncoding(encoding); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF_CFStringConvertEncodingToNSStringEncoding(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + UInt32 _rv; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "l", + &encoding)) + return NULL; + _rv = CFStringConvertEncodingToNSStringEncoding(encoding); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringConvertNSStringEncodingToEncoding(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringEncoding _rv; + UInt32 encoding; + if (!PyArg_ParseTuple(_args, "l", + &encoding)) + return NULL; + _rv = CFStringConvertNSStringEncodingToEncoding(encoding); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringConvertEncodingToWindowsCodepage(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + UInt32 _rv; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "l", + &encoding)) + return NULL; + _rv = CFStringConvertEncodingToWindowsCodepage(encoding); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringConvertWindowsCodepageToEncoding(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringEncoding _rv; + UInt32 codepage; + if (!PyArg_ParseTuple(_args, "l", + &codepage)) + return NULL; + _rv = CFStringConvertWindowsCodepageToEncoding(codepage); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CF_CFStringConvertEncodingToIANACharSetName(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + CFStringEncoding encoding; + if (!PyArg_ParseTuple(_args, "l", + &encoding)) + return NULL; + _rv = CFStringConvertEncodingToIANACharSetName(encoding); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + +static PyObject *CF___CFStringMakeConstantString(PyObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CFStringRef _rv; + char* cStr; + if (!PyArg_ParseTuple(_args, "s", + &cStr)) + return NULL; + _rv = __CFStringMakeConstantString(cStr); + _res = Py_BuildValue("O&", + CFStringRefObj_New, _rv); + return _res; +} + static PyMethodDef CF_methods[] = { {"CFAllocatorGetTypeID", (PyCFunction)CF_CFAllocatorGetTypeID, 1, "() -> (CFTypeID _rv)"}, @@ -388,6 +2453,84 @@ static PyMethodDef CF_methods[] = { "(CFIndex size, CFOptionFlags hint) -> (CFIndex _rv)"}, {"CFCopyTypeIDDescription", (PyCFunction)CF_CFCopyTypeIDDescription, 1, "(CFTypeID theType) -> (CFStringRef _rv)"}, + {"CFArrayGetTypeID", (PyCFunction)CF_CFArrayGetTypeID, 1, + "() -> (CFTypeID _rv)"}, + {"CFArrayCreateCopy", (PyCFunction)CF_CFArrayCreateCopy, 1, + "(CFArrayRef srcArray) -> (CFArrayRef _rv)"}, + {"CFArrayCreateMutable", (PyCFunction)CF_CFArrayCreateMutable, 1, + "(CFIndex capacity) -> (CFMutableArrayRef _rv)"}, + {"CFArrayCreateMutableCopy", (PyCFunction)CF_CFArrayCreateMutableCopy, 1, + "(CFIndex capacity, CFArrayRef srcArray) -> (CFMutableArrayRef _rv)"}, + {"CFDataGetTypeID", (PyCFunction)CF_CFDataGetTypeID, 1, + "() -> (CFTypeID _rv)"}, + {"CFDataCreate", (PyCFunction)CF_CFDataCreate, 1, + "(Buffer bytes) -> (CFDataRef _rv)"}, + {"CFDataCreateWithBytesNoCopy", (PyCFunction)CF_CFDataCreateWithBytesNoCopy, 1, + "(Buffer bytes) -> (CFDataRef _rv)"}, + {"CFDataCreateCopy", (PyCFunction)CF_CFDataCreateCopy, 1, + "(CFDataRef data) -> (CFDataRef _rv)"}, + {"CFDataCreateMutable", (PyCFunction)CF_CFDataCreateMutable, 1, + "(CFIndex capacity) -> (CFMutableDataRef _rv)"}, + {"CFDataCreateMutableCopy", (PyCFunction)CF_CFDataCreateMutableCopy, 1, + "(CFIndex capacity, CFDataRef data) -> (CFMutableDataRef _rv)"}, + {"CFDictionaryGetTypeID", (PyCFunction)CF_CFDictionaryGetTypeID, 1, + "() -> (CFTypeID _rv)"}, + {"CFDictionaryCreateCopy", (PyCFunction)CF_CFDictionaryCreateCopy, 1, + "(CFDictionaryRef dict) -> (CFDictionaryRef _rv)"}, + {"CFDictionaryCreateMutable", (PyCFunction)CF_CFDictionaryCreateMutable, 1, + "(CFIndex capacity) -> (CFMutableDictionaryRef _rv)"}, + {"CFDictionaryCreateMutableCopy", (PyCFunction)CF_CFDictionaryCreateMutableCopy, 1, + "(CFIndex capacity, CFDictionaryRef dict) -> (CFMutableDictionaryRef _rv)"}, + {"CFStringGetTypeID", (PyCFunction)CF_CFStringGetTypeID, 1, + "() -> (CFTypeID _rv)"}, + {"CFStringCreateWithPascalString", (PyCFunction)CF_CFStringCreateWithPascalString, 1, + "(StringPtr pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, + {"CFStringCreateWithCString", (PyCFunction)CF_CFStringCreateWithCString, 1, + "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, + {"CFStringCreateWithPascalStringNoCopy", (PyCFunction)CF_CFStringCreateWithPascalStringNoCopy, 1, + "(StringPtr pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, + {"CFStringCreateWithCStringNoCopy", (PyCFunction)CF_CFStringCreateWithCStringNoCopy, 1, + "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, + {"CFStringCreateWithSubstring", (PyCFunction)CF_CFStringCreateWithSubstring, 1, + "(CFStringRef str, CFRange range) -> (CFStringRef _rv)"}, + {"CFStringCreateCopy", (PyCFunction)CF_CFStringCreateCopy, 1, + "(CFStringRef theString) -> (CFStringRef _rv)"}, + {"CFStringCreateMutable", (PyCFunction)CF_CFStringCreateMutable, 1, + "(CFIndex maxLength) -> (CFMutableStringRef _rv)"}, + {"CFStringCreateMutableCopy", (PyCFunction)CF_CFStringCreateMutableCopy, 1, + "(CFIndex maxLength, CFStringRef theString) -> (CFMutableStringRef _rv)"}, + {"CFStringCreateWithBytes", (PyCFunction)CF_CFStringCreateWithBytes, 1, + "(Buffer bytes, CFStringEncoding encoding, Boolean isExternalRepresentation) -> (CFStringRef _rv)"}, + {"CFStringCreateFromExternalRepresentation", (PyCFunction)CF_CFStringCreateFromExternalRepresentation, 1, + "(CFDataRef data, CFStringEncoding encoding) -> (CFStringRef _rv)"}, + {"CFStringCreateExternalRepresentation", (PyCFunction)CF_CFStringCreateExternalRepresentation, 1, + "(CFStringRef theString, CFStringEncoding encoding, UInt8 lossByte) -> (CFDataRef _rv)"}, + {"CFStringGetSystemEncoding", (PyCFunction)CF_CFStringGetSystemEncoding, 1, + "() -> (CFStringEncoding _rv)"}, + {"CFStringGetMaximumSizeForEncoding", (PyCFunction)CF_CFStringGetMaximumSizeForEncoding, 1, + "(CFIndex length, CFStringEncoding encoding) -> (CFIndex _rv)"}, + {"CFStringCreateArrayWithFindResults", (PyCFunction)CF_CFStringCreateArrayWithFindResults, 1, + "(CFStringRef theString, CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags compareOptions) -> (CFArrayRef _rv)"}, + {"CFStringCreateByCombiningStrings", (PyCFunction)CF_CFStringCreateByCombiningStrings, 1, + "(CFArrayRef theArray, CFStringRef separatorString) -> (CFStringRef _rv)"}, + {"CFStringCreateArrayBySeparatingStrings", (PyCFunction)CF_CFStringCreateArrayBySeparatingStrings, 1, + "(CFStringRef theString, CFStringRef separatorString) -> (CFArrayRef _rv)"}, + {"CFStringIsEncodingAvailable", (PyCFunction)CF_CFStringIsEncodingAvailable, 1, + "(CFStringEncoding encoding) -> (Boolean _rv)"}, + {"CFStringGetNameOfEncoding", (PyCFunction)CF_CFStringGetNameOfEncoding, 1, + "(CFStringEncoding encoding) -> (CFStringRef _rv)"}, + {"CFStringConvertEncodingToNSStringEncoding", (PyCFunction)CF_CFStringConvertEncodingToNSStringEncoding, 1, + "(CFStringEncoding encoding) -> (UInt32 _rv)"}, + {"CFStringConvertNSStringEncodingToEncoding", (PyCFunction)CF_CFStringConvertNSStringEncodingToEncoding, 1, + "(UInt32 encoding) -> (CFStringEncoding _rv)"}, + {"CFStringConvertEncodingToWindowsCodepage", (PyCFunction)CF_CFStringConvertEncodingToWindowsCodepage, 1, + "(CFStringEncoding encoding) -> (UInt32 _rv)"}, + {"CFStringConvertWindowsCodepageToEncoding", (PyCFunction)CF_CFStringConvertWindowsCodepageToEncoding, 1, + "(UInt32 codepage) -> (CFStringEncoding _rv)"}, + {"CFStringConvertEncodingToIANACharSetName", (PyCFunction)CF_CFStringConvertEncodingToIANACharSetName, 1, + "(CFStringEncoding encoding) -> (CFStringRef _rv)"}, + {"__CFStringMakeConstantString", (PyCFunction)CF___CFStringMakeConstantString, 1, + "(char* cStr) -> (CFStringRef _rv)"}, {NULL, NULL, 0} }; @@ -415,10 +2558,38 @@ void initCF(void) Py_INCREF(&CFTypeRef_Type); if (PyDict_SetItemString(d, "CFTypeRefType", (PyObject *)&CFTypeRef_Type) != 0) Py_FatalError("can't initialize CFTypeRefType"); + CFArrayRef_Type.ob_type = &PyType_Type; + Py_INCREF(&CFArrayRef_Type); + if (PyDict_SetItemString(d, "CFArrayRefType", (PyObject *)&CFArrayRef_Type) != 0) + Py_FatalError("can't initialize CFArrayRefType"); + CFMutableArrayRef_Type.ob_type = &PyType_Type; + Py_INCREF(&CFMutableArrayRef_Type); + if (PyDict_SetItemString(d, "CFMutableArrayRefType", (PyObject *)&CFMutableArrayRef_Type) != 0) + Py_FatalError("can't initialize CFMutableArrayRefType"); + CFDictionaryRef_Type.ob_type = &PyType_Type; + Py_INCREF(&CFDictionaryRef_Type); + if (PyDict_SetItemString(d, "CFDictionaryRefType", (PyObject *)&CFDictionaryRef_Type) != 0) + Py_FatalError("can't initialize CFDictionaryRefType"); + CFMutableDictionaryRef_Type.ob_type = &PyType_Type; + Py_INCREF(&CFMutableDictionaryRef_Type); + if (PyDict_SetItemString(d, "CFMutableDictionaryRefType", (PyObject *)&CFMutableDictionaryRef_Type) != 0) + Py_FatalError("can't initialize CFMutableDictionaryRefType"); + CFDataRef_Type.ob_type = &PyType_Type; + Py_INCREF(&CFDataRef_Type); + if (PyDict_SetItemString(d, "CFDataRefType", (PyObject *)&CFDataRef_Type) != 0) + Py_FatalError("can't initialize CFDataRefType"); + CFMutableDataRef_Type.ob_type = &PyType_Type; + Py_INCREF(&CFMutableDataRef_Type); + if (PyDict_SetItemString(d, "CFMutableDataRefType", (PyObject *)&CFMutableDataRef_Type) != 0) + Py_FatalError("can't initialize CFMutableDataRefType"); CFStringRef_Type.ob_type = &PyType_Type; Py_INCREF(&CFStringRef_Type); if (PyDict_SetItemString(d, "CFStringRefType", (PyObject *)&CFStringRef_Type) != 0) Py_FatalError("can't initialize CFStringRefType"); + CFMutableStringRef_Type.ob_type = &PyType_Type; + Py_INCREF(&CFMutableStringRef_Type); + if (PyDict_SetItemString(d, "CFMutableStringRefType", (PyObject *)&CFMutableStringRef_Type) != 0) + Py_FatalError("can't initialize CFMutableStringRefType"); } /* ========================= End module CF ========================== */ diff --git a/Mac/Modules/cf/cfscan.py b/Mac/Modules/cf/cfscan.py index 776af5b..a4dab2d 100644 --- a/Mac/Modules/cf/cfscan.py +++ b/Mac/Modules/cf/cfscan.py @@ -9,24 +9,30 @@ from bgenlocations import TOOLBOXDIR LONG = "CoreFoundation" SHORT = "cf" -OBJECTS = ("CFTypeRef", "CFStringRef") +OBJECTS = ("CFTypeRef", + "CFArrayRef", "CFMutableArrayRef", + "CFDataRef", "CFMutableDataRef", + "CFDictionaryRef", "CFMutableDictionaryRef", + "CFStringRef", "CFMutableStringRef", + ) +# ADD object typenames here def main(): input = [ "CFBase.h", -### "CFArray.h", + "CFArray.h", ## "CFBag.h", ## "CFBundle.h", ## "CFCharacterSet.h", -### "CFData.h", + "CFData.h", ## "CFDate.h", -### "CFDictionary.h", + "CFDictionary.h", ## "CFNumber.h", ## "CFPlugIn.h", ## "CFPreferences.h", ## "CFPropertyList.h", ## "CFSet.h", -### "CFString.h", + "CFString.h", ## "CFStringEncodingExt.h", ## "CFTimeZone.h", ## "CFURL.h", @@ -65,6 +71,17 @@ class MyScanner(Scanner_OSX): "CFAllocatorReallocate", "CFAllocatorDeallocate", "CFGetAllocator", + # Array functions we skip for now. + "CFArrayGetValueAtIndex", + # Data pointer functions. Skip for now. + "CFDataGetBytePtr", + "CFDataGetMutableBytePtr", + "CFDataGetBytes", # XXXX Should support this one + # String functions + "CFStringGetPascalString", # Use the C-string methods. + "CFStringGetPascalStringPtr", # TBD automatically + "CFStringGetCStringPtr", + "CFStringGetCharactersPtr", ] def makegreylist(self): @@ -72,11 +89,25 @@ class MyScanner(Scanner_OSX): def makeblacklisttypes(self): return [ - "CFAllocatorContext", + "CFComparatorFunction", # Callback function pointer + "CFAllocatorContext", # Not interested in providing our own allocator + "void_ptr_ptr", # Tricky. This is the initializer for arrays... + "void_ptr", # Ditto for various array lookup methods + "CFArrayApplierFunction", # Callback function pointer + "CFDictionaryApplierFunction", # Callback function pointer + "UniChar_ptr", # XXXX To be done + "const_UniChar_ptr", # XXXX To be done + "UniChar", # XXXX To be done + "va_list", # For printf-to-a-cfstring. Use Python. + "const_CFStringEncoding_ptr", # To be done, I guess ] def makerepairinstructions(self): return [ + ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], + [("UcharInBuffer", "*", "*")]), + ([("const_char_ptr", "*", "ReturnMode")], + [("return_stringptr", "*", "*")]), ] if __name__ == "__main__": diff --git a/Mac/Modules/cf/cfsupport.py b/Mac/Modules/cf/cfsupport.py index 5d3787a..e73dd68 100644 --- a/Mac/Modules/cf/cfsupport.py +++ b/Mac/Modules/cf/cfsupport.py @@ -32,6 +32,7 @@ extern int CFTypeRefObj_Convert(PyObject *, CFTypeRef *); extern PyObject *CFStringRefObj_New(CFStringRef); extern int CFStringRefObj_Convert(PyObject *, CFStringRef *); +// ADD declarations #ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE //extern PyObject *_CFTypeRefObj_New(CFTypeRef); //extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *); @@ -40,6 +41,26 @@ extern int CFStringRefObj_Convert(PyObject *, CFStringRef *); //#define CFTypeRefObj_Convert _CFTypeRefObj_Convert #endif +/* +** Parse/generate RGB records +*/ +PyObject *CFRange_New(CFRange *itself) +{ + + return Py_BuildValue("ll", (long)itself->location, (long)itself->length); +} + +CFRange_Convert(PyObject *v, CFRange *p_itself) +{ + long location, length; + + if( !PyArg_ParseTuple(v, "ll", &location, &length) ) + return 0; + p_itself->location = (CFIndex)location; + p_itself->length = (CFIndex)length; + return 1; +} + """ initstuff = initstuff + """ @@ -51,13 +72,31 @@ Boolean = Type("Boolean", "l") CFTypeID = Type("CFTypeID", "l") # XXXX a guess, seems better than OSTypeType. CFHashCode = Type("CFHashCode", "l") CFIndex = Type("CFIndex", "l") +CFRange = OpaqueByValueType('CFRange', 'CFRange') CFOptionFlags = Type("CFOptionFlags", "l") -## CFStringRef = XXXX -CFAllocatorRef = FakeType("(CFAllocatorRef)NULL") +CFStringEncoding = Type("CFStringEncoding", "l") +CFComparisonResult = Type("CFComparisonResult", "l") # a bit dangerous... +char_ptr = stringptr +return_stringptr = Type("char *", "s") # ONLY FOR RETURN VALUES!! + +CFAllocatorRef = FakeType("(CFAllocatorRef)NULL") +CFArrayCallBacks_ptr = FakeType("&kCFTypeArrayCallBacks") +CFDictionaryKeyCallBacks_ptr = FakeType("&kCFTypeDictionaryKeyCallBacks") +CFDictionaryValueCallBacks_ptr = FakeType("&kCFTypeDictionaryValueCallBacks") # The real objects CFTypeRef = OpaqueByValueType("CFTypeRef", "CFTypeRefObj") +CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj") +CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj") +CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj") +CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj") +CFDataRef = OpaqueByValueType("CFDataRef", "CFDataRefObj") +CFMutableDataRef = OpaqueByValueType("CFMutableDataRef", "CFMutableDataRefObj") +CFDictionaryRef = OpaqueByValueType("CFDictionaryRef", "CFDictionaryRefObj") +CFMutableDictionaryRef = OpaqueByValueType("CFMutableDictionaryRef", "CFMutableDictionaryRefObj") CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj") +CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj") +# ADD object type here # Our (opaque) objects @@ -113,6 +152,78 @@ class MyGlobalObjectDefinition(GlobalObjectDefinition): class CFTypeRefObjectDefinition(MyGlobalObjectDefinition): pass +class CFArrayRefObjectDefinition(MyGlobalObjectDefinition): + basechain = "&CFTypeRefObj_chain" + + def outputRepr(self): + Output() + Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) + OutLbrace() + Output("char buf[100];") + Output("""sprintf(buf, "<CFArrayRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("return PyString_FromString(buf);") + OutRbrace() + +class CFMutableArrayRefObjectDefinition(MyGlobalObjectDefinition): + basechain = "&CFArrayRefObj_chain" + + def outputRepr(self): + Output() + Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) + OutLbrace() + Output("char buf[100];") + Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("return PyString_FromString(buf);") + OutRbrace() + +class CFDictionaryRefObjectDefinition(MyGlobalObjectDefinition): + basechain = "&CFTypeRefObj_chain" + + def outputRepr(self): + Output() + Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) + OutLbrace() + Output("char buf[100];") + Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("return PyString_FromString(buf);") + OutRbrace() + +class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition): + basechain = "&CFDictionaryRefObj_chain" + + def outputRepr(self): + Output() + Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) + OutLbrace() + Output("char buf[100];") + Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("return PyString_FromString(buf);") + OutRbrace() + +class CFDataRefObjectDefinition(MyGlobalObjectDefinition): + basechain = "&CFTypeRefObj_chain" + + def outputRepr(self): + Output() + Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) + OutLbrace() + Output("char buf[100];") + Output("""sprintf(buf, "<CFDataRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("return PyString_FromString(buf);") + OutRbrace() + +class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition): + basechain = "&CFDataRefObj_chain" + + def outputRepr(self): + Output() + Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) + OutLbrace() + Output("char buf[100];") + Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("return PyString_FromString(buf);") + OutRbrace() + class CFStringRefObjectDefinition(MyGlobalObjectDefinition): basechain = "&CFTypeRefObj_chain" @@ -121,19 +232,51 @@ class CFStringRefObjectDefinition(MyGlobalObjectDefinition): Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) OutLbrace() Output("char buf[100];") - Output("""sprintf(buf, "<CFString object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("""sprintf(buf, "<CFStringRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") Output("return PyString_FromString(buf);") OutRbrace() + +class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition): + basechain = "&CFStringRefObj_chain" + def outputRepr(self): + Output() + Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) + OutLbrace() + Output("char buf[100];") + Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""") + Output("return PyString_FromString(buf);") + OutRbrace() + + +# ADD object class here + # From here on it's basically all boiler plate... # Create the generator groups and link them module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) CFTypeRef_object = CFTypeRefObjectDefinition('CFTypeRef', 'CFTypeRefObj', 'CFTypeRef') +CFArrayRef_object = CFTypeRefObjectDefinition('CFArrayRef', 'CFArrayRefObj', 'CFArrayRef') +CFMutableArrayRef_object = CFTypeRefObjectDefinition('CFMutableArrayRef', 'CFMutableArrayRefObj', 'CFMutableArrayRef') +CFDictionaryRef_object = CFTypeRefObjectDefinition('CFDictionaryRef', 'CFDictionaryRefObj', 'CFDictionaryRef') +CFMutableDictionaryRef_object = CFTypeRefObjectDefinition('CFMutableDictionaryRef', 'CFMutableDictionaryRefObj', 'CFMutableDictionaryRef') +CFDataRef_object = CFTypeRefObjectDefinition('CFDataRef', 'CFDataRefObj', 'CFDataRef') +CFMutableDataRef_object = CFTypeRefObjectDefinition('CFMutableDataRef', 'CFMutableDataRefObj', 'CFMutableDataRef') CFStringRef_object = CFTypeRefObjectDefinition('CFStringRef', 'CFStringRefObj', 'CFStringRef') +CFMutableStringRef_object = CFTypeRefObjectDefinition('CFMutableStringRef', 'CFMutableStringRefObj', 'CFMutableStringRef') + +# ADD object here module.addobject(CFTypeRef_object) +module.addobject(CFArrayRef_object) +module.addobject(CFMutableArrayRef_object) +module.addobject(CFDictionaryRef_object) +module.addobject(CFMutableDictionaryRef_object) +module.addobject(CFDataRef_object) +module.addobject(CFMutableDataRef_object) module.addobject(CFStringRef_object) +module.addobject(CFMutableStringRef_object) +# ADD addobject call here # Create the generator classes used to populate the lists Function = OSErrFunctionGenerator @@ -142,7 +285,16 @@ Method = OSErrMethodGenerator # Create and populate the lists functions = [] CFTypeRef_methods = [] +CFArrayRef_methods = [] +CFMutableArrayRef_methods = [] +CFDictionaryRef_methods = [] +CFMutableDictionaryRef_methods = [] +CFDataRef_methods = [] +CFMutableDataRef_methods = [] CFStringRef_methods = [] +CFMutableStringRef_methods = [] + +# ADD _methods initializer here execfile(INPUTFILE) @@ -150,7 +302,16 @@ execfile(INPUTFILE) # (in a different wordl the scan program would generate this) for f in functions: module.add(f) for f in CFTypeRef_methods: CFTypeRef_object.add(f) +for f in CFArrayRef_methods: CFArrayRef_object.add(f) +for f in CFMutableArrayRef_methods: CFMutableArrayRef_object.add(f) +for f in CFDictionaryRef_methods: CFDictionaryRef_object.add(f) +for f in CFMutableDictionaryRef_methods: CFMutableDictionaryRef_object.add(f) +for f in CFDataRef_methods: CFDataRef_object.add(f) +for f in CFMutableDataRef_methods: CFMutableDataRef_object.add(f) for f in CFStringRef_methods: CFStringRef_object.add(f) +for f in CFMutableStringRef_methods: CFMutableStringRef_object.add(f) + +# ADD add forloop here # generate output (open the output file as late as possible) SetOutputFileName(OUTPUTFILE) |