diff options
author | Lumir Balhar <lbalhar@redhat.com> | 2017-10-24 09:00:11 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2017-11-08 17:57:21 +0100 |
commit | e00ba05d33af9d922fcad7f24bc5814d9145d71a (patch) | |
tree | a41d02228ac362aa1029423b7464f7f0fa6198c7 /source4/ntvfs/posix | |
parent | aed7faeab4b1c701768bb3c56b3f3bbfd2801938 (diff) | |
download | samba-e00ba05d33af9d922fcad7f24bc5814d9145d71a.tar.gz |
python: Port ntvfs posix bindings to Python 3 compatible form
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source4/ntvfs/posix')
-rw-r--r-- | source4/ntvfs/posix/python/pyposix_eadb.c | 23 | ||||
-rw-r--r-- | source4/ntvfs/posix/python/pyxattr_native.c | 23 | ||||
-rw-r--r-- | source4/ntvfs/posix/python/pyxattr_tdb.c | 23 | ||||
-rw-r--r-- | source4/ntvfs/posix/wscript_build | 24 |
4 files changed, 60 insertions, 33 deletions
diff --git a/source4/ntvfs/posix/python/pyposix_eadb.c b/source4/ntvfs/posix/python/pyposix_eadb.c index a94440be3f0..d43c7c47bb7 100644 --- a/source4/ntvfs/posix/python/pyposix_eadb.c +++ b/source4/ntvfs/posix/python/pyposix_eadb.c @@ -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; } diff --git a/source4/ntvfs/posix/python/pyxattr_native.c b/source4/ntvfs/posix/python/pyxattr_native.c index 6758996da6d..c5e740fe577 100644 --- a/source4/ntvfs/posix/python/pyxattr_native.c +++ b/source4/ntvfs/posix/python/pyxattr_native.c @@ -19,13 +19,12 @@ */ #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; +} diff --git a/source4/ntvfs/posix/python/pyxattr_tdb.c b/source4/ntvfs/posix/python/pyxattr_tdb.c index 56beedb1e50..05303b6aa00 100644 --- a/source4/ntvfs/posix/python/pyxattr_tdb.c +++ b/source4/ntvfs/posix/python/pyxattr_tdb.c @@ -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; } diff --git a/source4/ntvfs/posix/wscript_build b/source4/ntvfs/posix/wscript_build index a07da33484b..eac2dfc68e4 100644 --- a/source4/ntvfs/posix/wscript_build +++ b/source4/ntvfs/posix/wscript_build @@ -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' ) - |