static PyObject *testpytalloc_reference(PyObject *mod, PyObject *args) { pytalloc_Object *source = NULL; void *ptr; if (!PyArg_ParseTuple(args, "O!", pytalloc_GetObjectType(), &source)) return NULL; ptr = source->ptr; return pytalloc_reference_ex(pytalloc_GetObjectType(), ptr, ptr); }
void initsocket_wrapper(void) { PyObject *m; char exception_name[] = "socket_wrapper.error"; PyTypeObject *talloc_type = pytalloc_GetObjectType(); if (talloc_type == NULL) { return; } PySocket.tp_base = talloc_type; if (PyType_Ready(&PySocket) < 0) { return; } m = Py_InitModule3("socket_wrapper", py_socket_wrapper_methods, "Socket wrapper"); if (m == NULL) { return; } py_socket_error = PyErr_NewException(exception_name, NULL, NULL); Py_INCREF(py_socket_error); PyModule_AddObject(m, "error", py_socket_error); Py_INCREF(&PySocket); PyModule_AddObject(m, "socket", (PyObject *)&PySocket); }
void initcredentials(void) { PyObject *m; PyTypeObject *talloc_type = pytalloc_GetObjectType(); if (talloc_type == NULL) return; PyCredentials.tp_base = PyCredentialCacheContainer.tp_base = talloc_type; if (PyType_Ready(&PyCredentials) < 0) return; if (PyType_Ready(&PyCredentialCacheContainer) < 0) return; m = Py_InitModule3("credentials", NULL, "Credentials management."); if (m == NULL) return; PyModule_AddObject(m, "AUTO_USE_KERBEROS", PyInt_FromLong(CRED_AUTO_USE_KERBEROS)); PyModule_AddObject(m, "DONT_USE_KERBEROS", PyInt_FromLong(CRED_DONT_USE_KERBEROS)); PyModule_AddObject(m, "MUST_USE_KERBEROS", PyInt_FromLong(CRED_MUST_USE_KERBEROS)); PyModule_AddObject(m, "AUTO_KRB_FORWARDABLE", PyInt_FromLong(CRED_AUTO_KRB_FORWARDABLE)); PyModule_AddObject(m, "NO_KRB_FORWARDABLE", PyInt_FromLong(CRED_NO_KRB_FORWARDABLE)); PyModule_AddObject(m, "FORCE_KRB_FORWARDABLE", PyInt_FromLong(CRED_FORCE_KRB_FORWARDABLE)); Py_INCREF(&PyCredentials); PyModule_AddObject(m, "Credentials", (PyObject *)&PyCredentials); Py_INCREF(&PyCredentialCacheContainer); PyModule_AddObject(m, "CredentialCacheContainer", (PyObject *)&PyCredentialCacheContainer); }
/** * Import an existing talloc pointer into a Python object. */ _PUBLIC_ PyObject *pytalloc_steal_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr) { PyTypeObject *BaseObjectType = pytalloc_GetBaseObjectType(); PyTypeObject *ObjectType = pytalloc_GetObjectType(); if (mem_ctx == NULL) { return PyErr_NoMemory(); } if (PyType_IsSubtype(py_type, BaseObjectType)) { pytalloc_BaseObject *ret = (pytalloc_BaseObject *)py_type->tp_alloc(py_type, 0); ret->talloc_ctx = talloc_new(NULL); if (ret->talloc_ctx == NULL) { return NULL; } /* * This allows us to keep multiple references to this object - * we only reference this context, which is per ptr, not the * talloc_ctx, which is per pytalloc_Object */ if (talloc_steal(ret->talloc_ctx, mem_ctx) == NULL) { return NULL; } ret->talloc_ptr_ctx = mem_ctx; talloc_set_name_const(ret->talloc_ctx, py_type->tp_name); ret->ptr = ptr; return (PyObject *)ret; } else if (PyType_IsSubtype(py_type, ObjectType)) { pytalloc_Object *ret = (pytalloc_Object *)py_type->tp_alloc(py_type, 0); ret->talloc_ctx = talloc_new(NULL); if (ret->talloc_ctx == NULL) { return NULL; } if (talloc_steal(ret->talloc_ctx, mem_ctx) == NULL) { return NULL; } talloc_set_name_const(ret->talloc_ctx, py_type->tp_name); ret->ptr = ptr; return (PyObject *)ret; } else { PyErr_SetString(PyExc_RuntimeError, "pytalloc_steal_ex() called for object type " "not based on talloc"); return NULL; } }
/** * Import an existing talloc pointer into a Python object, leaving the * original parent, and creating a reference to the object in the python * object. * * We remember the object we hold the reference to (a * possibly-non-talloc pointer), the existing parent (typically the * start of the array) and the new referenced parent. That way we can * cope with the fact that we will have multiple parents, one per time * python sees the object. */ _PUBLIC_ PyObject *pytalloc_reference_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr) { PyTypeObject *BaseObjectType = pytalloc_GetBaseObjectType(); PyTypeObject *ObjectType = pytalloc_GetObjectType(); if (mem_ctx == NULL) { return PyErr_NoMemory(); } if (PyType_IsSubtype(py_type, BaseObjectType)) { pytalloc_BaseObject *ret = (pytalloc_BaseObject *)py_type->tp_alloc(py_type, 0); ret->talloc_ctx = talloc_new(NULL); if (ret->talloc_ctx == NULL) { return NULL; } if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) { return NULL; } talloc_set_name_const(ret->talloc_ctx, py_type->tp_name); ret->talloc_ptr_ctx = mem_ctx; ret->ptr = ptr; return (PyObject *)ret; } else if (PyType_IsSubtype(py_type, ObjectType)) { pytalloc_Object *ret = (pytalloc_Object *)py_type->tp_alloc(py_type, 0); ret->talloc_ctx = talloc_new(NULL); if (ret->talloc_ctx == NULL) { return NULL; } if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) { return NULL; } talloc_set_name_const(ret->talloc_ctx, py_type->tp_name); ret->ptr = ptr; return (PyObject *)ret; } else { PyErr_SetString(PyExc_RuntimeError, "pytalloc_reference_ex() called for object type " "not based on talloc"); return NULL; } }
void initparam(void) { PyObject *m; PyTypeObject *talloc_type = pytalloc_GetObjectType(); if (talloc_type == NULL) return; PyLoadparmContext.tp_base = talloc_type; PyLoadparmService.tp_base = talloc_type; if (PyType_Ready(&PyLoadparmContext) < 0) return; if (PyType_Ready(&PyLoadparmService) < 0) return; m = Py_InitModule3("param", pyparam_methods, "Parsing and writing Samba configuration files."); if (m == NULL) return; Py_INCREF(&PyLoadparmContext); PyModule_AddObject(m, "LoadParm", (PyObject *)&PyLoadparmContext); }
_PUBLIC_ int pytalloc_Check(PyObject *obj) { PyTypeObject *tp = pytalloc_GetObjectType(); return PyObject_TypeCheck(obj, tp); }
static PyObject *testpytalloc_get_object_type(PyObject *mod) { PyObject *type = (PyObject *)pytalloc_GetObjectType(); Py_INCREF(type); return type; }
static PyObject *testpytalloc_new(PyTypeObject *mod) { char *obj = talloc_strdup(NULL, "This is a test string");; return pytalloc_steal(pytalloc_GetObjectType(), obj); }