Commit 1eef1dc0 authored by Guido van Rossum's avatar Guido van Rossum

Test for xdrmem_create() failure.

Minor lay-out changes.
parent 3c7a8454
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
* *
* See xdrlib.py for usage notes. * See xdrlib.py for usage notes.
* *
* Note: this has so far, only been tested on Solaris 2.5 and SGI IRIX 5.3. * Note: this has so far, only been tested on Solaris 2.5 and IRIX 5.3. On
* On these systems, you will need to link with -lnsl for these * these systems, you will need to link with -lnsl for these symbols to be
* symbols to be defined. * defined.
*/ */
#include "Python.h" #include "Python.h"
...@@ -41,8 +41,11 @@ pack_float(self, args) ...@@ -41,8 +41,11 @@ pack_float(self, args)
if (!PyArg_ParseTuple(args, "f", &value)) if (!PyArg_ParseTuple(args, "f", &value))
return NULL; return NULL;
xdr.x_ops = NULL;
xdrmem_create(&xdr, addr.buffer, 4, XDR_ENCODE); 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); rtn = PyString_FromStringAndSize(addr.buffer, 4);
else else
PyErr_SetString(xdr_error, "conversion from float failed"); PyErr_SetString(xdr_error, "conversion from float failed");
...@@ -51,6 +54,8 @@ pack_float(self, args) ...@@ -51,6 +54,8 @@ pack_float(self, args)
return rtn; return rtn;
} }
static PyObject* static PyObject*
pack_double(self, args) pack_double(self, args)
PyObject* self; PyObject* self;
...@@ -67,8 +72,11 @@ pack_double(self, args) ...@@ -67,8 +72,11 @@ pack_double(self, args)
if (!PyArg_ParseTuple(args, "d", &value)) if (!PyArg_ParseTuple(args, "d", &value))
return NULL; return NULL;
xdr.x_ops = NULL;
xdrmem_create(&xdr, addr.buffer, 8, XDR_ENCODE); 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); rtn = PyString_FromStringAndSize(addr.buffer, 8);
else else
PyErr_SetString(xdr_error, "conversion from double failed"); PyErr_SetString(xdr_error, "conversion from double failed");
...@@ -99,8 +107,11 @@ unpack_float(self, args) ...@@ -99,8 +107,11 @@ unpack_float(self, args)
} }
/* Python guarantees that the string is 4 byte aligned */ /* Python guarantees that the string is 4 byte aligned */
xdr.x_ops = NULL;
xdrmem_create(&xdr, (caddr_t)string, 4, XDR_DECODE); 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); rtn = Py_BuildValue("f", value);
else else
PyErr_SetString(xdr_error, "conversion to float failed"); PyErr_SetString(xdr_error, "conversion to float failed");
...@@ -110,6 +121,7 @@ unpack_float(self, args) ...@@ -110,6 +121,7 @@ unpack_float(self, args)
} }
static PyObject* static PyObject*
unpack_double(self, args) unpack_double(self, args)
PyObject* self; PyObject* self;
...@@ -130,8 +142,11 @@ unpack_double(self, args) ...@@ -130,8 +142,11 @@ unpack_double(self, args)
} }
/* Python guarantees that the string is 4 byte aligned */ /* Python guarantees that the string is 4 byte aligned */
xdr.x_ops = NULL;
xdrmem_create(&xdr, (caddr_t)string, 8, XDR_DECODE); 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); rtn = Py_BuildValue("d", value);
else else
PyErr_SetString(xdr_error, "conversion to double failed"); PyErr_SetString(xdr_error, "conversion to double failed");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment