From: John Mulligan Date: Sat, 23 Apr 2022 18:19:59 +0000 (-0400) Subject: lib/smbconf: add a python function for raising smbconf exceptions X-Git-Tag: talloc-2.3.4~239 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcd50ea4ab4cc2f4f7cf7f21da3092cd107530ad;p=thirdparty%2Fsamba.git lib/smbconf: add a python function for raising smbconf exceptions The previous implementation in C was private to the module. Add a small python wrapper function so that a different python module may reuse the implementation. The python level function is prefixed with "_" to mark it as "private". Only future cooperating modules in the samba sources should make use of it. The function is shared at the python level as per the recommendation: https://stackoverflow.com/a/2136670 Signed-off-by: John Mulligan Reviewed-by: Jeremy Allison Reviewed-by: Douglas Bagnall --- diff --git a/lib/smbconf/pysmbconf.c b/lib/smbconf/pysmbconf.c index 5250a03684f..efb11d0432c 100644 --- a/lib/smbconf/pysmbconf.c +++ b/lib/smbconf/pysmbconf.c @@ -365,9 +365,24 @@ static PyObject *py_init_txt(PyObject * module, PyObject * args) return (PyObject *) obj; } +static PyObject *py_smbconf_error(PyObject * module, PyObject * args) +{ + sbcErr errcode; + + if (!PyArg_ParseTuple(args, "i", &errcode)) { + return NULL; + } + + /* this always raises an exception. it doesn't return the exception. */ + py_raise_SMBConfError(errcode); + return NULL; +} + static PyMethodDef pysmbconf_methods[] = { { "init_txt", (PyCFunction) py_init_txt, METH_VARARGS, "Return an SMBConf object for the given text config file." }, + { "_smbconf_error", (PyCFunction) py_smbconf_error, METH_VARARGS, + "Raise an SMBConfError based on the given error code." }, { 0 }, };