[Pyrex] when pyrex gets tough

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Sep 3 01:09:45 CEST 2007


David McNab wrote:
> But how do you access extern'ed variables of a struct type?

The same way as any other extern variable. Also, a couple of
helper functions for converting them to/from tuples shouldn't
be hard to arrange.

e.g.

cdef extern from "yuv4mpeg.h":

    ctypedef struct y4m_ratio_t:
       int n
       int d

    y4m_ratio_t y4m_fps_NTSC_FILM
    y4m_ratio_t y4m_fps_FILM
    y4m_ratio_t y4m_fps_PAL

cdef void to_ratio(object tup, y4m_ratio_t *ratio):
    ratio.n = tup[0]
    ratio.d = tup[1]

cdef object from_ratio(y4m_ratio_t ratio):
    return ratio.n, ratio.d

# Make the constants available to Python

fps_NTSC_FILM = from_ratio(y4m_fps_NTSC_FILM)
fps_FILM = from_ratio(y4m_fps_FILM)
fps_PAL = from_ratio(y4m_fps_PAL)


The above code compiles, although I haven't tried
to run it.

--
Greg



More information about the Pyrex mailing list