embedding on aix

apolloner apolloner at bap.at
Tue Mar 25 09:27:56 CET 2003


the following code works well :

#include "/usr/local/include/python2.1/Python.h"
int main(int argc, char ** argv)
{
    PyObject * module;
    PyObject * function;
    PyObject * result;
    int cresult;

    if (argc != 2)
    {
        printf("Usage: test1 <arg1> \n");
        exit(-1);
    } /* if */


    Py_Initialize();
    module = PyImport_ImportModule("apo");
    if (PyObject_HasAttrString(module, "apo"))
    {
        function = PyObject_GetAttrString(module, "apo");
        if (PyCallable_Check(function))
        {
            result = PyObject_CallFunction(function, "s",argv[1]);
       printf("%s",PyString_AsString(result));
        }
        else
        {
            printf("Error -- attribute is not a function/method\n");
        } /* if */
    }
    else
    {
        printf("Error -- Module does not contain \"apo\" function.\n");
    } /* if */ Py_Exit(0);
} 
  
apo.py :
def apo(s) :
    return s

... but when i try to import  a module :

apo.py :
from string import *
def apo(s):
   return s

I get a Segmentation fault :

Segmentation fault in stropmodule.split_whitespace at 0xd066eed8 ($t1)
0xd066eed8 (split_whitespace+0x294) 800c0000        lwz   r0,0x0(r12)
(dbx) where
stropmodule.split_whitespace() at 0xd066eed8
initstrop() at 0xd066c228
_PyImport_LoadDynamicModule() at 0x1006f7e0
load_module() at 0x10054c54
import_submodule() at 0x1005386c
load_next() at 0x10053d74
import_module_ex() at 0x100534e8
PyImport_ImportModuleEx() at 0x10056718
builtin___import__() at 0x1007ee00
call_cfunction() at 0x100322f0
call_object() at 0x1003236c
PyEval_CallObjectWithKeywords() at 0x10038958
eval_code2() at 0x10036858
PyEval_EvalCode() at 0x10037ebc
PyImport_ExecCodeModuleEx() at 0x10056a60
load_source_module() at 0x10054ee4
import_submodule() at 0x1005386c
load_next() at 0x10053d74
import_module_ex() at 0x100534e8
PyImport_ImportModuleEx() at 0x10056718
builtin___import__() at 0x1007ee00
call_cfunction() at 0x100322f0
call_object() at 0x1003236c
PyEval_CallObjectWithKeywords() at 0x10038958
eval_code2() at 0x10036858
PyEval_EvalCode() at 0x10037ebc
PyImport_ExecCodeModuleEx() at 0x10056a60
load_source_module() at 0x10054ee4
import_submodule() at 0x1005386c
load_next() at 0x10053d74
import_module_ex() at 0x100534e8
PyImport_ImportModuleEx() at 0x10056718
builtin___import__() at 0x1007ee00
call_cfunction() at 0x100322f0
call_object() at 0x1003236c
PyEval_CallObjectWithKeywords() at 0x10038958
PyObject_CallObject() at 0x100289e0
PyObject_CallFunction() at 0x10028934
PyImport_Import() at 0x10056624
PyImport_ImportModule() at 0x10056764
main(argc = 2, argv = 0x2ff225fc), line 22 in "t.c"

any hint ? or do you need more information 
thanks
udo

 




More information about the Python-list mailing list