]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pyldb: Move PyErr_LDB_OR_RAISE() and PyErr_LDB_DN_OR_RAISE() into pyldb.h
authorAndrew Bartlett <abartlet@samba.org>
Mon, 4 Dec 2023 21:34:56 +0000 (10:34 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 3 Mar 2024 22:33:35 +0000 (22:33 +0000)
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 <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/ldb/pyldb.h
source4/dns_server/pydns.c
source4/dsdb/pydsdb.c

index 45637b76691f3637640db803e341af70be74efb2..b4904d8f5703f2a31c4ce8d0d2bfc7eca6b6a2eb 100644 (file)
@@ -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 {
index 71e7deb0075987d6ef7cde4176750a2c44d0010e..81aa6b7488cde18896809eb0dd352a77ca95685d 100644 (file)
 #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)
 {
index 8aa8871825c852b34d7da708c83944c75c450926..fbbbadd3f3b3807712e3370f83f110ed8960239f 100644 (file)
 
 #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");