/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

  1. /* =========================== Module _CF =========================== */
  2. #include "Python.h"
  3. #include "pymactoolbox.h"
  4. /* Macro to test whether a weak-loaded CFM function exists */
  5. #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
  6. PyErr_SetString(PyExc_NotImplementedError, \
  7. "Not available in this shared library/OS version"); \
  8. return NULL; \
  9. }} while(0)
  10. #include <CoreServices/CoreServices.h>
  11. #include "pycfbridge.h"
  12. #ifdef USE_TOOLBOX_OBJECT_GLUE
  13. extern PyObject *_CFObj_New(CFTypeRef);
  14. extern int _CFObj_Convert(PyObject *, CFTypeRef *);
  15. #define CFObj_New _CFObj_New
  16. #define CFObj_Convert _CFObj_Convert
  17. extern PyObject *_CFTypeRefObj_New(CFTypeRef);
  18. extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
  19. #define CFTypeRefObj_New _CFTypeRefObj_New
  20. #define CFTypeRefObj_Convert _CFTypeRefObj_Convert
  21. extern PyObject *_CFStringRefObj_New(CFStringRef);
  22. extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
  23. #define CFStringRefObj_New _CFStringRefObj_New
  24. #define CFStringRefObj_Convert _CFStringRefObj_Convert
  25. extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
  26. extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
  27. #define CFMutableStringRefObj_New _CFMutableStringRefObj_New
  28. #define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
  29. extern PyObject *_CFArrayRefObj_New(CFArrayRef);
  30. extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
  31. #define CFArrayRefObj_New _CFArrayRefObj_New
  32. #define CFArrayRefObj_Convert _CFArrayRefObj_Convert
  33. extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
  34. extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
  35. #define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
  36. #define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
  37. extern PyObject *_CFDataRefObj_New(CFDataRef);
  38. extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
  39. #define CFDataRefObj_New _CFDataRefObj_New
  40. #define CFDataRefObj_Convert _CFDataRefObj_Convert
  41. extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
  42. extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
  43. #define CFMutableDataRefObj_New _CFMutableDataRefObj_New
  44. #define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
  45. extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
  46. extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
  47. #define CFDictionaryRefObj_New _CFDictionaryRefObj_New
  48. #define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
  49. extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
  50. extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
  51. #define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
  52. #define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
  53. extern PyObject *_CFURLRefObj_New(CFURLRef);
  54. extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
  55. extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
  56. #define CFURLRefObj_New _CFURLRefObj_New
  57. #define CFURLRefObj_Convert _CFURLRefObj_Convert
  58. #define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
  59. #endif
  60. /*
  61. ** Parse/generate CFRange records
  62. */
  63. PyObject *CFRange_New(CFRange *itself)
  64. {
  65. return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
  66. }
  67. int
  68. CFRange_Convert(PyObject *v, CFRange *p_itself)
  69. {
  70. long location, length;
  71. if( !PyArg_ParseTuple(v, "ll", &location, &length) )
  72. return 0;
  73. p_itself->location = (CFIndex)location;
  74. p_itself->length = (CFIndex)length;
  75. return 1;
  76. }
  77. /* Optional CFURL argument or None (passed as NULL) */
  78. int
  79. OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
  80. {
  81. if ( v == Py_None ) {
  82. p_itself = NULL;
  83. return 1;
  84. }
  85. return CFURLRefObj_Convert(v, p_itself);
  86. }
  87. static PyObject *CF_Error;
  88. /* --------------------- Object type CFTypeRef ---------------------- */
  89. PyTypeObject CFTypeRef_Type;
  90. #define CFTypeRefObj_Check(x) ((x)->ob_type == &CFTypeRef_Type || PyObject_TypeCheck((x), &CFTypeRef_Type))
  91. typedef struct CFTypeRefObject {
  92. PyObject_HEAD
  93. CFTypeRef ob_itself;
  94. void (*ob_freeit)(CFTypeRef ptr);
  95. } CFTypeRefObject;
  96. PyObject *CFTypeRefObj_New(CFTypeRef itself)
  97. {
  98. CFTypeRefObject *it;
  99. if (itself == NULL)
  100. {
  101. PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
  102. return NULL;
  103. }
  104. it = PyObject_NEW(CFTypeRefObject, &CFTypeRef_Type);
  105. if (it == NULL) return NULL;
  106. it->ob_itself = itself;
  107. it->ob_freeit = CFRelease;
  108. return (PyObject *)it;
  109. }
  110. int CFTypeRefObj_Convert(PyObject *v, CFTypeRef *p_itself)
  111. {
  112. if (v == Py_None) { *p_itself = NULL; return 1; }
  113. /* Check for other CF objects here */
  114. if (!CFTypeRefObj_Check(v))
  115. {
  116. PyErr_SetString(PyExc_TypeError, "CFTypeRef required");
  117. return 0;
  118. }
  119. *p_itself = ((CFTypeRefObject *)v)->ob_itself;
  120. return 1;
  121. }
  122. static void CFTypeRefObj_dealloc(CFTypeRefObject *self)
  123. {
  124. if (self->ob_freeit && self->ob_itself)
  125. {
  126. self->ob_freeit((CFTypeRef)self->ob_itself);
  127. self->ob_itself = NULL;
  128. }
  129. self->ob_type->tp_free((PyObject *)self);
  130. }
  131. static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args)
  132. {
  133. PyObject *_res = NULL;
  134. CFTypeID _rv;
  135. #ifndef CFGetTypeID
  136. PyMac_PRECHECK(CFGetTypeID);
  137. #endif
  138. if (!PyArg_ParseTuple(_args, ""))
  139. return NULL;
  140. _rv = CFGetTypeID(_self->ob_itself);
  141. _res = Py_BuildValue("l",
  142. _rv);
  143. return _res;
  144. }
  145. static PyObject *CFTypeRefObj_CFRetain(CFTypeRefObject *_self, PyObject *_args)
  146. {
  147. PyObject *_res = NULL;
  148. CFTypeRef _rv;
  149. #ifndef CFRetain
  150. PyMac_PRECHECK(CFRetain);
  151. #endif
  152. if (!PyArg_ParseTuple(_args, ""))
  153. return NULL;
  154. _rv = CFRetain(_self->ob_itself);
  155. _res = Py_BuildValue("O&",
  156. CFTypeRefObj_New, _rv);
  157. return _res;
  158. }
  159. static PyObject *CFTypeRefObj_CFRelease(CFTypeRefObject *_self, PyObject *_args)
  160. {
  161. PyObject *_res = NULL;
  162. #ifndef CFRelease
  163. PyMac_PRECHECK(CFRelease);
  164. #endif
  165. if (!PyArg_ParseTuple(_args, ""))
  166. return NULL;
  167. CFRelease(_self->ob_itself);
  168. Py_INCREF(Py_None);
  169. _res = Py_None;
  170. return _res;
  171. }
  172. static PyObject *CFTypeRefObj_CFGetRetainCount(CFTypeRefObject *_self, PyObject *_args)
  173. {
  174. PyObject *_res = NULL;
  175. CFIndex _rv;
  176. #ifndef CFGetRetainCount
  177. PyMac_PRECHECK(CFGetRetainCount);
  178. #endif
  179. if (!PyArg_ParseTuple(_args, ""))
  180. return NULL;
  181. _rv = CFGetRetainCount(_self->ob_itself);
  182. _res = Py_BuildValue("l",
  183. _rv);
  184. return _res;
  185. }
  186. static PyObject *CFTypeRefObj_CFEqual(CFTypeRefObject *_self, PyObject *_args)
  187. {
  188. PyObject *_res = NULL;
  189. Boolean _rv;
  190. CFTypeRef cf2;
  191. #ifndef CFEqual
  192. PyMac_PRECHECK(CFEqual);
  193. #endif
  194. if (!PyArg_ParseTuple(_args, "O&",
  195. CFTypeRefObj_Convert, &cf2))
  196. return NULL;
  197. _rv = CFEqual(_self->ob_itself,
  198. cf2);
  199. _res = Py_BuildValue("l",
  200. _rv);
  201. return _res;
  202. }
  203. static PyObject *CFTypeRefObj_CFHash(CFTypeRefObject *_self, PyObject *_args)
  204. {
  205. PyObject *_res = NULL;
  206. CFHashCode _rv;
  207. #ifndef CFHash
  208. PyMac_PRECHECK(CFHash);
  209. #endif
  210. if (!PyArg_ParseTuple(_args, ""))
  211. return NULL;
  212. _rv = CFHash(_self->ob_itself);
  213. _res = Py_BuildValue("l",
  214. _rv);
  215. return _res;
  216. }
  217. static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject *_args)
  218. {
  219. PyObject *_res = NULL;
  220. CFStringRef _rv;
  221. #ifndef CFCopyDescription
  222. PyMac_PRECHECK(CFCopyDescription);
  223. #endif
  224. if (!PyArg_ParseTuple(_args, ""))
  225. return NULL;
  226. _rv = CFCopyDescription(_self->ob_itself);
  227. _res = Py_BuildValue("O&",
  228. CFStringRefObj_New, _rv);
  229. return _res;
  230. }
  231. static PyObject *CFTypeRefObj_CFPropertyListCreateXMLData(CFTypeRefObject *_self, PyObject *_args)
  232. {
  233. PyObject *_res = NULL;
  234. CFDataRef _rv;
  235. if (!PyArg_ParseTuple(_args, ""))
  236. return NULL;
  237. _rv = CFPropertyListCreateXMLData((CFAllocatorRef)NULL,
  238. _self->ob_itself);
  239. _res = Py_BuildValue("O&",
  240. CFDataRefObj_New, _rv);
  241. return _res;
  242. }
  243. static PyObject *CFTypeRefObj_CFPropertyListCreateDeepCopy(CFTypeRefObject *_self, PyObject *_args)
  244. {
  245. PyObject *_res = NULL;
  246. CFTypeRef _rv;
  247. CFOptionFlags mutabilityOption;
  248. if (!PyArg_ParseTuple(_args, "l",
  249. &mutabilityOption))
  250. return NULL;
  251. _rv = CFPropertyListCreateDeepCopy((CFAllocatorRef)NULL,
  252. _self->ob_itself,
  253. mutabilityOption);
  254. _res = Py_BuildValue("O&",
  255. CFTypeRefObj_New, _rv);
  256. return _res;
  257. }
  258. static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args)
  259. {
  260. PyObject *_res = NULL;
  261. #ifndef CFShow
  262. PyMac_PRECHECK(CFShow);
  263. #endif
  264. if (!PyArg_ParseTuple(_args, ""))
  265. return NULL;
  266. CFShow(_self->ob_itself);
  267. Py_INCREF(Py_None);
  268. _res = Py_None;
  269. return _res;
  270. }
  271. static PyObject *CFTypeRefObj_CFPropertyListCreateFromXMLData(CFTypeRefObject *_self, PyObject *_args)
  272. {
  273. PyObject *_res = NULL;
  274. CFTypeRef _rv;
  275. CFOptionFlags mutabilityOption;
  276. CFStringRef errorString;
  277. if (!PyArg_ParseTuple(_args, "l",
  278. &mutabilityOption))
  279. return NULL;
  280. _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
  281. _self->ob_itself,
  282. mutabilityOption,
  283. &errorString);
  284. if (errorString)
  285. CFRelease(errorString);
  286. if (_rv == NULL) {
  287. PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
  288. return NULL;
  289. }
  290. _res = Py_BuildValue("O&",
  291. CFTypeRefObj_New, _rv);
  292. return _res;
  293. }
  294. static PyObject *CFTypeRefObj_toPython(CFTypeRefObject *_self, PyObject *_args)
  295. {
  296. PyObject *_res = NULL;
  297. _res = PyCF_CF2Python(_self->ob_itself);
  298. return _res;
  299. }
  300. static PyMethodDef CFTypeRefObj_methods[] = {
  301. {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1,
  302. PyDoc_STR("() -> (CFTypeID _rv)")},
  303. {"CFRetain", (PyCFunction)CFTypeRefObj_CFRetain, 1,
  304. PyDoc_STR("() -> (CFTypeRef _rv)")},
  305. {"CFRelease", (PyCFunction)CFTypeRefObj_CFRelease, 1,
  306. PyDoc_STR("() -> None")},
  307. {"CFGetRetainCount", (PyCFunction)CFTypeRefObj_CFGetRetainCount, 1,
  308. PyDoc_STR("() -> (CFIndex _rv)")},
  309. {"CFEqual", (PyCFunction)CFTypeRefObj_CFEqual, 1,
  310. PyDoc_STR("(CFTypeRef cf2) -> (Boolean _rv)")},
  311. {"CFHash", (PyCFunction)CFTypeRefObj_CFHash, 1,
  312. PyDoc_STR("() -> (CFHashCode _rv)")},
  313. {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1,
  314. PyDoc_STR("() -> (CFStringRef _rv)")},
  315. {"CFPropertyListCreateXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateXMLData, 1,
  316. PyDoc_STR("() -> (CFDataRef _rv)")},
  317. {"CFPropertyListCreateDeepCopy", (PyCFunction)CFTypeRefObj_CFPropertyListCreateDeepCopy, 1,
  318. PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRef _rv)")},
  319. {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1,
  320. PyDoc_STR("() -> None")},
  321. {"CFPropertyListCreateFromXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateFromXMLData, 1,
  322. PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)")},
  323. {"toPython", (PyCFunction)CFTypeRefObj_toPython, 1,
  324. PyDoc_STR("() -> (python_object)")},
  325. {NULL, NULL, 0}
  326. };
  327. #define CFTypeRefObj_getsetlist NULL
  328. static int CFTypeRefObj_compare(CFTypeRefObject *self, CFTypeRefObject *other)
  329. {
  330. /* XXXX Or should we use CFEqual?? */
  331. if ( self->ob_itself > other->ob_itself ) return 1;
  332. if ( self->ob_itself < other->ob_itself ) return -1;
  333. return 0;
  334. }
  335. static PyObject * CFTypeRefObj_repr(CFTypeRefObject *self)
  336. {
  337. char buf[100];
  338. 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);
  339. return PyString_FromString(buf);
  340. }
  341. static int CFTypeRefObj_hash(CFTypeRefObject *self)
  342. {
  343. /* XXXX Or should we use CFHash?? */
  344. return (int)self->ob_itself;
  345. }
  346. static int CFTypeRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  347. {
  348. CFTypeRef itself;
  349. char *kw[] = {"itself", 0};
  350. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
  351. {
  352. ((CFTypeRefObject *)_self)->ob_itself = itself;
  353. return 0;
  354. }
  355. return -1;
  356. }
  357. #define CFTypeRefObj_tp_alloc PyType_GenericAlloc
  358. static PyObject *CFTypeRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  359. {
  360. PyObject *self;
  361. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  362. ((CFTypeRefObject *)self)->ob_itself = NULL;
  363. ((CFTypeRefObject *)self)->ob_freeit = CFRelease;
  364. return self;
  365. }
  366. #define CFTypeRefObj_tp_free PyObject_Del
  367. PyTypeObject CFTypeRef_Type = {
  368. PyObject_HEAD_INIT(NULL)
  369. 0, /*ob_size*/
  370. "_CF.CFTypeRef", /*tp_name*/
  371. sizeof(CFTypeRefObject), /*tp_basicsize*/
  372. 0, /*tp_itemsize*/
  373. /* methods */
  374. (destructor) CFTypeRefObj_dealloc, /*tp_dealloc*/
  375. 0, /*tp_print*/
  376. (getattrfunc)0, /*tp_getattr*/
  377. (setattrfunc)0, /*tp_setattr*/
  378. (cmpfunc) CFTypeRefObj_compare, /*tp_compare*/
  379. (reprfunc) CFTypeRefObj_repr, /*tp_repr*/
  380. (PyNumberMethods *)0, /* tp_as_number */
  381. (PySequenceMethods *)0, /* tp_as_sequence */
  382. (PyMappingMethods *)0, /* tp_as_mapping */
  383. (hashfunc) CFTypeRefObj_hash, /*tp_hash*/
  384. 0, /*tp_call*/
  385. 0, /*tp_str*/
  386. PyObject_GenericGetAttr, /*tp_getattro*/
  387. PyObject_GenericSetAttr, /*tp_setattro */
  388. 0, /*tp_as_buffer*/
  389. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  390. 0, /*tp_doc*/
  391. 0, /*tp_traverse*/
  392. 0, /*tp_clear*/
  393. 0, /*tp_richcompare*/
  394. 0, /*tp_weaklistoffset*/
  395. 0, /*tp_iter*/
  396. 0, /*tp_iternext*/
  397. CFTypeRefObj_methods, /* tp_methods */
  398. 0, /*tp_members*/
  399. CFTypeRefObj_getsetlist, /*tp_getset*/
  400. 0, /*tp_base*/
  401. 0, /*tp_dict*/
  402. 0, /*tp_descr_get*/
  403. 0, /*tp_descr_set*/
  404. 0, /*tp_dictoffset*/
  405. CFTypeRefObj_tp_init, /* tp_init */
  406. CFTypeRefObj_tp_alloc, /* tp_alloc */
  407. CFTypeRefObj_tp_new, /* tp_new */
  408. CFTypeRefObj_tp_free, /* tp_free */
  409. };
  410. /* ------------------- End object type CFTypeRef -------------------- */
  411. /* --------------------- Object type CFArrayRef --------------------- */
  412. PyTypeObject CFArrayRef_Type;
  413. #define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type || PyObject_TypeCheck((x), &CFArrayRef_Type))
  414. typedef struct CFArrayRefObject {
  415. PyObject_HEAD
  416. CFArrayRef ob_itself;
  417. void (*ob_freeit)(CFTypeRef ptr);
  418. } CFArrayRefObject;
  419. PyObject *CFArrayRefObj_New(CFArrayRef itself)
  420. {
  421. CFArrayRefObject *it;
  422. if (itself == NULL)
  423. {
  424. PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
  425. return NULL;
  426. }
  427. it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type);
  428. if (it == NULL) return NULL;
  429. /* XXXX Should we tp_init or tp_new our basetype? */
  430. it->ob_itself = itself;
  431. it->ob_freeit = CFRelease;
  432. return (PyObject *)it;
  433. }
  434. int CFArrayRefObj_Convert(PyObject *v, CFArrayRef *p_itself)
  435. {
  436. if (v == Py_None) { *p_itself = NULL; return 1; }
  437. /* Check for other CF objects here */
  438. if (!CFArrayRefObj_Check(v))
  439. {
  440. PyErr_SetString(PyExc_TypeError, "CFArrayRef required");
  441. return 0;
  442. }
  443. *p_itself = ((CFArrayRefObject *)v)->ob_itself;
  444. return 1;
  445. }
  446. static void CFArrayRefObj_dealloc(CFArrayRefObject *self)
  447. {
  448. if (self->ob_freeit && self->ob_itself)
  449. {
  450. self->ob_freeit((CFTypeRef)self->ob_itself);
  451. self->ob_itself = NULL;
  452. }
  453. CFTypeRef_Type.tp_dealloc((PyObject *)self);
  454. }
  455. static PyObject *CFArrayRefObj_CFArrayCreateCopy(CFArrayRefObject *_self, PyObject *_args)
  456. {
  457. PyObject *_res = NULL;
  458. CFArrayRef _rv;
  459. if (!PyArg_ParseTuple(_args, ""))
  460. return NULL;
  461. _rv = CFArrayCreateCopy((CFAllocatorRef)NULL,
  462. _self->ob_itself);
  463. _res = Py_BuildValue("O&",
  464. CFArrayRefObj_New, _rv);
  465. return _res;
  466. }
  467. static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args)
  468. {
  469. PyObject *_res = NULL;
  470. CFIndex _rv;
  471. #ifndef CFArrayGetCount
  472. PyMac_PRECHECK(CFArrayGetCount);
  473. #endif
  474. if (!PyArg_ParseTuple(_args, ""))
  475. return NULL;
  476. _rv = CFArrayGetCount(_self->ob_itself);
  477. _res = Py_BuildValue("l",
  478. _rv);
  479. return _res;
  480. }
  481. static PyObject *CFArrayRefObj_CFStringCreateByCombiningStrings(CFArrayRefObject *_self, PyObject *_args)
  482. {
  483. PyObject *_res = NULL;
  484. CFStringRef _rv;
  485. CFStringRef separatorString;
  486. if (!PyArg_ParseTuple(_args, "O&",
  487. CFStringRefObj_Convert, &separatorString))
  488. return NULL;
  489. _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL,
  490. _self->ob_itself,
  491. separatorString);
  492. _res = Py_BuildValue("O&",
  493. CFStringRefObj_New, _rv);
  494. return _res;
  495. }
  496. static PyMethodDef CFArrayRefObj_methods[] = {
  497. {"CFArrayCreateCopy", (PyCFunction)CFArrayRefObj_CFArrayCreateCopy, 1,
  498. PyDoc_STR("() -> (CFArrayRef _rv)")},
  499. {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1,
  500. PyDoc_STR("() -> (CFIndex _rv)")},
  501. {"CFStringCreateByCombiningStrings", (PyCFunction)CFArrayRefObj_CFStringCreateByCombiningStrings, 1,
  502. PyDoc_STR("(CFStringRef separatorString) -> (CFStringRef _rv)")},
  503. {NULL, NULL, 0}
  504. };
  505. #define CFArrayRefObj_getsetlist NULL
  506. static int CFArrayRefObj_compare(CFArrayRefObject *self, CFArrayRefObject *other)
  507. {
  508. /* XXXX Or should we use CFEqual?? */
  509. if ( self->ob_itself > other->ob_itself ) return 1;
  510. if ( self->ob_itself < other->ob_itself ) return -1;
  511. return 0;
  512. }
  513. static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self)
  514. {
  515. char buf[100];
  516. sprintf(buf, "<CFArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
  517. return PyString_FromString(buf);
  518. }
  519. static int CFArrayRefObj_hash(CFArrayRefObject *self)
  520. {
  521. /* XXXX Or should we use CFHash?? */
  522. return (int)self->ob_itself;
  523. }
  524. static int CFArrayRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  525. {
  526. CFArrayRef itself;
  527. char *kw[] = {"itself", 0};
  528. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFArrayRefObj_Convert, &itself))
  529. {
  530. ((CFArrayRefObject *)_self)->ob_itself = itself;
  531. return 0;
  532. }
  533. /* Any CFTypeRef descendent is allowed as initializer too */
  534. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
  535. {
  536. ((CFArrayRefObject *)_self)->ob_itself = itself;
  537. return 0;
  538. }
  539. return -1;
  540. }
  541. #define CFArrayRefObj_tp_alloc PyType_GenericAlloc
  542. static PyObject *CFArrayRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  543. {
  544. PyObject *self;
  545. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  546. ((CFArrayRefObject *)self)->ob_itself = NULL;
  547. ((CFArrayRefObject *)self)->ob_freeit = CFRelease;
  548. return self;
  549. }
  550. #define CFArrayRefObj_tp_free PyObject_Del
  551. PyTypeObject CFArrayRef_Type = {
  552. PyObject_HEAD_INIT(NULL)
  553. 0, /*ob_size*/
  554. "_CF.CFArrayRef", /*tp_name*/
  555. sizeof(CFArrayRefObject), /*tp_basicsize*/
  556. 0, /*tp_itemsize*/
  557. /* methods */
  558. (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/
  559. 0, /*tp_print*/
  560. (getattrfunc)0, /*tp_getattr*/
  561. (setattrfunc)0, /*tp_setattr*/
  562. (cmpfunc) CFArrayRefObj_compare, /*tp_compare*/
  563. (reprfunc) CFArrayRefObj_repr, /*tp_repr*/
  564. (PyNumberMethods *)0, /* tp_as_number */
  565. (PySequenceMethods *)0, /* tp_as_sequence */
  566. (PyMappingMethods *)0, /* tp_as_mapping */
  567. (hashfunc) CFArrayRefObj_hash, /*tp_hash*/
  568. 0, /*tp_call*/
  569. 0, /*tp_str*/
  570. PyObject_GenericGetAttr, /*tp_getattro*/
  571. PyObject_GenericSetAttr, /*tp_setattro */
  572. 0, /*tp_as_buffer*/
  573. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  574. 0, /*tp_doc*/
  575. 0, /*tp_traverse*/
  576. 0, /*tp_clear*/
  577. 0, /*tp_richcompare*/
  578. 0, /*tp_weaklistoffset*/
  579. 0, /*tp_iter*/
  580. 0, /*tp_iternext*/
  581. CFArrayRefObj_methods, /* tp_methods */
  582. 0, /*tp_members*/
  583. CFArrayRefObj_getsetlist, /*tp_getset*/
  584. 0, /*tp_base*/
  585. 0, /*tp_dict*/
  586. 0, /*tp_descr_get*/
  587. 0, /*tp_descr_set*/
  588. 0, /*tp_dictoffset*/
  589. CFArrayRefObj_tp_init, /* tp_init */
  590. CFArrayRefObj_tp_alloc, /* tp_alloc */
  591. CFArrayRefObj_tp_new, /* tp_new */
  592. CFArrayRefObj_tp_free, /* tp_free */
  593. };
  594. /* ------------------- End object type CFArrayRef ------------------- */
  595. /* ----------------- Object type CFMutableArrayRef ------------------ */
  596. PyTypeObject CFMutableArrayRef_Type;
  597. #define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type || PyObject_TypeCheck((x), &CFMutableArrayRef_Type))
  598. typedef struct CFMutableArrayRefObject {
  599. PyObject_HEAD
  600. CFMutableArrayRef ob_itself;
  601. void (*ob_freeit)(CFTypeRef ptr);
  602. } CFMutableArrayRefObject;
  603. PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef itself)
  604. {
  605. CFMutableArrayRefObject *it;
  606. if (itself == NULL)
  607. {
  608. PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
  609. return NULL;
  610. }
  611. it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type);
  612. if (it == NULL) return NULL;
  613. /* XXXX Should we tp_init or tp_new our basetype? */
  614. it->ob_itself = itself;
  615. it->ob_freeit = CFRelease;
  616. return (PyObject *)it;
  617. }
  618. int CFMutableArrayRefObj_Convert(PyObject *v, CFMutableArrayRef *p_itself)
  619. {
  620. if (v == Py_None) { *p_itself = NULL; return 1; }
  621. /* Check for other CF objects here */
  622. if (!CFMutableArrayRefObj_Check(v))
  623. {
  624. PyErr_SetString(PyExc_TypeError, "CFMutableArrayRef required");
  625. return 0;
  626. }
  627. *p_itself = ((CFMutableArrayRefObject *)v)->ob_itself;
  628. return 1;
  629. }
  630. static void CFMutableArrayRefObj_dealloc(CFMutableArrayRefObject *self)
  631. {
  632. if (self->ob_freeit && self->ob_itself)
  633. {
  634. self->ob_freeit((CFTypeRef)self->ob_itself);
  635. self->ob_itself = NULL;
  636. }
  637. CFArrayRef_Type.tp_dealloc((PyObject *)self);
  638. }
  639. static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args)
  640. {
  641. PyObject *_res = NULL;
  642. CFIndex idx;
  643. #ifndef CFArrayRemoveValueAtIndex
  644. PyMac_PRECHECK(CFArrayRemoveValueAtIndex);
  645. #endif
  646. if (!PyArg_ParseTuple(_args, "l",
  647. &idx))
  648. return NULL;
  649. CFArrayRemoveValueAtIndex(_self->ob_itself,
  650. idx);
  651. Py_INCREF(Py_None);
  652. _res = Py_None;
  653. return _res;
  654. }
  655. static PyObject *CFMutableArrayRefObj_CFArrayRemoveAllValues(CFMutableArrayRefObject *_self, PyObject *_args)
  656. {
  657. PyObject *_res = NULL;
  658. #ifndef CFArrayRemoveAllValues
  659. PyMac_PRECHECK(CFArrayRemoveAllValues);
  660. #endif
  661. if (!PyArg_ParseTuple(_args, ""))
  662. return NULL;
  663. CFArrayRemoveAllValues(_self->ob_itself);
  664. Py_INCREF(Py_None);
  665. _res = Py_None;
  666. return _res;
  667. }
  668. static PyObject *CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices(CFMutableArrayRefObject *_self, PyObject *_args)
  669. {
  670. PyObject *_res = NULL;
  671. CFIndex idx1;
  672. CFIndex idx2;
  673. #ifndef CFArrayExchangeValuesAtIndices
  674. PyMac_PRECHECK(CFArrayExchangeValuesAtIndices);
  675. #endif
  676. if (!PyArg_ParseTuple(_args, "ll",
  677. &idx1,
  678. &idx2))
  679. return NULL;
  680. CFArrayExchangeValuesAtIndices(_self->ob_itself,
  681. idx1,
  682. idx2);
  683. Py_INCREF(Py_None);
  684. _res = Py_None;
  685. return _res;
  686. }
  687. static PyObject *CFMutableArrayRefObj_CFArrayAppendArray(CFMutableArrayRefObject *_self, PyObject *_args)
  688. {
  689. PyObject *_res = NULL;
  690. CFArrayRef otherArray;
  691. CFRange otherRange;
  692. #ifndef CFArrayAppendArray
  693. PyMac_PRECHECK(CFArrayAppendArray);
  694. #endif
  695. if (!PyArg_ParseTuple(_args, "O&O&",
  696. CFArrayRefObj_Convert, &otherArray,
  697. CFRange_Convert, &otherRange))
  698. return NULL;
  699. CFArrayAppendArray(_self->ob_itself,
  700. otherArray,
  701. otherRange);
  702. Py_INCREF(Py_None);
  703. _res = Py_None;
  704. return _res;
  705. }
  706. static PyMethodDef CFMutableArrayRefObj_methods[] = {
  707. {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1,
  708. PyDoc_STR("(CFIndex idx) -> None")},
  709. {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1,
  710. PyDoc_STR("() -> None")},
  711. {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1,
  712. PyDoc_STR("(CFIndex idx1, CFIndex idx2) -> None")},
  713. {"CFArrayAppendArray", (PyCFunction)CFMutableArrayRefObj_CFArrayAppendArray, 1,
  714. PyDoc_STR("(CFArrayRef otherArray, CFRange otherRange) -> None")},
  715. {NULL, NULL, 0}
  716. };
  717. #define CFMutableArrayRefObj_getsetlist NULL
  718. static int CFMutableArrayRefObj_compare(CFMutableArrayRefObject *self, CFMutableArrayRefObject *other)
  719. {
  720. /* XXXX Or should we use CFEqual?? */
  721. if ( self->ob_itself > other->ob_itself ) return 1;
  722. if ( self->ob_itself < other->ob_itself ) return -1;
  723. return 0;
  724. }
  725. static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self)
  726. {
  727. char buf[100];
  728. sprintf(buf, "<CFMutableArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
  729. return PyString_FromString(buf);
  730. }
  731. static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self)
  732. {
  733. /* XXXX Or should we use CFHash?? */
  734. return (int)self->ob_itself;
  735. }
  736. static int CFMutableArrayRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  737. {
  738. CFMutableArrayRef itself;
  739. char *kw[] = {"itself", 0};
  740. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFMutableArrayRefObj_Convert, &itself))
  741. {
  742. ((CFMutableArrayRefObject *)_self)->ob_itself = itself;
  743. return 0;
  744. }
  745. /* Any CFTypeRef descendent is allowed as initializer too */
  746. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
  747. {
  748. ((CFMutableArrayRefObject *)_self)->ob_itself = itself;
  749. return 0;
  750. }
  751. return -1;
  752. }
  753. #define CFMutableArrayRefObj_tp_alloc PyType_GenericAlloc
  754. static PyObject *CFMutableArrayRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  755. {
  756. PyObject *self;
  757. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  758. ((CFMutableArrayRefObject *)self)->ob_itself = NULL;
  759. ((CFMutableArrayRefObject *)self)->ob_freeit = CFRelease;
  760. return self;
  761. }
  762. #define CFMutableArrayRefObj_tp_free PyObject_Del
  763. PyTypeObject CFMutableArrayRef_Type = {
  764. PyObject_HEAD_INIT(NULL)
  765. 0, /*ob_size*/
  766. "_CF.CFMutableArrayRef", /*tp_name*/
  767. sizeof(CFMutableArrayRefObject), /*tp_basicsize*/
  768. 0, /*tp_itemsize*/
  769. /* methods */
  770. (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/
  771. 0, /*tp_print*/
  772. (getattrfunc)0, /*tp_getattr*/
  773. (setattrfunc)0, /*tp_setattr*/
  774. (cmpfunc) CFMutableArrayRefObj_compare, /*tp_compare*/
  775. (reprfunc) CFMutableArrayRefObj_repr, /*tp_repr*/
  776. (PyNumberMethods *)0, /* tp_as_number */
  777. (PySequenceMethods *)0, /* tp_as_sequence */
  778. (PyMappingMethods *)0, /* tp_as_mapping */
  779. (hashfunc) CFMutableArrayRefObj_hash, /*tp_hash*/
  780. 0, /*tp_call*/
  781. 0, /*tp_str*/
  782. PyObject_GenericGetAttr, /*tp_getattro*/
  783. PyObject_GenericSetAttr, /*tp_setattro */
  784. 0, /*tp_as_buffer*/
  785. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  786. 0, /*tp_doc*/
  787. 0, /*tp_traverse*/
  788. 0, /*tp_clear*/
  789. 0, /*tp_richcompare*/
  790. 0, /*tp_weaklistoffset*/
  791. 0, /*tp_iter*/
  792. 0, /*tp_iternext*/
  793. CFMutableArrayRefObj_methods, /* tp_methods */
  794. 0, /*tp_members*/
  795. CFMutableArrayRefObj_getsetlist, /*tp_getset*/
  796. 0, /*tp_base*/
  797. 0, /*tp_dict*/
  798. 0, /*tp_descr_get*/
  799. 0, /*tp_descr_set*/
  800. 0, /*tp_dictoffset*/
  801. CFMutableArrayRefObj_tp_init, /* tp_init */
  802. CFMutableArrayRefObj_tp_alloc, /* tp_alloc */
  803. CFMutableArrayRefObj_tp_new, /* tp_new */
  804. CFMutableArrayRefObj_tp_free, /* tp_free */
  805. };
  806. /* --------------- End object type CFMutableArrayRef ---------------- */
  807. /* ------------------ Object type CFDictionaryRef ------------------- */
  808. PyTypeObject CFDictionaryRef_Type;
  809. #define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type || PyObject_TypeCheck((x), &CFDictionaryRef_Type))
  810. typedef struct CFDictionaryRefObject {
  811. PyObject_HEAD
  812. CFDictionaryRef ob_itself;
  813. void (*ob_freeit)(CFTypeRef ptr);
  814. } CFDictionaryRefObject;
  815. PyObject *CFDictionaryRefObj_New(CFDictionaryRef itself)
  816. {
  817. CFDictionaryRefObject *it;
  818. if (itself == NULL)
  819. {
  820. PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
  821. return NULL;
  822. }
  823. it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type);
  824. if (it == NULL) return NULL;
  825. /* XXXX Should we tp_init or tp_new our basetype? */
  826. it->ob_itself = itself;
  827. it->ob_freeit = CFRelease;
  828. return (PyObject *)it;
  829. }
  830. int CFDictionaryRefObj_Convert(PyObject *v, CFDictionaryRef *p_itself)
  831. {
  832. if (v == Py_None) { *p_itself = NULL; return 1; }
  833. /* Check for other CF objects here */
  834. if (!CFDictionaryRefObj_Check(v))
  835. {
  836. PyErr_SetString(PyExc_TypeError, "CFDictionaryRef required");
  837. return 0;
  838. }
  839. *p_itself = ((CFDictionaryRefObject *)v)->ob_itself;
  840. return 1;
  841. }
  842. static void CFDictionaryRefObj_dealloc(CFDictionaryRefObject *self)
  843. {
  844. if (self->ob_freeit && self->ob_itself)
  845. {
  846. self->ob_freeit((CFTypeRef)self->ob_itself);
  847. self->ob_itself = NULL;
  848. }
  849. CFTypeRef_Type.tp_dealloc((PyObject *)self);
  850. }
  851. static PyObject *CFDictionaryRefObj_CFDictionaryCreateCopy(CFDictionaryRefObject *_self, PyObject *_args)
  852. {
  853. PyObject *_res = NULL;
  854. CFDictionaryRef _rv;
  855. if (!PyArg_ParseTuple(_args, ""))
  856. return NULL;
  857. _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL,
  858. _self->ob_itself);
  859. _res = Py_BuildValue("O&",
  860. CFDictionaryRefObj_New, _rv);
  861. return _res;
  862. }
  863. static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args)
  864. {
  865. PyObject *_res = NULL;
  866. CFIndex _rv;
  867. #ifndef CFDictionaryGetCount
  868. PyMac_PRECHECK(CFDictionaryGetCount);
  869. #endif
  870. if (!PyArg_ParseTuple(_args, ""))
  871. return NULL;
  872. _rv = CFDictionaryGetCount(_self->ob_itself);
  873. _res = Py_BuildValue("l",
  874. _rv);
  875. return _res;
  876. }
  877. static PyMethodDef CFDictionaryRefObj_methods[] = {
  878. {"CFDictionaryCreateCopy", (PyCFunction)CFDictionaryRefObj_CFDictionaryCreateCopy, 1,
  879. PyDoc_STR("() -> (CFDictionaryRef _rv)")},
  880. {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1,
  881. PyDoc_STR("() -> (CFIndex _rv)")},
  882. {NULL, NULL, 0}
  883. };
  884. #define CFDictionaryRefObj_getsetlist NULL
  885. static int CFDictionaryRefObj_compare(CFDictionaryRefObject *self, CFDictionaryRefObject *other)
  886. {
  887. /* XXXX Or should we use CFEqual?? */
  888. if ( self->ob_itself > other->ob_itself ) return 1;
  889. if ( self->ob_itself < other->ob_itself ) return -1;
  890. return 0;
  891. }
  892. static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self)
  893. {
  894. char buf[100];
  895. sprintf(buf, "<CFDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
  896. return PyString_FromString(buf);
  897. }
  898. static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self)
  899. {
  900. /* XXXX Or should we use CFHash?? */
  901. return (int)self->ob_itself;
  902. }
  903. static int CFDictionaryRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  904. {
  905. CFDictionaryRef itself;
  906. char *kw[] = {"itself", 0};
  907. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFDictionaryRefObj_Convert, &itself))
  908. {
  909. ((CFDictionaryRefObject *)_self)->ob_itself = itself;
  910. return 0;
  911. }
  912. /* Any CFTypeRef descendent is allowed as initializer too */
  913. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
  914. {
  915. ((CFDictionaryRefObject *)_self)->ob_itself = itself;
  916. return 0;
  917. }
  918. return -1;
  919. }
  920. #define CFDictionaryRefObj_tp_alloc PyType_GenericAlloc
  921. static PyObject *CFDictionaryRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  922. {
  923. PyObject *self;
  924. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  925. ((CFDictionaryRefObject *)self)->ob_itself = NULL;
  926. ((CFDictionaryRefObject *)self)->ob_freeit = CFRelease;
  927. return self;
  928. }
  929. #define CFDictionaryRefObj_tp_free PyObject_Del
  930. PyTypeObject CFDictionaryRef_Type = {
  931. PyObject_HEAD_INIT(NULL)
  932. 0, /*ob_size*/
  933. "_CF.CFDictionaryRef", /*tp_name*/
  934. sizeof(CFDictionaryRefObject), /*tp_basicsize*/
  935. 0, /*tp_itemsize*/
  936. /* methods */
  937. (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/
  938. 0, /*tp_print*/
  939. (getattrfunc)0, /*tp_getattr*/
  940. (setattrfunc)0, /*tp_setattr*/
  941. (cmpfunc) CFDictionaryRefObj_compare, /*tp_compare*/
  942. (reprfunc) CFDictionaryRefObj_repr, /*tp_repr*/
  943. (PyNumberMethods *)0, /* tp_as_number */
  944. (PySequenceMethods *)0, /* tp_as_sequence */
  945. (PyMappingMethods *)0, /* tp_as_mapping */
  946. (hashfunc) CFDictionaryRefObj_hash, /*tp_hash*/
  947. 0, /*tp_call*/
  948. 0, /*tp_str*/
  949. PyObject_GenericGetAttr, /*tp_getattro*/
  950. PyObject_GenericSetAttr, /*tp_setattro */
  951. 0, /*tp_as_buffer*/
  952. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  953. 0, /*tp_doc*/
  954. 0, /*tp_traverse*/
  955. 0, /*tp_clear*/
  956. 0, /*tp_richcompare*/
  957. 0, /*tp_weaklistoffset*/
  958. 0, /*tp_iter*/
  959. 0, /*tp_iternext*/
  960. CFDictionaryRefObj_methods, /* tp_methods */
  961. 0, /*tp_members*/
  962. CFDictionaryRefObj_getsetlist, /*tp_getset*/
  963. 0, /*tp_base*/
  964. 0, /*tp_dict*/
  965. 0, /*tp_descr_get*/
  966. 0, /*tp_descr_set*/
  967. 0, /*tp_dictoffset*/
  968. CFDictionaryRefObj_tp_init, /* tp_init */
  969. CFDictionaryRefObj_tp_alloc, /* tp_alloc */
  970. CFDictionaryRefObj_tp_new, /* tp_new */
  971. CFDictionaryRefObj_tp_free, /* tp_free */
  972. };
  973. /* ---------------- End object type CFDictionaryRef ----------------- */
  974. /* --------------- Object type CFMutableDictionaryRef --------------- */
  975. PyTypeObject CFMutableDictionaryRef_Type;
  976. #define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type || PyObject_TypeCheck((x), &CFMutableDictionaryRef_Type))
  977. typedef struct CFMutableDictionaryRefObject {
  978. PyObject_HEAD
  979. CFMutableDictionaryRef ob_itself;
  980. void (*ob_freeit)(CFTypeRef ptr);
  981. } CFMutableDictionaryRefObject;
  982. PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef itself)
  983. {
  984. CFMutableDictionaryRefObject *it;
  985. if (itself == NULL)
  986. {
  987. PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
  988. return NULL;
  989. }
  990. it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type);
  991. if (it == NULL) return NULL;
  992. /* XXXX Should we tp_init or tp_new our basetype? */
  993. it->ob_itself = itself;
  994. it->ob_freeit = CFRelease;
  995. return (PyObject *)it;
  996. }
  997. int CFMutableDictionaryRefObj_Convert(PyObject *v, CFMutableDictionaryRef *p_itself)
  998. {
  999. if (v == Py_None) { *p_itself = NULL; return 1; }
  1000. /* Check for other CF objects here */
  1001. if (!CFMutableDictionaryRefObj_Check(v))
  1002. {
  1003. PyErr_SetString(PyExc_TypeError, "CFMutableDictionaryRef required");
  1004. return 0;
  1005. }
  1006. *p_itself = ((CFMutableDictionaryRefObject *)v)->ob_itself;
  1007. return 1;
  1008. }
  1009. static void CFMutableDictionaryRefObj_dealloc(CFMutableDictionaryRefObject *self)
  1010. {
  1011. if (self->ob_freeit && self->ob_itself)
  1012. {
  1013. self->ob_freeit((CFTypeRef)self->ob_itself);
  1014. self->ob_itself = NULL;
  1015. }
  1016. CFDictionaryRef_Type.tp_dealloc((PyObject *)self);
  1017. }
  1018. static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args)
  1019. {
  1020. PyObject *_res = NULL;
  1021. #ifndef CFDictionaryRemoveAllValues
  1022. PyMac_PRECHECK(CFDictionaryRemoveAllValues);
  1023. #endif
  1024. if (!PyArg_ParseTuple(_args, ""))
  1025. return NULL;
  1026. CFDictionaryRemoveAllValues(_self->ob_itself);
  1027. Py_INCREF(Py_None);
  1028. _res = Py_None;
  1029. return _res;
  1030. }
  1031. static PyMethodDef CFMutableDictionaryRefObj_methods[] = {
  1032. {"CFDictionaryRemoveAllValues", (PyCFunction)CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues, 1,
  1033. PyDoc_STR("() -> None")},
  1034. {NULL, NULL, 0}
  1035. };
  1036. #define CFMutableDictionaryRefObj_getsetlist NULL
  1037. static int CFMutableDictionaryRefObj_compare(CFMutableDictionaryRefObject *self, CFMutableDictionaryRefObject *other)
  1038. {
  1039. /* XXXX Or should we use CFEqual?? */
  1040. if ( self->ob_itself > other->ob_itself ) return 1;
  1041. if ( self->ob_itself < other->ob_itself ) return -1;
  1042. return 0;
  1043. }
  1044. static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *self)
  1045. {
  1046. char buf[100];
  1047. sprintf(buf, "<CFMutableDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
  1048. return PyString_FromString(buf);
  1049. }
  1050. static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self)
  1051. {
  1052. /* XXXX Or should we use CFHash?? */
  1053. return (int)self->ob_itself;
  1054. }
  1055. static int CFMutableDictionaryRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  1056. {
  1057. CFMutableDictionaryRef itself;
  1058. char *kw[] = {"itself", 0};
  1059. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFMutableDictionaryRefObj_Convert, &itself))
  1060. {
  1061. ((CFMutableDictionaryRefObject *)_self)->ob_itself = itself;
  1062. return 0;
  1063. }
  1064. /* Any CFTypeRef descendent is allowed as initializer too */
  1065. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
  1066. {
  1067. ((CFMutableDictionaryRefObject *)_self)->ob_itself = itself;
  1068. return 0;
  1069. }
  1070. return -1;
  1071. }
  1072. #define CFMutableDictionaryRefObj_tp_alloc PyType_GenericAlloc
  1073. static PyObject *CFMutableDictionaryRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  1074. {
  1075. PyObject *self;
  1076. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  1077. ((CFMutableDictionaryRefObject *)self)->ob_itself = NULL;
  1078. ((CFMutableDictionaryRefObject *)self)->ob_freeit = CFRelease;
  1079. return self;
  1080. }
  1081. #define CFMutableDictionaryRefObj_tp_free PyObject_Del
  1082. PyTypeObject CFMutableDictionaryRef_Type = {
  1083. PyObject_HEAD_INIT(NULL)
  1084. 0, /*ob_size*/
  1085. "_CF.CFMutableDictionaryRef", /*tp_name*/
  1086. sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/
  1087. 0, /*tp_itemsize*/
  1088. /* methods */
  1089. (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/
  1090. 0, /*tp_print*/
  1091. (getattrfunc)0, /*tp_getattr*/
  1092. (setattrfunc)0, /*tp_setattr*/
  1093. (cmpfunc) CFMutableDictionaryRefObj_compare, /*tp_compare*/
  1094. (reprfunc) CFMutableDictionaryRefObj_repr, /*tp_repr*/
  1095. (PyNumberMethods *)0, /* tp_as_number */
  1096. (PySequenceMethods *)0, /* tp_as_sequence */
  1097. (PyMappingMethods *)0, /* tp_as_mapping */
  1098. (hashfunc) CFMutableDictionaryRefObj_hash, /*tp_hash*/
  1099. 0, /*tp_call*/
  1100. 0, /*tp_str*/
  1101. PyObject_GenericGetAttr, /*tp_getattro*/
  1102. PyObject_GenericSetAttr, /*tp_setattro */
  1103. 0, /*tp_as_buffer*/
  1104. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  1105. 0, /*tp_doc*/
  1106. 0, /*tp_traverse*/
  1107. 0, /*tp_clear*/
  1108. 0, /*tp_richcompare*/
  1109. 0, /*tp_weaklistoffset*/
  1110. 0, /*tp_iter*/
  1111. 0, /*tp_iternext*/
  1112. CFMutableDictionaryRefObj_methods, /* tp_methods */
  1113. 0, /*tp_members*/
  1114. CFMutableDictionaryRefObj_getsetlist, /*tp_getset*/
  1115. 0, /*tp_base*/
  1116. 0, /*tp_dict*/
  1117. 0, /*tp_descr_get*/
  1118. 0, /*tp_descr_set*/
  1119. 0, /*tp_dictoffset*/
  1120. CFMutableDictionaryRefObj_tp_init, /* tp_init */
  1121. CFMutableDictionaryRefObj_tp_alloc, /* tp_alloc */
  1122. CFMutableDictionaryRefObj_tp_new, /* tp_new */
  1123. CFMutableDictionaryRefObj_tp_free, /* tp_free */
  1124. };
  1125. /* ------------- End object type CFMutableDictionaryRef ------------- */
  1126. /* --------------------- Object type CFDataRef ---------------------- */
  1127. PyTypeObject CFDataRef_Type;
  1128. #define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type || PyObject_TypeCheck((x), &CFDataRef_Type))
  1129. typedef struct CFDataRefObject {
  1130. PyObject_HEAD
  1131. CFDataRef ob_itself;
  1132. void (*ob_freeit)(CFTypeRef ptr);
  1133. } CFDataRefObject;
  1134. PyObject *CFDataRefObj_New(CFDataRef itself)
  1135. {
  1136. CFDataRefObject *it;
  1137. if (itself == NULL)
  1138. {
  1139. PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
  1140. return NULL;
  1141. }
  1142. it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type);
  1143. if (it == NULL) return NULL;
  1144. /* XXXX Should we tp_init or tp_new our basetype? */
  1145. it->ob_itself = itself;
  1146. it->ob_freeit = CFRelease;
  1147. return (PyObject *)it;
  1148. }
  1149. int CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself)
  1150. {
  1151. if (v == Py_None) { *p_itself = NULL; return 1; }
  1152. if (PyString_Check(v)) {
  1153. char *cStr;
  1154. Py_ssize_t cLen;
  1155. if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
  1156. *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
  1157. return 1;
  1158. }
  1159. if (!CFDataRefObj_Check(v))
  1160. {
  1161. PyErr_SetString(PyExc_TypeError, "CFDataRef required");
  1162. return 0;
  1163. }
  1164. *p_itself = ((CFDataRefObject *)v)->ob_itself;
  1165. return 1;
  1166. }
  1167. static void CFDataRefObj_dealloc(CFDataRefObject *self)
  1168. {
  1169. if (self->ob_freeit && self->ob_itself)
  1170. {
  1171. self->ob_freeit((CFTypeRef)self->ob_itself);
  1172. self->ob_itself = NULL;
  1173. }
  1174. CFTypeRef_Type.tp_dealloc((PyObject *)self);
  1175. }
  1176. static PyObject *CFDataRefObj_CFDataCreateCopy(CFDataRefObject *_self, PyObject *_args)
  1177. {
  1178. PyObject *_res = NULL;
  1179. CFDataRef _rv;
  1180. if (!PyArg_ParseTuple(_args, ""))
  1181. return NULL;
  1182. _rv = CFDataCreateCopy((CFAllocatorRef)NULL,
  1183. _self->ob_itself);
  1184. _res = Py_BuildValue("O&",
  1185. CFDataRefObj_New, _rv);
  1186. return _res;
  1187. }
  1188. static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args)
  1189. {
  1190. PyObject *_res = NULL;
  1191. CFIndex _rv;
  1192. #ifndef CFDataGetLength
  1193. PyMac_PRECHECK(CFDataGetLength);
  1194. #endif
  1195. if (!PyArg_ParseTuple(_args, ""))
  1196. return NULL;
  1197. _rv = CFDataGetLength(_self->ob_itself);
  1198. _res = Py_BuildValue("l",
  1199. _rv);
  1200. return _res;
  1201. }
  1202. static PyObject *CFDataRefObj_CFStringCreateFromExternalRepresentation(CFDataRefObject *_self, PyObject *_args)
  1203. {
  1204. PyObject *_res = NULL;
  1205. CFStringRef _rv;
  1206. CFStringEncoding encoding;
  1207. if (!PyArg_ParseTuple(_args, "l",
  1208. &encoding))
  1209. return NULL;
  1210. _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL,
  1211. _self->ob_itself,
  1212. encoding);
  1213. _res = Py_BuildValue("O&",
  1214. CFStringRefObj_New, _rv);
  1215. return _res;
  1216. }
  1217. static PyObject *CFDataRefObj_CFDataGetData(CFDataRefObject *_self, PyObject *_args)
  1218. {
  1219. PyObject *_res = NULL;
  1220. int size = CFDataGetLength(_self->ob_itself);
  1221. char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
  1222. _res = (PyObject *)PyString_FromStringAndSize(data, size);
  1223. return _res;
  1224. }
  1225. static PyMethodDef CFDataRefObj_methods[] = {
  1226. {"CFDataCreateCopy", (PyCFunction)CFDataRefObj_CFDataCreateCopy, 1,
  1227. PyDoc_STR("() -> (CFDataRef _rv)")},
  1228. {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1,
  1229. PyDoc_STR("() -> (CFIndex _rv)")},
  1230. {"CFStringCreateFromExternalRepresentation", (PyCFunction)CFDataRefObj_CFStringCreateFromExternalRepresentation, 1,
  1231. PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
  1232. {"CFDataGetData", (PyCFunction)CFDataRefObj_CFDataGetData, 1,
  1233. PyDoc_STR("() -> (string _rv)")},
  1234. {NULL, NULL, 0}
  1235. };
  1236. #define CFDataRefObj_getsetlist NULL
  1237. static int CFDataRefObj_compare(CFDataRefObject *self, CFDataRefObject *other)
  1238. {
  1239. /* XXXX Or should we use CFEqual?? */
  1240. if ( self->ob_itself > other->ob_itself ) return 1;
  1241. if ( self->ob_itself < other->ob_itself ) return -1;
  1242. return 0;
  1243. }
  1244. static PyObject * CFDataRefObj_repr(CFDataRefObject *self)
  1245. {
  1246. char buf[100];
  1247. sprintf(buf, "<CFDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
  1248. return PyString_FromString(buf);
  1249. }
  1250. static int CFDataRefObj_hash(CFDataRefObject *self)
  1251. {
  1252. /* XXXX Or should we use CFHash?? */
  1253. return (int)self->ob_itself;
  1254. }
  1255. static int CFDataRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  1256. {
  1257. CFDataRef itself;
  1258. char *kw[] = {"itself", 0};
  1259. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFDataRefObj_Convert, &itself))
  1260. {
  1261. ((CFDataRefObject *)_self)->ob_itself = itself;
  1262. return 0;
  1263. }
  1264. /* Any CFTypeRef descendent is allowed as initializer too */
  1265. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeRefObj_Convert, &itself))
  1266. {
  1267. ((CFDataRefObject *)_self)->ob_itself = itself;
  1268. return 0;
  1269. }
  1270. return -1;
  1271. }
  1272. #define CFDataRefObj_tp_alloc PyType_GenericAlloc
  1273. static PyObject *CFDataRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  1274. {
  1275. PyObject *self;
  1276. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  1277. ((CFDataRefObject *)self)->ob_itself = NULL;
  1278. ((CFDataRefObject *)self)->ob_freeit = CFRelease;
  1279. return self;
  1280. }
  1281. #define CFDataRefObj_tp_free PyObject_Del
  1282. PyTypeObject CFDataRef_Type = {
  1283. PyObject_HEAD_INIT(NULL)
  1284. 0, /*ob_size*/
  1285. "_CF.CFDataRef", /*tp_name*/
  1286. sizeof(CFDataRefObject), /*tp_basicsize*/
  1287. 0, /*tp_itemsize*/
  1288. /* methods */
  1289. (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/
  1290. 0, /*tp_print*/
  1291. (getattrfunc)0, /*tp_getattr*/
  1292. (setattrfunc)0, /*tp_setattr*/
  1293. (cmpfunc) CFDataRefObj_compare, /*tp_compare*/
  1294. (reprfunc) CFDataRefObj_repr, /*tp_repr*/
  1295. (PyNumberMethods *)0, /* tp_as_number */
  1296. (PySequenceMethods *)0, /* tp_as_sequence */
  1297. (PyMappingMethods *)0, /* tp_as_mapping */
  1298. (hashfunc) CFDataRefObj_hash, /*tp_hash*/
  1299. 0, /*tp_call*/
  1300. 0, /*tp_str*/
  1301. PyObject_GenericGetAttr, /*tp_getattro*/
  1302. PyObject_GenericSetAttr, /*tp_setattro */
  1303. 0, /*tp_as_buffer*/
  1304. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  1305. 0, /*tp_doc*/
  1306. 0, /*tp_traverse*/
  1307. 0, /*tp_clear*/
  1308. 0, /*tp_richcompare*/
  1309. 0, /*tp_weaklistoffset*/
  1310. 0, /*tp_iter*/
  1311. 0, /*tp_iternext*/
  1312. CFDataRefObj_methods, /* tp_methods */
  1313. 0, /*tp_members*/
  1314. CFDataRefObj_getsetlist, /*tp_getset*/
  1315. 0, /*tp_base*/
  1316. 0, /*tp_dict*/
  1317. 0, /*tp_descr_get*/
  1318. 0, /*tp_descr_set*/
  1319. 0, /*tp_dictoffset*/
  1320. CFDataRefObj_tp_init, /* tp_init */
  1321. CFDataRefObj_tp_alloc, /* tp_alloc */
  1322. CFDataRefObj_tp_new, /* tp_new */
  1323. CFDataRefObj_tp_free, /* tp_free */
  1324. };
  1325. /* ------------------- End object type CFDataRef -------------------- */
  1326. /* ------------------ Object type CFMutableDataRef ------------------ */
  1327. PyTypeObject CFMutableDataRef_Type;
  1328. #define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type || PyObject_TypeCheck((x), &CFMutableDataRef_Type))
  1329. typedef struct CFMutableDataRefObject {
  1330. PyObject_HEAD
  1331. CFMutableDataRef ob_itself;
  1332. void (*ob_freeit)(CFTypeRef ptr);
  1333. } CFMutableDataRefObject;
  1334. PyObject *CFMutableDataRefObj_New(CFMutableDataRef itself)
  1335. {
  1336. CFMutableDataRefObject *it;
  1337. if (itself == NULL)
  1338. {
  1339. PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
  1340. return NULL;
  1341. }
  1342. it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type);
  1343. if (it == NULL) return NULL;
  1344. /* XXXX Should we tp_init or tp_new our basetype? */
  1345. it->ob_itself = itself;
  1346. it->ob_freeit = CFRelease;
  1347. return (PyObject *)it;
  1348. }
  1349. int CFMutableDataRefObj_Convert(PyObject *v, CFMutableDataRef *p_itself)
  1350. {
  1351. if (v == Py_None) { *p_itself = NULL; return 1; }
  1352. /* Check for other CF objects here */
  1353. if (!CFMutableDataRefObj_Check(v))
  1354. {
  1355. PyErr_SetString(PyExc_TypeError, "CFMutableDataRef required");
  1356. return 0;
  1357. }
  1358. *p_itself = ((CFMutableDataRefObject *)v)->ob_itself;
  1359. return 1;
  1360. }
  1361. static void CFMutableDataRefObj_dealloc(CFMutableDataRefObject *self)
  1362. {
  1363. if (self->ob_freeit && self->ob_itself)
  1364. {
  1365. self->ob_freeit((CFTypeRef)self->ob_itself);
  1366. self->ob_itself = NULL;
  1367. }
  1368. CFDataRef_Type.tp_dealloc((PyObject *)self);
  1369. }
  1370. static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args)
  1371. {
  1372. PyObject *_res = NULL;
  1373. CFIndex length;
  1374. #ifndef CFDataSetLength
  1375. PyMac_PRECHECK(CFDataSetLength);
  1376. #endif
  1377. if (!PyArg_ParseTuple(_args, "l",
  1378. &length))
  1379. return NULL;
  1380. CFDataSetLength(_self->ob_itself,
  1381. length);
  1382. Py_INCREF(Py_None);
  1383. _res = Py_None;
  1384. return _res;
  1385. }
  1386. static PyObject *CFMutableDataRefObj_CFDataIncreaseLength(CFMutableDataRefObject *_self, PyObject *_args)
  1387. {
  1388. PyObject *_res = NULL;
  1389. CFIndex extraLength;
  1390. #ifndef CFDataIncreaseLength
  1391. PyMac_PRECHECK(CFDataIncreaseLength);
  1392. #endif
  1393. if (!PyArg_ParseTuple(_args, "l",
  1394. &extraLength))
  1395. return NULL;
  1396. CFDataIncreaseLength(_self->ob_itself,
  1397. extraLength);
  1398. Py_INCREF(Py_None);
  1399. _res = Py_None;
  1400. return _res;
  1401. }
  1402. static PyObject *CFMutableDataRefObj_CFDataAppendBytes(CFMutableDataRefObject *_self, PyObject *_args)
  1403. {
  1404. PyObject *_res = NULL;
  1405. unsigned char *bytes__in__;
  1406. long bytes__len__;
  1407. int bytes__in_len__;
  1408. #ifndef CFDataAppendBytes
  1409. PyMac_PRECHECK(CFDataAppendBytes);
  1410. #endif
  1411. if (!PyArg_ParseTuple(_args, "s#",
  1412. &bytes__in__, &bytes__in_len__))
  1413. return NULL;
  1414. bytes__len__ = bytes__in_len__;
  1415. CFDataAppendBytes(_self->ob_itself,
  1416. bytes__in__, bytes__len__);
  1417. Py_INCREF(Py_None);
  1418. _res = Py_None;
  1419. return _res;
  1420. }
  1421. static PyObject *CFMutableDataRefObj_CFDataReplaceBytes(CFMutableDataRefObject *_self, PyObject *_args)
  1422. {
  1423. PyObject *_res = NULL;
  1424. CFRange range;
  1425. unsigned char *newBytes__in__;
  1426. long newBytes__len__;
  1427. int newBytes__in_len__;
  1428. #ifndef CFDataReplaceBytes
  1429. PyMac_PRECHECK(CFDataReplaceBytes);
  1430. #endif
  1431. if (!PyArg_ParseTuple(_args, "O&s#",
  1432. CFRange_Convert, &range,
  1433. &newBytes__in__, &newBytes__in_len__))
  1434. return NULL;
  1435. newBytes__len__ = newBytes__in_len__;
  1436. CFDataReplaceBytes(_self->ob_itself,
  1437. range,
  1438. newBytes__in__, newBytes__len__);
  1439. Py_INCREF(Py_None);
  1440. _res = Py_None;
  1441. return _res;
  1442. }
  1443. static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args)
  1444. {
  1445. PyObject *_res = NULL;
  1446. CFRange range;
  1447. #ifndef CFDataDeleteBytes
  1448. PyMac_PRECHECK(CFDataDeleteBytes);
  1449. #endif
  1450. if (!PyArg_ParseTuple(_args, "O&",
  1451. CFRange_Convert, &range))
  1452. return NULL;
  1453. CFDataDeleteBytes(_self->ob_itself,
  1454. range);
  1455. Py_INCREF(Py_None);
  1456. _res = Py_None;
  1457. return _res;
  1458. }
  1459. static PyMethodDef CFMutableDataRefObj_methods[] = {
  1460. {"CFDataSetLength", (PyCFunction)CFMutableDataRefObj_CFDataSetLength, 1,
  1461. PyDoc_STR("(CFIndex length) -> None")},
  1462. {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1,
  1463. PyDoc_STR("(CFIndex extraLength) -> None")},
  1464. {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1,
  1465. PyDoc_STR("(Buffer bytes) -> None")},
  1466. {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1,
  1467. PyDoc_STR("(CFRange range, Buffer newBytes) -> None")},
  1468. {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1,
  1469. PyDoc_STR("(CFRange range) -> None")},
  1470. {NULL, NULL, 0}
  1471. };
  1472. #define CFMutableDataRefObj_getsetlist NULL
  1473. static int CFMutableDataRefObj_compare(CFMutableDataRefObject *self, CFMutableDataRefObject *other)
  1474. {
  1475. /* XXXX Or should we use CFEqual?? */
  1476. if ( self->ob_itself > other->ob_itself ) return 1;
  1477. if ( self->ob_itself < other->ob_itself ) return -1;
  1478. return 0;
  1479. }
  1480. static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self)
  1481. {
  1482. char buf[100];
  1483. sprintf(buf, "<CFMutableDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
  1484. return PyString_FromString(buf);
  1485. }
  1486. static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self)
  1487. {
  1488. /* XXXX Or should we use CFHash?? */
  1489. return (int)self->ob_itself;
  1490. }
  1491. static int CFMutableDataRefObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  1492. {
  1493. CFMutableDataRef itself;
  1494. char *kw[] = {"itself", 0};
  1495. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFMutableDataRefObj_Convert, &itself))
  1496. {
  1497. ((CFMutableDataRefObject *)_self)->ob_itself = itself;
  1498. return 0;
  1499. }
  1500. /* Any CFTypeRef descendent is allowed as initializer too */
  1501. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CFTypeR