1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef Py_PYTHON_H 25 #if defined _MSC_VER 26 #pragma warning(push, 1) 27 #endif 28 #ifdef _DEBUG 29 #undef _DEBUG 30 #include <Python.h> 31 #define _DEBUG 32 #else 33 #include <Python.h> 34 #endif // #ifdef _DEBUG 35 #if defined _MSC_VER 36 #pragma warning(pop) 37 #endif 38 #endif // #ifdef Py_PYTHON_H 39 40 #include <rtl/string.h> 41 42 #include <stdlib.h> 43 #include <string.h> 44 45 #ifdef LINUX 46 # ifndef __USE_GNU 47 # define __USE_GNU 48 # endif 49 #endif 50 #include <dlfcn.h> 51 52 SAL_DLLPUBLIC_EXPORT void* PyInit_pyuno(void) 53 { 54 Dl_info dl_info; 55 void* (*func)(void); 56 57 if (dladdr((void*)&PyInit_pyuno, &dl_info) != 0) { 58 void* h = 0; 59 size_t len = strrchr(dl_info.dli_fname, '/') - dl_info.dli_fname + 1; 60 char* libname = malloc(len + RTL_CONSTASCII_LENGTH( SAL_DLLPREFIX "pyuno" SAL_DLLEXTENSION ) + 1); 61 strncpy(libname, dl_info.dli_fname, len); 62 strcpy(libname + (len), SAL_DLLPREFIX "pyuno" SAL_DLLEXTENSION); 63 64 h = dlopen (libname, RTLD_NOW | RTLD_GLOBAL); 65 free(libname); 66 if( h ) 67 { 68 func = (void* (*)(void))dlsym (h, "PyInit_pyuno"); 69 return (func) (); 70 } 71 } 72 return NULL; 73 } 74