diff options
author | Lumir Balhar <lbalhar@redhat.com> | 2017-08-08 11:50:30 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2017-08-22 17:38:17 +0200 |
commit | 0ffe030c0dcd46b51ffb2f11c03d5b48e93d32b9 (patch) | |
tree | b1ea188cdc7f0ca8260f9cdea2547db7eb153fee /source4/scripting | |
parent | 051a3ff6eb7dad08202b13aadbc6829370cc3f4b (diff) | |
download | samba-0ffe030c0dcd46b51ffb2f11c03d5b48e93d32b9.tar.gz |
python: Make generated modules samba.ntstatus and samba.werror Python 3 compatible.
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Tue Aug 22 17:38:17 CEST 2017 on sn-devel-144
Diffstat (limited to 'source4/scripting')
-rwxr-xr-x | source4/scripting/bin/gen_ntstatus.py | 16 | ||||
-rwxr-xr-x | source4/scripting/bin/gen_werror.py | 16 |
2 files changed, 24 insertions, 8 deletions
diff --git a/source4/scripting/bin/gen_ntstatus.py b/source4/scripting/bin/gen_ntstatus.py index 3267c3295ad..9e92f49fc1b 100755 --- a/source4/scripting/bin/gen_ntstatus.py +++ b/source4/scripting/bin/gen_ntstatus.py @@ -70,6 +70,7 @@ def generatePythonFile(out_file, errors): out_file.write(" * [MS-ERREF] http://msdn.microsoft.com/en-us/library/cc704588.aspx\n") out_file.write(" */\n") out_file.write("#include <Python.h>\n") + out_file.write("#include \"python/py3compat.h\"\n") out_file.write("#include \"includes.h\"\n\n") out_file.write("static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)\n"); out_file.write("{\n"); @@ -82,17 +83,24 @@ def generatePythonFile(out_file, errors): # This is needed to avoid a missing prototype error from the C # compiler. There is never a prototype for this function, it is a # module loaded by python with dlopen() and found with dlsym(). - out_file.write("void initntstatus(void);\n") - out_file.write("void initntstatus(void)\n") + out_file.write("static struct PyModuleDef moduledef = {\n") + out_file.write("\tPyModuleDef_HEAD_INIT,\n") + out_file.write("\t.m_name = \"ntstatus\",\n") + out_file.write("\t.m_doc = \"NTSTATUS error defines\",\n") + out_file.write("\t.m_size = -1,\n") + out_file.write("};\n\n") + out_file.write("MODULE_INIT_FUNC(ntstatus)\n") out_file.write("{\n") out_file.write("\tPyObject *m;\n\n") - out_file.write("\tm = Py_InitModule3(\"ntstatus\", NULL, \"NTSTATUS error defines\");\n"); + out_file.write("\tm = PyModule_Create(&moduledef);\n"); out_file.write("\tif (m == NULL)\n"); - out_file.write("\t\treturn;\n\n"); + out_file.write("\t\treturn NULL;\n\n"); for err in errors: line = """\tPyModule_AddObject(m, \"%s\", \t\tndr_PyLong_FromUnsignedLongLong(NT_STATUS_V(%s)));\n""" % (err.err_define, err.err_define) out_file.write(line) + out_file.write("\n"); + out_file.write("\treturn m;\n"); out_file.write("}\n"); def transformErrorName( error_name ): diff --git a/source4/scripting/bin/gen_werror.py b/source4/scripting/bin/gen_werror.py index 9a545726ba5..96611ae7eaa 100755 --- a/source4/scripting/bin/gen_werror.py +++ b/source4/scripting/bin/gen_werror.py @@ -72,6 +72,7 @@ def generatePythonFile(out_file, errors): out_file.write(" * [MS-ERREF] https://msdn.microsoft.com/en-us/library/cc231199.aspx\n") out_file.write(" */\n") out_file.write("#include <Python.h>\n") + out_file.write("#include \"python/py3compat.h\"\n") out_file.write("#include \"includes.h\"\n\n") out_file.write("static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)\n"); out_file.write("{\n"); @@ -84,17 +85,24 @@ def generatePythonFile(out_file, errors): # This is needed to avoid a missing prototype error from the C # compiler. There is never a prototype for this function, it is a # module loaded by python with dlopen() and found with dlsym(). - out_file.write("void initwerror(void);\n") - out_file.write("void initwerror(void)\n") + out_file.write("static struct PyModuleDef moduledef = {\n") + out_file.write("\tPyModuleDef_HEAD_INIT,\n") + out_file.write("\t.m_name = \"werror\",\n") + out_file.write("\t.m_doc = \"WERROR defines\",\n") + out_file.write("\t.m_size = -1,\n") + out_file.write("};\n\n") + out_file.write("MODULE_INIT_FUNC(werror)\n") out_file.write("{\n") out_file.write("\tPyObject *m;\n\n") - out_file.write("\tm = Py_InitModule3(\"werror\", NULL, \"WERROR defines\");\n"); + out_file.write("\tm = PyModule_Create(&moduledef);\n"); out_file.write("\tif (m == NULL)\n"); - out_file.write("\t\treturn;\n\n"); + out_file.write("\t\treturn NULL;\n\n"); for err in errors: line = """\tPyModule_AddObject(m, \"%s\", \t\tndr_PyLong_FromUnsignedLongLong(W_ERROR_V(%s)));\n""" % (err.err_define, err.err_define) out_file.write(line) + out_file.write("\n"); + out_file.write("\treturn m;\n"); out_file.write("}\n"); def transformErrorName( error_name ): |