pytalloc: Add pytalloc_BaseObject_PyType_Ready() wrapper
authorAndrew Bartlett <abartlet@samba.org>
Mon, 29 Feb 2016 20:26:29 +0000 (09:26 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 8 Mar 2016 00:58:29 +0000 (01:58 +0100)
This avoids the need for the caller to set tp_base and tp_basicsize and
so removes those as possible errors.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/talloc/ABI/pytalloc-util-2.1.6.sigs
lib/talloc/ABI/pytalloc-util.py3-2.1.6.sigs
lib/talloc/pytalloc.h
lib/talloc/pytalloc_guide.txt
lib/talloc/pytalloc_util.c

index 570be6309d0ea50abcc49e000ad2dc9056581410..666fec047f5fffbaa78b9727efb05d6bd2c3936f 100644 (file)
@@ -1,6 +1,7 @@
 _pytalloc_get_mem_ctx: TALLOC_CTX *(PyObject *)
 _pytalloc_get_ptr: void *(PyObject *)
 _pytalloc_get_type: void *(PyObject *, const char *)
+pytalloc_BaseObject_PyType_Ready: int (PyTypeObject *)
 pytalloc_BaseObject_check: int (PyObject *)
 pytalloc_BaseObject_size: size_t (void)
 pytalloc_CObject_FromTallocPtr: PyObject *(void *)
index 1d3d6cb37ac59756262077bb9d0dbfbe55cccf56..4410f110cb299ef5eaaeac54d43c5712d6beeb98 100644 (file)
@@ -1,6 +1,7 @@
 _pytalloc_get_mem_ctx: TALLOC_CTX *(PyObject *)
 _pytalloc_get_ptr: void *(PyObject *)
 _pytalloc_get_type: void *(PyObject *, const char *)
+pytalloc_BaseObject_PyType_Ready: int (PyTypeObject *)
 pytalloc_BaseObject_check: int (PyObject *)
 pytalloc_BaseObject_size: size_t (void)
 pytalloc_Check: int (PyObject *)
index 3c1cfda259de8c9325f0e61e4321f864a3c3c8b2..6a0ac187288c8cca63fdb0e29c028af8fa1bb122 100644 (file)
@@ -63,5 +63,6 @@ PyObject *pytalloc_CObject_FromTallocPtr(void *);
 
 size_t pytalloc_BaseObject_size(void);
 
+int pytalloc_BaseObject_PyType_Ready(PyTypeObject *type);
 
 #endif /* _PYTALLOC_H_ */
index b0351bb9eb0389e00243ff7e711a7830c6fe5127..8e9694e0177d3680cc5b3aafce597bdc2226682b 100644 (file)
@@ -71,6 +71,12 @@ Obtain a reference to the PyTypeObject for `pytalloc_Object`. The reference
 counter for the object will be incremented, so the caller will have to
 decrement it when it no longer needs it (using `Py_DECREF`).
 
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+int pytalloc_BaseObject_PyType_Ready(PyTypeObject *type);
+
+Wrapper for PyType_Ready() that will set the correct values into
+the PyTypeObject to create a BaseObject
+
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-
 int pytalloc_Check(PyObject *)
 
index 307e38a4c1e921403727158439e3d0e551b550a4..cb71dc975ccf65e77c0c0a87e344d0b4ebca9384 100644 (file)
@@ -259,3 +259,17 @@ _PUBLIC_ TALLOC_CTX *_pytalloc_get_mem_ctx(PyObject *py_obj)
        }
        return NULL;
 }
+
+_PUBLIC_ int pytalloc_BaseObject_PyType_Ready(PyTypeObject *type)
+{
+       PyTypeObject *talloc_type = pytalloc_GetBaseObjectType();
+       if (talloc_type == NULL) {
+               PyErr_Format(PyExc_TypeError, "pytalloc: unable to get talloc.BaseObject type");
+               return -1;
+       }
+
+       type->tp_base = talloc_type;
+       type->tp_basicsize = pytalloc_BaseObject_size();
+
+       return PyType_Ready(type);
+}