1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 /* make Python.h go first as a hack to work around _POSIX_C_SOURCE redefinition
24 #include <sal/config.h>
29 #if defined LINUX && !defined __USE_GNU
34 #include <rtl/string.h>
36 /* A wrapper around libpyuno.so, making sure the latter is loaded RTLD_GLOBAL
37 so that C++ exception handling works with old GCC versions (that determine
38 RTTI identity by comparing string addresses rather than string content).
41 static void * load(void const * address
, char const * symbol
) {
48 if (dladdr(address
, &dl_info
) == 0) {
51 slash
= strrchr(dl_info
.dli_fname
, '/');
55 len
= slash
- dl_info
.dli_fname
+ 1;
57 len
+ RTL_CONSTASCII_LENGTH(SAL_DLLPREFIX
"pyuno" SAL_DLLEXTENSION
)
59 if (libname
== NULL
) {
62 strncpy(libname
, dl_info
.dli_fname
, len
);
63 strcpy(libname
+ len
, SAL_DLLPREFIX
"pyuno" SAL_DLLEXTENSION
);
64 h
= dlopen(libname
, RTLD_LAZY
| RTLD_GLOBAL
);
67 fprintf(stderr
, "failed to load pyuno: '%s'\n", dlerror());
70 func
= dlsym(h
, symbol
);
75 // coverity[leaked_storage] - this is on purpose
79 #if PY_MAJOR_VERSION >= 3
81 SAL_DLLPUBLIC_EXPORT PyObject
* PyInit_pyuno(void) {
83 ((PyObject
* (*)(void)) load((void *) &PyInit_pyuno
, "PyInit_pyuno"))();
88 SAL_DLLPUBLIC_EXPORT
void initpyuno(void) {
89 ((void (*)(void)) load((void *) &initpyuno
, "initpyuno"))();
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */