[Zope-CVS] CVS: Packages/Spread - spreadmodule.c:1.4
Guido van Rossum
guido@python.org
Wed, 19 Dec 2001 17:39:47 -0500
Update of /cvs-repository/Packages/Spread
In directory cvs.zope.org:/tmp/cvs-serv27733
Modified Files:
spreadmodule.c
Log Message:
spread_connect():
- Don't call undocumented SP_connect_timeout(), its timeout argument
doesn't seem to work; we ain't gonna need the timeout, so remove the
timeout argument from spread_connect().
- Zero the group_name output buffer before passing it to SP_connect().
mailbox_receive():
- Zero the message output buffer before passing it to SP_receive().
new_membership_msg():
- don't believe that extra->members[i] is a null-terminated string;
copy using PyString_FromStringAndSize(), then resize based on
strlen().
XXX still to do: lots of error checking (e.g. _PyString_Resize() may
fail, PyTuple_New() may fail, etc.)
=== Packages/Spread/spreadmodule.c 1.3 => 1.4 ===
#include "sp.h"
-/* XXX This ought to be in sp.h */
-static sp_time Zero_timeout = { 0, 0 };
-
static PyObject *SpreadError;
static PyObject *spread_error(int);
static void spread_too_short_error(int, int, short, int);
@@ -187,11 +184,13 @@
self->extra = PyTuple_New(extra->num_members);
for (i = 0; i < extra->num_members; ++i) {
- PyObject *s = PyString_FromString(extra->members[i]);
+ PyObject *s = PyString_FromStringAndSize(extra->members[i],
+ MAX_GROUP_NAME);
if (!s) {
Py_DECREF(self->extra);
return NULL;
}
+ _PyString_Resize(&s, strlen(PyString_AS_STRING(s)));
PyTuple_SET_ITEM(self->extra, i, s);
}
return self;
@@ -455,9 +454,12 @@
sender = PyString_FromStringAndSize(NULL, MAX_GROUP_NAME);
if (!sender)
goto error;
+
message = PyString_FromStringAndSize(NULL, buf_size);
if (!message)
goto error;
+ memset(PyString_AS_STRING(message), '\0', buf_size);
+
groups = calloc(MAX_GROUP_NAME, self->max_groups);
if (!groups)
goto error;
@@ -641,26 +643,22 @@
int ret;
char *spread_name, *private_name;
int priority, membership;
- double py_timeout = 0.0;
- sp_time *sp_timeout = NULL;
PyObject *group_name = NULL;
- if (!PyArg_ParseTuple(args, "ssii|d:connect",
- &spread_name, &private_name, &priority,
- &membership, &py_timeout))
+ if (!PyArg_ParseTuple(args, "ssii:connect",
+ &spread_name, &private_name, &priority, &membership))
return NULL;
- /* XXX must convert double to timeout struct */
- sp_timeout = &Zero_timeout;
+ /* initialize output buffer for group name */
group_name = PyString_FromStringAndSize(NULL, MAX_GROUP_NAME);
if (group_name == NULL)
return NULL;
+ memset(PyString_AS_STRING(group_name), '\0', MAX_GROUP_NAME);
Py_BEGIN_ALLOW_THREADS
- ret = SP_connect_timeout(spread_name, private_name, priority,
- membership, &_mbox,
- PyString_AS_STRING(group_name),
- *sp_timeout);
+ ret = SP_connect(spread_name, private_name, priority,
+ membership, &_mbox,
+ PyString_AS_STRING(group_name));
Py_END_ALLOW_THREADS
if (ret == ACCEPT_SESSION) {