/* Generated by Cython 0.14.1 on Mon Apr 25 10:26:50 2011 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else

#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif

#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif

#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif

#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif

#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#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 PY_FORMAT_SIZE_T ""
  #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)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#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_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 PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif

#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)

#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #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
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif


#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif

#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE_API__enthought__traits__protocols___speedups

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif


/* inline attribute */
#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

/* unused attribute */
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || defined(__INTEL_COMPILER)
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(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 PyObject *__pyx_empty_bytes;
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[] = {
  "_speedups.pyx",
};

/* Type declarations */

/* "traits/protocols/_speedups.pyx":101
 * 
 * 
 * cdef class metamethod:             # <<<<<<<<<<<<<<
 *     """Wrapper for metaclass method that might be confused w/instance method"""
 * 
 */

struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod {
  PyObject_HEAD
  PyObject *func;
};

#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif

#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
  end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*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 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 CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/


static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
    }
    return r;
}

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from traits.protocols._speedups */

static PyTypeObject *__pyx_ptype_9enthought_6traits_9protocols_9_speedups_metamethod = 0;
static PyObject *__pyx_v_9enthought_6traits_9protocols_9_speedups__marker = 0;
static PyObject *__pyx_v_9enthought_6traits_9protocols_9_speedups___conform = 0;
static PyObject *__pyx_v_9enthought_6traits_9protocols_9_speedups___adapt = 0;
static PyObject *__pyx_v_9enthought_6traits_9protocols_9_speedups___mro = 0;
static PyObject *__pyx_v_9enthought_6traits_9protocols_9_speedups___ECType = 0;
static PyObject *__pyx_f_9enthought_6traits_9protocols_9_speedups__adapt(PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/
static PyObject *__pyx_f_9enthought_6traits_9protocols_9_speedups_buildClassicMRO(PyClassObject *, PyListObject *); /*proto*/
static PyObject *__pyx_f_9enthought_6traits_9protocols_9_speedups_buildECMRO(PyObject *, PyListObject *); /*proto*/
#define __Pyx_MODULE_NAME "traits.protocols._speedups"
static int __pyx_module_is_main_enthought__traits__protocols___speedups = 0;

/* Implementation of traits.protocols._speedups */
static PyObject *__pyx_builtin___import__;
static PyObject *__pyx_builtin_ImportError;
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_DeprecationWarning;
static PyObject *__pyx_builtin_Exception;
static char __pyx_k_1[] = "Read-only attribute";
static char __pyx_k_4[] = "The 'factory' argument to 'adapt()' will be removed in 1.0";
static char __pyx_k_5[] = "Can't adapt";
static char __pyx_k_10[] = "Not a classic class";
static char __pyx_k_13[] = "C Speedups for commonly-used operations";
static char __pyx_k_15[] = "traits.protocols._speedups";
static char __pyx_k__ob[] = "ob";
static char __pyx_k__get[] = "get";
static char __pyx_k__obj[] = "obj";
static char __pyx_k__sys[] = "sys";
static char __pyx_k__func[] = "func";
static char __pyx_k__self[] = "self";
static char __pyx_k__warn[] = "warn";
static char __pyx_k__adapt[] = "adapt";
static char __pyx_k__level[] = "level";
static char __pyx_k__getMRO[] = "getMRO";
static char __pyx_k__object[] = "object";
static char __pyx_k__tp_mro[] = "tp_mro";
static char __pyx_k____all__[] = "__all__";
static char __pyx_k____class[] = "__class";
static char __pyx_k____mro__[] = "__mro__";
static char __pyx_k__default[] = "default";
static char __pyx_k__factory[] = "factory";
static char __pyx_k__globals[] = "globals";
static char __pyx_k__ob_type[] = "ob_type";
static char __pyx_k__tb_next[] = "tb_next";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____name__[] = "__name__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__cl_bases[] = "cl_bases";
static char __pyx_k__exc_info[] = "exc_info";
static char __pyx_k__fromlist[] = "fromlist";
static char __pyx_k__in_class[] = "in_class";
static char __pyx_k__protocol[] = "protocol";
static char __pyx_k__warnings[] = "warnings";
static char __pyx_k__Exception[] = "Exception";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k____adapt__[] = "__adapt__";
static char __pyx_k____bases__[] = "__bases__";
static char __pyx_k____class__[] = "__class__";
static char __pyx_k__exc_clear[] = "exc_clear";
static char __pyx_k__protocols[] = "protocols";
static char __pyx_k____import__[] = "__import__";
static char __pyx_k__classicMRO[] = "classicMRO";
static char __pyx_k__metamethod[] = "metamethod";
static char __pyx_k__ImportError[] = "ImportError";
static char __pyx_k____conform__[] = "__conform__";
static char __pyx_k__extClassMRO[] = "extClassMRO";
static char __pyx_k__AttributeError[] = "AttributeError";
static char __pyx_k__ExtensionClass[] = "ExtensionClass";
static char __pyx_k__extendedClassic[] = "extendedClassic";
static char __pyx_k__DOES_NOT_SUPPORT[] = "DOES_NOT_SUPPORT";
static char __pyx_k__Protocol__call__[] = "Protocol__call__";
static char __pyx_k__AdaptationFailure[] = "AdaptationFailure";
static char __pyx_k__NO_ADAPTER_NEEDED[] = "NO_ADAPTER_NEEDED";
static char __pyx_k__Protocol__adapt__[] = "Protocol__adapt__";
static char __pyx_k__DeprecationWarning[] = "DeprecationWarning";
static char __pyx_k___Protocol__adapters[] = "_Protocol__adapters";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_n_s_15;
static PyObject *__pyx_kp_s_4;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_n_s__AdaptationFailure;
static PyObject *__pyx_n_s__AttributeError;
static PyObject *__pyx_n_s__DOES_NOT_SUPPORT;
static PyObject *__pyx_n_s__DeprecationWarning;
static PyObject *__pyx_n_s__Exception;
static PyObject *__pyx_n_s__ExtensionClass;
static PyObject *__pyx_n_s__ImportError;
static PyObject *__pyx_n_s__NO_ADAPTER_NEEDED;
static PyObject *__pyx_n_s__Protocol__adapt__;
static PyObject *__pyx_n_s__Protocol__call__;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s___Protocol__adapters;
static PyObject *__pyx_n_s____all__;
static PyObject *__pyx_n_s____bases__;
static PyObject *__pyx_n_s____class;
static PyObject *__pyx_n_s____import__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____mro__;
static PyObject *__pyx_n_s____name__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s__adapt;
static PyObject *__pyx_n_s__cl_bases;
static PyObject *__pyx_n_s__classicMRO;
static PyObject *__pyx_n_s__default;
static PyObject *__pyx_n_s__exc_clear;
static PyObject *__pyx_n_s__exc_info;
static PyObject *__pyx_n_s__extClassMRO;
static PyObject *__pyx_n_s__extendedClassic;
static PyObject *__pyx_n_s__factory;
static PyObject *__pyx_n_s__fromlist;
static PyObject *__pyx_n_s__func;
static PyObject *__pyx_n_s__get;
static PyObject *__pyx_n_s__getMRO;
static PyObject *__pyx_n_s__globals;
static PyObject *__pyx_n_s__in_class;
static PyObject *__pyx_n_s__level;
static PyObject *__pyx_n_s__metamethod;
static PyObject *__pyx_n_s__ob;
static PyObject *__pyx_n_s__ob_type;
static PyObject *__pyx_n_s__obj;
static PyObject *__pyx_n_s__object;
static PyObject *__pyx_n_s__protocol;
static PyObject *__pyx_n_s__protocols;
static PyObject *__pyx_n_s__self;
static PyObject *__pyx_n_s__sys;
static PyObject *__pyx_n_s__tb_next;
static PyObject *__pyx_n_s__tp_mro;
static PyObject *__pyx_n_s__warn;
static PyObject *__pyx_n_s__warnings;
static PyObject *__pyx_int_1;
static PyObject *__pyx_k_6;
static PyObject *__pyx_k_7;
static PyObject *__pyx_k_8;
static PyObject *__pyx_k_9;
static PyObject *__pyx_k_11;
static PyObject *__pyx_k_12;
static PyObject *__pyx_k_tuple_2;
static PyObject *__pyx_k_tuple_3;
static PyObject *__pyx_k_tuple_14;

/* "traits/protocols/_speedups.pyx":92
 * # Fundamental Adapters
 * 
 * def NO_ADAPTER_NEEDED(obj, protocol=None):             # <<<<<<<<<<<<<<
 *     """Assume 'obj' implements 'protocol' directly"""
 *     return obj
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_NO_ADAPTER_NEEDED(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_9enthought_6traits_9protocols_9_speedups_NO_ADAPTER_NEEDED[] = "Assume 'obj' implements 'protocol' directly";
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_NO_ADAPTER_NEEDED = {__Pyx_NAMESTR("NO_ADAPTER_NEEDED"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_NO_ADAPTER_NEEDED, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9enthought_6traits_9protocols_9_speedups_NO_ADAPTER_NEEDED)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_NO_ADAPTER_NEEDED(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_obj = 0;
  PyObject *__pyx_v_protocol = 0;
  PyObject *__pyx_r = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__obj,&__pyx_n_s__protocol,0};
  __Pyx_RefNannySetupContext("NO_ADAPTER_NEEDED");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    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_n_s__obj);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__protocol);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "NO_ADAPTER_NEEDED") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_obj = values[0];
    __pyx_v_protocol = values[1];
  } else {
    __pyx_v_protocol = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_protocol = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("NO_ADAPTER_NEEDED", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.NO_ADAPTER_NEEDED");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "traits/protocols/_speedups.pyx":94
 * def NO_ADAPTER_NEEDED(obj, protocol=None):
 *     """Assume 'obj' implements 'protocol' directly"""
 *     return obj             # <<<<<<<<<<<<<<
 * 
 * def DOES_NOT_SUPPORT(obj, protocol=None):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_obj);
  __pyx_r = __pyx_v_obj;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":96
 *     return obj
 * 
 * def DOES_NOT_SUPPORT(obj, protocol=None):             # <<<<<<<<<<<<<<
 *     """Prevent 'obj' from supporting 'protocol'"""
 *     return None
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_1DOES_NOT_SUPPORT(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_9enthought_6traits_9protocols_9_speedups_1DOES_NOT_SUPPORT[] = "Prevent 'obj' from supporting 'protocol'";
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_1DOES_NOT_SUPPORT = {__Pyx_NAMESTR("DOES_NOT_SUPPORT"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_1DOES_NOT_SUPPORT, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9enthought_6traits_9protocols_9_speedups_1DOES_NOT_SUPPORT)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_1DOES_NOT_SUPPORT(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_obj = 0;
  PyObject *__pyx_v_protocol = 0;
  PyObject *__pyx_r = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__obj,&__pyx_n_s__protocol,0};
  __Pyx_RefNannySetupContext("DOES_NOT_SUPPORT");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    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_n_s__obj);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__protocol);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "DOES_NOT_SUPPORT") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_obj = values[0];
    __pyx_v_protocol = values[1];
  } else {
    __pyx_v_protocol = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_protocol = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("DOES_NOT_SUPPORT", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.DOES_NOT_SUPPORT");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "traits/protocols/_speedups.pyx":98
 * def DOES_NOT_SUPPORT(obj, protocol=None):
 *     """Prevent 'obj' from supporting 'protocol'"""
 *     return None             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":106
 *     cdef object func
 * 
 *     def __init__(self, func):             # <<<<<<<<<<<<<<
 *         self.func = func
 * 
 */

static int __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_func = 0;
  int __pyx_r;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__func,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      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_n_s__func);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_func = values[0];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_func = PyTuple_GET_ITEM(__pyx_args, 0);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.metamethod.__init__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "traits/protocols/_speedups.pyx":107
 * 
 *     def __init__(self, func):
 *         self.func = func             # <<<<<<<<<<<<<<
 * 
 *     def __get__(self, ob, typ):
 */
  __Pyx_INCREF(__pyx_v_func);
  __Pyx_GIVEREF(__pyx_v_func);
  __Pyx_GOTREF(((struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)__pyx_v_self)->func);
  __Pyx_DECREF(((struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)__pyx_v_self)->func);
  ((struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)__pyx_v_self)->func = __pyx_v_func;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":109
 *         self.func = func
 * 
 *     def __get__(self, ob, typ):             # <<<<<<<<<<<<<<
 *         if ob is None:
 *             return self
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_1__get__(PyObject *__pyx_v_self, PyObject *__pyx_v_ob, PyObject *__pyx_v_typ); /*proto*/
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_1__get__(PyObject *__pyx_v_self, PyObject *__pyx_v_ob, PyObject *__pyx_v_typ) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("__get__");

  /* "traits/protocols/_speedups.pyx":110
 * 
 *     def __get__(self, ob, typ):
 *         if ob is None:             # <<<<<<<<<<<<<<
 *             return self
 *         return PyMethod_New(self.func, ob, typ)
 */
  __pyx_t_1 = (__pyx_v_ob == Py_None);
  if (__pyx_t_1) {

    /* "traits/protocols/_speedups.pyx":111
 *     def __get__(self, ob, typ):
 *         if ob is None:
 *             return self             # <<<<<<<<<<<<<<
 *         return PyMethod_New(self.func, ob, typ)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self);
    __pyx_r = __pyx_v_self;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "traits/protocols/_speedups.pyx":112
 *         if ob is None:
 *             return self
 *         return PyMethod_New(self.func, ob, typ)             # <<<<<<<<<<<<<<
 * 
 *     def __set__(self, ob, value):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = ((struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)__pyx_v_self)->func;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = __pyx_v_ob;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __pyx_v_typ;
  __Pyx_INCREF(__pyx_t_4);
  __pyx_t_5 = PyMethod_New(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("traits.protocols._speedups.metamethod.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":114
 *         return PyMethod_New(self.func, ob, typ)
 * 
 *     def __set__(self, ob, value):             # <<<<<<<<<<<<<<
 *         raise AttributeError("Read-only attribute")
 * 
 */

static int __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_2__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_ob, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_2__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_ob, PyObject *__pyx_v_value) {
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__set__");

  /* "traits/protocols/_speedups.pyx":115
 * 
 *     def __set__(self, ob, value):
 *         raise AttributeError("Read-only attribute")             # <<<<<<<<<<<<<<
 * 
 *     def __delete__(self, ob):
 */
  __pyx_t_1 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("traits.protocols._speedups.metamethod.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":117
 *         raise AttributeError("Read-only attribute")
 * 
 *     def __delete__(self, ob):             # <<<<<<<<<<<<<<
 *         raise AttributeError("Read-only attribute")
 * 
 */

static int __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_3__delete__(PyObject *__pyx_v_self, PyObject *__pyx_v_ob); /*proto*/
static int __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_3__delete__(PyObject *__pyx_v_self, PyObject *__pyx_v_ob) {
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__delete__");

  /* "traits/protocols/_speedups.pyx":118
 * 
 *     def __delete__(self, ob):
 *         raise AttributeError("Read-only attribute")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("traits.protocols._speedups.metamethod.__delete__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":131
 * 
 * 
 * cdef object _adapt(obj, protocol, default, factory):             # <<<<<<<<<<<<<<
 * 
 *     # We use nested 'if' blocks here because using 'and' causes Pyrex to
 */

static  PyObject *__pyx_f_9enthought_6traits_9protocols_9_speedups__adapt(PyObject *__pyx_v_obj, PyObject *__pyx_v_protocol, PyObject *__pyx_v_default, PyObject *__pyx_v_factory) {
  PyObject *__pyx_v_meth;
  PyObject *__pyx_v_result;
  PyObject *__pyx_v_e;
  PyObject *__pyx_v_warn;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("_adapt");
  __pyx_v_meth = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_result = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_e = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_warn = Py_None; __Pyx_INCREF(Py_None);

  /* "traits/protocols/_speedups.pyx":149
 * ###                return obj
 * 
 *     if PyObject_IsInstance(obj,protocol):             # <<<<<<<<<<<<<<
 *         return obj
 * 
 */
  __pyx_t_1 = __pyx_v_obj;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_protocol;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_IsInstance(__pyx_t_1, __pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "traits/protocols/_speedups.pyx":150
 * 
 *     if PyObject_IsInstance(obj,protocol):
 *         return obj             # <<<<<<<<<<<<<<
 * 
 *     try:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_obj);
    __pyx_r = __pyx_v_obj;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "traits/protocols/_speedups.pyx":152
 *         return obj
 * 
 *     try:             # <<<<<<<<<<<<<<
 *         meth = getattr(obj, __conform)
 *         try:
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "traits/protocols/_speedups.pyx":153
 * 
 *     try:
 *         meth = getattr(obj, __conform)             # <<<<<<<<<<<<<<
 *         try:
 *             result = meth(protocol)
 */
      __pyx_t_2 = __pyx_v_obj;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_1 = __pyx_v_9enthought_6traits_9protocols_9_speedups___conform;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_v_meth);
      __pyx_v_meth = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "traits/protocols/_speedups.pyx":154
 *     try:
 *         meth = getattr(obj, __conform)
 *         try:             # <<<<<<<<<<<<<<
 *             result = meth(protocol)
 *             if result is not None:
 */
      {
        PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
        __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
        __Pyx_XGOTREF(__pyx_save_exc_type);
        __Pyx_XGOTREF(__pyx_save_exc_value);
        __Pyx_XGOTREF(__pyx_save_exc_tb);
        /*try:*/ {

          /* "traits/protocols/_speedups.pyx":155
 *         meth = getattr(obj, __conform)
 *         try:
 *             result = meth(protocol)             # <<<<<<<<<<<<<<
 *             if result is not None:
 *                 return result
 */
          __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L12_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_4));
          __Pyx_INCREF(__pyx_v_protocol);
          PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_protocol);
          __Pyx_GIVEREF(__pyx_v_protocol);
          __pyx_t_1 = PyObject_Call(__pyx_v_meth, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L12_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_v_result);
          __pyx_v_result = __pyx_t_1;
          __pyx_t_1 = 0;

          /* "traits/protocols/_speedups.pyx":156
 *         try:
 *             result = meth(protocol)
 *             if result is not None:             # <<<<<<<<<<<<<<
 *                 return result
 *         except TypeError, e:
 */
          __pyx_t_5 = (__pyx_v_result != Py_None);
          if (__pyx_t_5) {

            /* "traits/protocols/_speedups.pyx":157
 *             result = meth(protocol)
 *             if result is not None:
 *                 return result             # <<<<<<<<<<<<<<
 *         except TypeError, e:
 *             if exc_info()[2].tb_next is not None:
 */
            __Pyx_XDECREF(__pyx_r);
            __Pyx_INCREF(__pyx_v_result);
            __pyx_r = __pyx_v_result;
            goto __pyx_L16_try_return;
            goto __pyx_L20;
          }
          __pyx_L20:;
        }
        __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
        __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
        __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
        goto __pyx_L19_try_end;
        __pyx_L16_try_return:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L8_try_return;
        __pyx_L12_error:;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "traits/protocols/_speedups.pyx":158
 *             if result is not None:
 *                 return result
 *         except TypeError, e:             # <<<<<<<<<<<<<<
 *             if exc_info()[2].tb_next is not None:
 *                 raise
 */
        __pyx_t_3 = PyErr_ExceptionMatches(__pyx_builtin_TypeError);
        if (__pyx_t_3) {
          __Pyx_AddTraceback("traits.protocols._speedups._adapt");
          if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L14_except_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_v_e);
          __pyx_v_e = __pyx_t_4;

          /* "traits/protocols/_speedups.pyx":159
 *                 return result
 *         except TypeError, e:
 *             if exc_info()[2].tb_next is not None:             # <<<<<<<<<<<<<<
 *                 raise
 *     except AttributeError, e:
 */
          __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__exc_info); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L14_except_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L14_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_7, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L14_except_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__tb_next); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L14_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_5 = (__pyx_t_7 != Py_None);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (__pyx_t_5) {

            /* "traits/protocols/_speedups.pyx":160
 *         except TypeError, e:
 *             if exc_info()[2].tb_next is not None:
 *                 raise             # <<<<<<<<<<<<<<
 *     except AttributeError, e:
 *         # Call exc_clear() instead of PyErr_Clear to make sure that the
 */
            __Pyx_GIVEREF(__pyx_t_1);
            __Pyx_GIVEREF(__pyx_t_4);
            __Pyx_GIVEREF(__pyx_t_2);
            __Pyx_ErrRestore(__pyx_t_1, __pyx_t_4, __pyx_t_2);
            __pyx_t_1 = 0; __pyx_t_4 = 0; __pyx_t_2 = 0; 
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L14_except_error;}
            goto __pyx_L23;
          }
          __pyx_L23:;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          goto __pyx_L13_exception_handled;
        }
        __pyx_L14_except_error:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L4_error;
        __pyx_L13_exception_handled:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        __pyx_L19_try_end:;
      }
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L11_try_end;
    __pyx_L8_try_return:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L0;
    __pyx_L4_error:;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "traits/protocols/_speedups.pyx":161
 *             if exc_info()[2].tb_next is not None:
 *                 raise
 *     except AttributeError, e:             # <<<<<<<<<<<<<<
 *         # Call exc_clear() instead of PyErr_Clear to make sure that the
 *         # sys.exc_* objects are also removed. This has caused some frames to
 */
    __pyx_t_3 = PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_3) {
      __Pyx_AddTraceback("traits.protocols._speedups._adapt");
      if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_v_e);
      __pyx_v_e = __pyx_t_4;

      /* "traits/protocols/_speedups.pyx":165
 *         # sys.exc_* objects are also removed. This has caused some frames to
 *         # live too long.
 *         exc_clear()             # <<<<<<<<<<<<<<
 * 
 *     try:
 */
      __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__exc_clear); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L5_exception_handled;
    }
    __pyx_L6_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L5_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L11_try_end:;
  }

  /* "traits/protocols/_speedups.pyx":167
 *         exc_clear()
 * 
 *     try:             # <<<<<<<<<<<<<<
 *         meth = getattr(protocol, __adapt)
 *         try:
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "traits/protocols/_speedups.pyx":168
 * 
 *     try:
 *         meth = getattr(protocol, __adapt)             # <<<<<<<<<<<<<<
 *         try:
 *             result = meth(obj)
 */
      __pyx_t_1 = __pyx_v_protocol;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = __pyx_v_9enthought_6traits_9protocols_9_speedups___adapt;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L26_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_v_meth);
      __pyx_v_meth = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "traits/protocols/_speedups.pyx":169
 *     try:
 *         meth = getattr(protocol, __adapt)
 *         try:             # <<<<<<<<<<<<<<
 *             result = meth(obj)
 *             if result is not None:
 */
      {
        PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
        __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
        __Pyx_XGOTREF(__pyx_save_exc_type);
        __Pyx_XGOTREF(__pyx_save_exc_value);
        __Pyx_XGOTREF(__pyx_save_exc_tb);
        /*try:*/ {

          /* "traits/protocols/_speedups.pyx":170
 *         meth = getattr(protocol, __adapt)
 *         try:
 *             result = meth(obj)             # <<<<<<<<<<<<<<
 *             if result is not None:
 *                 return result
 */
          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L34_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_2));
          __Pyx_INCREF(__pyx_v_obj);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_obj);
          __Pyx_GIVEREF(__pyx_v_obj);
          __pyx_t_4 = PyObject_Call(__pyx_v_meth, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L34_error;}
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_v_result);
          __pyx_v_result = __pyx_t_4;
          __pyx_t_4 = 0;

          /* "traits/protocols/_speedups.pyx":171
 *         try:
 *             result = meth(obj)
 *             if result is not None:             # <<<<<<<<<<<<<<
 *                 return result
 *         except TypeError:
 */
          __pyx_t_5 = (__pyx_v_result != Py_None);
          if (__pyx_t_5) {

            /* "traits/protocols/_speedups.pyx":172
 *             result = meth(obj)
 *             if result is not None:
 *                 return result             # <<<<<<<<<<<<<<
 *         except TypeError:
 *             if exc_info()[2].tb_next is not None:
 */
            __Pyx_XDECREF(__pyx_r);
            __Pyx_INCREF(__pyx_v_result);
            __pyx_r = __pyx_v_result;
            goto __pyx_L38_try_return;
            goto __pyx_L42;
          }
          __pyx_L42:;
        }
        __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
        __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
        __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
        goto __pyx_L41_try_end;
        __pyx_L38_try_return:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L30_try_return;
        __pyx_L34_error:;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "traits/protocols/_speedups.pyx":173
 *             if result is not None:
 *                 return result
 *         except TypeError:             # <<<<<<<<<<<<<<
 *             if exc_info()[2].tb_next is not None:
 *                 raise
 */
        __pyx_t_3 = PyErr_ExceptionMatches(__pyx_builtin_TypeError);
        if (__pyx_t_3) {
          __Pyx_AddTraceback("traits.protocols._speedups._adapt");
          if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L36_except_error;}
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_t_1);

          /* "traits/protocols/_speedups.pyx":174
 *                 return result
 *         except TypeError:
 *             if exc_info()[2].tb_next is not None:             # <<<<<<<<<<<<<<
 *                 raise
 *     except AttributeError, e:
 */
          __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__exc_info); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L36_except_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L36_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_7, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L36_except_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__tb_next); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L36_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_5 = (__pyx_t_7 != Py_None);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (__pyx_t_5) {

            /* "traits/protocols/_speedups.pyx":175
 *         except TypeError:
 *             if exc_info()[2].tb_next is not None:
 *                 raise             # <<<<<<<<<<<<<<
 *     except AttributeError, e:
 *         exc_clear()
 */
            __Pyx_GIVEREF(__pyx_t_4);
            __Pyx_GIVEREF(__pyx_t_2);
            __Pyx_GIVEREF(__pyx_t_1);
            __Pyx_ErrRestore(__pyx_t_4, __pyx_t_2, __pyx_t_1);
            __pyx_t_4 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; 
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L36_except_error;}
            goto __pyx_L45;
          }
          __pyx_L45:;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          goto __pyx_L35_exception_handled;
        }
        __pyx_L36_except_error:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L26_error;
        __pyx_L35_exception_handled:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        __pyx_L41_try_end:;
      }
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L33_try_end;
    __pyx_L30_try_return:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L0;
    __pyx_L26_error:;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "traits/protocols/_speedups.pyx":176
 *             if exc_info()[2].tb_next is not None:
 *                 raise
 *     except AttributeError, e:             # <<<<<<<<<<<<<<
 *         exc_clear()
 * 
 */
    __pyx_t_3 = PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_3) {
      __Pyx_AddTraceback("traits.protocols._speedups._adapt");
      if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L28_except_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_e);
      __pyx_v_e = __pyx_t_2;

      /* "traits/protocols/_speedups.pyx":177
 *                 raise
 *     except AttributeError, e:
 *         exc_clear()             # <<<<<<<<<<<<<<
 * 
 *     if default is _marker:
 */
      __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__exc_clear); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L28_except_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L28_except_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L27_exception_handled;
    }
    __pyx_L28_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L27_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L33_try_end:;
  }

  /* "traits/protocols/_speedups.pyx":179
 *         exc_clear()
 * 
 *     if default is _marker:             # <<<<<<<<<<<<<<
 *         if factory is not _marker:
 *             from warnings import warn
 */
  __pyx_t_5 = (__pyx_v_default == __pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  if (__pyx_t_5) {

    /* "traits/protocols/_speedups.pyx":180
 * 
 *     if default is _marker:
 *         if factory is not _marker:             # <<<<<<<<<<<<<<
 *             from warnings import warn
 *             warn("The 'factory' argument to 'adapt()' will be removed in 1.0",
 */
    __pyx_t_5 = (__pyx_v_factory != __pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
    if (__pyx_t_5) {

      /* "traits/protocols/_speedups.pyx":181
 *     if default is _marker:
 *         if factory is not _marker:
 *             from warnings import warn             # <<<<<<<<<<<<<<
 *             warn("The 'factory' argument to 'adapt()' will be removed in 1.0",
 *                 DeprecationWarning, 1)
 */
      __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __Pyx_INCREF(((PyObject *)__pyx_n_s__warn));
      PyList_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_n_s__warn));
      __Pyx_GIVEREF(((PyObject *)__pyx_n_s__warn));
      __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__warnings), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__warn); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_v_warn);
      __pyx_v_warn = __pyx_t_4;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "traits/protocols/_speedups.pyx":183
 *             from warnings import warn
 *             warn("The 'factory' argument to 'adapt()' will be removed in 1.0",
 *                 DeprecationWarning, 1)             # <<<<<<<<<<<<<<
 *             return factory(obj, protocol)
 *         raise AdaptationFailure("Can't adapt", obj, protocol)
 */
      __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_4));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_4));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4));
      __Pyx_INCREF(__pyx_builtin_DeprecationWarning);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_builtin_DeprecationWarning);
      __Pyx_GIVEREF(__pyx_builtin_DeprecationWarning);
      __Pyx_INCREF(__pyx_int_1);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_1);
      __Pyx_GIVEREF(__pyx_int_1);
      __pyx_t_4 = PyObject_Call(__pyx_v_warn, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "traits/protocols/_speedups.pyx":184
 *             warn("The 'factory' argument to 'adapt()' will be removed in 1.0",
 *                 DeprecationWarning, 1)
 *             return factory(obj, protocol)             # <<<<<<<<<<<<<<
 *         raise AdaptationFailure("Can't adapt", obj, protocol)
 * 
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      __Pyx_INCREF(__pyx_v_obj);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_obj);
      __Pyx_GIVEREF(__pyx_v_obj);
      __Pyx_INCREF(__pyx_v_protocol);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_protocol);
      __Pyx_GIVEREF(__pyx_v_protocol);
      __pyx_t_2 = PyObject_Call(__pyx_v_factory, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;
      goto __pyx_L49;
    }
    __pyx_L49:;

    /* "traits/protocols/_speedups.pyx":185
 *                 DeprecationWarning, 1)
 *             return factory(obj, protocol)
 *         raise AdaptationFailure("Can't adapt", obj, protocol)             # <<<<<<<<<<<<<<
 * 
 *     return default
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__AdaptationFailure); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_5));
    __Pyx_INCREF(__pyx_v_obj);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_obj);
    __Pyx_GIVEREF(__pyx_v_obj);
    __Pyx_INCREF(__pyx_v_protocol);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_protocol);
    __Pyx_GIVEREF(__pyx_v_protocol);
    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L48;
  }
  __pyx_L48:;

  /* "traits/protocols/_speedups.pyx":187
 *         raise AdaptationFailure("Can't adapt", obj, protocol)
 * 
 *     return default             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_default);
  __pyx_r = __pyx_v_default;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("traits.protocols._speedups._adapt");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_meth);
  __Pyx_DECREF(__pyx_v_result);
  __Pyx_DECREF(__pyx_v_e);
  __Pyx_DECREF(__pyx_v_warn);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":190
 * 
 * 
 * def adapt(obj, protocol, default=_marker, factory=_marker):             # <<<<<<<<<<<<<<
 *     """PEP 246-alike: Adapt 'obj' to 'protocol', return 'default'
 * 
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_2adapt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_9enthought_6traits_9protocols_9_speedups_2adapt[] = "PEP 246-alike: Adapt 'obj' to 'protocol', return 'default'\n\n    If 'default' is not supplied and no implementation is found,\n    raise 'AdaptationFailure'.";
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_2adapt = {__Pyx_NAMESTR("adapt"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_2adapt, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9enthought_6traits_9protocols_9_speedups_2adapt)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_2adapt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_obj = 0;
  PyObject *__pyx_v_protocol = 0;
  PyObject *__pyx_v_default = 0;
  PyObject *__pyx_v_factory = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__obj,&__pyx_n_s__protocol,&__pyx_n_s__default,&__pyx_n_s__factory,0};
  __Pyx_RefNannySetupContext("adapt");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[4] = {0,0,0,0};
    values[2] = __pyx_k_6;
    values[3] = __pyx_k_7;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      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_n_s__obj);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__protocol);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("adapt", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__default);
        if (value) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__factory);
        if (value) { values[3] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "adapt") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_obj = values[0];
    __pyx_v_protocol = values[1];
    __pyx_v_default = values[2];
    __pyx_v_factory = values[3];
  } else {
    __pyx_v_default = __pyx_k_6;
    __pyx_v_factory = __pyx_k_7;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4:
      __pyx_v_factory = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3:
      __pyx_v_default = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_protocol = PyTuple_GET_ITEM(__pyx_args, 1);
      __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("adapt", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.adapt");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "traits/protocols/_speedups.pyx":196
 *     raise 'AdaptationFailure'."""
 * 
 *     return _adapt(obj,protocol,default,factory)             # <<<<<<<<<<<<<<
 * 
 * def Protocol__call__(self, ob, default=_marker):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_v_obj;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_protocol;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = __pyx_v_default;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __pyx_v_factory;
  __Pyx_INCREF(__pyx_t_4);
  __pyx_t_5 = __pyx_f_9enthought_6traits_9protocols_9_speedups__adapt(__pyx_t_1, __pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("traits.protocols._speedups.adapt");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":198
 *     return _adapt(obj,protocol,default,factory)
 * 
 * def Protocol__call__(self, ob, default=_marker):             # <<<<<<<<<<<<<<
 *     """Adapt to this protocol"""
 *     return _adapt(ob,self,default,_marker)
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_3Protocol__call__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_9enthought_6traits_9protocols_9_speedups_3Protocol__call__[] = "Adapt to this protocol";
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_3Protocol__call__ = {__Pyx_NAMESTR("Protocol__call__"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_3Protocol__call__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9enthought_6traits_9protocols_9_speedups_3Protocol__call__)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_3Protocol__call__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_ob = 0;
  PyObject *__pyx_v_default = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__ob,&__pyx_n_s__default,0};
  __Pyx_RefNannySetupContext("Protocol__call__");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[2] = __pyx_k_8;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      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_n_s__self);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ob);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("Protocol__call__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__default);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "Protocol__call__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_self = values[0];
    __pyx_v_ob = values[1];
    __pyx_v_default = values[2];
  } else {
    __pyx_v_default = __pyx_k_8;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3:
      __pyx_v_default = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_ob = PyTuple_GET_ITEM(__pyx_args, 1);
      __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("Protocol__call__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.Protocol__call__");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "traits/protocols/_speedups.pyx":200
 * def Protocol__call__(self, ob, default=_marker):
 *     """Adapt to this protocol"""
 *     return _adapt(ob,self,default,_marker)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_v_ob;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_self;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = __pyx_v_default;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __pyx_v_9enthought_6traits_9protocols_9_speedups__marker;
  __Pyx_INCREF(__pyx_t_4);
  __pyx_t_5 = __pyx_f_9enthought_6traits_9protocols_9_speedups__adapt(__pyx_t_1, __pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("traits.protocols._speedups.Protocol__call__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":203
 * 
 * 
 * cdef buildClassicMRO(PyClassObject *cls, PyListObject *list):             # <<<<<<<<<<<<<<
 * 
 *     cdef PyTupleObject *bases
 */

static  PyObject *__pyx_f_9enthought_6traits_9protocols_9_speedups_buildClassicMRO(PyClassObject *__pyx_v_cls, PyListObject *__pyx_v_list) {
  PyTupleObject *__pyx_v_bases;
  int __pyx_v_i;
  PyObject *__pyx_v_tmp;
  PyObject *__pyx_r = NULL;
  PyListObject *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  void *__pyx_t_5;
  __Pyx_RefNannySetupContext("buildClassicMRO");
  __pyx_v_tmp = Py_None; __Pyx_INCREF(Py_None);

  /* "traits/protocols/_speedups.pyx":208
 *     cdef int i
 * 
 *     PyList_Append(list, <object> cls)             # <<<<<<<<<<<<<<
 *     bases = cls.cl_bases
 * 
 */
  __pyx_t_1 = __pyx_v_list;
  __pyx_t_2 = ((PyObject *)__pyx_v_cls);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyList_Append(__pyx_t_1, __pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "traits/protocols/_speedups.pyx":209
 * 
 *     PyList_Append(list, <object> cls)
 *     bases = cls.cl_bases             # <<<<<<<<<<<<<<
 * 
 *     if bases:
 */
  __pyx_v_bases = __pyx_v_cls->cl_bases;

  /* "traits/protocols/_speedups.pyx":211
 *     bases = cls.cl_bases
 * 
 *     if bases:             # <<<<<<<<<<<<<<
 *         for i from 0 <= i < PyTuple_GET_SIZE(bases):
 *             tmp = <object> PyTuple_GET_ITEM(bases, i)
 */
  __pyx_t_4 = (__pyx_v_bases != 0);
  if (__pyx_t_4) {

    /* "traits/protocols/_speedups.pyx":212
 * 
 *     if bases:
 *         for i from 0 <= i < PyTuple_GET_SIZE(bases):             # <<<<<<<<<<<<<<
 *             tmp = <object> PyTuple_GET_ITEM(bases, i)
 *             buildClassicMRO(<PyClassObject *>tmp, list)
 */
    __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v_bases);
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) {

      /* "traits/protocols/_speedups.pyx":213
 *     if bases:
 *         for i from 0 <= i < PyTuple_GET_SIZE(bases):
 *             tmp = <object> PyTuple_GET_ITEM(bases, i)             # <<<<<<<<<<<<<<
 *             buildClassicMRO(<PyClassObject *>tmp, list)
 * 
 */
      __pyx_t_5 = PyTuple_GET_ITEM(__pyx_v_bases, __pyx_v_i);
      __Pyx_INCREF(((PyObject *)__pyx_t_5));
      __Pyx_DECREF(__pyx_v_tmp);
      __pyx_v_tmp = ((PyObject *)__pyx_t_5);

      /* "traits/protocols/_speedups.pyx":214
 *         for i from 0 <= i < PyTuple_GET_SIZE(bases):
 *             tmp = <object> PyTuple_GET_ITEM(bases, i)
 *             buildClassicMRO(<PyClassObject *>tmp, list)             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_2 = __pyx_f_9enthought_6traits_9protocols_9_speedups_buildClassicMRO(((PyClassObject *)__pyx_v_tmp), __pyx_v_list); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    goto __pyx_L3;
  }
  __pyx_L3:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("traits.protocols._speedups.buildClassicMRO");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_tmp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":217
 * 
 * 
 * def classicMRO(ob, extendedClassic=False):             # <<<<<<<<<<<<<<
 * 
 *     if PyClass_Check(ob):
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_4classicMRO(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_4classicMRO = {__Pyx_NAMESTR("classicMRO"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_4classicMRO, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_4classicMRO(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_ob = 0;
  PyObject *__pyx_v_extendedClassic = 0;
  PyObject *__pyx_v_mro;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyListObject *__pyx_t_4;
  PyTypeObject *__pyx_t_5;
  PyListObject *__pyx_t_6;
  PyTypeObject *__pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ob,&__pyx_n_s__extendedClassic,0};
  __Pyx_RefNannySetupContext("classicMRO");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_k_9;
    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_n_s__ob);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__extendedClassic);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "classicMRO") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_ob = values[0];
    __pyx_v_extendedClassic = values[1];
  } else {
    __pyx_v_extendedClassic = __pyx_k_9;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_extendedClassic = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_ob = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("classicMRO", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.classicMRO");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_mro = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "traits/protocols/_speedups.pyx":219
 * def classicMRO(ob, extendedClassic=False):
 * 
 *     if PyClass_Check(ob):             # <<<<<<<<<<<<<<
 *         mro = []
 *         buildClassicMRO(<PyClassObject *>ob, <PyListObject *>mro)
 */
  __pyx_t_1 = __pyx_v_ob;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyClass_Check(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":220
 * 
 *     if PyClass_Check(ob):
 *         mro = []             # <<<<<<<<<<<<<<
 *         buildClassicMRO(<PyClassObject *>ob, <PyListObject *>mro)
 *         if extendedClassic:
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_DECREF(((PyObject *)__pyx_v_mro));
    __pyx_v_mro = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "traits/protocols/_speedups.pyx":221
 *     if PyClass_Check(ob):
 *         mro = []
 *         buildClassicMRO(<PyClassObject *>ob, <PyListObject *>mro)             # <<<<<<<<<<<<<<
 *         if extendedClassic:
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 */
    __pyx_t_1 = __pyx_f_9enthought_6traits_9protocols_9_speedups_buildClassicMRO(((PyClassObject *)__pyx_v_ob), ((PyListObject *)__pyx_v_mro)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "traits/protocols/_speedups.pyx":222
 *         mro = []
 *         buildClassicMRO(<PyClassObject *>ob, <PyListObject *>mro)
 *         if extendedClassic:             # <<<<<<<<<<<<<<
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *             PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_extendedClassic); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_3) {

      /* "traits/protocols/_speedups.pyx":223
 *         buildClassicMRO(<PyClassObject *>ob, <PyListObject *>mro)
 *         if extendedClassic:
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)             # <<<<<<<<<<<<<<
 *             PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 *         return mro
 */
      __pyx_t_4 = ((PyListObject *)__pyx_v_mro);
      __pyx_t_5 = (&PyInstance_Type);
      __pyx_t_1 = ((PyObject *)__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = PyList_Append(__pyx_t_4, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "traits/protocols/_speedups.pyx":224
 *         if extendedClassic:
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *             PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)             # <<<<<<<<<<<<<<
 *         return mro
 * 
 */
      __pyx_t_6 = ((PyListObject *)__pyx_v_mro);
      __pyx_t_7 = (&PyBaseObject_Type);
      __pyx_t_1 = ((PyObject *)__pyx_t_7);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = PyList_Append(__pyx_t_6, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "traits/protocols/_speedups.pyx":225
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *             PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 *         return mro             # <<<<<<<<<<<<<<
 * 
 *     raise TypeError("Not a classic class", ob)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_mro));
    __pyx_r = ((PyObject *)__pyx_v_mro);
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "traits/protocols/_speedups.pyx":227
 *         return mro
 * 
 *     raise TypeError("Not a classic class", ob)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_10));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
  __Pyx_INCREF(__pyx_v_ob);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_ob);
  __Pyx_GIVEREF(__pyx_v_ob);
  __pyx_t_8 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_Raise(__pyx_t_8, 0, 0);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("traits.protocols._speedups.classicMRO");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_mro);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":244
 * 
 * 
 * cdef buildECMRO(object cls, PyListObject *list):             # <<<<<<<<<<<<<<
 *     PyList_Append(list, cls)
 *     for i in cls.__bases__:
 */

static  PyObject *__pyx_f_9enthought_6traits_9protocols_9_speedups_buildECMRO(PyObject *__pyx_v_cls, PyListObject *__pyx_v_list) {
  PyObject *__pyx_v_i;
  PyObject *__pyx_r = NULL;
  PyListObject *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("buildECMRO");
  __pyx_v_i = Py_None; __Pyx_INCREF(Py_None);

  /* "traits/protocols/_speedups.pyx":245
 * 
 * cdef buildECMRO(object cls, PyListObject *list):
 *     PyList_Append(list, cls)             # <<<<<<<<<<<<<<
 *     for i in cls.__bases__:
 *         buildECMRO(i, list)
 */
  __pyx_t_1 = __pyx_v_list;
  __pyx_t_2 = __pyx_v_cls;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyList_Append(__pyx_t_1, __pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "traits/protocols/_speedups.pyx":246
 * cdef buildECMRO(object cls, PyListObject *list):
 *     PyList_Append(list, cls)
 *     for i in cls.__bases__:             # <<<<<<<<<<<<<<
 *         buildECMRO(i, list)
 * 
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_cls, __pyx_n_s____bases__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_4 = 0; __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5);
  } else {
    __pyx_t_4 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_5))) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
      if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
      __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++;
    } else {
      __pyx_t_2 = PyIter_Next(__pyx_t_5);
      if (!__pyx_t_2) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "traits/protocols/_speedups.pyx":247
 *     PyList_Append(list, cls)
 *     for i in cls.__bases__:
 *         buildECMRO(i, list)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_2 = __pyx_f_9enthought_6traits_9protocols_9_speedups_buildECMRO(__pyx_v_i, __pyx_v_list); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("traits.protocols._speedups.buildECMRO");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":250
 * 
 * 
 * def extClassMRO(ob, extendedClassic=False):             # <<<<<<<<<<<<<<
 *     mro = []
 *     buildECMRO(ob, <PyListObject *>mro)
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_5extClassMRO(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_5extClassMRO = {__Pyx_NAMESTR("extClassMRO"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_5extClassMRO, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_5extClassMRO(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_ob = 0;
  PyObject *__pyx_v_extendedClassic = 0;
  PyObject *__pyx_v_mro;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyListObject *__pyx_t_4;
  PyTypeObject *__pyx_t_5;
  int __pyx_t_6;
  PyListObject *__pyx_t_7;
  PyTypeObject *__pyx_t_8;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ob,&__pyx_n_s__extendedClassic,0};
  __Pyx_RefNannySetupContext("extClassMRO");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_k_11;
    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_n_s__ob);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__extendedClassic);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "extClassMRO") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_ob = values[0];
    __pyx_v_extendedClassic = values[1];
  } else {
    __pyx_v_extendedClassic = __pyx_k_11;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_extendedClassic = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_ob = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("extClassMRO", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.extClassMRO");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_mro = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "traits/protocols/_speedups.pyx":251
 * 
 * def extClassMRO(ob, extendedClassic=False):
 *     mro = []             # <<<<<<<<<<<<<<
 *     buildECMRO(ob, <PyListObject *>mro)
 *     if extendedClassic:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_mro));
  __pyx_v_mro = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "traits/protocols/_speedups.pyx":252
 * def extClassMRO(ob, extendedClassic=False):
 *     mro = []
 *     buildECMRO(ob, <PyListObject *>mro)             # <<<<<<<<<<<<<<
 *     if extendedClassic:
 *         PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 */
  __pyx_t_1 = __pyx_v_ob;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_f_9enthought_6traits_9protocols_9_speedups_buildECMRO(__pyx_t_1, ((PyListObject *)__pyx_v_mro)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "traits/protocols/_speedups.pyx":253
 *     mro = []
 *     buildECMRO(ob, <PyListObject *>mro)
 *     if extendedClassic:             # <<<<<<<<<<<<<<
 *         PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *         PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_extendedClassic); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "traits/protocols/_speedups.pyx":254
 *     buildECMRO(ob, <PyListObject *>mro)
 *     if extendedClassic:
 *         PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)             # <<<<<<<<<<<<<<
 *         PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 *     return mro
 */
    __pyx_t_4 = ((PyListObject *)__pyx_v_mro);
    __pyx_t_5 = (&PyInstance_Type);
    __pyx_t_2 = ((PyObject *)__pyx_t_5);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_6 = PyList_Append(__pyx_t_4, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "traits/protocols/_speedups.pyx":255
 *     if extendedClassic:
 *         PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *         PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)             # <<<<<<<<<<<<<<
 *     return mro
 * 
 */
    __pyx_t_7 = ((PyListObject *)__pyx_v_mro);
    __pyx_t_8 = (&PyBaseObject_Type);
    __pyx_t_2 = ((PyObject *)__pyx_t_8);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_6 = PyList_Append(__pyx_t_7, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "traits/protocols/_speedups.pyx":256
 *         PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *         PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 *     return mro             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_mro));
  __pyx_r = ((PyObject *)__pyx_v_mro);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("traits.protocols._speedups.extClassMRO");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_mro);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":260
 * 
 * 
 * def getMRO(ob, extendedClassic=False):             # <<<<<<<<<<<<<<
 * 
 *     if PyClass_Check(ob):
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_6getMRO(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_6getMRO = {__Pyx_NAMESTR("getMRO"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_6getMRO, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_6getMRO(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_ob = 0;
  PyObject *__pyx_v_extendedClassic = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ob,&__pyx_n_s__extendedClassic,0};
  __Pyx_RefNannySetupContext("getMRO");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = __pyx_k_12;
    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_n_s__ob);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__extendedClassic);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "getMRO") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_ob = values[0];
    __pyx_v_extendedClassic = values[1];
  } else {
    __pyx_v_extendedClassic = __pyx_k_12;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_extendedClassic = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_ob = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getMRO", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.getMRO");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "traits/protocols/_speedups.pyx":262
 * def getMRO(ob, extendedClassic=False):
 * 
 *     if PyClass_Check(ob):             # <<<<<<<<<<<<<<
 *         return classicMRO(ob,extendedClassic)
 * 
 */
  __pyx_t_1 = __pyx_v_ob;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyClass_Check(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":263
 * 
 *     if PyClass_Check(ob):
 *         return classicMRO(ob,extendedClassic)             # <<<<<<<<<<<<<<
 * 
 *     elif PyType_Check(ob):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__classicMRO); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_ob);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_ob);
    __Pyx_GIVEREF(__pyx_v_ob);
    __Pyx_INCREF(__pyx_v_extendedClassic);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_extendedClassic);
    __Pyx_GIVEREF(__pyx_v_extendedClassic);
    __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }

  /* "traits/protocols/_speedups.pyx":265
 *         return classicMRO(ob,extendedClassic)
 * 
 *     elif PyType_Check(ob):             # <<<<<<<<<<<<<<
 *         return ob.__mro__
 * 
 */
  __pyx_t_4 = __pyx_v_ob;
  __Pyx_INCREF(__pyx_t_4);
  __pyx_t_2 = PyType_Check(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":266
 * 
 *     elif PyType_Check(ob):
 *         return ob.__mro__             # <<<<<<<<<<<<<<
 * 
 *     elif PyObject_TypeCheck(ob,__ECType):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_ob, __pyx_n_s____mro__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }

  /* "traits/protocols/_speedups.pyx":268
 *         return ob.__mro__
 * 
 *     elif PyObject_TypeCheck(ob,__ECType):             # <<<<<<<<<<<<<<
 *         return extClassMRO(ob, extendedClassic)
 * 
 */
  __pyx_t_4 = __pyx_v_ob;
  __Pyx_INCREF(__pyx_t_4);
  __pyx_t_3 = __pyx_v_9enthought_6traits_9protocols_9_speedups___ECType;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_2 = PyObject_TypeCheck(__pyx_t_4, __pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":269
 * 
 *     elif PyObject_TypeCheck(ob,__ECType):
 *         return extClassMRO(ob, extendedClassic)             # <<<<<<<<<<<<<<
 * 
 *     return ob,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__extClassMRO); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_v_ob);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_ob);
    __Pyx_GIVEREF(__pyx_v_ob);
    __Pyx_INCREF(__pyx_v_extendedClassic);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_extendedClassic);
    __Pyx_GIVEREF(__pyx_v_extendedClassic);
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "traits/protocols/_speedups.pyx":271
 *         return extClassMRO(ob, extendedClassic)
 * 
 *     return ob,             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_ob);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_ob);
  __Pyx_GIVEREF(__pyx_v_ob);
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("traits.protocols._speedups.getMRO");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "traits/protocols/_speedups.pyx":285
 * 
 * 
 * def Protocol__adapt__(self, obj):             # <<<<<<<<<<<<<<
 * 
 *     cdef void *tmp
 */

static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_7Protocol__adapt__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_9enthought_6traits_9protocols_9_speedups_7Protocol__adapt__ = {__Pyx_NAMESTR("Protocol__adapt__"), (PyCFunction)__pyx_pf_9enthought_6traits_9protocols_9_speedups_7Protocol__adapt__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pf_9enthought_6traits_9protocols_9_speedups_7Protocol__adapt__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_obj = 0;
  void *__pyx_v_tmp;
  int __pyx_v_i;
  PyObject *__pyx_v_cls;
  PyObject *__pyx_v_mro;
  PyObject *__pyx_v_get;
  PyObject *__pyx_v_factory;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyListObject *__pyx_t_6;
  PyTypeObject *__pyx_t_7;
  PyListObject *__pyx_t_8;
  PyTypeObject *__pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  void *__pyx_t_13;
  void *__pyx_t_14;
  Py_ssize_t __pyx_t_15;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__obj,0};
  __Pyx_RefNannySetupContext("Protocol__adapt__");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    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_n_s__self);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__obj);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("Protocol__adapt__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __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), "Protocol__adapt__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_self = values[0];
    __pyx_v_obj = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("Protocol__adapt__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("traits.protocols._speedups.Protocol__adapt__");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_cls = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_mro = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_get = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_factory = Py_None; __Pyx_INCREF(Py_None);

  /* "traits/protocols/_speedups.pyx":290
 *     cdef int i
 * 
 *     if PyInstance_Check(obj):             # <<<<<<<<<<<<<<
 *         cls = <object> ((<PyInstanceObject *>obj).in_class)
 *     else:
 */
  __pyx_t_1 = __pyx_v_obj;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyInstance_Check(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":291
 * 
 *     if PyInstance_Check(obj):
 *         cls = <object> ((<PyInstanceObject *>obj).in_class)             # <<<<<<<<<<<<<<
 *     else:
 *         # We use __class__ instead of type to support proxies
 */
    __Pyx_INCREF(((PyObject *)((PyInstanceObject *)__pyx_v_obj)->in_class));
    __Pyx_DECREF(__pyx_v_cls);
    __pyx_v_cls = ((PyObject *)((PyInstanceObject *)__pyx_v_obj)->in_class);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "traits/protocols/_speedups.pyx":294
 *     else:
 *         # We use __class__ instead of type to support proxies
 *         try:             # <<<<<<<<<<<<<<
 *             cls = getattr(obj, __class)
 *         except AttributeError:
 */
    {
      PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
      __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
      __Pyx_XGOTREF(__pyx_save_exc_type);
      __Pyx_XGOTREF(__pyx_save_exc_value);
      __Pyx_XGOTREF(__pyx_save_exc_tb);
      /*try:*/ {

        /* "traits/protocols/_speedups.pyx":295
 *         # We use __class__ instead of type to support proxies
 *         try:
 *             cls = getattr(obj, __class)             # <<<<<<<<<<<<<<
 *         except AttributeError:
 *             # Some object have no __class__; use their type
 */
        __pyx_t_1 = __pyx_v_obj;
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s____class); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_v_cls);
        __pyx_v_cls = __pyx_t_4;
        __pyx_t_4 = 0;
      }
      __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
      __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
      __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
      goto __pyx_L14_try_end;
      __pyx_L7_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "traits/protocols/_speedups.pyx":296
 *         try:
 *             cls = getattr(obj, __class)
 *         except AttributeError:             # <<<<<<<<<<<<<<
 *             # Some object have no __class__; use their type
 *             cls = <object> (<PyObject *>obj).ob_type
 */
      __pyx_t_2 = PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
      if (__pyx_t_2) {
        __Pyx_AddTraceback("traits.protocols._speedups.Protocol__adapt__");
        if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_t_1);

        /* "traits/protocols/_speedups.pyx":298
 *         except AttributeError:
 *             # Some object have no __class__; use their type
 *             cls = <object> (<PyObject *>obj).ob_type             # <<<<<<<<<<<<<<
 * 
 *     mro = None
 */
        __Pyx_INCREF(((PyObject *)((PyObject *)__pyx_v_obj)->ob_type));
        __Pyx_DECREF(__pyx_v_cls);
        __pyx_v_cls = ((PyObject *)((PyObject *)__pyx_v_obj)->ob_type);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L8_exception_handled;
      }
      __pyx_L9_except_error:;
      __Pyx_XGIVEREF(__pyx_save_exc_type);
      __Pyx_XGIVEREF(__pyx_save_exc_value);
      __Pyx_XGIVEREF(__pyx_save_exc_tb);
      __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
      goto __pyx_L1_error;
      __pyx_L8_exception_handled:;
      __Pyx_XGIVEREF(__pyx_save_exc_type);
      __Pyx_XGIVEREF(__pyx_save_exc_value);
      __Pyx_XGIVEREF(__pyx_save_exc_tb);
      __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
      __pyx_L14_try_end:;
    }
  }
  __pyx_L6:;

  /* "traits/protocols/_speedups.pyx":300
 *             cls = <object> (<PyObject *>obj).ob_type
 * 
 *     mro = None             # <<<<<<<<<<<<<<
 *     if PyType_Check(cls):
 *         # It's a type, we can use its mro directly
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF(__pyx_v_mro);
  __pyx_v_mro = Py_None;

  /* "traits/protocols/_speedups.pyx":301
 * 
 *     mro = None
 *     if PyType_Check(cls):             # <<<<<<<<<<<<<<
 *         # It's a type, we can use its mro directly
 *         tmp = <void*>((<PyTypeObject *>cls).tp_mro)
 */
  __pyx_t_2 = PyType_Check(__pyx_v_cls);
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":303
 *     if PyType_Check(cls):
 *         # It's a type, we can use its mro directly
 *         tmp = <void*>((<PyTypeObject *>cls).tp_mro)             # <<<<<<<<<<<<<<
 *         if tmp != NULL:
 *             mro = <object>tmp
 */
    __pyx_v_tmp = ((void *)((PyTypeObject *)__pyx_v_cls)->tp_mro);

    /* "traits/protocols/_speedups.pyx":304
 *         # It's a type, we can use its mro directly
 *         tmp = <void*>((<PyTypeObject *>cls).tp_mro)
 *         if tmp != NULL:             # <<<<<<<<<<<<<<
 *             mro = <object>tmp
 * 
 */
    __pyx_t_5 = (__pyx_v_tmp != NULL);
    if (__pyx_t_5) {

      /* "traits/protocols/_speedups.pyx":305
 *         tmp = <void*>((<PyTypeObject *>cls).tp_mro)
 *         if tmp != NULL:
 *             mro = <object>tmp             # <<<<<<<<<<<<<<
 * 
 *     if mro is None:
 */
      __Pyx_INCREF(((PyObject *)__pyx_v_tmp));
      __Pyx_DECREF(__pyx_v_mro);
      __pyx_v_mro = ((PyObject *)__pyx_v_tmp);
      goto __pyx_L18;
    }
    __pyx_L18:;
    goto __pyx_L17;
  }
  __pyx_L17:;

  /* "traits/protocols/_speedups.pyx":307
 *             mro = <object>tmp
 * 
 *     if mro is None:             # <<<<<<<<<<<<<<
 *         if PyClass_Check(cls):
 *             # It's a classic class, build up its MRO
 */
  __pyx_t_5 = (__pyx_v_mro == Py_None);
  if (__pyx_t_5) {

    /* "traits/protocols/_speedups.pyx":308
 * 
 *     if mro is None:
 *         if PyClass_Check(cls):             # <<<<<<<<<<<<<<
 *             # It's a classic class, build up its MRO
 *             mro = []
 */
    __pyx_t_2 = PyClass_Check(__pyx_v_cls);
    if (__pyx_t_2) {

      /* "traits/protocols/_speedups.pyx":310
 *         if PyClass_Check(cls):
 *             # It's a classic class, build up its MRO
 *             mro = []             # <<<<<<<<<<<<<<
 *             buildClassicMRO(<PyClassObject *>cls, <PyListObject *>mro)
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_DECREF(__pyx_v_mro);
      __pyx_v_mro = ((PyObject *)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "traits/protocols/_speedups.pyx":311
 *             # It's a classic class, build up its MRO
 *             mro = []
 *             buildClassicMRO(<PyClassObject *>cls, <PyListObject *>mro)             # <<<<<<<<<<<<<<
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *             PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 */
      __pyx_t_1 = __pyx_f_9enthought_6traits_9protocols_9_speedups_buildClassicMRO(((PyClassObject *)__pyx_v_cls), ((PyListObject *)__pyx_v_mro)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "traits/protocols/_speedups.pyx":312
 *             mro = []
 *             buildClassicMRO(<PyClassObject *>cls, <PyListObject *>mro)
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)             # <<<<<<<<<<<<<<
 *             PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)
 * 
 */
      __pyx_t_6 = ((PyListObject *)__pyx_v_mro);
      __pyx_t_7 = (&PyInstance_Type);
      __pyx_t_1 = ((PyObject *)__pyx_t_7);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = PyList_Append(__pyx_t_6, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "traits/protocols/_speedups.pyx":313
 *             buildClassicMRO(<PyClassObject *>cls, <PyListObject *>mro)
 *             PyList_Append(<PyListObject *>mro, <object> &PyInstance_Type)
 *             PyList_Append(<PyListObject *>mro, <object> &PyBaseObject_Type)             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
      __pyx_t_8 = ((PyListObject *)__pyx_v_mro);
      __pyx_t_9 = (&PyBaseObject_Type);
      __pyx_t_1 = ((PyObject *)__pyx_t_9);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = PyList_Append(__pyx_t_8, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L20;
    }
    /*else*/ {

      /* "traits/protocols/_speedups.pyx":317
 *         else:
 *             # Fallback to getting __mro__ (for e.g. security proxies/ExtensionClass)
 *             try:             # <<<<<<<<<<<<<<
 *                 mro = getattr(cls, __mro)
 *             except Exception:
 */
      {
        PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
        __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
        __Pyx_XGOTREF(__pyx_save_exc_type);
        __Pyx_XGOTREF(__pyx_save_exc_value);
        __Pyx_XGOTREF(__pyx_save_exc_tb);
        /*try:*/ {

          /* "traits/protocols/_speedups.pyx":318
 *             # Fallback to getting __mro__ (for e.g. security proxies/ExtensionClass)
 *             try:
 *                 mro = getattr(cls, __mro)             # <<<<<<<<<<<<<<
 *             except Exception:
 *                 # No __mro__?  Is it an ExtensionClass?
 */
          __pyx_t_1 = __pyx_v_9enthought_6traits_9protocols_9_speedups___mro;
          __Pyx_INCREF(__pyx_t_1);
          __pyx_t_3 = PyObject_GetAttr(__pyx_v_cls, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L21_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_v_mro);
          __pyx_v_mro = __pyx_t_3;
          __pyx_t_3 = 0;
        }
        __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
        __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
        __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
        goto __pyx_L28_try_end;
        __pyx_L21_error:;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "traits/protocols/_speedups.pyx":319
 *             try:
 *                 mro = getattr(cls, __mro)
 *             except Exception:             # <<<<<<<<<<<<<<
 *                 # No __mro__?  Is it an ExtensionClass?
 *                 if PyObject_TypeCheck(cls,__ECType):
 */
        __pyx_t_2 = PyErr_ExceptionMatches(__pyx_builtin_Exception);
        if (__pyx_t_2) {
          __Pyx_AddTraceback("traits.protocols._speedups.Protocol__adapt__");
          if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_1, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L23_except_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GOTREF(__pyx_t_4);

          /* "traits/protocols/_speedups.pyx":321
 *             except Exception:
 *                 # No __mro__?  Is it an ExtensionClass?
 *                 if PyObject_TypeCheck(cls,__ECType):             # <<<<<<<<<<<<<<
 *                     # Yep, toss out the error and compute a reasonable MRO
 *                     mro = extClassMRO(cls, 1)
 */
          __pyx_t_10 = __pyx_v_9enthought_6traits_9protocols_9_speedups___ECType;
          __Pyx_INCREF(__pyx_t_10);
          __pyx_t_2 = PyObject_TypeCheck(__pyx_v_cls, __pyx_t_10);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (__pyx_t_2) {

            /* "traits/protocols/_speedups.pyx":323
 *                 if PyObject_TypeCheck(cls,__ECType):
 *                     # Yep, toss out the error and compute a reasonable MRO
 *                     mro = extClassMRO(cls, 1)             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise
 */
            __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__extClassMRO); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L23_except_error;}
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L23_except_error;}
            __Pyx_GOTREF(((PyObject *)__pyx_t_11));
            __Pyx_INCREF(__pyx_v_cls);
            PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_cls);
            __Pyx_GIVEREF(__pyx_v_cls);
            __Pyx_INCREF(__pyx_int_1);
            PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_1);
            __Pyx_GIVEREF(__pyx_int_1);
            __pyx_t_12 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L23_except_error;}
            __Pyx_GOTREF(__pyx_t_12);
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
            __Pyx_DECREF(__pyx_v_mro);
            __pyx_v_mro = __pyx_t_12;
            __pyx_t_12 = 0;
            goto __pyx_L31;
          }
          /*else*/ {

            /* "traits/protocols/_speedups.pyx":325
 *                     mro = extClassMRO(cls, 1)
 *                 else:
 *                     raise             # <<<<<<<<<<<<<<
 * 
 * 
 */
            __Pyx_GIVEREF(__pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_1);
            __Pyx_GIVEREF(__pyx_t_4);
            __Pyx_ErrRestore(__pyx_t_3, __pyx_t_1, __pyx_t_4);
            __pyx_t_3 = 0; __pyx_t_1 = 0; __pyx_t_4 = 0; 
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L23_except_error;}
          }
          __pyx_L31:;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          goto __pyx_L22_exception_handled;
        }
        __pyx_L23_except_error:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L1_error;
        __pyx_L22_exception_handled:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        __pyx_L28_try_end:;
      }
    }
    __pyx_L20:;
    goto __pyx_L19;
  }
  __pyx_L19:;

  /* "traits/protocols/_speedups.pyx":336
 * 
 * 
 *     get = self._Protocol__adapters.get             # <<<<<<<<<<<<<<
 * 
 *     if PyTuple_Check(mro):
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___Protocol__adapters); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__get); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_v_get);
  __pyx_v_get = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "traits/protocols/_speedups.pyx":338
 *     get = self._Protocol__adapters.get
 * 
 *     if PyTuple_Check(mro):             # <<<<<<<<<<<<<<
 *         #print "tuple",mro
 *         for i from 0 <= i < PyTuple_GET_SIZE(<PyTupleObject *>mro):
 */
  __pyx_t_2 = PyTuple_Check(__pyx_v_mro);
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":340
 *     if PyTuple_Check(mro):
 *         #print "tuple",mro
 *         for i from 0 <= i < PyTuple_GET_SIZE(<PyTupleObject *>mro):             # <<<<<<<<<<<<<<
 *             cls = <object> PyTuple_GET_ITEM(<PyTupleObject *>mro, i)
 *             factory=get(cls)
 */
    __pyx_t_2 = PyTuple_GET_SIZE(((PyTupleObject *)__pyx_v_mro));
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {

      /* "traits/protocols/_speedups.pyx":341
 *         #print "tuple",mro
 *         for i from 0 <= i < PyTuple_GET_SIZE(<PyTupleObject *>mro):
 *             cls = <object> PyTuple_GET_ITEM(<PyTupleObject *>mro, i)             # <<<<<<<<<<<<<<
 *             factory=get(cls)
 *             if factory is not None:
 */
      __pyx_t_13 = PyTuple_GET_ITEM(((PyTupleObject *)__pyx_v_mro), __pyx_v_i);
      __Pyx_INCREF(((PyObject *)__pyx_t_13));
      __Pyx_DECREF(__pyx_v_cls);
      __pyx_v_cls = ((PyObject *)__pyx_t_13);

      /* "traits/protocols/_speedups.pyx":342
 *         for i from 0 <= i < PyTuple_GET_SIZE(<PyTupleObject *>mro):
 *             cls = <object> PyTuple_GET_ITEM(<PyTupleObject *>mro, i)
 *             factory=get(cls)             # <<<<<<<<<<<<<<
 *             if factory is not None:
 *                 return factory[0](obj)
 */
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_INCREF(__pyx_v_cls);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cls);
      __Pyx_GIVEREF(__pyx_v_cls);
      __pyx_t_4 = PyObject_Call(__pyx_v_get, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_v_factory);
      __pyx_v_factory = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "traits/protocols/_speedups.pyx":343
 *             cls = <object> PyTuple_GET_ITEM(<PyTupleObject *>mro, i)
 *             factory=get(cls)
 *             if factory is not None:             # <<<<<<<<<<<<<<
 *                 return factory[0](obj)
 * 
 */
      __pyx_t_5 = (__pyx_v_factory != Py_None);
      if (__pyx_t_5) {

        /* "traits/protocols/_speedups.pyx":344
 *             factory=get(cls)
 *             if factory is not None:
 *                 return factory[0](obj)             # <<<<<<<<<<<<<<
 * 
 *     elif PyList_Check(mro):
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_factory, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_1));
        __Pyx_INCREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_3;
        __pyx_t_3 = 0;
        goto __pyx_L0;
        goto __pyx_L35;
      }
      __pyx_L35:;
    }
    goto __pyx_L32;
  }

  /* "traits/protocols/_speedups.pyx":346
 *                 return factory[0](obj)
 * 
 *     elif PyList_Check(mro):             # <<<<<<<<<<<<<<
 *         #print "list",mro
 *         for i from 0 <= i < PyList_GET_SIZE(<PyListObject *>mro):
 */
  __pyx_t_2 = PyList_Check(__pyx_v_mro);
  if (__pyx_t_2) {

    /* "traits/protocols/_speedups.pyx":348
 *     elif PyList_Check(mro):
 *         #print "list",mro
 *         for i from 0 <= i < PyList_GET_SIZE(<PyListObject *>mro):             # <<<<<<<<<<<<<<
 *             cls = <object> PyList_GET_ITEM(<PyListObject *>mro, i)
 *             factory=get(cls)
 */
    __pyx_t_2 = PyList_GET_SIZE(((PyListObject *)__pyx_v_mro));
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {

      /* "traits/protocols/_speedups.pyx":349
 *         #print "list",mro
 *         for i from 0 <= i < PyList_GET_SIZE(<PyListObject *>mro):
 *             cls = <object> PyList_GET_ITEM(<PyListObject *>mro, i)             # <<<<<<<<<<<<<<
 *             factory=get(cls)
 *             if factory is not None:
 */
      __pyx_t_14 = PyList_GET_ITEM(((PyListObject *)__pyx_v_mro), __pyx_v_i);
      __Pyx_INCREF(((PyObject *)__pyx_t_14));
      __Pyx_DECREF(__pyx_v_cls);
      __pyx_v_cls = ((PyObject *)__pyx_t_14);

      /* "traits/protocols/_speedups.pyx":350
 *         for i from 0 <= i < PyList_GET_SIZE(<PyListObject *>mro):
 *             cls = <object> PyList_GET_ITEM(<PyListObject *>mro, i)
 *             factory=get(cls)             # <<<<<<<<<<<<<<
 *             if factory is not None:
 *                 return factory[0](obj)
 */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_INCREF(__pyx_v_cls);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_cls);
      __Pyx_GIVEREF(__pyx_v_cls);
      __pyx_t_1 = PyObject_Call(__pyx_v_get, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_v_factory);
      __pyx_v_factory = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "traits/protocols/_speedups.pyx":351
 *             cls = <object> PyList_GET_ITEM(<PyListObject *>mro, i)
 *             factory=get(cls)
 *             if factory is not None:             # <<<<<<<<<<<<<<
 *                 return factory[0](obj)
 * 
 */
      __pyx_t_5 = (__pyx_v_factory != Py_None);
      if (__pyx_t_5) {

        /* "traits/protocols/_speedups.pyx":352
 *             factory=get(cls)
 *             if factory is not None:
 *                 return factory[0](obj)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_factory, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_3));
        __Pyx_INCREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
        __pyx_r = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L0;
        goto __pyx_L38;
      }
      __pyx_L38:;
    }
    goto __pyx_L32;
  }
  /*else*/ {

    /* "traits/protocols/_speedups.pyx":357
 *         #print "other",mro
 * 
 *         for cls in mro:             # <<<<<<<<<<<<<<
 *             factory=get(cls)
 *             if factory is not None:
 */
    if (PyList_CheckExact(__pyx_v_mro) || PyTuple_CheckExact(__pyx_v_mro)) {
      __pyx_t_15 = 0; __pyx_t_4 = __pyx_v_mro; __Pyx_INCREF(__pyx_t_4);
    } else {
      __pyx_t_15 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_mro); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
    }
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_4)) break;
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_4))) {
        if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++;
      } else {
        __pyx_t_3 = PyIter_Next(__pyx_t_4);
        if (!__pyx_t_3) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_DECREF(__pyx_v_cls);
      __pyx_v_cls = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "traits/protocols/_speedups.pyx":358
 * 
 *         for cls in mro:
 *             factory=get(cls)             # <<<<<<<<<<<<<<
 *             if factory is not None:
 *                 return factory[0](obj)
 */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_INCREF(__pyx_v_cls);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_cls);
      __Pyx_GIVEREF(__pyx_v_cls);
      __pyx_t_1 = PyObject_Call(__pyx_v_get, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_v_factory);
      __pyx_v_factory = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "traits/protocols/_speedups.pyx":359
 *         for cls in mro:
 *             factory=get(cls)
 *             if factory is not None:             # <<<<<<<<<<<<<<
 *                 return factory[0](obj)
 * 
 */
      __pyx_t_5 = (__pyx_v_factory != Py_None);
      if (__pyx_t_5) {

        /* "traits/protocols/_speedups.pyx":360
 *             factory=get(cls)
 *             if factory is not None:
 *                 return factory[0](obj)             # <<<<<<<<<<<<<<
 * 
 * 
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_factory, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_3));
        __Pyx_INCREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        __pyx_t_12 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
        __pyx_r = __pyx_t_12;
        __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        goto __pyx_L0;
        goto __pyx_L41;
      }
      __pyx_L41:;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_L32:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("traits.protocols._speedups.Protocol__adapt__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_cls);
  __Pyx_DECREF(__pyx_v_mro);
  __Pyx_DECREF(__pyx_v_get);
  __Pyx_DECREF(__pyx_v_factory);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_tp_new_9enthought_6traits_9protocols_9_speedups_metamethod(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)o);
  p->func = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_9enthought_6traits_9protocols_9_speedups_metamethod(PyObject *o) {
  struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *p = (struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)o;
  Py_XDECREF(p->func);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_9enthought_6traits_9protocols_9_speedups_metamethod(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *p = (struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)o;
  if (p->func) {
    e = (*v)(p->func, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_9enthought_6traits_9protocols_9_speedups_metamethod(PyObject *o) {
  struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *p = (struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->func);
  p->func = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_tp_descr_get_9enthought_6traits_9protocols_9_speedups_metamethod(PyObject *o, PyObject *i, PyObject *c) {
  PyObject *r = 0;
  if (!i) i = Py_None;
  if (!c) c = Py_None;
  r = __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_1__get__(o, i, c);
  return r;
}

static int __pyx_tp_descr_set_9enthought_6traits_9protocols_9_speedups_metamethod(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_2__set__(o, i, v);
  }
  else {
    return __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod_3__delete__(o, i);
  }
}

static PyMethodDef __pyx_methods_9enthought_6traits_9protocols_9_speedups_metamethod[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_metamethod = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_metamethod = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_metamethod = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_metamethod = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_9enthought_6traits_9protocols_9_speedups_metamethod = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("traits.protocols._speedups.metamethod"), /*tp_name*/
  sizeof(struct __pyx_obj_9enthought_6traits_9protocols_9_speedups_metamethod), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_9enthought_6traits_9protocols_9_speedups_metamethod, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_metamethod, /*tp_as_number*/
  &__pyx_tp_as_sequence_metamethod, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_metamethod, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_metamethod, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("Wrapper for metaclass method that might be confused w/instance method"), /*tp_doc*/
  __pyx_tp_traverse_9enthought_6traits_9protocols_9_speedups_metamethod, /*tp_traverse*/
  __pyx_tp_clear_9enthought_6traits_9protocols_9_speedups_metamethod, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_9enthought_6traits_9protocols_9_speedups_metamethod, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  __pyx_tp_descr_get_9enthought_6traits_9protocols_9_speedups_metamethod, /*tp_descr_get*/
  __pyx_tp_descr_set_9enthought_6traits_9protocols_9_speedups_metamethod, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_9enthought_6traits_9protocols_9_speedups_10metamethod___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_9enthought_6traits_9protocols_9_speedups_metamethod, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("_speedups"),
    __Pyx_DOCSTR(__pyx_k_13), /* 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_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
  {&__pyx_n_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 1},
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_n_s__AdaptationFailure, __pyx_k__AdaptationFailure, sizeof(__pyx_k__AdaptationFailure), 0, 0, 1, 1},
  {&__pyx_n_s__AttributeError, __pyx_k__AttributeError, sizeof(__pyx_k__AttributeError), 0, 0, 1, 1},
  {&__pyx_n_s__DOES_NOT_SUPPORT, __pyx_k__DOES_NOT_SUPPORT, sizeof(__pyx_k__DOES_NOT_SUPPORT), 0, 0, 1, 1},
  {&__pyx_n_s__DeprecationWarning, __pyx_k__DeprecationWarning, sizeof(__pyx_k__DeprecationWarning), 0, 0, 1, 1},
  {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1},
  {&__pyx_n_s__ExtensionClass, __pyx_k__ExtensionClass, sizeof(__pyx_k__ExtensionClass), 0, 0, 1, 1},
  {&__pyx_n_s__ImportError, __pyx_k__ImportError, sizeof(__pyx_k__ImportError), 0, 0, 1, 1},
  {&__pyx_n_s__NO_ADAPTER_NEEDED, __pyx_k__NO_ADAPTER_NEEDED, sizeof(__pyx_k__NO_ADAPTER_NEEDED), 0, 0, 1, 1},
  {&__pyx_n_s__Protocol__adapt__, __pyx_k__Protocol__adapt__, sizeof(__pyx_k__Protocol__adapt__), 0, 0, 1, 1},
  {&__pyx_n_s__Protocol__call__, __pyx_k__Protocol__call__, sizeof(__pyx_k__Protocol__call__), 0, 0, 1, 1},
  {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
  {&__pyx_n_s___Protocol__adapters, __pyx_k___Protocol__adapters, sizeof(__pyx_k___Protocol__adapters), 0, 0, 1, 1},
  {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
  {&__pyx_n_s____bases__, __pyx_k____bases__, sizeof(__pyx_k____bases__), 0, 0, 1, 1},
  {&__pyx_n_s____class, __pyx_k____class, sizeof(__pyx_k____class), 0, 0, 1, 1},
  {&__pyx_n_s____import__, __pyx_k____import__, sizeof(__pyx_k____import__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____mro__, __pyx_k____mro__, sizeof(__pyx_k____mro__), 0, 0, 1, 1},
  {&__pyx_n_s____name__, __pyx_k____name__, sizeof(__pyx_k____name__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s__adapt, __pyx_k__adapt, sizeof(__pyx_k__adapt), 0, 0, 1, 1},
  {&__pyx_n_s__cl_bases, __pyx_k__cl_bases, sizeof(__pyx_k__cl_bases), 0, 0, 1, 1},
  {&__pyx_n_s__classicMRO, __pyx_k__classicMRO, sizeof(__pyx_k__classicMRO), 0, 0, 1, 1},
  {&__pyx_n_s__default, __pyx_k__default, sizeof(__pyx_k__default), 0, 0, 1, 1},
  {&__pyx_n_s__exc_clear, __pyx_k__exc_clear, sizeof(__pyx_k__exc_clear), 0, 0, 1, 1},
  {&__pyx_n_s__exc_info, __pyx_k__exc_info, sizeof(__pyx_k__exc_info), 0, 0, 1, 1},
  {&__pyx_n_s__extClassMRO, __pyx_k__extClassMRO, sizeof(__pyx_k__extClassMRO), 0, 0, 1, 1},
  {&__pyx_n_s__extendedClassic, __pyx_k__extendedClassic, sizeof(__pyx_k__extendedClassic), 0, 0, 1, 1},
  {&__pyx_n_s__factory, __pyx_k__factory, sizeof(__pyx_k__factory), 0, 0, 1, 1},
  {&__pyx_n_s__fromlist, __pyx_k__fromlist, sizeof(__pyx_k__fromlist), 0, 0, 1, 1},
  {&__pyx_n_s__func, __pyx_k__func, sizeof(__pyx_k__func), 0, 0, 1, 1},
  {&__pyx_n_s__get, __pyx_k__get, sizeof(__pyx_k__get), 0, 0, 1, 1},
  {&__pyx_n_s__getMRO, __pyx_k__getMRO, sizeof(__pyx_k__getMRO), 0, 0, 1, 1},
  {&__pyx_n_s__globals, __pyx_k__globals, sizeof(__pyx_k__globals), 0, 0, 1, 1},
  {&__pyx_n_s__in_class, __pyx_k__in_class, sizeof(__pyx_k__in_class), 0, 0, 1, 1},
  {&__pyx_n_s__level, __pyx_k__level, sizeof(__pyx_k__level), 0, 0, 1, 1},
  {&__pyx_n_s__metamethod, __pyx_k__metamethod, sizeof(__pyx_k__metamethod), 0, 0, 1, 1},
  {&__pyx_n_s__ob, __pyx_k__ob, sizeof(__pyx_k__ob), 0, 0, 1, 1},
  {&__pyx_n_s__ob_type, __pyx_k__ob_type, sizeof(__pyx_k__ob_type), 0, 0, 1, 1},
  {&__pyx_n_s__obj, __pyx_k__obj, sizeof(__pyx_k__obj), 0, 0, 1, 1},
  {&__pyx_n_s__object, __pyx_k__object, sizeof(__pyx_k__object), 0, 0, 1, 1},
  {&__pyx_n_s__protocol, __pyx_k__protocol, sizeof(__pyx_k__protocol), 0, 0, 1, 1},
  {&__pyx_n_s__protocols, __pyx_k__protocols, sizeof(__pyx_k__protocols), 0, 0, 1, 1},
  {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1},
  {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
  {&__pyx_n_s__tb_next, __pyx_k__tb_next, sizeof(__pyx_k__tb_next), 0, 0, 1, 1},
  {&__pyx_n_s__tp_mro, __pyx_k__tp_mro, sizeof(__pyx_k__tp_mro), 0, 0, 1, 1},
  {&__pyx_n_s__warn, __pyx_k__warn, sizeof(__pyx_k__warn), 0, 0, 1, 1},
  {&__pyx_n_s__warnings, __pyx_k__warnings, sizeof(__pyx_k__warnings), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin___import__ = __Pyx_GetName(__pyx_b, __pyx_n_s____import__); if (!__pyx_builtin___import__) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ImportError = __Pyx_GetName(__pyx_b, __pyx_n_s__ImportError); if (!__pyx_builtin_ImportError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_object = __Pyx_GetName(__pyx_b, __pyx_n_s__object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_AttributeError = __Pyx_GetName(__pyx_b, __pyx_n_s__AttributeError); if (!__pyx_builtin_AttributeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_DeprecationWarning = __Pyx_GetName(__pyx_b, __pyx_n_s__DeprecationWarning); if (!__pyx_builtin_DeprecationWarning) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");

  /* "traits/protocols/_speedups.pyx":115
 * 
 *     def __set__(self, ob, value):
 *         raise AttributeError("Read-only attribute")             # <<<<<<<<<<<<<<
 * 
 *     def __delete__(self, ob):
 */
  __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_2));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
  PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));

  /* "traits/protocols/_speedups.pyx":118
 * 
 *     def __delete__(self, ob):
 *         raise AttributeError("Read-only attribute")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_3));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
  PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_s_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3));

  /* "traits/protocols/_speedups.pyx":66
 * # an extension module, globals() returns the globals dictionary of the last
 * # pure Python module that was executing.
 * AdaptationFailure = __import__(             # <<<<<<<<<<<<<<
 *     'protocols', globals=dict(__name__=__name__),
 *     fromlist=['AdaptationFailure'], level=1
 */
  __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_14));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__protocols));
  PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_n_s__protocols));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__protocols));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  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;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__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 init_speedups(void); /*proto*/
PyMODINIT_FUNC init_speedups(void)
#else
PyMODINIT_FUNC PyInit__speedups(void); /*proto*/
PyMODINIT_FUNC PyInit__speedups(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__speedups(void)", __LINE__, __FILE__);
  #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;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __pyx_binding_PyCFunctionType_USED
  if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_speedups"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_13), 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_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- 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;}
  if (__pyx_module_is_main_enthought__traits__protocols___speedups) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 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;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_9enthought_6traits_9protocols_9_speedups__marker = Py_None; Py_INCREF(Py_None);
  __pyx_v_9enthought_6traits_9protocols_9_speedups___conform = Py_None; Py_INCREF(Py_None);
  __pyx_v_9enthought_6traits_9protocols_9_speedups___adapt = Py_None; Py_INCREF(Py_None);
  __pyx_v_9enthought_6traits_9protocols_9_speedups___mro = Py_None; Py_INCREF(Py_None);
  __pyx_v_9enthought_6traits_9protocols_9_speedups___ECType = Py_None; Py_INCREF(Py_None);
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_9enthought_6traits_9protocols_9_speedups_metamethod) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "metamethod", (PyObject *)&__pyx_type_9enthought_6traits_9protocols_9_speedups_metamethod) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_9enthought_6traits_9protocols_9_speedups_metamethod = &__pyx_type_9enthought_6traits_9protocols_9_speedups_metamethod;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "traits/protocols/_speedups.pyx":3
 * """C Speedups for commonly-used operations"""
 * 
 * __all__ = [             # <<<<<<<<<<<<<<
 *     'NO_ADAPTER_NEEDED', 'DOES_NOT_SUPPORT',
 *     'adapt', 'Protocol__adapt__', 'metamethod', 'classicMRO', 'getMRO',
 */
  __pyx_t_1 = PyList_New(8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__NO_ADAPTER_NEEDED));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__NO_ADAPTER_NEEDED));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__NO_ADAPTER_NEEDED));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__DOES_NOT_SUPPORT));
  PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__DOES_NOT_SUPPORT));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__DOES_NOT_SUPPORT));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__adapt));
  PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__adapt));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__adapt));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__Protocol__adapt__));
  PyList_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__Protocol__adapt__));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Protocol__adapt__));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__metamethod));
  PyList_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__metamethod));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__metamethod));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__classicMRO));
  PyList_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_n_s__classicMRO));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__classicMRO));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__getMRO));
  PyList_SET_ITEM(__pyx_t_1, 6, ((PyObject *)__pyx_n_s__getMRO));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__getMRO));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__Protocol__call__));
  PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__Protocol__call__));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Protocol__call__));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "traits/protocols/_speedups.pyx":61
 * 
 * cdef object _marker, __conform, __adapt, __mro, __ECType
 * from sys import exc_info, exc_clear             # <<<<<<<<<<<<<<
 * # Since we can't do "from future import absolute_import", we use __import__
 * # directly.  Fake the globals dictionary with just the relevant information. In
 */
  __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__exc_info));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__exc_info));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exc_info));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__exc_clear));
  PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__exc_clear));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__exc_clear));
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exc_info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__exc_info, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exc_clear); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__exc_clear, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "traits/protocols/_speedups.pyx":66
 * # an extension module, globals() returns the globals dictionary of the last
 * # pure Python module that was executing.
 * AdaptationFailure = __import__(             # <<<<<<<<<<<<<<
 *     'protocols', globals=dict(__name__=__name__),
 *     fromlist=['AdaptationFailure'], level=1
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));

  /* "traits/protocols/_speedups.pyx":67
 * # pure Python module that was executing.
 * AdaptationFailure = __import__(
 *     'protocols', globals=dict(__name__=__name__),             # <<<<<<<<<<<<<<
 *     fromlist=['AdaptationFailure'], level=1
 * ).AdaptationFailure
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s____name__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s____name__), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__globals), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "traits/protocols/_speedups.pyx":68
 * AdaptationFailure = __import__(
 *     'protocols', globals=dict(__name__=__name__),
 *     fromlist=['AdaptationFailure'], level=1             # <<<<<<<<<<<<<<
 * ).AdaptationFailure
 * 
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__AdaptationFailure));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__AdaptationFailure));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__AdaptationFailure));
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__fromlist), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__level), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = PyEval_CallObjectWithKeywords(__pyx_builtin___import__, ((PyObject *)__pyx_k_tuple_14), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__AdaptationFailure); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__AdaptationFailure, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "traits/protocols/_speedups.pyx":71
 * ).AdaptationFailure
 * 
 * try:             # <<<<<<<<<<<<<<
 *     from ExtensionClass import ExtensionClass
 *     __ECType = ExtensionClass
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "traits/protocols/_speedups.pyx":72
 * 
 * try:
 *     from ExtensionClass import ExtensionClass             # <<<<<<<<<<<<<<
 *     __ECType = ExtensionClass
 * except ImportError:
 */
      __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L2_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_INCREF(((PyObject *)__pyx_n_s__ExtensionClass));
      PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__ExtensionClass));
      __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ExtensionClass));
      __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__ExtensionClass), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L2_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__ExtensionClass); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L2_error;}
      __Pyx_GOTREF(__pyx_t_2);
      if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ExtensionClass, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L2_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "traits/protocols/_speedups.pyx":73
 * try:
 *     from ExtensionClass import ExtensionClass
 *     __ECType = ExtensionClass             # <<<<<<<<<<<<<<
 * except ImportError:
 *     __ECType = type
 */
      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__ExtensionClass); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L2_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___ECType);
      __Pyx_DECREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___ECType);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_v_9enthought_6traits_9protocols_9_speedups___ECType = __pyx_t_1;
      __pyx_t_1 = 0;
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L9_try_end;
    __pyx_L2_error:;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "traits/protocols/_speedups.pyx":74
 *     from ExtensionClass import ExtensionClass
 *     __ECType = ExtensionClass
 * except ImportError:             # <<<<<<<<<<<<<<
 *     __ECType = type
 * 
 */
    __pyx_t_4 = PyErr_ExceptionMatches(__pyx_builtin_ImportError);
    if (__pyx_t_4) {
      __Pyx_AddTraceback("traits.protocols._speedups");
      if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_3);

      /* "traits/protocols/_speedups.pyx":75
 *     __ECType = ExtensionClass
 * except ImportError:
 *     __ECType = type             # <<<<<<<<<<<<<<
 * 
 * _marker    = object()
 */
      __Pyx_INCREF(((PyObject *)((PyObject*)(&PyType_Type))));
      __Pyx_GOTREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___ECType);
      __Pyx_DECREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___ECType);
      __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyType_Type))));
      __pyx_v_9enthought_6traits_9protocols_9_speedups___ECType = ((PyObject *)((PyObject*)(&PyType_Type)));
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L3_exception_handled;
    }
    __pyx_L4_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L3_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L9_try_end:;
  }

  /* "traits/protocols/_speedups.pyx":77
 *     __ECType = type
 * 
 * _marker    = object()             # <<<<<<<<<<<<<<
 * __conform  = PyString_InternFromString("__conform__")
 * __adapt    = PyString_InternFromString("__adapt__")
 */
  __pyx_t_3 = PyObject_Call(__pyx_builtin_object, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __Pyx_DECREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_v_9enthought_6traits_9protocols_9_speedups__marker = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":78
 * 
 * _marker    = object()
 * __conform  = PyString_InternFromString("__conform__")             # <<<<<<<<<<<<<<
 * __adapt    = PyString_InternFromString("__adapt__")
 * __class    = PyString_InternFromString("__class__")
 */
  __pyx_t_3 = PyString_InternFromString(__pyx_k____conform__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___conform);
  __Pyx_DECREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___conform);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_v_9enthought_6traits_9protocols_9_speedups___conform = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":79
 * _marker    = object()
 * __conform  = PyString_InternFromString("__conform__")
 * __adapt    = PyString_InternFromString("__adapt__")             # <<<<<<<<<<<<<<
 * __class    = PyString_InternFromString("__class__")
 * __mro      = PyString_InternFromString("__mro__")
 */
  __pyx_t_3 = PyString_InternFromString(__pyx_k____adapt__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___adapt);
  __Pyx_DECREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___adapt);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_v_9enthought_6traits_9protocols_9_speedups___adapt = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":80
 * __conform  = PyString_InternFromString("__conform__")
 * __adapt    = PyString_InternFromString("__adapt__")
 * __class    = PyString_InternFromString("__class__")             # <<<<<<<<<<<<<<
 * __mro      = PyString_InternFromString("__mro__")
 * 
 */
  __pyx_t_3 = PyString_InternFromString(__pyx_k____class__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____class, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":81
 * __adapt    = PyString_InternFromString("__adapt__")
 * __class    = PyString_InternFromString("__class__")
 * __mro      = PyString_InternFromString("__mro__")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PyString_InternFromString(__pyx_k____mro__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___mro);
  __Pyx_DECREF(__pyx_v_9enthought_6traits_9protocols_9_speedups___mro);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_v_9enthought_6traits_9protocols_9_speedups___mro = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":92
 * # Fundamental Adapters
 * 
 * def NO_ADAPTER_NEEDED(obj, protocol=None):             # <<<<<<<<<<<<<<
 *     """Assume 'obj' implements 'protocol' directly"""
 *     return obj
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_NO_ADAPTER_NEEDED, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__NO_ADAPTER_NEEDED, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":96
 *     return obj
 * 
 * def DOES_NOT_SUPPORT(obj, protocol=None):             # <<<<<<<<<<<<<<
 *     """Prevent 'obj' from supporting 'protocol'"""
 *     return None
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_1DOES_NOT_SUPPORT, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DOES_NOT_SUPPORT, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":190
 * 
 * 
 * def adapt(obj, protocol, default=_marker, factory=_marker):             # <<<<<<<<<<<<<<
 *     """PEP 246-alike: Adapt 'obj' to 'protocol', return 'default'
 * 
 */
  __Pyx_INCREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __pyx_k_6 = __pyx_v_9enthought_6traits_9protocols_9_speedups__marker;
  __Pyx_GIVEREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __Pyx_INCREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __pyx_k_7 = __pyx_v_9enthought_6traits_9protocols_9_speedups__marker;
  __Pyx_GIVEREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_2adapt, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__adapt, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":198
 *     return _adapt(obj,protocol,default,factory)
 * 
 * def Protocol__call__(self, ob, default=_marker):             # <<<<<<<<<<<<<<
 *     """Adapt to this protocol"""
 *     return _adapt(ob,self,default,_marker)
 */
  __Pyx_INCREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __pyx_k_8 = __pyx_v_9enthought_6traits_9protocols_9_speedups__marker;
  __Pyx_GIVEREF(__pyx_v_9enthought_6traits_9protocols_9_speedups__marker);
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_3Protocol__call__, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Protocol__call__, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":217
 * 
 * 
 * def classicMRO(ob, extendedClassic=False):             # <<<<<<<<<<<<<<
 * 
 *     if PyClass_Check(ob):
 */
  __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_k_9 = __pyx_t_3;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_4classicMRO, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__classicMRO, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":250
 * 
 * 
 * def extClassMRO(ob, extendedClassic=False):             # <<<<<<<<<<<<<<
 *     mro = []
 *     buildECMRO(ob, <PyListObject *>mro)
 */
  __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_k_11 = __pyx_t_3;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_5extClassMRO, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__extClassMRO, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":260
 * 
 * 
 * def getMRO(ob, extendedClassic=False):             # <<<<<<<<<<<<<<
 * 
 *     if PyClass_Check(ob):
 */
  __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_k_12 = __pyx_t_3;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_6getMRO, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__getMRO, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":285
 * 
 * 
 * def Protocol__adapt__(self, obj):             # <<<<<<<<<<<<<<
 * 
 *     cdef void *tmp
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9enthought_6traits_9protocols_9_speedups_7Protocol__adapt__, NULL, __pyx_n_s_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Protocol__adapt__, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "traits/protocols/_speedups.pyx":1
 * """C Speedups for commonly-used operations"""             # <<<<<<<<<<<<<<
 * 
 * __all__ = [
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    __Pyx_AddTraceback("init traits.protocols._speedups");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init traits.protocols._speedups");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */

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_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 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)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #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 {
                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) &&
                        _PyString_Eq(**name, key)) 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) &&
                            _PyString_Eq(**name, key)) 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 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 CYTHON_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 CYTHON_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 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;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;

    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (!PyExceptionClass_Check(type)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }

bad:
    return;
}
#endif

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
    if (unlikely(tstate->curexc_type))
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
        goto bad;
    #endif
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
    Py_INCREF(local_type);
    Py_INCREF(local_value);
    Py_INCREF(local_tb);
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    /* Make sure tstate is in a consistent state when we XDECREF
       these objects (XDECREF may run arbitrary code). */
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}



static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}

static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
    PyObject *r = PyObject_GetAttr(o, n);
    if (!r) {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError))
            goto bad;
        PyErr_Clear();
        r = d;
        Py_INCREF(d);
    }
    return r;
bad:
    return NULL;
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#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;
    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;
    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,*/
        __pyx_empty_bytes, /*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,*/
        __pyx_empty_bytes  /*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(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->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_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *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 CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_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 CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
