Calling stdlib functions from pyrex

Clark C . Evans cce at clarkevans.com
Thu Jul 4 18:41:00 EDT 2002


On Thu, Jul 04, 2002 at 05:34:45PM -0400, Clark C . Evans wrote:
| Hello.  This pyrex stuff looks like a great tool.  I tried to convert
| the module that I just posted recently, but I ran into a bit of
| difficulty... here is my error message:
| 
|     pyrexc tztool.pyx
|       Unpickling lexicon...
|       Done (0.11 seconds)
|     gcc -c -fPIC -I/usr/local/include/python2.2/ tztool.c
|       tztool.c:21: redefinition of `struct tm'
|       tztool.c:35: conflicting types for `setenv'
|       /usr/include/stdlib.h:123: previous declaration of `setenv'

The problem seems to be that the generated code makes type
declarations.  Is there a way to shut this feature off?  When 
I go into the generated .c file and delete the declarations
everything is happy...  

Great product BTW, I just converted a few other modules
to use pyx without a hitch.  What is superb is that I can
have one .pyx file mixing my .c and my .py stuff instead
of having two files.   This is just outstanding.  Now we
just need to get the python build system to grok .pyx files!

Clark

P.S.  I had _one_ a bug in tztools.pyx (the fact that I 
      could read the instructions and only have one bug
      on the first compile is just great... your 
      documentation is very good).

| ctypedef long time_t
| cdef extern struct tm:
|         int     tm_sec
|         int     tm_min
|         int     tm_hour
|         int     tm_mday
|         int     tm_mon
|         int     tm_year
|         int     tm_wday
|         int     tm_yday
|         int     tm_isdst
|         long    tm_gmtoff
|         char    *tm_zone
| cdef extern void setenv(char *key, char *val, int override)
| cdef extern void unsetenv(char *key)
| cdef extern void tzset()
| cdef extern int  time(time_t *junk)
| cdef extern tm * localtime_r(time_t *now, tm *fill)
| 
| def offset(zone):
|     cdef time_t now
|     cdef tm     a
      setenv("TZ",zone,1)
|     tzset()
|     now = time(<time_t *>0)
|     localtime_r(&now, &a)
|     unsetenv("TZ")
|     tpl = (a.tm_zone,a.tm_gmtoff/60)
|     tzset()
|     return tpl






More information about the Python-list mailing list