[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pyamf-commits
Subject:    [pyamf-commits] r1798 - in pyamf/branches: . cpyamf-amf3
From:       commits () pyamf ! org (commits () pyamf ! org)
Date:       2008-11-24 15:51:19
Message-ID: 20081124145058.ADBD27BC063 () mail ! collab ! com
[Download RAW message or body]

Author: nick
Date: 2008-11-24 15:50:58 +0100 (Mon, 24 Nov 2008)
New Revision: 1798

Added:
   pyamf/branches/cpyamf-amf3/
   pyamf/branches/cpyamf-amf3/cpyamf/amf3.c
   pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx
Modified:
   pyamf/branches/cpyamf-amf3/pyamf/amf3.py
   pyamf/branches/cpyamf-amf3/setup.py
Log:
Added cpyamf amf3 module (written in Cython) for fast decode_int/encode_int

Added: pyamf/branches/cpyamf-amf3/cpyamf/amf3.c
===================================================================
--- pyamf/branches/cpyamf-amf3/cpyamf/amf3.c	                        (rev 0)
+++ pyamf/branches/cpyamf-amf3/cpyamf/amf3.c	2008-11-24 14:50:58 UTC (rev 1798)
@@ -0,0 +1,1842 @@
+/* Generated by Cython 0.10.1 on Mon Nov 24 14:50:04 2008 */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "structmember.h"
+#ifndef PY_LONG_LONG
+  #define PY_LONG_LONG LONG_LONG
+#endif
+#ifndef DL_EXPORT
+  #define DL_EXPORT(t) t
+#endif
+#if PY_VERSION_HEX < 0x02040000
+  #define METH_COEXIST 0
+#endif
+#if PY_VERSION_HEX < 0x02050000
+  typedef int Py_ssize_t;
+  #define PY_SSIZE_T_MAX INT_MAX
+  #define PY_SSIZE_T_MIN INT_MIN
+  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
+  #define PyNumber_Index(o)    PyNumber_Int(o)
+  #define PyIndex_Check(o)     PyNumber_Check(o)
+#endif
+#if PY_VERSION_HEX < 0x02060000
+  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
+  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
+  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
+  #define PyVarObject_HEAD_INIT(type, size) \
+          PyObject_HEAD_INIT(type) size,
+  #define PyType_Modified(t)
+
+  typedef struct {
+       void *buf;
+       PyObject *obj;
+       Py_ssize_t len;
+       Py_ssize_t itemsize;
+       int readonly;
+       int ndim;
+       char *format;
+       Py_ssize_t *shape;
+       Py_ssize_t *strides;
+       Py_ssize_t *suboffsets;
+       void *internal;
+  } Py_buffer;
+
+  #define PyBUF_SIMPLE 0
+  #define PyBUF_WRITABLE 0x0001
+  #define PyBUF_LOCK 0x0002
+  #define PyBUF_FORMAT 0x0004
+  #define PyBUF_ND 0x0008
+  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
+
+#endif
+#if PY_MAJOR_VERSION < 3
+  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+#else
+  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define Py_TPFLAGS_CHECKTYPES 0
+  #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
+  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyBaseString_Type            PyUnicode_Type
+  #define PyString_Type                PyBytes_Type
+  #define PyInt_Type                   PyLong_Type
+  #define PyInt_Check(op)              PyLong_Check(op)
+  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
+  #define PyInt_FromString             PyLong_FromString
+  #define PyInt_FromUnicode            PyLong_FromUnicode
+  #define PyInt_FromLong               PyLong_FromLong
+  #define PyInt_FromSize_t             PyLong_FromSize_t
+  #define PyInt_FromSsize_t            PyLong_FromSsize_t
+  #define PyInt_AsLong                 PyLong_AsLong
+  #define PyInt_AS_LONG                PyLong_AS_LONG
+  #define PyInt_AsSsize_t              PyLong_AsSsize_t
+  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
+  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
+#else
+  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
+  #define PyBytes_Type                 PyString_Type
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
+#endif
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+  #ifndef __stdcall
+    #define __stdcall
+  #endif
+  #ifndef __cdecl
+    #define __cdecl
+  #endif
+#else
+  #define _USE_MATH_DEFINES
+#endif
+#ifdef __cplusplus
+#define __PYX_EXTERN_C extern "C"
+#else
+#define __PYX_EXTERN_C extern
+#endif
+#include <math.h>
+#define __PYX_HAVE_API__cpyamf__amf3
+
+
+#ifdef __GNUC__
+#define INLINE __inline__
+#elif _WIN32
+#define INLINE __inline
+#else
+#define INLINE 
+#endif
+
+typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char \
is_identifier;} __Pyx_StringTabEntry; /*proto*/ +
+
+
+static int __pyx_skip_dispatch = 0;
+
+
+/* Type Conversion Predeclarations */
+
+#if PY_MAJOR_VERSION < 3
+#define __Pyx_PyBytes_FromString PyString_FromString
+#define __Pyx_PyBytes_AsString   PyString_AsString
+#else
+#define __Pyx_PyBytes_FromString PyBytes_FromString
+#define __Pyx_PyBytes_AsString   PyBytes_AsString
+#endif
+
+#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : \
(Py_INCREF(Py_False), Py_False)) +static INLINE int __Pyx_PyObject_IsTrue(PyObject* \
x); +static INLINE PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x);
+static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(PyObject* x);
+static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b);
+
+#define __pyx_PyInt_AsLong(x) (PyInt_CheckExact(x) ? PyInt_AS_LONG(x) : \
PyInt_AsLong(x)) +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? \
PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +
+static INLINE unsigned char __pyx_PyInt_unsigned_char(PyObject* x);
+static INLINE unsigned short __pyx_PyInt_unsigned_short(PyObject* x);
+static INLINE char __pyx_PyInt_char(PyObject* x);
+static INLINE short __pyx_PyInt_short(PyObject* x);
+static INLINE int __pyx_PyInt_int(PyObject* x);
+static INLINE long __pyx_PyInt_long(PyObject* x);
+static INLINE signed char __pyx_PyInt_signed_char(PyObject* x);
+static INLINE signed short __pyx_PyInt_signed_short(PyObject* x);
+static INLINE signed int __pyx_PyInt_signed_int(PyObject* x);
+static INLINE signed long __pyx_PyInt_signed_long(PyObject* x);
+static INLINE long double __pyx_PyInt_long_double(PyObject* x);
+#ifdef __GNUC__
+/* Test for GCC > 2.95 */
+#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
+#define likely(x)   __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#else /* __GNUC__ > 2 ... */
+#define likely(x)   (x)
+#define unlikely(x) (x)
+#endif /* __GNUC__ > 2 ... */
+#else /* __GNUC__ */
+#define likely(x)   (x)
+#define unlikely(x) (x)
+#endif /* __GNUC__ */
+    
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static PyObject *__pyx_empty_tuple;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+static const char **__pyx_f;
+
+static void __Pyx_RaiseDoubleKeywordsError(
+    const char* func_name, PyObject* kw_name); /*proto*/
+
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
+
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     \
PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* \
function_name); /*proto*/ +
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+
+static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); \
/*proto*/ +static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, \
PyObject **tb); /*proto*/ +
+static int __Pyx_Print(PyObject *, int); /*proto*/
+#if PY_MAJOR_VERSION >= 3
+static PyObject* __pyx_print = 0;
+static PyObject* __pyx_print_kwargs = 0;
+#endif
+
+static void __Pyx_WriteUnraisable(const char *name); /*proto*/
+
+static void __Pyx_AddTraceback(const char *funcname); /*proto*/
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+/* Type declarations */
+
+/* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":63
+ *     return PyString_FromStringAndSize(bytes, size)
+ * 
+ * cdef long _decode_int(object stream, int sign=0):             # <<<<<<<<<<<<<<
+ *     cdef int n = 0
+ *     cdef long result = 0
+ */
+
+struct __pyx_opt_args_6cpyamf_4amf3__decode_int {
+  int __pyx_n;
+  int sign;
+};
+/* Module declarations from cpyamf.amf3 */
+
+static PyObject *__pyx_f_6cpyamf_4amf3__encode_int(long); /*proto*/
+static long __pyx_f_6cpyamf_4amf3__decode_int(PyObject *, struct \
__pyx_opt_args_6cpyamf_4amf3__decode_int *__pyx_optional_args); /*proto*/ +
+
+/* Implementation of cpyamf.amf3 */
+static char __pyx_k_n[] = "n";
+static PyObject *__pyx_kp_n;
+static char __pyx_k_stream[] = "stream";
+static PyObject *__pyx_kp_stream;
+static char __pyx_k_sign[] = "sign";
+static PyObject *__pyx_kp_sign;
+static char __pyx_k_OverflowError[] = "OverflowError";
+static PyObject *__pyx_kp_OverflowError;
+static char __pyx_k_read_uchar[] = "read_uchar";
+static PyObject *__pyx_kp_read_uchar;
+static char __pyx_k_2[] = "hi";
+static PyObject *__pyx_kp_2;
+static PyObject *__pyx_builtin_OverflowError;
+static PyObject *__pyx_kp_1;
+static char __pyx_k_1[] = "Out of range";
+
+/* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":9
+ * 
+ * 
+ * cdef _encode_int(long n):             # <<<<<<<<<<<<<<
+ *     if n < 0:
+ *         n += 0x20000000
+ */
+
+static  PyObject *__pyx_f_6cpyamf_4amf3__encode_int(long __pyx_v_n) {
+  Py_ssize_t __pyx_v_size;
+  char *__pyx_v_bytes;
+  long __pyx_v_real_value;
+  char __pyx_v_changed;
+  unsigned char __pyx_v_count;
+  PyObject *__pyx_r;
+  int __pyx_1;
+  PyObject *__pyx_2 = 0;
+  PyObject *__pyx_3 = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":10
+ * 
+ * cdef _encode_int(long n):
+ *     if n < 0:             # <<<<<<<<<<<<<<
+ *         n += 0x20000000
+ * 
+ */
+  __pyx_1 = (__pyx_v_n < 0);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":11
+ * cdef _encode_int(long n):
+ *     if n < 0:
+ *         n += 0x20000000             # <<<<<<<<<<<<<<
+ * 
+ *     if n >= 0x40000000:
+ */
+    __pyx_v_n += 0x20000000;
+    goto __pyx_L3;
+  }
+  __pyx_L3:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":13
+ *         n += 0x20000000
+ * 
+ *     if n >= 0x40000000:             # <<<<<<<<<<<<<<
+ *         raise OverflowError("Out of range")
+ * 
+ */
+  __pyx_1 = (__pyx_v_n >= 0x40000000);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":14
+ * 
+ *     if n >= 0x40000000:
+ *         raise OverflowError("Out of range")             # <<<<<<<<<<<<<<
+ * 
+ *     cdef Py_ssize_t size = 0
+ */
+    __pyx_2 = PyTuple_New(1); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; \
__pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +    \
Py_INCREF(__pyx_kp_1); +    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_kp_1);
+    __pyx_3 = PyObject_Call(__pyx_builtin_OverflowError, ((PyObject *)__pyx_2), \
NULL); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; \
__pyx_clineno = __LINE__; goto __pyx_L1_error;} +    Py_DECREF(((PyObject \
*)__pyx_2)); __pyx_2 = 0; +    __Pyx_Raise(__pyx_3, 0, 0);
+    Py_DECREF(__pyx_3); __pyx_3 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto \
__pyx_L1_error;} +    goto __pyx_L4;
+  }
+  __pyx_L4:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":16
+ *         raise OverflowError("Out of range")
+ * 
+ *     cdef Py_ssize_t size = 0             # <<<<<<<<<<<<<<
+ *     cdef char *bytes = NULL
+ *     cdef long real_value = n
+ */
+  __pyx_v_size = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":17
+ * 
+ *     cdef Py_ssize_t size = 0
+ *     cdef char *bytes = NULL             # <<<<<<<<<<<<<<
+ *     cdef long real_value = n
+ *     cdef char changed = 0
+ */
+  __pyx_v_bytes = NULL;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":18
+ *     cdef Py_ssize_t size = 0
+ *     cdef char *bytes = NULL
+ *     cdef long real_value = n             # <<<<<<<<<<<<<<
+ *     cdef char changed = 0
+ *     cdef unsigned char count = 0
+ */
+  __pyx_v_real_value = __pyx_v_n;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":19
+ *     cdef char *bytes = NULL
+ *     cdef long real_value = n
+ *     cdef char changed = 0             # <<<<<<<<<<<<<<
+ *     cdef unsigned char count = 0
+ * 
+ */
+  __pyx_v_changed = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":20
+ *     cdef long real_value = n
+ *     cdef char changed = 0
+ *     cdef unsigned char count = 0             # <<<<<<<<<<<<<<
+ * 
+ *     if n > 0x1fffff:
+ */
+  __pyx_v_count = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":22
+ *     cdef unsigned char count = 0
+ * 
+ *     if n > 0x1fffff:             # <<<<<<<<<<<<<<
+ *         size = 4
+ *         bytes = <char *>PyMem_Malloc(size + 1)
+ */
+  __pyx_1 = (__pyx_v_n > 0x1fffff);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":23
+ * 
+ *     if n > 0x1fffff:
+ *         size = 4             # <<<<<<<<<<<<<<
+ *         bytes = <char *>PyMem_Malloc(size + 1)
+ *         changed = 1
+ */
+    __pyx_v_size = 4;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":24
+ *     if n > 0x1fffff:
+ *         size = 4
+ *         bytes = <char *>PyMem_Malloc(size + 1)             # <<<<<<<<<<<<<<
+ *         changed = 1
+ *         n = n >> 1
+ */
+    __pyx_v_bytes = ((char *)PyMem_Malloc((__pyx_v_size + 1)));
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":25
+ *         size = 4
+ *         bytes = <char *>PyMem_Malloc(size + 1)
+ *         changed = 1             # <<<<<<<<<<<<<<
+ *         n = n >> 1
+ *         bytes[count] = 0x80 | ((n >> 21) & 0xff)
+ */
+    __pyx_v_changed = 1;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":26
+ *         bytes = <char *>PyMem_Malloc(size + 1)
+ *         changed = 1
+ *         n = n >> 1             # <<<<<<<<<<<<<<
+ *         bytes[count] = 0x80 | ((n >> 21) & 0xff)
+ *         count += 1
+ */
+    __pyx_v_n = (__pyx_v_n >> 1);
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":27
+ *         changed = 1
+ *         n = n >> 1
+ *         bytes[count] = 0x80 | ((n >> 21) & 0xff)             # <<<<<<<<<<<<<<
+ *         count += 1
+ * 
+ */
+    (__pyx_v_bytes[__pyx_v_count]) = (0x80 | ((__pyx_v_n >> 21) & 0xff));
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":28
+ *         n = n >> 1
+ *         bytes[count] = 0x80 | ((n >> 21) & 0xff)
+ *         count += 1             # <<<<<<<<<<<<<<
+ * 
+ *     if n > 0x3fff:
+ */
+    __pyx_v_count += 1;
+    goto __pyx_L5;
+  }
+  __pyx_L5:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":30
+ *         count += 1
+ * 
+ *     if n > 0x3fff:             # <<<<<<<<<<<<<<
+ *         if bytes == NULL:
+ *             size = 3
+ */
+  __pyx_1 = (__pyx_v_n > 0x3fff);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":31
+ * 
+ *     if n > 0x3fff:
+ *         if bytes == NULL:             # <<<<<<<<<<<<<<
+ *             size = 3
+ *             bytes = <char *>PyMem_Malloc(size + 1)
+ */
+    __pyx_1 = (__pyx_v_bytes == NULL);
+    if (__pyx_1) {
+
+      /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":32
+ *     if n > 0x3fff:
+ *         if bytes == NULL:
+ *             size = 3             # <<<<<<<<<<<<<<
+ *             bytes = <char *>PyMem_Malloc(size + 1)
+ * 
+ */
+      __pyx_v_size = 3;
+
+      /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":33
+ *         if bytes == NULL:
+ *             size = 3
+ *             bytes = <char *>PyMem_Malloc(size + 1)             # <<<<<<<<<<<<<<
+ * 
+ *         bytes[count] = 0x80 | ((n >> 14) & 0xff)
+ */
+      __pyx_v_bytes = ((char *)PyMem_Malloc((__pyx_v_size + 1)));
+      goto __pyx_L7;
+    }
+    __pyx_L7:;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":35
+ *             bytes = <char *>PyMem_Malloc(size + 1)
+ * 
+ *         bytes[count] = 0x80 | ((n >> 14) & 0xff)             # <<<<<<<<<<<<<<
+ *         count += 1
+ * 
+ */
+    (__pyx_v_bytes[__pyx_v_count]) = (0x80 | ((__pyx_v_n >> 14) & 0xff));
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":36
+ * 
+ *         bytes[count] = 0x80 | ((n >> 14) & 0xff)
+ *         count += 1             # <<<<<<<<<<<<<<
+ * 
+ *     if n > 0x7f:
+ */
+    __pyx_v_count += 1;
+    goto __pyx_L6;
+  }
+  __pyx_L6:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":38
+ *         count += 1
+ * 
+ *     if n > 0x7f:             # <<<<<<<<<<<<<<
+ *         if bytes == NULL:
+ *             size = 2
+ */
+  __pyx_1 = (__pyx_v_n > 0x7f);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":39
+ * 
+ *     if n > 0x7f:
+ *         if bytes == NULL:             # <<<<<<<<<<<<<<
+ *             size = 2
+ *             bytes = <char *>PyMem_Malloc(size + 1)
+ */
+    __pyx_1 = (__pyx_v_bytes == NULL);
+    if (__pyx_1) {
+
+      /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":40
+ *     if n > 0x7f:
+ *         if bytes == NULL:
+ *             size = 2             # <<<<<<<<<<<<<<
+ *             bytes = <char *>PyMem_Malloc(size + 1)
+ * 
+ */
+      __pyx_v_size = 2;
+
+      /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":41
+ *         if bytes == NULL:
+ *             size = 2
+ *             bytes = <char *>PyMem_Malloc(size + 1)             # <<<<<<<<<<<<<<
+ * 
+ *         bytes[count] = 0x80 | ((n >> 7) & 0xff)
+ */
+      __pyx_v_bytes = ((char *)PyMem_Malloc((__pyx_v_size + 1)));
+      goto __pyx_L9;
+    }
+    __pyx_L9:;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":43
+ *             bytes = <char *>PyMem_Malloc(size + 1)
+ * 
+ *         bytes[count] = 0x80 | ((n >> 7) & 0xff)             # <<<<<<<<<<<<<<
+ *         count += 1
+ * 
+ */
+    (__pyx_v_bytes[__pyx_v_count]) = (0x80 | ((__pyx_v_n >> 7) & 0xff));
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":44
+ * 
+ *         bytes[count] = 0x80 | ((n >> 7) & 0xff)
+ *         count += 1             # <<<<<<<<<<<<<<
+ * 
+ *     if changed == 1:
+ */
+    __pyx_v_count += 1;
+    goto __pyx_L8;
+  }
+  __pyx_L8:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":46
+ *         count += 1
+ * 
+ *     if changed == 1:             # <<<<<<<<<<<<<<
+ *         n = real_value
+ * 
+ */
+  __pyx_1 = (__pyx_v_changed == 1);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":47
+ * 
+ *     if changed == 1:
+ *         n = real_value             # <<<<<<<<<<<<<<
+ * 
+ *     if bytes == NULL:
+ */
+    __pyx_v_n = __pyx_v_real_value;
+    goto __pyx_L10;
+  }
+  __pyx_L10:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":49
+ *         n = real_value
+ * 
+ *     if bytes == NULL:             # <<<<<<<<<<<<<<
+ *         size = 1
+ * 
+ */
+  __pyx_1 = (__pyx_v_bytes == NULL);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":50
+ * 
+ *     if bytes == NULL:
+ *         size = 1             # <<<<<<<<<<<<<<
+ * 
+ *         bytes = <char *>PyMem_Malloc(size + 1)
+ */
+    __pyx_v_size = 1;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":52
+ *         size = 1
+ * 
+ *         bytes = <char *>PyMem_Malloc(size + 1)             # <<<<<<<<<<<<<<
+ * 
+ *     if n > 0x1fffff:
+ */
+    __pyx_v_bytes = ((char *)PyMem_Malloc((__pyx_v_size + 1)));
+    goto __pyx_L11;
+  }
+  __pyx_L11:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":54
+ *         bytes = <char *>PyMem_Malloc(size + 1)
+ * 
+ *     if n > 0x1fffff:             # <<<<<<<<<<<<<<
+ *         bytes[count] = n & 0xff
+ *     else:
+ */
+  __pyx_1 = (__pyx_v_n > 0x1fffff);
+  if (__pyx_1) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":55
+ * 
+ *     if n > 0x1fffff:
+ *         bytes[count] = n & 0xff             # <<<<<<<<<<<<<<
+ *     else:
+ *         bytes[count] = n & 0x7f
+ */
+    (__pyx_v_bytes[__pyx_v_count]) = (__pyx_v_n & 0xff);
+    goto __pyx_L12;
+  }
+  /*else*/ {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":57
+ *         bytes[count] = n & 0xff
+ *     else:
+ *         bytes[count] = n & 0x7f             # <<<<<<<<<<<<<<
+ * 
+ *     bytes[count + 1] = 0
+ */
+    (__pyx_v_bytes[__pyx_v_count]) = (__pyx_v_n & 0x7f);
+  }
+  __pyx_L12:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":59
+ *         bytes[count] = n & 0x7f
+ * 
+ *     bytes[count + 1] = 0             # <<<<<<<<<<<<<<
+ * 
+ *     return PyString_FromStringAndSize(bytes, size)
+ */
+  (__pyx_v_bytes[(__pyx_v_count + 1)]) = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":61
+ *     bytes[count + 1] = 0
+ * 
+ *     return PyString_FromStringAndSize(bytes, size)             # <<<<<<<<<<<<<<
+ * 
+ * cdef long _decode_int(object stream, int sign=0):
+ */
+  __pyx_2 = PyString_FromStringAndSize(__pyx_v_bytes, __pyx_v_size); if \
(unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = \
__LINE__; goto __pyx_L1_error;} +  __pyx_r = __pyx_2;
+  __pyx_2 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; Py_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_3);
+  __Pyx_AddTraceback("cpyamf.amf3._encode_int");
+  __pyx_r = 0;
+  __pyx_L0:;
+  return __pyx_r;
+}
+
+/* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":63
+ *     return PyString_FromStringAndSize(bytes, size)
+ * 
+ * cdef long _decode_int(object stream, int sign=0):             # <<<<<<<<<<<<<<
+ *     cdef int n = 0
+ *     cdef long result = 0
+ */
+
+static  long __pyx_f_6cpyamf_4amf3__decode_int(PyObject *__pyx_v_stream, struct \
__pyx_opt_args_6cpyamf_4amf3__decode_int *__pyx_optional_args) { +  int __pyx_v_sign \
= 0; +  int __pyx_v_n;
+  long __pyx_v_result;
+  unsigned char __pyx_v_b;
+  long __pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  unsigned char __pyx_3;
+  int __pyx_4;
+  long __pyx_5;
+  if (__pyx_optional_args) {
+    if (__pyx_optional_args->__pyx_n > 0) {
+      __pyx_v_sign = __pyx_optional_args->sign;
+    }
+  }
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":64
+ * 
+ * cdef long _decode_int(object stream, int sign=0):
+ *     cdef int n = 0             # <<<<<<<<<<<<<<
+ *     cdef long result = 0
+ *     cdef unsigned char b = <unsigned char>stream.read_uchar()
+ */
+  __pyx_v_n = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":65
+ * cdef long _decode_int(object stream, int sign=0):
+ *     cdef int n = 0
+ *     cdef long result = 0             # <<<<<<<<<<<<<<
+ *     cdef unsigned char b = <unsigned char>stream.read_uchar()
+ * 
+ */
+  __pyx_v_result = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":66
+ *     cdef int n = 0
+ *     cdef long result = 0
+ *     cdef unsigned char b = <unsigned char>stream.read_uchar()             # \
<<<<<<<<<<<<<< + * 
+ *     while b & 0x80 != 0 and n < 3:
+ */
+  __pyx_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read_uchar); if \
(unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = \
__LINE__; goto __pyx_L1_error;} +  __pyx_2 = PyObject_Call(__pyx_1, ((PyObject \
*)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; \
__pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
Py_DECREF(__pyx_1); __pyx_1 = 0; +  __pyx_3 = __pyx_PyInt_unsigned_char(__pyx_2); if \
(unlikely((__pyx_3 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = \
__pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
Py_DECREF(__pyx_2); __pyx_2 = 0; +  __pyx_v_b = ((unsigned char)__pyx_3);
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":68
+ *     cdef unsigned char b = <unsigned char>stream.read_uchar()
+ * 
+ *     while b & 0x80 != 0 and n < 3:             # <<<<<<<<<<<<<<
+ *         result <<= 7
+ *         result |= b & 0x7f
+ */
+  while (1) {
+    __pyx_4 = ((__pyx_v_b & 0x80) != 0);
+    if (__pyx_4) {
+      __pyx_4 = (__pyx_v_n < 3);
+    }
+    if (!__pyx_4) break;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":69
+ * 
+ *     while b & 0x80 != 0 and n < 3:
+ *         result <<= 7             # <<<<<<<<<<<<<<
+ *         result |= b & 0x7f
+ *         b = <unsigned char>stream.read_uchar()
+ */
+    __pyx_v_result <<= 7;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":70
+ *     while b & 0x80 != 0 and n < 3:
+ *         result <<= 7
+ *         result |= b & 0x7f             # <<<<<<<<<<<<<<
+ *         b = <unsigned char>stream.read_uchar()
+ *         n += 1
+ */
+    __pyx_v_result |= (__pyx_v_b & 0x7f);
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":71
+ *         result <<= 7
+ *         result |= b & 0x7f
+ *         b = <unsigned char>stream.read_uchar()             # <<<<<<<<<<<<<<
+ *         n += 1
+ * 
+ */
+    __pyx_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read_uchar); if \
(unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = \
__LINE__; goto __pyx_L1_error;} +    __pyx_2 = PyObject_Call(__pyx_1, ((PyObject \
*)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; \
__pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +    \
Py_DECREF(__pyx_1); __pyx_1 = 0; +    __pyx_3 = __pyx_PyInt_unsigned_char(__pyx_2); \
if (unlikely((__pyx_3 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = \
__pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +    \
Py_DECREF(__pyx_2); __pyx_2 = 0; +    __pyx_v_b = ((unsigned char)__pyx_3);
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":72
+ *         result |= b & 0x7f
+ *         b = <unsigned char>stream.read_uchar()
+ *         n += 1             # <<<<<<<<<<<<<<
+ * 
+ *     if n < 3:
+ */
+    __pyx_v_n += 1;
+  }
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":74
+ *         n += 1
+ * 
+ *     if n < 3:             # <<<<<<<<<<<<<<
+ *         result <<= 7
+ *         result |= b
+ */
+  __pyx_4 = (__pyx_v_n < 3);
+  if (__pyx_4) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":75
+ * 
+ *     if n < 3:
+ *         result <<= 7             # <<<<<<<<<<<<<<
+ *         result |= b
+ *     else:
+ */
+    __pyx_v_result <<= 7;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":76
+ *     if n < 3:
+ *         result <<= 7
+ *         result |= b             # <<<<<<<<<<<<<<
+ *     else:
+ *         result <<= 8
+ */
+    __pyx_v_result |= __pyx_v_b;
+    goto __pyx_L5;
+  }
+  /*else*/ {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":78
+ *         result |= b
+ *     else:
+ *         result <<= 8             # <<<<<<<<<<<<<<
+ *         result |= b
+ * 
+ */
+    __pyx_v_result <<= 8;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":79
+ *     else:
+ *         result <<= 8
+ *         result |= b             # <<<<<<<<<<<<<<
+ * 
+ *         if result & 0x10000000 != 0:
+ */
+    __pyx_v_result |= __pyx_v_b;
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":81
+ *         result |= b
+ * 
+ *         if result & 0x10000000 != 0:             # <<<<<<<<<<<<<<
+ *             if sign == 1:
+ *                 result -= 0x20000000
+ */
+    __pyx_4 = ((__pyx_v_result & 0x10000000) != 0);
+    if (__pyx_4) {
+
+      /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":82
+ * 
+ *         if result & 0x10000000 != 0:
+ *             if sign == 1:             # <<<<<<<<<<<<<<
+ *                 result -= 0x20000000
+ *             else:
+ */
+      __pyx_4 = (__pyx_v_sign == 1);
+      if (__pyx_4) {
+
+        /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":83
+ *         if result & 0x10000000 != 0:
+ *             if sign == 1:
+ *                 result -= 0x20000000             # <<<<<<<<<<<<<<
+ *             else:
+ *                 result <<= 1
+ */
+        __pyx_v_result -= 0x20000000;
+        goto __pyx_L7;
+      }
+      /*else*/ {
+
+        /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":85
+ *                 result -= 0x20000000
+ *             else:
+ *                 result <<= 1             # <<<<<<<<<<<<<<
+ *                 result += 1
+ * 
+ */
+        __pyx_v_result <<= 1;
+
+        /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":86
+ *             else:
+ *                 result <<= 1
+ *                 result += 1             # <<<<<<<<<<<<<<
+ * 
+ *     return PyLong_FromLong(result)
+ */
+        __pyx_v_result += 1;
+      }
+      __pyx_L7:;
+      goto __pyx_L6;
+    }
+    __pyx_L6:;
+  }
+  __pyx_L5:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":88
+ *                 result += 1
+ * 
+ *     return PyLong_FromLong(result)             # <<<<<<<<<<<<<<
+ * 
+ * def encode_int(n):
+ */
+  __pyx_1 = PyLong_FromLong(__pyx_v_result); if (unlikely(!__pyx_1)) {__pyx_filename \
= __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
__pyx_5 = __pyx_PyInt_long(__pyx_1); if (unlikely((__pyx_5 == (long)-1) && \
PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = \
__LINE__; goto __pyx_L1_error;} +  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_r = __pyx_5;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  __Pyx_WriteUnraisable("cpyamf.amf3._decode_int");
+  __pyx_r = 0;
+  __pyx_L0:;
+  return __pyx_r;
+}
+
+/* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":90
+ *     return PyLong_FromLong(result)
+ * 
+ * def encode_int(n):             # <<<<<<<<<<<<<<
+ *     return _encode_int(n)
+ * 
+ */
+
+static PyObject *__pyx_pf_6cpyamf_4amf3_encode_int(PyObject *__pyx_self, PyObject \
*__pyx_v_n); /*proto*/ +static PyObject *__pyx_pf_6cpyamf_4amf3_encode_int(PyObject \
*__pyx_self, PyObject *__pyx_v_n) { +  PyObject *__pyx_r;
+  long __pyx_1;
+  PyObject *__pyx_2 = 0;
+  __pyx_self = __pyx_self;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":91
+ * 
+ * def encode_int(n):
+ *     return _encode_int(n)             # <<<<<<<<<<<<<<
+ * 
+ * def decode_int(stream, sign):
+ */
+  __pyx_1 = __pyx_PyInt_long(__pyx_v_n); if (unlikely((__pyx_1 == (long)-1) && \
PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = \
__LINE__; goto __pyx_L1_error;} +  __pyx_2 = \
__pyx_f_6cpyamf_4amf3__encode_int(__pyx_1); if (unlikely(!__pyx_2)) {__pyx_filename = \
__pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
__pyx_r = __pyx_2; +  __pyx_2 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; Py_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  Py_XDECREF(__pyx_2);
+  __Pyx_AddTraceback("cpyamf.amf3.encode_int");
+  __pyx_r = NULL;
+  __pyx_L0:;
+  return __pyx_r;
+}
+
+/* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":93
+ *     return _encode_int(n)
+ * 
+ * def decode_int(stream, sign):             # <<<<<<<<<<<<<<
+ *     cdef int s = 0
+ * 
+ */
+
+static PyObject *__pyx_pf_6cpyamf_4amf3_decode_int(PyObject *__pyx_self, PyObject \
*__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject \
*__pyx_pf_6cpyamf_4amf3_decode_int(PyObject *__pyx_self, PyObject *__pyx_args, \
PyObject *__pyx_kwds) { +  PyObject *__pyx_v_stream = 0;
+  PyObject *__pyx_v_sign = 0;
+  int __pyx_v_s;
+  PyObject *__pyx_r;
+  PyObject *__pyx_1 = 0;
+  int __pyx_2;
+  struct __pyx_opt_args_6cpyamf_4amf3__decode_int __pyx_3;
+  long __pyx_4;
+  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_stream,&__pyx_kp_sign,0};
+  __pyx_self = __pyx_self;
+  if (unlikely(__pyx_kwds)) {
+    PyObject* values[2] = {0,0};
+    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
+    switch (PyTuple_GET_SIZE(__pyx_args)) {
+      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      case  0: break;
+      default: goto __pyx_L5_argtuple_error;
+    }
+    switch (PyTuple_GET_SIZE(__pyx_args)) {
+      case  0:
+      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_stream);
+      if (likely(values[0])) kw_args--;
+      else goto __pyx_L5_argtuple_error;
+      case  1:
+      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_sign);
+      if (likely(values[1])) kw_args--;
+      else {
+        __Pyx_RaiseArgtupleInvalid("decode_int", 1, 2, 2, 1); {__pyx_filename = \
__pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} +      \
} +    }
+    if (unlikely(kw_args > 0)) {
+      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, \
values, PyTuple_GET_SIZE(__pyx_args), "decode_int") < 0)) {__pyx_filename = \
__pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} +    }
+    __pyx_v_stream = values[0];
+    __pyx_v_sign = values[1];
+  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+    goto __pyx_L5_argtuple_error;
+  } else {
+    __pyx_v_stream = PyTuple_GET_ITEM(__pyx_args, 0);
+    __pyx_v_sign = PyTuple_GET_ITEM(__pyx_args, 1);
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("decode_int", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); \
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto \
__pyx_L3_error;} +  __pyx_L3_error:;
+  __Pyx_AddTraceback("cpyamf.amf3.decode_int");
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":94
+ * 
+ * def decode_int(stream, sign):
+ *     cdef int s = 0             # <<<<<<<<<<<<<<
+ * 
+ *     if sign is True:
+ */
+  __pyx_v_s = 0;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":96
+ *     cdef int s = 0
+ * 
+ *     if sign is True:             # <<<<<<<<<<<<<<
+ *         s = 1
+ *     else:
+ */
+  __pyx_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_1)) {__pyx_filename = \
__pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
__pyx_2 = (__pyx_v_sign == __pyx_1); +  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  if (__pyx_2) {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":97
+ * 
+ *     if sign is True:
+ *         s = 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         s = 0
+ */
+    __pyx_v_s = 1;
+    goto __pyx_L6;
+  }
+  /*else*/ {
+
+    /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":99
+ *         s = 1
+ *     else:
+ *         s = 0             # <<<<<<<<<<<<<<
+ * 
+ *     print 'hi'
+ */
+    __pyx_v_s = 0;
+  }
+  __pyx_L6:;
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":101
+ *         s = 0
+ * 
+ *     print 'hi'             # <<<<<<<<<<<<<<
+ * 
+ *     return _decode_int(stream, s)
+ */
+  __pyx_1 = PyTuple_New(1); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; \
__pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
Py_INCREF(__pyx_kp_2); +  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_kp_2);
+  if (__Pyx_Print(((PyObject *)__pyx_1), 1) < 0) {__pyx_filename = __pyx_f[0]; \
__pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
Py_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0; +
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":103
+ *     print 'hi'
+ * 
+ *     return _decode_int(stream, s)             # <<<<<<<<<<<<<<
+ * 
+ */
+  __pyx_3.__pyx_n = 1;
+  __pyx_3.sign = __pyx_v_s;
+  __pyx_4 = __pyx_f_6cpyamf_4amf3__decode_int(__pyx_v_stream, &__pyx_3); 
+  __pyx_1 = PyInt_FromLong(__pyx_4); if (unlikely(!__pyx_1)) {__pyx_filename = \
__pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
__pyx_r = __pyx_1; +  __pyx_1 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; Py_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  Py_XDECREF(__pyx_1);
+  __Pyx_AddTraceback("cpyamf.amf3.decode_int");
+  __pyx_r = NULL;
+  __pyx_L0:;
+  return __pyx_r;
+}
+
+static struct PyMethodDef __pyx_methods[] = {
+  {"encode_int", (PyCFunction)__pyx_pf_6cpyamf_4amf3_encode_int, METH_O, 0},
+  {"decode_int", (PyCFunction)__pyx_pf_6cpyamf_4amf3_decode_int, \
METH_VARARGS|METH_KEYWORDS, 0}, +  {0, 0, 0, 0}
+};
+
+static void __pyx_init_filenames(void); /*proto*/
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef __pyx_moduledef = {
+    PyModuleDef_HEAD_INIT,
+    "amf3",
+    0, /* m_doc */
+    -1, /* m_size */
+    __pyx_methods /* m_methods */,
+    NULL, /* m_reload */
+    NULL, /* m_traverse */
+    NULL, /* m_clear */
+    NULL /* m_free */
+};
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+  {&__pyx_kp_n, __pyx_k_n, sizeof(__pyx_k_n), 1, 1, 1},
+  {&__pyx_kp_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 1, 1, 1},
+  {&__pyx_kp_sign, __pyx_k_sign, sizeof(__pyx_k_sign), 1, 1, 1},
+  {&__pyx_kp_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 1, \
1, 1}, +  {&__pyx_kp_read_uchar, __pyx_k_read_uchar, sizeof(__pyx_k_read_uchar), 1, \
1, 1}, +  {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0},
+  {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 0},
+  {0, 0, 0, 0, 0, 0}
+};
+static int __Pyx_InitCachedBuiltins(void) {
+  __pyx_builtin_OverflowError = __Pyx_GetName(__pyx_b, __pyx_kp_OverflowError); if \
(!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; \
__pyx_clineno = __LINE__; goto __pyx_L1_error;} +  return 0;
+  __pyx_L1_error:;
+  return -1;
+}
+
+static int __Pyx_InitGlobals(void) {
+  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; \
__pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; +  return 0;
+  __pyx_L1_error:;
+  return -1;
+}
+
+#if PY_MAJOR_VERSION < 3
+PyMODINIT_FUNC initamf3(void); /*proto*/
+PyMODINIT_FUNC initamf3(void)
+#else
+PyMODINIT_FUNC PyInit_amf3(void); /*proto*/
+PyMODINIT_FUNC PyInit_amf3(void)
+#endif
+{
+  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) \
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto \
__pyx_L1_error;} +  /*--- Library function declarations ---*/
+  __pyx_init_filenames();
+  /*--- Initialize various global constants etc. ---*/
+  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno \
= 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  /*--- Module creation code \
---*/ +  #if PY_MAJOR_VERSION < 3
+  __pyx_m = Py_InitModule4("amf3", __pyx_methods, 0, 0, PYTHON_API_VERSION);
+  #else
+  __pyx_m = PyModule_Create(&__pyx_moduledef);
+  #endif
+  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = \
__LINE__; goto __pyx_L1_error;}; +  #if PY_MAJOR_VERSION < 3
+  Py_INCREF(__pyx_m);
+  #endif
+  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME);
+  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = \
__LINE__; goto __pyx_L1_error;}; +  if (PyObject_SetAttrString(__pyx_m, \
"__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; \
__pyx_clineno = __LINE__; goto __pyx_L1_error;}; +  /*--- Builtin init code ---*/
+  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; \
__pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +  \
__pyx_skip_dispatch = 0; +  /*--- Global init code ---*/
+  /*--- Function export code ---*/
+  /*--- Type init code ---*/
+  /*--- Type import code ---*/
+  /*--- Function import code ---*/
+  /*--- Execution code ---*/
+
+  /* "/Users/nick/projects/pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx":93
+ *     return _encode_int(n)
+ * 
+ * def decode_int(stream, sign):             # <<<<<<<<<<<<<<
+ *     cdef int s = 0
+ * 
+ */
+  #if PY_MAJOR_VERSION < 3
+  return;
+  #else
+  return __pyx_m;
+  #endif
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("cpyamf.amf3");
+  #if PY_MAJOR_VERSION >= 3
+  return NULL;
+  #endif
+}
+
+static const char *__pyx_filenames[] = {
+  "amf3.pyx",
+};
+
+/* Runtime support code */
+
+static void __pyx_init_filenames(void) {
+  __pyx_f = __pyx_filenames;
+}
+
+static void __Pyx_RaiseDoubleKeywordsError(
+    const char* func_name,
+    PyObject* kw_name)
+{
+    PyErr_Format(PyExc_TypeError,
+        #if PY_MAJOR_VERSION >= 3
+        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
+        #else
+        "%s() got multiple values for keyword argument '%s'", func_name,
+        PyString_AS_STRING(kw_name));
+        #endif
+}
+
+static void __Pyx_RaiseArgtupleInvalid(
+    const char* func_name,
+    int exact,
+    Py_ssize_t num_min,
+    Py_ssize_t num_max,
+    Py_ssize_t num_found)
+{
+    Py_ssize_t num_expected;
+    const char *number, *more_or_less;
+
+    if (num_found < num_min) {
+        num_expected = num_min;
+        more_or_less = "at least";
+    } else {
+        num_expected = num_max;
+        more_or_less = "at most";
+    }
+    if (exact) {
+        more_or_less = "exactly";
+    }
+    number = (num_expected == 1) ? "" : "s";
+    PyErr_Format(PyExc_TypeError,
+        #if PY_VERSION_HEX < 0x02050000
+            "%s() takes %s %d positional argument%s (%d given)",
+        #else
+            "%s() takes %s %zd positional argument%s (%zd given)",
+        #endif
+        func_name, more_or_less, num_expected, number, num_found);
+}
+
+static int __Pyx_ParseOptionalKeywords(
+    PyObject *kwds,
+    PyObject **argnames[],
+    PyObject *kwds2,
+    PyObject *values[],
+    Py_ssize_t num_pos_args,
+    const char* function_name)
+{
+    PyObject *key = 0, *value = 0;
+    Py_ssize_t pos = 0;
+    PyObject*** name;
+    PyObject*** first_kw_arg = argnames + num_pos_args;
+
+    while (PyDict_Next(kwds, &pos, &key, &value)) {
+        #if PY_MAJOR_VERSION < 3
+        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
+        #else
+        if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) \
{ +        #endif
+            goto invalid_keyword_type;
+        } else {
+            name = argnames;
+            while (*name && (**name != key)) name++;
+            if (*name) {
+                if (name < first_kw_arg) goto arg_passed_twice;
+                values[name-argnames] = value;
+            } else {
+                for (name = first_kw_arg; *name; name++) {
+                    #if PY_MAJOR_VERSION >= 3
+                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
+                        PyUnicode_Compare(**name, key) == 0) break;
+                    #else
+                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
+                        strcmp(PyString_AS_STRING(**name),
+                               PyString_AS_STRING(key)) == 0) break;
+                    #endif
+                }
+                if (*name) {
+                    values[name-argnames] = value;
+                } else {
+                    /* unexpected keyword found */
+                    for (name=argnames; name != first_kw_arg; name++) {
+                        if (**name == key) goto arg_passed_twice;
+                        #if PY_MAJOR_VERSION >= 3
+                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
+                            PyUnicode_Compare(**name, key) == 0) goto \
arg_passed_twice; +                        #else
+                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
+                            strcmp(PyString_AS_STRING(**name),
+                                   PyString_AS_STRING(key)) == 0) goto \
arg_passed_twice; +                        #endif
+                    }
+                    if (kwds2) {
+                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+                    } else {
+                        goto invalid_keyword;
+                    }
+                }
+            }
+        }
+    }
+    return 0;
+arg_passed_twice:
+    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
+    goto bad;
+invalid_keyword_type:
+    PyErr_Format(PyExc_TypeError,
+        "%s() keywords must be strings", function_name);
+    goto bad;
+invalid_keyword:
+    PyErr_Format(PyExc_TypeError,
+    #if PY_MAJOR_VERSION < 3
+        "%s() got an unexpected keyword argument '%s'",
+        function_name, PyString_AsString(key));
+    #else
+        "%s() got an unexpected keyword argument '%U'",
+        function_name, key);
+    #endif
+bad:
+    return -1;
+}
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+    PyObject *result;
+    result = PyObject_GetAttr(dict, name);
+    if (!result)
+        PyErr_SetObject(PyExc_NameError, name);
+    return result;
+}
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
+    Py_XINCREF(type);
+    Py_XINCREF(value);
+    Py_XINCREF(tb);
+    /* First, check the traceback argument, replacing None with NULL. */
+    if (tb == Py_None) {
+        Py_DECREF(tb);
+        tb = 0;
+    }
+    else if (tb != NULL && !PyTraceBack_Check(tb)) {
+        PyErr_SetString(PyExc_TypeError,
+            "raise: arg 3 must be a traceback or None");
+        goto raise_error;
+    }
+    /* Next, replace a missing value with None */
+    if (value == NULL) {
+        value = Py_None;
+        Py_INCREF(value);
+    }
+    #if PY_VERSION_HEX < 0x02050000
+    if (!PyClass_Check(type))
+    #else
+    if (!PyType_Check(type))
+    #endif
+    {
+        /* Raising an instance.  The value should be a dummy. */
+        if (value != Py_None) {
+            PyErr_SetString(PyExc_TypeError,
+                "instance exception may not have a separate value");
+            goto raise_error;
+        }
+        /* Normalize to raise <class>, <instance> */
+        Py_DECREF(value);
+        value = type;
+        #if PY_VERSION_HEX < 0x02050000
+            if (PyInstance_Check(type)) {
+                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+                Py_INCREF(type);
+            }
+            else {
+                type = 0;
+                PyErr_SetString(PyExc_TypeError,
+                    "raise: exception must be an old-style class or instance");
+                goto raise_error;
+            }
+        #else
+            type = (PyObject*) Py_TYPE(type);
+            Py_INCREF(type);
+            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject \
*)PyExc_BaseException)) { +                PyErr_SetString(PyExc_TypeError,
+                    "raise: exception class must be a subclass of BaseException");
+                goto raise_error;
+            }
+        #endif
+    }
+    __Pyx_ErrRestore(type, value, tb);
+    return;
+raise_error:
+    Py_XDECREF(value);
+    Py_XDECREF(type);
+    Py_XDECREF(tb);
+    return;
+}
+
+static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    PyThreadState *tstate = PyThreadState_GET();
+
+    tmp_type = tstate->curexc_type;
+    tmp_value = tstate->curexc_value;
+    tmp_tb = tstate->curexc_traceback;
+    tstate->curexc_type = type;
+    tstate->curexc_value = value;
+    tstate->curexc_traceback = tb;
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+}
+
+static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) \
{ +    PyThreadState *tstate = PyThreadState_GET();
+    *type = tstate->curexc_type;
+    *value = tstate->curexc_value;
+    *tb = tstate->curexc_traceback;
+
+    tstate->curexc_type = 0;
+    tstate->curexc_value = 0;
+    tstate->curexc_traceback = 0;
+}
+
+
+#if PY_MAJOR_VERSION < 3
+static PyObject *__Pyx_GetStdout(void) {
+    PyObject *f = PySys_GetObject("stdout");
+    if (!f) {
+        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+    }
+    return f;
+}
+
+static int __Pyx_Print(PyObject *arg_tuple, int newline) {
+    PyObject *f;
+    PyObject* v;
+    int i;
+    
+    if (!(f = __Pyx_GetStdout()))
+        return -1;
+    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
+        if (PyFile_SoftSpace(f, 1)) {
+            if (PyFile_WriteString(" ", f) < 0)
+                return -1;
+        }
+        v = PyTuple_GET_ITEM(arg_tuple, i);
+        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
+            return -1;
+        if (PyString_Check(v)) {
+            char *s = PyString_AsString(v);
+            Py_ssize_t len = PyString_Size(v);
+            if (len > 0 &&
+                isspace(Py_CHARMASK(s[len-1])) &&
+                s[len-1] != ' ')
+                    PyFile_SoftSpace(f, 0);
+        }
+    }
+    if (newline) {
+        if (PyFile_WriteString("\n", f) < 0)
+            return -1;
+        PyFile_SoftSpace(f, 0);
+    }
+    return 0;
+}
+
+#else /* Python 3 has a print function */
+static int __Pyx_Print(PyObject *arg_tuple, int newline) {
+    PyObject* kwargs = 0;
+    PyObject* result = 0;
+    PyObject* end_string;
+    if (!__pyx_print) {
+        __pyx_print = PyObject_GetAttrString(__pyx_b, "print");
+        if (!__pyx_print)
+            return -1;
+    }
+    if (!newline) {
+        if (!__pyx_print_kwargs) {
+            __pyx_print_kwargs = PyDict_New();
+            if (!__pyx_print_kwargs)
+                return -1;
+            end_string = PyUnicode_FromStringAndSize(" ", 1);
+            if (!end_string)
+                return -1;
+            if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) {
+                Py_DECREF(end_string);
+                return -1;
+            }
+            Py_DECREF(end_string);
+        }
+        kwargs = __pyx_print_kwargs;
+    }
+    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
+    if (!result)
+        return -1;
+    Py_DECREF(result);
+    return 0;
+}
+#endif
+
+static void __Pyx_WriteUnraisable(const char *name) {
+    PyObject *old_exc, *old_val, *old_tb;
+    PyObject *ctx;
+    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
+    #if PY_MAJOR_VERSION < 3
+    ctx = PyString_FromString(name);
+    #else
+    ctx = PyUnicode_FromString(name);
+    #endif
+    __Pyx_ErrRestore(old_exc, old_val, old_tb);
+    if (!ctx) {
+        PyErr_WriteUnraisable(Py_None);
+    } else {
+        PyErr_WriteUnraisable(ctx);
+        Py_DECREF(ctx);
+    }
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+
+static void __Pyx_AddTraceback(const char *funcname) {
+    PyObject *py_srcfile = 0;
+    PyObject *py_funcname = 0;
+    PyObject *py_globals = 0;
+    PyObject *empty_string = 0;
+    PyCodeObject *py_code = 0;
+    PyFrameObject *py_frame = 0;
+
+    #if PY_MAJOR_VERSION < 3
+    py_srcfile = PyString_FromString(__pyx_filename);
+    #else
+    py_srcfile = PyUnicode_FromString(__pyx_filename);
+    #endif
+    if (!py_srcfile) goto bad;
+    if (__pyx_clineno) {
+        #if PY_MAJOR_VERSION < 3
+        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, \
__pyx_clineno); +        #else
+        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, \
__pyx_clineno); +        #endif
+    }
+    else {
+        #if PY_MAJOR_VERSION < 3
+        py_funcname = PyString_FromString(funcname);
+        #else
+        py_funcname = PyUnicode_FromString(funcname);
+        #endif
+    }
+    if (!py_funcname) goto bad;
+    py_globals = PyModule_GetDict(__pyx_m);
+    if (!py_globals) goto bad;
+    #if PY_MAJOR_VERSION < 3
+    empty_string = PyString_FromStringAndSize("", 0);
+    #else
+    empty_string = PyBytes_FromStringAndSize("", 0);
+    #endif
+    if (!empty_string) goto bad;
+    py_code = PyCode_New(
+        0,            /*int argcount,*/
+        #if PY_MAJOR_VERSION >= 3
+        0,            /*int kwonlyargcount,*/
+        #endif
+        0,            /*int nlocals,*/
+        0,            /*int stacksize,*/
+        0,            /*int flags,*/
+        empty_string, /*PyObject *code,*/
+        __pyx_empty_tuple,  /*PyObject *consts,*/
+        __pyx_empty_tuple,  /*PyObject *names,*/
+        __pyx_empty_tuple,  /*PyObject *varnames,*/
+        __pyx_empty_tuple,  /*PyObject *freevars,*/
+        __pyx_empty_tuple,  /*PyObject *cellvars,*/
+        py_srcfile,   /*PyObject *filename,*/
+        py_funcname,  /*PyObject *name,*/
+        __pyx_lineno,   /*int firstlineno,*/
+        empty_string  /*PyObject *lnotab*/
+    );
+    if (!py_code) goto bad;
+    py_frame = PyFrame_New(
+        PyThreadState_GET(), /*PyThreadState *tstate,*/
+        py_code,             /*PyCodeObject *code,*/
+        py_globals,          /*PyObject *globals,*/
+        0                    /*PyObject *locals*/
+    );
+    if (!py_frame) goto bad;
+    py_frame->f_lineno = __pyx_lineno;
+    PyTraceBack_Here(py_frame);
+bad:
+    Py_XDECREF(py_srcfile);
+    Py_XDECREF(py_funcname);
+    Py_XDECREF(empty_string);
+    Py_XDECREF(py_code);
+    Py_XDECREF(py_frame);
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+    while (t->p) {
+        #if PY_MAJOR_VERSION < 3
+        if (t->is_unicode && (!t->is_identifier)) {
+            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+        } else if (t->intern) {
+            *t->p = PyString_InternFromString(t->s);
+        } else {
+            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+        }
+        #else  /* Python 3+ has unicode identifiers */
+        if (t->is_identifier || (t->is_unicode && t->intern)) {
+            *t->p = PyUnicode_InternFromString(t->s);
+        } else if (t->is_unicode) {
+            *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+        } else {
+            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+        }
+        #endif
+        if (!*t->p)
+            return -1;
+        ++t;
+    }
+    return 0;
+}
+
+/* Type Conversion Functions */
+
+static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b) {
+  Py_ssize_t ival;
+  PyObject* x = PyNumber_Index(b);
+  if (!x) return -1;
+  ival = PyInt_AsSsize_t(x);
+  Py_DECREF(x);
+  return ival;
+}
+
+static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+   if (x == Py_True) return 1;
+   else if (x == Py_False) return 0;
+   else return PyObject_IsTrue(x);
+}
+
+static INLINE PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x) {
+    if (PyInt_CheckExact(x)) {
+        return PyInt_AS_LONG(x);
+    }
+    else if (PyLong_CheckExact(x)) {
+        return PyLong_AsLongLong(x);
+    }
+    else {
+        PY_LONG_LONG val;
+        PyObject* tmp = PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1;
+        val = __pyx_PyInt_AsLongLong(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+}
+
+static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
+    if (PyInt_CheckExact(x)) {
+        long val = PyInt_AS_LONG(x);
+        if (unlikely(val < 0)) {
+            PyErr_SetString(PyExc_TypeError, "Negative assignment to unsigned \
type."); +            return (unsigned PY_LONG_LONG)-1;
+        }
+        return val;
+    }
+    else if (PyLong_CheckExact(x)) {
+        return PyLong_AsUnsignedLongLong(x);
+    }
+    else {
+        PY_LONG_LONG val;
+        PyObject* tmp = PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1;
+        val = __pyx_PyInt_AsUnsignedLongLong(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+}
+
+
+static INLINE unsigned char __pyx_PyInt_unsigned_char(PyObject* x) {
+    if (sizeof(unsigned char) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        unsigned char val = (unsigned char)long_val;
+        if (unlikely((val != long_val)  || (long_val < 0))) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
unsigned char"); +            return (unsigned char)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE unsigned short __pyx_PyInt_unsigned_short(PyObject* x) {
+    if (sizeof(unsigned short) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        unsigned short val = (unsigned short)long_val;
+        if (unlikely((val != long_val)  || (long_val < 0))) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
unsigned short"); +            return (unsigned short)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE char __pyx_PyInt_char(PyObject* x) {
+    if (sizeof(char) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        char val = (char)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
char"); +            return (char)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE short __pyx_PyInt_short(PyObject* x) {
+    if (sizeof(short) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        short val = (short)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
short"); +            return (short)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE int __pyx_PyInt_int(PyObject* x) {
+    if (sizeof(int) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        int val = (int)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
int"); +            return (int)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE long __pyx_PyInt_long(PyObject* x) {
+    if (sizeof(long) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        long val = (long)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
long"); +            return (long)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE signed char __pyx_PyInt_signed_char(PyObject* x) {
+    if (sizeof(signed char) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        signed char val = (signed char)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
signed char"); +            return (signed char)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE signed short __pyx_PyInt_signed_short(PyObject* x) {
+    if (sizeof(signed short) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        signed short val = (signed short)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
signed short"); +            return (signed short)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE signed int __pyx_PyInt_signed_int(PyObject* x) {
+    if (sizeof(signed int) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        signed int val = (signed int)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
signed int"); +            return (signed int)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE signed long __pyx_PyInt_signed_long(PyObject* x) {
+    if (sizeof(signed long) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        signed long val = (signed long)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to \
signed long"); +            return (signed long)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+
+static INLINE long double __pyx_PyInt_long_double(PyObject* x) {
+    if (sizeof(long double) < sizeof(long)) {
+        long long_val = __pyx_PyInt_AsLong(x);
+        long double val = (long double)long_val;
+        if (unlikely((val != long_val) )) {
+            PyErr_SetString(PyExc_OverflowError, "value too large to convert to long \
double"); +            return (long double)-1;
+        }
+        return val;
+    }
+    else {
+        return __pyx_PyInt_AsLong(x);
+    }
+}
+

Added: pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx
===================================================================
--- pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx	                        (rev 0)
+++ pyamf/branches/cpyamf-amf3/cpyamf/amf3.pyx	2008-11-24 14:50:58 UTC (rev 1798)
@@ -0,0 +1,102 @@
+cdef extern from "Python.h":
+    ctypedef unsigned long size_t
+    void *PyMem_Malloc(size_t n)
+    void PyMem_Free(void *p)
+    object PyString_FromStringAndSize(char *buffer, Py_ssize_t length)
+    object PyLong_FromLong(long v)
+
+
+cdef _encode_int(long n):
+    if n < 0:
+        n += 0x20000000
+
+    if n >= 0x40000000:
+        raise OverflowError("Out of range")
+
+    cdef Py_ssize_t size = 0
+    cdef char *bytes = NULL
+    cdef long real_value = n
+    cdef char changed = 0
+    cdef unsigned char count = 0
+
+    if n > 0x1fffff:
+        size = 4
+        bytes = <char *>PyMem_Malloc(size + 1)
+        changed = 1
+        n = n >> 1
+        bytes[count] = 0x80 | ((n >> 21) & 0xff)
+        count += 1
+
+    if n > 0x3fff:
+        if bytes == NULL:
+            size = 3
+            bytes = <char *>PyMem_Malloc(size + 1)
+
+        bytes[count] = 0x80 | ((n >> 14) & 0xff)
+        count += 1
+
+    if n > 0x7f:
+        if bytes == NULL:
+            size = 2
+            bytes = <char *>PyMem_Malloc(size + 1)
+
+        bytes[count] = 0x80 | ((n >> 7) & 0xff)
+        count += 1
+
+    if changed == 1:
+        n = real_value
+
+    if bytes == NULL:
+        size = 1
+
+        bytes = <char *>PyMem_Malloc(size + 1)
+
+    if n > 0x1fffff:
+        bytes[count] = n & 0xff
+    else:
+        bytes[count] = n & 0x7f
+
+    bytes[count + 1] = 0
+
+    return PyString_FromStringAndSize(bytes, size)
+
+cdef long _decode_int(object stream, int sign=0):
+    cdef int n = 0
+    cdef long result = 0
+    cdef unsigned char b = <unsigned char>stream.read_uchar()
+
+    while b & 0x80 != 0 and n < 3:
+        result <<= 7
+        result |= b & 0x7f
+        b = <unsigned char>stream.read_uchar()
+        n += 1
+
+    if n < 3:
+        result <<= 7
+        result |= b
+    else:
+        result <<= 8
+        result |= b
+
+        if result & 0x10000000 != 0:
+            if sign == 1:
+                result -= 0x20000000
+            else:
+                result <<= 1
+                result += 1
+
+    return PyLong_FromLong(result)
+
+def encode_int(n):
+    return _encode_int(n)
+
+def decode_int(stream, sign):
+    cdef int s = 0
+
+    if sign is True:
+        s = 1
+    else:
+        s = 0
+
+    return _decode_int(stream, s)
+    
\ No newline at end of file

Modified: pyamf/branches/cpyamf-amf3/pyamf/amf3.py
===================================================================
--- pyamf/trunk/pyamf/amf3.py	2008-11-23 20:33:48 UTC (rev 1796)
+++ pyamf/branches/cpyamf-amf3/pyamf/amf3.py	2008-11-24 14:50:58 UTC (rev 1798)
@@ -971,31 +971,8 @@
         <http://osflash.org/amf3/parsing_integers>} for the AMF3 integer data
         format.
         """
-        n = result = 0
-        b = self.stream.read_uchar()
+        return _decode_int(self.stream, signed)
 
-        while b & 0x80 != 0 and n < 3:
-            result <<= 7
-            result |= b & 0x7f
-            b = self.stream.read_uchar()
-            n += 1
-
-        if n < 3:
-            result <<= 7
-            result |= b
-        else:
-            result <<= 8
-            result |= b
-
-            if result & 0x10000000 != 0:
-                if signed:
-                    result -= 0x20000000
-                else:
-                    result <<= 1
-                    result += 1
-
-        return result
-
     def readString(self, use_references=True):
         """
         Reads and returns a string from the stream.
@@ -1766,36 +1743,68 @@
 
     return buf
 
-def _encode_int(n):
-    """
-    @raise ValueError: Out of range.
-    """
-    if n & 0xf0000000 not in [0, 0xf0000000]:
-        raise OverflowError("Out of range")
+try:
+    from cpyamf.amf3 import encode_int as _encode_int
+except ImportError:
+    def _encode_int(n):
+        """
+        @raise OverflowError: Out of range.
+        """
+        if n & 0xf0000000 not in [0, 0xf0000000]:
+            raise OverflowError("Out of range")
 
-    bytes = ''
-    real_value = None
+        bytes = ''
+        real_value = None
 
-    if n < 0:
-        n += 0x20000000
+        if n < 0:
+            n += 0x20000000
 
-    if n > 0x1fffff:
-        real_value = n
-        n >>= 1
-        bytes += chr(0x80 | ((n >> 21) & 0xff))
+        if n > 0x1fffff:
+            real_value = n
+            n >>= 1
+            bytes += chr(0x80 | ((n >> 21) & 0xff))
 
-    if n > 0x3fff:
-        bytes += chr(0x80 | ((n >> 14) & 0xff))
+        if n > 0x3fff:
+            bytes += chr(0x80 | ((n >> 14) & 0xff))
 
-    if n > 0x7f:
-        bytes += chr(0x80 | ((n >> 7) & 0xff))
+        if n > 0x7f:
+            bytes += chr(0x80 | ((n >> 7) & 0xff))
 
-    if real_value is not None:
-        n = real_value
+        if real_value is not None:
+            n = real_value
 
-    if n > 0x1fffff:
-        bytes += chr(n & 0xff)
-    else:
-        bytes += chr(n & 0x7f)
+        if n > 0x1fffff:
+            bytes += chr(n & 0xff)
+        else:
+            bytes += chr(n & 0x7f)
 
-    return bytes
+        return bytes
+
+try:
+    from cpyamf.amf3 import decode_int as _decode_int
+except ImportError:
+    def _decode_int(stream, signed=False):
+        n = result = 0
+        b = stream.read_uchar()
+
+        while b & 0x80 != 0 and n < 3:
+            result <<= 7
+            result |= b & 0x7f
+            b = stream.read_uchar()
+            n += 1
+
+        if n < 3:
+            result <<= 7
+            result |= b
+        else:
+            result <<= 8
+            result |= b
+
+            if result & 0x10000000 != 0:
+                if signed:
+                    result -= 0x20000000
+                else:
+                    result <<= 1
+                    result += 1
+
+        return result
\ No newline at end of file

Modified: pyamf/branches/cpyamf-amf3/setup.py
===================================================================
--- pyamf/trunk/setup.py	2008-11-23 20:33:48 UTC (rev 1796)
+++ pyamf/branches/cpyamf-amf3/setup.py	2008-11-24 14:50:58 UTC (rev 1798)
@@ -37,6 +37,7 @@
 
 if USE_CPYAMF and not sys.platform.startswith('java'):
     ext_modules.append(Extension('cpyamf.util', ["cpyamf/util.c"], \
extra_compile_args=['-O3'])) +    ext_modules.append(Extension('cpyamf.amf3', \
["cpyamf/amf3.c"], extra_compile_args=['-O3']))  
 install_requires = []
 if sys.version_info < (2, 5):


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic