swig-python import error

2008-03-07 Thread abarun22
Hi
I am facing a problem while loading a SWIG generated shared module
from python. The development is under HP-UX 32b platform. I use gcc
version 4.0.2 to build the shared module.  This is how i try to build
the module.

# Compilation
GCC=$GCC -march=1.1
$GCC -v -c -fpic ${ETUDE}.c ${ETUDE}_wrap.c -DDOUBLE_PRECISION -
DDON_DOUBLE_PRECISION  ${PYTHON_INCLUDE_PATH} ${CHAINE_INCLUDE_PATH}

# linking
ld -b binary -g -shared ${ETUDE}.o ${ETUDE}_wrap.o -o _${ETUDE}.so \
-a archive ${LIBS_CHAINE_PATH} -lfichiers_r8 -lmem -lutilitaires -
lsysteme -lcalcul -lmsgml -lcaractere \
-rpath -L/michprojects/ef/deli/Working/Source/deli9-PYAPI/Sandbox/libs/
chaine/PYAPI/don -L/michprojects/ef/deli/Working/Source/deli9-PYAPI/
Sandbox/libs/chaine/hppa_portable-hp-hpux11.11/Debug

The module generated is called _don.so. In addition to that i set the
module path in LD_LIBRARY_PATH environment variable. Th error looks
like as follows.

Import error: module cannot be loaded.

But i am wondering how i am getting import error although every thing
looks OK. Any ideas are most welcome and thanks in advance.
Regards,
Arun
-- 
http://mail.python.org/mailman/listinfo/python-list


How to access nested structural members from python

2007-11-28 Thread abarun22
Hi
I would like to know if there are any ways to access the members of a
nested structure inside python. I use SWIG as interface for C. My
structure comes as follows.
struct SA{
int nb_dep, max_dep
SB *b
}

struct SB{
int id[10], node, kg;
double dep[3];
}

I have written a C helper function like this to access the internal
members of the structure SB.
SB get_sb(SB *b, int index){
 return(b[index]);
}
From python i call like this for example:
modname.get_sb(sb, i).node where i=1,2N

What i would like to know is that any other way to access the internal
pieces of nested structure. Any ideas in this regard are most welcome.
-- 
http://mail.python.org/mailman/listinfo/python-list


C pointer representation in python

2007-11-26 Thread abarun22
Hi
I am new to SWIG and python. I have a problem while trying to call a C
function from Python using SWIG as an interface. The function is
defined as follows.

void* myfunc(TfichierDLR *fichier, char *nom, char *type, char *txt,
char *classe, TicThemeDLR *icTheme, int **num, int *ier)

The last two are output parameters (**num and *ier) and i wonder how
to represent those while calling from python. Especially 'num' being a
double pointer is tricky to handle. Also how can we represent the
return variable which is a null pointer.

I would be extremely pleased to hear any ideas/suggestions in this
regard.

Regards
Arun
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C pointer representation in python

2007-11-26 Thread abarun22
HI
Thanks for the suggestion and i believe that seems a good idea. But
because of some work related constraints i have to use SWIG for the
moment.
Regards
Arun

Terry Reedy wrote:
 [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 | Hi
 | I am new to SWIG and python. I have a problem while trying to call a C
 | function from Python using SWIG as an interface.

 Did you consider using the ctypes module?
 (It is new in the stdlib for 2.5, I believe.)
 Some consider it easier to use than swig.
-- 
http://mail.python.org/mailman/listinfo/python-list


swig-python - shared (vs) static libraries

2007-10-29 Thread abarun22
HI
I am new to SWIG  Python and right now i am in the process of
wrapping some C functionalities present in a static library for
python. I do have my C file name.c which just contains some helper
functions.
I tried to link my object files (e.g name.o  name_wrap.o) with the
static libraries (whose functionalities need to be wrapped) to form a
shared library that can be imported from Python. While doing so i
cannot be able to access the C data structure from Python and i got
all values as zero. I work in Linux gcc version.
I created my shared object like this:
ld -G name.o name_wrap.o -o _name.so -Bstatic -lfoo1 -lfoo2 -lfoo3.
On the other hand to dig more in to this i tried to simulate the
static libraries with simple dummy code in my file name.c so that i
can avoid linking the static libraries. This case i could be able to
retrieve the vaues of the data structure. I wonder if the problem
could be due to linking of the static libraries to create the shared
object.
Any body experienced the same problem or having related ideas pls help
me.
Best regards
Arun

-- 
http://mail.python.org/mailman/listinfo/python-list


swig-python - shared (vs) static libraries

2007-10-29 Thread abarun22
HI
I am new to SWIG  Python and right now i am in the process of
wrapping some C functionalities present in a static library for
python. I do have my C file name.c which just contains some helper
functions.
I tried to link my object files (e.g name.o  name_wrap.o) with the
static libraries (whose functionalities need to be wrapped) to form a
shared library that can be imported from Python. While doing so i
cannot be able to access the C data structure from Python and i got
all values as zero. I work in Linux gcc version.
I created my shared object like this:
ld -G name.o name_wrap.o -o _name.so -Bstatic -lfoo1 -lfoo2 -lfoo3.
On the other hand to dig more in to this i tried to simulate the
static libraries with simple dummy code in my file name.c so that i
can avoid linking the static libraries. This case i could be able to
retrieve the vaues of the data structure. I wonder if the problem
could be due to linking of the static libraries to create the shared
object.
Any body experienced the same problem or having related ideas pls help
me.
Best regards
Arun

-- 
http://mail.python.org/mailman/listinfo/python-list


SWIG-PYTHON - Problem in header file inclusion

2007-10-20 Thread abarun22
Hi
I am facing a problem while including a C header file in the SWIG
interface file.  However the problem does not occur when i directly
copy the contents of header file in the same place.

My interface file read as follows.
/*  interface file dep.i  */
%module dep
%{
#include dep.h
%}
%inline %{
extern int  ReadDep (char* fname, DONfic* don, int nb2, int nb4);
%}

And my header file consists of the structure DONfic as shown below.
/* Header file dep.h */
typedef struct _DONfic {
   intnb_dep, nb_inc_dep, ncasec_dep;
   intmax_dep;
} DONfic;

From python i tried to access the C structure as a python class as
shown below.
/* File pydep.py*/
 import dep
...
 d = dep.DONfic()
Gives the following error message

Traceback (most recent call last):
 File pydep.py, line 5, in ?
   d = dep.DONfic()
AttributeError: 'module' object has no attribute 'DONfic'
The problem is that i cannot get access to the structure if i directly
include the file dep.h. On the other hand if i copy the contents of
the header file and paste it directly in to the header section of the
SWIG interface file it works.
It works for the following interface file .
%module dep
%{
typedef struct _DONfic {
   intnb_dep, nb_inc_dep, ncasec_dep;
   intmax_dep;
} DONfic;
%}
%inline %{
extern int  ReadDep (char* fname, DONfic* don, int nb2, int nb4);
%}


I tried out lot of options and does n't seems to work. Any suggestions
or ideas are most welcome.

-- 
http://mail.python.org/mailman/listinfo/python-list


SWIG-PYTHON - Problem in header file inclusion

2007-10-19 Thread abarun22
Hi
I am facing a problem while including a C header file in the SWIG
interface file.  However the problem does not occur when i directly
copy the contents of header file in the same place.

My interface file read as follows.
/*  interface file dep.i  */
%module dep
%{
#include dep.h
%}
%inline %{
extern int  ReadDep (char* fname, DONfic* don, int nb2, int nb4);
%}

And my header file consists of the structure DONfic as shown below.
/* Header file dep.h */
typedef struct _DONfic {
intnb_dep, nb_inc_dep, ncasec_dep;
intmax_dep;
} DONfic;

From python i tried to access the C structure as a python class as
shown below.
/* File pydep.py*/
 import dep
...
 d = dep.DONfic()
Gives the following error message

Traceback (most recent call last):
  File pydep.py, line 5, in ?
d = dep.DONfic()
AttributeError: 'module' object has no attribute 'DONfic'
The problem is that i cannot get access to the structure if i directly
include the file dep.h. On the other hand if i copy the contents of
the header file and paste it directly in to the header section of the
SWIG interface file it works.
It works for the following interface file .
%module dep
%{
typedef struct _DONfic {
intnb_dep, nb_inc_dep, ncasec_dep;
intmax_dep;
} DONfic;
%}
%inline %{
extern int  ReadDep (char* fname, DONfic* don, int nb2, int nb4);
%}


I tried out lot of options and does n't seems to work. Any suggestions
or ideas are most welcome.

-- 
http://mail.python.org/mailman/listinfo/python-list