python: Port ntvfs posix bindings to Python 3 compatible form
authorLumir Balhar <lbalhar@redhat.com>
Tue, 24 Oct 2017 07:00:11 +0000 (09:00 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 8 Nov 2017 16:57:21 +0000 (17:57 +0100)
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
selftest/tests.py
source4/ntvfs/posix/python/pyposix_eadb.c
source4/ntvfs/posix/python/pyxattr_native.c
source4/ntvfs/posix/python/pyxattr_tdb.c
source4/ntvfs/posix/wscript_build

index 704dbad3b73f094606f621e90322a088d34168b8..181313ebc952187c928affc90734f7d2c47cfd46 100644 (file)
@@ -126,7 +126,7 @@ plantestsuite(
      os.path.join(bbdir, "dbcheck-links.sh"),
      '$PREFIX_ABS/provision', 'release-4-5-0-pre1', configuration])
 planpythontestsuite("none", "samba.tests.upgradeprovision")
-planpythontestsuite("none", "samba.tests.xattr")
+planpythontestsuite("none", "samba.tests.xattr", py3_compatible=True)
 planpythontestsuite("none", "samba.tests.ntacls")
 planpythontestsuite("none", "samba.tests.policy")
 planpythontestsuite("none", "samba.tests.kcc.graph")
index a94440be3f0930944a001c2d438a456db5549735..d43c7c47bb79f7fd25eab648e2ae883a1939733a 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include <Python.h>
+#include "python/py3compat.h"
 #include "includes.h"
 #include "system/filesys.h"
 #include <tdb.h>
@@ -28,8 +29,6 @@
 #include "libcli/util/pyerrors.h"
 #include "param/pyparam.h"
 
-void initposix_eadb(void);
-
 static PyObject *py_is_xattr_supported(PyObject *self)
 {
        return Py_True;
@@ -102,7 +101,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
                talloc_free(mem_ctx);
                return NULL;
        }
-       ret = PyString_FromStringAndSize((char *)blob.data, blob.length);
+       ret = PyStr_FromStringAndSize((char *)blob.data, blob.length);
        talloc_free(mem_ctx);
        return ret;
 }
@@ -119,12 +118,22 @@ static PyMethodDef py_posix_eadb_methods[] = {
        { NULL }
 };
 
-void initposix_eadb(void)
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    .m_name = "posix_eadb",
+    .m_doc = "Python bindings for xattr manipulation.",
+    .m_size = -1,
+    .m_methods = py_posix_eadb_methods,
+};
+
+MODULE_INIT_FUNC(posix_eadb)
 {
        PyObject *m;
 
-       m = Py_InitModule3("posix_eadb", py_posix_eadb_methods,
-                          "Python bindings for xattr manipulation.");
+       m = PyModule_Create(&moduledef);
+
        if (m == NULL)
-               return;
+               return NULL;
+
+       return m;
 }
index 6758996da6d2f474d610400ad36f7142041950f0..c5e740fe577ac4154891622e324b19b85897d180 100644 (file)
 */
 
 #include <Python.h>
+#include "python/py3compat.h"
 #include "includes.h"
 #include "librpc/ndr/libndr.h"
 #include "system/filesys.h"
 #include "lib/util/base64.h"
 
-void initxattr_native(void);
-
 static PyObject *py_is_xattr_supported(PyObject *self)
 {
 #if !defined(HAVE_XATTR_SUPPORT)
@@ -91,7 +90,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
                talloc_free(mem_ctx);
                return NULL;
        }
-       ret = PyString_FromStringAndSize(buf, len);
+       ret = PyStr_FromStringAndSize(buf, len);
        talloc_free(mem_ctx);
        return ret;
 }
@@ -108,14 +107,22 @@ static PyMethodDef py_xattr_methods[] = {
        { NULL }
 };
 
-void initxattr_native(void)
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    .m_name = "xattr_native",
+    .m_doc = "Python bindings for xattr manipulation.",
+    .m_size = -1,
+    .m_methods = py_xattr_methods,
+};
+
+MODULE_INIT_FUNC(xattr_native)
 {
        PyObject *m;
 
-       m = Py_InitModule3("xattr_native", py_xattr_methods,
-                          "Python bindings for xattr manipulation.");
+       m = PyModule_Create(&moduledef);
 
        if (m == NULL)
-               return;
-}
+               return NULL;
 
+       return m;
+}
index 56beedb1e5032ce77642248b617a18c9c15a119b..05303b6aa00ab1890c6a9b777488eb429bea2fc6 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include <Python.h>
+#include "python/py3compat.h"
 #include "includes.h"
 #include "system/filesys.h"
 #include <tdb.h>
@@ -32,8 +33,6 @@
 #include "lib/dbwrap/dbwrap_tdb.h"
 #include "source3/lib/xattr_tdb.h"
 
-void initxattr_tdb(void);
-
 static PyObject *py_is_xattr_supported(PyObject *self)
 {
        return Py_True;
@@ -138,7 +137,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
                talloc_free(mem_ctx);
                return NULL;
        }
-       ret_obj = PyString_FromStringAndSize((char *)blob.data, xattr_size);
+       ret_obj = PyStr_FromStringAndSize((char *)blob.data, xattr_size);
        talloc_free(mem_ctx);
        return ret_obj;
 }
@@ -155,13 +154,23 @@ static PyMethodDef py_xattr_methods[] = {
        { NULL }
 };
 
-void initxattr_tdb(void)
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    .m_name = "xattr_tdb",
+    .m_doc = "Python bindings for xattr manipulation.",
+    .m_size = -1,
+    .m_methods = py_xattr_methods,
+};
+
+MODULE_INIT_FUNC(xattr_tdb)
 {
        PyObject *m;
 
-       m = Py_InitModule3("xattr_tdb", py_xattr_methods,
-                          "Python bindings for xattr manipulation.");
+       m = PyModule_Create(&moduledef);
+
        if (m == NULL)
-               return;
+               return NULL;
+
+       return m;
 }
 
index a07da33484b160e8a662e37929c29a20106a2ad9..eac2dfc68e486f0ff4e23926ee1831a60867667a 100644 (file)
@@ -41,27 +41,29 @@ if bld.CONFIG_SET('WITH_NTVFS_FILESERVER'):
     )
 
 
-bld.SAMBA_PYTHON('python_xattr_native',
-       source='python/pyxattr_native.c',
-       deps='ndr ldb samdb samba-credentials pyparam_util attr',
-       realname='samba/xattr_native.so'
-       )
-
 bld.SAMBA_LIBRARY('posix_eadb',
                   source='posix_eadb.c',
                   deps='tdb tdb-wrap samba-util',
                   autoproto='posix_eadb_proto.h',
                   private_library=True)
 
-bld.SAMBA_PYTHON('python_posix_eadb',
+for env in bld.gen_python_environments():
+    pyparam_util = bld.pyembed_libname('pyparam_util')
+
+    bld.SAMBA_PYTHON('python_xattr_native',
+        source='python/pyxattr_native.c',
+        deps='ndr ldb samdb samba-credentials %s attr' % pyparam_util,
+        realname='samba/xattr_native.so'
+        )
+
+    bld.SAMBA_PYTHON('python_posix_eadb',
        source='python/pyposix_eadb.c',
-       deps='pyparam_util posix_eadb tdb',
+       deps='%s posix_eadb tdb' % pyparam_util,
        realname='samba/posix_eadb.so'
        )
 
-bld.SAMBA_PYTHON('python_xattr_tdb',
+    bld.SAMBA_PYTHON('python_xattr_tdb',
        source='python/pyxattr_tdb.c',
-       deps='pyparam_util xattr_tdb',
+       deps='%s xattr_tdb' % pyparam_util,
        realname='samba/xattr_tdb.so'
        )
-