/* Generated by Pyrex 0.9.3 on Fri Jul 01 13:46:48 2005 */

#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#include "windows.h"
#include "win32_load_driver.h"
#include "win32_vretrace_orig.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 win32_vretrace */

staticforward PyTypeObject __pyx_type_14win32_vretrace_VRetraceHandleKeeper;

struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper {
  PyObject_HEAD
  HANDLE VRetrace_Handle;
};

static PyTypeObject *__pyx_ptype_14win32_vretrace_VRetraceHandleKeeper = 0;
static struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *__pyx_v_14win32_vretrace_hk;
static PyObject *__pyx_k1;

/* Implementation of win32_vretrace */

static PyObject *__pyx_n_WAIT_INSIDE;
static PyObject *__pyx_n_WAIT_START;
static PyObject *__pyx_n_WAIT_END;
static PyObject *__pyx_n_LoadVRetraceDriver;
static PyObject *__pyx_n_WaitForRetrace;

static PyObject *__pyx_n_RuntimeError;

static PyObject *__pyx_k2p;
static PyObject *__pyx_k3p;
static PyObject *__pyx_k4p;

static char (__pyx_k2[]) = "Could not load driver VRETRACE.SYS";
static char (__pyx_k3[]) = "Invalid version (%lx) returned";
static char (__pyx_k4[]) = "No vertical retrace detected";

static PyObject *__pyx_f_14win32_vretrace_LoadVRetraceDriver(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_14win32_vretrace_LoadVRetraceDriver(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  BOOL __pyx_v_success;
  HANDLE __pyx_v_VRetrace_Handle;
  DWORD __pyx_v_dwVersion;
  DWORD __pyx_v_dwCycles;
  DWORD __pyx_v_dwRetCount;
  DWORD __pyx_v_dwReturned;
  struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *__pyx_v_hk;
  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;
  ((PyObject*)__pyx_v_hk) = Py_None; Py_INCREF(((PyObject*)__pyx_v_hk));

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":50 */
  __pyx_v_VRetrace_Handle = LoadDriver(VRETRACE_NAME);

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":51 */
  __pyx_1 = (__pyx_v_VRetrace_Handle == INVALID_HANDLE_VALUE);
  if (__pyx_1) {

    /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":52 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;}
    Py_INCREF(__pyx_k2p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k2p);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":55 */
  __pyx_v_dwVersion = 0;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":56 */
  __pyx_v_success = DeviceIoControl(__pyx_v_VRetrace_Handle,IOCTL_VRETRACE_VERSION,0,0,(&__pyx_v_dwVersion),(sizeof(__pyx_v_dwVersion)),(&__pyx_v_dwReturned),0);

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":61 */
  __pyx_1 = (!__pyx_v_success);
  if (!__pyx_1) {
    __pyx_1 = (__pyx_v_dwVersion < 256);
  }
  if (__pyx_1) {

    /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":62 */
    CloseHandle(__pyx_v_VRetrace_Handle);

    /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":63 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    __pyx_3 = PyInt_FromLong(__pyx_v_dwVersion); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    __pyx_4 = PyNumber_Remainder(__pyx_k3p, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_4);
    __pyx_4 = 0;
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":67 */
  __pyx_v_dwCycles = 0;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":68 */
  __pyx_v_success = DeviceIoControl(__pyx_v_VRetrace_Handle,IOCTL_VRETRACE_TEST,(&__pyx_v_dwCycles),(sizeof(__pyx_v_dwCycles)),(&__pyx_v_dwRetCount),(sizeof(__pyx_v_dwRetCount)),(&__pyx_v_dwReturned),0);

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":73 */
  __pyx_1 = (!__pyx_v_success);
  if (!__pyx_1) {
    __pyx_1 = (__pyx_v_dwRetCount == 0);
  }
  if (__pyx_1) {

    /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":74 */
    CloseHandle(__pyx_v_VRetrace_Handle);

    /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":75 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_RuntimeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
    Py_INCREF(__pyx_k4p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k4p);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":78 */
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; goto __pyx_L1;}
  __pyx_3 = PyObject_CallObject(((PyObject*)__pyx_ptype_14win32_vretrace_VRetraceHandleKeeper), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (!__Pyx_TypeTest(__pyx_3, __pyx_ptype_14win32_vretrace_VRetraceHandleKeeper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_hk));
  ((PyObject *)__pyx_v_hk) = __pyx_3;
  __pyx_3 = 0;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":79 */
  __pyx_v_hk->VRetrace_Handle = __pyx_v_VRetrace_Handle;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":80 */
  Py_INCREF(((PyObject *)__pyx_v_hk));
  __pyx_r = ((PyObject *)__pyx_v_hk);
  goto __pyx_L0;

  __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("win32_vretrace.LoadVRetraceDriver");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_hk);
  return __pyx_r;
}

static PyObject *__pyx_f_14win32_vretrace_WaitForRetrace(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14win32_vretrace_WaitForRetrace[] = "Wait for a vertical retrace signal\n\n    Arguments:\n    wait_start -- if true, will wait for the next retrace if one is already active\n\n    ";
static PyObject *__pyx_f_14win32_vretrace_WaitForRetrace(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_wait_start = 0;
  DWORD __pyx_v_dwWaitCode;
  DWORD __pyx_v_dwReturned;
  PyObject *__pyx_r;
  DWORD __pyx_1;
  static char *__pyx_argnames[] = {"wait_start",0};
  __pyx_v_wait_start = __pyx_k1;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|O", __pyx_argnames, &__pyx_v_wait_start)) return 0;
  Py_INCREF(__pyx_v_wait_start);

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":93 */
  __pyx_1 = PyInt_AsLong(__pyx_v_wait_start); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;}
  __pyx_v_dwWaitCode = __pyx_1;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":94 */
  DeviceIoControl(__pyx_v_14win32_vretrace_hk->VRetrace_Handle,IOCTL_VRETRACE_WAIT,(&__pyx_v_dwWaitCode),(sizeof(__pyx_v_dwWaitCode)),0,0,(&__pyx_v_dwReturned),0);

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("win32_vretrace.WaitForRetrace");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_wait_start);
  return __pyx_r;
}

static __Pyx_InternTabEntry __pyx_intern_tab[] = {
  {&__pyx_n_LoadVRetraceDriver, "LoadVRetraceDriver"},
  {&__pyx_n_RuntimeError, "RuntimeError"},
  {&__pyx_n_WAIT_END, "WAIT_END"},
  {&__pyx_n_WAIT_INSIDE, "WAIT_INSIDE"},
  {&__pyx_n_WAIT_START, "WAIT_START"},
  {&__pyx_n_WaitForRetrace, "WaitForRetrace"},
  {0, 0}
};

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

static PyObject *__pyx_tp_new_14win32_vretrace_VRetraceHandleKeeper(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *p = (struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *)o;
  return o;
}

static void __pyx_tp_dealloc_14win32_vretrace_VRetraceHandleKeeper(PyObject *o) {
  struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *p = (struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *)o;
  (*o->ob_type->tp_free)(o);
}

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

static int __pyx_tp_clear_14win32_vretrace_VRetraceHandleKeeper(PyObject *o) {
  struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *p = (struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper *)o;
  return 0;
}

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

static PyNumberMethods __pyx_tp_as_number_VRetraceHandleKeeper = {
  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_VRetraceHandleKeeper = {
  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_VRetraceHandleKeeper = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

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

statichere PyTypeObject __pyx_type_14win32_vretrace_VRetraceHandleKeeper = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "win32_vretrace.VRetraceHandleKeeper", /*tp_name*/
  sizeof(struct __pyx_obj_14win32_vretrace_VRetraceHandleKeeper), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_14win32_vretrace_VRetraceHandleKeeper, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_VRetraceHandleKeeper, /*tp_as_number*/
  &__pyx_tp_as_sequence_VRetraceHandleKeeper, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_VRetraceHandleKeeper, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_VRetraceHandleKeeper, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_14win32_vretrace_VRetraceHandleKeeper, /*tp_traverse*/
  __pyx_tp_clear_14win32_vretrace_VRetraceHandleKeeper, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_14win32_vretrace_VRetraceHandleKeeper, /*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_14win32_vretrace_VRetraceHandleKeeper, /*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[] = {
  {"LoadVRetraceDriver", (PyCFunction)__pyx_f_14win32_vretrace_LoadVRetraceDriver, METH_VARARGS|METH_KEYWORDS, 0},
  {"WaitForRetrace", (PyCFunction)__pyx_f_14win32_vretrace_WaitForRetrace, METH_VARARGS|METH_KEYWORDS, __pyx_doc_14win32_vretrace_WaitForRetrace},
  {0, 0, 0, 0}
};

DL_EXPORT(void) initwin32_vretrace(void); /*proto*/
DL_EXPORT(void) initwin32_vretrace(void) {
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  __pyx_m = Py_InitModule4("win32_vretrace", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;};
  ((PyObject*)__pyx_v_14win32_vretrace_hk) = Py_None; Py_INCREF(((PyObject*)__pyx_v_14win32_vretrace_hk));
  if (PyType_Ready(&__pyx_type_14win32_vretrace_VRetraceHandleKeeper) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "VRetraceHandleKeeper", (PyObject *)&__pyx_type_14win32_vretrace_VRetraceHandleKeeper) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; goto __pyx_L1;}
  __pyx_ptype_14win32_vretrace_VRetraceHandleKeeper = &__pyx_type_14win32_vretrace_VRetraceHandleKeeper;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":36 */
  __pyx_1 = PyInt_FromLong(VRETRACE_WAIT_INSIDE); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_WAIT_INSIDE, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":37 */
  __pyx_1 = PyInt_FromLong(VRETRACE_WAIT_START); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_WAIT_START, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":38 */
  __pyx_1 = PyInt_FromLong(VRETRACE_WAIT_END); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_WAIT_END, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":82 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_WAIT_START); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;}
  __pyx_k1 = __pyx_1;
  __pyx_1 = 0;

  /* "C:\Documents and Settings\astraw\Desktop\visionegg-devel\src\win32_vretrace.pyx":101 */
  __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n_LoadVRetraceDriver); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  if (!__Pyx_TypeTest(__pyx_4, __pyx_ptype_14win32_vretrace_VRetraceHandleKeeper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_14win32_vretrace_hk));
  ((PyObject *)__pyx_v_14win32_vretrace_hk) = __pyx_4;
  __pyx_4 = 0;
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("win32_vretrace");
}

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

/* 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 int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (obj == Py_None || PyObject_TypeCheck(obj, type))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %s to %s",
        obj->ob_type->tp_name, type->tp_name);
    return 0;
}

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);
    }
    /* Next, repeatedly, replace a tuple exception with its first item */
    while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
        PyObject *tmp = type;
        type = PyTuple_GET_ITEM(type, 0);
        Py_INCREF(type);
        Py_DECREF(tmp);
    }
    if (PyString_Check(type))
        ;
    else if (PyClass_Check(type))
        ; /*PyErr_NormalizeException(&type, &value, &tb);*/
    else if (PyInstance_Check(type)) {
        /* 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;
        }
        else {
            /* Normalize to raise <class>, <instance> */
            Py_DECREF(value);
            value = type;
            type = (PyObject*) ((PyInstanceObject*)type)->in_class;
            Py_INCREF(type);
        }
    }
    else {
        /* Not something you can raise.  You get an exception
           anyway, just not what you specified :-) */
        PyErr_Format(PyExc_TypeError,
                 "exceptions must be strings, classes, or "
                 "instances, not %s", type->ob_type->tp_name);
        goto raise_error;
    }
    PyErr_Restore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

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);
}
