Commit edecf75b authored by Martin Sustrik's avatar Martin Sustrik

python binding checks ctx argument type

parent 8cdf7532
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#pragma warning (disable:4996) #pragma warning (disable:4996)
#endif #endif
extern PyTypeObject context_type;
struct context_t struct context_t
{ {
PyObject_HEAD PyObject_HEAD
...@@ -55,14 +57,14 @@ int context_init (context_t *self, PyObject *args, PyObject *kwdict) ...@@ -55,14 +57,14 @@ int context_init (context_t *self, PyObject *args, PyObject *kwdict)
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "ii", (char**) kwlist, if (!PyArg_ParseTupleAndKeywords (args, kwdict, "ii", (char**) kwlist,
&app_threads, &io_threads)) { &app_threads, &io_threads)) {
PyErr_SetString (PyExc_SystemError, "invalid arguments"); PyErr_SetString (PyExc_SystemError, "invalid arguments");
return -1; // ? return -1;
} }
assert (!self->handle); assert (!self->handle);
self->handle = zmq_init (app_threads, io_threads); self->handle = zmq_init (app_threads, io_threads);
if (!self->handle) { if (!self->handle) {
PyErr_SetString (PyExc_SystemError, strerror (errno)); PyErr_SetString (PyExc_SystemError, strerror (errno));
return -1; // ? return -1;
} }
return 0; return 0;
...@@ -79,6 +81,8 @@ void context_dealloc (context_t *self) ...@@ -79,6 +81,8 @@ void context_dealloc (context_t *self)
self->ob_type->tp_free ((PyObject*) self); self->ob_type->tp_free ((PyObject*) self);
} }
extern PyTypeObject socket_type;
struct socket_t struct socket_t
{ {
PyObject_HEAD PyObject_HEAD
...@@ -100,18 +104,17 @@ int socket_init (socket_t *self, PyObject *args, PyObject *kwdict) ...@@ -100,18 +104,17 @@ int socket_init (socket_t *self, PyObject *args, PyObject *kwdict)
context_t *context; context_t *context;
int socket_type; int socket_type;
static const char *kwlist [] = {"context", "type", NULL}; static const char *kwlist [] = {"context", "type", NULL};
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "Oi", (char**) kwlist, if (!PyArg_ParseTupleAndKeywords (args, kwdict, "O!i", (char**) kwlist,
&context, &socket_type)) { &context_type, &context, &socket_type)) {
PyErr_SetString (PyExc_SystemError, "invalid arguments"); PyErr_SetString (PyExc_SystemError, "invalid arguments");
return NULL; return -1;
} }
// TODO: Check whether 'context' is really a libpyzmq.Context object.
assert (!self->handle); assert (!self->handle);
self->handle = zmq_socket (context->handle, socket_type); self->handle = zmq_socket (context->handle, socket_type);
if (!self->handle) { if (!self->handle) {
PyErr_SetString (PyExc_SystemError, strerror (errno)); PyErr_SetString (PyExc_SystemError, strerror (errno));
return -1; // ? return -1;
} }
return 0; return 0;
...@@ -157,7 +160,6 @@ PyObject *socket_setsockopt (socket_t *self, PyObject *args, PyObject *kwdict) ...@@ -157,7 +160,6 @@ PyObject *socket_setsockopt (socket_t *self, PyObject *args, PyObject *kwdict)
case ZMQ_IDENTITY: case ZMQ_IDENTITY:
case ZMQ_SUBSCRIBE: case ZMQ_SUBSCRIBE:
case ZMQ_UNSUBSCRIBE: case ZMQ_UNSUBSCRIBE:
rc = zmq_setsockopt (self->handle, option, PyString_AsString (optval), rc = zmq_setsockopt (self->handle, option, PyString_AsString (optval),
PyString_Size (optval)); PyString_Size (optval));
break; break;
...@@ -309,7 +311,7 @@ static PyMethodDef context_methods [] = ...@@ -309,7 +311,7 @@ static PyMethodDef context_methods [] =
} }
}; };
static PyTypeObject context_type = PyTypeObject context_type =
{ {
PyObject_HEAD_INIT (NULL) PyObject_HEAD_INIT (NULL)
0, 0,
...@@ -395,7 +397,7 @@ static PyMethodDef socket_methods [] = ...@@ -395,7 +397,7 @@ static PyMethodDef socket_methods [] =
} }
}; };
static PyTypeObject socket_type = PyTypeObject socket_type =
{ {
PyObject_HEAD_INIT (NULL) PyObject_HEAD_INIT (NULL)
0, 0,
......
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