/* Generated by Pyrex 0.9.2.1 on Sat Jun 26 22:41:00 2004 */

#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#include "Carbon/Carbon.h"
#include "agl.h"


typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
static int __Pyx_PrintItem(PyObject *); /*proto*/
static int __Pyx_PrintNewline(void); /*proto*/
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static void __Pyx_ReRaise(void); /*proto*/
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
static PyObject *__Pyx_GetExcValue(void); /*proto*/
static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
static void __Pyx_WriteUnraisable(char *name); /*proto*/
static void __Pyx_AddTraceback(char *funcname); /*proto*/
static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
static int __Pyx_GetVtable(PyObject *dict, void **vtabptr); /*proto*/
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
staticforward char **__pyx_f;

/* Declarations from AGL */

staticforward PyTypeObject __pyx_type_3AGL_Context;

struct __pyx_obj_3AGL_Context {
  PyObject_HEAD
  struct __AGLContextRec (*agl_context);
};

static PyTypeObject *__pyx_ptype_3AGL_Context = 0;

/* Implementation of AGL */


static PyObject *__pyx_n_AGLError;
static PyObject *__pyx_n_StandardError;
static PyObject *__pyx_n___init__;

static PyObject *__pyx_n_Exception;

static PyObject *__pyx_k2p;

char (__pyx_k2[]) = "%s: %s";

static PyObject *__pyx_f_3AGL_8AGLError___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_3AGL_8AGLError___init__ = {"__init__", (PyCFunction)__pyx_f_3AGL_8AGLError___init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_f_3AGL_8AGLError___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_funcname = 0;
  PyObject *__pyx_v_message;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {"self","funcname",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_self, &__pyx_v_funcname)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_funcname);
  __pyx_v_message = Py_None; Py_INCREF(__pyx_v_message);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":93 */
  __pyx_1 = PyString_FromString(((char (*))aglErrorString(aglGetError()))); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;}
  Py_DECREF(__pyx_v_message);
  __pyx_v_message = __pyx_1;
  __pyx_1 = 0;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":94 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_Exception); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n___init__); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyTuple_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;}
  Py_INCREF(__pyx_v_funcname);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_funcname);
  Py_INCREF(__pyx_v_message);
  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_v_message);
  __pyx_3 = PyNumber_Remainder(__pyx_k2p, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3);
  __pyx_3 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_2, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("AGL.AGLError.__init__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_message);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_funcname);
  return __pyx_r;
}

static PyObject *__pyx_n_raise_agl_error;
static PyObject *__pyx_n_aglChoosePixelFormat;
static PyObject *__pyx_n_aglCreateContext;


static int __pyx_f_3AGL_7Context___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_3AGL_7Context___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_3AGL_Context *__pyx_v_share = 0;
  int __pyx_v_double_buffer;
  int __pyx_v_alpha_size;
  int __pyx_v_depth_size;
  int __pyx_v_stencil_size;
  int __pyx_v_accum_size;
  struct __AGLContextRec (*__pyx_v_agl_share);
  long (__pyx_v_attribs[20]);
  int __pyx_v_ap;
  struct __AGLPixelFormatRec (*__pyx_v_format);
  int __pyx_v_result;
  int __pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"share","double_buffer","alpha_size","depth_size","stencil_size","accum_size",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "Oiiiii", __pyx_argnames, &__pyx_v_share, &__pyx_v_double_buffer, &__pyx_v_alpha_size, &__pyx_v_depth_size, &__pyx_v_stencil_size, &__pyx_v_accum_size)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_share);
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_share), __pyx_ptype_3AGL_Context, 1, "share")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":109 */
  __pyx_1 = ((PyObject *)__pyx_v_share) != Py_None;
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":110 */
    __pyx_v_agl_share = __pyx_v_share->agl_context;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":112 */
    __pyx_v_agl_share = 0;
  }
  __pyx_L2:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":113 */
  (__pyx_v_attribs[0]) = AGL_RGBA;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":114 */
  __pyx_v_ap = 1;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":115 */
  __pyx_1 = __pyx_v_alpha_size;
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":116 */
    (__pyx_v_attribs[__pyx_v_ap]) = AGL_ALPHA_SIZE;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":117 */
    (__pyx_v_attribs[(__pyx_v_ap + 1)]) = __pyx_v_alpha_size;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":118 */
    __pyx_v_ap = (__pyx_v_ap + 2);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":119 */
  __pyx_1 = __pyx_v_depth_size;
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":120 */
    (__pyx_v_attribs[__pyx_v_ap]) = AGL_DEPTH_SIZE;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":121 */
    (__pyx_v_attribs[(__pyx_v_ap + 1)]) = __pyx_v_depth_size;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":122 */
    __pyx_v_ap = (__pyx_v_ap + 2);
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":123 */
  __pyx_1 = __pyx_v_stencil_size;
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":124 */
    (__pyx_v_attribs[__pyx_v_ap]) = AGL_STENCIL_SIZE;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":125 */
    (__pyx_v_attribs[(__pyx_v_ap + 1)]) = __pyx_v_stencil_size;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":126 */
    __pyx_v_ap = (__pyx_v_ap + 2);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":127 */
  __pyx_1 = __pyx_v_accum_size;
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":128 */
    (__pyx_v_attribs[__pyx_v_ap]) = AGL_ACCUM_RED_SIZE;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":129 */
    (__pyx_v_attribs[(__pyx_v_ap + 1)]) = __pyx_v_accum_size;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":130 */
    (__pyx_v_attribs[(__pyx_v_ap + 2)]) = AGL_ACCUM_GREEN_SIZE;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":131 */
    (__pyx_v_attribs[(__pyx_v_ap + 3)]) = __pyx_v_accum_size;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":132 */
    (__pyx_v_attribs[(__pyx_v_ap + 4)]) = AGL_ACCUM_BLUE_SIZE;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":133 */
    (__pyx_v_attribs[(__pyx_v_ap + 5)]) = __pyx_v_accum_size;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":134 */
    __pyx_v_ap = (__pyx_v_ap + 6);

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":135 */
    __pyx_1 = __pyx_v_alpha_size;
    if (__pyx_1) {

      /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":136 */
      (__pyx_v_attribs[__pyx_v_ap]) = AGL_ACCUM_ALPHA_SIZE;

      /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":137 */
      (__pyx_v_attribs[(__pyx_v_ap + 1)]) = __pyx_v_alpha_size;

      /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":138 */
      __pyx_v_ap = (__pyx_v_ap + 2);
      goto __pyx_L7;
    }
    __pyx_L7:;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":139 */
  __pyx_1 = __pyx_v_double_buffer;
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":140 */
    (__pyx_v_attribs[__pyx_v_ap]) = AGL_DOUBLEBUFFER;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":141 */
    __pyx_v_ap = (__pyx_v_ap + 1);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":142 */
  (__pyx_v_attribs[__pyx_v_ap]) = AGL_NONE;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":143 */
  __pyx_v_format = aglChoosePixelFormat(0,0,__pyx_v_attribs);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":144 */
  __pyx_1 = (!(__pyx_v_format != 0));
  if (__pyx_1) {
    __pyx_1 = __pyx_v_double_buffer;
  }
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":145 */
    (__pyx_v_attribs[(__pyx_v_ap - 1)]) = AGL_NONE;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":146 */
    __pyx_v_format = aglChoosePixelFormat(0,0,__pyx_v_attribs);
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":147 */
  __pyx_1 = (!(__pyx_v_format != 0));
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":148 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_raise_agl_error); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; goto __pyx_L1;}
    Py_INCREF(__pyx_n_aglChoosePixelFormat);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_n_aglChoosePixelFormat);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":149 */
  /*try:*/ {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":150 */
    ((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context = aglCreateContext(__pyx_v_format,__pyx_v_agl_share);

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":151 */
    __pyx_1 = (!(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context != 0));
    if (__pyx_1) {

      /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":152 */
      __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_raise_agl_error); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; goto __pyx_L12;}
      __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; goto __pyx_L12;}
      Py_INCREF(__pyx_n_aglCreateContext);
      PyTuple_SET_ITEM(__pyx_3, 0, __pyx_n_aglCreateContext);
      __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; goto __pyx_L12;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      Py_DECREF(__pyx_4); __pyx_4 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;
  }
  /*finally:*/ {
    int __pyx_why;
    __pyx_why = 0; goto __pyx_L13;
    __pyx_L11: __pyx_why = 3; goto __pyx_L13;
    __pyx_L12: {
      __pyx_why = 4;
      Py_XDECREF(__pyx_2); __pyx_2 = 0;
      Py_XDECREF(__pyx_3); __pyx_3 = 0;
      Py_XDECREF(__pyx_4); __pyx_4 = 0;
      PyErr_Fetch(&__pyx_2, &__pyx_3, &__pyx_4);
      __pyx_1 = __pyx_lineno;
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":154 */
    aglDestroyPixelFormat(__pyx_v_format);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        PyErr_Restore(__pyx_2, __pyx_3, __pyx_4);
        __pyx_lineno = __pyx_1;
        __pyx_2 = 0;
        __pyx_3 = 0;
        __pyx_4 = 0;
        goto __pyx_L1;
      }
    }
  }

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("AGL.Context.__new__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_share);
  return __pyx_r;
}

static void __pyx_f_3AGL_7Context___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_f_3AGL_7Context___dealloc__(PyObject *__pyx_v_self) {
  int __pyx_1;
  Py_INCREF(__pyx_v_self);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":157 */
  __pyx_1 = (((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context != 0);
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":158 */
    __pyx_1 = (((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context == aglGetCurrentContext());
    if (__pyx_1) {

      /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":159 */
      aglSetCurrentContext(0);
      goto __pyx_L3;
    }
    __pyx_L3:;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":160 */
    aglSetDrawable(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context,0);

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":161 */
    aglDestroyContext(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context);
    goto __pyx_L2;
  }
  __pyx_L2:;

  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("AGL.Context.__dealloc__");
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
}

static PyObject *__pyx_n_aglSetDrawable;
static PyObject *__pyx_n_aglEnable;
static PyObject *__pyx_n_aglSetInteger;


static PyObject *__pyx_f_3AGL_7Context_update_port(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3AGL_7Context_update_port[] = "Attach the context to the current grafport, and set\n		the buffer rect from the bounds of the current clip\n		region.";
static PyObject *__pyx_f_3AGL_7Context_update_port(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  long (__pyx_v_params[4]);
  struct OpaqueGrafPtr (*__pyx_v_port);
  struct OpaqueRgnHandle (*__pyx_v_clip_rgn);
  Rect __pyx_v_port_rect;
  Rect __pyx_v_buffer_rect;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":172 */
  GetPort((&__pyx_v_port));

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":173 */
  GetPortBounds(__pyx_v_port,(&__pyx_v_port_rect));

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":174 */
  __pyx_v_clip_rgn = NewRgn();

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":175 */
  GetPortClipRegion(__pyx_v_port,__pyx_v_clip_rgn);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":176 */
  GetRegionBounds(__pyx_v_clip_rgn,(&__pyx_v_buffer_rect));

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":177 */
  DisposeRgn(__pyx_v_clip_rgn);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":180 */
  (__pyx_v_params[0]) = (__pyx_v_buffer_rect.left - __pyx_v_port_rect.left);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":181 */
  (__pyx_v_params[1]) = (__pyx_v_port_rect.bottom - __pyx_v_buffer_rect.bottom);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":182 */
  (__pyx_v_params[2]) = (__pyx_v_buffer_rect.right - __pyx_v_buffer_rect.left);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":183 */
  (__pyx_v_params[3]) = (__pyx_v_buffer_rect.bottom - __pyx_v_buffer_rect.top);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":184 */
  __pyx_1 = (!aglSetDrawable(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context,__pyx_v_port));
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":185 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_raise_agl_error); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
    Py_INCREF(__pyx_n_aglSetDrawable);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_n_aglSetDrawable);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":186 */
  __pyx_1 = (!aglEnable(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context,AGL_BUFFER_RECT));
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":187 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_raise_agl_error); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; goto __pyx_L1;}
    Py_INCREF(__pyx_n_aglEnable);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_n_aglEnable);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":188 */
  __pyx_1 = (!aglSetInteger(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context,AGL_BUFFER_RECT,__pyx_v_params));
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":189 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_raise_agl_error); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; goto __pyx_L1;}
    Py_INCREF(__pyx_n_aglSetInteger);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_n_aglSetInteger);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("AGL.Context.update_port");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_3AGL_7Context_swap_buffers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_3AGL_7Context_swap_buffers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":192 */
  aglSwapBuffers(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context);

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("AGL.Context.swap_buffers");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_aglSetCurrentContext;


static PyObject *__pyx_f_3AGL_7Context_with_current(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3AGL_7Context_with_current[] = "Execute the proc with this context as the current context.";
static PyObject *__pyx_f_3AGL_7Context_with_current(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_proc = 0;
  struct __AGLContextRec (*__pyx_v_old_agl_context);
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"proc",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_proc)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_proc);

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":197 */
  __pyx_v_old_agl_context = aglGetCurrentContext();

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":198 */
  __pyx_1 = (!aglSetCurrentContext(((struct __pyx_obj_3AGL_Context *)__pyx_v_self)->agl_context));
  if (__pyx_1) {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":199 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_raise_agl_error); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; goto __pyx_L1;}
    Py_INCREF(__pyx_n_aglSetCurrentContext);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_n_aglSetCurrentContext);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":200 */
  /*try:*/ {

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":201 */
    __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; goto __pyx_L4;}
    __pyx_3 = PyObject_CallObject(__pyx_v_proc, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; goto __pyx_L4;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
  }
  /*finally:*/ {
    int __pyx_why;
    __pyx_why = 0; goto __pyx_L5;
    __pyx_L3: __pyx_why = 3; goto __pyx_L5;
    __pyx_L4: {
      __pyx_why = 4;
      Py_XDECREF(__pyx_4); __pyx_4 = 0;
      Py_XDECREF(__pyx_2); __pyx_2 = 0;
      Py_XDECREF(__pyx_3); __pyx_3 = 0;
      PyErr_Fetch(&__pyx_4, &__pyx_2, &__pyx_3);
      __pyx_1 = __pyx_lineno;
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":203 */
    aglSetCurrentContext(__pyx_v_old_agl_context);
    switch (__pyx_why) {
      case 3: goto __pyx_L0;
      case 4: {
        PyErr_Restore(__pyx_4, __pyx_2, __pyx_3);
        __pyx_lineno = __pyx_1;
        __pyx_4 = 0;
        __pyx_2 = 0;
        __pyx_3 = 0;
        goto __pyx_L1;
      }
    }
  }

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("AGL.Context.with_current");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_proc);
  return __pyx_r;
}

static __Pyx_InternTabEntry __pyx_intern_tab[] = {
  {&__pyx_n_AGLError, "AGLError"},
  {&__pyx_n_Exception, "Exception"},
  {&__pyx_n_StandardError, "StandardError"},
  {&__pyx_n___init__, "__init__"},
  {&__pyx_n_aglChoosePixelFormat, "aglChoosePixelFormat"},
  {&__pyx_n_aglCreateContext, "aglCreateContext"},
  {&__pyx_n_aglEnable, "aglEnable"},
  {&__pyx_n_aglSetCurrentContext, "aglSetCurrentContext"},
  {&__pyx_n_aglSetDrawable, "aglSetDrawable"},
  {&__pyx_n_aglSetInteger, "aglSetInteger"},
  {&__pyx_n_raise_agl_error, "raise_agl_error"},
  {0, 0}
};

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_k2p, __pyx_k2, sizeof(__pyx_k2)},
  {0, 0, 0}
};

static PyObject *__pyx_tp_new_3AGL_Context(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  struct __pyx_obj_3AGL_Context *p = (struct __pyx_obj_3AGL_Context *)o;
  if (__pyx_f_3AGL_7Context___new__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_3AGL_Context(PyObject *o) {
  struct __pyx_obj_3AGL_Context *p = (struct __pyx_obj_3AGL_Context *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++o->ob_refcnt;
    __pyx_f_3AGL_7Context___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --o->ob_refcnt;
    PyErr_Restore(etype, eval, etb);
  }
  (*o->ob_type->tp_free)(o);
}

static int __pyx_tp_traverse_3AGL_Context(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_3AGL_Context *p = (struct __pyx_obj_3AGL_Context *)o;
  return 0;
}

static int __pyx_tp_clear_3AGL_Context(PyObject *o) {
  struct __pyx_obj_3AGL_Context *p = (struct __pyx_obj_3AGL_Context *)o;
  return 0;
}

static struct PyMethodDef __pyx_methods_3AGL_Context[] = {
  {"update_port", (PyCFunction)__pyx_f_3AGL_7Context_update_port, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3AGL_7Context_update_port},
  {"swap_buffers", (PyCFunction)__pyx_f_3AGL_7Context_swap_buffers, METH_VARARGS|METH_KEYWORDS, 0},
  {"with_current", (PyCFunction)__pyx_f_3AGL_7Context_with_current, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3AGL_7Context_with_current},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_Context = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  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*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  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*/
};

static PySequenceMethods __pyx_tp_as_sequence_Context = {
  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_Context = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_Context = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

statichere PyTypeObject __pyx_type_3AGL_Context = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "AGL.Context", /*tp_name*/
  sizeof(struct __pyx_obj_3AGL_Context), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_3AGL_Context, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_Context, /*tp_as_number*/
  &__pyx_tp_as_sequence_Context, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_Context, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_Context, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_3AGL_Context, /*tp_traverse*/
  __pyx_tp_clear_3AGL_Context, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_3AGL_Context, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_3AGL_Context, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

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

DL_EXPORT(void) initAGL(void); /*proto*/
DL_EXPORT(void) initAGL(void) {
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  __pyx_m = Py_InitModule4("AGL", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
  if (PyType_Ready(&__pyx_type_3AGL_Context) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "Context", (PyObject *)&__pyx_type_3AGL_Context) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;}
  __pyx_ptype_3AGL_Context = &__pyx_type_3AGL_Context;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":90 */
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;}
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_StandardError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
  __pyx_2 = 0;
  __pyx_2 = __Pyx_CreateClass(__pyx_3, __pyx_1, __pyx_n_AGLError, "AGL"); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":92 */
  __pyx_3 = PyCFunction_New(&__pyx_mdef_3AGL_8AGLError___init__, 0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
  __pyx_4 = PyMethod_New(__pyx_3, 0, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  if (PyObject_SetAttr(__pyx_2, __pyx_n___init__, __pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_AGLError, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/Local/Projects/C/PyGUI/GUI/Mac/AGL.pyx":194 */
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("AGL");
}

static char *__pyx_filenames[] = {
  "AGL.pyx",
};
statichere char **__pyx_f = __pyx_filenames;

/* Runtime support code */

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name) {
	if (!type) {
		PyErr_Format(PyExc_SystemError, "Missing type object");
		return 0;
	}
	if ((none_allowed && obj == Py_None) || PyObject_TypeCheck(obj, type))
		return 1;
	PyErr_Format(PyExc_TypeError,
		"Argument '%s' has incorrect type (expected %s, got %s)",
		name, type->tp_name, obj->ob_type->tp_name);
	return 0;
}

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 PyObject *__Pyx_CreateClass(
	PyObject *bases, PyObject *dict, PyObject *name, char *modname)
{
	PyObject *py_modname;
	PyObject *result = 0;
	
	py_modname = PyString_FromString(modname);
	if (!py_modname)
		goto bad;
	if (PyDict_SetItemString(dict, "__module__", py_modname) < 0)
		goto bad;
	result = PyClass_New(bases, dict, name);
bad:
	Py_XDECREF(py_modname);
	return result;
}

static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
	while (t->p) {
		*t->p = PyString_InternFromString(t->s);
		if (!*t->p)
			return -1;
		++t;
	}
	return 0;
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
	while (t->p) {
		*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
		if (!*t->p)
			return -1;
		++t;
	}
	return 0;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(char *funcname) {
	PyObject *py_srcfile = 0;
	PyObject *py_funcname = 0;
	PyObject *py_globals = 0;
	PyObject *empty_tuple = 0;
	PyObject *empty_string = 0;
	PyCodeObject *py_code = 0;
	PyFrameObject *py_frame = 0;
	
	py_srcfile = PyString_FromString(__pyx_filename);
	if (!py_srcfile) goto bad;
	py_funcname = PyString_FromString(funcname);
	if (!py_funcname) goto bad;
	py_globals = PyModule_GetDict(__pyx_m);
	if (!py_globals) goto bad;
	empty_tuple = PyTuple_New(0);
	if (!empty_tuple) goto bad;
	empty_string = PyString_FromString("");
	if (!empty_string) goto bad;
	py_code = PyCode_New(
		0,            /*int argcount,*/
		0,            /*int nlocals,*/
		0,            /*int stacksize,*/
		0,            /*int flags,*/
		empty_string, /*PyObject *code,*/
		empty_tuple,  /*PyObject *consts,*/
		empty_tuple,  /*PyObject *names,*/
		empty_tuple,  /*PyObject *varnames,*/
		empty_tuple,  /*PyObject *freevars,*/
		empty_tuple,  /*PyObject *cellvars,*/
		py_srcfile,   /*PyObject *filename,*/
		py_funcname,  /*PyObject *name,*/
		__pyx_lineno,   /*int firstlineno,*/
		empty_string  /*PyObject *lnotab*/
	);
	if (!py_code) goto bad;
	py_frame = PyFrame_New(
		PyThreadState_Get(), /*PyThreadState *tstate,*/
		py_code,             /*PyCodeObject *code,*/
		py_globals,          /*PyObject *globals,*/
		0                    /*PyObject *locals*/
	);
	if (!py_frame) goto bad;
	py_frame->f_lineno = __pyx_lineno;
	PyTraceBack_Here(py_frame);
bad:
	Py_XDECREF(py_srcfile);
	Py_XDECREF(py_funcname);
	Py_XDECREF(empty_tuple);
	Py_XDECREF(empty_string);
	Py_XDECREF(py_code);
	Py_XDECREF(py_frame);
}
