summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-08-20 19:47:44 (GMT)
committerGuido van Rossum <guido@python.org>1996-08-20 19:47:44 (GMT)
commitd62d8bced3b7fe380d14147438dc4ec41a3ba7fb (patch)
treee8febd6d53d0c22ad312579088dc1e13f7393e97 /Modules
parentcde317ae624c6c8c81da20b7ca099e10c34917f6 (diff)
downloadcpython-d62d8bced3b7fe380d14147438dc4ec41a3ba7fb.zip
cpython-d62d8bced3b7fe380d14147438dc4ec41a3ba7fb.tar.gz
cpython-d62d8bced3b7fe380d14147438dc4ec41a3ba7fb.tar.bz2
Test for xdrmem_create() failure.
Minor lay-out changes.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_xdrmodule.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/Modules/_xdrmodule.c b/Modules/_xdrmodule.c
index 27a8d5c..42e545f 100644
--- a/Modules/_xdrmodule.c
+++ b/Modules/_xdrmodule.c
@@ -10,9 +10,9 @@
*
* 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"
@@ -27,8 +27,8 @@ static PyObject* xdr_error;
static PyObject*
pack_float(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
float value;
@@ -41,8 +41,11 @@ pack_float(self, args)
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");
@@ -51,10 +54,12 @@ pack_float(self, args)
return rtn;
}
+
+
static PyObject*
pack_double(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
double value;
@@ -67,8 +72,11 @@ pack_double(self, args)
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");
@@ -81,8 +89,8 @@ pack_double(self, args)
static PyObject*
unpack_float(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
float value;
@@ -99,8 +107,11 @@ unpack_float(self, args)
}
/* 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");
@@ -110,10 +121,11 @@ unpack_float(self, args)
}
+
static PyObject*
unpack_double(self, args)
- PyObject* self;
- PyObject* args;
+ PyObject* self;
+ PyObject* args;
{
XDR xdr;
double value;
@@ -130,8 +142,11 @@ unpack_double(self, args)
}
/* 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");