1/* 2 * Manual wrappers for CFBag 3 */ 4static PyObject* 5mod_CFBagGetValues( 6 PyObject* self __attribute__((__unused__)), 7 PyObject* args) 8{ 9 PyObject* py_bag; 10 CFBagRef bag; 11 12 13 if (!PyArg_ParseTuple(args, "O", &py_bag)) { 14 return NULL; 15 } 16 17 if (PyObjC_PythonToObjC(@encode(CFBagRef), py_bag, &bag) < 0) { 18 return NULL; 19 } 20 21 CFIndex count = CFBagGetCount(bag); 22 NSObject** members = malloc(sizeof(NSObject*) * count); 23 if (members == NULL) { 24 PyErr_NoMemory(); 25 return NULL; 26 } 27 memset(members, 0, sizeof(NSObject*) * count); 28 29 CFBagGetValues(bag, (const void**)members); 30 PyObject* result = PyObjC_CArrayToPython(@encode(NSObject*), members, (Py_ssize_t)count); 31 free(members); 32 return result; 33} 34 35 36static PyObject* 37mod_CFBagCreate(PyObject* self __attribute__((__unused__)), 38 PyObject* args) 39{ 40 PyObject* py_allocator; 41 PyObject* py_members; 42 Py_ssize_t count; 43 CFAllocatorRef allocator; 44 void** members; 45 int r; 46 PyObject* buf = NULL; 47 CFBagRef bag; 48 49 50 if (!PyArg_ParseTuple(args, "OO" Py_ARG_SIZE_T, &py_allocator, &py_members, &count)) { 51 return NULL; 52 } 53 54 if (PyObjC_PythonToObjC(@encode(CFAllocatorRef), py_allocator, &allocator) < 0) { 55 return NULL; 56 } 57 58 r = PyObjC_PythonToCArray(NO, NO, @encode(NSObject*), py_members, (void**)&members, &count, &buf); 59 if (r == -1) { 60 return NULL; 61 } 62 63 bag = CFBagCreate(allocator, (const void**)members, (CFIndex)count, &kCFTypeBagCallBacks); 64 65 PyObjC_FreeCArray(r, members); 66 Py_XDECREF(buf); 67 68 PyObject* result = PyObjC_ObjCToPython(@encode(CFBagRef), &bag); 69 if (bag) { 70 CFRelease(bag); 71 } 72 return result; 73} 74 75static PyObject* 76mod_CFBagCreateMutable(PyObject* self __attribute__((__unused__)), 77 PyObject* args) 78{ 79 PyObject* py_allocator; 80 Py_ssize_t count; 81 CFAllocatorRef allocator; 82 CFBagRef bag; 83 84 85 if (!PyArg_ParseTuple(args, "O" Py_ARG_SIZE_T, &py_allocator, &count)) { 86 return NULL; 87 } 88 89 if (PyObjC_PythonToObjC(@encode(CFAllocatorRef), py_allocator, &allocator) < 0) { 90 return NULL; 91 } 92 93 bag = CFBagCreateMutable(allocator, count, &kCFTypeBagCallBacks); 94 95 PyObject* result = PyObjC_ObjCToPython(@encode(CFBagRef), &bag); 96 if (bag) { 97 CFRelease(bag); 98 } 99 return result; 100} 101 102#define COREFOUNDATION_CFBAG_METHODS \ 103 { \ 104 "CFBagCreate", \ 105 (PyCFunction)mod_CFBagCreate, \ 106 METH_VARARGS, \ 107 NULL \ 108 }, \ 109 { \ 110 "CFBagCreateMutable", \ 111 (PyCFunction)mod_CFBagCreateMutable, \ 112 METH_VARARGS, \ 113 NULL \ 114 }, \ 115 { \ 116 "CFBagGetValues", \ 117 (PyCFunction)mod_CFBagGetValues, \ 118 METH_VARARGS, \ 119 NULL \ 120 }, 121