From: Douglas Bagnall Date: Thu, 7 Mar 2024 21:42:06 +0000 (+1300) Subject: ldb:pyldb: reorder structs for possible type-punning X-Git-Tag: tdb-1.4.11~1194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72ad126ab74b247460ccf4bdb590efc28cbd2be8;p=thirdparty%2Fsamba.git ldb:pyldb: reorder structs for possible type-punning Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/pyldb.h b/lib/ldb/pyldb.h index 5487def58a0..27d5fe3b441 100644 --- a/lib/ldb/pyldb.h +++ b/lib/ldb/pyldb.h @@ -51,15 +51,51 @@ typedef struct { return NULL; \ } +/* + * A note about PyLdbObject back-references and struct member ordering. + * + * PyLdbDnObject, PyLdbMessageObject, and PyLdbResultObject all + * contain pointers to the PyLdbObject that was used to create them. + * This is used to check that the ldb pointer in the underlying ldb + * struct is still valid -- that is, it points to the same ldb as the + * PyLdbObject. + * + * We keep these pointers in third place in the structs, like this + * { + * PyObject_HEAD + * TALLOC_CTX *mem_ctx; + * PyLdbObject *pyldb; + * ... + * } + * + * so that, if we feel like it in future, we can do type-punning in + * the way Python does. For example: + * + * typedef struct { + * PyObject_HEAD + * TALLOC_CTX *mem_ctx; + * PyLdbObject *pyldb; + * } PyLdbChildObject; + * + * #define pyldb_child_get_pyldb(pyobj) ((PyLdbChildObject *)pyobj)->pyldb + * + * #define PY_LDB_OWNS_THIS_CHILD(pyldb, child) \ + * (((PyLdbObject *)ldb) == ((PyLdbChildObject *)child)->ldb) + * + * At present we don't do this, because there are not a whole lot of + * cases where we want to do the same things with dNs, messages, and + * results. + */ + typedef struct { PyObject_HEAD TALLOC_CTX *mem_ctx; - struct ldb_dn *dn; /* * We use this to keep a reference to the ldb context within * the struct ldb_dn and to know if it is still valid */ PyLdbObject *pyldb; + struct ldb_dn *dn; } PyLdbDnObject; PyObject *pyldb_Dn_FromDn(struct ldb_dn *dn, PyLdbObject *pyldb); @@ -97,14 +133,15 @@ bool pyldb_check_type(PyObject *obj, const char *type_name); typedef struct { PyObject_HEAD TALLOC_CTX *mem_ctx; - struct ldb_message *msg; /* * We use this to keep a reference to the ldb context within * the struct ldb_dn (under struct ldb_message) and to know if * it is still valid */ PyLdbObject *pyldb; + struct ldb_message *msg; } PyLdbMessageObject; + #define pyldb_Message_AsMessage(pyobj) ((PyLdbMessageObject *)pyobj)->msg /* @@ -131,10 +168,10 @@ typedef struct { typedef struct { PyObject_HEAD TALLOC_CTX *mem_ctx; + PyLdbObject *pyldb; PyObject *msgs; PyObject *referals; PyObject *controls; - PyLdbObject *pyldb; } PyLdbResultObject; typedef struct {