diff options
author | Lumir Balhar <lbalhar@redhat.com> | 2017-01-02 08:51:19 +0100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2017-03-10 07:31:11 +0100 |
commit | e9a464911cc7eeb226a2ff86268ae5ef379cc162 (patch) | |
tree | 0ed74a2738695323e622aca8c5aea8b5ff71acfe /lib/ldb-samba/pyldb.c | |
parent | 9d8bcead4f4e60209fad0b68faafad9d7f18d41e (diff) | |
download | samba-e9a464911cc7eeb226a2ff86268ae5ef379cc162.tar.gz |
python: samba._ldb: Port of samba._ldb to Python 3 compatible form
Port of samba._ldb Python module to Python 3 compatible form.
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'lib/ldb-samba/pyldb.c')
-rw-r--r-- | lib/ldb-samba/pyldb.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/ldb-samba/pyldb.c b/lib/ldb-samba/pyldb.c index 6c0d2a76b2e..dfcb5510e6d 100644 --- a/lib/ldb-samba/pyldb.c +++ b/lib/ldb-samba/pyldb.c @@ -20,6 +20,7 @@ */ #include <Python.h> +#include "python/py3compat.h" #include "includes.h" #include <ldb.h> #include <pyldb.h> @@ -29,7 +30,6 @@ #include "lib/ldb-samba/ldif_handlers.h" #include "auth/pyauth.h" -void init_ldb(void); static PyObject *pyldb_module; static PyObject *py_ldb_error; @@ -237,6 +237,14 @@ static PyMethodDef py_samba_ldb_methods[] = { { NULL }, }; +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + .m_name = "_ldb", + .m_doc = "Samba-specific LDB python bindings", + .m_size = -1, + .m_methods = py_samba_ldb_methods, +}; + static PyTypeObject PySambaLdb = { .tp_name = "samba._ldb.Ldb", .tp_doc = "Connection to a LDB database.", @@ -244,27 +252,29 @@ static PyTypeObject PySambaLdb = { .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, }; -void init_ldb(void) +MODULE_INIT_FUNC(_ldb) { PyObject *m; pyldb_module = PyImport_ImportModule("ldb"); if (pyldb_module == NULL) - return; + return NULL; PySambaLdb.tp_base = (PyTypeObject *)PyObject_GetAttrString(pyldb_module, "Ldb"); if (PySambaLdb.tp_base == NULL) - return; + return NULL; py_ldb_error = PyObject_GetAttrString(pyldb_module, "LdbError"); if (PyType_Ready(&PySambaLdb) < 0) - return; + return NULL; - m = Py_InitModule3("_ldb", NULL, "Samba-specific LDB python bindings"); + m = PyModule_Create(&moduledef); if (m == NULL) - return; + return NULL; Py_INCREF(&PySambaLdb); PyModule_AddObject(m, "Ldb", (PyObject *)&PySambaLdb); + + return m; } |