[Pyrex] Pyrex questions
Greg Ewing
greg at cosc.canterbury.ac.nz
Wed Jun 2 03:14:35 CEST 2004
Tom Kobialka <u3356514 at anu.edu.au>:
> Is there a searchable online mailing list archive available for
> Pyrex?
No, there isn't, sorry.
> I am encapsulating a small C program that makes use of a very specific
> gravitational wave frame library. I want to call the routines in the
> library from my C program. Do I have to encapsulate the library in
> Pyrex in order to call it from my encapsulated C program?
I'm a bit confused about what you're trying to do. If the
gravitational wave library is only called through your C code, and
never directly from Python, you should only have to wrap your C code,
i.e.
Python -> Pyrex wrapper for your C code -> your C code -> Library
> it doesn't seem to mention C routines and procedures such as atoi,
> malloc, opendir (dirent.h), casting or nesting i.e monkey = (char *)
> malloc(strlen(banana) + strlen(paddlepop->chocolate))
Any C routine can be called from Pyrex if you declare it appropriately
in a 'cdef extern from' block; see the section on "Interfacing with
External C Code". Casting is possible, bit with a slightly different
syntax; see "Differences between C and Pyrex expression syntax".
Your example would be translated into Pyrex as follows:
cdef extern from "stdlib.h":
void *malloc(int len)
cdef extern from "string.h":
int strlen(char *)
# suitable definitions here for monkey, banana,
# paddleop and chocolate
monkey = <char *> malloc(strlen(banana) +
strlen(paddlepop.chocolate))
> Does anyone have a small sized (300 + line) C program and
> corresponding pyrex code
Have you looked at Michael's Quick Guide to Pyrex? It contains
a couple of examples of wrapping real-world C libraries.
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg at cosc.canterbury.ac.nz +--------------------------------------+
More information about the Pyrex
mailing list