python: Port samba.messaging module to Python 3 compatible form.
authorLumir Balhar <lbalhar@redhat.com>
Thu, 14 Sep 2017 07:30:28 +0000 (09:30 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 23 Oct 2017 09:42:19 +0000 (11:42 +0200)
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/lib/messaging/pymessaging.c
source4/lib/messaging/wscript_build
source4/librpc/wscript_build

index d83f5e6a63790d99016833d77fc8c1d99adcea42..6e64bb9a0600255199dd58a3a3abd2dcdd2c71e5 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include <Python.h>
+#include "python/py3compat.h"
 #include "includes.h"
 #include "python/modules.h"
 #include "libcli/util/pyerrors.h"
@@ -36,7 +37,6 @@
 #include <pytalloc.h>
 #include "messaging_internal.h"
 
-void initmessaging(void);
 
 extern PyTypeObject imessaging_Type;
 
@@ -493,7 +493,7 @@ static PyGetSetDef py_imessaging_getset[] = {
 
 
 PyTypeObject imessaging_Type = {
-       PyObject_HEAD_INIT(NULL) 0,
+       PyVarObject_HEAD_INIT(NULL, 0)
        .tp_name = "messaging.Messaging",
        .tp_basicsize = sizeof(imessaging_Object),
        .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
@@ -505,19 +505,29 @@ PyTypeObject imessaging_Type = {
                  "Create a new object that can be used to communicate with the peers in the specified messaging path.\n"
 };
 
-void initmessaging(void)
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    .m_name = "messaging",
+    .m_doc = "Internal RPC",
+    .m_size = -1,
+    .m_methods = NULL,
+};
+
+MODULE_INIT_FUNC(messaging)
 {
        PyObject *mod;
 
        if (PyType_Ready(&imessaging_Type) < 0)
-               return;
+               return NULL;
 
-       mod = Py_InitModule3("messaging", NULL, "Internal RPC");
+       mod = PyModule_Create(&moduledef);
        if (mod == NULL)
-               return;
+               return NULL;
 
        Py_INCREF((PyObject *)&imessaging_Type);
        PyModule_AddObject(mod, "Messaging", (PyObject *)&imessaging_Type);
        PyModule_AddObject(mod, "IRPC_CALL_TIMEOUT", PyInt_FromLong(IRPC_CALL_TIMEOUT));
        PyModule_AddObject(mod, "IRPC_CALL_TIMEOUT_INF", PyInt_FromLong(IRPC_CALL_TIMEOUT_INF));
+
+       return mod;
 }
index 2b6cf81885c0de3061049c1f562d5dcf2685f573..4929ccdf51566884d325c969ded47927164f0679 100644 (file)
@@ -13,9 +13,13 @@ bld.SAMBA_LIBRARY('MESSAGING',
        private_library=True
        )
 
-bld.SAMBA_PYTHON('python_messaging',
-       source='pymessaging.c',
-       deps='MESSAGING events pyparam_util pytalloc-util',
-       realname='samba/messaging.so'
-       )
+for env in bld.gen_python_environments():
+
+       pyparam_util = bld.pyembed_libname('pyparam_util')
+       pytalloc_util = bld.pyembed_libname('pytalloc-util')
 
+       bld.SAMBA_PYTHON('python_messaging',
+               source='pymessaging.c',
+               deps='MESSAGING events pyparam_util pytalloc-util',
+               realname='samba/messaging.so'
+               )
index 1c3f8dedd15212c02e3107fef0bcc34b609babfc..eed0551824b2589a282da332f03af43400de0664 100644 (file)
@@ -338,7 +338,7 @@ for env in bld.gen_python_environments():
 
        bld.SAMBA_PYTHON('python_irpc',
                source='gen_ndr/py_irpc.c',
-               deps='RPC_NDR_IRPC pytalloc-util pyrpc_util',
+               deps='RPC_NDR_IRPC %s %s' % (pytalloc_util, pyrpc_util),
                realname='samba/dcerpc/irpc.so'
                )