Commit 02f740d5 authored by Denis Bilenko's avatar Denis Bilenko

cython: use void* instead of object to avoid additional unnecessary...

cython: use void* instead of object to avoid additional unnecessary incref/decref; also use xdecref where makes sense
parent 232bc505
......@@ -50,8 +50,9 @@ cdef extern from "sys/types.h":
ctypedef unsigned char u_char
cdef extern from "Python.h":
void Py_INCREF(object o)
void Py_DECREF(object o)
void Py_INCREF(void* o)
void Py_DECREF(void* o)
void Py_XDECREF(void* o)
object PyString_FromStringAndSize(char *v, int len)
object PyString_FromString(char *v)
......@@ -163,12 +164,12 @@ cdef class event:
cdef _addref(self):
if self._incref <= 0:
Py_INCREF(self)
Py_INCREF(<void*>self)
self._incref += 1
cdef _delref(self):
if self._incref > 0:
Py_DECREF(self)
Py_DECREF(<void*>self)
self._incref -= 1
property pending:
......@@ -461,18 +462,15 @@ include "evhttp.pxi"
def set_exc_info(object type, object value):
cdef PyThreadState* tstate = PyThreadState_GET()
if tstate.exc_type != NULL:
Py_DECREF(<object>tstate.exc_type)
if tstate.exc_value != NULL:
Py_DECREF(<object>tstate.exc_value)
if tstate.exc_traceback != NULL:
Py_DECREF(<object>tstate.exc_traceback)
Py_XDECREF(tstate.exc_type)
Py_XDECREF(tstate.exc_value)
Py_XDECREF(tstate.exc_traceback)
if value is None:
tstate.exc_type = NULL
tstate.exc_value = NULL
else:
Py_INCREF(type)
Py_INCREF(value)
Py_INCREF(<void*>type)
Py_INCREF(<void*>value)
tstate.exc_type = <void*>type
tstate.exc_value = <void *>value
tstate.exc_traceback = NULL
......@@ -56,7 +56,7 @@ def dns_err_to_string(int err):
cdef void __evdns_callback(int code, char type, int count, int ttl, void *addrs, void *arg) with gil:
cdef int i
cdef object callback = <object>arg
Py_DECREF(callback)
Py_DECREF(<void*>callback)
cdef object addr
cdef object result
......@@ -91,7 +91,7 @@ def dns_resolve_ipv4(char *name, int flags, object callback):
cdef int result = evdns_resolve_ipv4(name, flags, __evdns_callback, <void *>callback)
if result:
raise IOError('evdns_resolve_ipv4(%r, %r) returned %s' % (name, flags, result, ))
Py_INCREF(callback)
Py_INCREF(<void*>callback)
def dns_resolve_ipv6(char *name, int flags, object callback):
......@@ -104,7 +104,7 @@ def dns_resolve_ipv6(char *name, int flags, object callback):
cdef int result = evdns_resolve_ipv6(name, flags, __evdns_callback, <void *>callback)
if result:
raise IOError('evdns_resolve_ip6(%r, %r) returned %s' % (name, flags, result, ))
Py_INCREF(callback)
Py_INCREF(<void*>callback)
def dns_resolve_reverse(char* packed_ip, int flags, object callback):
......@@ -117,7 +117,7 @@ def dns_resolve_reverse(char* packed_ip, int flags, object callback):
cdef int result = evdns_resolve_reverse(<void *>packed_ip, flags, __evdns_callback, <void *>callback)
if result:
raise IOError('evdns_resolve_reverse(%r, %r) returned %s' % (packed_ip, flags, result, ))
Py_INCREF(callback)
Py_INCREF(<void*>callback)
def dns_resolve_reverse_ipv6(char* packed_ip, int flags, object callback):
......@@ -130,4 +130,4 @@ def dns_resolve_reverse_ipv6(char* packed_ip, int flags, object callback):
cdef int result = evdns_resolve_reverse_ipv6(<void *>packed_ip, flags, __evdns_callback, <void *>callback)
if result:
raise IOError('evdns_resolve_reverse_ipv6(%r, %r) returned %s' % (packed_ip, flags, result, ))
Py_INCREF(callback)
Py_INCREF(<void*>callback)
......@@ -485,12 +485,12 @@ cdef class http_request_client(http_request_base):
cdef _addref(self):
if self._incref <= 0:
Py_INCREF(self)
Py_INCREF(<void*>self)
self._incref += 1
cdef _delref(self):
if self._incref > 0:
Py_DECREF(self)
Py_DECREF(<void*>self)
self._incref -= 1
self.callback = None
......
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