mirror of
https://github.com/samba-team/samba.git
synced 2025-12-04 08:23:50 +03:00
python: Allow wrapping pointers within talloc'ed memory that are not talloc contexts.
(This used to be commit 9c038a7411)
This commit is contained in:
@@ -22,14 +22,16 @@
|
||||
void py_talloc_dealloc(PyObject* self)
|
||||
{
|
||||
py_talloc_Object *obj = (py_talloc_Object *)self;
|
||||
talloc_free(obj->talloc_ptr);
|
||||
talloc_free(obj->talloc_ctx);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
PyObject *py_talloc_import(PyTypeObject *py_type, void *ptr)
|
||||
PyObject *py_talloc_import(PyTypeObject *py_type, TALLOC_CTX *mem_ctx,
|
||||
void *ptr)
|
||||
{
|
||||
PyObject *ret = PyObject_New(py_talloc_Object, &py_type);
|
||||
ret->talloc_ptr = talloc_reference(NULL, ptr);
|
||||
ret->talloc_ctx = talloc_reference(mem_ctx, ptr);
|
||||
ret->ptr = ptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -38,5 +40,5 @@ PyObject *py_talloc_default_repr(PyObject *py_obj)
|
||||
py_talloc_Object *obj = (py_talloc_Object *)py_obj;
|
||||
|
||||
return PyString_FromFormat("<talloc: %s>",
|
||||
talloc_get_name(obj->talloc_ptr));
|
||||
talloc_get_name(obj->talloc_ctx));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
void *talloc_ptr;
|
||||
TALLOC_CTX *talloc_ctx;
|
||||
void *ptr;
|
||||
} py_talloc_Object;
|
||||
|
||||
/* Deallocate a py_talloc_Object */
|
||||
@@ -36,9 +37,13 @@ void py_talloc_dealloc(PyObject* self);
|
||||
/* FIXME: Call PyErr_SetString(PyExc_TypeError, "expected " __STR(type) ")
|
||||
* when talloc_get_type() returns NULL. */
|
||||
#define py_talloc_get_type(py_obj, type) \
|
||||
talloc_get_type(((py_talloc_Object *)py_obj)->talloc_ptr, type)
|
||||
talloc_get_type(py_talloc_get_ptr(py_obj), type)
|
||||
|
||||
PyObject *py_talloc_import(PyTypeObject *py_type, void *ptr);
|
||||
#define py_talloc_get_ptr(py_obj) ((py_talloc_Object *)py_obj)->ptr
|
||||
#define py_talloc_get_mem_ctx(py_obj) ((py_talloc_Object *)py_obj)->talloc_ctx
|
||||
|
||||
PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
|
||||
#define py_talloc_import(py_type, talloc_ptr) py_talloc_import_ex(py_type, talloc_ptr, talloc_ptr)
|
||||
|
||||
/* Sane default implementation of reprfunc. */
|
||||
PyObject *py_talloc_default_repr(PyObject *py_obj);
|
||||
|
||||
Reference in New Issue
Block a user