]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pyldb: Consolidate PyErr_SetLdbError() using the pyldb version
authorAndrew Bartlett <abartlet@samba.org>
Sun, 24 Mar 2024 23:36:35 +0000 (12:36 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 28 Mar 2024 01:50:41 +0000 (01:50 +0000)
Now that pyldb-util is a private library to Samba, we have no excuses not to
consolidate helper functions like this.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/ldb-samba/pyldb.c
lib/ldb/pyldb.c
lib/ldb/pyldb.h
lib/ldb/pyldb_util.c
source4/dsdb/pydsdb.c

index 8154679146b23decf579e0dc433b9bd95d2ca3ca..958b3ad4b166fa7e216db2c3814b4f48ca351c8b 100644 (file)
@@ -37,16 +37,6 @@ static PyObject *pyldb_module;
 static PyObject *py_ldb_error;
 static PyTypeObject PySambaLdb;
 
-static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
-{
-       if (ret == LDB_ERR_PYTHON_EXCEPTION)
-               return; /* Python exception should already be set, just keep that */
-
-       PyErr_SetObject(error, 
-                       Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
-                       ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
-}
-
 static PyObject *py_ldb_set_loadparm(PyObject *self, PyObject *args)
 {
        PyObject *py_lp_ctx;
index 67e6141d1b880210c8cc1093da40ef8cad49de8d..cd4268a9a7413dec13dcad4e63d126be05940a3c 100644 (file)
@@ -260,27 +260,6 @@ static PyTypeObject PyLdbControl = {
        .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
 };
 
-static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
-{
-       PyObject *exc = NULL;
-       if (ret == LDB_ERR_PYTHON_EXCEPTION) {
-               return; /* Python exception should already be set, just keep that */
-       }
-       exc = Py_BuildValue("(i,s)", ret,
-                           ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx));
-       if (exc == NULL) {
-               /*
-                * Py_BuildValue failed, and will have set its own exception.
-                * It isn't the one we wanted, but it will have to do.
-                * This is all very unexpected.
-                */
-               fprintf(stderr, "could not make LdbError %d!\n", ret);
-               return;
-       }
-       PyErr_SetObject(error, exc);
-       Py_DECREF(exc);
-}
-
 static PyObject *py_ldb_bytes_str(PyBytesObject *self)
 {
        char *msg = NULL;
index 34357eada1a4ec8dbfa0a0545ffaf994ea1a2ea2..fe5139bef5a90f7eb04f29278d4185efefb3785f 100644 (file)
@@ -112,6 +112,8 @@ typedef struct {
        struct ldb_control *data;
 } PyLdbControlObject;
 
+void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx);
+
 #define PyErr_LDB_ERROR_IS_ERR_RAISE(err,ret,ldb) do { \
        if (ret != LDB_SUCCESS) { \
                PyErr_SetLdbError(err, ret, ldb); \
index 9d7086cf294c6ffbfcee817fba4b325d4b2da28c..e09114f4ab841e30695da9aa8ad8271fb77fb89c 100644 (file)
@@ -184,3 +184,24 @@ PyObject *pyldb_Dn_FromDn(struct ldb_dn *dn)
        py_ret->dn = dn;
        return (PyObject *)py_ret;
 }
+
+void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
+{
+       PyObject *exc = NULL;
+       if (ret == LDB_ERR_PYTHON_EXCEPTION) {
+               return; /* Python exception should already be set, just keep that */
+       }
+       exc = Py_BuildValue("(i,s)", ret,
+                           ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx));
+       if (exc == NULL) {
+               /*
+                * Py_BuildValue failed, and will have set its own exception.
+                * It isn't the one we wanted, but it will have to do.
+                * This is all very unexpected.
+                */
+               fprintf(stderr, "could not make LdbError %d!\n", ret);
+               return;
+       }
+       PyErr_SetObject(error, exc);
+       Py_DECREF(exc);
+}
index fbbbadd3f3b3807712e3370f83f110ed8960239f..5d94fdd9c9aa5f16b1deb3912e2a023d7a86eb3b 100644 (file)
@@ -49,16 +49,6 @@ static PyObject *py_ldb_get_exception(void)
        return result;
 }
 
-static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
-{
-       if (ret == LDB_ERR_PYTHON_EXCEPTION)
-               return; /* Python exception should already be set, just keep that */
-
-       PyErr_SetObject(error, 
-                       Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
-                       ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
-}
-
 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb, *result;