1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

pytalloc: Add pytalloc_BaseObject_PyType_Ready() wrapper

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>
This commit is contained in:
Andrew Bartlett 2016-03-01 09:26:29 +13:00
parent d82b11b21c
commit d850991ee2
5 changed files with 23 additions and 0 deletions

View 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 *)

View 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 *)

View 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_ */

View 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 *)

View 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);
}