Skip to content

Commit

Permalink
Merge pull request #34 from hydralabs/cython-travis
Browse files Browse the repository at this point in the history
PyAMF now working with the latest version of Cython (0.21.2)
  • Loading branch information
njoyce committed Jan 21, 2015
2 parents 4eb6bb8 + 9d9a1ea commit f91cd6b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ before_script:

script:
- python setup.py test
- pip install Cython
- python setup.py test
16 changes: 8 additions & 8 deletions cpyamf/amf0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cdef class Decoder(codec.Decoder):
codec.Codec.__init__(self, *args, **kwargs)

cdef object readNumber(self):
cdef double i
cdef double i = -1

self.stream.read_double(&i)

Expand Down Expand Up @@ -211,8 +211,8 @@ cdef class Decoder(codec.Decoder):
return obj

cdef object readDate(self):
cdef double ms
cdef short tz
cdef double ms = -1
cdef short tz = -1

self.stream.read_double(&ms)
tz = self.stream.read_short()
Expand All @@ -228,7 +228,7 @@ cdef class Decoder(codec.Decoder):
return d

cdef object readLongString(self, bint bytes=0):
cdef unsigned long l
cdef unsigned long l = 0
cdef char *b = NULL
cdef object s

Expand Down Expand Up @@ -352,8 +352,8 @@ cdef class Encoder(codec.Encoder):
"""
Write array to the stream.
"""
cdef Py_ssize_t size, i
cdef PyObject *x
cdef Py_ssize_t size = -1, i = -1
cdef PyObject *x = NULL

if self.writeReference(a) != -1:
return 0
Expand All @@ -373,8 +373,8 @@ cdef class Encoder(codec.Encoder):
return 0

cdef int writeTuple(self, object a) except -1:
cdef Py_ssize_t size, i
cdef PyObject *x
cdef Py_ssize_t size = -1, i = -1
cdef PyObject *x = NULL

if self.writeReference(a) != -1:
return 0
Expand Down
8 changes: 4 additions & 4 deletions cpyamf/amf3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ cdef class ClassDefinition(object):
return stream.write(self.encoded_ref, self.encoded_ref_size)

cdef Py_ssize_t ref = 0
cdef char *buf
cdef char *buf = NULL
cdef int ret = 0

if self.encoding != OBJECT_ENCODING_EXTERNAL:
Expand Down Expand Up @@ -276,7 +276,7 @@ cdef class Decoder(codec.Decoder):
return <object>r

cdef object readNumber(self):
cdef double d
cdef double d = -1

self.stream.read_double(&d)

Expand Down Expand Up @@ -424,7 +424,7 @@ cdef class Decoder(codec.Decoder):

cdef int _readDynamic(self, ClassDefinition class_def, dict obj) except -1:
cdef object attr
cdef char *peek
cdef char *peek = NULL


while True:
Expand Down Expand Up @@ -1026,7 +1026,7 @@ cdef class Encoder(codec.Encoder):

return self.writeObject(proxy, 1)

cdef inline int handleBasicTypes(self, object element, object py_type) except -1:
cdef int handleBasicTypes(self, object element, object py_type) except -1:
cdef int ret = codec.Encoder.handleBasicTypes(self, element, py_type)

if ret == 1: # not handled
Expand Down
2 changes: 1 addition & 1 deletion cpyamf/codec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ cdef class Encoder(Codec):
cdef int writeMixedArray(self, object o) except -1
cdef int writeGenerator(self, object) except -1

cdef inline int handleBasicTypes(self, object element, object py_type) except -1
cdef int handleBasicTypes(self, object element, object py_type) except -1
cdef int checkBadTypes(self, object element, object py_type) except -1
cpdef int writeElement(self, object element) except -1

Expand Down
31 changes: 20 additions & 11 deletions cpyamf/codec.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ cdef class IndexedCollection(object):
if current_size != self.size:
self.size = current_size

cpy = <PyObject **>PyMem_Realloc(self.data, sizeof(PyObject *) * self.size)
cpy = <PyObject **>PyMem_Realloc(
self.data,
sizeof(PyObject *) * self.size
)

if cpy == NULL:
self._clear()
Expand Down Expand Up @@ -159,7 +162,9 @@ cdef class IndexedCollection(object):
def __richcmp__(self, object other, int op):
cdef int equal
cdef Py_ssize_t i
cdef IndexedCollection s = self # this is necessary because cython does not see the c-space vars of the class for this func
# this is necessary because cython does not see the c-space vars of the
# class for this func
cdef IndexedCollection s = self

if PyDict_Check(other) == 1:
equal = s.refs == other
Expand Down Expand Up @@ -221,13 +226,13 @@ cdef class Context(object):

return 0

cpdef inline object getObject(self, Py_ssize_t ref):
cpdef object getObject(self, Py_ssize_t ref):
return self.objects.getByReference(ref)

cpdef inline Py_ssize_t getObjectReference(self, object obj) except -2:
cpdef Py_ssize_t getObjectReference(self, object obj) except -2:
return self.objects.getReferenceTo(obj)

cpdef inline Py_ssize_t addObject(self, object obj) except -1:
cpdef Py_ssize_t addObject(self, object obj) except -1:
return self.objects.append(obj)

cpdef object getClassAlias(self, object klass):
Expand Down Expand Up @@ -494,7 +499,7 @@ cdef class Encoder(Codec):
cdef int writeMixedArray(self, object o) except -1:
raise NotImplementedError

cdef inline int handleBasicTypes(self, object element, object py_type) except -1:
cdef int handleBasicTypes(self, object element, object py_type) except -1:
"""
@return: 0 = handled, -1 = error, 1 = not handled
"""
Expand Down Expand Up @@ -539,13 +544,17 @@ cdef class Encoder(Codec):

cdef int checkBadTypes(self, object element, object py_type) except -1:
if PyModule_CheckExact(element):
raise pyamf.EncodeError("Cannot encode modules")
raise pyamf.EncodeError("Cannot encode modules %r" % (element,))
elif PyMethod_Check(element):
raise pyamf.EncodeError("Cannot encode methods")
raise pyamf.EncodeError("Cannot encode methods %r" % (element,))
elif PyFunction_Check(element) or py_type is BuiltinFunctionType:
raise pyamf.EncodeError("Cannot encode functions")
raise pyamf.EncodeError("Cannot encode functions %r" % (
element,
))
elif PyClass_Check(element) or PyType_CheckExact(element):
raise pyamf.EncodeError("Cannot encode class objects")
raise pyamf.EncodeError("Cannot encode class objects %r" % (
element,
))
elif PyTime_CheckExact(element):
raise pyamf.EncodeError('A datetime.time instance was found but '
'AMF has no way to encode time objects. Please use '
Expand Down Expand Up @@ -594,7 +603,7 @@ cdef class Encoder(Codec):
Part of the iterator protocol.
"""
cdef Py_ssize_t start_pos, end_pos
cdef char *buf
cdef char *buf = NULL

try:
element = self.bucket.pop(0)
Expand Down
4 changes: 2 additions & 2 deletions cpyamf/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ cdef class cBufferedByteStream:
cdef Py_ssize_t length
cdef Py_ssize_t min_buf_size

cpdef inline Py_ssize_t tell(self) except -1
cpdef Py_ssize_t tell(self) except -1
cdef int write(self, char *buf, Py_ssize_t size) except -1
cdef inline int _init_buffer(self)
cdef int _actually_increase_buffer(self, Py_ssize_t size) except -1
cdef int _increase_buffer(self, Py_ssize_t size) except -1
cdef inline bint has_available(self, Py_ssize_t size) except -1
cdef int read(self, char **buf, Py_ssize_t size) except -1
cpdef bint at_eof(self) except -1
cpdef inline Py_ssize_t remaining(self) except -1
cpdef Py_ssize_t remaining(self) except -1
cpdef int seek(self, Py_ssize_t pos, int mode=*) except -1
cpdef object getvalue(self)
cdef Py_ssize_t peek(self, char **buf, Py_ssize_t size) except -1
Expand Down
7 changes: 4 additions & 3 deletions cpyamf/util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ cdef class cBufferedByteStream(object):

return 0

cpdef inline Py_ssize_t tell(self):
cpdef Py_ssize_t tell(self):
"""
Returns the position of the stream pointer.
"""
Expand Down Expand Up @@ -320,15 +320,15 @@ cdef class cBufferedByteStream(object):

return 0

cpdef inline bint at_eof(self) except -1:
cpdef bint at_eof(self) except -1:
"""
Returns C{True} if the internal pointer is at the end of the stream.
@rtype: C{bool}
"""
return self.length == self.pos

cpdef inline Py_ssize_t remaining(self) except -1:
cpdef Py_ssize_t remaining(self) except -1:
"""
Returns number of remaining bytes.
"""
Expand Down Expand Up @@ -1093,6 +1093,7 @@ cdef class BufferedByteStream(cBufferedByteStream):
raise TypeError('Expecting float for val')

cdef double d = val
cdef int done = 0

if float_broken == 1:
if memcmp(&d, &platform_nan, 8) == 0:
Expand Down

0 comments on commit f91cd6b

Please sign in to comment.