[PATCH] libpython and pycom modules Python 3 compatible

Stefan Metzmacher metze at samba.org
Wed Apr 26 13:28:05 UTC 2017


Hi Lumír,

why did you change -bld.SAMBA_SUBSYSTEM('COM',...)?
It's pure C code, we don't need this per python environment.

I don't thing we need tests for pycom, it doesn't do anything useful
currently at all.

I think we could just remove source4/lib/com/pycom.c

Given the simplicity of the PySys_PathPrepend(), I don't think
new tests are required.

Reviewed-by: me for the PySys_PathPrepend patch.

Can someone review and push the attached patchset?

Thanks!
metze

Am 25.04.2017 um 22:08 schrieb Lumir Balhar via samba-technical:
> Hello.
> 
> I ported next two modules to Python 3 compatible form. I know that newly
> ported modules should be tested first and I would like to do it but I
> don't know how to test them. For example, pycom module is used mainly in
> code generated by PIDL. Writing some tests for the py_update_path()
> function in libpython should be simple (using ctypes) but I don't know
> if this is a good approach.
> 
> Thank you and have a nice day.
> 
> Lumír
> 
-------------- next part --------------
From 5e8c4936c49fe11a627b0fe2d9f4b71cb9dbf558 Mon Sep 17 00:00:00 2001
From: Lumir Balhar <lbalhar at redhat.com>
Date: Thu, 20 Apr 2017 15:11:58 +0200
Subject: [PATCH 1/2] python: Port simple libpython module to Python 3
 compatible form

Signed-off-by: Lumir Balhar <lbalhar at redhat.com>
Reviewed-by: Stefan Metzmacher <metze at samba.org>
---
 python/modules.c     |  3 ++-
 python/wscript_build | 18 ++++++++++--------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/python/modules.c b/python/modules.c
index 371f0d5..5db3dd3 100644
--- a/python/modules.c
+++ b/python/modules.c
@@ -18,13 +18,14 @@
 */
 
 #include <Python.h>
+#include "py3compat.h"
 #include "includes.h"
 #include "python/modules.h"
 #include "dynconfig/dynconfig.h"
 
 static bool PySys_PathPrepend(PyObject *list, const char *path)
 {
-	PyObject *py_path = PyString_FromString(path);
+	PyObject *py_path = PyStr_FromString(path);
 	if (py_path == NULL)
 		return false;
 
diff --git a/python/wscript_build b/python/wscript_build
index 87da26f..19881df 100644
--- a/python/wscript_build
+++ b/python/wscript_build
@@ -8,14 +8,6 @@ bld.SAMBA_LIBRARY('samba_python',
 	pyembed=True,
 	enabled=bld.PYTHON_BUILD_IS_ENABLED())
 
-bld.SAMBA_SUBSYSTEM('LIBPYTHON',
-	source='modules.c',
-	public_deps='',
-	init_function_sentinel='{NULL,NULL}',
-	deps='talloc',
-	pyext=True,
-	enabled=bld.PYTHON_BUILD_IS_ENABLED())
-
 for env in bld.gen_python_environments():
 	pytalloc_util = bld.pyembed_libname('pytalloc-util')
 	pyparam_util = bld.pyembed_libname('pyparam_util')
@@ -26,6 +18,16 @@ for env in bld.gen_python_environments():
 		realname='samba/_glue.so'
 		)
 
+	libpython = bld.pyembed_libname('LIBPYTHON')
+
+	bld.SAMBA_SUBSYSTEM(libpython,
+		source='modules.c',
+		public_deps='',
+		init_function_sentinel='{NULL,NULL}',
+		deps='talloc',
+		pyext=True,
+		enabled=bld.PYTHON_BUILD_IS_ENABLED())
+
 if bld.PYTHON_BUILD_IS_ENABLED():
     for env in bld.gen_python_environments():
 	# install out various python scripts for use by make test
-- 
1.9.1


From fcc57bf8052b275018b02813c4254d944722731a Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Wed, 26 Apr 2017 15:25:43 +0200
Subject: [PATCH 2/2] s4:lib/com: remove unused pycom binding

This is completely untested and from reading the code it doesn't really
do anything beside always returning None from the get_class_object() method.

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 source4/lib/com/pycom.c       | 83 -------------------------------------------
 source4/lib/com/wscript_build |  7 ----
 2 files changed, 90 deletions(-)
 delete mode 100644 source4/lib/com/pycom.c

diff --git a/source4/lib/com/pycom.c b/source4/lib/com/pycom.c
deleted file mode 100644
index b445812..0000000
--- a/source4/lib/com/pycom.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   Python bindings for COM library.
-   Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2008
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <Python.h>
-#include "includes.h"
-#include "lib/com/com.h"
-#include "librpc/ndr/libndr.h"
-#include "libcli/util/pyerrors.h"
-
-void initcom(void);
-
-static struct com_context *py_com_ctx = NULL; /* FIXME: evil global */
-
-static PyObject *py_get_class_object(PyObject *self, PyObject *args)
-{
-	char *s_clsid, *s_iid;
-	struct GUID clsid, iid;
-	struct IUnknown *object;
-	NTSTATUS status;
-	WERROR error;
-
-	if (!PyArg_ParseTuple(args, "ss", &s_clsid, &s_iid))
-		return NULL;
-
-	status = GUID_from_string(s_clsid, &clsid);
-	if (!NT_STATUS_IS_OK(status)) {
-		PyErr_FromNTSTATUS(status);
-		return NULL;
-	}
-
-	status = GUID_from_string(s_iid, &iid);
-	if (!NT_STATUS_IS_OK(status)) {
-		PyErr_FromNTSTATUS(status);
-		return NULL;
-	}
-
-	error = com_get_class_object(py_com_ctx, &clsid, &iid, &object);
-	if (!W_ERROR_IS_OK(error)) {
-		PyErr_FromWERROR(error);
-		return NULL;
-	}
-	
-	/* FIXME: Magic, integrate with stubs generated by pidl. */
-
-	Py_RETURN_NONE;
-}
-
-static struct PyMethodDef com_methods[] = {
-	{ "get_class_object", (PyCFunction)py_get_class_object, METH_VARARGS, "S.get_class_object(clsid, iid) -> instance" },
-	{ NULL },
-};
-
-void initcom(void)
-{
-	PyObject *m;
-	WERROR error;
-
-	error = com_init_ctx(&py_com_ctx, NULL);
-	if (!W_ERROR_IS_OK(error)) {
-		PyErr_FromWERROR(error);
-		return;
-	}
-
-	m = Py_InitModule3("com", com_methods, "Simple COM implementation");
-	if (m == NULL)
-		return;
-}
diff --git a/source4/lib/com/wscript_build b/source4/lib/com/wscript_build
index 763de1f..b96f39f 100644
--- a/source4/lib/com/wscript_build
+++ b/source4/lib/com/wscript_build
@@ -26,10 +26,3 @@ bld.SAMBA_MODULE('com_simple',
 	init_function='com_simple_init'
 	)
 
-
-bld.SAMBA_PYTHON('pycom',
-	source='pycom.c',
-	deps='COM',
-	realname='samba/com.so',
-	)
-
-- 
1.9.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20170426/02fe87d0/signature.sig>


More information about the samba-technical mailing list