/Mac/Modules/cf/_CFmodule.c
http://unladen-swallow.googlecode.com/ · C · 4996 lines · 4442 code · 456 blank · 98 comment · 374 complexity · 0a8f460a90537f888b4ce7c8d25b1b2c MD5 · raw file
Large files are truncated click here to view the full file
- /* =========================== Module _CF =========================== */
- #include "Python.h"
- #include "pymactoolbox.h"
- /* Macro to test whether a weak-loaded CFM function exists */
- #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
- }} while(0)
- #include <CoreServices/CoreServices.h>
- #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
- #define CFTypeRefObj_Convert _CFTypeRefObj_Convert
- extern PyObject *_CFStringRefObj_New(CFStringRef);
- extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
- #define CFStringRefObj_New _CFStringRefObj_New
- #define CFStringRefObj_Convert _CFStringRefObj_Convert
- extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
- extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
- #define CFMutableStringRefObj_New _CFMutableStringRefObj_New
- #define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
- extern PyObject *_CFArrayRefObj_New(CFArrayRef);
- extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
- #define CFArrayRefObj_New _CFArrayRefObj_New
- #define CFArrayRefObj_Convert _CFArrayRefObj_Convert
- extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
- extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
- #define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
- #define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
- extern PyObject *_CFDataRefObj_New(CFDataRef);
- extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
- #define CFDataRefObj_New _CFDataRefObj_New
- #define CFDataRefObj_Convert _CFDataRefObj_Convert
- extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
- extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
- #define CFMutableDataRefObj_New _CFMutableDataRefObj_New
- #define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
- extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
- extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
- #define CFDictionaryRefObj_New _CFDictionaryRefObj_New
- #define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
- extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
- extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
- #define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
- #define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
- extern PyObject *_CFURLRefObj_New(CFURLRef);
- extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
- extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
- #define CFURLRefObj_New _CFURLRefObj_New
- #define CFURLRefObj_Convert _CFURLRefObj_Convert
- #define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
- #endif
- /*
- ** Parse/generate CFRange records
- */
- PyObject *CFRange_New(CFRange *itself)
- {
- return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
- }
- int
- 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;
- }
- /* Optional CFURL argument or None (passed as NULL) */
- int
- OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
- {
- if ( v == Py_None ) {
- p_itself = NULL;
- return 1;
- }
- return CFURLRefObj_Convert(v, p_itself);
- }
- static PyObject *CF_Error;
- /* --------------------- Object type CFTypeRef ---------------------- */
- PyTypeObject CFTypeRef_Type;
- #define CFTypeRefObj_Check(x) ((x)->ob_type == &CFTypeRef_Type || PyObject_TypeCheck((x), &CFTypeRef_Type))
- typedef struct CFTypeRefObject {
- PyObject_HEAD
- CFTypeRef ob_itself;
- void (*ob_freeit)(CFTypeRef ptr);
- } CFTypeRefObject;
- PyObject *CFTypeRefObj_New(CFTypeRef itself)
- {
- CFTypeRefObject *it;
- if (itself == NULL)
- {
- PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
- return NULL;
- }
- it = PyObject_NEW(CFTypeRefObject, &CFTypeRef_Type);
- if (it == NULL) return NULL;
- it->ob_itself = itself;
- it->ob_freeit = CFRelease;
- return (PyObject *)it;
- }
- int CFTypeRefObj_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))
- {
- PyErr_SetString(PyExc_TypeError, "CFTypeRef required");
- return 0;
- }
- *p_itself = ((CFTypeRefObject *)v)->ob_itself;
- return 1;
- }
- static void CFTypeRefObj_dealloc(CFTypeRefObject *self)
- {
- if (self->ob_freeit && self->ob_itself)
- {
- self->ob_freeit((CFTypeRef)self->ob_itself);
- self->ob_itself = NULL;
- }
- self->ob_type->tp_free((PyObject *)self);
- }
- static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFTypeID _rv;
- #ifndef CFGetTypeID
- PyMac_PRECHECK(CFGetTypeID);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFGetTypeID(_self->ob_itself);
- _res = Py_BuildValue("l",
- _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFRetain(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFTypeRef _rv;
- #ifndef CFRetain
- PyMac_PRECHECK(CFRetain);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFRetain(_self->ob_itself);
- _res = Py_BuildValue("O&",
- CFTypeRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFRelease(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- #ifndef CFRelease
- PyMac_PRECHECK(CFRelease);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- CFRelease(_self->ob_itself);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
- }
- static PyObject *CFTypeRefObj_CFGetRetainCount(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFIndex _rv;
- #ifndef CFGetRetainCount
- PyMac_PRECHECK(CFGetRetainCount);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFGetRetainCount(_self->ob_itself);
- _res = Py_BuildValue("l",
- _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFEqual(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- Boolean _rv;
- CFTypeRef cf2;
- #ifndef CFEqual
- PyMac_PRECHECK(CFEqual);
- #endif
- if (!PyArg_ParseTuple(_args, "O&",
- CFTypeRefObj_Convert, &cf2))
- return NULL;
- _rv = CFEqual(_self->ob_itself,
- cf2);
- _res = Py_BuildValue("l",
- _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFHash(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFHashCode _rv;
- #ifndef CFHash
- PyMac_PRECHECK(CFHash);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFHash(_self->ob_itself);
- _res = Py_BuildValue("l",
- _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFStringRef _rv;
- #ifndef CFCopyDescription
- PyMac_PRECHECK(CFCopyDescription);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFCopyDescription(_self->ob_itself);
- _res = Py_BuildValue("O&",
- CFStringRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFPropertyListCreateXMLData(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFDataRef _rv;
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFPropertyListCreateXMLData((CFAllocatorRef)NULL,
- _self->ob_itself);
- _res = Py_BuildValue("O&",
- CFDataRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFPropertyListCreateDeepCopy(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFTypeRef _rv;
- CFOptionFlags mutabilityOption;
- if (!PyArg_ParseTuple(_args, "l",
- &mutabilityOption))
- return NULL;
- _rv = CFPropertyListCreateDeepCopy((CFAllocatorRef)NULL,
- _self->ob_itself,
- mutabilityOption);
- _res = Py_BuildValue("O&",
- CFTypeRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- #ifndef CFShow
- PyMac_PRECHECK(CFShow);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- CFShow(_self->ob_itself);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
- }
- static PyObject *CFTypeRefObj_CFPropertyListCreateFromXMLData(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFTypeRef _rv;
- CFOptionFlags mutabilityOption;
- CFStringRef errorString;
- if (!PyArg_ParseTuple(_args, "l",
- &mutabilityOption))
- return NULL;
- _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
- _self->ob_itself,
- mutabilityOption,
- &errorString);
- if (errorString)
- CFRelease(errorString);
- if (_rv == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
- return NULL;
- }
- _res = Py_BuildValue("O&",
- CFTypeRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFTypeRefObj_toPython(CFTypeRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- _res = PyCF_CF2Python(_self->ob_itself);
- return _res;
- }
- static PyMethodDef CFTypeRefObj_methods[] = {
- {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1,
- PyDoc_STR("() -> (CFTypeID _rv)")},
- {"CFRetain", (PyCFunction)CFTypeRefObj_CFRetain, 1,
- PyDoc_STR("() -> (CFTypeRef _rv)")},
- {"CFRelease", (PyCFunction)CFTypeRefObj_CFRelease, 1,
- PyDoc_STR("() -> None")},
- {"CFGetRetainCount", (PyCFunction)CFTypeRefObj_CFGetRetainCount, 1,
- PyDoc_STR("() -> (CFIndex _rv)")},
- {"CFEqual", (PyCFunction)CFTypeRefObj_CFEqual, 1,
- PyDoc_STR("(CFTypeRef cf2) -> (Boolean _rv)")},
- {"CFHash", (PyCFunction)CFTypeRefObj_CFHash, 1,
- PyDoc_STR("() -> (CFHashCode _rv)")},
- {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1,
- PyDoc_STR("() -> (CFStringRef _rv)")},
- {"CFPropertyListCreateXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateXMLData, 1,
- PyDoc_STR("() -> (CFDataRef _rv)")},
- {"CFPropertyListCreateDeepCopy", (PyCFunction)CFTypeRefObj_CFPropertyListCreateDeepCopy, 1,
- PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRef _rv)")},
- {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1,
- PyDoc_STR("() -> None")},
- {"CFPropertyListCreateFromXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateFromXMLData, 1,
- PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)")},
- {"toPython", (PyCFunction)CFTypeRefObj_toPython, 1,
- PyDoc_STR("() -> (python_object)")},
- {NULL, NULL, 0}
- };
- #define CFTypeRefObj_getsetlist NULL
- static int CFTypeRefObj_compare(CFTypeRefObject *self, CFTypeRefObject *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 * CFTypeRefObj_repr(CFTypeRefObject *self)
- {
- char buf[100];
- sprintf(buf, "<CFTypeRef type-%d object at 0x%8.8x for 0x%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);
- return PyString_FromString(buf);
- }
- static int CFTypeRefObj_hash(CFTypeRefObject *self)
- {
- /* XXXX Or should we use CFHash?? */
- return (int)self->ob_itself;
- }
- static int CFTypeRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
- {
- CFTypeRef itself;
- char *kw[] = {"itself", 0};
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
- {
- ((CFTypeRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- return -1;
- }
- #define CFTypeRefObj_tp_alloc PyType_GenericAlloc
- static PyObject *CFTypeRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
- {
- PyObject *self;
- if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
- ((CFTypeRefObject *)self)->ob_itself = NULL;
- ((CFTypeRefObject *)self)->ob_freeit = CFRelease;
- return self;
- }
- #define CFTypeRefObj_tp_free PyObject_Del
- PyTypeObject CFTypeRef_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "_CF.CFTypeRef", /*tp_name*/
- sizeof(CFTypeRefObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor) CFTypeRefObj_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)0, /*tp_setattr*/
- (cmpfunc) CFTypeRefObj_compare, /*tp_compare*/
- (reprfunc) CFTypeRefObj_repr, /*tp_repr*/
- (PyNumberMethods *)0, /* tp_as_number */
- (PySequenceMethods *)0, /* tp_as_sequence */
- (PyMappingMethods *)0, /* tp_as_mapping */
- (hashfunc) CFTypeRefObj_hash, /*tp_hash*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- PyObject_GenericSetAttr, /*tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- CFTypeRefObj_methods, /* tp_methods */
- 0, /*tp_members*/
- CFTypeRefObj_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- CFTypeRefObj_tp_init, /* tp_init */
- CFTypeRefObj_tp_alloc, /* tp_alloc */
- CFTypeRefObj_tp_new, /* tp_new */
- CFTypeRefObj_tp_free, /* tp_free */
- };
- /* ------------------- End object type CFTypeRef -------------------- */
- /* --------------------- Object type CFArrayRef --------------------- */
- PyTypeObject CFArrayRef_Type;
- #define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type || PyObject_TypeCheck((x), &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)
- {
- PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
- return NULL;
- }
- it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type);
- if (it == NULL) return NULL;
- /* XXXX Should we tp_init or tp_new our basetype? */
- it->ob_itself = itself;
- it->ob_freeit = CFRelease;
- return (PyObject *)it;
- }
- int 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);
- self->ob_itself = NULL;
- }
- CFTypeRef_Type.tp_dealloc((PyObject *)self);
- }
- static PyObject *CFArrayRefObj_CFArrayCreateCopy(CFArrayRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFArrayRef _rv;
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFArrayCreateCopy((CFAllocatorRef)NULL,
- _self->ob_itself);
- _res = Py_BuildValue("O&",
- CFArrayRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFIndex _rv;
- #ifndef CFArrayGetCount
- PyMac_PRECHECK(CFArrayGetCount);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFArrayGetCount(_self->ob_itself);
- _res = Py_BuildValue("l",
- _rv);
- return _res;
- }
- static PyObject *CFArrayRefObj_CFStringCreateByCombiningStrings(CFArrayRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFStringRef _rv;
- CFStringRef separatorString;
- if (!PyArg_ParseTuple(_args, "O&",
- CFStringRefObj_Convert, &separatorString))
- return NULL;
- _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL,
- _self->ob_itself,
- separatorString);
- _res = Py_BuildValue("O&",
- CFStringRefObj_New, _rv);
- return _res;
- }
- static PyMethodDef CFArrayRefObj_methods[] = {
- {"CFArrayCreateCopy", (PyCFunction)CFArrayRefObj_CFArrayCreateCopy, 1,
- PyDoc_STR("() -> (CFArrayRef _rv)")},
- {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1,
- PyDoc_STR("() -> (CFIndex _rv)")},
- {"CFStringCreateByCombiningStrings", (PyCFunction)CFArrayRefObj_CFStringCreateByCombiningStrings, 1,
- PyDoc_STR("(CFStringRef separatorString) -> (CFStringRef _rv)")},
- {NULL, NULL, 0}
- };
- #define CFArrayRefObj_getsetlist 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, "<CFArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
- return PyString_FromString(buf);
- }
- static int CFArrayRefObj_hash(CFArrayRefObject *self)
- {
- /* XXXX Or should we use CFHash?? */
- return (int)self->ob_itself;
- }
- static int CFArrayRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
- {
- CFArrayRef itself;
- char *kw[] = {"itself", 0};
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFArrayRefObj_Convert, &itself))
- {
- ((CFArrayRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- /* Any CFTypeRef descendent is allowed as initializer too */
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
- {
- ((CFArrayRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- return -1;
- }
- #define CFArrayRefObj_tp_alloc PyType_GenericAlloc
- static PyObject *CFArrayRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
- {
- PyObject *self;
- if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
- ((CFArrayRefObject *)self)->ob_itself = NULL;
- ((CFArrayRefObject *)self)->ob_freeit = CFRelease;
- return self;
- }
- #define CFArrayRefObj_tp_free PyObject_Del
- PyTypeObject CFArrayRef_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "_CF.CFArrayRef", /*tp_name*/
- sizeof(CFArrayRefObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)0, /*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*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- PyObject_GenericSetAttr, /*tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- CFArrayRefObj_methods, /* tp_methods */
- 0, /*tp_members*/
- CFArrayRefObj_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- CFArrayRefObj_tp_init, /* tp_init */
- CFArrayRefObj_tp_alloc, /* tp_alloc */
- CFArrayRefObj_tp_new, /* tp_new */
- CFArrayRefObj_tp_free, /* tp_free */
- };
- /* ------------------- End object type CFArrayRef ------------------- */
- /* ----------------- Object type CFMutableArrayRef ------------------ */
- PyTypeObject CFMutableArrayRef_Type;
- #define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type || PyObject_TypeCheck((x), &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)
- {
- PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
- return NULL;
- }
- it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type);
- if (it == NULL) return NULL;
- /* XXXX Should we tp_init or tp_new our basetype? */
- it->ob_itself = itself;
- it->ob_freeit = CFRelease;
- return (PyObject *)it;
- }
- int 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);
- self->ob_itself = NULL;
- }
- CFArrayRef_Type.tp_dealloc((PyObject *)self);
- }
- static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFIndex idx;
- #ifndef CFArrayRemoveValueAtIndex
- PyMac_PRECHECK(CFArrayRemoveValueAtIndex);
- #endif
- 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;
- #ifndef CFArrayRemoveAllValues
- PyMac_PRECHECK(CFArrayRemoveAllValues);
- #endif
- 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;
- #ifndef CFArrayExchangeValuesAtIndices
- PyMac_PRECHECK(CFArrayExchangeValuesAtIndices);
- #endif
- 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 PyObject *CFMutableArrayRefObj_CFArrayAppendArray(CFMutableArrayRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFArrayRef otherArray;
- CFRange otherRange;
- #ifndef CFArrayAppendArray
- PyMac_PRECHECK(CFArrayAppendArray);
- #endif
- if (!PyArg_ParseTuple(_args, "O&O&",
- CFArrayRefObj_Convert, &otherArray,
- CFRange_Convert, &otherRange))
- return NULL;
- CFArrayAppendArray(_self->ob_itself,
- otherArray,
- otherRange);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
- }
- static PyMethodDef CFMutableArrayRefObj_methods[] = {
- {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1,
- PyDoc_STR("(CFIndex idx) -> None")},
- {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1,
- PyDoc_STR("() -> None")},
- {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1,
- PyDoc_STR("(CFIndex idx1, CFIndex idx2) -> None")},
- {"CFArrayAppendArray", (PyCFunction)CFMutableArrayRefObj_CFArrayAppendArray, 1,
- PyDoc_STR("(CFArrayRef otherArray, CFRange otherRange) -> None")},
- {NULL, NULL, 0}
- };
- #define CFMutableArrayRefObj_getsetlist 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, "<CFMutableArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
- return PyString_FromString(buf);
- }
- static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self)
- {
- /* XXXX Or should we use CFHash?? */
- return (int)self->ob_itself;
- }
- static int CFMutableArrayRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
- {
- CFMutableArrayRef itself;
- char *kw[] = {"itself", 0};
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFMutableArrayRefObj_Convert, &itself))
- {
- ((CFMutableArrayRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- /* Any CFTypeRef descendent is allowed as initializer too */
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
- {
- ((CFMutableArrayRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- return -1;
- }
- #define CFMutableArrayRefObj_tp_alloc PyType_GenericAlloc
- static PyObject *CFMutableArrayRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
- {
- PyObject *self;
- if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
- ((CFMutableArrayRefObject *)self)->ob_itself = NULL;
- ((CFMutableArrayRefObject *)self)->ob_freeit = CFRelease;
- return self;
- }
- #define CFMutableArrayRefObj_tp_free PyObject_Del
- PyTypeObject CFMutableArrayRef_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "_CF.CFMutableArrayRef", /*tp_name*/
- sizeof(CFMutableArrayRefObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)0, /*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*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- PyObject_GenericSetAttr, /*tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- CFMutableArrayRefObj_methods, /* tp_methods */
- 0, /*tp_members*/
- CFMutableArrayRefObj_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- CFMutableArrayRefObj_tp_init, /* tp_init */
- CFMutableArrayRefObj_tp_alloc, /* tp_alloc */
- CFMutableArrayRefObj_tp_new, /* tp_new */
- CFMutableArrayRefObj_tp_free, /* tp_free */
- };
- /* --------------- End object type CFMutableArrayRef ---------------- */
- /* ------------------ Object type CFDictionaryRef ------------------- */
- PyTypeObject CFDictionaryRef_Type;
- #define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type || PyObject_TypeCheck((x), &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)
- {
- PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
- return NULL;
- }
- it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type);
- if (it == NULL) return NULL;
- /* XXXX Should we tp_init or tp_new our basetype? */
- it->ob_itself = itself;
- it->ob_freeit = CFRelease;
- return (PyObject *)it;
- }
- int 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);
- self->ob_itself = NULL;
- }
- CFTypeRef_Type.tp_dealloc((PyObject *)self);
- }
- static PyObject *CFDictionaryRefObj_CFDictionaryCreateCopy(CFDictionaryRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFDictionaryRef _rv;
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL,
- _self->ob_itself);
- _res = Py_BuildValue("O&",
- CFDictionaryRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFIndex _rv;
- #ifndef CFDictionaryGetCount
- PyMac_PRECHECK(CFDictionaryGetCount);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFDictionaryGetCount(_self->ob_itself);
- _res = Py_BuildValue("l",
- _rv);
- return _res;
- }
- static PyMethodDef CFDictionaryRefObj_methods[] = {
- {"CFDictionaryCreateCopy", (PyCFunction)CFDictionaryRefObj_CFDictionaryCreateCopy, 1,
- PyDoc_STR("() -> (CFDictionaryRef _rv)")},
- {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1,
- PyDoc_STR("() -> (CFIndex _rv)")},
- {NULL, NULL, 0}
- };
- #define CFDictionaryRefObj_getsetlist 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, "<CFDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
- return PyString_FromString(buf);
- }
- static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self)
- {
- /* XXXX Or should we use CFHash?? */
- return (int)self->ob_itself;
- }
- static int CFDictionaryRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
- {
- CFDictionaryRef itself;
- char *kw[] = {"itself", 0};
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFDictionaryRefObj_Convert, &itself))
- {
- ((CFDictionaryRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- /* Any CFTypeRef descendent is allowed as initializer too */
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
- {
- ((CFDictionaryRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- return -1;
- }
- #define CFDictionaryRefObj_tp_alloc PyType_GenericAlloc
- static PyObject *CFDictionaryRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
- {
- PyObject *self;
- if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
- ((CFDictionaryRefObject *)self)->ob_itself = NULL;
- ((CFDictionaryRefObject *)self)->ob_freeit = CFRelease;
- return self;
- }
- #define CFDictionaryRefObj_tp_free PyObject_Del
- PyTypeObject CFDictionaryRef_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "_CF.CFDictionaryRef", /*tp_name*/
- sizeof(CFDictionaryRefObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)0, /*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*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- PyObject_GenericSetAttr, /*tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- CFDictionaryRefObj_methods, /* tp_methods */
- 0, /*tp_members*/
- CFDictionaryRefObj_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- CFDictionaryRefObj_tp_init, /* tp_init */
- CFDictionaryRefObj_tp_alloc, /* tp_alloc */
- CFDictionaryRefObj_tp_new, /* tp_new */
- CFDictionaryRefObj_tp_free, /* tp_free */
- };
- /* ---------------- End object type CFDictionaryRef ----------------- */
- /* --------------- Object type CFMutableDictionaryRef --------------- */
- PyTypeObject CFMutableDictionaryRef_Type;
- #define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type || PyObject_TypeCheck((x), &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)
- {
- PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
- return NULL;
- }
- it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type);
- if (it == NULL) return NULL;
- /* XXXX Should we tp_init or tp_new our basetype? */
- it->ob_itself = itself;
- it->ob_freeit = CFRelease;
- return (PyObject *)it;
- }
- int 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);
- self->ob_itself = NULL;
- }
- CFDictionaryRef_Type.tp_dealloc((PyObject *)self);
- }
- static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- #ifndef CFDictionaryRemoveAllValues
- PyMac_PRECHECK(CFDictionaryRemoveAllValues);
- #endif
- 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,
- PyDoc_STR("() -> None")},
- {NULL, NULL, 0}
- };
- #define CFMutableDictionaryRefObj_getsetlist 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, "<CFMutableDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
- return PyString_FromString(buf);
- }
- static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self)
- {
- /* XXXX Or should we use CFHash?? */
- return (int)self->ob_itself;
- }
- static int CFMutableDictionaryRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
- {
- CFMutableDictionaryRef itself;
- char *kw[] = {"itself", 0};
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFMutableDictionaryRefObj_Convert, &itself))
- {
- ((CFMutableDictionaryRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- /* Any CFTypeRef descendent is allowed as initializer too */
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
- {
- ((CFMutableDictionaryRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- return -1;
- }
- #define CFMutableDictionaryRefObj_tp_alloc PyType_GenericAlloc
- static PyObject *CFMutableDictionaryRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
- {
- PyObject *self;
- if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
- ((CFMutableDictionaryRefObject *)self)->ob_itself = NULL;
- ((CFMutableDictionaryRefObject *)self)->ob_freeit = CFRelease;
- return self;
- }
- #define CFMutableDictionaryRefObj_tp_free PyObject_Del
- PyTypeObject CFMutableDictionaryRef_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "_CF.CFMutableDictionaryRef", /*tp_name*/
- sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)0, /*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*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- PyObject_GenericSetAttr, /*tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- CFMutableDictionaryRefObj_methods, /* tp_methods */
- 0, /*tp_members*/
- CFMutableDictionaryRefObj_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- CFMutableDictionaryRefObj_tp_init, /* tp_init */
- CFMutableDictionaryRefObj_tp_alloc, /* tp_alloc */
- CFMutableDictionaryRefObj_tp_new, /* tp_new */
- CFMutableDictionaryRefObj_tp_free, /* tp_free */
- };
- /* ------------- End object type CFMutableDictionaryRef ------------- */
- /* --------------------- Object type CFDataRef ---------------------- */
- PyTypeObject CFDataRef_Type;
- #define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type || PyObject_TypeCheck((x), &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)
- {
- PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
- return NULL;
- }
- it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type);
- if (it == NULL) return NULL;
- /* XXXX Should we tp_init or tp_new our basetype? */
- it->ob_itself = itself;
- it->ob_freeit = CFRelease;
- return (PyObject *)it;
- }
- int CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself)
- {
- if (v == Py_None) { *p_itself = NULL; return 1; }
- if (PyString_Check(v)) {
- char *cStr;
- Py_ssize_t cLen;
- if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
- *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
- return 1;
- }
- 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);
- self->ob_itself = NULL;
- }
- CFTypeRef_Type.tp_dealloc((PyObject *)self);
- }
- static PyObject *CFDataRefObj_CFDataCreateCopy(CFDataRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFDataRef _rv;
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFDataCreateCopy((CFAllocatorRef)NULL,
- _self->ob_itself);
- _res = Py_BuildValue("O&",
- CFDataRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFIndex _rv;
- #ifndef CFDataGetLength
- PyMac_PRECHECK(CFDataGetLength);
- #endif
- if (!PyArg_ParseTuple(_args, ""))
- return NULL;
- _rv = CFDataGetLength(_self->ob_itself);
- _res = Py_BuildValue("l",
- _rv);
- return _res;
- }
- static PyObject *CFDataRefObj_CFStringCreateFromExternalRepresentation(CFDataRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFStringRef _rv;
- CFStringEncoding encoding;
- if (!PyArg_ParseTuple(_args, "l",
- &encoding))
- return NULL;
- _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL,
- _self->ob_itself,
- encoding);
- _res = Py_BuildValue("O&",
- CFStringRefObj_New, _rv);
- return _res;
- }
- static PyObject *CFDataRefObj_CFDataGetData(CFDataRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- int size = CFDataGetLength(_self->ob_itself);
- char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
- _res = (PyObject *)PyString_FromStringAndSize(data, size);
- return _res;
- }
- static PyMethodDef CFDataRefObj_methods[] = {
- {"CFDataCreateCopy", (PyCFunction)CFDataRefObj_CFDataCreateCopy, 1,
- PyDoc_STR("() -> (CFDataRef _rv)")},
- {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1,
- PyDoc_STR("() -> (CFIndex _rv)")},
- {"CFStringCreateFromExternalRepresentation", (PyCFunction)CFDataRefObj_CFStringCreateFromExternalRepresentation, 1,
- PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
- {"CFDataGetData", (PyCFunction)CFDataRefObj_CFDataGetData, 1,
- PyDoc_STR("() -> (string _rv)")},
- {NULL, NULL, 0}
- };
- #define CFDataRefObj_getsetlist 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, "<CFDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
- return PyString_FromString(buf);
- }
- static int CFDataRefObj_hash(CFDataRefObject *self)
- {
- /* XXXX Or should we use CFHash?? */
- return (int)self->ob_itself;
- }
- static int CFDataRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
- {
- CFDataRef itself;
- char *kw[] = {"itself", 0};
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFDataRefObj_Convert, &itself))
- {
- ((CFDataRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- /* Any CFTypeRef descendent is allowed as initializer too */
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
- {
- ((CFDataRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- return -1;
- }
- #define CFDataRefObj_tp_alloc PyType_GenericAlloc
- static PyObject *CFDataRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
- {
- PyObject *self;
- if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
- ((CFDataRefObject *)self)->ob_itself = NULL;
- ((CFDataRefObject *)self)->ob_freeit = CFRelease;
- return self;
- }
- #define CFDataRefObj_tp_free PyObject_Del
- PyTypeObject CFDataRef_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "_CF.CFDataRef", /*tp_name*/
- sizeof(CFDataRefObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)0, /*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*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- PyObject_GenericSetAttr, /*tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- CFDataRefObj_methods, /* tp_methods */
- 0, /*tp_members*/
- CFDataRefObj_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- CFDataRefObj_tp_init, /* tp_init */
- CFDataRefObj_tp_alloc, /* tp_alloc */
- CFDataRefObj_tp_new, /* tp_new */
- CFDataRefObj_tp_free, /* tp_free */
- };
- /* ------------------- End object type CFDataRef -------------------- */
- /* ------------------ Object type CFMutableDataRef ------------------ */
- PyTypeObject CFMutableDataRef_Type;
- #define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type || PyObject_TypeCheck((x), &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)
- {
- PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
- return NULL;
- }
- it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type);
- if (it == NULL) return NULL;
- /* XXXX Should we tp_init or tp_new our basetype? */
- it->ob_itself = itself;
- it->ob_freeit = CFRelease;
- return (PyObject *)it;
- }
- int 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);
- self->ob_itself = NULL;
- }
- CFDataRef_Type.tp_dealloc((PyObject *)self);
- }
- static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFIndex length;
- #ifndef CFDataSetLength
- PyMac_PRECHECK(CFDataSetLength);
- #endif
- 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;
- #ifndef CFDataIncreaseLength
- PyMac_PRECHECK(CFDataIncreaseLength);
- #endif
- 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__;
- #ifndef CFDataAppendBytes
- PyMac_PRECHECK(CFDataAppendBytes);
- #endif
- 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;
- 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__;
- #ifndef CFDataReplaceBytes
- PyMac_PRECHECK(CFDataReplaceBytes);
- #endif
- 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;
- return _res;
- }
- static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
- CFRange range;
- #ifndef CFDataDeleteBytes
- PyMac_PRECHECK(CFDataDeleteBytes);
- #endif
- 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,
- PyDoc_STR("(CFIndex length) -> None")},
- {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1,
- PyDoc_STR("(CFIndex extraLength) -> None")},
- {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1,
- PyDoc_STR("(Buffer bytes) -> None")},
- {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1,
- PyDoc_STR("(CFRange range, Buffer newBytes) -> None")},
- {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1,
- PyDoc_STR("(CFRange range) -> None")},
- {NULL, NULL, 0}
- };
- #define CFMutableDataRefObj_getsetlist 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, "<CFMutableDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
- return PyString_FromString(buf);
- }
- static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self)
- {
- /* XXXX Or should we use CFHash?? */
- return (int)self->ob_itself;
- }
- static int CFMutableDataRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
- {
- CFMutableDataRef itself;
- char *kw[] = {"itself", 0};
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFMutableDataRefObj_Convert, &itself))
- {
- ((CFMutableDataRefObject *)_self)->ob_itself = itself;
- return 0;
- }
- /* Any CFTypeRef descendent is allowed as initializer too */
- if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeR…