[Pyrex] Pyrex doesn't recognize a declared variable...
Brian Myers
tarkawebfoot at charter.net
Fri Feb 24 06:02:34 CET 2006
I'm trying to wrap the decNumber library with Pyrex and have had
pretty good success so far. There's only one last problem showing up.
I have an extension class defined like this:
In a .pxd file:
cdef extern from "decNumber.h":
ctypedef struct decNumber:
int32_t digits #/* Count of digits in the
coefficient; >0 */
int32_t exponent #/* Unadjusted exponent, unbiased,
in */
#/* range: -1999999997 through 999999999 */
uint8_t bits #/* Indicator bits (see above) */
char *lsu
In a .pyx file:
cdef class oetl_decimal:
.
.
.
cdef void set_buffer(self, decNumber *buffer):
if buffer[0].digits > self.context.ctx.digits:
raise InvalidOperation("Context precision is too low
to set buffer.")
decNumberRescale(self.buffer, buffer,
self.context.decScale, &self.context.ctx)
self.context.c_assert()
.
.
.
def normalized(self):
cdef decNumber *tmp
tmp = <decNumber *> alloca(128)
decNumberNormalize(tmp, self.buffer, &self.context.ctx)
self.context.c_assert()
res = oetl_decimal(self.context)
res.set_buffer(tmp)
return res
When I compile, Pyrex complains in the call to res.set_buffer
(tmp) above that it can't convert a decNumber (*) to a python object.
But tmp is cdef'ed as a decNumber * and set_buffer is cdef'ed to
accept a decNumber * as its second parameter.
Am I doing something stupid and obvious here? I've tried a
couple of things, including looking at the generated code (which
looks OK to me), and discovered that Pyrex seems to know tmp is a
decNumber *. It doesn't seem to realize the set_buffer's second
argument is a decNumber *.
Any help appreciated
Brian
More information about the Pyrex
mailing list