python: samba._ldb: Port of samba._ldb to Python 3 compatible form
authorLumir Balhar <lbalhar@redhat.com>
Mon, 2 Jan 2017 07:51:19 +0000 (08:51 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 10 Mar 2017 06:31:11 +0000 (07:31 +0100)
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>
lib/ldb-samba/pyldb.c
lib/ldb-samba/wscript_build
python/samba/__init__.py

index 6c0d2a76b2efb9a63b0e5d908e14a63505240bd6..dfcb5510e6dc9e4035c496e7c45276ed33727c1a 100644 (file)
@@ -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;
 }
index d35b2277da78a2312aa9b6630c95e5456906e917..c538b5a126053291e2e29199a353c83486090b2b 100644 (file)
@@ -18,10 +18,12 @@ bld.SAMBA_SUBSYSTEM('ldbwrap',
                     deps='ldb samba-util ldbsamba samba-hostconfig'
                     )
 
-
-bld.SAMBA_PYTHON('python_samba__ldb', 'pyldb.c',
-                 deps='ldbsamba pyparam_util ldbwrap pyldb-util pyauth',
-                 realname='samba/_ldb.so')
+for env in bld.gen_python_environments():
+    pyparam_util = bld.pyembed_libname('pyparam_util')
+    pyldb_util = bld.pyembed_libname('pyldb-util')
+    bld.SAMBA_PYTHON('python_samba__ldb', 'pyldb.c',
+                     deps='ldbsamba %s ldbwrap %s pyauth' % (pyparam_util, pyldb_util),
+                     realname='samba/_ldb.so')
 
 bld.SAMBA_MODULE('ldbsamba_extensions',
                  source='samba_extensions.c',
index a5db0f0353ece43785755340219ac4c81ba7d0e5..29f4378e7564d879f9b798884c993af1a55f848e 100644 (file)
@@ -29,11 +29,7 @@ import ldb
 from samba.compat import PY3
 import samba.param
 from samba import _glue
-if not PY3:
-    from samba._ldb import Ldb as _Ldb
-else:
-    # samba._ldb is not yet ported to Python 3
-    _Ldb = object
+from samba._ldb import Ldb as _Ldb
 
 
 def source_tree_topdir():