File: glexception.i

package info (click to toggle)
mgltools-opengltk 1.5.7-1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 8,592 kB
  • ctags: 38,393
  • sloc: ansic: 98,617; python: 3,818; cpp: 1,943; sh: 1,332; tcl: 1,127; makefile: 65
file content (76 lines) | stat: -rw-r--r-- 1,742 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * copyright_notice
 */

%{
#include "opengltk.h"

static struct opengltk_export* s_opengltk = NULL;
PyObject_t PypImport_ModuleAttr( char const* modulename, char const* name)
{
  PyObject_t module, result;
  module = PyImport_ImportModule( (char*)modulename);
  if (NOT module) return NULL;
  result = PyObject_GetAttrString( module, (char*)name);
  Py_DECREF( module);
  return result;
}

void* PypImport_ModuleCobjAttr( char const* module, char const* name)
{
  PyObject_t attr;
  void* result;

  attr = PypImport_ModuleAttr( module, name);
  if (NOT attr) return NULL;
  result = PyCObject_AsVoidPtr( attr);
  Py_DECREF( attr);
  return result;
}


%}

%init
{
  s_opengltk = PypImport_ModuleCobjAttr( "opengltk.extent._utillib",
					 "opengltk_export");
  if (NOT s_opengltk) return;
  s_opengltk->checkerror = 1;
}

%exception
{
  GLenum errcode;

  if (s_opengltk->pythread)
    {
      printf ("pythread \n");
      if (PyThreadState_Get() != s_opengltk->pythread)
	return PyErr_Format( PyExc_RuntimeError,
			     "OpenGL is attached to a different thread");
      PyEval_ReleaseThread( s_opengltk->pythread);
    }
  $function
  if (s_opengltk->checkerror)
	
    {	
      errcode = glGetError();
      if (s_opengltk->pythread && s_opengltk->threadunlocked)
	PyEval_RestoreThread( s_opengltk->pythread);
#ifdef _WIN32
/*       if (GL_INVALID_OPERATION == errcode) printf( "rrrrrrr\n"); */
      if (errcode && GL_INVALID_OPERATION != errcode)
#else
      if (errcode)
#endif
	{
	  PyObject_t errret;
	  errret = s_opengltk->processerror( errcode);
	  if (errret) Py_DECREF( errret);
	  else return NULL;
	}
    }
  else if (s_opengltk->pythread && s_opengltk->threadunlocked)
    PyEval_RestoreThread( s_opengltk->pythread);
}