PyFloat_AsDouble broken with RedHat 6.x???

Tim Peters tim_one at email.msn.com
Sun Sep 26 22:42:24 EDT 1999


[Norbert Pirzkal]
> 	I am having a strange problem with some of my (swigged) C
> extension to Python.
> 	I have a function which does the following (somewhat simplified...):
>
> static  PyObject test(PyObject *self, PyObject *args) {
> ...
>     PyObject * _resultobj;
>     char * _argc0 ;
>     PyObject * _obj2 ;
>     PyObject * _obj3 ;
>     PyObject * _obj4 ;
>     double *dtmp;
> ...
> PyArg_ParseTuple(args,"sOOO:fits_write_key",&_argc0,&_obj2,
> &_obj3,&_obj4);
> if(PyFloat_Check(_obj3)) {
>     dtmp = (double *)calloc(1,sizeof(double));
>     dtmp=PyFloat_AsDouble((PyObject *)_obj3);
> }

But this code doesn't make sense.  dtmp is declared as a pointer to double,
but PyFloat_AsDouble returns a double (not a pointer to a double).  Doesn't
the compiler complain about this?  Or isn't this the actual code?

> ...
> This code works perfectly under Linux RedHat 5.2, Solaris, and even
> OpenStep 4.2, BUT it stopped working with the new release of RedHat 6.0.
> It looks like the function(s) PyFloat_As..() are broken somehow.

Have you stepped into it in the debugger (it's in Objects/floatobject.c)?
It starts like so:

	if (op && PyFloat_Check(op))
		return PyFloat_AS_DOUBLE((PyFloatObject*) op);

PyFloat_AsDouble is a trivial macro:

#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)

PyFloatObject is a simple struct:

typedef struct {
	PyObject_HEAD
	double ob_fval;
} PyFloatObject;

The macro simply returns the ob_fval member.  Since the code as posted
doesn't make sense, you'll have to take it from here with the actual code
<wink>.

> When I pass for example, 1.0 as the third argument to my function under
> Python, the value returned by PyFloat_AsDouble is  2.93991353473135E-102

If you don't know how to use the debugger on this system, write a small
self-contained module that exhibits the problem.  There's really no info
here to go on, and nobody else has reported a problem with this.

if-it-returned-2.93991353473135E-103-it-would-be-obvious<wink>-ly y'rs  -
tim






More information about the Python-list mailing list