tiny extension crashes

Alex Martelli aleaxit at yahoo.com
Thu Mar 15 07:35:12 EST 2001


"John J. Lee" <phrxy at csv.warwick.ac.uk> wrote in message
news:Pine.SOL.4.30.0103141957240.10526-100000 at mimosa.csv.warwick.ac.uk...
>
> I've been using a tiny little C extension module that I wrote for a while
    [snip]
>     double number;
>     double *intp;
>
>     if (!PyArg_ParseTuple(args, "d", &number))
>         return NULL;
>     if (fabs(modf(number, intp)) >= 0.5) {

As others have noted, THIS is your problem -- I just wanted
to underscore that this is a very common C-newbie error: when
a function takes a "whatever*" (pointer-to-whatever) argument,
you need to pass *the address of something* (or possibly, for
some functions, an explicit NULL), *NEVER* a generic and not
initialized variable of type "whatever*".  It's easy to remember:
C arguments are by-value -- all you ARE passing is the VALUE
of the actual argument; passing as actual-argument a variable
is never right unless it's been previously initialized by some
suitable expression being assigned to it (for some reason, this
programming error typically affects the passing of arguments
which are declared to have pointer-type).


Alex






More information about the Python-list mailing list