Patricio Stegmann | 9 Apr 2010 01:57
Picon
Favicon

curiosity

Hello to all,

Do someone know if there is a simpler parser to create python wrappers from c-file-headers or something that is not based on gccxml but simply on parsing the files and creating something usable ?

Thank you for any clue !

Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up now.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
ctypes-users mailing list
ctypes-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ctypes-users
anjali nair | 9 Apr 2010 07:46
Picon

to view output?


Hi Folks,

I am new to ctype.

I tried a very simple wrapping of C using Python. The python version that I am using is Python 2.4.3. I installed ctype 1.0.2 .

The c file hello.c is as follows:
#include<stdio.h>
void hello(char what)
{
printf("hllo");
}

int main()
{
hello('a');
return 0;
}

my setup.py

from ctypes import cdll
hello_lib = cdll.LoadLibrary("hello.so")
hello = hello_lib.hello

I did a gcc -o hello.so -shared -fPIC hello.c

How will I view the output now?


Thanks in advance

--
Anjali M
Student
PSG College of Technology

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
ctypes-users mailing list
ctypes-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ctypes-users
Cun Zhang | 9 Apr 2010 09:28
Picon

Re: to view output?

from ctypes import *
hello_lib = cdll.LoadLibrary("hello.so")
hello = hello_lib.hello
CHAR=(c_char)('a')
hello(CHAR)

On Fri, Apr 9, 2010 at 1:46 PM, anjali nair <anjalinairm <at> gmail.com> wrote:
>
> Hi Folks,
>
> I am new to ctype.
>
> I tried a very simple wrapping of C using Python. The python version that I
> am using is Python 2.4.3. I installed ctype 1.0.2 .
>
> The c file hello.c is as follows:
> #include<stdio.h>
> void hello(char what)
> {
> printf("hllo");
> }
>
> int main()
> {
> hello('a');
> return 0;
> }
>
> my setup.py
>
> from ctypes import cdll
> hello_lib = cdll.LoadLibrary("hello.so")
> hello = hello_lib.hello
>
> I did a gcc -o hello.so -shared -fPIC hello.c
>
> How will I view the output now?
>
>
> Thanks in advance
>
> --
> Anjali M
> Student
> PSG College of Technology
>
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> ctypes-users mailing list
> ctypes-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>
>

--

-- 
Blog: http://www.edwardpku.com/cun

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Thomas Heller | 9 Apr 2010 09:47

Re: curiosity

Patricio Stegmann schrieb:
> Hello to all,
> 

> Do someone know if there is a simpler parser to create python
> wrappers from c-file-headers or something that is not based on gccxml
> but simply on parsing the files and creating something usable ?

Does pyglet have something?  This looks promising (haven't tried it myself):

http://pyglet.googlecode.com/svn/trunk/tools/wraptypes/

--

-- 
Thanks,
Thomas

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
anjali nair | 9 Apr 2010 09:58
Picon

Re: to view output?

Thanks a lot...

On Fri, Apr 9, 2010 at 12:58 PM, Cun Zhang <apzc2529 <at> gmail.com> wrote:
from ctypes import *
hello_lib = cdll.LoadLibrary("hello.so")
hello = hello_lib.hello
CHAR=(c_char)('a')
hello(CHAR)

On Fri, Apr 9, 2010 at 1:46 PM, anjali nair <anjalinairm <at> gmail.com> wrote:
>
> Hi Folks,
>
> I am new to ctype.
>
> I tried a very simple wrapping of C using Python. The python version that I
> am using is Python 2.4.3. I installed ctype 1.0.2 .
>
> The c file hello.c is as follows:
> #include<stdio.h>
> void hello(char what)
> {
> printf("hllo");
> }
>
> int main()
> {
> hello('a');
> return 0;
> }
>
> my setup.py
>
> from ctypes import cdll
> hello_lib = cdll.LoadLibrary("hello.so")
> hello = hello_lib.hello
>
> I did a gcc -o hello.so -shared -fPIC hello.c
>
> How will I view the output now?
>
>
> Thanks in advance
>
> --
> Anjali M
> Student
> PSG College of Technology
>
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> ctypes-users mailing list
> ctypes-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>
>



--
Blog: http://www.edwardpku.com/cun



--
Anjali M
Student
PSG College of Technology

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
ctypes-users mailing list
ctypes-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ctypes-users
Thomas Heller | 9 Apr 2010 10:02

Re: feature request for setting _pack_ to a higher value

Axel Seibert schrieb:
> Hi, Thomas!
> 
> I tried to apply your solution to my problem. I found two issues with that:
> a) a couple of my structs that require padding are Unions. Do you have a solution for that?
> b) I believe that line "missing = a - size % a" needs to be replaced by missing = a - sizeof(t) % a

Axel - sorry for this delayed reply; I'm very short on time.  Is the question
still open or did you find a solution yourself in the meantime?

--

-- 
Thanks,
Thomas

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Axel Seibert | 11 Apr 2010 11:46

Re: feature request for setting _pack_ to a higher value

Hi, Thomas!

Thanx for asking -- no, I have not found any other solution yet.

So long,
Axel

Am 09.04.2010 um 10:02 schrieb Thomas Heller:

> Axel Seibert schrieb:
>> Hi, Thomas!
>> 
>> I tried to apply your solution to my problem. I found two issues with that:
>> a) a couple of my structs that require padding are Unions. Do you have a solution for that?
>> b) I believe that line "missing = a - size % a" needs to be replaced by missing = a - sizeof(t) % a
> 
> Axel - sorry for this delayed reply; I'm very short on time.  Is the question
> still open or did you find a solution yourself in the meantime?
> 
> -- 
> Thanks,
> Thomas
> 
> 
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> ctypes-users mailing list
> ctypes-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
> 

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Thomas Heller | 13 Apr 2010 22:01

Re: feature request for setting _pack_ to a higher value

Axel Seibert schrieb:
> Hi, Thomas!
> 
> Thanx for asking -- no, I have not found any other solution yet.

Ok, so the remaining question was:  How can I change a (generated) ctypes Union
definition so that the packing is a multiple of an arbitrary value, 8 in this case.

Background:  A Union contains all the _fields_ in the same memory block (they overlay
each other; only one is normally valid), so the Union size is the size of the largest
field.  We have now the goal to bring the union size up to a multiple of 8 by adding
a dummy field.  Here is the ode that I wrote:

<snip>
from ctypes import *

def fill_union(value, fields):
    size = 0
    for name, typ in fields:
        size = max(size, sizeof(typ))
    delta = 8 - size % 8
    return fields + [("", c_char * (size + delta))]

class X(Union):
    _fields_ = fill_union(8, [("a", c_char),
                              ("b", c_short),
                              ("c", c_char * 31)])

print sizeof(X)
<snip/>

> So long,
> Axel
> 
> Am 09.04.2010 um 10:02 schrieb Thomas Heller:
> 
>> Axel Seibert schrieb:
>>> Hi, Thomas!
>>> 
>>> I tried to apply your solution to my problem. I found two issues with that:
>>> a) a couple of my structs that require padding are Unions. Do you have a solution for that?
>>> b) I believe that line "missing = a - size % a" needs to be replaced by missing = a - sizeof(t) % a
>> 
>> Axel - sorry for this delayed reply; I'm very short on time.  Is the question
>> still open or did you find a solution yourself in the meantime?
>> 
>> -- 
>> Thanks,
>> Thomas
>> 
>> 
>> ------------------------------------------------------------------------------
>> Download Intel&#174; Parallel Studio Eval
>> Try the new software tools for yourself. Speed compiling, find bugs
>> proactively, and fine-tune applications for parallel performance.
>> See why Intel Parallel Studio got high marks during beta.
>> http://p.sf.net/sfu/intel-sw-dev
>> _______________________________________________
>> ctypes-users mailing list
>> ctypes-users <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>> 
> 
> 
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev

--

-- 
Thanks,
Thomas

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Axel Seibert | 14 Apr 2010 22:01

Re: feature request for setting _pack_ to a higher value

Hi, Thomas!

Thanx for your suggestion. I took your code and changed my union definition. I believe your code has an issue
if size happens to be the same as value (8 in our example), because then modulo operation in the line delta = 8
- size % 8 yields 0, and then delta is set to 8, while it actually should be 0. Right?

So, the original fill_union raises the following exception:
Assert sizeof(N13ARValueStruct3DOT_1E) == 8, sizeof(N13ARValueStruct3DOT_1E
AssertionError: 16

After changing the logic to return the fields unchanged in case size == value, I get another exception:
assert alignment(N13ARValueStruct3DOT_1E) == 8, alignment(N13ARValueStruct3DOT_1E)
AssertionError: 4

So, while the size is now calculated ok, the alignment still is not ok. 
Any thoughts?

Thanx,
Axel

Am 13.04.2010 um 22:01 schrieb Thomas Heller:

> Axel Seibert schrieb:
>> Hi, Thomas!
>> 
>> Thanx for asking -- no, I have not found any other solution yet.
> 
> Ok, so the remaining question was:  How can I change a (generated) ctypes Union
> definition so that the packing is a multiple of an arbitrary value, 8 in this case.
> 
> Background:  A Union contains all the _fields_ in the same memory block (they overlay
> each other; only one is normally valid), so the Union size is the size of the largest
> field.  We have now the goal to bring the union size up to a multiple of 8 by adding
> a dummy field.  Here is the ode that I wrote:
> 
> <snip>
> from ctypes import *
> 
> def fill_union(value, fields):
>    size = 0
>    for name, typ in fields:
>        size = max(size, sizeof(typ))
>    delta = 8 - size % 8
>    return fields + [("", c_char * (size + delta))]
> 
> class X(Union):
>    _fields_ = fill_union(8, [("a", c_char),
>                              ("b", c_short),
>                              ("c", c_char * 31)])
> 
> print sizeof(X)
> <snip/>
> 
>> So long,
>> Axel
>> 
>> Am 09.04.2010 um 10:02 schrieb Thomas Heller:
>> 
>>> Axel Seibert schrieb:
>>>> Hi, Thomas!
>>>> 
>>>> I tried to apply your solution to my problem. I found two issues with that:
>>>> a) a couple of my structs that require padding are Unions. Do you have a solution for that?
>>>> b) I believe that line "missing = a - size % a" needs to be replaced by missing = a - sizeof(t) % a
>>> 
>>> Axel - sorry for this delayed reply; I'm very short on time.  Is the question
>>> still open or did you find a solution yourself in the meantime?
>>> 
>>> -- 
>>> Thanks,
>>> Thomas
>>> 
>>> 
>>> ------------------------------------------------------------------------------
>>> Download Intel&#174; Parallel Studio Eval
>>> Try the new software tools for yourself. Speed compiling, find bugs
>>> proactively, and fine-tune applications for parallel performance.
>>> See why Intel Parallel Studio got high marks during beta.
>>> http://p.sf.net/sfu/intel-sw-dev
>>> _______________________________________________
>>> ctypes-users mailing list
>>> ctypes-users <at> lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>>> 
>> 
>> 
>> ------------------------------------------------------------------------------
>> Download Intel&#174; Parallel Studio Eval
>> Try the new software tools for yourself. Speed compiling, find bugs
>> proactively, and fine-tune applications for parallel performance.
>> See why Intel Parallel Studio got high marks during beta.
>> http://p.sf.net/sfu/intel-sw-dev
> 
> 
> -- 
> Thanks,
> Thomas
> 
> 
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> ctypes-users mailing list
> ctypes-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
> 

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Paul Northug | 16 Apr 2010 09:44
Picon

.so interdependencies

Hello,

I would like to load a .so on Linux that I made myself (g++ -shared
*.o -o libmytest.so).

I can compile and run C programs against this .so, but when I try to
load it using ctypes:

test = cdll.LoadLibrary('libmytest.so')

I get an error:

libmytest.so: undefined symbol: slamch_

which is a function in a different library .so that is used by a
function in my library.

They are both in LD_LIBRARY_PATH. Is there a way to resolve this? I
have the freedom of creating the library, if that helps, but I don't
know much about shared libraries and how the dependencies between
libraries get resolved. Did I build my .so correctly given that it
works fine in other C programs that use it?

I have read one other post describing a similar problem but it didn't
seem to have gotten resolved.

Thanks,
Pål

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

Gmane