hai,
This is punitha.Iam having some doubts
regarding python (python extending with c).In our
application python is used as a glue language.It is used to call c
funcions(which is in the form of dlls).Once a c function
is called,Pyhton variable receives the return value and it passes that
value to the next c function.Python is linked
with c using swig.Swig is an automatic wrapper interface generator
which contains only the function declaration.
Our main aim is to allow the user to write
his own code and link it with
the provided primitive functions(C functions). We tried this in two
ways.
- User writes his own code in C language in the form of DLL and then
it is linked with other primitive function(C
function) using python.
- User writes his own code in python itself and it is linked with the
other primitive blocks.
My problem is with the second try,where user writes their own code.
1.In python code,C function will be called and the value returned by
that function will be used in the python code.In my
case,the c function returns an array,python is receiving the address
and printing only the address not the value.
I dont know how to get those array values and use it in python.
This problem exist in both the linux and windows version.I have given
an example below which i tried in linux.
/***********************(C function which returns an array)
-(last.c)*****************/
#include<stdio.h>
int* new_last()
{
int a[10];
int i,j=0;
for(i=0;i<=5;i++)
{
a=1+j;
//printf("%d\n",a);
j++;
}
return(a);
}
/***************************************************************************************/
/**************************swig
file-(last.i)*****************************************/
%module last
%inline %{
int *new_last();
%}
/****************************************************************************************/
/**************************python
file(files.py)*****************************************/
#!/usr/local/bin/python
import last #HERE IAM CALLING THE C FUNCTION AND
PRINTING THE RETURNED ARRAY.
k=last.new_last()
print k
/**********************************************************************************************************/
Here the c file(last.c) and the interface file(last.i) is
created,compiled and .so files are created.
Also the python file(files.py) is created and executed.
/**********************************************************************************************************/
[punitha@sys-23 lasttry]$ vi last.c
[punitha@sys-23 lasttry]$ vi last.i
[punitha@sys-23 lasttry]$ vi files.py
[punitha@sys-23 lasttry]$ swig -python last.i
[punitha@sys-23 lasttry]$ gcc -c last.c last_wrap.c
\-I/usr/include/python2.3
[punitha@sys-23 lasttry]$ ld -shared last.o last_wrap.o -o _last.so
[punitha@sys-23 lasttry]$ chmod +x files.py
[punitha@sys-23 lasttry]$ python files.py
_e07decfe_p_int
[punitha@sys-23 lasttry]$
/************************************************************************************************************/
When i run python files.py command,it is returning the starting address
of the array.How to get the array value
from this address in python?
2.Python is not supporting long double.But in our application we need
long double.Is there any solution to get it?
3.Is it possible to call a c function(which is in the form of exe)
residing in turbo C from python?
DLL calling from python is working both in windows(vc++) and linux.If
it is possible to call an exe from python in
vc++,then i can do it in turbo c.I failed in calling an exe from
python.Is it possible to call an exe from python?
4.Is there any book available for Python extention & embedding with C?
Please give me some suggestion regarding this.
----regards
punitha