*
* See xdrlib.py for usage notes.
*
- * Note: this has so far, only been tested on Solaris 2.5 and SGI IRIX 5.3.
- * On these systems, you will need to link with -lnsl for these
- * symbols to be defined.
+ * Note: this has so far, only been tested on Solaris 2.5 and IRIX 5.3. On
+ * these systems, you will need to link with -lnsl for these symbols to be
+ * defined.
*/
#include "Python.h"
\f
static PyObject*
pack_float(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
float value;
if (!PyArg_ParseTuple(args, "f", &value))
return NULL;
+ xdr.x_ops = NULL;
xdrmem_create(&xdr, addr.buffer, 4, XDR_ENCODE);
- if (xdr_float(&xdr, &value))
+ if( xdr.x_ops == NULL )
+ PyErr_SetString(xdr_error, "XDR stream initialization failed.");
+ else if (xdr_float(&xdr, &value))
rtn = PyString_FromStringAndSize(addr.buffer, 4);
else
PyErr_SetString(xdr_error, "conversion from float failed");
return rtn;
}
+
+\f
static PyObject*
pack_double(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
double value;
if (!PyArg_ParseTuple(args, "d", &value))
return NULL;
+ xdr.x_ops = NULL;
xdrmem_create(&xdr, addr.buffer, 8, XDR_ENCODE);
- if (xdr_double(&xdr, &value))
+ if( xdr.x_ops == NULL )
+ PyErr_SetString(xdr_error, "XDR stream initialization failed.");
+ else if (xdr_double(&xdr, &value))
rtn = PyString_FromStringAndSize(addr.buffer, 8);
else
PyErr_SetString(xdr_error, "conversion from double failed");
\f
static PyObject*
unpack_float(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
float value;
}
/* Python guarantees that the string is 4 byte aligned */
+ xdr.x_ops = NULL;
xdrmem_create(&xdr, (caddr_t)string, 4, XDR_DECODE);
- if (xdr_float(&xdr, &value))
+ if( xdr.x_ops == NULL )
+ PyErr_SetString(xdr_error, "XDR stream initialization failed.");
+ else if (xdr_float(&xdr, &value))
rtn = Py_BuildValue("f", value);
else
PyErr_SetString(xdr_error, "conversion to float failed");
}
+\f
static PyObject*
unpack_double(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
double value;
}
/* Python guarantees that the string is 4 byte aligned */
+ xdr.x_ops = NULL;
xdrmem_create(&xdr, (caddr_t)string, 8, XDR_DECODE);
- if (xdr_double(&xdr, &value))
+ if( xdr.x_ops == NULL )
+ PyErr_SetString(xdr_error, "XDR stream initialization failed.");
+ else if (xdr_double(&xdr, &value))
rtn = Py_BuildValue("d", value);
else
PyErr_SetString(xdr_error, "conversion to double failed");