You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ms...@apache.org on 2020/01/28 14:42:27 UTC

[openoffice] 05/08: pyuno: wrap the right entrypoint for Python 3 in the pyuno dlopen wrapper

This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit bee4b9955243a08e7572e1fc52f40544baf3c55f
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sat Jan 18 10:20:44 2020 +0200

    pyuno: wrap the right entrypoint for Python 3 in the pyuno dlopen wrapper
    
    Patch by: me
    
    (cherry picked from commit 29716487c9dd2d298fa194b73f148072e7f0a3e7)
---
 main/pyuno/Library_pyuno_loader.mk             |  2 ++
 main/pyuno/source/module/pyuno_dlopenwrapper.c | 39 ++++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/main/pyuno/Library_pyuno_loader.mk b/main/pyuno/Library_pyuno_loader.mk
index afbea6f..c13cee7 100644
--- a/main/pyuno/Library_pyuno_loader.mk
+++ b/main/pyuno/Library_pyuno_loader.mk
@@ -38,6 +38,8 @@ else ifeq ($(OS),MACOSX)
 $(eval $(call gb_Library_add_libs,pyuno_loader,-ldl))
 endif
 
+$(call gb_Library_use_external,pyuno_loader,python)
+
 $(eval $(call gb_Library_add_cobjects,pyuno_loader,\
 	pyuno/source/module/pyuno_dlopenwrapper \
 ))
diff --git a/main/pyuno/source/module/pyuno_dlopenwrapper.c b/main/pyuno/source/module/pyuno_dlopenwrapper.c
index beef85b..bb6614c 100644
--- a/main/pyuno/source/module/pyuno_dlopenwrapper.c
+++ b/main/pyuno/source/module/pyuno_dlopenwrapper.c
@@ -21,6 +21,22 @@
 
 
 
+#ifndef Py_PYTHON_H
+#if defined _MSC_VER
+#pragma warning(push, 1)
+#endif
+#ifdef _DEBUG
+#undef _DEBUG
+#include <Python.h>
+#define _DEBUG
+#else
+#include <Python.h>
+#endif // #ifdef _DEBUG
+#if defined _MSC_VER
+#pragma warning(pop)
+#endif
+#endif // #ifdef Py_PYTHON_H
+
 #include <rtl/string.h>
 
 #include <stdlib.h>
@@ -33,12 +49,24 @@
 #endif
 #include <dlfcn.h>
 
+#if PY_MAJOR_VERSION >= 3
+SAL_DLLPUBLIC_EXPORT void* PyInit_pyuno(void)
+#else
 SAL_DLLPUBLIC_EXPORT void initpyuno ()
+#endif
 {
     Dl_info dl_info;
+#if PY_MAJOR_VERSION >= 3
+    void* (*func)(void);
+#else
     void (*func)(void);
+#endif
 
+#if PY_MAJOR_VERSION >= 3
+    if (dladdr((void*)&PyInit_pyuno, &dl_info) != 0) {
+#else
     if (dladdr((void*)&initpyuno, &dl_info) != 0) { 
+#endif
         void* h = 0;
 	size_t len = strrchr(dl_info.dli_fname, '/') - dl_info.dli_fname + 1;
 	char* libname = malloc(len + RTL_CONSTASCII_LENGTH( SAL_DLLPREFIX "pyuno" SAL_DLLEXTENSION ) + 1);
@@ -49,8 +77,15 @@ SAL_DLLPUBLIC_EXPORT void initpyuno ()
 	free(libname);
         if( h )
         {
-            func = (void (*)())dlsym (h, "initpyuno");
-            (func) ();
+#if PY_MAJOR_VERSION >= 3
+            func = (void* (*)(void))dlsym (h, "PyInit_pyuno");
+#else
+            func = (void (*)(void))dlsym (h, "initpyuno");
+#endif
+            return (func) ();
         }
     } 
+#if PY_MAJOR_VERSION >= 3
+    return NULL;
+#endif
 }