diff options
author | Roger Hu <roger.hu@gmail.com> | 2014-06-16 07:55:36 -0700 |
---|---|---|
committer | Roger Hu <roger.hu@gmail.com> | 2014-06-16 07:59:06 -0700 |
commit | e94026076d382444f237db7c41f768c3b366d971 (patch) | |
tree | 2eeca4c8982596de9083e8529273efb7599111df | |
parent | 7d58aba8bb404f1a886c415bd417f5fb9d987a3f (diff) | |
download | librabbitmq-e94026076d382444f237db7c41f768c3b366d971.tar.gz |
Check if the return value is -1. If so, goto fail, which will invoke PyErr_Ocurred().
https://docs.python.org/2/c-api/int.html
https://docs.python.org/2/c-api/float.html
Somehow runnning PyErr_Ocurred() when no exception has been generated triggers an unknown thread state and
seg faults.
Again, I noticed this issue when trying to pass in a Python dictionary with integer/double values and seg faults.
-rw-r--r-- | Modules/_librabbitmq/connection.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/_librabbitmq/connection.c b/Modules/_librabbitmq/connection.c index dd7a3f8..db34215 100644 --- a/Modules/_librabbitmq/connection.c +++ b/Modules/_librabbitmq/connection.c @@ -269,8 +269,10 @@ PyDict_ToAMQTable(amqp_connection_state_t conn, PyObject *src, amqp_pool_t *pool else if (PyLong_Check(dvalue) || PyInt_Check(dvalue)) { /* Int | Long */ clong_value = (int64_t)PyLong_AsLong(dvalue); - if (PyErr_Occurred()) - goto error; + + if (clong_value == -1) + goto error; + AMQTable_SetIntValue(&dst, PyString_AS_AMQBYTES(dkey), clong_value @@ -278,8 +280,10 @@ PyDict_ToAMQTable(amqp_connection_state_t conn, PyObject *src, amqp_pool_t *pool } else if (PyFloat_Check(dvalue)) { cdouble_value = PyFloat_AsDouble(dvalue); - if (PyErr_Occurred()) - goto error; + + if (cdouble_value == -1) + goto error; + AMQTable_SetDoubleValue(&dst, PyString_AS_AMQBYTES(dkey), cdouble_value |