Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedding python into shared library crash on AIX #50991

Closed
damahay123 mannequin opened this issue Aug 20, 2009 · 5 comments
Closed

Embedding python into shared library crash on AIX #50991

damahay123 mannequin opened this issue Aug 20, 2009 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@damahay123
Copy link
Mannequin

damahay123 mannequin commented Aug 20, 2009

BPO 6742
Nosy @loewis

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2009-08-20.13:32:01.217>
labels = ['interpreter-core', 'type-crash']
title = 'Embedding python into shared library crash on AIX'
updated_at = <Date 2014-03-23.03:12:47.956>
user = 'https://bugs.python.org/damahay123'

bugs.python.org fields:

activity = <Date 2014-03-23.03:12:47.956>
actor = 'BreamoreBoy'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2009-08-20.13:32:01.217>
creator = 'damahay123'
dependencies = []
files = []
hgrepos = []
issue_num = 6742
keywords = []
message_count = 5.0
messages = ['91773', '91789', '116025', '192851', '214541']
nosy_count = 4.0
nosy_names = ['loewis', 'sable', 'damahay123', 'BreamoreBoy']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'languishing'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue6742'
versions = ['Python 2.6']

@damahay123
Copy link
Mannequin Author

damahay123 mannequin commented Aug 20, 2009

Hi there,
I'm trying to embedding my python code into a .so on AIX and load it
with my main application. Since there is no libpython2.6.so available on
AIX, I have to link my .so with libpython2.6.a. I have to make some
twist to make it compile. And so far so good until I run my main. My
embedding python .so give me error like the following
Fatal Python error: Interpreter not initialized (version mismatch?)
I check the initialization status by calling Py_IsInitialized and it
said yes. So I'm wondering if this embedding python into .so ever work
on AIX.
I have no problem to do the same thing on linux, solaris since python
has libpython2.6.so on both system. But our system needs the supoort on
AIX. My embedding python is very simple like the following

#include <Python.h>
#include <iostream>

extern "C"
void allocate()
{
    std::cout << " am i ok = " << Py_IsInitialized() << std::endl;
    
    Py_InitializeEx(0);
    std::cout << " am i ok 1 = " << Py_IsInitialized() << std::endl;
    
    PyRun_SimpleString("from time import time, datetime, ctime\n"
                       "print 'Today is',ctime(time())\n");
    Py_Finalize();
}

my main application is also very simple
#include <iostream>
#include <iomanip>
#include <dlfcn.h>
//#include <link.h>
#include <Python.h>

typedef  void (*ALLOCATE)();

int main (int argc, char ** argv)
{
    // parse params to load shared object
    if (argc < 2)
    {
	std::cerr << "Usage: " << argv[0] << " sharedObject(s)" << std::endl;
	return 0;
    }

    //    Py_Initialize();
    
    for (int i = 1; i < argc; ++i)
    {
	void * handle = ::dlopen(argv[i], RTLD_LAZY);
	if (!handle)
	{
	    std::cerr << dlerror() << argv[i] << std::endl;
	
	    return 0;
	}
	
	// Use that handle to locate the symbol.  The symbol must be 
	// demangled so it has to be compiled with extern "C".
	ALLOCATE dlmAllocate = (ALLOCATE) ::dlsym(handle, "allocate");
	if (!dlmAllocate)
	{
	    std::cerr << dlerror() << std::endl;
	    return 0;
	}
    
	dlmAllocate();
    }


    return 0;
}

here is my makefile

CXX := g++

default: DLOpenTest mypython.so

DLOpenTest: DLOpen.C
$(CXX) -o DLOpenTest DLOpen.C -ldl
-Wl,-bE:/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/lib/python2.6/config/python.exp
-lld -I/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/include/python2.6
-L/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/lib/ -lpython2.6 -lpthread

mypython.so: mypython.C
$(CXX) -shared -nostartfiles
-I/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/include/python2.6
-L/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/lib/ -lpython2.6 -lpthread -o
mypython.so mypython.C

clean:
rm *.o DLOpenTest mypython.so

Can someone help me out? Or has anyone even tried same thing on AIX?

NOTE, the issue is not like bpo-4434 or 1332869. Please don't reply
this issue with those two number. I've seen them already. It's not helpful

Thanks a log

@damahay123 damahay123 mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Aug 20, 2009
@loewis
Copy link
Mannequin

loewis mannequin commented Aug 20, 2009

If you get differing results from Py_IsInitialized, my guess is that you
managed to link two different copies of the Python VM into your
application, each with its own set of global variables.

An AIX expert would be required to diagnose this in more detail;
unfortunately, we are not aware of any such expert.

@sable
Copy link
Mannequin

sable mannequin commented Sep 10, 2010

You may want to take a look at bpo-941346 in order to compile libpython2.6.so on AIX.

I also embed python in my AIX application, and I had no problem once python was compiled as share thanks to the patch provided in the other issue.

@tiran tiran added the stale Stale PR or inactive for long period of time. label Jul 10, 2013
@sable
Copy link
Mannequin

sable mannequin commented Jul 11, 2013

This issue has been fixed as part of bpo-941346 and should be closed in my opinion.

@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Mar 23, 2014

msg192851 states that this should be closed. If somebody agrees with that statement would they please do the honours.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

2 participants