From: Andrew Bartlett Date: Mon, 4 Dec 2023 21:34:56 +0000 (+1300) Subject: pyldb: Move PyErr_LDB_OR_RAISE() and PyErr_LDB_DN_OR_RAISE() into pyldb.h X-Git-Tag: tdb-1.4.11~1539 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8b0d00a8e3e9fb427db6eef565de7b09e42784f8;p=thirdparty%2Fsamba.git pyldb: Move PyErr_LDB_OR_RAISE() and PyErr_LDB_DN_OR_RAISE() into pyldb.h While these style of macros are against our coding style, it is still better to have them in a single place, and while pyldb.h is technically public Samba is the only user of the C bindings. Signed-off-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/lib/ldb/pyldb.h b/lib/ldb/pyldb.h index 45637b76691..b4904d8f570 100644 --- a/lib/ldb/pyldb.h +++ b/lib/ldb/pyldb.h @@ -42,6 +42,13 @@ typedef struct { (pyldb_check_type(pyobj, "Ldb") ? \ pyldb_Ldb_AS_LDBCONTEXT(pyobj) : NULL) +#define PyErr_LDB_OR_RAISE(py_ldb, ldb) \ + ldb = pyldb_Ldb_AsLdbContext(py_ldb); \ + if (!ldb) { \ + PyErr_SetString(PyExc_TypeError, "Ldb connection object required"); \ + return NULL; \ + } + typedef struct { PyObject_HEAD TALLOC_CTX *mem_ctx; @@ -52,6 +59,13 @@ PyObject *pyldb_Dn_FromDn(struct ldb_dn *); bool pyldb_Object_AsDn(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb_ctx, struct ldb_dn **dn); #define pyldb_Dn_AS_DN(pyobj) ((PyLdbDnObject *)pyobj)->dn +#define PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn) \ + if (!pyldb_check_type(py_ldb_dn, "Dn")) { \ + PyErr_SetString(PyExc_TypeError, "ldb Dn object required"); \ + return NULL; \ + } \ + dn = pyldb_Dn_AS_DN(py_ldb_dn); + bool pyldb_check_type(PyObject *obj, const char *type_name); typedef struct { diff --git a/source4/dns_server/pydns.c b/source4/dns_server/pydns.c index 71e7deb0075..81aa6b7488c 100644 --- a/source4/dns_server/pydns.c +++ b/source4/dns_server/pydns.c @@ -31,21 +31,6 @@ #include "librpc/gen_ndr/ndr_dnsp.h" #include "librpc/rpc/pyrpc_util.h" -/* FIXME: These should be in a header file somewhere */ -#define PyErr_LDB_OR_RAISE(py_ldb, ldb) \ - ldb = pyldb_Ldb_AsLdbContext(py_ldb); \ - if (!ldb) { \ - PyErr_SetString(PyExc_TypeError, "Ldb connection object required"); \ - return NULL; \ - } - -#define PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn) \ - if (!pyldb_check_type(py_ldb_dn, "Dn")) { \ - PyErr_SetString(PyExc_TypeError, "ldb Dn object required"); \ - return NULL; \ - } \ - dn = pyldb_Dn_AS_DN(py_ldb_dn); - static PyObject *py_dnsp_DnssrvRpcRecord_get_list(struct dnsp_DnssrvRpcRecord *records, uint16_t num_records) { diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c index 8aa8871825c..fbbbadd3f3b 100644 --- a/source4/dsdb/pydsdb.c +++ b/source4/dsdb/pydsdb.c @@ -37,21 +37,6 @@ #undef strcasecmp -/* FIXME: These should be in a header file somewhere */ -#define PyErr_LDB_OR_RAISE(py_ldb, ldb) \ - ldb = pyldb_Ldb_AsLdbContext(py_ldb); \ - if (!ldb) { \ - PyErr_SetString(PyExc_TypeError, "Ldb connection object required"); \ - return NULL; \ - } - -#define PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn) \ - if (!pyldb_check_type(py_ldb_dn, "Dn")) { \ - PyErr_SetString(PyExc_TypeError, "ldb Dn object required"); \ - return NULL; \ - } \ - dn = pyldb_Dn_AS_DN(py_ldb_dn); - static PyObject *py_ldb_get_exception(void) { PyObject *mod = PyImport_ImportModule("ldb");