diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/python/generic | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r-- | source/blender/python/generic/CMakeLists.txt | 54 | ||||
-rw-r--r-- | source/blender/python/generic/bgl.c | 4355 | ||||
-rw-r--r-- | source/blender/python/generic/bgl.h | 31 | ||||
-rw-r--r-- | source/blender/python/generic/blf_py_api.c | 664 | ||||
-rw-r--r-- | source/blender/python/generic/blf_py_api.h | 2 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 500 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.h | 17 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_threads.c | 18 | ||||
-rw-r--r-- | source/blender/python/generic/idprop_py_api.c | 2671 | ||||
-rw-r--r-- | source/blender/python/generic/idprop_py_api.h | 39 | ||||
-rw-r--r-- | source/blender/python/generic/imbuf_py_api.c | 563 | ||||
-rw-r--r-- | source/blender/python/generic/imbuf_py_api.h | 2 | ||||
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 2020 | ||||
-rw-r--r-- | source/blender/python/generic/py_capi_utils.h | 120 | ||||
-rw-r--r-- | source/blender/python/generic/python_utildefines.h | 29 |
15 files changed, 5544 insertions, 5541 deletions
diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt index ea766d9f8d1..3b4182bc795 100644 --- a/source/blender/python/generic/CMakeLists.txt +++ b/source/blender/python/generic/CMakeLists.txt @@ -16,42 +16,42 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - . - ../../blenkernel - ../../blenlib - ../../gpu - ../../makesdna - ../../../../intern/guardedalloc - ../../../../intern/glew-mx + . + ../../blenkernel + ../../blenlib + ../../gpu + ../../makesdna + ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS - ${GLEW_INCLUDE_PATH} - ${PYTHON_INCLUDE_DIRS} + ${GLEW_INCLUDE_PATH} + ${PYTHON_INCLUDE_DIRS} ) set(SRC - bgl.c - blf_py_api.c - bpy_internal_import.c - bpy_threads.c - idprop_py_api.c - imbuf_py_api.c - py_capi_utils.c - - bgl.h - blf_py_api.h - bpy_internal_import.h - idprop_py_api.h - imbuf_py_api.h - py_capi_utils.h - - # header-only - python_utildefines.h + bgl.c + blf_py_api.c + bpy_internal_import.c + bpy_threads.c + idprop_py_api.c + imbuf_py_api.c + py_capi_utils.c + + bgl.h + blf_py_api.h + bpy_internal_import.h + idprop_py_api.h + imbuf_py_api.h + py_capi_utils.h + + # header-only + python_utildefines.h ) set(LIB - ${GLEW_LIBRARY} + ${GLEW_LIBRARY} ) add_definitions(${GL_DEFINITIONS}) diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index c089a2d03c2..02cad742ed9 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -35,123 +35,121 @@ #include "bgl.h" - /* -------------------------------------------------------------------- */ /** \name Local utility defines for wrapping OpenGL * \{ */ /*@ By golly George! It looks like fancy pants macro time!!! */ - /* TYPE_str is the string to pass to Py_ArgParse (for the format) */ /* TYPE_var is the name to pass to the GL function */ /* TYPE_ref is the pointer to pass to Py_ArgParse (to store in) */ /* TYPE_def is the C initialization of the variable */ -#define void_str "" +#define void_str "" #define void_var(num) -#define void_ref(num) &bgl_var##num -#define void_def(num) char bgl_var##num +#define void_ref(num) &bgl_var##num +#define void_def(num) char bgl_var##num #if 0 -#define buffer_str "O!" -#define buffer_var(number) (bgl_buffer##number)->buf.asvoid -#define buffer_ref(number) &BGL_bufferType, &bgl_buffer##number -#define buffer_def(number) Buffer *bgl_buffer##number +# define buffer_str "O!" +# define buffer_var(number) (bgl_buffer##number)->buf.asvoid +# define buffer_ref(number) &BGL_bufferType, &bgl_buffer##number +# define buffer_def(number) Buffer *bgl_buffer##number #endif /* GL Pointer fields, handled by buffer type */ /* GLdoubleP, GLfloatP, GLintP, GLuintP, GLshortP, GLsizeiP, GLcharP */ -#define GLbooleanP_str "O!" -#define GLbooleanP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLbooleanP_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLbooleanP_def(number) Buffer *bgl_buffer##number +#define GLbooleanP_str "O!" +#define GLbooleanP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLbooleanP_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLbooleanP_def(number) Buffer *bgl_buffer##number -#define GLbyteP_str "O!" +#define GLbyteP_str "O!" #define GLbyteP_var(number) (bgl_buffer##number)->buf.asvoid #define GLbyteP_ref(number) &BGL_bufferType, &bgl_buffer##number #define GLbyteP_def(number) Buffer *bgl_buffer##number -#define GLubyteP_str "O!" -#define GLubyteP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLubyteP_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLubyteP_def(number) Buffer *bgl_buffer##number +#define GLubyteP_str "O!" +#define GLubyteP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLubyteP_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLubyteP_def(number) Buffer *bgl_buffer##number -#define GLintP_str "O!" -#define GLintP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLintP_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLintP_def(number) Buffer *bgl_buffer##number +#define GLintP_str "O!" +#define GLintP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLintP_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLintP_def(number) Buffer *bgl_buffer##number -#define GLint64P_str "O!" -#define GLint64P_var(number) (bgl_buffer##number)->buf.asvoid -#define GLint64P_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLint64P_def(number) Buffer *bgl_buffer##number +#define GLint64P_str "O!" +#define GLint64P_var(number) (bgl_buffer##number)->buf.asvoid +#define GLint64P_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLint64P_def(number) Buffer *bgl_buffer##number -#define GLenumP_str "O!" -#define GLenumP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLenumP_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLenumP_def(number) Buffer *bgl_buffer##number +#define GLenumP_str "O!" +#define GLenumP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLenumP_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLenumP_def(number) Buffer *bgl_buffer##number -#define GLuintP_str "O!" +#define GLuintP_str "O!" #define GLuintP_var(number) (bgl_buffer##number)->buf.asvoid #define GLuintP_ref(number) &BGL_bufferType, &bgl_buffer##number #define GLuintP_def(number) Buffer *bgl_buffer##number #if 0 -#define GLuint64P_str "O!" -#define GLuint64P_var(number) (bgl_buffer##number)->buf.asvoid -#define GLuint64P_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLuint64P_def(number) Buffer *bgl_buffer##number +# define GLuint64P_str "O!" +# define GLuint64P_var(number) (bgl_buffer##number)->buf.asvoid +# define GLuint64P_ref(number) &BGL_bufferType, &bgl_buffer##number +# define GLuint64P_def(number) Buffer *bgl_buffer##number #endif -#define GLshortP_str "O!" -#define GLshortP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLshortP_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLshortP_def(number) Buffer *bgl_buffer##number +#define GLshortP_str "O!" +#define GLshortP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLshortP_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLshortP_def(number) Buffer *bgl_buffer##number -#define GLushortP_str "O!" +#define GLushortP_str "O!" #define GLushortP_var(number) (bgl_buffer##number)->buf.asvoid #define GLushortP_ref(number) &BGL_bufferType, &bgl_buffer##number #define GLushortP_def(number) Buffer *bgl_buffer##number -#define GLfloatP_str "O!" -#define GLfloatP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLfloatP_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLfloatP_def(number) Buffer *bgl_buffer##number +#define GLfloatP_str "O!" +#define GLfloatP_var(number) (bgl_buffer##number)->buf.asvoid +#define GLfloatP_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLfloatP_def(number) Buffer *bgl_buffer##number -#define GLdoubleP_str "O!" +#define GLdoubleP_str "O!" #define GLdoubleP_var(number) (bgl_buffer##number)->buf.asvoid #define GLdoubleP_ref(number) &BGL_bufferType, &bgl_buffer##number #define GLdoubleP_def(number) Buffer *bgl_buffer##number #if 0 -#define GLclampfP_str "O!" -#define GLclampfP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLclampfP_ref(number) &BGL_bufferType, &bgl_buffer##number -#define GLclampfP_def(number) Buffer *bgl_buffer##number +# define GLclampfP_str "O!" +# define GLclampfP_var(number) (bgl_buffer##number)->buf.asvoid +# define GLclampfP_ref(number) &BGL_bufferType, &bgl_buffer##number +# define GLclampfP_def(number) Buffer *bgl_buffer##number #endif -#define GLvoidP_str "O&" +#define GLvoidP_str "O&" #define GLvoidP_var(number) ((bgl_buffer##number) ? (bgl_buffer##number)->buf.asvoid : NULL) #define GLvoidP_ref(number) BGL_BufferOrNoneConverter, &bgl_buffer##number #define GLvoidP_def(number) Buffer *bgl_buffer##number -#define GLsizeiP_str "O!" +#define GLsizeiP_str "O!" #define GLsizeiP_var(number) (bgl_buffer##number)->buf.asvoid #define GLsizeiP_ref(number) &BGL_bufferType, &bgl_buffer##number #define GLsizeiP_def(number) Buffer *bgl_buffer##number -#define GLcharP_str "O!" +#define GLcharP_str "O!" #define GLcharP_var(number) (bgl_buffer##number)->buf.asvoid #define GLcharP_ref(number) &BGL_bufferType, &bgl_buffer##number #define GLcharP_def(number) Buffer *bgl_buffer##number #if 0 -#define buffer_str "O!" -#define buffer_var(number) (bgl_buffer##number)->buf.asvoid -#define buffer_ref(number) &BGL_bufferType, &bgl_buffer##number -#define buffer_def(number) Buffer *bgl_buffer##number +# define buffer_str "O!" +# define buffer_var(number) (bgl_buffer##number)->buf.asvoid +# define buffer_ref(number) &BGL_bufferType, &bgl_buffer##number +# define buffer_def(number) Buffer *bgl_buffer##number #endif /*@The standard GL typedefs are used as prototypes, we can't @@ -163,274 +161,260 @@ */ /* typedef unsigned int GLenum; */ -#define GLenum_str "i" -#define GLenum_var(num) bgl_var##num -#define GLenum_ref(num) &bgl_var##num -#define GLenum_def(num) /* unsigned */ int GLenum_var(num) +#define GLenum_str "i" +#define GLenum_var(num) bgl_var##num +#define GLenum_ref(num) &bgl_var##num +#define GLenum_def(num) /* unsigned */ int GLenum_var(num) /* typedef unsigned int GLboolean; */ -#define GLboolean_str "b" -#define GLboolean_var(num) bgl_var##num -#define GLboolean_ref(num) &bgl_var##num -#define GLboolean_def(num) /* unsigned */ char GLboolean_var(num) +#define GLboolean_str "b" +#define GLboolean_var(num) bgl_var##num +#define GLboolean_ref(num) &bgl_var##num +#define GLboolean_def(num) /* unsigned */ char GLboolean_var(num) /* typedef unsigned int GLbitfield; */ -#define GLbitfield_str "i" -#define GLbitfield_var(num) bgl_var##num -#define GLbitfield_ref(num) &bgl_var##num -#define GLbitfield_def(num) /* unsigned */ int GLbitfield_var(num) +#define GLbitfield_str "i" +#define GLbitfield_var(num) bgl_var##num +#define GLbitfield_ref(num) &bgl_var##num +#define GLbitfield_def(num) /* unsigned */ int GLbitfield_var(num) #if 0 /* typedef signed char GLbyte; */ -#define GLbyte_str "b" -#define GLbyte_var(num) bgl_var##num -#define GLbyte_ref(num) &bgl_var##num -#define GLbyte_def(num) signed char GLbyte_var(num) +# define GLbyte_str "b" +# define GLbyte_var(num) bgl_var##num +# define GLbyte_ref(num) &bgl_var##num +# define GLbyte_def(num) signed char GLbyte_var(num) #endif /* typedef short GLshort; */ -#define GLshort_str "h" -#define GLshort_var(num) bgl_var##num -#define GLshort_ref(num) &bgl_var##num -#define GLshort_def(num) short GLshort_var(num) +#define GLshort_str "h" +#define GLshort_var(num) bgl_var##num +#define GLshort_ref(num) &bgl_var##num +#define GLshort_def(num) short GLshort_var(num) /* typedef int GLint; */ -#define GLint_str "i" -#define GLint_var(num) bgl_var##num -#define GLint_ref(num) &bgl_var##num -#define GLint_def(num) int GLint_var(num) +#define GLint_str "i" +#define GLint_var(num) bgl_var##num +#define GLint_ref(num) &bgl_var##num +#define GLint_def(num) int GLint_var(num) /* typedef int GLsizei; */ -#define GLsizei_str "n" -#define GLsizei_var(num) bgl_var##num -#define GLsizei_ref(num) &bgl_var##num -#define GLsizei_def(num) size_t GLsizei_var(num) +#define GLsizei_str "n" +#define GLsizei_var(num) bgl_var##num +#define GLsizei_ref(num) &bgl_var##num +#define GLsizei_def(num) size_t GLsizei_var(num) /* typedef int GLsizeiptr; */ -#define GLsizeiptr_str "n" -#define GLsizeiptr_var(num) bgl_var##num -#define GLsizeiptr_ref(num) &bgl_var##num -#define GLsizeiptr_def(num) size_t GLsizeiptr_var(num) +#define GLsizeiptr_str "n" +#define GLsizeiptr_var(num) bgl_var##num +#define GLsizeiptr_ref(num) &bgl_var##num +#define GLsizeiptr_def(num) size_t GLsizeiptr_var(num) /* typedef int GLintptr; */ -#define GLintptr_str "n" -#define GLintptr_var(num) bgl_var##num -#define GLintptr_ref(num) &bgl_var##num -#define GLintptr_def(num) size_t GLintptr_var(num) +#define GLintptr_str "n" +#define GLintptr_var(num) bgl_var##num +#define GLintptr_ref(num) &bgl_var##num +#define GLintptr_def(num) size_t GLintptr_var(num) /* typedef unsigned char GLubyte; */ -#define GLubyte_str "B" -#define GLubyte_var(num) bgl_var##num -#define GLubyte_ref(num) &bgl_var##num -#define GLubyte_def(num) /* unsigned */ char GLubyte_var(num) +#define GLubyte_str "B" +#define GLubyte_var(num) bgl_var##num +#define GLubyte_ref(num) &bgl_var##num +#define GLubyte_def(num) /* unsigned */ char GLubyte_var(num) #if 0 /* typedef unsigned short GLushort; */ -#define GLushort_str "H" -#define GLushort_var(num) bgl_var##num -#define GLushort_ref(num) &bgl_var##num -#define GLushort_def(num) /* unsigned */ short GLushort_var(num) +# define GLushort_str "H" +# define GLushort_var(num) bgl_var##num +# define GLushort_ref(num) &bgl_var##num +# define GLushort_def(num) /* unsigned */ short GLushort_var(num) #endif /* typedef unsigned int GLuint; */ -#define GLuint_str "I" -#define GLuint_var(num) bgl_var##num -#define GLuint_ref(num) &bgl_var##num -#define GLuint_def(num) /* unsigned */ int GLuint_var(num) +#define GLuint_str "I" +#define GLuint_var(num) bgl_var##num +#define GLuint_ref(num) &bgl_var##num +#define GLuint_def(num) /* unsigned */ int GLuint_var(num) /* typedef unsigned int GLuint64; */ #if 0 -#define GLuint64_str "Q" -#define GLuint64_var(num) bgl_var##num -#define GLuint64_ref(num) &bgl_var##num -#define GLuint64_def(num) /* unsigned */ int GLuint64_var(num) +# define GLuint64_str "Q" +# define GLuint64_var(num) bgl_var##num +# define GLuint64_ref(num) &bgl_var##num +# define GLuint64_def(num) /* unsigned */ int GLuint64_var(num) #endif /* typedef unsigned int GLsync; */ #if 0 -#define GLsync_str "I" -#define GLsync_var(num) bgl_var##num -#define GLsync_ref(num) &bgl_var##num -#define GLsync_def(num) /* unsigned */ int GLsync_var(num) +# define GLsync_str "I" +# define GLsync_var(num) bgl_var##num +# define GLsync_ref(num) &bgl_var##num +# define GLsync_def(num) /* unsigned */ int GLsync_var(num) #endif /* typedef float GLfloat; */ -#define GLfloat_str "f" -#define GLfloat_var(num) bgl_var##num -#define GLfloat_ref(num) &bgl_var##num -#define GLfloat_def(num) float GLfloat_var(num) +#define GLfloat_str "f" +#define GLfloat_var(num) bgl_var##num +#define GLfloat_ref(num) &bgl_var##num +#define GLfloat_def(num) float GLfloat_var(num) /* typedef char *GLstring; */ -#define GLstring_str "s" +#define GLstring_str "s" #define GLstring_var(number) bgl_var##number #define GLstring_ref(number) &bgl_var##number #define GLstring_def(number) char *GLstring_var(number) /* typedef float GLclampf; */ #if 0 -#define GLclampf_str "f" -#define GLclampf_var(num) bgl_var##num -#define GLclampf_ref(num) &bgl_var##num -#define GLclampf_def(num) float GLclampf_var(num) +# define GLclampf_str "f" +# define GLclampf_var(num) bgl_var##num +# define GLclampf_ref(num) &bgl_var##num +# define GLclampf_def(num) float GLclampf_var(num) #endif /* typedef double GLdouble; */ -#define GLdouble_str "d" -#define GLdouble_var(num) bgl_var##num -#define GLdouble_ref(num) &bgl_var##num -#define GLdouble_def(num) double GLdouble_var(num) +#define GLdouble_str "d" +#define GLdouble_var(num) bgl_var##num +#define GLdouble_ref(num) &bgl_var##num +#define GLdouble_def(num) double GLdouble_var(num) /* typedef double GLclampd; */ #if 0 -#define GLclampd_str "d" -#define GLclampd_var(num) bgl_var##num -#define GLclampd_ref(num) &bgl_var##num -#define GLclampd_def(num) double GLclampd_var(num) +# define GLclampd_str "d" +# define GLclampd_var(num) bgl_var##num +# define GLclampd_ref(num) &bgl_var##num +# define GLclampd_def(num) double GLclampd_var(num) #endif -#define _arg_def1(a1) \ - a1##_def(1) +#define _arg_def1(a1) a1##_def(1) #define _arg_def2(a1, a2) \ - _arg_def1(a1); a2##_def(2) + _arg_def1(a1); \ + a2##_def(2) #define _arg_def3(a1, a2, a3) \ - _arg_def2(a1, a2); a3##_def(3) + _arg_def2(a1, a2); \ + a3##_def(3) #define _arg_def4(a1, a2, a3, a4) \ - _arg_def3(a1, a2, a3); a4##_def(4) + _arg_def3(a1, a2, a3); \ + a4##_def(4) #define _arg_def5(a1, a2, a3, a4, a5) \ - _arg_def4(a1, a2, a3, a4); a5##_def(5) + _arg_def4(a1, a2, a3, a4); \ + a5##_def(5) #define _arg_def6(a1, a2, a3, a4, a5, a6) \ - _arg_def5(a1, a2, a3, a4, a5); a6##_def(6) + _arg_def5(a1, a2, a3, a4, a5); \ + a6##_def(6) #define _arg_def7(a1, a2, a3, a4, a5, a6, a7) \ - _arg_def6(a1, a2, a3, a4, a5, a6); a7##_def(7) + _arg_def6(a1, a2, a3, a4, a5, a6); \ + a7##_def(7) #define _arg_def8(a1, a2, a3, a4, a5, a6, a7, a8) \ - _arg_def7(a1, a2, a3, a4, a5, a6, a7); a8##_def(8) + _arg_def7(a1, a2, a3, a4, a5, a6, a7); \ + a8##_def(8) #define _arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \ - _arg_def8(a1, a2, a3, a4, a5, a6, a7, a8); a9##_def(9) + _arg_def8(a1, a2, a3, a4, a5, a6, a7, a8); \ + a9##_def(9) #define _arg_def10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \ - _arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9); a10##_def(10) + _arg_def9(a1, a2, a3, a4, a5, a6, a7, a8, a9); \ + a10##_def(10) #define _arg_def11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \ - _arg_def10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); a11##_def(11) -#define arg_def(...) VA_NARGS_CALL_OVERLOAD(_arg_def, __VA_ARGS__) - -#define _arg_var1(a1) \ - a1##_var(1) -#define _arg_var2(a1, a2) \ - _arg_var1(a1), a2##_var(2) -#define _arg_var3(a1, a2, a3) \ - _arg_var2(a1, a2), a3##_var(3) -#define _arg_var4(a1, a2, a3, a4) \ - _arg_var3(a1, a2, a3), a4##_var(4) -#define _arg_var5(a1, a2, a3, a4, a5) \ - _arg_var4(a1, a2, a3, a4), a5##_var(5) -#define _arg_var6(a1, a2, a3, a4, a5, a6) \ - _arg_var5(a1, a2, a3, a4, a5), a6##_var(6) -#define _arg_var7(a1, a2, a3, a4, a5, a6, a7) \ - _arg_var6(a1, a2, a3, a4, a5, a6), a7##_var(7) + _arg_def10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \ + a11##_def(11) +#define arg_def(...) VA_NARGS_CALL_OVERLOAD(_arg_def, __VA_ARGS__) + +#define _arg_var1(a1) a1##_var(1) +#define _arg_var2(a1, a2) _arg_var1(a1), a2##_var(2) +#define _arg_var3(a1, a2, a3) _arg_var2(a1, a2), a3##_var(3) +#define _arg_var4(a1, a2, a3, a4) _arg_var3(a1, a2, a3), a4##_var(4) +#define _arg_var5(a1, a2, a3, a4, a5) _arg_var4(a1, a2, a3, a4), a5##_var(5) +#define _arg_var6(a1, a2, a3, a4, a5, a6) _arg_var5(a1, a2, a3, a4, a5), a6##_var(6) +#define _arg_var7(a1, a2, a3, a4, a5, a6, a7) _arg_var6(a1, a2, a3, a4, a5, a6), a7##_var(7) #define _arg_var8(a1, a2, a3, a4, a5, a6, a7, a8) \ - _arg_var7(a1, a2, a3, a4, a5, a6, a7), a8##_var(8) + _arg_var7(a1, a2, a3, a4, a5, a6, a7), a8##_var(8) #define _arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \ - _arg_var8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_var(9) + _arg_var8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_var(9) #define _arg_var10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \ - _arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_var(10) + _arg_var9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_var(10) #define _arg_var11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \ - _arg_var10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), a11##_var(11) -#define arg_var(...) VA_NARGS_CALL_OVERLOAD(_arg_var, __VA_ARGS__) - -#define _arg_ref1(a1) \ - a1##_ref(1) -#define _arg_ref2(a1, a2) \ - _arg_ref1(a1), a2##_ref(2) -#define _arg_ref3(a1, a2, a3) \ - _arg_ref2(a1, a2), a3##_ref(3) -#define _arg_ref4(a1, a2, a3, a4) \ - _arg_ref3(a1, a2, a3), a4##_ref(4) -#define _arg_ref5(a1, a2, a3, a4, a5) \ - _arg_ref4(a1, a2, a3, a4), a5##_ref(5) -#define _arg_ref6(a1, a2, a3, a4, a5, a6) \ - _arg_ref5(a1, a2, a3, a4, a5), a6##_ref(6) -#define _arg_ref7(a1, a2, a3, a4, a5, a6, a7) \ - _arg_ref6(a1, a2, a3, a4, a5, a6), a7##_ref(7) + _arg_var10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), a11##_var(11) +#define arg_var(...) VA_NARGS_CALL_OVERLOAD(_arg_var, __VA_ARGS__) + +#define _arg_ref1(a1) a1##_ref(1) +#define _arg_ref2(a1, a2) _arg_ref1(a1), a2##_ref(2) +#define _arg_ref3(a1, a2, a3) _arg_ref2(a1, a2), a3##_ref(3) +#define _arg_ref4(a1, a2, a3, a4) _arg_ref3(a1, a2, a3), a4##_ref(4) +#define _arg_ref5(a1, a2, a3, a4, a5) _arg_ref4(a1, a2, a3, a4), a5##_ref(5) +#define _arg_ref6(a1, a2, a3, a4, a5, a6) _arg_ref5(a1, a2, a3, a4, a5), a6##_ref(6) +#define _arg_ref7(a1, a2, a3, a4, a5, a6, a7) _arg_ref6(a1, a2, a3, a4, a5, a6), a7##_ref(7) #define _arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8) \ - _arg_ref7(a1, a2, a3, a4, a5, a6, a7), a8##_ref(8) + _arg_ref7(a1, a2, a3, a4, a5, a6, a7), a8##_ref(8) #define _arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \ - _arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_ref(9) + _arg_ref8(a1, a2, a3, a4, a5, a6, a7, a8), a9##_ref(9) #define _arg_ref10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \ - _arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_ref(10) + _arg_ref9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10##_ref(10) #define _arg_ref11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \ - _arg_ref10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), a11##_ref(11) -#define arg_ref(...) VA_NARGS_CALL_OVERLOAD(_arg_ref, __VA_ARGS__) - -#define _arg_str1(a1) \ - a1##_str -#define _arg_str2(a1, a2) \ - _arg_str1(a1) a2##_str -#define _arg_str3(a1, a2, a3) \ - _arg_str2(a1, a2) a3##_str -#define _arg_str4(a1, a2, a3, a4) \ - _arg_str3(a1, a2, a3) a4##_str -#define _arg_str5(a1, a2, a3, a4, a5) \ - _arg_str4(a1, a2, a3, a4) a5##_str -#define _arg_str6(a1, a2, a3, a4, a5, a6) \ - _arg_str5(a1, a2, a3, a4, a5) a6##_str -#define _arg_str7(a1, a2, a3, a4, a5, a6, a7) \ - _arg_str6(a1, a2, a3, a4, a5, a6) a7##_str -#define _arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) \ - _arg_str7(a1, a2, a3, a4, a5, a6, a7) a8##_str + _arg_ref10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), a11##_ref(11) +#define arg_ref(...) VA_NARGS_CALL_OVERLOAD(_arg_ref, __VA_ARGS__) + +#define _arg_str1(a1) a1##_str +#define _arg_str2(a1, a2) _arg_str1(a1) a2##_str +#define _arg_str3(a1, a2, a3) _arg_str2(a1, a2) a3##_str +#define _arg_str4(a1, a2, a3, a4) _arg_str3(a1, a2, a3) a4##_str +#define _arg_str5(a1, a2, a3, a4, a5) _arg_str4(a1, a2, a3, a4) a5##_str +#define _arg_str6(a1, a2, a3, a4, a5, a6) _arg_str5(a1, a2, a3, a4, a5) a6##_str +#define _arg_str7(a1, a2, a3, a4, a5, a6, a7) _arg_str6(a1, a2, a3, a4, a5, a6) a7##_str +#define _arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) _arg_str7(a1, a2, a3, a4, a5, a6, a7) a8##_str #define _arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \ - _arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) a9##_str + _arg_str8(a1, a2, a3, a4, a5, a6, a7, a8) a9##_str #define _arg_str10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \ - _arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9) a10##_str + _arg_str9(a1, a2, a3, a4, a5, a6, a7, a8, a9) a10##_str #define _arg_str11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \ - _arg_str10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) a11##_str -#define arg_str(...) VA_NARGS_CALL_OVERLOAD(_arg_str, __VA_ARGS__) + _arg_str10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) a11##_str +#define arg_str(...) VA_NARGS_CALL_OVERLOAD(_arg_str, __VA_ARGS__) #define ret_def_void #define ret_set_void -#define ret_ret_void return Py_INCREF(Py_None), Py_None +#define ret_ret_void return Py_INCREF(Py_None), Py_None -#define ret_def_GLint int ret_int -#define ret_set_GLint ret_int = -#define ret_ret_GLint return PyLong_FromLong(ret_int) +#define ret_def_GLint int ret_int +#define ret_set_GLint ret_int = +#define ret_ret_GLint return PyLong_FromLong(ret_int) -#define ret_def_GLuint unsigned int ret_uint -#define ret_set_GLuint ret_uint = -#define ret_ret_GLuint return PyLong_FromLong((long) ret_uint) +#define ret_def_GLuint unsigned int ret_uint +#define ret_set_GLuint ret_uint = +#define ret_ret_GLuint return PyLong_FromLong((long)ret_uint) #if 0 -#define ret_def_GLsizei size_t ret_size_t -#define ret_set_GLsizei ret_size_t = -#define ret_ret_GLsizei return PyLong_FromSsize_t(ret_size_t) +# define ret_def_GLsizei size_t ret_size_t +# define ret_set_GLsizei ret_size_t = +# define ret_ret_GLsizei return PyLong_FromSsize_t(ret_size_t) #endif #if 0 -#define ret_def_GLsync unsigned int ret_sync -#define ret_set_GLsync ret_sync = -#define ret_ret_GLsync return PyLong_FromLong((long) ret_sync) +# define ret_def_GLsync unsigned int ret_sync +# define ret_set_GLsync ret_sync = +# define ret_ret_GLsync return PyLong_FromLong((long)ret_sync) #endif -#define ret_def_GLenum unsigned int ret_uint -#define ret_set_GLenum ret_uint = -#define ret_ret_GLenum return PyLong_FromLong((long) ret_uint) +#define ret_def_GLenum unsigned int ret_uint +#define ret_set_GLenum ret_uint = +#define ret_ret_GLenum return PyLong_FromLong((long)ret_uint) #define ret_def_GLboolean unsigned char ret_bool #define ret_set_GLboolean ret_bool = -#define ret_ret_GLboolean return PyLong_FromLong((long) ret_bool) +#define ret_ret_GLboolean return PyLong_FromLong((long)ret_bool) -#define ret_def_GLstring const unsigned char *ret_str -#define ret_set_GLstring ret_str = +#define ret_def_GLstring const unsigned char *ret_str +#define ret_set_GLstring ret_str = -#define ret_ret_GLstring \ - if (ret_str) { \ - return PyUnicode_FromString((const char *)ret_str); \ - } \ - else { \ - PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \ - return NULL; \ - } \ +#define ret_ret_GLstring \ + if (ret_str) { \ + return PyUnicode_FromString((const char *)ret_str); \ + } \ + else { \ + PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \ + return NULL; \ + } /** \} */ - /* -------------------------------------------------------------------- */ /* Forward Declarations */ @@ -447,94 +431,88 @@ static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq); static PyObject *Buffer_subscript(Buffer *self, PyObject *item); static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value); - /* -------------------------------------------------------------------- */ /** \name Utility Functions * \{ */ - int BGL_typeSize(int type) { - switch (type) { - case GL_BYTE: - return sizeof(char); - case GL_SHORT: - return sizeof(short); - case GL_INT: - return sizeof(int); - case GL_FLOAT: - return sizeof(float); - case GL_DOUBLE: - return sizeof(double); - } - return -1; + switch (type) { + case GL_BYTE: + return sizeof(char); + case GL_SHORT: + return sizeof(short); + case GL_INT: + return sizeof(int); + case GL_FLOAT: + return sizeof(float); + case GL_DOUBLE: + return sizeof(double); + } + return -1; } static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer) { - const char format = PyC_StructFmt_type_from_str(pybuffer->format); - Py_ssize_t itemsize = pybuffer->itemsize; - - if (PyC_StructFmt_type_is_float_any(format)) { - if (itemsize == 4) { - return GL_FLOAT; - } - if (itemsize == 8) { - return GL_DOUBLE; - } - } - if (PyC_StructFmt_type_is_byte(format) || - PyC_StructFmt_type_is_int_any(format)) - { - if (itemsize == 1) { - return GL_BYTE; - } - if (itemsize == 2) { - return GL_SHORT; - } - if (itemsize == 4) { - return GL_INT; - } - } - - return -1; /* UNKNOWN */ + const char format = PyC_StructFmt_type_from_str(pybuffer->format); + Py_ssize_t itemsize = pybuffer->itemsize; + + if (PyC_StructFmt_type_is_float_any(format)) { + if (itemsize == 4) { + return GL_FLOAT; + } + if (itemsize == 8) { + return GL_DOUBLE; + } + } + if (PyC_StructFmt_type_is_byte(format) || PyC_StructFmt_type_is_int_any(format)) { + if (itemsize == 1) { + return GL_BYTE; + } + if (itemsize == 2) { + return GL_SHORT; + } + if (itemsize == 4) { + return GL_INT; + } + } + + return -1; /* UNKNOWN */ } static bool compare_dimensions(int ndim, int *dim1, Py_ssize_t *dim2) { - for (int i = 0; i < ndim; i++) { - if (dim1[i] != dim2[i]) { - return false; - } - } - return true; + for (int i = 0; i < ndim; i++) { + if (dim1[i] != dim2[i]) { + return false; + } + } + return true; } /** \} */ - /* -------------------------------------------------------------------- */ /** \name Buffer API * \{ */ static PySequenceMethods Buffer_SeqMethods = { - (lenfunc) Buffer_len, /*sq_length */ - (binaryfunc) NULL, /*sq_concat */ - (ssizeargfunc) NULL, /*sq_repeat */ - (ssizeargfunc) Buffer_item, /*sq_item */ - (ssizessizeargfunc) NULL, /*sq_slice, deprecated, handled in Buffer_item */ - (ssizeobjargproc) Buffer_ass_item, /*sq_ass_item */ - (ssizessizeobjargproc) NULL, /*sq_ass_slice, deprecated handled in Buffer_ass_item */ - (objobjproc) NULL, /* sq_contains */ - (binaryfunc) NULL, /* sq_inplace_concat */ - (ssizeargfunc) NULL, /* sq_inplace_repeat */ + (lenfunc)Buffer_len, /*sq_length */ + (binaryfunc)NULL, /*sq_concat */ + (ssizeargfunc)NULL, /*sq_repeat */ + (ssizeargfunc)Buffer_item, /*sq_item */ + (ssizessizeargfunc)NULL, /*sq_slice, deprecated, handled in Buffer_item */ + (ssizeobjargproc)Buffer_ass_item, /*sq_ass_item */ + (ssizessizeobjargproc)NULL, /*sq_ass_slice, deprecated handled in Buffer_ass_item */ + (objobjproc)NULL, /* sq_contains */ + (binaryfunc)NULL, /* sq_inplace_concat */ + (ssizeargfunc)NULL, /* sq_inplace_repeat */ }; - static PyMappingMethods Buffer_AsMapping = { - (lenfunc)Buffer_len, - (binaryfunc)Buffer_subscript, - (objobjargproc)Buffer_ass_subscript, + (lenfunc)Buffer_len, + (binaryfunc)Buffer_subscript, + (objobjargproc)Buffer_ass_subscript, }; static void Buffer_dealloc(Buffer *self); @@ -542,145 +520,142 @@ static PyObject *Buffer_repr(Buffer *self); static PyObject *Buffer_to_list(Buffer *self) { - int i, len = self->dimensions[0]; - PyObject *list = PyList_New(len); + int i, len = self->dimensions[0]; + PyObject *list = PyList_New(len); - for (i = 0; i < len; i++) { - PyList_SET_ITEM(list, i, Buffer_item(self, i)); - } + for (i = 0; i < len; i++) { + PyList_SET_ITEM(list, i, Buffer_item(self, i)); + } - return list; + return list; } static PyObject *Buffer_to_list_recursive(Buffer *self) { - PyObject *list; - - if (self->ndimensions > 1) { - int i, len = self->dimensions[0]; - list = PyList_New(len); - - for (i = 0; i < len; i++) { - Buffer *sub = (Buffer *)Buffer_item(self, i); - PyList_SET_ITEM(list, i, Buffer_to_list_recursive(sub)); - Py_DECREF(sub); - } - } - else { - list = Buffer_to_list(self); - } - - return list; + PyObject *list; + + if (self->ndimensions > 1) { + int i, len = self->dimensions[0]; + list = PyList_New(len); + + for (i = 0; i < len; i++) { + Buffer *sub = (Buffer *)Buffer_item(self, i); + PyList_SET_ITEM(list, i, Buffer_to_list_recursive(sub)); + Py_DECREF(sub); + } + } + else { + list = Buffer_to_list(self); + } + + return list; } static PyObject *Buffer_dimensions(Buffer *self, void *UNUSED(arg)) { - PyObject *list = PyList_New(self->ndimensions); - int i; + PyObject *list = PyList_New(self->ndimensions); + int i; - for (i = 0; i < self->ndimensions; i++) { - PyList_SET_ITEM(list, i, PyLong_FromLong(self->dimensions[i])); - } + for (i = 0; i < self->ndimensions; i++) { + PyList_SET_ITEM(list, i, PyLong_FromLong(self->dimensions[i])); + } - return list; + return list; } static PyMethodDef Buffer_methods[] = { - {"to_list", (PyCFunction)Buffer_to_list_recursive, METH_NOARGS, - "return the buffer as a list"}, - {NULL, NULL, 0, NULL}, + {"to_list", (PyCFunction)Buffer_to_list_recursive, METH_NOARGS, "return the buffer as a list"}, + {NULL, NULL, 0, NULL}, }; static PyGetSetDef Buffer_getseters[] = { - {(char *)"dimensions", (getter)Buffer_dimensions, NULL, NULL, NULL}, - {NULL, NULL, NULL, NULL, NULL}, + {(char *)"dimensions", (getter)Buffer_dimensions, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL}, }; - PyTypeObject BGL_bufferType = { - PyVarObject_HEAD_INIT(NULL, 0) - "bgl.Buffer", /*tp_name */ - sizeof(Buffer), /*tp_basicsize */ - 0, /*tp_itemsize */ - (destructor)Buffer_dealloc, /*tp_dealloc */ - (printfunc)NULL, /*tp_print */ - NULL, /*tp_getattr */ - NULL, /*tp_setattr */ - NULL, /*tp_compare */ - (reprfunc) Buffer_repr, /*tp_repr */ - NULL, /*tp_as_number */ - &Buffer_SeqMethods, /*tp_as_sequence */ - &Buffer_AsMapping, /* PyMappingMethods *tp_as_mapping; */ - - /* More standard operations (here for binary compatibility) */ - - NULL, /* hashfunc tp_hash; */ - NULL, /* ternaryfunc tp_call; */ - NULL, /* reprfunc tp_str; */ - NULL, /* getattrofunc tp_getattro; */ - NULL, /* setattrofunc tp_setattro; */ - - /* Functions to access object as input/output buffer */ - NULL, /* PyBufferProcs *tp_as_buffer; */ - - /*** Flags to define presence of optional/expanded features ***/ - Py_TPFLAGS_DEFAULT, /* long tp_flags; */ - - NULL, /* char *tp_doc; Documentation string */ - /*** Assigned meaning in release 2.0 ***/ - /* call function for all accessible objects */ - NULL, /* traverseproc tp_traverse; */ - - /* delete references to contained objects */ - NULL, /* inquiry tp_clear; */ - - /*** Assigned meaning in release 2.1 ***/ - /*** rich comparisons ***/ - NULL, /* richcmpfunc tp_richcompare; */ - - /*** weak reference enabler ***/ - 0, /* long tp_weaklistoffset; */ - - /*** Added in release 2.2 ***/ - /* Iterators */ - NULL, /* getiterfunc tp_iter; */ - NULL, /* iternextfunc tp_iternext; */ - /*** Attribute descriptor and subclassing stuff ***/ - Buffer_methods, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - Buffer_getseters, /* struct PyGetSetDef *tp_getset; */ - NULL, /*tp_base*/ - NULL, /*tp_dict*/ - NULL, /*tp_descr_get*/ - NULL, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - NULL, /*tp_init*/ - NULL, /*tp_alloc*/ - Buffer_new, /*tp_new*/ - NULL, /*tp_free*/ - NULL, /*tp_is_gc*/ - NULL, /*tp_bases*/ - NULL, /*tp_mro*/ - NULL, /*tp_cache*/ - NULL, /*tp_subclasses*/ - NULL, /*tp_weaklist*/ - NULL, /*tp_del*/ + PyVarObject_HEAD_INIT(NULL, 0) "bgl.Buffer", /*tp_name */ + sizeof(Buffer), /*tp_basicsize */ + 0, /*tp_itemsize */ + (destructor)Buffer_dealloc, /*tp_dealloc */ + (printfunc)NULL, /*tp_print */ + NULL, /*tp_getattr */ + NULL, /*tp_setattr */ + NULL, /*tp_compare */ + (reprfunc)Buffer_repr, /*tp_repr */ + NULL, /*tp_as_number */ + &Buffer_SeqMethods, /*tp_as_sequence */ + &Buffer_AsMapping, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + NULL, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + /*** Attribute descriptor and subclassing stuff ***/ + Buffer_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + Buffer_getseters, /* struct PyGetSetDef *tp_getset; */ + NULL, /*tp_base*/ + NULL, /*tp_dict*/ + NULL, /*tp_descr_get*/ + NULL, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + NULL, /*tp_init*/ + NULL, /*tp_alloc*/ + Buffer_new, /*tp_new*/ + NULL, /*tp_free*/ + NULL, /*tp_is_gc*/ + NULL, /*tp_bases*/ + NULL, /*tp_mro*/ + NULL, /*tp_cache*/ + NULL, /*tp_subclasses*/ + NULL, /*tp_weaklist*/ + NULL, /*tp_del*/ }; - -static Buffer *BGL_MakeBuffer_FromData(PyObject *parent, int type, int ndimensions, int *dimensions, void *buf) +static Buffer *BGL_MakeBuffer_FromData( + PyObject *parent, int type, int ndimensions, int *dimensions, void *buf) { - Buffer *buffer = (Buffer *)PyObject_NEW(Buffer, &BGL_bufferType); + Buffer *buffer = (Buffer *)PyObject_NEW(Buffer, &BGL_bufferType); - Py_XINCREF(parent); - buffer->parent = parent; - buffer->ndimensions = ndimensions; - buffer->dimensions = MEM_mallocN(ndimensions * sizeof(int), "Buffer dimensions"); - memcpy(buffer->dimensions, dimensions, ndimensions * sizeof(int)); - buffer->type = type; - buffer->buf.asvoid = buf; + Py_XINCREF(parent); + buffer->parent = parent; + buffer->ndimensions = ndimensions; + buffer->dimensions = MEM_mallocN(ndimensions * sizeof(int), "Buffer dimensions"); + memcpy(buffer->dimensions, dimensions, ndimensions * sizeof(int)); + buffer->type = type; + buffer->buf.asvoid = buf; - return buffer; + return buffer; } /** @@ -692,741 +667,771 @@ static Buffer *BGL_MakeBuffer_FromData(PyObject *parent, int type, int ndimensio */ Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuffer) { - Buffer *buffer; - void *buf = NULL; - int i, size = BGL_typeSize(type); + Buffer *buffer; + void *buf = NULL; + int i, size = BGL_typeSize(type); - for (i = 0; i < ndimensions; i++) { - size *= dimensions[i]; - } + for (i = 0; i < ndimensions; i++) { + size *= dimensions[i]; + } - buf = MEM_mallocN(size, "Buffer buffer"); + buf = MEM_mallocN(size, "Buffer buffer"); - buffer = BGL_MakeBuffer_FromData(NULL, type, ndimensions, dimensions, buf); + buffer = BGL_MakeBuffer_FromData(NULL, type, ndimensions, dimensions, buf); - if (initbuffer) { - memcpy(buffer->buf.asvoid, initbuffer, size); - } - else { - memset(buffer->buf.asvoid, 0, size); - } - return buffer; + if (initbuffer) { + memcpy(buffer->buf.asvoid, initbuffer, size); + } + else { + memset(buffer->buf.asvoid, 0, size); + } + return buffer; } /* Custom converter function so we can support a buffer or NULL. */ static int BGL_BufferOrNoneConverter(PyObject *object, Buffer **buffer) { - if (object == Py_None) { - *buffer = NULL; - return 1; - } - else if (PyObject_TypeCheck(object, &BGL_bufferType)) { - *buffer = (Buffer *)object; - return 1; - } - else { - PyErr_SetString(PyExc_TypeError, "expected a bgl.Buffer or None"); - return 0; - } + if (object == Py_None) { + *buffer = NULL; + return 1; + } + else if (PyObject_TypeCheck(object, &BGL_bufferType)) { + *buffer = (Buffer *)object; + return 1; + } + else { + PyErr_SetString(PyExc_TypeError, "expected a bgl.Buffer or None"); + return 0; + } } -#define MAX_DIMENSIONS 256 +#define MAX_DIMENSIONS 256 static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) { - PyObject *length_ob = NULL, *init = NULL; - Buffer *buffer = NULL; - int dimensions[MAX_DIMENSIONS]; - - int type; - Py_ssize_t i, ndimensions = 0; - - if (kwds && PyDict_Size(kwds)) { - PyErr_SetString(PyExc_TypeError, - "bgl.Buffer(): takes no keyword args"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "iO|O: bgl.Buffer", &type, &length_ob, &init)) { - return NULL; - } - if (!ELEM(type, GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE)) { - PyErr_SetString(PyExc_AttributeError, - "invalid first argument type, should be one of " - "GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE"); - return NULL; - } - - if (PyLong_Check(length_ob)) { - ndimensions = 1; - if (((dimensions[0] = PyLong_AsLong(length_ob)) < 1)) { - PyErr_SetString(PyExc_AttributeError, - "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS)); - return NULL; - } - } - else if (PySequence_Check(length_ob)) { - ndimensions = PySequence_Size(length_ob); - if (ndimensions > MAX_DIMENSIONS) { - PyErr_SetString(PyExc_AttributeError, - "too many dimensions, max is "STRINGIFY(MAX_DIMENSIONS)); - return NULL; - } - else if (ndimensions < 1) { - PyErr_SetString(PyExc_AttributeError, - "sequence must have at least one dimension"); - return NULL; - } - for (i = 0; i < ndimensions; i++) { - PyObject *ob = PySequence_GetItem(length_ob, i); - - if (!PyLong_Check(ob)) { - dimensions[i] = 1; - } - else { - dimensions[i] = PyLong_AsLong(ob); - } - Py_DECREF(ob); - - if (dimensions[i] < 1) { - PyErr_SetString(PyExc_AttributeError, - "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS)); - return NULL; - } - } - } - else { - PyErr_Format(PyExc_TypeError, - "invalid second argument argument expected a sequence " - "or an int, not a %.200s", Py_TYPE(length_ob)->tp_name); - return NULL; - } - - if (init && PyObject_CheckBuffer(init)) { - Py_buffer pybuffer; - - if (PyObject_GetBuffer(init, &pybuffer, PyBUF_ND | PyBUF_FORMAT) == -1) { - /* PyObject_GetBuffer raise a PyExc_BufferError */ - return NULL; - } - - if (type != gl_buffer_type_from_py_buffer(&pybuffer)) { - PyErr_Format(PyExc_TypeError, - "`GL_TYPE` and `typestr` of object with buffer interface do not match. '%s'", pybuffer.format); - } - else if (ndimensions != pybuffer.ndim || - !compare_dimensions(ndimensions, dimensions, pybuffer.shape)) - { - PyErr_Format(PyExc_TypeError, "array size does not match"); - } - else { - buffer = BGL_MakeBuffer_FromData(init, type, pybuffer.ndim, dimensions, pybuffer.buf); - } - - PyBuffer_Release(&pybuffer); - } - else { - buffer = BGL_MakeBuffer(type, ndimensions, dimensions, NULL); - if (init && Buffer_ass_slice(buffer, 0, dimensions[0], init)) { - Py_DECREF(buffer); - return NULL; - } - } - - return (PyObject *)buffer; + PyObject *length_ob = NULL, *init = NULL; + Buffer *buffer = NULL; + int dimensions[MAX_DIMENSIONS]; + + int type; + Py_ssize_t i, ndimensions = 0; + + if (kwds && PyDict_Size(kwds)) { + PyErr_SetString(PyExc_TypeError, "bgl.Buffer(): takes no keyword args"); + return NULL; + } + + if (!PyArg_ParseTuple(args, "iO|O: bgl.Buffer", &type, &length_ob, &init)) { + return NULL; + } + if (!ELEM(type, GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE)) { + PyErr_SetString(PyExc_AttributeError, + "invalid first argument type, should be one of " + "GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE"); + return NULL; + } + + if (PyLong_Check(length_ob)) { + ndimensions = 1; + if (((dimensions[0] = PyLong_AsLong(length_ob)) < 1)) { + PyErr_SetString(PyExc_AttributeError, + "dimensions must be between 1 and " STRINGIFY(MAX_DIMENSIONS)); + return NULL; + } + } + else if (PySequence_Check(length_ob)) { + ndimensions = PySequence_Size(length_ob); + if (ndimensions > MAX_DIMENSIONS) { + PyErr_SetString(PyExc_AttributeError, + "too many dimensions, max is " STRINGIFY(MAX_DIMENSIONS)); + return NULL; + } + else if (ndimensions < 1) { + PyErr_SetString(PyExc_AttributeError, "sequence must have at least one dimension"); + return NULL; + } + for (i = 0; i < ndimensions; i++) { + PyObject *ob = PySequence_GetItem(length_ob, i); + + if (!PyLong_Check(ob)) { + dimensions[i] = 1; + } + else { + dimensions[i] = PyLong_AsLong(ob); + } + Py_DECREF(ob); + + if (dimensions[i] < 1) { + PyErr_SetString(PyExc_AttributeError, + "dimensions must be between 1 and " STRINGIFY(MAX_DIMENSIONS)); + return NULL; + } + } + } + else { + PyErr_Format(PyExc_TypeError, + "invalid second argument argument expected a sequence " + "or an int, not a %.200s", + Py_TYPE(length_ob)->tp_name); + return NULL; + } + + if (init && PyObject_CheckBuffer(init)) { + Py_buffer pybuffer; + + if (PyObject_GetBuffer(init, &pybuffer, PyBUF_ND | PyBUF_FORMAT) == -1) { + /* PyObject_GetBuffer raise a PyExc_BufferError */ + return NULL; + } + + if (type != gl_buffer_type_from_py_buffer(&pybuffer)) { + PyErr_Format(PyExc_TypeError, + "`GL_TYPE` and `typestr` of object with buffer interface do not match. '%s'", + pybuffer.format); + } + else if (ndimensions != pybuffer.ndim || + !compare_dimensions(ndimensions, dimensions, pybuffer.shape)) { + PyErr_Format(PyExc_TypeError, "array size does not match"); + } + else { + buffer = BGL_MakeBuffer_FromData(init, type, pybuffer.ndim, dimensions, pybuffer.buf); + } + + PyBuffer_Release(&pybuffer); + } + else { + buffer = BGL_MakeBuffer(type, ndimensions, dimensions, NULL); + if (init && Buffer_ass_slice(buffer, 0, dimensions[0], init)) { + Py_DECREF(buffer); + return NULL; + } + } + + return (PyObject *)buffer; } /* Buffer sequence methods */ static int Buffer_len(Buffer *self) { - return self->dimensions[0]; + return self->dimensions[0]; } static PyObject *Buffer_item(Buffer *self, int i) { - if (i >= self->dimensions[0] || i < 0) { - PyErr_SetString(PyExc_IndexError, "array index out of range"); - return NULL; - } - - if (self->ndimensions == 1) { - switch (self->type) { - case GL_BYTE: return Py_BuildValue("b", self->buf.asbyte[i]); - case GL_SHORT: return Py_BuildValue("h", self->buf.asshort[i]); - case GL_INT: return Py_BuildValue("i", self->buf.asint[i]); - case GL_FLOAT: return PyFloat_FromDouble(self->buf.asfloat[i]); - case GL_DOUBLE: return Py_BuildValue("d", self->buf.asdouble[i]); - } - } - else { - int j, offset = i * BGL_typeSize(self->type); - - for (j = 1; j < self->ndimensions; j++) { - offset *= self->dimensions[j]; - } - - return (PyObject *)BGL_MakeBuffer_FromData( - (PyObject *)self, self->type, - self->ndimensions - 1, - self->dimensions + 1, - self->buf.asbyte + offset); - } - - return NULL; + if (i >= self->dimensions[0] || i < 0) { + PyErr_SetString(PyExc_IndexError, "array index out of range"); + return NULL; + } + + if (self->ndimensions == 1) { + switch (self->type) { + case GL_BYTE: + return Py_BuildValue("b", self->buf.asbyte[i]); + case GL_SHORT: + return Py_BuildValue("h", self->buf.asshort[i]); + case GL_INT: + return Py_BuildValue("i", self->buf.asint[i]); + case GL_FLOAT: + return PyFloat_FromDouble(self->buf.asfloat[i]); + case GL_DOUBLE: + return Py_BuildValue("d", self->buf.asdouble[i]); + } + } + else { + int j, offset = i * BGL_typeSize(self->type); + + for (j = 1; j < self->ndimensions; j++) { + offset *= self->dimensions[j]; + } + + return (PyObject *)BGL_MakeBuffer_FromData((PyObject *)self, + self->type, + self->ndimensions - 1, + self->dimensions + 1, + self->buf.asbyte + offset); + } + + return NULL; } static PyObject *Buffer_slice(Buffer *self, int begin, int end) { - PyObject *list; - int count; - - if (begin < 0) { - begin = 0; - } - if (end > self->dimensions[0]) { - end = self->dimensions[0]; - } - if (begin > end) { - begin = end; - } - - list = PyList_New(end - begin); - - for (count = begin; count < end; count++) { - PyList_SET_ITEM(list, count - begin, Buffer_item(self, count)); - } - return list; + PyObject *list; + int count; + + if (begin < 0) { + begin = 0; + } + if (end > self->dimensions[0]) { + end = self->dimensions[0]; + } + if (begin > end) { + begin = end; + } + + list = PyList_New(end - begin); + + for (count = begin; count < end; count++) { + PyList_SET_ITEM(list, count - begin, Buffer_item(self, count)); + } + return list; } static int Buffer_ass_item(Buffer *self, int i, PyObject *v) { - if (i >= self->dimensions[0] || i < 0) { - PyErr_SetString(PyExc_IndexError, - "array assignment index out of range"); - return -1; - } - - if (self->ndimensions != 1) { - Buffer *row = (Buffer *)Buffer_item(self, i); - - if (row) { - int ret = Buffer_ass_slice(row, 0, self->dimensions[1], v); - Py_DECREF(row); - return ret; - } - else { - return -1; - } - } - - switch (self->type) { - case GL_BYTE: return PyArg_Parse(v, "b:Expected ints", &self->buf.asbyte[i]) ? 0 : -1; - case GL_SHORT: return PyArg_Parse(v, "h:Expected ints", &self->buf.asshort[i]) ? 0 : -1; - case GL_INT: return PyArg_Parse(v, "i:Expected ints", &self->buf.asint[i]) ? 0 : -1; - case GL_FLOAT: return PyArg_Parse(v, "f:Expected floats", &self->buf.asfloat[i]) ? 0 : -1; - case GL_DOUBLE: return PyArg_Parse(v, "d:Expected floats", &self->buf.asdouble[i]) ? 0 : -1; - default: return 0; /* should never happen */ - } + if (i >= self->dimensions[0] || i < 0) { + PyErr_SetString(PyExc_IndexError, "array assignment index out of range"); + return -1; + } + + if (self->ndimensions != 1) { + Buffer *row = (Buffer *)Buffer_item(self, i); + + if (row) { + int ret = Buffer_ass_slice(row, 0, self->dimensions[1], v); + Py_DECREF(row); + return ret; + } + else { + return -1; + } + } + + switch (self->type) { + case GL_BYTE: + return PyArg_Parse(v, "b:Expected ints", &self->buf.asbyte[i]) ? 0 : -1; + case GL_SHORT: + return PyArg_Parse(v, "h:Expected ints", &self->buf.asshort[i]) ? 0 : -1; + case GL_INT: + return PyArg_Parse(v, "i:Expected ints", &self->buf.asint[i]) ? 0 : -1; + case GL_FLOAT: + return PyArg_Parse(v, "f:Expected floats", &self->buf.asfloat[i]) ? 0 : -1; + case GL_DOUBLE: + return PyArg_Parse(v, "d:Expected floats", &self->buf.asdouble[i]) ? 0 : -1; + default: + return 0; /* should never happen */ + } } static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq) { - PyObject *item; - int count, err = 0; - - if (begin < 0) { - begin = 0; - } - if (end > self->dimensions[0]) { - end = self->dimensions[0]; - } - if (begin > end) { - begin = end; - } - - if (!PySequence_Check(seq)) { - PyErr_Format(PyExc_TypeError, - "buffer[:] = value, invalid assignment. " - "Expected a sequence, not an %.200s type", - Py_TYPE(seq)->tp_name); - return -1; - } - - /* re-use count var */ - if ((count = PySequence_Size(seq)) != (end - begin)) { - PyErr_Format(PyExc_TypeError, - "buffer[:] = value, size mismatch in assignment. " - "Expected: %d (given: %d)", count, end - begin); - return -1; - } - - for (count = begin; count < end; count++) { - item = PySequence_GetItem(seq, count - begin); - if (item) { - err = Buffer_ass_item(self, count, item); - Py_DECREF(item); - } - else { - err = -1; - } - if (err) { - break; - } - } - return err; + PyObject *item; + int count, err = 0; + + if (begin < 0) { + begin = 0; + } + if (end > self->dimensions[0]) { + end = self->dimensions[0]; + } + if (begin > end) { + begin = end; + } + + if (!PySequence_Check(seq)) { + PyErr_Format(PyExc_TypeError, + "buffer[:] = value, invalid assignment. " + "Expected a sequence, not an %.200s type", + Py_TYPE(seq)->tp_name); + return -1; + } + + /* re-use count var */ + if ((count = PySequence_Size(seq)) != (end - begin)) { + PyErr_Format(PyExc_TypeError, + "buffer[:] = value, size mismatch in assignment. " + "Expected: %d (given: %d)", + count, + end - begin); + return -1; + } + + for (count = begin; count < end; count++) { + item = PySequence_GetItem(seq, count - begin); + if (item) { + err = Buffer_ass_item(self, count, item); + Py_DECREF(item); + } + else { + err = -1; + } + if (err) { + break; + } + } + return err; } static PyObject *Buffer_subscript(Buffer *self, PyObject *item) { - if (PyIndex_Check(item)) { - Py_ssize_t i; - i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) { - return NULL; - } - if (i < 0) { - i += self->dimensions[0]; - } - return Buffer_item(self, i); - } - else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength; - - if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { - return NULL; - } - - if (slicelength <= 0) { - return PyTuple_New(0); - } - else if (step == 1) { - return Buffer_slice(self, start, stop); - } - else { - PyErr_SetString(PyExc_IndexError, - "slice steps not supported with vectors"); - return NULL; - } - } - else { - PyErr_Format(PyExc_TypeError, - "buffer indices must be integers, not %.200s", - Py_TYPE(item)->tp_name); - return NULL; - } + if (PyIndex_Check(item)) { + Py_ssize_t i; + i = PyNumber_AsSsize_t(item, PyExc_IndexError); + if (i == -1 && PyErr_Occurred()) { + return NULL; + } + if (i < 0) { + i += self->dimensions[0]; + } + return Buffer_item(self, i); + } + else if (PySlice_Check(item)) { + Py_ssize_t start, stop, step, slicelength; + + if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { + return NULL; + } + + if (slicelength <= 0) { + return PyTuple_New(0); + } + else if (step == 1) { + return Buffer_slice(self, start, stop); + } + else { + PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); + return NULL; + } + } + else { + PyErr_Format( + PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; + } } static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value) { - if (PyIndex_Check(item)) { - Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) { - return -1; - } - if (i < 0) { - i += self->dimensions[0]; - } - return Buffer_ass_item(self, i, value); - } - else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength; - - if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { - return -1; - } - - if (step == 1) { - return Buffer_ass_slice(self, start, stop, value); - } - else { - PyErr_SetString(PyExc_IndexError, - "slice steps not supported with vectors"); - return -1; - } - } - else { - PyErr_Format(PyExc_TypeError, - "buffer indices must be integers, not %.200s", - Py_TYPE(item)->tp_name); - return -1; - } + if (PyIndex_Check(item)) { + Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); + if (i == -1 && PyErr_Occurred()) { + return -1; + } + if (i < 0) { + i += self->dimensions[0]; + } + return Buffer_ass_item(self, i, value); + } + else if (PySlice_Check(item)) { + Py_ssize_t start, stop, step, slicelength; + + if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { + return -1; + } + + if (step == 1) { + return Buffer_ass_slice(self, start, stop, value); + } + else { + PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); + return -1; + } + } + else { + PyErr_Format( + PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; + } } - static void Buffer_dealloc(Buffer *self) { - if (self->parent) { - Py_DECREF(self->parent); - } - else { - MEM_freeN(self->buf.asvoid); - } + if (self->parent) { + Py_DECREF(self->parent); + } + else { + MEM_freeN(self->buf.asvoid); + } - MEM_freeN(self->dimensions); + MEM_freeN(self->dimensions); - PyObject_DEL(self); + PyObject_DEL(self); } - static PyObject *Buffer_repr(Buffer *self) { - PyObject *list = Buffer_to_list_recursive(self); - PyObject *repr; - const char *typestr; - - switch (self->type) { - case GL_BYTE: typestr = "GL_BYTE"; break; - case GL_SHORT: typestr = "GL_SHORT"; break; - case GL_INT: typestr = "GL_INT"; break; - case GL_FLOAT: typestr = "GL_FLOAT"; break; - case GL_DOUBLE: typestr = "GL_DOUBLE"; break; - default: typestr = "UNKNOWN"; break; - } - - repr = PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list); - Py_DECREF(list); - - return repr; + PyObject *list = Buffer_to_list_recursive(self); + PyObject *repr; + const char *typestr; + + switch (self->type) { + case GL_BYTE: + typestr = "GL_BYTE"; + break; + case GL_SHORT: + typestr = "GL_SHORT"; + break; + case GL_INT: + typestr = "GL_INT"; + break; + case GL_FLOAT: + typestr = "GL_FLOAT"; + break; + case GL_DOUBLE: + typestr = "GL_DOUBLE"; + break; + default: + typestr = "UNKNOWN"; + break; + } + + repr = PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list); + Py_DECREF(list); + + return repr; } /** \} */ - /* -------------------------------------------------------------------- */ /** \name OpenGL API Wrapping * \{ */ -#define BGL_Wrap(funcname, ret, arg_list) \ -static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \ -{ \ - arg_def arg_list; \ - ret_def_##ret; \ - if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) { \ - return NULL; \ - } \ - ret_set_##ret gl##funcname (arg_var arg_list); \ - ret_ret_##ret; \ -} +#define BGL_Wrap(funcname, ret, arg_list) \ + static PyObject *Method_##funcname(PyObject *UNUSED(self), PyObject *args) \ + { \ + arg_def arg_list; \ + ret_def_##ret; \ + if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) { \ + return NULL; \ + } \ + ret_set_##ret gl##funcname(arg_var arg_list); \ + ret_ret_##ret; \ + } /* GL_VERSION_1_0 */ -BGL_Wrap(BlendFunc, void, (GLenum, GLenum)); -BGL_Wrap(Clear, void, (GLbitfield)); -BGL_Wrap(ClearColor, void, (GLfloat, GLfloat, GLfloat, GLfloat)); -BGL_Wrap(ClearDepth, void, (GLdouble)); -BGL_Wrap(ClearStencil, void, (GLint)); -BGL_Wrap(ColorMask, void, (GLboolean, GLboolean, GLboolean, GLboolean)); -BGL_Wrap(CullFace, void, (GLenum)); -BGL_Wrap(DepthFunc, void, (GLenum)); -BGL_Wrap(DepthMask, void, (GLboolean)); -BGL_Wrap(DepthRange, void, (GLdouble, GLdouble)); -BGL_Wrap(Disable, void, (GLenum)); -BGL_Wrap(DrawBuffer, void, (GLenum)); -BGL_Wrap(Enable, void, (GLenum)); -BGL_Wrap(Finish, void, (void)); -BGL_Wrap(Flush, void, (void)); -BGL_Wrap(FrontFace, void, (GLenum)); -BGL_Wrap(GetBooleanv, void, (GLenum, GLbooleanP)); -BGL_Wrap(GetDoublev, void, (GLenum, GLdoubleP)); -BGL_Wrap(GetError, GLenum, (void)); -BGL_Wrap(GetFloatv, void, (GLenum, GLfloatP)); -BGL_Wrap(GetIntegerv, void, (GLenum, GLintP)); -BGL_Wrap(GetString, GLstring, (GLenum)); -BGL_Wrap(GetTexImage, void, (GLenum, GLint, GLenum, GLenum, GLvoidP)); -BGL_Wrap(GetTexLevelParameterfv, void, (GLenum, GLint, GLenum, GLfloatP)); -BGL_Wrap(GetTexLevelParameteriv, void, (GLenum, GLint, GLenum, GLintP)); -BGL_Wrap(GetTexParameterfv, void, (GLenum, GLenum, GLfloatP)); -BGL_Wrap(GetTexParameteriv, void, (GLenum, GLenum, GLintP)); -BGL_Wrap(Hint, void, (GLenum, GLenum)); -BGL_Wrap(IsEnabled, GLboolean, (GLenum)); -BGL_Wrap(LineWidth, void, (GLfloat)); -BGL_Wrap(LogicOp, void, (GLenum)); -BGL_Wrap(PixelStoref, void, (GLenum, GLfloat)); -BGL_Wrap(PixelStorei, void, (GLenum, GLint)); -BGL_Wrap(PointSize, void, (GLfloat)); -BGL_Wrap(PolygonMode, void, (GLenum, GLenum)); -BGL_Wrap(ReadBuffer, void, (GLenum)); -BGL_Wrap(ReadPixels, void, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)); -BGL_Wrap(Scissor, void, (GLint, GLint, GLsizei, GLsizei)); -BGL_Wrap(StencilFunc, void, (GLenum, GLint, GLuint)); -BGL_Wrap(StencilMask, void, (GLuint)); -BGL_Wrap(StencilOp, void, (GLenum, GLenum, GLenum)); -BGL_Wrap(TexImage1D, void, (GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, GLvoidP)); -BGL_Wrap(TexImage2D, void, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP)); -BGL_Wrap(TexParameterf, void, (GLenum, GLenum, GLfloat)); -BGL_Wrap(TexParameterfv, void, (GLenum, GLenum, GLfloatP)); -BGL_Wrap(TexParameteri, void, (GLenum, GLenum, GLint)); -BGL_Wrap(TexParameteriv, void, (GLenum, GLenum, GLintP)); -BGL_Wrap(Viewport, void, (GLint, GLint, GLsizei, GLsizei)); - +BGL_Wrap(BlendFunc, void, (GLenum, GLenum)); +BGL_Wrap(Clear, void, (GLbitfield)); +BGL_Wrap(ClearColor, void, (GLfloat, GLfloat, GLfloat, GLfloat)); +BGL_Wrap(ClearDepth, void, (GLdouble)); +BGL_Wrap(ClearStencil, void, (GLint)); +BGL_Wrap(ColorMask, void, (GLboolean, GLboolean, GLboolean, GLboolean)); +BGL_Wrap(CullFace, void, (GLenum)); +BGL_Wrap(DepthFunc, void, (GLenum)); +BGL_Wrap(DepthMask, void, (GLboolean)); +BGL_Wrap(DepthRange, void, (GLdouble, GLdouble)); +BGL_Wrap(Disable, void, (GLenum)); +BGL_Wrap(DrawBuffer, void, (GLenum)); +BGL_Wrap(Enable, void, (GLenum)); +BGL_Wrap(Finish, void, (void)); +BGL_Wrap(Flush, void, (void)); +BGL_Wrap(FrontFace, void, (GLenum)); +BGL_Wrap(GetBooleanv, void, (GLenum, GLbooleanP)); +BGL_Wrap(GetDoublev, void, (GLenum, GLdoubleP)); +BGL_Wrap(GetError, GLenum, (void)); +BGL_Wrap(GetFloatv, void, (GLenum, GLfloatP)); +BGL_Wrap(GetIntegerv, void, (GLenum, GLintP)); +BGL_Wrap(GetString, GLstring, (GLenum)); +BGL_Wrap(GetTexImage, void, (GLenum, GLint, GLenum, GLenum, GLvoidP)); +BGL_Wrap(GetTexLevelParameterfv, void, (GLenum, GLint, GLenum, GLfloatP)); +BGL_Wrap(GetTexLevelParameteriv, void, (GLenum, GLint, GLenum, GLintP)); +BGL_Wrap(GetTexParameterfv, void, (GLenum, GLenum, GLfloatP)); +BGL_Wrap(GetTexParameteriv, void, (GLenum, GLenum, GLintP)); +BGL_Wrap(Hint, void, (GLenum, GLenum)); +BGL_Wrap(IsEnabled, GLboolean, (GLenum)); +BGL_Wrap(LineWidth, void, (GLfloat)); +BGL_Wrap(LogicOp, void, (GLenum)); +BGL_Wrap(PixelStoref, void, (GLenum, GLfloat)); +BGL_Wrap(PixelStorei, void, (GLenum, GLint)); +BGL_Wrap(PointSize, void, (GLfloat)); +BGL_Wrap(PolygonMode, void, (GLenum, GLenum)); +BGL_Wrap(ReadBuffer, void, (GLenum)); +BGL_Wrap(ReadPixels, void, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)); +BGL_Wrap(Scissor, void, (GLint, GLint, GLsizei, GLsizei)); +BGL_Wrap(StencilFunc, void, (GLenum, GLint, GLuint)); +BGL_Wrap(StencilMask, void, (GLuint)); +BGL_Wrap(StencilOp, void, (GLenum, GLenum, GLenum)); +BGL_Wrap(TexImage1D, void, (GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, GLvoidP)); +BGL_Wrap(TexImage2D, + void, + (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP)); +BGL_Wrap(TexParameterf, void, (GLenum, GLenum, GLfloat)); +BGL_Wrap(TexParameterfv, void, (GLenum, GLenum, GLfloatP)); +BGL_Wrap(TexParameteri, void, (GLenum, GLenum, GLint)); +BGL_Wrap(TexParameteriv, void, (GLenum, GLenum, GLintP)); +BGL_Wrap(Viewport, void, (GLint, GLint, GLsizei, GLsizei)); /* GL_VERSION_1_1 */ -BGL_Wrap(BindTexture, void, (GLenum, GLuint)); -BGL_Wrap(CopyTexImage1D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint)); -BGL_Wrap(CopyTexImage2D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint)); -BGL_Wrap(CopyTexSubImage1D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei)); -BGL_Wrap(CopyTexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei)); -BGL_Wrap(DeleteTextures, void, (GLsizei, GLuintP)); -BGL_Wrap(DrawArrays, void, (GLenum, GLint, GLsizei)); -BGL_Wrap(DrawElements, void, (GLenum, GLsizei, GLenum, GLvoidP)); -BGL_Wrap(GenTextures, void, (GLsizei, GLuintP)); -BGL_Wrap(IsTexture, GLboolean, (GLuint)); -BGL_Wrap(PolygonOffset, void, (GLfloat, GLfloat)); -BGL_Wrap(TexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, GLvoidP)); -BGL_Wrap(TexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)); - +BGL_Wrap(BindTexture, void, (GLenum, GLuint)); +BGL_Wrap(CopyTexImage1D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint)); +BGL_Wrap(CopyTexImage2D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint)); +BGL_Wrap(CopyTexSubImage1D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei)); +BGL_Wrap(CopyTexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei)); +BGL_Wrap(DeleteTextures, void, (GLsizei, GLuintP)); +BGL_Wrap(DrawArrays, void, (GLenum, GLint, GLsizei)); +BGL_Wrap(DrawElements, void, (GLenum, GLsizei, GLenum, GLvoidP)); +BGL_Wrap(GenTextures, void, (GLsizei, GLuintP)); +BGL_Wrap(IsTexture, GLboolean, (GLuint)); +BGL_Wrap(PolygonOffset, void, (GLfloat, GLfloat)); +BGL_Wrap(TexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, GLvoidP)); +BGL_Wrap(TexSubImage2D, + void, + (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)); /* GL_VERSION_1_2 */ -BGL_Wrap(CopyTexSubImage3D, void, (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei)); -BGL_Wrap(DrawRangeElements, void, (GLenum, GLuint, GLuint, GLsizei, GLenum, GLvoidP)); -BGL_Wrap(TexImage3D, void, (GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP)); -BGL_Wrap(TexSubImage3D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)); - +BGL_Wrap(CopyTexSubImage3D, + void, + (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei)); +BGL_Wrap(DrawRangeElements, void, (GLenum, GLuint, GLuint, GLsizei, GLenum, GLvoidP)); +BGL_Wrap(TexImage3D, + void, + (GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP)); +BGL_Wrap(TexSubImage3D, + void, + (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)); /* GL_VERSION_1_3 */ -BGL_Wrap(ActiveTexture, void, (GLenum)); -BGL_Wrap(CompressedTexImage1D, void, (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, GLvoidP)); -BGL_Wrap(CompressedTexImage2D, void, (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, GLvoidP)); -BGL_Wrap(CompressedTexImage3D, void, (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, GLvoidP)); -BGL_Wrap(CompressedTexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, GLvoidP)); -BGL_Wrap(CompressedTexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP)); -BGL_Wrap(CompressedTexSubImage3D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP)); -BGL_Wrap(GetCompressedTexImage, void, (GLenum, GLint, GLvoidP)); -BGL_Wrap(SampleCoverage, void, (GLfloat, GLboolean)); - +BGL_Wrap(ActiveTexture, void, (GLenum)); +BGL_Wrap(CompressedTexImage1D, void, (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, GLvoidP)); +BGL_Wrap(CompressedTexImage2D, + void, + (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, GLvoidP)); +BGL_Wrap(CompressedTexImage3D, + void, + (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, GLvoidP)); +BGL_Wrap(CompressedTexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, GLvoidP)); +BGL_Wrap(CompressedTexSubImage2D, + void, + (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP)); +BGL_Wrap( + CompressedTexSubImage3D, + void, + (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP)); +BGL_Wrap(GetCompressedTexImage, void, (GLenum, GLint, GLvoidP)); +BGL_Wrap(SampleCoverage, void, (GLfloat, GLboolean)); /* GL_VERSION_1_4 */ -BGL_Wrap(BlendColor, void, (GLfloat, GLfloat, GLfloat, GLfloat)); -BGL_Wrap(BlendEquation, void, (GLenum)); - +BGL_Wrap(BlendColor, void, (GLfloat, GLfloat, GLfloat, GLfloat)); +BGL_Wrap(BlendEquation, void, (GLenum)); /* GL_VERSION_1_5 */ -BGL_Wrap(BeginQuery, void, (GLenum, GLuint)); -BGL_Wrap(BindBuffer, void, (GLenum, GLuint)); -BGL_Wrap(BufferData, void, (GLenum, GLsizeiptr, GLvoidP, GLenum)); -BGL_Wrap(BufferSubData, void, (GLenum, GLintptr, GLsizeiptr, GLvoidP)); -BGL_Wrap(DeleteBuffers, void, (GLsizei, GLuintP)); -BGL_Wrap(DeleteQueries, void, (GLsizei, GLuintP)); -BGL_Wrap(EndQuery, void, (GLenum)); -BGL_Wrap(GenBuffers, void, (GLsizei, GLuintP)); -BGL_Wrap(GenQueries, void, (GLsizei, GLuintP)); -BGL_Wrap(GetBufferParameteriv, void, (GLenum, GLenum, GLintP)); -BGL_Wrap(GetBufferPointerv, void, (GLenum, GLenum, GLvoidP)); -BGL_Wrap(GetBufferSubData, void, (GLenum, GLintptr, GLsizeiptr, GLvoidP)); -BGL_Wrap(GetQueryObjectiv, void, (GLuint, GLenum, GLintP)); -BGL_Wrap(GetQueryObjectuiv, void, (GLuint, GLenum, GLuintP)); -BGL_Wrap(GetQueryiv, void, (GLenum, GLenum, GLintP)); -BGL_Wrap(IsBuffer, GLboolean, (GLuint)); -BGL_Wrap(IsQuery, GLboolean, (GLuint)); -BGL_Wrap(MapBuffer, void, (GLenum, GLenum)); -BGL_Wrap(UnmapBuffer, GLboolean, (GLenum)); - +BGL_Wrap(BeginQuery, void, (GLenum, GLuint)); +BGL_Wrap(BindBuffer, void, (GLenum, GLuint)); +BGL_Wrap(BufferData, void, (GLenum, GLsizeiptr, GLvoidP, GLenum)); +BGL_Wrap(BufferSubData, void, (GLenum, GLintptr, GLsizeiptr, GLvoidP)); +BGL_Wrap(DeleteBuffers, void, (GLsizei, GLuintP)); +BGL_Wrap(DeleteQueries, void, (GLsizei, GLuintP)); +BGL_Wrap(EndQuery, void, (GLenum)); +BGL_Wrap(GenBuffers, void, (GLsizei, GLuintP)); +BGL_Wrap(GenQueries, void, (GLsizei, GLuintP)); +BGL_Wrap(GetBufferParameteriv, void, (GLenum, GLenum, GLintP)); +BGL_Wrap(GetBufferPointerv, void, (GLenum, GLenum, GLvoidP)); +BGL_Wrap(GetBufferSubData, void, (GLenum, GLintptr, GLsizeiptr, GLvoidP)); +BGL_Wrap(GetQueryObjectiv, void, (GLuint, GLenum, GLintP)); +BGL_Wrap(GetQueryObjectuiv, void, (GLuint, GLenum, GLuintP)); +BGL_Wrap(GetQueryiv, void, (GLenum, GLenum, GLintP)); +BGL_Wrap(IsBuffer, GLboolean, (GLuint)); +BGL_Wrap(IsQuery, GLboolean, (GLuint)); +BGL_Wrap(MapBuffer, void, (GLenum, GLenum)); +BGL_Wrap(UnmapBuffer, GLboolean, (GLenum)); /* GL_VERSION_2_0 */ -BGL_Wrap(AttachShader, void, (GLuint, GLuint)); -BGL_Wrap(BindAttribLocation, void, (GLuint, GLuint, GLstring)); -BGL_Wrap(BlendEquationSeparate, void, (GLenum, GLenum)); -BGL_Wrap(CompileShader, void, (GLuint)); -BGL_Wrap(CreateProgram, GLuint, (void)); -BGL_Wrap(CreateShader, GLuint, (GLenum)); -BGL_Wrap(DeleteProgram, void, (GLuint)); -BGL_Wrap(DeleteShader, void, (GLuint)); -BGL_Wrap(DetachShader, void, (GLuint, GLuint)); -BGL_Wrap(DisableVertexAttribArray, void, (GLuint)); -BGL_Wrap(DrawBuffers, void, (GLsizei, GLenumP)); -BGL_Wrap(EnableVertexAttribArray, void, (GLuint)); -BGL_Wrap(GetActiveAttrib, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLintP, GLenumP, GLcharP)); -BGL_Wrap(GetActiveUniform, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLintP, GLenumP, GLcharP)); -BGL_Wrap(GetAttachedShaders, void, (GLuint, GLsizei, GLsizeiP, GLuintP)); -BGL_Wrap(GetAttribLocation, GLint, (GLuint, GLstring)); -BGL_Wrap(GetProgramInfoLog, void, (GLuint, GLsizei, GLsizeiP, GLcharP)); -BGL_Wrap(GetProgramiv, void, (GLuint, GLenum, GLintP)); -BGL_Wrap(GetShaderInfoLog, void, (GLuint, GLsizei, GLsizeiP, GLcharP)); -BGL_Wrap(GetShaderSource, void, (GLuint, GLsizei, GLsizeiP, GLcharP)); -BGL_Wrap(GetShaderiv, void, (GLuint, GLenum, GLintP)); -BGL_Wrap(GetUniformLocation, GLint, (GLuint, GLstring)); -BGL_Wrap(GetUniformfv, void, (GLuint, GLint, GLfloatP)); -BGL_Wrap(GetUniformiv, void, (GLuint, GLint, GLintP)); -BGL_Wrap(GetVertexAttribPointerv, void, (GLuint, GLenum, GLvoidP)); -BGL_Wrap(GetVertexAttribdv, void, (GLuint, GLenum, GLdoubleP)); -BGL_Wrap(GetVertexAttribfv, void, (GLuint, GLenum, GLfloatP)); -BGL_Wrap(GetVertexAttribiv, void, (GLuint, GLenum, GLintP)); -BGL_Wrap(IsProgram, GLboolean, (GLuint)); -BGL_Wrap(IsShader, GLboolean, (GLuint)); -BGL_Wrap(LinkProgram, void, (GLuint)); -BGL_Wrap(StencilFuncSeparate, void, (GLenum, GLenum, GLint, GLuint)); -BGL_Wrap(StencilMaskSeparate, void, (GLenum, GLuint)); -BGL_Wrap(StencilOpSeparate, void, (GLenum, GLenum, GLenum, GLenum)); -BGL_Wrap(Uniform1f, void, (GLint, GLfloat)); -BGL_Wrap(Uniform1fv, void, (GLint, GLsizei, GLfloatP)); -BGL_Wrap(Uniform1i, void, (GLint, GLint)); -BGL_Wrap(Uniform1iv, void, (GLint, GLsizei, GLintP)); -BGL_Wrap(Uniform2f, void, (GLint, GLfloat, GLfloat)); -BGL_Wrap(Uniform2fv, void, (GLint, GLsizei, GLfloatP)); -BGL_Wrap(Uniform2i, void, (GLint, GLint, GLint)); -BGL_Wrap(Uniform2iv, void, (GLint, GLsizei, GLintP)); -BGL_Wrap(Uniform3f, void, (GLint, GLfloat, GLfloat, GLfloat)); -BGL_Wrap(Uniform3fv, void, (GLint, GLsizei, GLfloatP)); -BGL_Wrap(Uniform3i, void, (GLint, GLint, GLint, GLint)); -BGL_Wrap(Uniform3iv, void, (GLint, GLsizei, GLintP)); -BGL_Wrap(Uniform4f, void, (GLint, GLfloat, GLfloat, GLfloat, GLfloat)); -BGL_Wrap(Uniform4fv, void, (GLint, GLsizei, GLfloatP)); -BGL_Wrap(Uniform4i, void, (GLint, GLint, GLint, GLint, GLint)); -BGL_Wrap(Uniform4iv, void, (GLint, GLsizei, GLintP)); -BGL_Wrap(UniformMatrix2fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UniformMatrix3fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UniformMatrix4fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UseProgram, void, (GLuint)); -BGL_Wrap(ValidateProgram, void, (GLuint)); -BGL_Wrap(VertexAttrib1d, void, (GLuint, GLdouble)); -BGL_Wrap(VertexAttrib1dv, void, (GLuint, GLdoubleP)); -BGL_Wrap(VertexAttrib1f, void, (GLuint, GLfloat)); -BGL_Wrap(VertexAttrib1fv, void, (GLuint, GLfloatP)); -BGL_Wrap(VertexAttrib1s, void, (GLuint, GLshort)); -BGL_Wrap(VertexAttrib1sv, void, (GLuint, GLshortP)); -BGL_Wrap(VertexAttrib2d, void, (GLuint, GLdouble, GLdouble)); -BGL_Wrap(VertexAttrib2dv, void, (GLuint, GLdoubleP)); -BGL_Wrap(VertexAttrib2f, void, (GLuint, GLfloat, GLfloat)); -BGL_Wrap(VertexAttrib2fv, void, (GLuint, GLfloatP)); -BGL_Wrap(VertexAttrib2s, void, (GLuint, GLshort, GLshort)); -BGL_Wrap(VertexAttrib2sv, void, (GLuint, GLshortP)); -BGL_Wrap(VertexAttrib3d, void, (GLuint, GLdouble, GLdouble, GLdouble)); -BGL_Wrap(VertexAttrib3dv, void, (GLuint, GLdoubleP)); -BGL_Wrap(VertexAttrib3f, void, (GLuint, GLfloat, GLfloat, GLfloat)); -BGL_Wrap(VertexAttrib3fv, void, (GLuint, GLfloatP)); -BGL_Wrap(VertexAttrib3s, void, (GLuint, GLshort, GLshort, GLshort)); -BGL_Wrap(VertexAttrib3sv, void, (GLuint, GLshortP)); -BGL_Wrap(VertexAttrib4Nbv, void, (GLuint, GLbyteP)); -BGL_Wrap(VertexAttrib4Niv, void, (GLuint, GLintP)); -BGL_Wrap(VertexAttrib4Nsv, void, (GLuint, GLshortP)); -BGL_Wrap(VertexAttrib4Nub, void, (GLuint, GLubyte, GLubyte, GLubyte, GLubyte)); -BGL_Wrap(VertexAttrib4Nubv, void, (GLuint, GLubyteP)); -BGL_Wrap(VertexAttrib4Nuiv, void, (GLuint, GLuintP)); -BGL_Wrap(VertexAttrib4Nusv, void, (GLuint, GLushortP)); -BGL_Wrap(VertexAttrib4bv, void, (GLuint, GLbyteP)); -BGL_Wrap(VertexAttrib4d, void, (GLuint, GLdouble, GLdouble, GLdouble, GLdouble)); -BGL_Wrap(VertexAttrib4dv, void, (GLuint, GLdoubleP)); -BGL_Wrap(VertexAttrib4f, void, (GLuint, GLfloat, GLfloat, GLfloat, GLfloat)); -BGL_Wrap(VertexAttrib4fv, void, (GLuint, GLfloatP)); -BGL_Wrap(VertexAttrib4iv, void, (GLuint, GLintP)); -BGL_Wrap(VertexAttrib4s, void, (GLuint, GLshort, GLshort, GLshort, GLshort)); -BGL_Wrap(VertexAttrib4sv, void, (GLuint, GLshortP)); -BGL_Wrap(VertexAttrib4ubv, void, (GLuint, GLubyteP)); -BGL_Wrap(VertexAttrib4uiv, void, (GLuint, GLuintP)); -BGL_Wrap(VertexAttrib4usv, void, (GLuint, GLushortP)); -BGL_Wrap(VertexAttribPointer, void, (GLuint, GLint, GLenum, GLboolean, GLsizei, GLvoidP)); - +BGL_Wrap(AttachShader, void, (GLuint, GLuint)); +BGL_Wrap(BindAttribLocation, void, (GLuint, GLuint, GLstring)); +BGL_Wrap(BlendEquationSeparate, void, (GLenum, GLenum)); +BGL_Wrap(CompileShader, void, (GLuint)); +BGL_Wrap(CreateProgram, GLuint, (void)); +BGL_Wrap(CreateShader, GLuint, (GLenum)); +BGL_Wrap(DeleteProgram, void, (GLuint)); +BGL_Wrap(DeleteShader, void, (GLuint)); +BGL_Wrap(DetachShader, void, (GLuint, GLuint)); +BGL_Wrap(DisableVertexAttribArray, void, (GLuint)); +BGL_Wrap(DrawBuffers, void, (GLsizei, GLenumP)); +BGL_Wrap(EnableVertexAttribArray, void, (GLuint)); +BGL_Wrap(GetActiveAttrib, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLintP, GLenumP, GLcharP)); +BGL_Wrap(GetActiveUniform, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLintP, GLenumP, GLcharP)); +BGL_Wrap(GetAttachedShaders, void, (GLuint, GLsizei, GLsizeiP, GLuintP)); +BGL_Wrap(GetAttribLocation, GLint, (GLuint, GLstring)); +BGL_Wrap(GetProgramInfoLog, void, (GLuint, GLsizei, GLsizeiP, GLcharP)); +BGL_Wrap(GetProgramiv, void, (GLuint, GLenum, GLintP)); +BGL_Wrap(GetShaderInfoLog, void, (GLuint, GLsizei, GLsizeiP, GLcharP)); +BGL_Wrap(GetShaderSource, void, (GLuint, GLsizei, GLsizeiP, GLcharP)); +BGL_Wrap(GetShaderiv, void, (GLuint, GLenum, GLintP)); +BGL_Wrap(GetUniformLocation, GLint, (GLuint, GLstring)); +BGL_Wrap(GetUniformfv, void, (GLuint, GLint, GLfloatP)); +BGL_Wrap(GetUniformiv, void, (GLuint, GLint, GLintP)); +BGL_Wrap(GetVertexAttribPointerv, void, (GLuint, GLenum, GLvoidP)); +BGL_Wrap(GetVertexAttribdv, void, (GLuint, GLenum, GLdoubleP)); +BGL_Wrap(GetVertexAttribfv, void, (GLuint, GLenum, GLfloatP)); +BGL_Wrap(GetVertexAttribiv, void, (GLuint, GLenum, GLintP)); +BGL_Wrap(IsProgram, GLboolean, (GLuint)); +BGL_Wrap(IsShader, GLboolean, (GLuint)); +BGL_Wrap(LinkProgram, void, (GLuint)); +BGL_Wrap(StencilFuncSeparate, void, (GLenum, GLenum, GLint, GLuint)); +BGL_Wrap(StencilMaskSeparate, void, (GLenum, GLuint)); +BGL_Wrap(StencilOpSeparate, void, (GLenum, GLenum, GLenum, GLenum)); +BGL_Wrap(Uniform1f, void, (GLint, GLfloat)); +BGL_Wrap(Uniform1fv, void, (GLint, GLsizei, GLfloatP)); +BGL_Wrap(Uniform1i, void, (GLint, GLint)); +BGL_Wrap(Uniform1iv, void, (GLint, GLsizei, GLintP)); +BGL_Wrap(Uniform2f, void, (GLint, GLfloat, GLfloat)); +BGL_Wrap(Uniform2fv, void, (GLint, GLsizei, GLfloatP)); +BGL_Wrap(Uniform2i, void, (GLint, GLint, GLint)); +BGL_Wrap(Uniform2iv, void, (GLint, GLsizei, GLintP)); +BGL_Wrap(Uniform3f, void, (GLint, GLfloat, GLfloat, GLfloat)); +BGL_Wrap(Uniform3fv, void, (GLint, GLsizei, GLfloatP)); +BGL_Wrap(Uniform3i, void, (GLint, GLint, GLint, GLint)); +BGL_Wrap(Uniform3iv, void, (GLint, GLsizei, GLintP)); +BGL_Wrap(Uniform4f, void, (GLint, GLfloat, GLfloat, GLfloat, GLfloat)); +BGL_Wrap(Uniform4fv, void, (GLint, GLsizei, GLfloatP)); +BGL_Wrap(Uniform4i, void, (GLint, GLint, GLint, GLint, GLint)); +BGL_Wrap(Uniform4iv, void, (GLint, GLsizei, GLintP)); +BGL_Wrap(UniformMatrix2fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UniformMatrix3fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UniformMatrix4fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UseProgram, void, (GLuint)); +BGL_Wrap(ValidateProgram, void, (GLuint)); +BGL_Wrap(VertexAttrib1d, void, (GLuint, GLdouble)); +BGL_Wrap(VertexAttrib1dv, void, (GLuint, GLdoubleP)); +BGL_Wrap(VertexAttrib1f, void, (GLuint, GLfloat)); +BGL_Wrap(VertexAttrib1fv, void, (GLuint, GLfloatP)); +BGL_Wrap(VertexAttrib1s, void, (GLuint, GLshort)); +BGL_Wrap(VertexAttrib1sv, void, (GLuint, GLshortP)); +BGL_Wrap(VertexAttrib2d, void, (GLuint, GLdouble, GLdouble)); +BGL_Wrap(VertexAttrib2dv, void, (GLuint, GLdoubleP)); +BGL_Wrap(VertexAttrib2f, void, (GLuint, GLfloat, GLfloat)); +BGL_Wrap(VertexAttrib2fv, void, (GLuint, GLfloatP)); +BGL_Wrap(VertexAttrib2s, void, (GLuint, GLshort, GLshort)); +BGL_Wrap(VertexAttrib2sv, void, (GLuint, GLshortP)); +BGL_Wrap(VertexAttrib3d, void, (GLuint, GLdouble, GLdouble, GLdouble)); +BGL_Wrap(VertexAttrib3dv, void, (GLuint, GLdoubleP)); +BGL_Wrap(VertexAttrib3f, void, (GLuint, GLfloat, GLfloat, GLfloat)); +BGL_Wrap(VertexAttrib3fv, void, (GLuint, GLfloatP)); +BGL_Wrap(VertexAttrib3s, void, (GLuint, GLshort, GLshort, GLshort)); +BGL_Wrap(VertexAttrib3sv, void, (GLuint, GLshortP)); +BGL_Wrap(VertexAttrib4Nbv, void, (GLuint, GLbyteP)); +BGL_Wrap(VertexAttrib4Niv, void, (GLuint, GLintP)); +BGL_Wrap(VertexAttrib4Nsv, void, (GLuint, GLshortP)); +BGL_Wrap(VertexAttrib4Nub, void, (GLuint, GLubyte, GLubyte, GLubyte, GLubyte)); +BGL_Wrap(VertexAttrib4Nubv, void, (GLuint, GLubyteP)); +BGL_Wrap(VertexAttrib4Nuiv, void, (GLuint, GLuintP)); +BGL_Wrap(VertexAttrib4Nusv, void, (GLuint, GLushortP)); +BGL_Wrap(VertexAttrib4bv, void, (GLuint, GLbyteP)); +BGL_Wrap(VertexAttrib4d, void, (GLuint, GLdouble, GLdouble, GLdouble, GLdouble)); +BGL_Wrap(VertexAttrib4dv, void, (GLuint, GLdoubleP)); +BGL_Wrap(VertexAttrib4f, void, (GLuint, GLfloat, GLfloat, GLfloat, GLfloat)); +BGL_Wrap(VertexAttrib4fv, void, (GLuint, GLfloatP)); +BGL_Wrap(VertexAttrib4iv, void, (GLuint, GLintP)); +BGL_Wrap(VertexAttrib4s, void, (GLuint, GLshort, GLshort, GLshort, GLshort)); +BGL_Wrap(VertexAttrib4sv, void, (GLuint, GLshortP)); +BGL_Wrap(VertexAttrib4ubv, void, (GLuint, GLubyteP)); +BGL_Wrap(VertexAttrib4uiv, void, (GLuint, GLuintP)); +BGL_Wrap(VertexAttrib4usv, void, (GLuint, GLushortP)); +BGL_Wrap(VertexAttribPointer, void, (GLuint, GLint, GLenum, GLboolean, GLsizei, GLvoidP)); /* GL_VERSION_2_1 */ -BGL_Wrap(UniformMatrix2x3fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UniformMatrix2x4fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UniformMatrix3x2fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UniformMatrix3x4fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UniformMatrix4x2fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); -BGL_Wrap(UniformMatrix4x3fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); - +BGL_Wrap(UniformMatrix2x3fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UniformMatrix2x4fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UniformMatrix3x2fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UniformMatrix3x4fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UniformMatrix4x2fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); +BGL_Wrap(UniformMatrix4x3fv, void, (GLint, GLsizei, GLboolean, GLfloatP)); /* GL_VERSION_3_0 */ -BGL_Wrap(BindFramebuffer, void, (GLenum, GLuint)); -BGL_Wrap(BindRenderbuffer, void, (GLenum, GLuint)); -BGL_Wrap(BindVertexArray, void, (GLuint)); -BGL_Wrap(BlitFramebuffer, void, (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum)); -BGL_Wrap(CheckFramebufferStatus, GLenum, (GLenum)); -BGL_Wrap(DeleteFramebuffers, void, (GLsizei, GLuintP)); -BGL_Wrap(DeleteRenderbuffers, void, (GLsizei, GLuintP)); -BGL_Wrap(DeleteVertexArrays, void, (GLsizei, GLuintP)); -BGL_Wrap(FramebufferRenderbuffer, void, (GLenum, GLenum, GLenum, GLuint)); -BGL_Wrap(GenFramebuffers, void, (GLsizei, GLuintP)); -BGL_Wrap(GenRenderbuffers, void, (GLsizei, GLuintP)); -BGL_Wrap(GenVertexArrays, void, (GLsizei, GLuintP)); -BGL_Wrap(GetStringi, GLstring, (GLenum, GLuint)); -BGL_Wrap(IsVertexArray, GLboolean, (GLuint)); -BGL_Wrap(RenderbufferStorage, void, (GLenum, GLenum, GLsizei, GLsizei)); - +BGL_Wrap(BindFramebuffer, void, (GLenum, GLuint)); +BGL_Wrap(BindRenderbuffer, void, (GLenum, GLuint)); +BGL_Wrap(BindVertexArray, void, (GLuint)); +BGL_Wrap(BlitFramebuffer, + void, + (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum)); +BGL_Wrap(CheckFramebufferStatus, GLenum, (GLenum)); +BGL_Wrap(DeleteFramebuffers, void, (GLsizei, GLuintP)); +BGL_Wrap(DeleteRenderbuffers, void, (GLsizei, GLuintP)); +BGL_Wrap(DeleteVertexArrays, void, (GLsizei, GLuintP)); +BGL_Wrap(FramebufferRenderbuffer, void, (GLenum, GLenum, GLenum, GLuint)); +BGL_Wrap(GenFramebuffers, void, (GLsizei, GLuintP)); +BGL_Wrap(GenRenderbuffers, void, (GLsizei, GLuintP)); +BGL_Wrap(GenVertexArrays, void, (GLsizei, GLuintP)); +BGL_Wrap(GetStringi, GLstring, (GLenum, GLuint)); +BGL_Wrap(IsVertexArray, GLboolean, (GLuint)); +BGL_Wrap(RenderbufferStorage, void, (GLenum, GLenum, GLsizei, GLsizei)); /* GL_VERSION_3_1 */ -BGL_Wrap(BindBufferBase, void, (GLenum, GLuint, GLuint)); -BGL_Wrap(BindBufferRange, void, (GLenum, GLuint, GLuint, GLintptr, GLsizeiptr)); -BGL_Wrap(GetActiveUniformBlockName, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLcharP)); -BGL_Wrap(GetActiveUniformBlockiv, void, (GLuint, GLuint, GLenum, GLintP)); -BGL_Wrap(GetActiveUniformName, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLcharP)); -BGL_Wrap(GetActiveUniformsiv, void, (GLuint, GLsizei, GLuintP, GLenum, GLintP)); -BGL_Wrap(GetIntegeri_v, void, (GLenum, GLuint, GLintP)); -BGL_Wrap(GetUniformBlockIndex, GLuint, (GLuint, GLstring)); -BGL_Wrap(GetUniformIndices, void, (GLuint, GLsizei, GLcharP, GLuintP)); -BGL_Wrap(UniformBlockBinding, void, (GLuint, GLuint, GLuint)); - +BGL_Wrap(BindBufferBase, void, (GLenum, GLuint, GLuint)); +BGL_Wrap(BindBufferRange, void, (GLenum, GLuint, GLuint, GLintptr, GLsizeiptr)); +BGL_Wrap(GetActiveUniformBlockName, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLcharP)); +BGL_Wrap(GetActiveUniformBlockiv, void, (GLuint, GLuint, GLenum, GLintP)); +BGL_Wrap(GetActiveUniformName, void, (GLuint, GLuint, GLsizei, GLsizeiP, GLcharP)); +BGL_Wrap(GetActiveUniformsiv, void, (GLuint, GLsizei, GLuintP, GLenum, GLintP)); +BGL_Wrap(GetIntegeri_v, void, (GLenum, GLuint, GLintP)); +BGL_Wrap(GetUniformBlockIndex, GLuint, (GLuint, GLstring)); +BGL_Wrap(GetUniformIndices, void, (GLuint, GLsizei, GLcharP, GLuintP)); +BGL_Wrap(UniformBlockBinding, void, (GLuint, GLuint, GLuint)); /* GL_VERSION_3_2 */ -BGL_Wrap(FramebufferTexture, void, (GLenum, GLenum, GLuint, GLint)); -BGL_Wrap(GetBufferParameteri64v, void, (GLenum, GLenum, GLint64P)); -BGL_Wrap(GetInteger64i_v, void, (GLenum, GLuint, GLint64P)); -BGL_Wrap(GetMultisamplefv, void, (GLenum, GLuint, GLfloatP)); -BGL_Wrap(SampleMaski, void, (GLuint, GLbitfield)); -BGL_Wrap(TexImage2DMultisample, void, (GLenum, GLsizei, GLenum, GLsizei, GLsizei, GLboolean)); -BGL_Wrap(TexImage3DMultisample, void, (GLenum, GLsizei, GLenum, GLsizei, GLsizei, GLsizei, GLboolean)); - +BGL_Wrap(FramebufferTexture, void, (GLenum, GLenum, GLuint, GLint)); +BGL_Wrap(GetBufferParameteri64v, void, (GLenum, GLenum, GLint64P)); +BGL_Wrap(GetInteger64i_v, void, (GLenum, GLuint, GLint64P)); +BGL_Wrap(GetMultisamplefv, void, (GLenum, GLuint, GLfloatP)); +BGL_Wrap(SampleMaski, void, (GLuint, GLbitfield)); +BGL_Wrap(TexImage2DMultisample, void, (GLenum, GLsizei, GLenum, GLsizei, GLsizei, GLboolean)); +BGL_Wrap(TexImage3DMultisample, + void, + (GLenum, GLsizei, GLenum, GLsizei, GLsizei, GLsizei, GLboolean)); /* GL_VERSION_3_3 */ /* no new functions besides packed immediate mode (not part of core profile) */ /** \} */ - /* -------------------------------------------------------------------- */ /** \name Module Definition * \{ */ static struct PyModuleDef BGL_module_def = { - PyModuleDef_HEAD_INIT, - "bgl", /* m_name */ - NULL, /* m_doc */ - 0, /* m_size */ - NULL, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ + PyModuleDef_HEAD_INIT, + "bgl", /* m_name */ + NULL, /* m_doc */ + 0, /* m_size */ + NULL, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ }; static void py_module_dict_add_int(PyObject *dict, const char *name, int value) { - PyObject *item; - PyDict_SetItemString(dict, name, item = PyLong_FromLong(value)); - Py_DECREF(item); + PyObject *item; + PyDict_SetItemString(dict, name, item = PyLong_FromLong(value)); + Py_DECREF(item); } static void py_module_dict_add_int64(PyObject *dict, const char *name, int64_t value) { - PyObject *item; - PyDict_SetItemString(dict, name, item = PyLong_FromLongLong(value)); - Py_DECREF(item); + PyObject *item; + PyDict_SetItemString(dict, name, item = PyLong_FromLongLong(value)); + Py_DECREF(item); } -static void py_module_dict_add_method(PyObject *submodule, PyObject *dict, PyMethodDef *method_def, bool is_valid) +static void py_module_dict_add_method(PyObject *submodule, + PyObject *dict, + PyMethodDef *method_def, + bool is_valid) { - if (is_valid) { - PyObject *m; - m = PyCFunction_NewEx(method_def, NULL, submodule); - PyDict_SetItemString(dict, method_def->ml_name, m); - Py_DECREF(m); - } - else { - PyDict_SetItemString(dict, method_def->ml_name, Py_None); - } + if (is_valid) { + PyObject *m; + m = PyCFunction_NewEx(method_def, NULL, submodule); + PyDict_SetItemString(dict, method_def->ml_name, m); + Py_DECREF(m); + } + else { + PyDict_SetItemString(dict, method_def->ml_name, Py_None); + } } PyObject *BPyInit_bgl(void) { - PyObject *submodule, *dict; - submodule = PyModule_Create(&BGL_module_def); - dict = PyModule_GetDict(submodule); + PyObject *submodule, *dict; + submodule = PyModule_Create(&BGL_module_def); + dict = PyModule_GetDict(submodule); - if (PyType_Ready(&BGL_bufferType) < 0) { - return NULL; /* should never happen */ - } + if (PyType_Ready(&BGL_bufferType) < 0) { + return NULL; /* should never happen */ + } - PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType); - Py_INCREF((PyObject *)&BGL_bufferType); + PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType); + Py_INCREF((PyObject *)&BGL_bufferType); /* needed since some function pointers won't be NULL */ #ifdef __GNUC__ @@ -1434,1166 +1439,1166 @@ PyObject *BPyInit_bgl(void) #endif #define PY_MOD_ADD_METHOD(func) \ - { \ - static PyMethodDef method_def = {"gl"#func, Method_##func, METH_VARARGS}; \ - py_module_dict_add_method(submodule, dict, &method_def, (gl##func != NULL)); \ - } ((void)0) - - /* GL_VERSION_1_0 */ - { - PY_MOD_ADD_METHOD(BlendFunc); - PY_MOD_ADD_METHOD(Clear); - PY_MOD_ADD_METHOD(ClearColor); - PY_MOD_ADD_METHOD(ClearDepth); - PY_MOD_ADD_METHOD(ClearStencil); - PY_MOD_ADD_METHOD(ColorMask); - PY_MOD_ADD_METHOD(CullFace); - PY_MOD_ADD_METHOD(DepthFunc); - PY_MOD_ADD_METHOD(DepthMask); - PY_MOD_ADD_METHOD(DepthRange); - PY_MOD_ADD_METHOD(Disable); - PY_MOD_ADD_METHOD(DrawBuffer); - PY_MOD_ADD_METHOD(Enable); - PY_MOD_ADD_METHOD(Finish); - PY_MOD_ADD_METHOD(Flush); - PY_MOD_ADD_METHOD(FrontFace); - PY_MOD_ADD_METHOD(GetBooleanv); - PY_MOD_ADD_METHOD(GetDoublev); - PY_MOD_ADD_METHOD(GetError); - PY_MOD_ADD_METHOD(GetFloatv); - PY_MOD_ADD_METHOD(GetIntegerv); - PY_MOD_ADD_METHOD(GetString); - PY_MOD_ADD_METHOD(GetTexImage); - PY_MOD_ADD_METHOD(GetTexLevelParameterfv); - PY_MOD_ADD_METHOD(GetTexLevelParameteriv); - PY_MOD_ADD_METHOD(GetTexParameterfv); - PY_MOD_ADD_METHOD(GetTexParameteriv); - PY_MOD_ADD_METHOD(Hint); - PY_MOD_ADD_METHOD(IsEnabled); - PY_MOD_ADD_METHOD(LineWidth); - PY_MOD_ADD_METHOD(LogicOp); - PY_MOD_ADD_METHOD(PixelStoref); - PY_MOD_ADD_METHOD(PixelStorei); - PY_MOD_ADD_METHOD(PointSize); - PY_MOD_ADD_METHOD(PolygonMode); - PY_MOD_ADD_METHOD(ReadBuffer); - PY_MOD_ADD_METHOD(ReadPixels); - PY_MOD_ADD_METHOD(Scissor); - PY_MOD_ADD_METHOD(StencilFunc); - PY_MOD_ADD_METHOD(StencilMask); - PY_MOD_ADD_METHOD(StencilOp); - PY_MOD_ADD_METHOD(TexImage1D); - PY_MOD_ADD_METHOD(TexImage2D); - PY_MOD_ADD_METHOD(TexParameterf); - PY_MOD_ADD_METHOD(TexParameterfv); - PY_MOD_ADD_METHOD(TexParameteri); - PY_MOD_ADD_METHOD(TexParameteriv); - PY_MOD_ADD_METHOD(Viewport); - } - - /* GL_VERSION_1_1 */ - { - PY_MOD_ADD_METHOD(BindTexture); - PY_MOD_ADD_METHOD(CopyTexImage1D); - PY_MOD_ADD_METHOD(CopyTexImage2D); - PY_MOD_ADD_METHOD(CopyTexSubImage1D); - PY_MOD_ADD_METHOD(CopyTexSubImage2D); - PY_MOD_ADD_METHOD(DeleteTextures); - PY_MOD_ADD_METHOD(DrawArrays); - PY_MOD_ADD_METHOD(DrawElements); - PY_MOD_ADD_METHOD(GenTextures); - PY_MOD_ADD_METHOD(IsTexture); - PY_MOD_ADD_METHOD(PolygonOffset); - PY_MOD_ADD_METHOD(TexSubImage1D); - PY_MOD_ADD_METHOD(TexSubImage2D); - } - - /* GL_VERSION_1_2 */ - { - PY_MOD_ADD_METHOD(CopyTexSubImage3D); - PY_MOD_ADD_METHOD(DrawRangeElements); - PY_MOD_ADD_METHOD(TexImage3D); - PY_MOD_ADD_METHOD(TexSubImage3D); - } - - /* GL_VERSION_1_3 */ - { - PY_MOD_ADD_METHOD(ActiveTexture); - PY_MOD_ADD_METHOD(CompressedTexImage1D); - PY_MOD_ADD_METHOD(CompressedTexImage2D); - PY_MOD_ADD_METHOD(CompressedTexImage3D); - PY_MOD_ADD_METHOD(CompressedTexSubImage1D); - PY_MOD_ADD_METHOD(CompressedTexSubImage2D); - PY_MOD_ADD_METHOD(CompressedTexSubImage3D); - PY_MOD_ADD_METHOD(GetCompressedTexImage); - PY_MOD_ADD_METHOD(SampleCoverage); - } - - /* GL_VERSION_1_4 */ - { - PY_MOD_ADD_METHOD(BlendColor); - PY_MOD_ADD_METHOD(BlendEquation); - } - - /* GL_VERSION_1_5 */ - { - PY_MOD_ADD_METHOD(BeginQuery); - PY_MOD_ADD_METHOD(BindBuffer); - PY_MOD_ADD_METHOD(BufferData); - PY_MOD_ADD_METHOD(BufferSubData); - PY_MOD_ADD_METHOD(DeleteBuffers); - PY_MOD_ADD_METHOD(DeleteQueries); - PY_MOD_ADD_METHOD(EndQuery); - PY_MOD_ADD_METHOD(GenBuffers); - PY_MOD_ADD_METHOD(GenQueries); - PY_MOD_ADD_METHOD(GetBufferParameteriv); - PY_MOD_ADD_METHOD(GetBufferPointerv); - PY_MOD_ADD_METHOD(GetBufferSubData); - PY_MOD_ADD_METHOD(GetQueryObjectiv); - PY_MOD_ADD_METHOD(GetQueryObjectuiv); - PY_MOD_ADD_METHOD(GetQueryiv); - PY_MOD_ADD_METHOD(IsBuffer); - PY_MOD_ADD_METHOD(IsQuery); - PY_MOD_ADD_METHOD(MapBuffer); - PY_MOD_ADD_METHOD(UnmapBuffer); - } - - /* GL_VERSION_2_0 */ - { - PY_MOD_ADD_METHOD(AttachShader); - PY_MOD_ADD_METHOD(BindAttribLocation); - PY_MOD_ADD_METHOD(BlendEquationSeparate); - PY_MOD_ADD_METHOD(CompileShader); - PY_MOD_ADD_METHOD(CreateProgram); - PY_MOD_ADD_METHOD(CreateShader); - PY_MOD_ADD_METHOD(DeleteProgram); - PY_MOD_ADD_METHOD(DeleteShader); - PY_MOD_ADD_METHOD(DetachShader); - PY_MOD_ADD_METHOD(DisableVertexAttribArray); - PY_MOD_ADD_METHOD(DrawBuffers); - PY_MOD_ADD_METHOD(EnableVertexAttribArray); - PY_MOD_ADD_METHOD(GetActiveAttrib); - PY_MOD_ADD_METHOD(GetActiveUniform); - PY_MOD_ADD_METHOD(GetAttachedShaders); - PY_MOD_ADD_METHOD(GetAttribLocation); - PY_MOD_ADD_METHOD(GetProgramInfoLog); - PY_MOD_ADD_METHOD(GetProgramiv); - PY_MOD_ADD_METHOD(GetShaderInfoLog); - PY_MOD_ADD_METHOD(GetShaderSource); - PY_MOD_ADD_METHOD(GetShaderiv); - PY_MOD_ADD_METHOD(GetUniformLocation); - PY_MOD_ADD_METHOD(GetUniformfv); - PY_MOD_ADD_METHOD(GetUniformiv); - PY_MOD_ADD_METHOD(GetVertexAttribPointerv); - PY_MOD_ADD_METHOD(GetVertexAttribdv); - PY_MOD_ADD_METHOD(GetVertexAttribfv); - PY_MOD_ADD_METHOD(GetVertexAttribiv); - PY_MOD_ADD_METHOD(IsProgram); - PY_MOD_ADD_METHOD(IsShader); - PY_MOD_ADD_METHOD(LinkProgram); - PY_MOD_ADD_METHOD(ShaderSource); - PY_MOD_ADD_METHOD(StencilFuncSeparate); - PY_MOD_ADD_METHOD(StencilMaskSeparate); - PY_MOD_ADD_METHOD(StencilOpSeparate); - PY_MOD_ADD_METHOD(Uniform1f); - PY_MOD_ADD_METHOD(Uniform1fv); - PY_MOD_ADD_METHOD(Uniform1i); - PY_MOD_ADD_METHOD(Uniform1iv); - PY_MOD_ADD_METHOD(Uniform2f); - PY_MOD_ADD_METHOD(Uniform2fv); - PY_MOD_ADD_METHOD(Uniform2i); - PY_MOD_ADD_METHOD(Uniform2iv); - PY_MOD_ADD_METHOD(Uniform3f); - PY_MOD_ADD_METHOD(Uniform3fv); - PY_MOD_ADD_METHOD(Uniform3i); - PY_MOD_ADD_METHOD(Uniform3iv); - PY_MOD_ADD_METHOD(Uniform4f); - PY_MOD_ADD_METHOD(Uniform4fv); - PY_MOD_ADD_METHOD(Uniform4i); - PY_MOD_ADD_METHOD(Uniform4iv); - PY_MOD_ADD_METHOD(UniformMatrix2fv); - PY_MOD_ADD_METHOD(UniformMatrix3fv); - PY_MOD_ADD_METHOD(UniformMatrix4fv); - PY_MOD_ADD_METHOD(UseProgram); - PY_MOD_ADD_METHOD(ValidateProgram); - PY_MOD_ADD_METHOD(VertexAttrib1d); - PY_MOD_ADD_METHOD(VertexAttrib1dv); - PY_MOD_ADD_METHOD(VertexAttrib1f); - PY_MOD_ADD_METHOD(VertexAttrib1fv); - PY_MOD_ADD_METHOD(VertexAttrib1s); - PY_MOD_ADD_METHOD(VertexAttrib1sv); - PY_MOD_ADD_METHOD(VertexAttrib2d); - PY_MOD_ADD_METHOD(VertexAttrib2dv); - PY_MOD_ADD_METHOD(VertexAttrib2f); - PY_MOD_ADD_METHOD(VertexAttrib2fv); - PY_MOD_ADD_METHOD(VertexAttrib2s); - PY_MOD_ADD_METHOD(VertexAttrib2sv); - PY_MOD_ADD_METHOD(VertexAttrib3d); - PY_MOD_ADD_METHOD(VertexAttrib3dv); - PY_MOD_ADD_METHOD(VertexAttrib3f); - PY_MOD_ADD_METHOD(VertexAttrib3fv); - PY_MOD_ADD_METHOD(VertexAttrib3s); - PY_MOD_ADD_METHOD(VertexAttrib3sv); - PY_MOD_ADD_METHOD(VertexAttrib4Nbv); - PY_MOD_ADD_METHOD(VertexAttrib4Niv); - PY_MOD_ADD_METHOD(VertexAttrib4Nsv); - PY_MOD_ADD_METHOD(VertexAttrib4Nub); - PY_MOD_ADD_METHOD(VertexAttrib4Nubv); - PY_MOD_ADD_METHOD(VertexAttrib4Nuiv); - PY_MOD_ADD_METHOD(VertexAttrib4Nusv); - PY_MOD_ADD_METHOD(VertexAttrib4bv); - PY_MOD_ADD_METHOD(VertexAttrib4d); - PY_MOD_ADD_METHOD(VertexAttrib4dv); - PY_MOD_ADD_METHOD(VertexAttrib4f); - PY_MOD_ADD_METHOD(VertexAttrib4fv); - PY_MOD_ADD_METHOD(VertexAttrib4iv); - PY_MOD_ADD_METHOD(VertexAttrib4s); - PY_MOD_ADD_METHOD(VertexAttrib4sv); - PY_MOD_ADD_METHOD(VertexAttrib4ubv); - PY_MOD_ADD_METHOD(VertexAttrib4uiv); - PY_MOD_ADD_METHOD(VertexAttrib4usv); - PY_MOD_ADD_METHOD(VertexAttribPointer); - } - - /* GL_VERSION_2_1 */ - { - PY_MOD_ADD_METHOD(UniformMatrix2x3fv); - PY_MOD_ADD_METHOD(UniformMatrix2x4fv); - PY_MOD_ADD_METHOD(UniformMatrix3x2fv); - PY_MOD_ADD_METHOD(UniformMatrix3x4fv); - PY_MOD_ADD_METHOD(UniformMatrix4x2fv); - PY_MOD_ADD_METHOD(UniformMatrix4x3fv); - } - - /* GL_VERSION_3_0 */ - { - PY_MOD_ADD_METHOD(BindFramebuffer); - PY_MOD_ADD_METHOD(BindRenderbuffer); - PY_MOD_ADD_METHOD(BindVertexArray); - PY_MOD_ADD_METHOD(BlitFramebuffer); - PY_MOD_ADD_METHOD(CheckFramebufferStatus); - PY_MOD_ADD_METHOD(DeleteFramebuffers); - PY_MOD_ADD_METHOD(DeleteRenderbuffers); - PY_MOD_ADD_METHOD(DeleteVertexArrays); - PY_MOD_ADD_METHOD(FramebufferRenderbuffer); - PY_MOD_ADD_METHOD(GenFramebuffers); - PY_MOD_ADD_METHOD(GenRenderbuffers); - PY_MOD_ADD_METHOD(GenVertexArrays); - PY_MOD_ADD_METHOD(GetStringi); - PY_MOD_ADD_METHOD(IsVertexArray); - PY_MOD_ADD_METHOD(RenderbufferStorage); - } - - /* GL_VERSION_3_1 */ - { - PY_MOD_ADD_METHOD(BindBufferBase); - PY_MOD_ADD_METHOD(BindBufferRange); - PY_MOD_ADD_METHOD(GetActiveUniformBlockName); - PY_MOD_ADD_METHOD(GetActiveUniformBlockiv); - PY_MOD_ADD_METHOD(GetActiveUniformName); - PY_MOD_ADD_METHOD(GetActiveUniformsiv); - PY_MOD_ADD_METHOD(GetIntegeri_v); - PY_MOD_ADD_METHOD(GetUniformBlockIndex); - PY_MOD_ADD_METHOD(GetUniformIndices); - PY_MOD_ADD_METHOD(UniformBlockBinding); - } - - /* GL_VERSION_3_2 */ - { - PY_MOD_ADD_METHOD(FramebufferTexture); - PY_MOD_ADD_METHOD(GetBufferParameteri64v); - PY_MOD_ADD_METHOD(GetInteger64i_v); - PY_MOD_ADD_METHOD(GetMultisamplefv); - PY_MOD_ADD_METHOD(SampleMaski); - PY_MOD_ADD_METHOD(TexImage2DMultisample); - PY_MOD_ADD_METHOD(TexImage3DMultisample); - } - - /* GL_VERSION_3_3 */ - { - } + { \ + static PyMethodDef method_def = {"gl" #func, Method_##func, METH_VARARGS}; \ + py_module_dict_add_method(submodule, dict, &method_def, (gl##func != NULL)); \ + } \ + ((void)0) + + /* GL_VERSION_1_0 */ + { + PY_MOD_ADD_METHOD(BlendFunc); + PY_MOD_ADD_METHOD(Clear); + PY_MOD_ADD_METHOD(ClearColor); + PY_MOD_ADD_METHOD(ClearDepth); + PY_MOD_ADD_METHOD(ClearStencil); + PY_MOD_ADD_METHOD(ColorMask); + PY_MOD_ADD_METHOD(CullFace); + PY_MOD_ADD_METHOD(DepthFunc); + PY_MOD_ADD_METHOD(DepthMask); + PY_MOD_ADD_METHOD(DepthRange); + PY_MOD_ADD_METHOD(Disable); + PY_MOD_ADD_METHOD(DrawBuffer); + PY_MOD_ADD_METHOD(Enable); + PY_MOD_ADD_METHOD(Finish); + PY_MOD_ADD_METHOD(Flush); + PY_MOD_ADD_METHOD(FrontFace); + PY_MOD_ADD_METHOD(GetBooleanv); + PY_MOD_ADD_METHOD(GetDoublev); + PY_MOD_ADD_METHOD(GetError); + PY_MOD_ADD_METHOD(GetFloatv); + PY_MOD_ADD_METHOD(GetIntegerv); + PY_MOD_ADD_METHOD(GetString); + PY_MOD_ADD_METHOD(GetTexImage); + PY_MOD_ADD_METHOD(GetTexLevelParameterfv); + PY_MOD_ADD_METHOD(GetTexLevelParameteriv); + PY_MOD_ADD_METHOD(GetTexParameterfv); + PY_MOD_ADD_METHOD(GetTexParameteriv); + PY_MOD_ADD_METHOD(Hint); + PY_MOD_ADD_METHOD(IsEnabled); + PY_MOD_ADD_METHOD(LineWidth); + PY_MOD_ADD_METHOD(LogicOp); + PY_MOD_ADD_METHOD(PixelStoref); + PY_MOD_ADD_METHOD(PixelStorei); + PY_MOD_ADD_METHOD(PointSize); + PY_MOD_ADD_METHOD(PolygonMode); + PY_MOD_ADD_METHOD(ReadBuffer); + PY_MOD_ADD_METHOD(ReadPixels); + PY_MOD_ADD_METHOD(Scissor); + PY_MOD_ADD_METHOD(StencilFunc); + PY_MOD_ADD_METHOD(StencilMask); + PY_MOD_ADD_METHOD(StencilOp); + PY_MOD_ADD_METHOD(TexImage1D); + PY_MOD_ADD_METHOD(TexImage2D); + PY_MOD_ADD_METHOD(TexParameterf); + PY_MOD_ADD_METHOD(TexParameterfv); + PY_MOD_ADD_METHOD(TexParameteri); + PY_MOD_ADD_METHOD(TexParameteriv); + PY_MOD_ADD_METHOD(Viewport); + } + + /* GL_VERSION_1_1 */ + { + PY_MOD_ADD_METHOD(BindTexture); + PY_MOD_ADD_METHOD(CopyTexImage1D); + PY_MOD_ADD_METHOD(CopyTexImage2D); + PY_MOD_ADD_METHOD(CopyTexSubImage1D); + PY_MOD_ADD_METHOD(CopyTexSubImage2D); + PY_MOD_ADD_METHOD(DeleteTextures); + PY_MOD_ADD_METHOD(DrawArrays); + PY_MOD_ADD_METHOD(DrawElements); + PY_MOD_ADD_METHOD(GenTextures); + PY_MOD_ADD_METHOD(IsTexture); + PY_MOD_ADD_METHOD(PolygonOffset); + PY_MOD_ADD_METHOD(TexSubImage1D); + PY_MOD_ADD_METHOD(TexSubImage2D); + } + + /* GL_VERSION_1_2 */ + { + PY_MOD_ADD_METHOD(CopyTexSubImage3D); + PY_MOD_ADD_METHOD(DrawRangeElements); + PY_MOD_ADD_METHOD(TexImage3D); + PY_MOD_ADD_METHOD(TexSubImage3D); + } + + /* GL_VERSION_1_3 */ + { + PY_MOD_ADD_METHOD(ActiveTexture); + PY_MOD_ADD_METHOD(CompressedTexImage1D); + PY_MOD_ADD_METHOD(CompressedTexImage2D); + PY_MOD_ADD_METHOD(CompressedTexImage3D); + PY_MOD_ADD_METHOD(CompressedTexSubImage1D); + PY_MOD_ADD_METHOD(CompressedTexSubImage2D); + PY_MOD_ADD_METHOD(CompressedTexSubImage3D); + PY_MOD_ADD_METHOD(GetCompressedTexImage); + PY_MOD_ADD_METHOD(SampleCoverage); + } + + /* GL_VERSION_1_4 */ + { + PY_MOD_ADD_METHOD(BlendColor); + PY_MOD_ADD_METHOD(BlendEquation); + } + + /* GL_VERSION_1_5 */ + { + PY_MOD_ADD_METHOD(BeginQuery); + PY_MOD_ADD_METHOD(BindBuffer); + PY_MOD_ADD_METHOD(BufferData); + PY_MOD_ADD_METHOD(BufferSubData); + PY_MOD_ADD_METHOD(DeleteBuffers); + PY_MOD_ADD_METHOD(DeleteQueries); + PY_MOD_ADD_METHOD(EndQuery); + PY_MOD_ADD_METHOD(GenBuffers); + PY_MOD_ADD_METHOD(GenQueries); + PY_MOD_ADD_METHOD(GetBufferParameteriv); + PY_MOD_ADD_METHOD(GetBufferPointerv); + PY_MOD_ADD_METHOD(GetBufferSubData); + PY_MOD_ADD_METHOD(GetQueryObjectiv); + PY_MOD_ADD_METHOD(GetQueryObjectuiv); + PY_MOD_ADD_METHOD(GetQueryiv); + PY_MOD_ADD_METHOD(IsBuffer); + PY_MOD_ADD_METHOD(IsQuery); + PY_MOD_ADD_METHOD(MapBuffer); + PY_MOD_ADD_METHOD(UnmapBuffer); + } + + /* GL_VERSION_2_0 */ + { + PY_MOD_ADD_METHOD(AttachShader); + PY_MOD_ADD_METHOD(BindAttribLocation); + PY_MOD_ADD_METHOD(BlendEquationSeparate); + PY_MOD_ADD_METHOD(CompileShader); + PY_MOD_ADD_METHOD(CreateProgram); + PY_MOD_ADD_METHOD(CreateShader); + PY_MOD_ADD_METHOD(DeleteProgram); + PY_MOD_ADD_METHOD(DeleteShader); + PY_MOD_ADD_METHOD(DetachShader); + PY_MOD_ADD_METHOD(DisableVertexAttribArray); + PY_MOD_ADD_METHOD(DrawBuffers); + PY_MOD_ADD_METHOD(EnableVertexAttribArray); + PY_MOD_ADD_METHOD(GetActiveAttrib); + PY_MOD_ADD_METHOD(GetActiveUniform); + PY_MOD_ADD_METHOD(GetAttachedShaders); + PY_MOD_ADD_METHOD(GetAttribLocation); + PY_MOD_ADD_METHOD(GetProgramInfoLog); + PY_MOD_ADD_METHOD(GetProgramiv); + PY_MOD_ADD_METHOD(GetShaderInfoLog); + PY_MOD_ADD_METHOD(GetShaderSource); + PY_MOD_ADD_METHOD(GetShaderiv); + PY_MOD_ADD_METHOD(GetUniformLocation); + PY_MOD_ADD_METHOD(GetUniformfv); + PY_MOD_ADD_METHOD(GetUniformiv); + PY_MOD_ADD_METHOD(GetVertexAttribPointerv); + PY_MOD_ADD_METHOD(GetVertexAttribdv); + PY_MOD_ADD_METHOD(GetVertexAttribfv); + PY_MOD_ADD_METHOD(GetVertexAttribiv); + PY_MOD_ADD_METHOD(IsProgram); + PY_MOD_ADD_METHOD(IsShader); + PY_MOD_ADD_METHOD(LinkProgram); + PY_MOD_ADD_METHOD(ShaderSource); + PY_MOD_ADD_METHOD(StencilFuncSeparate); + PY_MOD_ADD_METHOD(StencilMaskSeparate); + PY_MOD_ADD_METHOD(StencilOpSeparate); + PY_MOD_ADD_METHOD(Uniform1f); + PY_MOD_ADD_METHOD(Uniform1fv); + PY_MOD_ADD_METHOD(Uniform1i); + PY_MOD_ADD_METHOD(Uniform1iv); + PY_MOD_ADD_METHOD(Uniform2f); + PY_MOD_ADD_METHOD(Uniform2fv); + PY_MOD_ADD_METHOD(Uniform2i); + PY_MOD_ADD_METHOD(Uniform2iv); + PY_MOD_ADD_METHOD(Uniform3f); + PY_MOD_ADD_METHOD(Uniform3fv); + PY_MOD_ADD_METHOD(Uniform3i); + PY_MOD_ADD_METHOD(Uniform3iv); + PY_MOD_ADD_METHOD(Uniform4f); + PY_MOD_ADD_METHOD(Uniform4fv); + PY_MOD_ADD_METHOD(Uniform4i); + PY_MOD_ADD_METHOD(Uniform4iv); + PY_MOD_ADD_METHOD(UniformMatrix2fv); + PY_MOD_ADD_METHOD(UniformMatrix3fv); + PY_MOD_ADD_METHOD(UniformMatrix4fv); + PY_MOD_ADD_METHOD(UseProgram); + PY_MOD_ADD_METHOD(ValidateProgram); + PY_MOD_ADD_METHOD(VertexAttrib1d); + PY_MOD_ADD_METHOD(VertexAttrib1dv); + PY_MOD_ADD_METHOD(VertexAttrib1f); + PY_MOD_ADD_METHOD(VertexAttrib1fv); + PY_MOD_ADD_METHOD(VertexAttrib1s); + PY_MOD_ADD_METHOD(VertexAttrib1sv); + PY_MOD_ADD_METHOD(VertexAttrib2d); + PY_MOD_ADD_METHOD(VertexAttrib2dv); + PY_MOD_ADD_METHOD(VertexAttrib2f); + PY_MOD_ADD_METHOD(VertexAttrib2fv); + PY_MOD_ADD_METHOD(VertexAttrib2s); + PY_MOD_ADD_METHOD(VertexAttrib2sv); + PY_MOD_ADD_METHOD(VertexAttrib3d); + PY_MOD_ADD_METHOD(VertexAttrib3dv); + PY_MOD_ADD_METHOD(VertexAttrib3f); + PY_MOD_ADD_METHOD(VertexAttrib3fv); + PY_MOD_ADD_METHOD(VertexAttrib3s); + PY_MOD_ADD_METHOD(VertexAttrib3sv); + PY_MOD_ADD_METHOD(VertexAttrib4Nbv); + PY_MOD_ADD_METHOD(VertexAttrib4Niv); + PY_MOD_ADD_METHOD(VertexAttrib4Nsv); + PY_MOD_ADD_METHOD(VertexAttrib4Nub); + PY_MOD_ADD_METHOD(VertexAttrib4Nubv); + PY_MOD_ADD_METHOD(VertexAttrib4Nuiv); + PY_MOD_ADD_METHOD(VertexAttrib4Nusv); + PY_MOD_ADD_METHOD(VertexAttrib4bv); + PY_MOD_ADD_METHOD(VertexAttrib4d); + PY_MOD_ADD_METHOD(VertexAttrib4dv); + PY_MOD_ADD_METHOD(VertexAttrib4f); + PY_MOD_ADD_METHOD(VertexAttrib4fv); + PY_MOD_ADD_METHOD(VertexAttrib4iv); + PY_MOD_ADD_METHOD(VertexAttrib4s); + PY_MOD_ADD_METHOD(VertexAttrib4sv); + PY_MOD_ADD_METHOD(VertexAttrib4ubv); + PY_MOD_ADD_METHOD(VertexAttrib4uiv); + PY_MOD_ADD_METHOD(VertexAttrib4usv); + PY_MOD_ADD_METHOD(VertexAttribPointer); + } + + /* GL_VERSION_2_1 */ + { + PY_MOD_ADD_METHOD(UniformMatrix2x3fv); + PY_MOD_ADD_METHOD(UniformMatrix2x4fv); + PY_MOD_ADD_METHOD(UniformMatrix3x2fv); + PY_MOD_ADD_METHOD(UniformMatrix3x4fv); + PY_MOD_ADD_METHOD(UniformMatrix4x2fv); + PY_MOD_ADD_METHOD(UniformMatrix4x3fv); + } + + /* GL_VERSION_3_0 */ + { + PY_MOD_ADD_METHOD(BindFramebuffer); + PY_MOD_ADD_METHOD(BindRenderbuffer); + PY_MOD_ADD_METHOD(BindVertexArray); + PY_MOD_ADD_METHOD(BlitFramebuffer); + PY_MOD_ADD_METHOD(CheckFramebufferStatus); + PY_MOD_ADD_METHOD(DeleteFramebuffers); + PY_MOD_ADD_METHOD(DeleteRenderbuffers); + PY_MOD_ADD_METHOD(DeleteVertexArrays); + PY_MOD_ADD_METHOD(FramebufferRenderbuffer); + PY_MOD_ADD_METHOD(GenFramebuffers); + PY_MOD_ADD_METHOD(GenRenderbuffers); + PY_MOD_ADD_METHOD(GenVertexArrays); + PY_MOD_ADD_METHOD(GetStringi); + PY_MOD_ADD_METHOD(IsVertexArray); + PY_MOD_ADD_METHOD(RenderbufferStorage); + } + + /* GL_VERSION_3_1 */ + { + PY_MOD_ADD_METHOD(BindBufferBase); + PY_MOD_ADD_METHOD(BindBufferRange); + PY_MOD_ADD_METHOD(GetActiveUniformBlockName); + PY_MOD_ADD_METHOD(GetActiveUniformBlockiv); + PY_MOD_ADD_METHOD(GetActiveUniformName); + PY_MOD_ADD_METHOD(GetActiveUniformsiv); + PY_MOD_ADD_METHOD(GetIntegeri_v); + PY_MOD_ADD_METHOD(GetUniformBlockIndex); + PY_MOD_ADD_METHOD(GetUniformIndices); + PY_MOD_ADD_METHOD(UniformBlockBinding); + } + + /* GL_VERSION_3_2 */ + { + PY_MOD_ADD_METHOD(FramebufferTexture); + PY_MOD_ADD_METHOD(GetBufferParameteri64v); + PY_MOD_ADD_METHOD(GetInteger64i_v); + PY_MOD_ADD_METHOD(GetMultisamplefv); + PY_MOD_ADD_METHOD(SampleMaski); + PY_MOD_ADD_METHOD(TexImage2DMultisample); + PY_MOD_ADD_METHOD(TexImage3DMultisample); + } + + /* GL_VERSION_3_3 */ + { + } #define PY_DICT_ADD_INT(x) py_module_dict_add_int(dict, #x, x) #define PY_DICT_ADD_INT64(x) py_module_dict_add_int64(dict, #x, x) - /* GL_VERSION_1_1 */ - { - PY_DICT_ADD_INT(GL_ALPHA); - PY_DICT_ADD_INT(GL_ALWAYS); - PY_DICT_ADD_INT(GL_AND); - PY_DICT_ADD_INT(GL_AND_INVERTED); - PY_DICT_ADD_INT(GL_AND_REVERSE); - PY_DICT_ADD_INT(GL_BACK); - PY_DICT_ADD_INT(GL_BACK_LEFT); - PY_DICT_ADD_INT(GL_BACK_RIGHT); - PY_DICT_ADD_INT(GL_BLEND); - PY_DICT_ADD_INT(GL_BLEND_DST); - PY_DICT_ADD_INT(GL_BLEND_SRC); - PY_DICT_ADD_INT(GL_BLUE); - PY_DICT_ADD_INT(GL_BYTE); - PY_DICT_ADD_INT(GL_CCW); - PY_DICT_ADD_INT(GL_CLEAR); - PY_DICT_ADD_INT(GL_COLOR); - PY_DICT_ADD_INT(GL_COLOR_BUFFER_BIT); - PY_DICT_ADD_INT(GL_COLOR_CLEAR_VALUE); - PY_DICT_ADD_INT(GL_COLOR_LOGIC_OP); - PY_DICT_ADD_INT(GL_COLOR_WRITEMASK); - PY_DICT_ADD_INT(GL_COPY); - PY_DICT_ADD_INT(GL_COPY_INVERTED); - PY_DICT_ADD_INT(GL_CULL_FACE); - PY_DICT_ADD_INT(GL_CULL_FACE_MODE); - PY_DICT_ADD_INT(GL_CW); - PY_DICT_ADD_INT(GL_DECR); - PY_DICT_ADD_INT(GL_DEPTH); - PY_DICT_ADD_INT(GL_DEPTH_BUFFER_BIT); - PY_DICT_ADD_INT(GL_DEPTH_CLEAR_VALUE); - PY_DICT_ADD_INT(GL_DEPTH_COMPONENT); - PY_DICT_ADD_INT(GL_DEPTH_FUNC); - PY_DICT_ADD_INT(GL_DEPTH_RANGE); - PY_DICT_ADD_INT(GL_DEPTH_TEST); - PY_DICT_ADD_INT(GL_DEPTH_WRITEMASK); - PY_DICT_ADD_INT(GL_DITHER); - PY_DICT_ADD_INT(GL_DONT_CARE); - PY_DICT_ADD_INT(GL_DOUBLE); - PY_DICT_ADD_INT(GL_DOUBLEBUFFER); - PY_DICT_ADD_INT(GL_DRAW_BUFFER); - PY_DICT_ADD_INT(GL_DST_ALPHA); - PY_DICT_ADD_INT(GL_DST_COLOR); - PY_DICT_ADD_INT(GL_EQUAL); - PY_DICT_ADD_INT(GL_EQUIV); - PY_DICT_ADD_INT(GL_EXTENSIONS); - PY_DICT_ADD_INT(GL_FALSE); - PY_DICT_ADD_INT(GL_FASTEST); - PY_DICT_ADD_INT(GL_FILL); - PY_DICT_ADD_INT(GL_FLOAT); - PY_DICT_ADD_INT(GL_FRONT); - PY_DICT_ADD_INT(GL_FRONT_AND_BACK); - PY_DICT_ADD_INT(GL_FRONT_FACE); - PY_DICT_ADD_INT(GL_FRONT_LEFT); - PY_DICT_ADD_INT(GL_FRONT_RIGHT); - PY_DICT_ADD_INT(GL_GEQUAL); - PY_DICT_ADD_INT(GL_GREATER); - PY_DICT_ADD_INT(GL_GREEN); - PY_DICT_ADD_INT(GL_INCR); - PY_DICT_ADD_INT(GL_INT); - PY_DICT_ADD_INT(GL_INVALID_ENUM); - PY_DICT_ADD_INT(GL_INVALID_OPERATION); - PY_DICT_ADD_INT(GL_INVALID_VALUE); - PY_DICT_ADD_INT(GL_INVERT); - PY_DICT_ADD_INT(GL_KEEP); - PY_DICT_ADD_INT(GL_LEFT); - PY_DICT_ADD_INT(GL_LEQUAL); - PY_DICT_ADD_INT(GL_LESS); - PY_DICT_ADD_INT(GL_LINE); - PY_DICT_ADD_INT(GL_LINEAR); - PY_DICT_ADD_INT(GL_LINEAR_MIPMAP_LINEAR); - PY_DICT_ADD_INT(GL_LINEAR_MIPMAP_NEAREST); - PY_DICT_ADD_INT(GL_LINES); - PY_DICT_ADD_INT(GL_LINE_LOOP); - PY_DICT_ADD_INT(GL_LINE_SMOOTH); - PY_DICT_ADD_INT(GL_LINE_SMOOTH_HINT); - PY_DICT_ADD_INT(GL_LINE_STRIP); - PY_DICT_ADD_INT(GL_LINE_WIDTH); - PY_DICT_ADD_INT(GL_LINE_WIDTH_GRANULARITY); - PY_DICT_ADD_INT(GL_LINE_WIDTH_RANGE); - PY_DICT_ADD_INT(GL_LOGIC_OP_MODE); - PY_DICT_ADD_INT(GL_MAX_TEXTURE_SIZE); - PY_DICT_ADD_INT(GL_MAX_VIEWPORT_DIMS); - PY_DICT_ADD_INT(GL_NAND); - PY_DICT_ADD_INT(GL_NEAREST); - PY_DICT_ADD_INT(GL_NEAREST_MIPMAP_LINEAR); - PY_DICT_ADD_INT(GL_NEAREST_MIPMAP_NEAREST); - PY_DICT_ADD_INT(GL_NEVER); - PY_DICT_ADD_INT(GL_NICEST); - PY_DICT_ADD_INT(GL_NONE); - PY_DICT_ADD_INT(GL_NOOP); - PY_DICT_ADD_INT(GL_NOR); - PY_DICT_ADD_INT(GL_NOTEQUAL); - PY_DICT_ADD_INT(GL_NO_ERROR); - PY_DICT_ADD_INT(GL_ONE); - PY_DICT_ADD_INT(GL_ONE_MINUS_DST_ALPHA); - PY_DICT_ADD_INT(GL_ONE_MINUS_DST_COLOR); - PY_DICT_ADD_INT(GL_ONE_MINUS_SRC_ALPHA); - PY_DICT_ADD_INT(GL_ONE_MINUS_SRC_COLOR); - PY_DICT_ADD_INT(GL_OR); - PY_DICT_ADD_INT(GL_OR_INVERTED); - PY_DICT_ADD_INT(GL_OR_REVERSE); - PY_DICT_ADD_INT(GL_OUT_OF_MEMORY); - PY_DICT_ADD_INT(GL_PACK_ALIGNMENT); - PY_DICT_ADD_INT(GL_PACK_LSB_FIRST); - PY_DICT_ADD_INT(GL_PACK_ROW_LENGTH); - PY_DICT_ADD_INT(GL_PACK_SKIP_PIXELS); - PY_DICT_ADD_INT(GL_PACK_SKIP_ROWS); - PY_DICT_ADD_INT(GL_PACK_SWAP_BYTES); - PY_DICT_ADD_INT(GL_POINT); - PY_DICT_ADD_INT(GL_POINTS); - PY_DICT_ADD_INT(GL_POINT_SIZE); - PY_DICT_ADD_INT(GL_POLYGON_MODE); - PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FACTOR); - PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FILL); - PY_DICT_ADD_INT(GL_POLYGON_OFFSET_LINE); - PY_DICT_ADD_INT(GL_POLYGON_OFFSET_POINT); - PY_DICT_ADD_INT(GL_POLYGON_OFFSET_UNITS); - PY_DICT_ADD_INT(GL_POLYGON_SMOOTH); - PY_DICT_ADD_INT(GL_POLYGON_SMOOTH_HINT); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_1D); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D); - PY_DICT_ADD_INT(GL_R3_G3_B2); - PY_DICT_ADD_INT(GL_READ_BUFFER); - PY_DICT_ADD_INT(GL_RED); - PY_DICT_ADD_INT(GL_RENDERER); - PY_DICT_ADD_INT(GL_REPEAT); - PY_DICT_ADD_INT(GL_REPLACE); - PY_DICT_ADD_INT(GL_RGB); - PY_DICT_ADD_INT(GL_RGB10); - PY_DICT_ADD_INT(GL_RGB10_A2); - PY_DICT_ADD_INT(GL_RGB12); - PY_DICT_ADD_INT(GL_RGB16); - PY_DICT_ADD_INT(GL_RGB4); - PY_DICT_ADD_INT(GL_RGB5); - PY_DICT_ADD_INT(GL_RGB5_A1); - PY_DICT_ADD_INT(GL_RGB8); - PY_DICT_ADD_INT(GL_RGBA); - PY_DICT_ADD_INT(GL_RGBA12); - PY_DICT_ADD_INT(GL_RGBA16); - PY_DICT_ADD_INT(GL_RGBA2); - PY_DICT_ADD_INT(GL_RGBA4); - PY_DICT_ADD_INT(GL_RGBA8); - PY_DICT_ADD_INT(GL_RIGHT); - PY_DICT_ADD_INT(GL_SCISSOR_BOX); - PY_DICT_ADD_INT(GL_SCISSOR_TEST); - PY_DICT_ADD_INT(GL_SET); - PY_DICT_ADD_INT(GL_SHORT); - PY_DICT_ADD_INT(GL_SRC_ALPHA); - PY_DICT_ADD_INT(GL_SRC_ALPHA_SATURATE); - PY_DICT_ADD_INT(GL_SRC_COLOR); - PY_DICT_ADD_INT(GL_STENCIL); - PY_DICT_ADD_INT(GL_STENCIL_BUFFER_BIT); - PY_DICT_ADD_INT(GL_STENCIL_CLEAR_VALUE); - PY_DICT_ADD_INT(GL_STENCIL_FAIL); - PY_DICT_ADD_INT(GL_STENCIL_FUNC); - PY_DICT_ADD_INT(GL_STENCIL_INDEX); - PY_DICT_ADD_INT(GL_STENCIL_PASS_DEPTH_FAIL); - PY_DICT_ADD_INT(GL_STENCIL_PASS_DEPTH_PASS); - PY_DICT_ADD_INT(GL_STENCIL_REF); - PY_DICT_ADD_INT(GL_STENCIL_TEST); - PY_DICT_ADD_INT(GL_STENCIL_VALUE_MASK); - PY_DICT_ADD_INT(GL_STENCIL_WRITEMASK); - PY_DICT_ADD_INT(GL_STEREO); - PY_DICT_ADD_INT(GL_SUBPIXEL_BITS); - PY_DICT_ADD_INT(GL_TEXTURE); - PY_DICT_ADD_INT(GL_TEXTURE_1D); - PY_DICT_ADD_INT(GL_TEXTURE_2D); - PY_DICT_ADD_INT(GL_TEXTURE_ALPHA_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_1D); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D); - PY_DICT_ADD_INT(GL_TEXTURE_BLUE_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_BORDER_COLOR); - PY_DICT_ADD_INT(GL_TEXTURE_GREEN_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_HEIGHT); - PY_DICT_ADD_INT(GL_TEXTURE_INTERNAL_FORMAT); - PY_DICT_ADD_INT(GL_TEXTURE_MAG_FILTER); - PY_DICT_ADD_INT(GL_TEXTURE_MIN_FILTER); - PY_DICT_ADD_INT(GL_TEXTURE_RED_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_WIDTH); - PY_DICT_ADD_INT(GL_TEXTURE_WRAP_S); - PY_DICT_ADD_INT(GL_TEXTURE_WRAP_T); - PY_DICT_ADD_INT(GL_TRIANGLES); - PY_DICT_ADD_INT(GL_TRIANGLE_FAN); - PY_DICT_ADD_INT(GL_TRIANGLE_STRIP); - PY_DICT_ADD_INT(GL_TRUE); - PY_DICT_ADD_INT(GL_UNPACK_ALIGNMENT); - PY_DICT_ADD_INT(GL_UNPACK_LSB_FIRST); - PY_DICT_ADD_INT(GL_UNPACK_ROW_LENGTH); - PY_DICT_ADD_INT(GL_UNPACK_SKIP_PIXELS); - PY_DICT_ADD_INT(GL_UNPACK_SKIP_ROWS); - PY_DICT_ADD_INT(GL_UNPACK_SWAP_BYTES); - PY_DICT_ADD_INT(GL_UNSIGNED_BYTE); - PY_DICT_ADD_INT(GL_UNSIGNED_INT); - PY_DICT_ADD_INT(GL_UNSIGNED_SHORT); - PY_DICT_ADD_INT(GL_VENDOR); - PY_DICT_ADD_INT(GL_VERSION); - PY_DICT_ADD_INT(GL_VIEWPORT); - PY_DICT_ADD_INT(GL_XOR); - PY_DICT_ADD_INT(GL_ZERO); - } - - /* GL_VERSION_1_2 */ - { - PY_DICT_ADD_INT(GL_ALIASED_LINE_WIDTH_RANGE); - PY_DICT_ADD_INT(GL_BGR); - PY_DICT_ADD_INT(GL_BGRA); - PY_DICT_ADD_INT(GL_CLAMP_TO_EDGE); - PY_DICT_ADD_INT(GL_MAX_3D_TEXTURE_SIZE); - PY_DICT_ADD_INT(GL_MAX_ELEMENTS_INDICES); - PY_DICT_ADD_INT(GL_MAX_ELEMENTS_VERTICES); - PY_DICT_ADD_INT(GL_PACK_IMAGE_HEIGHT); - PY_DICT_ADD_INT(GL_PACK_SKIP_IMAGES); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_3D); - PY_DICT_ADD_INT(GL_SMOOTH_LINE_WIDTH_GRANULARITY); - PY_DICT_ADD_INT(GL_SMOOTH_LINE_WIDTH_RANGE); - PY_DICT_ADD_INT(GL_SMOOTH_POINT_SIZE_GRANULARITY); - PY_DICT_ADD_INT(GL_SMOOTH_POINT_SIZE_RANGE); - PY_DICT_ADD_INT(GL_TEXTURE_3D); - PY_DICT_ADD_INT(GL_TEXTURE_BASE_LEVEL); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_3D); - PY_DICT_ADD_INT(GL_TEXTURE_DEPTH); - PY_DICT_ADD_INT(GL_TEXTURE_MAX_LEVEL); - PY_DICT_ADD_INT(GL_TEXTURE_MAX_LOD); - PY_DICT_ADD_INT(GL_TEXTURE_MIN_LOD); - PY_DICT_ADD_INT(GL_TEXTURE_WRAP_R); - PY_DICT_ADD_INT(GL_UNPACK_IMAGE_HEIGHT); - PY_DICT_ADD_INT(GL_UNPACK_SKIP_IMAGES); - PY_DICT_ADD_INT(GL_UNSIGNED_BYTE_2_3_3_REV); - PY_DICT_ADD_INT(GL_UNSIGNED_BYTE_3_3_2); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_10_10_10_2); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_2_10_10_10_REV); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_8_8_8_8); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_8_8_8_8_REV); - PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_1_5_5_5_REV); - PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_4_4_4_4); - PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_4_4_4_4_REV); - PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_5_5_1); - PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5); - PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5_REV); - } - - /* GL_VERSION_1_3 */ - { - PY_DICT_ADD_INT(GL_ACTIVE_TEXTURE); - PY_DICT_ADD_INT(GL_CLAMP_TO_BORDER); - PY_DICT_ADD_INT(GL_COMPRESSED_RGB); - PY_DICT_ADD_INT(GL_COMPRESSED_RGBA); - PY_DICT_ADD_INT(GL_COMPRESSED_TEXTURE_FORMATS); - PY_DICT_ADD_INT(GL_MAX_CUBE_MAP_TEXTURE_SIZE); - PY_DICT_ADD_INT(GL_MULTISAMPLE); - PY_DICT_ADD_INT(GL_NUM_COMPRESSED_TEXTURE_FORMATS); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_CUBE_MAP); - PY_DICT_ADD_INT(GL_SAMPLES); - PY_DICT_ADD_INT(GL_SAMPLE_ALPHA_TO_COVERAGE); - PY_DICT_ADD_INT(GL_SAMPLE_ALPHA_TO_ONE); - PY_DICT_ADD_INT(GL_SAMPLE_BUFFERS); - PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE); - PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE_INVERT); - PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE_VALUE); - PY_DICT_ADD_INT(GL_TEXTURE0); - PY_DICT_ADD_INT(GL_TEXTURE1); - PY_DICT_ADD_INT(GL_TEXTURE10); - PY_DICT_ADD_INT(GL_TEXTURE11); - PY_DICT_ADD_INT(GL_TEXTURE12); - PY_DICT_ADD_INT(GL_TEXTURE13); - PY_DICT_ADD_INT(GL_TEXTURE14); - PY_DICT_ADD_INT(GL_TEXTURE15); - PY_DICT_ADD_INT(GL_TEXTURE16); - PY_DICT_ADD_INT(GL_TEXTURE17); - PY_DICT_ADD_INT(GL_TEXTURE18); - PY_DICT_ADD_INT(GL_TEXTURE19); - PY_DICT_ADD_INT(GL_TEXTURE2); - PY_DICT_ADD_INT(GL_TEXTURE20); - PY_DICT_ADD_INT(GL_TEXTURE21); - PY_DICT_ADD_INT(GL_TEXTURE22); - PY_DICT_ADD_INT(GL_TEXTURE23); - PY_DICT_ADD_INT(GL_TEXTURE24); - PY_DICT_ADD_INT(GL_TEXTURE25); - PY_DICT_ADD_INT(GL_TEXTURE26); - PY_DICT_ADD_INT(GL_TEXTURE27); - PY_DICT_ADD_INT(GL_TEXTURE28); - PY_DICT_ADD_INT(GL_TEXTURE29); - PY_DICT_ADD_INT(GL_TEXTURE3); - PY_DICT_ADD_INT(GL_TEXTURE30); - PY_DICT_ADD_INT(GL_TEXTURE31); - PY_DICT_ADD_INT(GL_TEXTURE4); - PY_DICT_ADD_INT(GL_TEXTURE5); - PY_DICT_ADD_INT(GL_TEXTURE6); - PY_DICT_ADD_INT(GL_TEXTURE7); - PY_DICT_ADD_INT(GL_TEXTURE8); - PY_DICT_ADD_INT(GL_TEXTURE9); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_CUBE_MAP); - PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSED); - PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSED_IMAGE_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSION_HINT); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_X); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z); - } - - /* GL_VERSION_1_4 */ - { - PY_DICT_ADD_INT(GL_BLEND_DST_ALPHA); - PY_DICT_ADD_INT(GL_BLEND_DST_RGB); - PY_DICT_ADD_INT(GL_BLEND_SRC_ALPHA); - PY_DICT_ADD_INT(GL_BLEND_SRC_RGB); - PY_DICT_ADD_INT(GL_CONSTANT_ALPHA); - PY_DICT_ADD_INT(GL_CONSTANT_COLOR); - PY_DICT_ADD_INT(GL_DECR_WRAP); - PY_DICT_ADD_INT(GL_DEPTH_COMPONENT16); - PY_DICT_ADD_INT(GL_DEPTH_COMPONENT24); - PY_DICT_ADD_INT(GL_DEPTH_COMPONENT32); - PY_DICT_ADD_INT(GL_FUNC_ADD); - PY_DICT_ADD_INT(GL_FUNC_REVERSE_SUBTRACT); - PY_DICT_ADD_INT(GL_FUNC_SUBTRACT); - PY_DICT_ADD_INT(GL_INCR_WRAP); - PY_DICT_ADD_INT(GL_MAX); - PY_DICT_ADD_INT(GL_MAX_TEXTURE_LOD_BIAS); - PY_DICT_ADD_INT(GL_MIN); - PY_DICT_ADD_INT(GL_MIRRORED_REPEAT); - PY_DICT_ADD_INT(GL_ONE_MINUS_CONSTANT_ALPHA); - PY_DICT_ADD_INT(GL_ONE_MINUS_CONSTANT_COLOR); - PY_DICT_ADD_INT(GL_POINT_FADE_THRESHOLD_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_COMPARE_FUNC); - PY_DICT_ADD_INT(GL_TEXTURE_COMPARE_MODE); - PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_LOD_BIAS); - } - - /* GL_VERSION_1_5 */ - { - PY_DICT_ADD_INT(GL_ARRAY_BUFFER); - PY_DICT_ADD_INT(GL_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_BUFFER_ACCESS); - PY_DICT_ADD_INT(GL_BUFFER_MAPPED); - PY_DICT_ADD_INT(GL_BUFFER_MAP_POINTER); - PY_DICT_ADD_INT(GL_BUFFER_SIZE); - PY_DICT_ADD_INT(GL_BUFFER_USAGE); - PY_DICT_ADD_INT(GL_CURRENT_QUERY); - PY_DICT_ADD_INT(GL_DYNAMIC_COPY); - PY_DICT_ADD_INT(GL_DYNAMIC_DRAW); - PY_DICT_ADD_INT(GL_DYNAMIC_READ); - PY_DICT_ADD_INT(GL_ELEMENT_ARRAY_BUFFER); - PY_DICT_ADD_INT(GL_ELEMENT_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_QUERY_COUNTER_BITS); - PY_DICT_ADD_INT(GL_QUERY_RESULT); - PY_DICT_ADD_INT(GL_QUERY_RESULT_AVAILABLE); - PY_DICT_ADD_INT(GL_READ_ONLY); - PY_DICT_ADD_INT(GL_READ_WRITE); - PY_DICT_ADD_INT(GL_SAMPLES_PASSED); - PY_DICT_ADD_INT(GL_STATIC_COPY); - PY_DICT_ADD_INT(GL_STATIC_DRAW); - PY_DICT_ADD_INT(GL_STATIC_READ); - PY_DICT_ADD_INT(GL_STREAM_COPY); - PY_DICT_ADD_INT(GL_STREAM_DRAW); - PY_DICT_ADD_INT(GL_STREAM_READ); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_WRITE_ONLY); - } - - /* GL_VERSION_2_0 */ - { - PY_DICT_ADD_INT(GL_ACTIVE_ATTRIBUTES); - PY_DICT_ADD_INT(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH); - PY_DICT_ADD_INT(GL_ACTIVE_UNIFORMS); - PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_MAX_LENGTH); - PY_DICT_ADD_INT(GL_ATTACHED_SHADERS); - PY_DICT_ADD_INT(GL_BLEND_EQUATION_ALPHA); - PY_DICT_ADD_INT(GL_BLEND_EQUATION_RGB); - PY_DICT_ADD_INT(GL_BOOL); - PY_DICT_ADD_INT(GL_BOOL_VEC2); - PY_DICT_ADD_INT(GL_BOOL_VEC3); - PY_DICT_ADD_INT(GL_BOOL_VEC4); - PY_DICT_ADD_INT(GL_COMPILE_STATUS); - PY_DICT_ADD_INT(GL_CURRENT_PROGRAM); - PY_DICT_ADD_INT(GL_CURRENT_VERTEX_ATTRIB); - PY_DICT_ADD_INT(GL_DELETE_STATUS); - PY_DICT_ADD_INT(GL_DRAW_BUFFER0); - PY_DICT_ADD_INT(GL_DRAW_BUFFER1); - PY_DICT_ADD_INT(GL_DRAW_BUFFER10); - PY_DICT_ADD_INT(GL_DRAW_BUFFER11); - PY_DICT_ADD_INT(GL_DRAW_BUFFER12); - PY_DICT_ADD_INT(GL_DRAW_BUFFER13); - PY_DICT_ADD_INT(GL_DRAW_BUFFER14); - PY_DICT_ADD_INT(GL_DRAW_BUFFER15); - PY_DICT_ADD_INT(GL_DRAW_BUFFER2); - PY_DICT_ADD_INT(GL_DRAW_BUFFER3); - PY_DICT_ADD_INT(GL_DRAW_BUFFER4); - PY_DICT_ADD_INT(GL_DRAW_BUFFER5); - PY_DICT_ADD_INT(GL_DRAW_BUFFER6); - PY_DICT_ADD_INT(GL_DRAW_BUFFER7); - PY_DICT_ADD_INT(GL_DRAW_BUFFER8); - PY_DICT_ADD_INT(GL_DRAW_BUFFER9); - PY_DICT_ADD_INT(GL_FLOAT_MAT2); - PY_DICT_ADD_INT(GL_FLOAT_MAT3); - PY_DICT_ADD_INT(GL_FLOAT_MAT4); - PY_DICT_ADD_INT(GL_FLOAT_VEC2); - PY_DICT_ADD_INT(GL_FLOAT_VEC3); - PY_DICT_ADD_INT(GL_FLOAT_VEC4); - PY_DICT_ADD_INT(GL_FRAGMENT_SHADER); - PY_DICT_ADD_INT(GL_FRAGMENT_SHADER_DERIVATIVE_HINT); - PY_DICT_ADD_INT(GL_INFO_LOG_LENGTH); - PY_DICT_ADD_INT(GL_INT_VEC2); - PY_DICT_ADD_INT(GL_INT_VEC3); - PY_DICT_ADD_INT(GL_INT_VEC4); - PY_DICT_ADD_INT(GL_LINK_STATUS); - PY_DICT_ADD_INT(GL_LOWER_LEFT); - PY_DICT_ADD_INT(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS); - PY_DICT_ADD_INT(GL_MAX_DRAW_BUFFERS); - PY_DICT_ADD_INT(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_TEXTURE_IMAGE_UNITS); - PY_DICT_ADD_INT(GL_MAX_VARYING_FLOATS); - PY_DICT_ADD_INT(GL_MAX_VERTEX_ATTRIBS); - PY_DICT_ADD_INT(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS); - PY_DICT_ADD_INT(GL_MAX_VERTEX_UNIFORM_COMPONENTS); - PY_DICT_ADD_INT(GL_POINT_SPRITE_COORD_ORIGIN); - PY_DICT_ADD_INT(GL_SAMPLER_1D); - PY_DICT_ADD_INT(GL_SAMPLER_1D_SHADOW); - PY_DICT_ADD_INT(GL_SAMPLER_2D); - PY_DICT_ADD_INT(GL_SAMPLER_2D_SHADOW); - PY_DICT_ADD_INT(GL_SAMPLER_3D); - PY_DICT_ADD_INT(GL_SAMPLER_CUBE); - PY_DICT_ADD_INT(GL_SHADER_SOURCE_LENGTH); - PY_DICT_ADD_INT(GL_SHADER_TYPE); - PY_DICT_ADD_INT(GL_SHADING_LANGUAGE_VERSION); - PY_DICT_ADD_INT(GL_STENCIL_BACK_FAIL); - PY_DICT_ADD_INT(GL_STENCIL_BACK_FUNC); - PY_DICT_ADD_INT(GL_STENCIL_BACK_PASS_DEPTH_FAIL); - PY_DICT_ADD_INT(GL_STENCIL_BACK_PASS_DEPTH_PASS); - PY_DICT_ADD_INT(GL_STENCIL_BACK_REF); - PY_DICT_ADD_INT(GL_STENCIL_BACK_VALUE_MASK); - PY_DICT_ADD_INT(GL_STENCIL_BACK_WRITEMASK); - PY_DICT_ADD_INT(GL_UPPER_LEFT); - PY_DICT_ADD_INT(GL_VALIDATE_STATUS); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_ENABLED); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_NORMALIZED); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_SIZE); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_VERTEX_PROGRAM_POINT_SIZE); - PY_DICT_ADD_INT(GL_VERTEX_SHADER); - } - - /* GL_VERSION_2_1 */ - { - PY_DICT_ADD_INT(GL_COMPRESSED_SRGB); - PY_DICT_ADD_INT(GL_COMPRESSED_SRGB_ALPHA); - PY_DICT_ADD_INT(GL_FLOAT_MAT2x3); - PY_DICT_ADD_INT(GL_FLOAT_MAT2x4); - PY_DICT_ADD_INT(GL_FLOAT_MAT3x2); - PY_DICT_ADD_INT(GL_FLOAT_MAT3x4); - PY_DICT_ADD_INT(GL_FLOAT_MAT4x2); - PY_DICT_ADD_INT(GL_FLOAT_MAT4x3); - PY_DICT_ADD_INT(GL_PIXEL_PACK_BUFFER); - PY_DICT_ADD_INT(GL_PIXEL_PACK_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_PIXEL_UNPACK_BUFFER); - PY_DICT_ADD_INT(GL_PIXEL_UNPACK_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_SRGB); - PY_DICT_ADD_INT(GL_SRGB8); - PY_DICT_ADD_INT(GL_SRGB8_ALPHA8); - PY_DICT_ADD_INT(GL_SRGB_ALPHA); - } - - /* GL_VERSION_3_0 */ - { - PY_DICT_ADD_INT(GL_BGRA_INTEGER); - PY_DICT_ADD_INT(GL_BGR_INTEGER); - PY_DICT_ADD_INT(GL_BLUE_INTEGER); - PY_DICT_ADD_INT(GL_BUFFER_ACCESS_FLAGS); - PY_DICT_ADD_INT(GL_BUFFER_MAP_LENGTH); - PY_DICT_ADD_INT(GL_BUFFER_MAP_OFFSET); - PY_DICT_ADD_INT(GL_CLAMP_READ_COLOR); - PY_DICT_ADD_INT(GL_CLIP_DISTANCE0); - PY_DICT_ADD_INT(GL_CLIP_DISTANCE1); - PY_DICT_ADD_INT(GL_CLIP_DISTANCE2); - PY_DICT_ADD_INT(GL_CLIP_DISTANCE3); - PY_DICT_ADD_INT(GL_CLIP_DISTANCE4); - PY_DICT_ADD_INT(GL_CLIP_DISTANCE5); + /* GL_VERSION_1_1 */ + { + PY_DICT_ADD_INT(GL_ALPHA); + PY_DICT_ADD_INT(GL_ALWAYS); + PY_DICT_ADD_INT(GL_AND); + PY_DICT_ADD_INT(GL_AND_INVERTED); + PY_DICT_ADD_INT(GL_AND_REVERSE); + PY_DICT_ADD_INT(GL_BACK); + PY_DICT_ADD_INT(GL_BACK_LEFT); + PY_DICT_ADD_INT(GL_BACK_RIGHT); + PY_DICT_ADD_INT(GL_BLEND); + PY_DICT_ADD_INT(GL_BLEND_DST); + PY_DICT_ADD_INT(GL_BLEND_SRC); + PY_DICT_ADD_INT(GL_BLUE); + PY_DICT_ADD_INT(GL_BYTE); + PY_DICT_ADD_INT(GL_CCW); + PY_DICT_ADD_INT(GL_CLEAR); + PY_DICT_ADD_INT(GL_COLOR); + PY_DICT_ADD_INT(GL_COLOR_BUFFER_BIT); + PY_DICT_ADD_INT(GL_COLOR_CLEAR_VALUE); + PY_DICT_ADD_INT(GL_COLOR_LOGIC_OP); + PY_DICT_ADD_INT(GL_COLOR_WRITEMASK); + PY_DICT_ADD_INT(GL_COPY); + PY_DICT_ADD_INT(GL_COPY_INVERTED); + PY_DICT_ADD_INT(GL_CULL_FACE); + PY_DICT_ADD_INT(GL_CULL_FACE_MODE); + PY_DICT_ADD_INT(GL_CW); + PY_DICT_ADD_INT(GL_DECR); + PY_DICT_ADD_INT(GL_DEPTH); + PY_DICT_ADD_INT(GL_DEPTH_BUFFER_BIT); + PY_DICT_ADD_INT(GL_DEPTH_CLEAR_VALUE); + PY_DICT_ADD_INT(GL_DEPTH_COMPONENT); + PY_DICT_ADD_INT(GL_DEPTH_FUNC); + PY_DICT_ADD_INT(GL_DEPTH_RANGE); + PY_DICT_ADD_INT(GL_DEPTH_TEST); + PY_DICT_ADD_INT(GL_DEPTH_WRITEMASK); + PY_DICT_ADD_INT(GL_DITHER); + PY_DICT_ADD_INT(GL_DONT_CARE); + PY_DICT_ADD_INT(GL_DOUBLE); + PY_DICT_ADD_INT(GL_DOUBLEBUFFER); + PY_DICT_ADD_INT(GL_DRAW_BUFFER); + PY_DICT_ADD_INT(GL_DST_ALPHA); + PY_DICT_ADD_INT(GL_DST_COLOR); + PY_DICT_ADD_INT(GL_EQUAL); + PY_DICT_ADD_INT(GL_EQUIV); + PY_DICT_ADD_INT(GL_EXTENSIONS); + PY_DICT_ADD_INT(GL_FALSE); + PY_DICT_ADD_INT(GL_FASTEST); + PY_DICT_ADD_INT(GL_FILL); + PY_DICT_ADD_INT(GL_FLOAT); + PY_DICT_ADD_INT(GL_FRONT); + PY_DICT_ADD_INT(GL_FRONT_AND_BACK); + PY_DICT_ADD_INT(GL_FRONT_FACE); + PY_DICT_ADD_INT(GL_FRONT_LEFT); + PY_DICT_ADD_INT(GL_FRONT_RIGHT); + PY_DICT_ADD_INT(GL_GEQUAL); + PY_DICT_ADD_INT(GL_GREATER); + PY_DICT_ADD_INT(GL_GREEN); + PY_DICT_ADD_INT(GL_INCR); + PY_DICT_ADD_INT(GL_INT); + PY_DICT_ADD_INT(GL_INVALID_ENUM); + PY_DICT_ADD_INT(GL_INVALID_OPERATION); + PY_DICT_ADD_INT(GL_INVALID_VALUE); + PY_DICT_ADD_INT(GL_INVERT); + PY_DICT_ADD_INT(GL_KEEP); + PY_DICT_ADD_INT(GL_LEFT); + PY_DICT_ADD_INT(GL_LEQUAL); + PY_DICT_ADD_INT(GL_LESS); + PY_DICT_ADD_INT(GL_LINE); + PY_DICT_ADD_INT(GL_LINEAR); + PY_DICT_ADD_INT(GL_LINEAR_MIPMAP_LINEAR); + PY_DICT_ADD_INT(GL_LINEAR_MIPMAP_NEAREST); + PY_DICT_ADD_INT(GL_LINES); + PY_DICT_ADD_INT(GL_LINE_LOOP); + PY_DICT_ADD_INT(GL_LINE_SMOOTH); + PY_DICT_ADD_INT(GL_LINE_SMOOTH_HINT); + PY_DICT_ADD_INT(GL_LINE_STRIP); + PY_DICT_ADD_INT(GL_LINE_WIDTH); + PY_DICT_ADD_INT(GL_LINE_WIDTH_GRANULARITY); + PY_DICT_ADD_INT(GL_LINE_WIDTH_RANGE); + PY_DICT_ADD_INT(GL_LOGIC_OP_MODE); + PY_DICT_ADD_INT(GL_MAX_TEXTURE_SIZE); + PY_DICT_ADD_INT(GL_MAX_VIEWPORT_DIMS); + PY_DICT_ADD_INT(GL_NAND); + PY_DICT_ADD_INT(GL_NEAREST); + PY_DICT_ADD_INT(GL_NEAREST_MIPMAP_LINEAR); + PY_DICT_ADD_INT(GL_NEAREST_MIPMAP_NEAREST); + PY_DICT_ADD_INT(GL_NEVER); + PY_DICT_ADD_INT(GL_NICEST); + PY_DICT_ADD_INT(GL_NONE); + PY_DICT_ADD_INT(GL_NOOP); + PY_DICT_ADD_INT(GL_NOR); + PY_DICT_ADD_INT(GL_NOTEQUAL); + PY_DICT_ADD_INT(GL_NO_ERROR); + PY_DICT_ADD_INT(GL_ONE); + PY_DICT_ADD_INT(GL_ONE_MINUS_DST_ALPHA); + PY_DICT_ADD_INT(GL_ONE_MINUS_DST_COLOR); + PY_DICT_ADD_INT(GL_ONE_MINUS_SRC_ALPHA); + PY_DICT_ADD_INT(GL_ONE_MINUS_SRC_COLOR); + PY_DICT_ADD_INT(GL_OR); + PY_DICT_ADD_INT(GL_OR_INVERTED); + PY_DICT_ADD_INT(GL_OR_REVERSE); + PY_DICT_ADD_INT(GL_OUT_OF_MEMORY); + PY_DICT_ADD_INT(GL_PACK_ALIGNMENT); + PY_DICT_ADD_INT(GL_PACK_LSB_FIRST); + PY_DICT_ADD_INT(GL_PACK_ROW_LENGTH); + PY_DICT_ADD_INT(GL_PACK_SKIP_PIXELS); + PY_DICT_ADD_INT(GL_PACK_SKIP_ROWS); + PY_DICT_ADD_INT(GL_PACK_SWAP_BYTES); + PY_DICT_ADD_INT(GL_POINT); + PY_DICT_ADD_INT(GL_POINTS); + PY_DICT_ADD_INT(GL_POINT_SIZE); + PY_DICT_ADD_INT(GL_POLYGON_MODE); + PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FACTOR); + PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FILL); + PY_DICT_ADD_INT(GL_POLYGON_OFFSET_LINE); + PY_DICT_ADD_INT(GL_POLYGON_OFFSET_POINT); + PY_DICT_ADD_INT(GL_POLYGON_OFFSET_UNITS); + PY_DICT_ADD_INT(GL_POLYGON_SMOOTH); + PY_DICT_ADD_INT(GL_POLYGON_SMOOTH_HINT); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_1D); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D); + PY_DICT_ADD_INT(GL_R3_G3_B2); + PY_DICT_ADD_INT(GL_READ_BUFFER); + PY_DICT_ADD_INT(GL_RED); + PY_DICT_ADD_INT(GL_RENDERER); + PY_DICT_ADD_INT(GL_REPEAT); + PY_DICT_ADD_INT(GL_REPLACE); + PY_DICT_ADD_INT(GL_RGB); + PY_DICT_ADD_INT(GL_RGB10); + PY_DICT_ADD_INT(GL_RGB10_A2); + PY_DICT_ADD_INT(GL_RGB12); + PY_DICT_ADD_INT(GL_RGB16); + PY_DICT_ADD_INT(GL_RGB4); + PY_DICT_ADD_INT(GL_RGB5); + PY_DICT_ADD_INT(GL_RGB5_A1); + PY_DICT_ADD_INT(GL_RGB8); + PY_DICT_ADD_INT(GL_RGBA); + PY_DICT_ADD_INT(GL_RGBA12); + PY_DICT_ADD_INT(GL_RGBA16); + PY_DICT_ADD_INT(GL_RGBA2); + PY_DICT_ADD_INT(GL_RGBA4); + PY_DICT_ADD_INT(GL_RGBA8); + PY_DICT_ADD_INT(GL_RIGHT); + PY_DICT_ADD_INT(GL_SCISSOR_BOX); + PY_DICT_ADD_INT(GL_SCISSOR_TEST); + PY_DICT_ADD_INT(GL_SET); + PY_DICT_ADD_INT(GL_SHORT); + PY_DICT_ADD_INT(GL_SRC_ALPHA); + PY_DICT_ADD_INT(GL_SRC_ALPHA_SATURATE); + PY_DICT_ADD_INT(GL_SRC_COLOR); + PY_DICT_ADD_INT(GL_STENCIL); + PY_DICT_ADD_INT(GL_STENCIL_BUFFER_BIT); + PY_DICT_ADD_INT(GL_STENCIL_CLEAR_VALUE); + PY_DICT_ADD_INT(GL_STENCIL_FAIL); + PY_DICT_ADD_INT(GL_STENCIL_FUNC); + PY_DICT_ADD_INT(GL_STENCIL_INDEX); + PY_DICT_ADD_INT(GL_STENCIL_PASS_DEPTH_FAIL); + PY_DICT_ADD_INT(GL_STENCIL_PASS_DEPTH_PASS); + PY_DICT_ADD_INT(GL_STENCIL_REF); + PY_DICT_ADD_INT(GL_STENCIL_TEST); + PY_DICT_ADD_INT(GL_STENCIL_VALUE_MASK); + PY_DICT_ADD_INT(GL_STENCIL_WRITEMASK); + PY_DICT_ADD_INT(GL_STEREO); + PY_DICT_ADD_INT(GL_SUBPIXEL_BITS); + PY_DICT_ADD_INT(GL_TEXTURE); + PY_DICT_ADD_INT(GL_TEXTURE_1D); + PY_DICT_ADD_INT(GL_TEXTURE_2D); + PY_DICT_ADD_INT(GL_TEXTURE_ALPHA_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_1D); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D); + PY_DICT_ADD_INT(GL_TEXTURE_BLUE_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_BORDER_COLOR); + PY_DICT_ADD_INT(GL_TEXTURE_GREEN_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_HEIGHT); + PY_DICT_ADD_INT(GL_TEXTURE_INTERNAL_FORMAT); + PY_DICT_ADD_INT(GL_TEXTURE_MAG_FILTER); + PY_DICT_ADD_INT(GL_TEXTURE_MIN_FILTER); + PY_DICT_ADD_INT(GL_TEXTURE_RED_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_WIDTH); + PY_DICT_ADD_INT(GL_TEXTURE_WRAP_S); + PY_DICT_ADD_INT(GL_TEXTURE_WRAP_T); + PY_DICT_ADD_INT(GL_TRIANGLES); + PY_DICT_ADD_INT(GL_TRIANGLE_FAN); + PY_DICT_ADD_INT(GL_TRIANGLE_STRIP); + PY_DICT_ADD_INT(GL_TRUE); + PY_DICT_ADD_INT(GL_UNPACK_ALIGNMENT); + PY_DICT_ADD_INT(GL_UNPACK_LSB_FIRST); + PY_DICT_ADD_INT(GL_UNPACK_ROW_LENGTH); + PY_DICT_ADD_INT(GL_UNPACK_SKIP_PIXELS); + PY_DICT_ADD_INT(GL_UNPACK_SKIP_ROWS); + PY_DICT_ADD_INT(GL_UNPACK_SWAP_BYTES); + PY_DICT_ADD_INT(GL_UNSIGNED_BYTE); + PY_DICT_ADD_INT(GL_UNSIGNED_INT); + PY_DICT_ADD_INT(GL_UNSIGNED_SHORT); + PY_DICT_ADD_INT(GL_VENDOR); + PY_DICT_ADD_INT(GL_VERSION); + PY_DICT_ADD_INT(GL_VIEWPORT); + PY_DICT_ADD_INT(GL_XOR); + PY_DICT_ADD_INT(GL_ZERO); + } + + /* GL_VERSION_1_2 */ + { + PY_DICT_ADD_INT(GL_ALIASED_LINE_WIDTH_RANGE); + PY_DICT_ADD_INT(GL_BGR); + PY_DICT_ADD_INT(GL_BGRA); + PY_DICT_ADD_INT(GL_CLAMP_TO_EDGE); + PY_DICT_ADD_INT(GL_MAX_3D_TEXTURE_SIZE); + PY_DICT_ADD_INT(GL_MAX_ELEMENTS_INDICES); + PY_DICT_ADD_INT(GL_MAX_ELEMENTS_VERTICES); + PY_DICT_ADD_INT(GL_PACK_IMAGE_HEIGHT); + PY_DICT_ADD_INT(GL_PACK_SKIP_IMAGES); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_3D); + PY_DICT_ADD_INT(GL_SMOOTH_LINE_WIDTH_GRANULARITY); + PY_DICT_ADD_INT(GL_SMOOTH_LINE_WIDTH_RANGE); + PY_DICT_ADD_INT(GL_SMOOTH_POINT_SIZE_GRANULARITY); + PY_DICT_ADD_INT(GL_SMOOTH_POINT_SIZE_RANGE); + PY_DICT_ADD_INT(GL_TEXTURE_3D); + PY_DICT_ADD_INT(GL_TEXTURE_BASE_LEVEL); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_3D); + PY_DICT_ADD_INT(GL_TEXTURE_DEPTH); + PY_DICT_ADD_INT(GL_TEXTURE_MAX_LEVEL); + PY_DICT_ADD_INT(GL_TEXTURE_MAX_LOD); + PY_DICT_ADD_INT(GL_TEXTURE_MIN_LOD); + PY_DICT_ADD_INT(GL_TEXTURE_WRAP_R); + PY_DICT_ADD_INT(GL_UNPACK_IMAGE_HEIGHT); + PY_DICT_ADD_INT(GL_UNPACK_SKIP_IMAGES); + PY_DICT_ADD_INT(GL_UNSIGNED_BYTE_2_3_3_REV); + PY_DICT_ADD_INT(GL_UNSIGNED_BYTE_3_3_2); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_10_10_10_2); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_2_10_10_10_REV); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_8_8_8_8); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_8_8_8_8_REV); + PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_1_5_5_5_REV); + PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_4_4_4_4); + PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_4_4_4_4_REV); + PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_5_5_1); + PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5); + PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5_REV); + } + + /* GL_VERSION_1_3 */ + { + PY_DICT_ADD_INT(GL_ACTIVE_TEXTURE); + PY_DICT_ADD_INT(GL_CLAMP_TO_BORDER); + PY_DICT_ADD_INT(GL_COMPRESSED_RGB); + PY_DICT_ADD_INT(GL_COMPRESSED_RGBA); + PY_DICT_ADD_INT(GL_COMPRESSED_TEXTURE_FORMATS); + PY_DICT_ADD_INT(GL_MAX_CUBE_MAP_TEXTURE_SIZE); + PY_DICT_ADD_INT(GL_MULTISAMPLE); + PY_DICT_ADD_INT(GL_NUM_COMPRESSED_TEXTURE_FORMATS); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_CUBE_MAP); + PY_DICT_ADD_INT(GL_SAMPLES); + PY_DICT_ADD_INT(GL_SAMPLE_ALPHA_TO_COVERAGE); + PY_DICT_ADD_INT(GL_SAMPLE_ALPHA_TO_ONE); + PY_DICT_ADD_INT(GL_SAMPLE_BUFFERS); + PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE); + PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE_INVERT); + PY_DICT_ADD_INT(GL_SAMPLE_COVERAGE_VALUE); + PY_DICT_ADD_INT(GL_TEXTURE0); + PY_DICT_ADD_INT(GL_TEXTURE1); + PY_DICT_ADD_INT(GL_TEXTURE10); + PY_DICT_ADD_INT(GL_TEXTURE11); + PY_DICT_ADD_INT(GL_TEXTURE12); + PY_DICT_ADD_INT(GL_TEXTURE13); + PY_DICT_ADD_INT(GL_TEXTURE14); + PY_DICT_ADD_INT(GL_TEXTURE15); + PY_DICT_ADD_INT(GL_TEXTURE16); + PY_DICT_ADD_INT(GL_TEXTURE17); + PY_DICT_ADD_INT(GL_TEXTURE18); + PY_DICT_ADD_INT(GL_TEXTURE19); + PY_DICT_ADD_INT(GL_TEXTURE2); + PY_DICT_ADD_INT(GL_TEXTURE20); + PY_DICT_ADD_INT(GL_TEXTURE21); + PY_DICT_ADD_INT(GL_TEXTURE22); + PY_DICT_ADD_INT(GL_TEXTURE23); + PY_DICT_ADD_INT(GL_TEXTURE24); + PY_DICT_ADD_INT(GL_TEXTURE25); + PY_DICT_ADD_INT(GL_TEXTURE26); + PY_DICT_ADD_INT(GL_TEXTURE27); + PY_DICT_ADD_INT(GL_TEXTURE28); + PY_DICT_ADD_INT(GL_TEXTURE29); + PY_DICT_ADD_INT(GL_TEXTURE3); + PY_DICT_ADD_INT(GL_TEXTURE30); + PY_DICT_ADD_INT(GL_TEXTURE31); + PY_DICT_ADD_INT(GL_TEXTURE4); + PY_DICT_ADD_INT(GL_TEXTURE5); + PY_DICT_ADD_INT(GL_TEXTURE6); + PY_DICT_ADD_INT(GL_TEXTURE7); + PY_DICT_ADD_INT(GL_TEXTURE8); + PY_DICT_ADD_INT(GL_TEXTURE9); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_CUBE_MAP); + PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSED); + PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSED_IMAGE_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_COMPRESSION_HINT); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_X); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z); + } + + /* GL_VERSION_1_4 */ + { + PY_DICT_ADD_INT(GL_BLEND_DST_ALPHA); + PY_DICT_ADD_INT(GL_BLEND_DST_RGB); + PY_DICT_ADD_INT(GL_BLEND_SRC_ALPHA); + PY_DICT_ADD_INT(GL_BLEND_SRC_RGB); + PY_DICT_ADD_INT(GL_CONSTANT_ALPHA); + PY_DICT_ADD_INT(GL_CONSTANT_COLOR); + PY_DICT_ADD_INT(GL_DECR_WRAP); + PY_DICT_ADD_INT(GL_DEPTH_COMPONENT16); + PY_DICT_ADD_INT(GL_DEPTH_COMPONENT24); + PY_DICT_ADD_INT(GL_DEPTH_COMPONENT32); + PY_DICT_ADD_INT(GL_FUNC_ADD); + PY_DICT_ADD_INT(GL_FUNC_REVERSE_SUBTRACT); + PY_DICT_ADD_INT(GL_FUNC_SUBTRACT); + PY_DICT_ADD_INT(GL_INCR_WRAP); + PY_DICT_ADD_INT(GL_MAX); + PY_DICT_ADD_INT(GL_MAX_TEXTURE_LOD_BIAS); + PY_DICT_ADD_INT(GL_MIN); + PY_DICT_ADD_INT(GL_MIRRORED_REPEAT); + PY_DICT_ADD_INT(GL_ONE_MINUS_CONSTANT_ALPHA); + PY_DICT_ADD_INT(GL_ONE_MINUS_CONSTANT_COLOR); + PY_DICT_ADD_INT(GL_POINT_FADE_THRESHOLD_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_COMPARE_FUNC); + PY_DICT_ADD_INT(GL_TEXTURE_COMPARE_MODE); + PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_LOD_BIAS); + } + + /* GL_VERSION_1_5 */ + { + PY_DICT_ADD_INT(GL_ARRAY_BUFFER); + PY_DICT_ADD_INT(GL_ARRAY_BUFFER_BINDING); + PY_DICT_ADD_INT(GL_BUFFER_ACCESS); + PY_DICT_ADD_INT(GL_BUFFER_MAPPED); + PY_DICT_ADD_INT(GL_BUFFER_MAP_POINTER); + PY_DICT_ADD_INT(GL_BUFFER_SIZE); + PY_DICT_ADD_INT(GL_BUFFER_USAGE); + PY_DICT_ADD_INT(GL_CURRENT_QUERY); + PY_DICT_ADD_INT(GL_DYNAMIC_COPY); + PY_DICT_ADD_INT(GL_DYNAMIC_DRAW); + PY_DICT_ADD_INT(GL_DYNAMIC_READ); + PY_DICT_ADD_INT(GL_ELEMENT_ARRAY_BUFFER); + PY_DICT_ADD_INT(GL_ELEMENT_ARRAY_BUFFER_BINDING); + PY_DICT_ADD_INT(GL_QUERY_COUNTER_BITS); + PY_DICT_ADD_INT(GL_QUERY_RESULT); + PY_DICT_ADD_INT(GL_QUERY_RESULT_AVAILABLE); + PY_DICT_ADD_INT(GL_READ_ONLY); + PY_DICT_ADD_INT(GL_READ_WRITE); + PY_DICT_ADD_INT(GL_SAMPLES_PASSED); + PY_DICT_ADD_INT(GL_STATIC_COPY); + PY_DICT_ADD_INT(GL_STATIC_DRAW); + PY_DICT_ADD_INT(GL_STATIC_READ); + PY_DICT_ADD_INT(GL_STREAM_COPY); + PY_DICT_ADD_INT(GL_STREAM_DRAW); + PY_DICT_ADD_INT(GL_STREAM_READ); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING); + PY_DICT_ADD_INT(GL_WRITE_ONLY); + } + + /* GL_VERSION_2_0 */ + { + PY_DICT_ADD_INT(GL_ACTIVE_ATTRIBUTES); + PY_DICT_ADD_INT(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH); + PY_DICT_ADD_INT(GL_ACTIVE_UNIFORMS); + PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_MAX_LENGTH); + PY_DICT_ADD_INT(GL_ATTACHED_SHADERS); + PY_DICT_ADD_INT(GL_BLEND_EQUATION_ALPHA); + PY_DICT_ADD_INT(GL_BLEND_EQUATION_RGB); + PY_DICT_ADD_INT(GL_BOOL); + PY_DICT_ADD_INT(GL_BOOL_VEC2); + PY_DICT_ADD_INT(GL_BOOL_VEC3); + PY_DICT_ADD_INT(GL_BOOL_VEC4); + PY_DICT_ADD_INT(GL_COMPILE_STATUS); + PY_DICT_ADD_INT(GL_CURRENT_PROGRAM); + PY_DICT_ADD_INT(GL_CURRENT_VERTEX_ATTRIB); + PY_DICT_ADD_INT(GL_DELETE_STATUS); + PY_DICT_ADD_INT(GL_DRAW_BUFFER0); + PY_DICT_ADD_INT(GL_DRAW_BUFFER1); + PY_DICT_ADD_INT(GL_DRAW_BUFFER10); + PY_DICT_ADD_INT(GL_DRAW_BUFFER11); + PY_DICT_ADD_INT(GL_DRAW_BUFFER12); + PY_DICT_ADD_INT(GL_DRAW_BUFFER13); + PY_DICT_ADD_INT(GL_DRAW_BUFFER14); + PY_DICT_ADD_INT(GL_DRAW_BUFFER15); + PY_DICT_ADD_INT(GL_DRAW_BUFFER2); + PY_DICT_ADD_INT(GL_DRAW_BUFFER3); + PY_DICT_ADD_INT(GL_DRAW_BUFFER4); + PY_DICT_ADD_INT(GL_DRAW_BUFFER5); + PY_DICT_ADD_INT(GL_DRAW_BUFFER6); + PY_DICT_ADD_INT(GL_DRAW_BUFFER7); + PY_DICT_ADD_INT(GL_DRAW_BUFFER8); + PY_DICT_ADD_INT(GL_DRAW_BUFFER9); + PY_DICT_ADD_INT(GL_FLOAT_MAT2); + PY_DICT_ADD_INT(GL_FLOAT_MAT3); + PY_DICT_ADD_INT(GL_FLOAT_MAT4); + PY_DICT_ADD_INT(GL_FLOAT_VEC2); + PY_DICT_ADD_INT(GL_FLOAT_VEC3); + PY_DICT_ADD_INT(GL_FLOAT_VEC4); + PY_DICT_ADD_INT(GL_FRAGMENT_SHADER); + PY_DICT_ADD_INT(GL_FRAGMENT_SHADER_DERIVATIVE_HINT); + PY_DICT_ADD_INT(GL_INFO_LOG_LENGTH); + PY_DICT_ADD_INT(GL_INT_VEC2); + PY_DICT_ADD_INT(GL_INT_VEC3); + PY_DICT_ADD_INT(GL_INT_VEC4); + PY_DICT_ADD_INT(GL_LINK_STATUS); + PY_DICT_ADD_INT(GL_LOWER_LEFT); + PY_DICT_ADD_INT(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS); + PY_DICT_ADD_INT(GL_MAX_DRAW_BUFFERS); + PY_DICT_ADD_INT(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_TEXTURE_IMAGE_UNITS); + PY_DICT_ADD_INT(GL_MAX_VARYING_FLOATS); + PY_DICT_ADD_INT(GL_MAX_VERTEX_ATTRIBS); + PY_DICT_ADD_INT(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS); + PY_DICT_ADD_INT(GL_MAX_VERTEX_UNIFORM_COMPONENTS); + PY_DICT_ADD_INT(GL_POINT_SPRITE_COORD_ORIGIN); + PY_DICT_ADD_INT(GL_SAMPLER_1D); + PY_DICT_ADD_INT(GL_SAMPLER_1D_SHADOW); + PY_DICT_ADD_INT(GL_SAMPLER_2D); + PY_DICT_ADD_INT(GL_SAMPLER_2D_SHADOW); + PY_DICT_ADD_INT(GL_SAMPLER_3D); + PY_DICT_ADD_INT(GL_SAMPLER_CUBE); + PY_DICT_ADD_INT(GL_SHADER_SOURCE_LENGTH); + PY_DICT_ADD_INT(GL_SHADER_TYPE); + PY_DICT_ADD_INT(GL_SHADING_LANGUAGE_VERSION); + PY_DICT_ADD_INT(GL_STENCIL_BACK_FAIL); + PY_DICT_ADD_INT(GL_STENCIL_BACK_FUNC); + PY_DICT_ADD_INT(GL_STENCIL_BACK_PASS_DEPTH_FAIL); + PY_DICT_ADD_INT(GL_STENCIL_BACK_PASS_DEPTH_PASS); + PY_DICT_ADD_INT(GL_STENCIL_BACK_REF); + PY_DICT_ADD_INT(GL_STENCIL_BACK_VALUE_MASK); + PY_DICT_ADD_INT(GL_STENCIL_BACK_WRITEMASK); + PY_DICT_ADD_INT(GL_UPPER_LEFT); + PY_DICT_ADD_INT(GL_VALIDATE_STATUS); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_ENABLED); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_NORMALIZED); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_POINTER); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_SIZE); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_STRIDE); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_TYPE); + PY_DICT_ADD_INT(GL_VERTEX_PROGRAM_POINT_SIZE); + PY_DICT_ADD_INT(GL_VERTEX_SHADER); + } + + /* GL_VERSION_2_1 */ + { + PY_DICT_ADD_INT(GL_COMPRESSED_SRGB); + PY_DICT_ADD_INT(GL_COMPRESSED_SRGB_ALPHA); + PY_DICT_ADD_INT(GL_FLOAT_MAT2x3); + PY_DICT_ADD_INT(GL_FLOAT_MAT2x4); + PY_DICT_ADD_INT(GL_FLOAT_MAT3x2); + PY_DICT_ADD_INT(GL_FLOAT_MAT3x4); + PY_DICT_ADD_INT(GL_FLOAT_MAT4x2); + PY_DICT_ADD_INT(GL_FLOAT_MAT4x3); + PY_DICT_ADD_INT(GL_PIXEL_PACK_BUFFER); + PY_DICT_ADD_INT(GL_PIXEL_PACK_BUFFER_BINDING); + PY_DICT_ADD_INT(GL_PIXEL_UNPACK_BUFFER); + PY_DICT_ADD_INT(GL_PIXEL_UNPACK_BUFFER_BINDING); + PY_DICT_ADD_INT(GL_SRGB); + PY_DICT_ADD_INT(GL_SRGB8); + PY_DICT_ADD_INT(GL_SRGB8_ALPHA8); + PY_DICT_ADD_INT(GL_SRGB_ALPHA); + } + + /* GL_VERSION_3_0 */ + { + PY_DICT_ADD_INT(GL_BGRA_INTEGER); + PY_DICT_ADD_INT(GL_BGR_INTEGER); + PY_DICT_ADD_INT(GL_BLUE_INTEGER); + PY_DICT_ADD_INT(GL_BUFFER_ACCESS_FLAGS); + PY_DICT_ADD_INT(GL_BUFFER_MAP_LENGTH); + PY_DICT_ADD_INT(GL_BUFFER_MAP_OFFSET); + PY_DICT_ADD_INT(GL_CLAMP_READ_COLOR); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE0); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE1); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE2); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE3); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE4); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE5); #if 0 - PY_DICT_ADD_INT(GL_CLIP_DISTANCE6); - PY_DICT_ADD_INT(GL_CLIP_DISTANCE7); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE6); + PY_DICT_ADD_INT(GL_CLIP_DISTANCE7); #endif - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT0); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT1); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT2); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT3); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT4); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT5); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT6); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT7); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT8); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT9); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT10); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT11); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT12); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT13); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT14); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT15); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT0); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT1); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT2); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT3); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT4); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT5); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT6); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT7); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT8); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT9); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT10); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT11); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT12); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT13); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT14); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT15); #if 0 - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT16); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT17); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT18); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT19); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT20); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT21); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT22); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT23); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT24); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT25); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT26); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT27); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT28); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT29); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT30); - PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT31); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT16); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT17); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT18); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT19); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT20); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT21); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT22); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT23); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT24); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT25); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT26); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT27); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT28); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT29); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT30); + PY_DICT_ADD_INT(GL_COLOR_ATTACHMENT31); #endif - PY_DICT_ADD_INT(GL_COMPARE_REF_TO_TEXTURE); - PY_DICT_ADD_INT(GL_COMPRESSED_RED); - PY_DICT_ADD_INT(GL_COMPRESSED_RED_RGTC1); - PY_DICT_ADD_INT(GL_COMPRESSED_RG); - PY_DICT_ADD_INT(GL_COMPRESSED_RG_RGTC2); - PY_DICT_ADD_INT(GL_COMPRESSED_SIGNED_RED_RGTC1); - PY_DICT_ADD_INT(GL_COMPRESSED_SIGNED_RG_RGTC2); - PY_DICT_ADD_INT(GL_CONTEXT_FLAGS); - PY_DICT_ADD_INT(GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT); - PY_DICT_ADD_INT(GL_DEPTH24_STENCIL8); - PY_DICT_ADD_INT(GL_DEPTH32F_STENCIL8); - PY_DICT_ADD_INT(GL_DEPTH_ATTACHMENT); - PY_DICT_ADD_INT(GL_DEPTH_COMPONENT32F); - PY_DICT_ADD_INT(GL_DEPTH_STENCIL); - PY_DICT_ADD_INT(GL_DEPTH_STENCIL_ATTACHMENT); - PY_DICT_ADD_INT(GL_DRAW_FRAMEBUFFER); - PY_DICT_ADD_INT(GL_DRAW_FRAMEBUFFER_BINDING); - PY_DICT_ADD_INT(GL_FIXED_ONLY); - PY_DICT_ADD_INT(GL_FLOAT_32_UNSIGNED_INT_24_8_REV); - PY_DICT_ADD_INT(GL_FRAMEBUFFER); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_BINDING); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_COMPLETE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_DEFAULT); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_SRGB); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_UNDEFINED); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_UNSUPPORTED); - PY_DICT_ADD_INT(GL_GREEN_INTEGER); - PY_DICT_ADD_INT(GL_HALF_FLOAT); - PY_DICT_ADD_INT(GL_INDEX); - PY_DICT_ADD_INT(GL_INTERLEAVED_ATTRIBS); - PY_DICT_ADD_INT(GL_INT_SAMPLER_1D); - PY_DICT_ADD_INT(GL_INT_SAMPLER_1D_ARRAY); - PY_DICT_ADD_INT(GL_INT_SAMPLER_2D); - PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_ARRAY); - PY_DICT_ADD_INT(GL_INT_SAMPLER_3D); - PY_DICT_ADD_INT(GL_INT_SAMPLER_CUBE); - PY_DICT_ADD_INT(GL_INVALID_FRAMEBUFFER_OPERATION); - PY_DICT_ADD_INT(GL_MAJOR_VERSION); - PY_DICT_ADD_INT(GL_MAP_FLUSH_EXPLICIT_BIT); - PY_DICT_ADD_INT(GL_MAP_INVALIDATE_BUFFER_BIT); - PY_DICT_ADD_INT(GL_MAP_INVALIDATE_RANGE_BIT); - PY_DICT_ADD_INT(GL_MAP_READ_BIT); - PY_DICT_ADD_INT(GL_MAP_UNSYNCHRONIZED_BIT); - PY_DICT_ADD_INT(GL_MAP_WRITE_BIT); - PY_DICT_ADD_INT(GL_MAX_ARRAY_TEXTURE_LAYERS); - PY_DICT_ADD_INT(GL_MAX_CLIP_DISTANCES); - PY_DICT_ADD_INT(GL_MAX_COLOR_ATTACHMENTS); - PY_DICT_ADD_INT(GL_MAX_PROGRAM_TEXEL_OFFSET); - PY_DICT_ADD_INT(GL_MAX_RENDERBUFFER_SIZE); - PY_DICT_ADD_INT(GL_MAX_SAMPLES); - PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS); - PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_VARYING_COMPONENTS); - PY_DICT_ADD_INT(GL_MINOR_VERSION); - PY_DICT_ADD_INT(GL_MIN_PROGRAM_TEXEL_OFFSET); - PY_DICT_ADD_INT(GL_NUM_EXTENSIONS); - PY_DICT_ADD_INT(GL_PRIMITIVES_GENERATED); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_1D_ARRAY); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_ARRAY); - PY_DICT_ADD_INT(GL_QUERY_BY_REGION_NO_WAIT); - PY_DICT_ADD_INT(GL_QUERY_BY_REGION_WAIT); - PY_DICT_ADD_INT(GL_QUERY_NO_WAIT); - PY_DICT_ADD_INT(GL_QUERY_WAIT); - PY_DICT_ADD_INT(GL_R11F_G11F_B10F); - PY_DICT_ADD_INT(GL_R16); - PY_DICT_ADD_INT(GL_R16F); - PY_DICT_ADD_INT(GL_R16I); - PY_DICT_ADD_INT(GL_R16UI); - PY_DICT_ADD_INT(GL_R32F); - PY_DICT_ADD_INT(GL_R32I); - PY_DICT_ADD_INT(GL_R32UI); - PY_DICT_ADD_INT(GL_R8); - PY_DICT_ADD_INT(GL_R8I); - PY_DICT_ADD_INT(GL_R8UI); - PY_DICT_ADD_INT(GL_RASTERIZER_DISCARD); - PY_DICT_ADD_INT(GL_READ_FRAMEBUFFER); - PY_DICT_ADD_INT(GL_READ_FRAMEBUFFER_BINDING); - PY_DICT_ADD_INT(GL_RED_INTEGER); - PY_DICT_ADD_INT(GL_RENDERBUFFER); - PY_DICT_ADD_INT(GL_RENDERBUFFER_ALPHA_SIZE); - PY_DICT_ADD_INT(GL_RENDERBUFFER_BINDING); - PY_DICT_ADD_INT(GL_RENDERBUFFER_BLUE_SIZE); - PY_DICT_ADD_INT(GL_RENDERBUFFER_DEPTH_SIZE); - PY_DICT_ADD_INT(GL_RENDERBUFFER_GREEN_SIZE); - PY_DICT_ADD_INT(GL_RENDERBUFFER_HEIGHT); - PY_DICT_ADD_INT(GL_RENDERBUFFER_INTERNAL_FORMAT); - PY_DICT_ADD_INT(GL_RENDERBUFFER_RED_SIZE); - PY_DICT_ADD_INT(GL_RENDERBUFFER_SAMPLES); - PY_DICT_ADD_INT(GL_RENDERBUFFER_STENCIL_SIZE); - PY_DICT_ADD_INT(GL_RENDERBUFFER_WIDTH); - PY_DICT_ADD_INT(GL_RG); - PY_DICT_ADD_INT(GL_RG16); - PY_DICT_ADD_INT(GL_RG16F); - PY_DICT_ADD_INT(GL_RG16I); - PY_DICT_ADD_INT(GL_RG16UI); - PY_DICT_ADD_INT(GL_RG32F); - PY_DICT_ADD_INT(GL_RG32I); - PY_DICT_ADD_INT(GL_RG32UI); - PY_DICT_ADD_INT(GL_RG8); - PY_DICT_ADD_INT(GL_RG8I); - PY_DICT_ADD_INT(GL_RG8UI); - PY_DICT_ADD_INT(GL_RGB16F); - PY_DICT_ADD_INT(GL_RGB16I); - PY_DICT_ADD_INT(GL_RGB16UI); - PY_DICT_ADD_INT(GL_RGB32F); - PY_DICT_ADD_INT(GL_RGB32I); - PY_DICT_ADD_INT(GL_RGB32UI); - PY_DICT_ADD_INT(GL_RGB8I); - PY_DICT_ADD_INT(GL_RGB8UI); - PY_DICT_ADD_INT(GL_RGB9_E5); - PY_DICT_ADD_INT(GL_RGBA16F); - PY_DICT_ADD_INT(GL_RGBA16I); - PY_DICT_ADD_INT(GL_RGBA16UI); - PY_DICT_ADD_INT(GL_RGBA32F); - PY_DICT_ADD_INT(GL_RGBA32I); - PY_DICT_ADD_INT(GL_RGBA32UI); - PY_DICT_ADD_INT(GL_RGBA8I); - PY_DICT_ADD_INT(GL_RGBA8UI); - PY_DICT_ADD_INT(GL_RGBA_INTEGER); - PY_DICT_ADD_INT(GL_RGB_INTEGER); - PY_DICT_ADD_INT(GL_RG_INTEGER); - PY_DICT_ADD_INT(GL_SAMPLER_1D_ARRAY); - PY_DICT_ADD_INT(GL_SAMPLER_1D_ARRAY_SHADOW); - PY_DICT_ADD_INT(GL_SAMPLER_2D_ARRAY); - PY_DICT_ADD_INT(GL_SAMPLER_2D_ARRAY_SHADOW); - PY_DICT_ADD_INT(GL_SAMPLER_CUBE_SHADOW); - PY_DICT_ADD_INT(GL_SEPARATE_ATTRIBS); - PY_DICT_ADD_INT(GL_STENCIL_ATTACHMENT); - PY_DICT_ADD_INT(GL_STENCIL_INDEX1); - PY_DICT_ADD_INT(GL_STENCIL_INDEX16); - PY_DICT_ADD_INT(GL_STENCIL_INDEX4); - PY_DICT_ADD_INT(GL_STENCIL_INDEX8); - PY_DICT_ADD_INT(GL_TEXTURE_1D_ARRAY); - PY_DICT_ADD_INT(GL_TEXTURE_2D_ARRAY); - PY_DICT_ADD_INT(GL_TEXTURE_ALPHA_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_1D_ARRAY); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_ARRAY); - PY_DICT_ADD_INT(GL_TEXTURE_BLUE_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_GREEN_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_RED_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_SHARED_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_STENCIL_SIZE); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_MODE); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_START); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_VARYINGS); - PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_10F_11F_11F_REV); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_24_8); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_5_9_9_9_REV); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_1D); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_3D); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_CUBE); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC2); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC3); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC4); - PY_DICT_ADD_INT(GL_UNSIGNED_NORMALIZED); - PY_DICT_ADD_INT(GL_VERTEX_ARRAY_BINDING); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_INTEGER); - } - - /* GL_VERSION_3_1 */ - { - PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_BLOCKS); - PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH); - PY_DICT_ADD_INT(GL_COPY_READ_BUFFER); - PY_DICT_ADD_INT(GL_COPY_WRITE_BUFFER); - PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_RECT); - PY_DICT_ADD_INT(GL_INT_SAMPLER_BUFFER); - PY_DICT_ADD_INT(GL_INVALID_INDEX); - PY_DICT_ADD_INT(GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_COMBINED_UNIFORM_BLOCKS); - PY_DICT_ADD_INT(GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_FRAGMENT_UNIFORM_BLOCKS); - PY_DICT_ADD_INT(GL_MAX_GEOMETRY_UNIFORM_BLOCKS); - PY_DICT_ADD_INT(GL_MAX_RECTANGLE_TEXTURE_SIZE); - PY_DICT_ADD_INT(GL_MAX_TEXTURE_BUFFER_SIZE); - PY_DICT_ADD_INT(GL_MAX_UNIFORM_BLOCK_SIZE); - PY_DICT_ADD_INT(GL_MAX_UNIFORM_BUFFER_BINDINGS); - PY_DICT_ADD_INT(GL_MAX_VERTEX_UNIFORM_BLOCKS); - PY_DICT_ADD_INT(GL_PRIMITIVE_RESTART); - PY_DICT_ADD_INT(GL_PRIMITIVE_RESTART_INDEX); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_RECTANGLE); - PY_DICT_ADD_INT(GL_R16_SNORM); - PY_DICT_ADD_INT(GL_R8_SNORM); - PY_DICT_ADD_INT(GL_RG16_SNORM); - PY_DICT_ADD_INT(GL_RG8_SNORM); - PY_DICT_ADD_INT(GL_RGB16_SNORM); - PY_DICT_ADD_INT(GL_RGB8_SNORM); - PY_DICT_ADD_INT(GL_RGBA16_SNORM); - PY_DICT_ADD_INT(GL_RGBA8_SNORM); - PY_DICT_ADD_INT(GL_SAMPLER_2D_RECT); - PY_DICT_ADD_INT(GL_SAMPLER_2D_RECT_SHADOW); - PY_DICT_ADD_INT(GL_SAMPLER_BUFFER); - PY_DICT_ADD_INT(GL_SIGNED_NORMALIZED); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_BUFFER); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_RECTANGLE); - PY_DICT_ADD_INT(GL_TEXTURE_BUFFER); - PY_DICT_ADD_INT(GL_TEXTURE_BUFFER_DATA_STORE_BINDING); - PY_DICT_ADD_INT(GL_TEXTURE_RECTANGLE); - PY_DICT_ADD_INT(GL_UNIFORM_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_BINDING); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_DATA_SIZE); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_INDEX); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_NAME_LENGTH); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER); - PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER); - PY_DICT_ADD_INT(GL_UNIFORM_BUFFER); - PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT); - PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_SIZE); - PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_START); - PY_DICT_ADD_INT(GL_UNIFORM_IS_ROW_MAJOR); - PY_DICT_ADD_INT(GL_UNIFORM_MATRIX_STRIDE); - PY_DICT_ADD_INT(GL_UNIFORM_NAME_LENGTH); - PY_DICT_ADD_INT(GL_UNIFORM_OFFSET); - PY_DICT_ADD_INT(GL_UNIFORM_SIZE); - PY_DICT_ADD_INT(GL_UNIFORM_TYPE); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_RECT); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_BUFFER); - } - - /* GL_VERSION_3_2 */ - { - PY_DICT_ADD_INT(GL_ALREADY_SIGNALED); - PY_DICT_ADD_INT(GL_CONDITION_SATISFIED); - PY_DICT_ADD_INT(GL_CONTEXT_COMPATIBILITY_PROFILE_BIT); - PY_DICT_ADD_INT(GL_CONTEXT_CORE_PROFILE_BIT); - PY_DICT_ADD_INT(GL_CONTEXT_PROFILE_MASK); - PY_DICT_ADD_INT(GL_DEPTH_CLAMP); - PY_DICT_ADD_INT(GL_FIRST_VERTEX_CONVENTION); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_LAYERED); - PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS); - PY_DICT_ADD_INT(GL_GEOMETRY_INPUT_TYPE); - PY_DICT_ADD_INT(GL_GEOMETRY_OUTPUT_TYPE); - PY_DICT_ADD_INT(GL_GEOMETRY_SHADER); - PY_DICT_ADD_INT(GL_GEOMETRY_VERTICES_OUT); - PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_MULTISAMPLE); - PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY); - PY_DICT_ADD_INT(GL_LAST_VERTEX_CONVENTION); - PY_DICT_ADD_INT(GL_LINES_ADJACENCY); - PY_DICT_ADD_INT(GL_LINE_STRIP_ADJACENCY); - PY_DICT_ADD_INT(GL_MAX_COLOR_TEXTURE_SAMPLES); - PY_DICT_ADD_INT(GL_MAX_DEPTH_TEXTURE_SAMPLES); - PY_DICT_ADD_INT(GL_MAX_FRAGMENT_INPUT_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_GEOMETRY_INPUT_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_GEOMETRY_OUTPUT_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_GEOMETRY_OUTPUT_VERTICES); - PY_DICT_ADD_INT(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS); - PY_DICT_ADD_INT(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_GEOMETRY_UNIFORM_COMPONENTS); - PY_DICT_ADD_INT(GL_MAX_INTEGER_SAMPLES); - PY_DICT_ADD_INT(GL_MAX_SAMPLE_MASK_WORDS); - PY_DICT_ADD_INT(GL_MAX_SERVER_WAIT_TIMEOUT); - PY_DICT_ADD_INT(GL_MAX_VERTEX_OUTPUT_COMPONENTS); - PY_DICT_ADD_INT(GL_OBJECT_TYPE); - PY_DICT_ADD_INT(GL_PROGRAM_POINT_SIZE); - PY_DICT_ADD_INT(GL_PROVOKING_VERTEX); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_MULTISAMPLE); - PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY); - PY_DICT_ADD_INT(GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION); - PY_DICT_ADD_INT(GL_SAMPLER_2D_MULTISAMPLE); - PY_DICT_ADD_INT(GL_SAMPLER_2D_MULTISAMPLE_ARRAY); - PY_DICT_ADD_INT(GL_SAMPLE_MASK); - PY_DICT_ADD_INT(GL_SAMPLE_MASK_VALUE); - PY_DICT_ADD_INT(GL_SAMPLE_POSITION); - PY_DICT_ADD_INT(GL_SIGNALED); - PY_DICT_ADD_INT(GL_SYNC_CONDITION); - PY_DICT_ADD_INT(GL_SYNC_FENCE); - PY_DICT_ADD_INT(GL_SYNC_FLAGS); - PY_DICT_ADD_INT(GL_SYNC_FLUSH_COMMANDS_BIT); - PY_DICT_ADD_INT(GL_SYNC_GPU_COMMANDS_COMPLETE); - PY_DICT_ADD_INT(GL_SYNC_STATUS); - PY_DICT_ADD_INT(GL_TEXTURE_2D_MULTISAMPLE); - PY_DICT_ADD_INT(GL_TEXTURE_2D_MULTISAMPLE_ARRAY); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_MULTISAMPLE); - PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY); - PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_SEAMLESS); - PY_DICT_ADD_INT(GL_TEXTURE_FIXED_SAMPLE_LOCATIONS); - PY_DICT_ADD_INT(GL_TEXTURE_SAMPLES); - PY_DICT_ADD_INT(GL_TIMEOUT_EXPIRED); - PY_DICT_ADD_INT64(GL_TIMEOUT_IGNORED); - PY_DICT_ADD_INT(GL_TRIANGLES_ADJACENCY); - PY_DICT_ADD_INT(GL_TRIANGLE_STRIP_ADJACENCY); - PY_DICT_ADD_INT(GL_UNSIGNALED); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE); - PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY); - PY_DICT_ADD_INT(GL_WAIT_FAILED); - } - - /* GL_VERSION_3_3 */ - { - PY_DICT_ADD_INT(GL_ANY_SAMPLES_PASSED); - PY_DICT_ADD_INT(GL_INT_2_10_10_10_REV); - PY_DICT_ADD_INT(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS); - PY_DICT_ADD_INT(GL_ONE_MINUS_SRC1_ALPHA); - PY_DICT_ADD_INT(GL_ONE_MINUS_SRC1_COLOR); - PY_DICT_ADD_INT(GL_RGB10_A2UI); - PY_DICT_ADD_INT(GL_SAMPLER_BINDING); - PY_DICT_ADD_INT(GL_SRC1_COLOR); - PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_A); - PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_B); - PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_G); - PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_R); - PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_RGBA); - PY_DICT_ADD_INT(GL_TIMESTAMP); - PY_DICT_ADD_INT(GL_TIME_ELAPSED); - PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR); - } - - return submodule; + PY_DICT_ADD_INT(GL_COMPARE_REF_TO_TEXTURE); + PY_DICT_ADD_INT(GL_COMPRESSED_RED); + PY_DICT_ADD_INT(GL_COMPRESSED_RED_RGTC1); + PY_DICT_ADD_INT(GL_COMPRESSED_RG); + PY_DICT_ADD_INT(GL_COMPRESSED_RG_RGTC2); + PY_DICT_ADD_INT(GL_COMPRESSED_SIGNED_RED_RGTC1); + PY_DICT_ADD_INT(GL_COMPRESSED_SIGNED_RG_RGTC2); + PY_DICT_ADD_INT(GL_CONTEXT_FLAGS); + PY_DICT_ADD_INT(GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT); + PY_DICT_ADD_INT(GL_DEPTH24_STENCIL8); + PY_DICT_ADD_INT(GL_DEPTH32F_STENCIL8); + PY_DICT_ADD_INT(GL_DEPTH_ATTACHMENT); + PY_DICT_ADD_INT(GL_DEPTH_COMPONENT32F); + PY_DICT_ADD_INT(GL_DEPTH_STENCIL); + PY_DICT_ADD_INT(GL_DEPTH_STENCIL_ATTACHMENT); + PY_DICT_ADD_INT(GL_DRAW_FRAMEBUFFER); + PY_DICT_ADD_INT(GL_DRAW_FRAMEBUFFER_BINDING); + PY_DICT_ADD_INT(GL_FIXED_ONLY); + PY_DICT_ADD_INT(GL_FLOAT_32_UNSIGNED_INT_24_8_REV); + PY_DICT_ADD_INT(GL_FRAMEBUFFER); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_BINDING); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_COMPLETE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_DEFAULT); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_SRGB); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_UNDEFINED); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_UNSUPPORTED); + PY_DICT_ADD_INT(GL_GREEN_INTEGER); + PY_DICT_ADD_INT(GL_HALF_FLOAT); + PY_DICT_ADD_INT(GL_INDEX); + PY_DICT_ADD_INT(GL_INTERLEAVED_ATTRIBS); + PY_DICT_ADD_INT(GL_INT_SAMPLER_1D); + PY_DICT_ADD_INT(GL_INT_SAMPLER_1D_ARRAY); + PY_DICT_ADD_INT(GL_INT_SAMPLER_2D); + PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_ARRAY); + PY_DICT_ADD_INT(GL_INT_SAMPLER_3D); + PY_DICT_ADD_INT(GL_INT_SAMPLER_CUBE); + PY_DICT_ADD_INT(GL_INVALID_FRAMEBUFFER_OPERATION); + PY_DICT_ADD_INT(GL_MAJOR_VERSION); + PY_DICT_ADD_INT(GL_MAP_FLUSH_EXPLICIT_BIT); + PY_DICT_ADD_INT(GL_MAP_INVALIDATE_BUFFER_BIT); + PY_DICT_ADD_INT(GL_MAP_INVALIDATE_RANGE_BIT); + PY_DICT_ADD_INT(GL_MAP_READ_BIT); + PY_DICT_ADD_INT(GL_MAP_UNSYNCHRONIZED_BIT); + PY_DICT_ADD_INT(GL_MAP_WRITE_BIT); + PY_DICT_ADD_INT(GL_MAX_ARRAY_TEXTURE_LAYERS); + PY_DICT_ADD_INT(GL_MAX_CLIP_DISTANCES); + PY_DICT_ADD_INT(GL_MAX_COLOR_ATTACHMENTS); + PY_DICT_ADD_INT(GL_MAX_PROGRAM_TEXEL_OFFSET); + PY_DICT_ADD_INT(GL_MAX_RENDERBUFFER_SIZE); + PY_DICT_ADD_INT(GL_MAX_SAMPLES); + PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS); + PY_DICT_ADD_INT(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_VARYING_COMPONENTS); + PY_DICT_ADD_INT(GL_MINOR_VERSION); + PY_DICT_ADD_INT(GL_MIN_PROGRAM_TEXEL_OFFSET); + PY_DICT_ADD_INT(GL_NUM_EXTENSIONS); + PY_DICT_ADD_INT(GL_PRIMITIVES_GENERATED); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_1D_ARRAY); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_ARRAY); + PY_DICT_ADD_INT(GL_QUERY_BY_REGION_NO_WAIT); + PY_DICT_ADD_INT(GL_QUERY_BY_REGION_WAIT); + PY_DICT_ADD_INT(GL_QUERY_NO_WAIT); + PY_DICT_ADD_INT(GL_QUERY_WAIT); + PY_DICT_ADD_INT(GL_R11F_G11F_B10F); + PY_DICT_ADD_INT(GL_R16); + PY_DICT_ADD_INT(GL_R16F); + PY_DICT_ADD_INT(GL_R16I); + PY_DICT_ADD_INT(GL_R16UI); + PY_DICT_ADD_INT(GL_R32F); + PY_DICT_ADD_INT(GL_R32I); + PY_DICT_ADD_INT(GL_R32UI); + PY_DICT_ADD_INT(GL_R8); + PY_DICT_ADD_INT(GL_R8I); + PY_DICT_ADD_INT(GL_R8UI); + PY_DICT_ADD_INT(GL_RASTERIZER_DISCARD); + PY_DICT_ADD_INT(GL_READ_FRAMEBUFFER); + PY_DICT_ADD_INT(GL_READ_FRAMEBUFFER_BINDING); + PY_DICT_ADD_INT(GL_RED_INTEGER); + PY_DICT_ADD_INT(GL_RENDERBUFFER); + PY_DICT_ADD_INT(GL_RENDERBUFFER_ALPHA_SIZE); + PY_DICT_ADD_INT(GL_RENDERBUFFER_BINDING); + PY_DICT_ADD_INT(GL_RENDERBUFFER_BLUE_SIZE); + PY_DICT_ADD_INT(GL_RENDERBUFFER_DEPTH_SIZE); + PY_DICT_ADD_INT(GL_RENDERBUFFER_GREEN_SIZE); + PY_DICT_ADD_INT(GL_RENDERBUFFER_HEIGHT); + PY_DICT_ADD_INT(GL_RENDERBUFFER_INTERNAL_FORMAT); + PY_DICT_ADD_INT(GL_RENDERBUFFER_RED_SIZE); + PY_DICT_ADD_INT(GL_RENDERBUFFER_SAMPLES); + PY_DICT_ADD_INT(GL_RENDERBUFFER_STENCIL_SIZE); + PY_DICT_ADD_INT(GL_RENDERBUFFER_WIDTH); + PY_DICT_ADD_INT(GL_RG); + PY_DICT_ADD_INT(GL_RG16); + PY_DICT_ADD_INT(GL_RG16F); + PY_DICT_ADD_INT(GL_RG16I); + PY_DICT_ADD_INT(GL_RG16UI); + PY_DICT_ADD_INT(GL_RG32F); + PY_DICT_ADD_INT(GL_RG32I); + PY_DICT_ADD_INT(GL_RG32UI); + PY_DICT_ADD_INT(GL_RG8); + PY_DICT_ADD_INT(GL_RG8I); + PY_DICT_ADD_INT(GL_RG8UI); + PY_DICT_ADD_INT(GL_RGB16F); + PY_DICT_ADD_INT(GL_RGB16I); + PY_DICT_ADD_INT(GL_RGB16UI); + PY_DICT_ADD_INT(GL_RGB32F); + PY_DICT_ADD_INT(GL_RGB32I); + PY_DICT_ADD_INT(GL_RGB32UI); + PY_DICT_ADD_INT(GL_RGB8I); + PY_DICT_ADD_INT(GL_RGB8UI); + PY_DICT_ADD_INT(GL_RGB9_E5); + PY_DICT_ADD_INT(GL_RGBA16F); + PY_DICT_ADD_INT(GL_RGBA16I); + PY_DICT_ADD_INT(GL_RGBA16UI); + PY_DICT_ADD_INT(GL_RGBA32F); + PY_DICT_ADD_INT(GL_RGBA32I); + PY_DICT_ADD_INT(GL_RGBA32UI); + PY_DICT_ADD_INT(GL_RGBA8I); + PY_DICT_ADD_INT(GL_RGBA8UI); + PY_DICT_ADD_INT(GL_RGBA_INTEGER); + PY_DICT_ADD_INT(GL_RGB_INTEGER); + PY_DICT_ADD_INT(GL_RG_INTEGER); + PY_DICT_ADD_INT(GL_SAMPLER_1D_ARRAY); + PY_DICT_ADD_INT(GL_SAMPLER_1D_ARRAY_SHADOW); + PY_DICT_ADD_INT(GL_SAMPLER_2D_ARRAY); + PY_DICT_ADD_INT(GL_SAMPLER_2D_ARRAY_SHADOW); + PY_DICT_ADD_INT(GL_SAMPLER_CUBE_SHADOW); + PY_DICT_ADD_INT(GL_SEPARATE_ATTRIBS); + PY_DICT_ADD_INT(GL_STENCIL_ATTACHMENT); + PY_DICT_ADD_INT(GL_STENCIL_INDEX1); + PY_DICT_ADD_INT(GL_STENCIL_INDEX16); + PY_DICT_ADD_INT(GL_STENCIL_INDEX4); + PY_DICT_ADD_INT(GL_STENCIL_INDEX8); + PY_DICT_ADD_INT(GL_TEXTURE_1D_ARRAY); + PY_DICT_ADD_INT(GL_TEXTURE_2D_ARRAY); + PY_DICT_ADD_INT(GL_TEXTURE_ALPHA_TYPE); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_1D_ARRAY); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_ARRAY); + PY_DICT_ADD_INT(GL_TEXTURE_BLUE_TYPE); + PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_TYPE); + PY_DICT_ADD_INT(GL_TEXTURE_GREEN_TYPE); + PY_DICT_ADD_INT(GL_TEXTURE_RED_TYPE); + PY_DICT_ADD_INT(GL_TEXTURE_SHARED_SIZE); + PY_DICT_ADD_INT(GL_TEXTURE_STENCIL_SIZE); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_MODE); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_BUFFER_START); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_VARYINGS); + PY_DICT_ADD_INT(GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_10F_11F_11F_REV); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_24_8); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_5_9_9_9_REV); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_1D); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_3D); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_CUBE); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC2); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC3); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_VEC4); + PY_DICT_ADD_INT(GL_UNSIGNED_NORMALIZED); + PY_DICT_ADD_INT(GL_VERTEX_ARRAY_BINDING); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_INTEGER); + } + + /* GL_VERSION_3_1 */ + { + PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_BLOCKS); + PY_DICT_ADD_INT(GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH); + PY_DICT_ADD_INT(GL_COPY_READ_BUFFER); + PY_DICT_ADD_INT(GL_COPY_WRITE_BUFFER); + PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_RECT); + PY_DICT_ADD_INT(GL_INT_SAMPLER_BUFFER); + PY_DICT_ADD_INT(GL_INVALID_INDEX); + PY_DICT_ADD_INT(GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_COMBINED_UNIFORM_BLOCKS); + PY_DICT_ADD_INT(GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_FRAGMENT_UNIFORM_BLOCKS); + PY_DICT_ADD_INT(GL_MAX_GEOMETRY_UNIFORM_BLOCKS); + PY_DICT_ADD_INT(GL_MAX_RECTANGLE_TEXTURE_SIZE); + PY_DICT_ADD_INT(GL_MAX_TEXTURE_BUFFER_SIZE); + PY_DICT_ADD_INT(GL_MAX_UNIFORM_BLOCK_SIZE); + PY_DICT_ADD_INT(GL_MAX_UNIFORM_BUFFER_BINDINGS); + PY_DICT_ADD_INT(GL_MAX_VERTEX_UNIFORM_BLOCKS); + PY_DICT_ADD_INT(GL_PRIMITIVE_RESTART); + PY_DICT_ADD_INT(GL_PRIMITIVE_RESTART_INDEX); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_RECTANGLE); + PY_DICT_ADD_INT(GL_R16_SNORM); + PY_DICT_ADD_INT(GL_R8_SNORM); + PY_DICT_ADD_INT(GL_RG16_SNORM); + PY_DICT_ADD_INT(GL_RG8_SNORM); + PY_DICT_ADD_INT(GL_RGB16_SNORM); + PY_DICT_ADD_INT(GL_RGB8_SNORM); + PY_DICT_ADD_INT(GL_RGBA16_SNORM); + PY_DICT_ADD_INT(GL_RGBA8_SNORM); + PY_DICT_ADD_INT(GL_SAMPLER_2D_RECT); + PY_DICT_ADD_INT(GL_SAMPLER_2D_RECT_SHADOW); + PY_DICT_ADD_INT(GL_SAMPLER_BUFFER); + PY_DICT_ADD_INT(GL_SIGNED_NORMALIZED); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_BUFFER); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_RECTANGLE); + PY_DICT_ADD_INT(GL_TEXTURE_BUFFER); + PY_DICT_ADD_INT(GL_TEXTURE_BUFFER_DATA_STORE_BINDING); + PY_DICT_ADD_INT(GL_TEXTURE_RECTANGLE); + PY_DICT_ADD_INT(GL_UNIFORM_ARRAY_STRIDE); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_BINDING); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_DATA_SIZE); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_INDEX); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_NAME_LENGTH); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER); + PY_DICT_ADD_INT(GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER); + PY_DICT_ADD_INT(GL_UNIFORM_BUFFER); + PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_BINDING); + PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT); + PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_SIZE); + PY_DICT_ADD_INT(GL_UNIFORM_BUFFER_START); + PY_DICT_ADD_INT(GL_UNIFORM_IS_ROW_MAJOR); + PY_DICT_ADD_INT(GL_UNIFORM_MATRIX_STRIDE); + PY_DICT_ADD_INT(GL_UNIFORM_NAME_LENGTH); + PY_DICT_ADD_INT(GL_UNIFORM_OFFSET); + PY_DICT_ADD_INT(GL_UNIFORM_SIZE); + PY_DICT_ADD_INT(GL_UNIFORM_TYPE); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_RECT); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_BUFFER); + } + + /* GL_VERSION_3_2 */ + { + PY_DICT_ADD_INT(GL_ALREADY_SIGNALED); + PY_DICT_ADD_INT(GL_CONDITION_SATISFIED); + PY_DICT_ADD_INT(GL_CONTEXT_COMPATIBILITY_PROFILE_BIT); + PY_DICT_ADD_INT(GL_CONTEXT_CORE_PROFILE_BIT); + PY_DICT_ADD_INT(GL_CONTEXT_PROFILE_MASK); + PY_DICT_ADD_INT(GL_DEPTH_CLAMP); + PY_DICT_ADD_INT(GL_FIRST_VERTEX_CONVENTION); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_ATTACHMENT_LAYERED); + PY_DICT_ADD_INT(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS); + PY_DICT_ADD_INT(GL_GEOMETRY_INPUT_TYPE); + PY_DICT_ADD_INT(GL_GEOMETRY_OUTPUT_TYPE); + PY_DICT_ADD_INT(GL_GEOMETRY_SHADER); + PY_DICT_ADD_INT(GL_GEOMETRY_VERTICES_OUT); + PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_MULTISAMPLE); + PY_DICT_ADD_INT(GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY); + PY_DICT_ADD_INT(GL_LAST_VERTEX_CONVENTION); + PY_DICT_ADD_INT(GL_LINES_ADJACENCY); + PY_DICT_ADD_INT(GL_LINE_STRIP_ADJACENCY); + PY_DICT_ADD_INT(GL_MAX_COLOR_TEXTURE_SAMPLES); + PY_DICT_ADD_INT(GL_MAX_DEPTH_TEXTURE_SAMPLES); + PY_DICT_ADD_INT(GL_MAX_FRAGMENT_INPUT_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_GEOMETRY_INPUT_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_GEOMETRY_OUTPUT_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_GEOMETRY_OUTPUT_VERTICES); + PY_DICT_ADD_INT(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS); + PY_DICT_ADD_INT(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_GEOMETRY_UNIFORM_COMPONENTS); + PY_DICT_ADD_INT(GL_MAX_INTEGER_SAMPLES); + PY_DICT_ADD_INT(GL_MAX_SAMPLE_MASK_WORDS); + PY_DICT_ADD_INT(GL_MAX_SERVER_WAIT_TIMEOUT); + PY_DICT_ADD_INT(GL_MAX_VERTEX_OUTPUT_COMPONENTS); + PY_DICT_ADD_INT(GL_OBJECT_TYPE); + PY_DICT_ADD_INT(GL_PROGRAM_POINT_SIZE); + PY_DICT_ADD_INT(GL_PROVOKING_VERTEX); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_MULTISAMPLE); + PY_DICT_ADD_INT(GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY); + PY_DICT_ADD_INT(GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION); + PY_DICT_ADD_INT(GL_SAMPLER_2D_MULTISAMPLE); + PY_DICT_ADD_INT(GL_SAMPLER_2D_MULTISAMPLE_ARRAY); + PY_DICT_ADD_INT(GL_SAMPLE_MASK); + PY_DICT_ADD_INT(GL_SAMPLE_MASK_VALUE); + PY_DICT_ADD_INT(GL_SAMPLE_POSITION); + PY_DICT_ADD_INT(GL_SIGNALED); + PY_DICT_ADD_INT(GL_SYNC_CONDITION); + PY_DICT_ADD_INT(GL_SYNC_FENCE); + PY_DICT_ADD_INT(GL_SYNC_FLAGS); + PY_DICT_ADD_INT(GL_SYNC_FLUSH_COMMANDS_BIT); + PY_DICT_ADD_INT(GL_SYNC_GPU_COMMANDS_COMPLETE); + PY_DICT_ADD_INT(GL_SYNC_STATUS); + PY_DICT_ADD_INT(GL_TEXTURE_2D_MULTISAMPLE); + PY_DICT_ADD_INT(GL_TEXTURE_2D_MULTISAMPLE_ARRAY); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_MULTISAMPLE); + PY_DICT_ADD_INT(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY); + PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_SEAMLESS); + PY_DICT_ADD_INT(GL_TEXTURE_FIXED_SAMPLE_LOCATIONS); + PY_DICT_ADD_INT(GL_TEXTURE_SAMPLES); + PY_DICT_ADD_INT(GL_TIMEOUT_EXPIRED); + PY_DICT_ADD_INT64(GL_TIMEOUT_IGNORED); + PY_DICT_ADD_INT(GL_TRIANGLES_ADJACENCY); + PY_DICT_ADD_INT(GL_TRIANGLE_STRIP_ADJACENCY); + PY_DICT_ADD_INT(GL_UNSIGNALED); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE); + PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY); + PY_DICT_ADD_INT(GL_WAIT_FAILED); + } + + /* GL_VERSION_3_3 */ + { + PY_DICT_ADD_INT(GL_ANY_SAMPLES_PASSED); + PY_DICT_ADD_INT(GL_INT_2_10_10_10_REV); + PY_DICT_ADD_INT(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS); + PY_DICT_ADD_INT(GL_ONE_MINUS_SRC1_ALPHA); + PY_DICT_ADD_INT(GL_ONE_MINUS_SRC1_COLOR); + PY_DICT_ADD_INT(GL_RGB10_A2UI); + PY_DICT_ADD_INT(GL_SAMPLER_BINDING); + PY_DICT_ADD_INT(GL_SRC1_COLOR); + PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_A); + PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_B); + PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_G); + PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_R); + PY_DICT_ADD_INT(GL_TEXTURE_SWIZZLE_RGBA); + PY_DICT_ADD_INT(GL_TIMESTAMP); + PY_DICT_ADD_INT(GL_TIME_ELAPSED); + PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR); + } + + return submodule; } static PyObject *Method_ShaderSource(PyObject *UNUSED(self), PyObject *args) { - unsigned int shader; - const char *source; + unsigned int shader; + const char *source; - if (!PyArg_ParseTuple(args, "Is", &shader, &source)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "Is", &shader, &source)) { + return NULL; + } - glShaderSource(shader, 1, (const char **)&source, NULL); + glShaderSource(shader, 1, (const char **)&source, NULL); - Py_RETURN_NONE; + Py_RETURN_NONE; } - /** \} */ diff --git a/source/blender/python/generic/bgl.h b/source/blender/python/generic/bgl.h index 105056be5e6..8c81dc48340 100644 --- a/source/blender/python/generic/bgl.h +++ b/source/blender/python/generic/bgl.h @@ -33,22 +33,21 @@ int BGL_typeSize(int type); * For Python access to OpenGL functions requiring a pointer. */ typedef struct _Buffer { - PyObject_VAR_HEAD - PyObject *parent; - - int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */ - int ndimensions; - int *dimensions; - - union { - char *asbyte; - short *asshort; - int *asint; - float *asfloat; - double *asdouble; - - void *asvoid; - } buf; + PyObject_VAR_HEAD PyObject *parent; + + int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */ + int ndimensions; + int *dimensions; + + union { + char *asbyte; + short *asshort; + int *asint; + float *asfloat; + double *asdouble; + + void *asvoid; + } buf; } Buffer; /** The type object */ diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index 9161e5d979b..a2c7c9099c1 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -29,486 +29,470 @@ #include "python_utildefines.h" - PyDoc_STRVAR(py_blf_position_doc, -".. function:: position(fontid, x, y, z)\n" -"\n" -" Set the position for drawing text.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg x: X axis position to draw the text.\n" -" :type x: float\n" -" :arg y: Y axis position to draw the text.\n" -" :type y: float\n" -" :arg z: Z axis position to draw the text.\n" -" :type z: float\n" -); + ".. function:: position(fontid, x, y, z)\n" + "\n" + " Set the position for drawing text.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg x: X axis position to draw the text.\n" + " :type x: float\n" + " :arg y: Y axis position to draw the text.\n" + " :type y: float\n" + " :arg z: Z axis position to draw the text.\n" + " :type z: float\n"); static PyObject *py_blf_position(PyObject *UNUSED(self), PyObject *args) { - int fontid; - float x, y, z; + int fontid; + float x, y, z; - if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) { + return NULL; + } - BLF_position(fontid, x, y, z); + BLF_position(fontid, x, y, z); - Py_RETURN_NONE; + Py_RETURN_NONE; } - PyDoc_STRVAR(py_blf_size_doc, -".. function:: size(fontid, size, dpi)\n" -"\n" -" Set the size and dpi for drawing text.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg size: Point size of the font.\n" -" :type size: int\n" -" :arg dpi: dots per inch value to use for drawing.\n" -" :type dpi: int\n" -); + ".. function:: size(fontid, size, dpi)\n" + "\n" + " Set the size and dpi for drawing text.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg size: Point size of the font.\n" + " :type size: int\n" + " :arg dpi: dots per inch value to use for drawing.\n" + " :type dpi: int\n"); static PyObject *py_blf_size(PyObject *UNUSED(self), PyObject *args) { - int fontid, size, dpi; + int fontid, size, dpi; - if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi)) { + return NULL; + } - BLF_size(fontid, size, dpi); + BLF_size(fontid, size, dpi); - Py_RETURN_NONE; + Py_RETURN_NONE; } - PyDoc_STRVAR(py_blf_aspect_doc, -".. function:: aspect(fontid, aspect)\n" -"\n" -" Set the aspect for drawing text.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg aspect: The aspect ratio for text drawing to use.\n" -" :type aspect: float\n" -); + ".. function:: aspect(fontid, aspect)\n" + "\n" + " Set the aspect for drawing text.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg aspect: The aspect ratio for text drawing to use.\n" + " :type aspect: float\n"); static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args) { - float aspect; - int fontid; + float aspect; + int fontid; - if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) { + return NULL; + } - BLF_aspect(fontid, aspect, aspect, 1.0); + BLF_aspect(fontid, aspect, aspect, 1.0); - Py_RETURN_NONE; + Py_RETURN_NONE; } - PyDoc_STRVAR(py_blf_color_doc, -".. function:: color(fontid, r, g, b, a)\n" -"\n" -" Set the color for drawing text.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg r: red channel 0.0 - 1.0.\n" -" :type r: float\n" -" :arg g: green channel 0.0 - 1.0.\n" -" :type g: float\n" -" :arg b: blue channel 0.0 - 1.0.\n" -" :type b: float\n" -" :arg a: alpha channel 0.0 - 1.0.\n" -" :type a: float\n" -); + ".. function:: color(fontid, r, g, b, a)\n" + "\n" + " Set the color for drawing text.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg r: red channel 0.0 - 1.0.\n" + " :type r: float\n" + " :arg g: green channel 0.0 - 1.0.\n" + " :type g: float\n" + " :arg b: blue channel 0.0 - 1.0.\n" + " :type b: float\n" + " :arg a: alpha channel 0.0 - 1.0.\n" + " :type a: float\n"); static PyObject *py_blf_color(PyObject *UNUSED(self), PyObject *args) { - int fontid; - float rgba[4]; + int fontid; + float rgba[4]; - if (!PyArg_ParseTuple( - args, "iffff:blf.color", - &fontid, &rgba[0], &rgba[1], &rgba[2], &rgba[3])) - { - return NULL; - } + if (!PyArg_ParseTuple( + args, "iffff:blf.color", &fontid, &rgba[0], &rgba[1], &rgba[2], &rgba[3])) { + return NULL; + } - BLF_color4fv(fontid, rgba); + BLF_color4fv(fontid, rgba); - Py_RETURN_NONE; + Py_RETURN_NONE; } - #if BLF_BLUR_ENABLE PyDoc_STRVAR(py_blf_blur_doc, -".. function:: blur(fontid, radius)\n" -"\n" -" Set the blur radius for drawing text.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg radius: The radius for blurring text (in pixels).\n" -" :type radius: int\n" -); + ".. function:: blur(fontid, radius)\n" + "\n" + " Set the blur radius for drawing text.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg radius: The radius for blurring text (in pixels).\n" + " :type radius: int\n"); static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args) { - int blur, fontid; + int blur, fontid; - if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur)) { + return NULL; + } - BLF_blur(fontid, blur); + BLF_blur(fontid, blur); - Py_RETURN_NONE; + Py_RETURN_NONE; } #endif - PyDoc_STRVAR(py_blf_draw_doc, -".. function:: draw(fontid, text)\n" -"\n" -" Draw text in the current context.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg text: the text to draw.\n" -" :type text: string\n" -); + ".. function:: draw(fontid, text)\n" + "\n" + " Draw text in the current context.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg text: the text to draw.\n" + " :type text: string\n"); static PyObject *py_blf_draw(PyObject *UNUSED(self), PyObject *args) { - const char *text; - int text_length; - int fontid; + const char *text; + int text_length; + int fontid; - if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) { + return NULL; + } - BLF_draw(fontid, text, (unsigned int)text_length); + BLF_draw(fontid, text, (unsigned int)text_length); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_dimensions_doc, -".. function:: dimensions(fontid, text)\n" -"\n" -" Return the width and height of the text.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg text: the text to draw.\n" -" :type text: string\n" -" :return: the width and height of the text.\n" -" :rtype: tuple of 2 floats\n" -); + ".. function:: dimensions(fontid, text)\n" + "\n" + " Return the width and height of the text.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg text: the text to draw.\n" + " :type text: string\n" + " :return: the width and height of the text.\n" + " :rtype: tuple of 2 floats\n"); static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args) { - const char *text; - float r_width, r_height; - PyObject *ret; - int fontid; - - if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) { - return NULL; - } - - BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height); - - ret = PyTuple_New(2); - PyTuple_SET_ITEMS(ret, - PyFloat_FromDouble(r_width), - PyFloat_FromDouble(r_height)); - return ret; + const char *text; + float r_width, r_height; + PyObject *ret; + int fontid; + + if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) { + return NULL; + } + + BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height); + + ret = PyTuple_New(2); + PyTuple_SET_ITEMS(ret, PyFloat_FromDouble(r_width), PyFloat_FromDouble(r_height)); + return ret; } PyDoc_STRVAR(py_blf_clipping_doc, -".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n" -"\n" -" Set the clipping, enable/disable using CLIPPING.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg xmin: Clip the drawing area by these bounds.\n" -" :type xmin: float\n" -" :arg ymin: Clip the drawing area by these bounds.\n" -" :type ymin: float\n" -" :arg xmax: Clip the drawing area by these bounds.\n" -" :type xmax: float\n" -" :arg ymax: Clip the drawing area by these bounds.\n" -" :type ymax: float\n" -); + ".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n" + "\n" + " Set the clipping, enable/disable using CLIPPING.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg xmin: Clip the drawing area by these bounds.\n" + " :type xmin: float\n" + " :arg ymin: Clip the drawing area by these bounds.\n" + " :type ymin: float\n" + " :arg xmax: Clip the drawing area by these bounds.\n" + " :type xmax: float\n" + " :arg ymax: Clip the drawing area by these bounds.\n" + " :type ymax: float\n"); static PyObject *py_blf_clipping(PyObject *UNUSED(self), PyObject *args) { - float xmin, ymin, xmax, ymax; - int fontid; + float xmin, ymin, xmax, ymax; + int fontid; - if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) { + return NULL; + } - BLF_clipping(fontid, xmin, ymin, xmax, ymax); + BLF_clipping(fontid, xmin, ymin, xmax, ymax); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_word_wrap_doc, -".. function:: word_wrap(fontid, wrap_width)\n" -"\n" -" Set the wrap width, enable/disable using WORD_WRAP.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg wrap_width: The width (in pixels) to wrap words at.\n" -" :type wrap_width: int\n" -); + ".. function:: word_wrap(fontid, wrap_width)\n" + "\n" + " Set the wrap width, enable/disable using WORD_WRAP.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg wrap_width: The width (in pixels) to wrap words at.\n" + " :type wrap_width: int\n"); static PyObject *py_blf_word_wrap(PyObject *UNUSED(self), PyObject *args) { - int wrap_width; - int fontid; + int wrap_width; + int fontid; - if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) { + return NULL; + } - BLF_wordwrap(fontid, wrap_width); + BLF_wordwrap(fontid, wrap_width); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_disable_doc, -".. function:: disable(fontid, option)\n" -"\n" -" Disable option.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n" -" :type option: int\n" -); + ".. function:: disable(fontid, option)\n" + "\n" + " Disable option.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n" + " :type option: int\n"); static PyObject *py_blf_disable(PyObject *UNUSED(self), PyObject *args) { - int option, fontid; + int option, fontid; - if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) { + return NULL; + } - BLF_disable(fontid, option); + BLF_disable(fontid, option); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_enable_doc, -".. function:: enable(fontid, option)\n" -"\n" -" Enable option.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n" -" :type option: int\n" -); + ".. function:: enable(fontid, option)\n" + "\n" + " Enable option.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n" + " :type option: int\n"); static PyObject *py_blf_enable(PyObject *UNUSED(self), PyObject *args) { - int option, fontid; + int option, fontid; - if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) { + return NULL; + } - BLF_enable(fontid, option); + BLF_enable(fontid, option); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_rotation_doc, -".. function:: rotation(fontid, angle)\n" -"\n" -" Set the text rotation angle, enable/disable using ROTATION.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg angle: The angle for text drawing to use.\n" -" :type angle: float\n" -); + ".. function:: rotation(fontid, angle)\n" + "\n" + " Set the text rotation angle, enable/disable using ROTATION.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg angle: The angle for text drawing to use.\n" + " :type angle: float\n"); static PyObject *py_blf_rotation(PyObject *UNUSED(self), PyObject *args) { - float angle; - int fontid; + float angle; + int fontid; - if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) { + return NULL; + } - BLF_rotation(fontid, angle); + BLF_rotation(fontid, angle); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_shadow_doc, -".. function:: shadow(fontid, level, r, g, b, a)\n" -"\n" -" Shadow options, enable/disable using SHADOW .\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg level: The blur level, can be 3, 5 or 0.\n" -" :type level: int\n" -" :arg r: Shadow color (red channel 0.0 - 1.0).\n" -" :type r: float\n" -" :arg g: Shadow color (green channel 0.0 - 1.0).\n" -" :type g: float\n" -" :arg b: Shadow color (blue channel 0.0 - 1.0).\n" -" :type b: float\n" -" :arg a: Shadow color (alpha channel 0.0 - 1.0).\n" -" :type a: float\n" -); + ".. function:: shadow(fontid, level, r, g, b, a)\n" + "\n" + " Shadow options, enable/disable using SHADOW .\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg level: The blur level, can be 3, 5 or 0.\n" + " :type level: int\n" + " :arg r: Shadow color (red channel 0.0 - 1.0).\n" + " :type r: float\n" + " :arg g: Shadow color (green channel 0.0 - 1.0).\n" + " :type g: float\n" + " :arg b: Shadow color (blue channel 0.0 - 1.0).\n" + " :type b: float\n" + " :arg a: Shadow color (alpha channel 0.0 - 1.0).\n" + " :type a: float\n"); static PyObject *py_blf_shadow(PyObject *UNUSED(self), PyObject *args) { - int level, fontid; - float rgba[4]; + int level, fontid; + float rgba[4]; - if (!PyArg_ParseTuple( - args, "iiffff:blf.shadow", - &fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3])) - { - return NULL; - } + if (!PyArg_ParseTuple( + args, "iiffff:blf.shadow", &fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3])) { + return NULL; + } - if (level != 0 && level != 3 && level != 5) { - PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5)"); - return NULL; - } + if (level != 0 && level != 3 && level != 5) { + PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5)"); + return NULL; + } - BLF_shadow(fontid, level, rgba); + BLF_shadow(fontid, level, rgba); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_shadow_offset_doc, -".. function:: shadow_offset(fontid, x, y)\n" -"\n" -" Set the offset for shadow text.\n" -"\n" -" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n" -" :type fontid: int\n" -" :arg x: Vertical shadow offset value in pixels.\n" -" :type x: float\n" -" :arg y: Horizontal shadow offset value in pixels.\n" -" :type y: float\n" -); + ".. function:: shadow_offset(fontid, x, y)\n" + "\n" + " Set the offset for shadow text.\n" + "\n" + " :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default " + "font use 0.\n" + " :type fontid: int\n" + " :arg x: Vertical shadow offset value in pixels.\n" + " :type x: float\n" + " :arg y: Horizontal shadow offset value in pixels.\n" + " :type y: float\n"); static PyObject *py_blf_shadow_offset(PyObject *UNUSED(self), PyObject *args) { - int x, y, fontid; + int x, y, fontid; - if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) { + return NULL; + } - BLF_shadow_offset(fontid, x, y); + BLF_shadow_offset(fontid, x, y); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(py_blf_load_doc, -".. function:: load(filename)\n" -"\n" -" Load a new font.\n" -"\n" -" :arg filename: the filename of the font.\n" -" :type filename: string\n" -" :return: the new font's fontid or -1 if there was an error.\n" -" :rtype: integer\n" -); + ".. function:: load(filename)\n" + "\n" + " Load a new font.\n" + "\n" + " :arg filename: the filename of the font.\n" + " :type filename: string\n" + " :return: the new font's fontid or -1 if there was an error.\n" + " :rtype: integer\n"); static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args) { - const char *filename; + const char *filename; - if (!PyArg_ParseTuple(args, "s:blf.load", &filename)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "s:blf.load", &filename)) { + return NULL; + } - return PyLong_FromLong(BLF_load(filename)); + return PyLong_FromLong(BLF_load(filename)); } PyDoc_STRVAR(py_blf_unload_doc, -".. function:: unload(filename)\n" -"\n" -" Unload an existing font.\n" -"\n" -" :arg filename: the filename of the font.\n" -" :type filename: string\n" -); + ".. function:: unload(filename)\n" + "\n" + " Unload an existing font.\n" + "\n" + " :arg filename: the filename of the font.\n" + " :type filename: string\n"); static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args) { - const char *filename; + const char *filename; - if (!PyArg_ParseTuple(args, "s:blf.unload", &filename)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "s:blf.unload", &filename)) { + return NULL; + } - BLF_unload(filename); + BLF_unload(filename); - Py_RETURN_NONE; + Py_RETURN_NONE; } /*----------------------------MODULE INIT-------------------------*/ static PyMethodDef BLF_methods[] = { - {"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, py_blf_aspect_doc}, + {"aspect", (PyCFunction)py_blf_aspect, METH_VARARGS, py_blf_aspect_doc}, #if BLF_BLUR_ENABLE - {"blur", (PyCFunction) py_blf_blur, METH_VARARGS, py_blf_blur_doc}, + {"blur", (PyCFunction)py_blf_blur, METH_VARARGS, py_blf_blur_doc}, #endif - {"clipping", (PyCFunction) py_blf_clipping, METH_VARARGS, py_blf_clipping_doc}, - {"word_wrap", (PyCFunction) py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc}, - {"disable", (PyCFunction) py_blf_disable, METH_VARARGS, py_blf_disable_doc}, - {"dimensions", (PyCFunction) py_blf_dimensions, METH_VARARGS, py_blf_dimensions_doc}, - {"draw", (PyCFunction) py_blf_draw, METH_VARARGS, py_blf_draw_doc}, - {"enable", (PyCFunction) py_blf_enable, METH_VARARGS, py_blf_enable_doc}, - {"position", (PyCFunction) py_blf_position, METH_VARARGS, py_blf_position_doc}, - {"rotation", (PyCFunction) py_blf_rotation, METH_VARARGS, py_blf_rotation_doc}, - {"shadow", (PyCFunction) py_blf_shadow, METH_VARARGS, py_blf_shadow_doc}, - {"shadow_offset", (PyCFunction) py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_doc}, - {"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc}, - {"color", (PyCFunction) py_blf_color, METH_VARARGS, py_blf_color_doc}, - {"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc}, - {"unload", (PyCFunction) py_blf_unload, METH_VARARGS, py_blf_unload_doc}, - {NULL, NULL, 0, NULL}, + {"clipping", (PyCFunction)py_blf_clipping, METH_VARARGS, py_blf_clipping_doc}, + {"word_wrap", (PyCFunction)py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc}, + {"disable", (PyCFunction)py_blf_disable, METH_VARARGS, py_blf_disable_doc}, + {"dimensions", (PyCFunction)py_blf_dimensions, METH_VARARGS, py_blf_dimensions_doc}, + {"draw", (PyCFunction)py_blf_draw, METH_VARARGS, py_blf_draw_doc}, + {"enable", (PyCFunction)py_blf_enable, METH_VARARGS, py_blf_enable_doc}, + {"position", (PyCFunction)py_blf_position, METH_VARARGS, py_blf_position_doc}, + {"rotation", (PyCFunction)py_blf_rotation, METH_VARARGS, py_blf_rotation_doc}, + {"shadow", (PyCFunction)py_blf_shadow, METH_VARARGS, py_blf_shadow_doc}, + {"shadow_offset", (PyCFunction)py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_doc}, + {"size", (PyCFunction)py_blf_size, METH_VARARGS, py_blf_size_doc}, + {"color", (PyCFunction)py_blf_color, METH_VARARGS, py_blf_color_doc}, + {"load", (PyCFunction)py_blf_load, METH_VARARGS, py_blf_load_doc}, + {"unload", (PyCFunction)py_blf_unload, METH_VARARGS, py_blf_unload_doc}, + {NULL, NULL, 0, NULL}, }; -PyDoc_STRVAR(BLF_doc, -"This module provides access to blenders text drawing functions." -); +PyDoc_STRVAR(BLF_doc, "This module provides access to blenders text drawing functions."); static struct PyModuleDef BLF_module_def = { - PyModuleDef_HEAD_INIT, - "blf", /* m_name */ - BLF_doc, /* m_doc */ - 0, /* m_size */ - BLF_methods, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ + PyModuleDef_HEAD_INIT, + "blf", /* m_name */ + BLF_doc, /* m_doc */ + 0, /* m_size */ + BLF_methods, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ }; PyObject *BPyInit_blf(void) { - PyObject *submodule; + PyObject *submodule; - submodule = PyModule_Create(&BLF_module_def); + submodule = PyModule_Create(&BLF_module_def); - PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION); - PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING); - PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW); - PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT); - PyModule_AddIntConstant(submodule, "WORD_WRAP", BLF_WORD_WRAP); - PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME); + PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION); + PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING); + PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW); + PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT); + PyModule_AddIntConstant(submodule, "WORD_WRAP", BLF_WORD_WRAP); + PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME); - return submodule; + return submodule; } diff --git a/source/blender/python/generic/blf_py_api.h b/source/blender/python/generic/blf_py_api.h index ba816016b4f..d55dd85854e 100644 --- a/source/blender/python/generic/blf_py_api.h +++ b/source/blender/python/generic/blf_py_api.h @@ -23,4 +23,4 @@ PyObject *BPyInit_blf(void); -#endif /* __BLF_PY_API_H__ */ +#endif /* __BLF_PY_API_H__ */ diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 0baa4008f2d..2df828d89e0 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -24,7 +24,6 @@ * This should eventually be replaced by import hooks (pep 302). */ - #include <Python.h> #include <stddef.h> @@ -39,18 +38,18 @@ #include "BKE_main.h" /* UNUSED */ -#include "BKE_text.h" /* txt_to_buf */ +#include "BKE_text.h" /* txt_to_buf */ #include "py_capi_utils.h" -#include "bpy_internal_import.h" /* own include */ +#include "bpy_internal_import.h" /* own include */ static Main *bpy_import_main = NULL; static ListBase bpy_import_main_list; static PyMethodDef bpy_import_meth; static PyMethodDef bpy_reload_meth; -static PyObject *imp_reload_orig = NULL; +static PyObject *imp_reload_orig = NULL; /* 'builtins' is most likely PyEval_GetBuiltins() */ @@ -68,304 +67,309 @@ static PyObject *imp_reload_orig = NULL; */ void bpy_import_init(PyObject *builtins) { - PyObject *item; - PyObject *mod; - - PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item); - - /* move reload here - * XXX, use import hooks */ - mod = PyImport_ImportModuleLevel("importlib", NULL, NULL, NULL, 0); - if (mod) { - PyObject *mod_dict = PyModule_GetDict(mod); - - /* blender owns the function */ - imp_reload_orig = PyDict_GetItemString(mod_dict, "reload"); - Py_INCREF(imp_reload_orig); - - PyDict_SetItemString(mod_dict, "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item); - Py_DECREF(mod); - } - else { - BLI_assert(!"unable to load 'importlib' module."); - } + PyObject *item; + PyObject *mod; + + PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); + Py_DECREF(item); + + /* move reload here + * XXX, use import hooks */ + mod = PyImport_ImportModuleLevel("importlib", NULL, NULL, NULL, 0); + if (mod) { + PyObject *mod_dict = PyModule_GetDict(mod); + + /* blender owns the function */ + imp_reload_orig = PyDict_GetItemString(mod_dict, "reload"); + Py_INCREF(imp_reload_orig); + + PyDict_SetItemString(mod_dict, "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); + Py_DECREF(item); + Py_DECREF(mod); + } + else { + BLI_assert(!"unable to load 'importlib' module."); + } } - static void free_compiled_text(Text *text) { - if (text->compiled) { - Py_DECREF((PyObject *)text->compiled); - } - text->compiled = NULL; + if (text->compiled) { + Py_DECREF((PyObject *)text->compiled); + } + text->compiled = NULL; } struct Main *bpy_import_main_get(void) { - return bpy_import_main; + return bpy_import_main; } void bpy_import_main_set(struct Main *maggie) { - bpy_import_main = maggie; + bpy_import_main = maggie; } /* returns a dummy filename for a textblock so we can tell what file a text block comes from */ void bpy_text_filename_get(char *fn, size_t fn_len, Text *text) { - BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2); + BLI_snprintf( + fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2); } bool bpy_text_compile(Text *text) { - char fn_dummy[FILE_MAX]; - PyObject *fn_dummy_py; - char *buf; + char fn_dummy[FILE_MAX]; + PyObject *fn_dummy_py; + char *buf; - bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); + bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); - /* if previously compiled, free the object */ - free_compiled_text(text); + /* if previously compiled, free the object */ + free_compiled_text(text); - fn_dummy_py = PyC_UnicodeFromByte(fn_dummy); + fn_dummy_py = PyC_UnicodeFromByte(fn_dummy); - buf = txt_to_buf(text); - text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1); - MEM_freeN(buf); + buf = txt_to_buf(text); + text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1); + MEM_freeN(buf); - Py_DECREF(fn_dummy_py); + Py_DECREF(fn_dummy_py); - if (PyErr_Occurred()) { - PyErr_Print(); - PyErr_Clear(); - PySys_SetObject("last_traceback", NULL); - free_compiled_text(text); - return false; - } - else { - return true; - } + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + PySys_SetObject("last_traceback", NULL); + free_compiled_text(text); + return false; + } + else { + return true; + } } PyObject *bpy_text_import(Text *text) { - char modulename[MAX_ID_NAME + 2]; - int len; - - if (!text->compiled) { - if (bpy_text_compile(text) == false) { - return NULL; - } - } - - len = strlen(text->id.name + 2); - BLI_strncpy(modulename, text->id.name + 2, len); - modulename[len - 3] = '\0'; /* remove .py */ - return PyImport_ExecCodeModule(modulename, text->compiled); + char modulename[MAX_ID_NAME + 2]; + int len; + + if (!text->compiled) { + if (bpy_text_compile(text) == false) { + return NULL; + } + } + + len = strlen(text->id.name + 2); + BLI_strncpy(modulename, text->id.name + 2, len); + modulename[len - 3] = '\0'; /* remove .py */ + return PyImport_ExecCodeModule(modulename, text->compiled); } PyObject *bpy_text_import_name(const char *name, int *found) { - Text *text; - char txtname[MAX_ID_NAME - 2]; - int namelen = strlen(name); -//XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; - Main *maggie = bpy_import_main; - - *found = 0; - - if (!maggie) { - printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); - return NULL; - } - - /* we know this cant be importable, the name is too long for blender! */ - if (namelen >= (MAX_ID_NAME - 2) - 3) { - return NULL; - } - - memcpy(txtname, name, namelen); - memcpy(&txtname[namelen], ".py", 4); - - text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2); - - if (text) { - *found = 1; - return bpy_text_import(text); - } - - /* If we still haven't found the module try additional modules form bpy_import_main_list */ - maggie = bpy_import_main_list.first; - while (maggie && !text) { - text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2); - maggie = maggie->next; - } - - if (!text) { - return NULL; - } - else { - *found = 1; - } - - return bpy_text_import(text); + Text *text; + char txtname[MAX_ID_NAME - 2]; + int namelen = strlen(name); + //XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; + Main *maggie = bpy_import_main; + + *found = 0; + + if (!maggie) { + printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); + return NULL; + } + + /* we know this cant be importable, the name is too long for blender! */ + if (namelen >= (MAX_ID_NAME - 2) - 3) { + return NULL; + } + + memcpy(txtname, name, namelen); + memcpy(&txtname[namelen], ".py", 4); + + text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2); + + if (text) { + *found = 1; + return bpy_text_import(text); + } + + /* If we still haven't found the module try additional modules form bpy_import_main_list */ + maggie = bpy_import_main_list.first; + while (maggie && !text) { + text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2); + maggie = maggie->next; + } + + if (!text) { + return NULL; + } + else { + *found = 1; + } + + return bpy_text_import(text); } - /* * find in-memory module and recompile */ PyObject *bpy_text_reimport(PyObject *module, int *found) { - Text *text; - const char *name; - const char *filepath; -//XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; - Main *maggie = bpy_import_main; - - if (!maggie) { - printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); - return NULL; - } - - *found = 0; - - /* get name, filename from the module itself */ - if ((name = PyModule_GetName(module)) == NULL) { - return NULL; - } - - { - PyObject *module_file = PyModule_GetFilenameObject(module); - if (module_file == NULL) { - return NULL; - } - filepath = _PyUnicode_AsString(module_file); - Py_DECREF(module_file); - if (filepath == NULL) { - return NULL; - } - } - - /* look up the text object */ - text = BLI_findstring(&maggie->texts, BLI_path_basename(filepath), offsetof(ID, name) + 2); - - /* uh-oh.... didn't find it */ - if (!text) { - return NULL; - } - else { - *found = 1; - } - - if (bpy_text_compile(text) == false) { - return NULL; - } - - /* make into a module */ - return PyImport_ExecCodeModule(name, text->compiled); + Text *text; + const char *name; + const char *filepath; + //XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; + Main *maggie = bpy_import_main; + + if (!maggie) { + printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); + return NULL; + } + + *found = 0; + + /* get name, filename from the module itself */ + if ((name = PyModule_GetName(module)) == NULL) { + return NULL; + } + + { + PyObject *module_file = PyModule_GetFilenameObject(module); + if (module_file == NULL) { + return NULL; + } + filepath = _PyUnicode_AsString(module_file); + Py_DECREF(module_file); + if (filepath == NULL) { + return NULL; + } + } + + /* look up the text object */ + text = BLI_findstring(&maggie->texts, BLI_path_basename(filepath), offsetof(ID, name) + 2); + + /* uh-oh.... didn't find it */ + if (!text) { + return NULL; + } + else { + *found = 1; + } + + if (bpy_text_compile(text) == false) { + return NULL; + } + + /* make into a module */ + return PyImport_ExecCodeModule(name, text->compiled); } - static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { - PyObject *exception, *err, *tb; - const char *name; - int found = 0; - PyObject *globals = NULL, *locals = NULL, *fromlist = NULL; - int level = 0; /* relative imports */ - PyObject *newmodule; - - static const char *_keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL}; - static _PyArg_Parser _parser = {"s|OOOi:bpy_import_meth", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast( - args, kw, &_parser, - &name, &globals, &locals, &fromlist, &level)) - { - return NULL; - } - - /* import existing builtin modules or modules that have been imported already */ - newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); - - if (newmodule) { - return newmodule; - } - - PyErr_Fetch(&exception, &err, &tb); /* get the python error in case we cant import as blender text either */ - - /* importing from existing modules failed, see if we have this module as blender text */ - newmodule = bpy_text_import_name(name, &found); - - if (newmodule) { /* found module as blender text, ignore above exception */ - PyErr_Clear(); - Py_XDECREF(exception); - Py_XDECREF(err); - Py_XDECREF(tb); - /* printf("imported from text buffer...\n"); */ - } - else if (found == 1) { /* blender text module failed to execute but was found, use its error message */ - Py_XDECREF(exception); - Py_XDECREF(err); - Py_XDECREF(tb); - return NULL; - } - else { - /* no blender text was found that could import the module - * reuse the original error from PyImport_ImportModuleEx */ - PyErr_Restore(exception, err, tb); - } - return newmodule; + PyObject *exception, *err, *tb; + const char *name; + int found = 0; + PyObject *globals = NULL, *locals = NULL, *fromlist = NULL; + int level = 0; /* relative imports */ + PyObject *newmodule; + + static const char *_keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL}; + static _PyArg_Parser _parser = {"s|OOOi:bpy_import_meth", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, &name, &globals, &locals, &fromlist, &level)) { + return NULL; + } + + /* import existing builtin modules or modules that have been imported already */ + newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); + + if (newmodule) { + return newmodule; + } + + PyErr_Fetch(&exception, + &err, + &tb); /* get the python error in case we cant import as blender text either */ + + /* importing from existing modules failed, see if we have this module as blender text */ + newmodule = bpy_text_import_name(name, &found); + + if (newmodule) { /* found module as blender text, ignore above exception */ + PyErr_Clear(); + Py_XDECREF(exception); + Py_XDECREF(err); + Py_XDECREF(tb); + /* printf("imported from text buffer...\n"); */ + } + else if (found == + 1) { /* blender text module failed to execute but was found, use its error message */ + Py_XDECREF(exception); + Py_XDECREF(err); + Py_XDECREF(tb); + return NULL; + } + else { + /* no blender text was found that could import the module + * reuse the original error from PyImport_ImportModuleEx */ + PyErr_Restore(exception, err, tb); + } + return newmodule; } - /* * our reload() module, to handle reloading in-memory scripts */ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) { - PyObject *exception, *err, *tb; - PyObject *newmodule = NULL; - int found = 0; - - /* try reimporting from file */ - - /* in Py3.3 this just calls imp.reload() which we overwrite, causing recursive calls */ - //newmodule = PyImport_ReloadModule(module); - - newmodule = PyObject_CallFunctionObjArgs(imp_reload_orig, module, NULL); - - if (newmodule) { - return newmodule; - } - - /* no file, try importing from memory */ - PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */ - - newmodule = bpy_text_reimport(module, &found); - if (newmodule) { /* found module as blender text, ignore above exception */ - PyErr_Clear(); - Py_XDECREF(exception); - Py_XDECREF(err); - Py_XDECREF(tb); - /* printf("imported from text buffer...\n"); */ - } - else if (found == 1) { /* blender text module failed to execute but was found, use its error message */ - Py_XDECREF(exception); - Py_XDECREF(err); - Py_XDECREF(tb); - return NULL; - } - else { - /* no blender text was found that could import the module - * reuse the original error from PyImport_ImportModuleEx */ - PyErr_Restore(exception, err, tb); - } - - return newmodule; + PyObject *exception, *err, *tb; + PyObject *newmodule = NULL; + int found = 0; + + /* try reimporting from file */ + + /* in Py3.3 this just calls imp.reload() which we overwrite, causing recursive calls */ + //newmodule = PyImport_ReloadModule(module); + + newmodule = PyObject_CallFunctionObjArgs(imp_reload_orig, module, NULL); + + if (newmodule) { + return newmodule; + } + + /* no file, try importing from memory */ + PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */ + + newmodule = bpy_text_reimport(module, &found); + if (newmodule) { /* found module as blender text, ignore above exception */ + PyErr_Clear(); + Py_XDECREF(exception); + Py_XDECREF(err); + Py_XDECREF(tb); + /* printf("imported from text buffer...\n"); */ + } + else if (found == + 1) { /* blender text module failed to execute but was found, use its error message */ + Py_XDECREF(exception); + Py_XDECREF(err); + Py_XDECREF(tb); + return NULL; + } + else { + /* no blender text was found that could import the module + * reuse the original error from PyImport_ImportModuleEx */ + PyErr_Restore(exception, err, tb); + } + + return newmodule; } -static PyMethodDef bpy_import_meth = {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"}; -static PyMethodDef bpy_reload_meth = {"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"}; +static PyMethodDef bpy_import_meth = {"bpy_import_meth", + (PyCFunction)blender_import, + METH_VARARGS | METH_KEYWORDS, + "blenders import"}; +static PyMethodDef bpy_reload_meth = { + "bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"}; diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h index bb02b7c2cfe..2ab535d1018 100644 --- a/source/blender/python/generic/bpy_internal_import.h +++ b/source/blender/python/generic/bpy_internal_import.h @@ -18,7 +18,6 @@ * \ingroup pygen */ - /* Note, the BGE needs to use this too, keep it minimal */ #ifndef __BPY_INTERNAL_IMPORT_H__ @@ -26,26 +25,26 @@ /* python redefines :/ */ #ifdef _POSIX_C_SOURCE -#undef _POSIX_C_SOURCE +# undef _POSIX_C_SOURCE #endif #ifdef _XOPEN_SOURCE -#undef _XOPEN_SOURCE +# undef _XOPEN_SOURCE #endif struct Text; void bpy_import_init(PyObject *builtins); -bool bpy_text_compile(struct Text *text); -PyObject *bpy_text_import(struct Text *text); -PyObject *bpy_text_import_name(const char *name, int *found); -PyObject *bpy_text_reimport(PyObject *module, int *found); -/* void bpy_text_clear_modules(int clear_all);*/ /* Clear user modules */ +bool bpy_text_compile(struct Text *text); +PyObject *bpy_text_import(struct Text *text); +PyObject *bpy_text_import_name(const char *name, int *found); +PyObject *bpy_text_reimport(PyObject *module, int *found); +/* void bpy_text_clear_modules(int clear_all);*/ /* Clear user modules */ void bpy_text_filename_get(char *fn, size_t fn_len, struct Text *text); struct Main *bpy_import_main_get(void); void bpy_import_main_set(struct Main *maggie); -#endif /* __BPY_INTERNAL_IMPORT_H__ */ +#endif /* __BPY_INTERNAL_IMPORT_H__ */ diff --git a/source/blender/python/generic/bpy_threads.c b/source/blender/python/generic/bpy_threads.c index 1f80caa6182..2474b08180f 100644 --- a/source/blender/python/generic/bpy_threads.c +++ b/source/blender/python/generic/bpy_threads.c @@ -29,20 +29,20 @@ /* analogue of PyEval_SaveThread() */ BPy_ThreadStatePtr BPY_thread_save(void) { - PyThreadState *tstate = PyThreadState_Swap(NULL); - /* note: tstate can be NULL when quitting Blender */ + PyThreadState *tstate = PyThreadState_Swap(NULL); + /* note: tstate can be NULL when quitting Blender */ - if (tstate && PyEval_ThreadsInitialized()) { - PyEval_ReleaseLock(); - } + if (tstate && PyEval_ThreadsInitialized()) { + PyEval_ReleaseLock(); + } - return (BPy_ThreadStatePtr)tstate; + return (BPy_ThreadStatePtr)tstate; } /* analogue of PyEval_RestoreThread() */ void BPY_thread_restore(BPy_ThreadStatePtr tstate) { - if (tstate) { - PyEval_RestoreThread((PyThreadState *)tstate); - } + if (tstate) { + PyEval_RestoreThread((PyThreadState *)tstate); + } } diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c index f18d02a4405..d96bef797cb 100644 --- a/source/blender/python/generic/idprop_py_api.c +++ b/source/blender/python/generic/idprop_py_api.c @@ -31,7 +31,7 @@ #define USE_STRING_COERCE #ifdef USE_STRING_COERCE -#include "py_capi_utils.h" +# include "py_capi_utils.h" #endif #include "python_utildefines.h" @@ -48,81 +48,80 @@ extern bool pyrna_id_CheckPyObject(PyObject *obj); static PyObject *idprop_py_from_idp_string(const IDProperty *prop) { - if (prop->subtype == IDP_STRING_SUB_BYTE) { - return PyBytes_FromStringAndSize(IDP_String(prop), prop->len); - } - else { + if (prop->subtype == IDP_STRING_SUB_BYTE) { + return PyBytes_FromStringAndSize(IDP_String(prop), prop->len); + } + else { #ifdef USE_STRING_COERCE - return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1); + return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1); #else - return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1); + return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1); #endif - } + } } static PyObject *idprop_py_from_idp_int(const IDProperty *prop) { - return PyLong_FromLong((long)IDP_Int(prop)); + return PyLong_FromLong((long)IDP_Int(prop)); } static PyObject *idprop_py_from_idp_float(const IDProperty *prop) { - return PyFloat_FromDouble((double)IDP_Float(prop)); + return PyFloat_FromDouble((double)IDP_Float(prop)); } static PyObject *idprop_py_from_idp_double(const IDProperty *prop) { - return PyFloat_FromDouble(IDP_Double(prop)); + return PyFloat_FromDouble(IDP_Double(prop)); } static PyObject *idprop_py_from_idp_group(ID *id, IDProperty *prop, IDProperty *parent) { - BPy_IDProperty *group = PyObject_New(BPy_IDProperty, &BPy_IDGroup_Type); - group->id = id; - group->prop = prop; - group->parent = parent; /* can be NULL */ - return (PyObject *)group; + BPy_IDProperty *group = PyObject_New(BPy_IDProperty, &BPy_IDGroup_Type); + group->id = id; + group->prop = prop; + group->parent = parent; /* can be NULL */ + return (PyObject *)group; } static PyObject *idprop_py_from_idp_id(IDProperty *prop) { - return pyrna_id_CreatePyObject(prop->data.pointer); + return pyrna_id_CreatePyObject(prop->data.pointer); } static PyObject *idprop_py_from_idp_array(ID *id, IDProperty *prop) { - BPy_IDProperty *array = PyObject_New(BPy_IDProperty, &BPy_IDArray_Type); - array->id = id; - array->prop = prop; - return (PyObject *)array; + BPy_IDProperty *array = PyObject_New(BPy_IDProperty, &BPy_IDArray_Type); + array->id = id; + array->prop = prop; + return (PyObject *)array; } static PyObject *idprop_py_from_idp_idparray(ID *id, IDProperty *prop) { - PyObject *seq = PyList_New(prop->len); - IDProperty *array = IDP_IDPArray(prop); - int i; + PyObject *seq = PyList_New(prop->len); + IDProperty *array = IDP_IDPArray(prop); + int i; - if (!seq) { - PyErr_Format(PyExc_RuntimeError, - "%s: IDP_IDPARRAY: PyList_New(%d) failed", - __func__, prop->len); - return NULL; - } + if (!seq) { + PyErr_Format( + PyExc_RuntimeError, "%s: IDP_IDPARRAY: PyList_New(%d) failed", __func__, prop->len); + return NULL; + } - for (i = 0; i < prop->len; i++) { - PyObject *wrap = BPy_IDGroup_WrapData(id, array++, prop); + for (i = 0; i < prop->len; i++) { + PyObject *wrap = BPy_IDGroup_WrapData(id, array++, prop); - /* BPy_IDGroup_MapDataToPy sets the error */ - if (UNLIKELY(wrap == NULL)) { - Py_DECREF(seq); - return NULL; - } + /* BPy_IDGroup_MapDataToPy sets the error */ + if (UNLIKELY(wrap == NULL)) { + Py_DECREF(seq); + return NULL; + } - PyList_SET_ITEM(seq, i, wrap); - } + PyList_SET_ITEM(seq, i, wrap); + } - return seq; + return seq; } /* -------------------------------------------------------------------------- */ @@ -130,236 +129,252 @@ static PyObject *idprop_py_from_idp_idparray(ID *id, IDProperty *prop) /* use for both array and group */ static Py_hash_t BPy_IDGroup_hash(BPy_IDProperty *self) { - return _Py_HashPointer(self->prop); + return _Py_HashPointer(self->prop); } static PyObject *BPy_IDGroup_repr(BPy_IDProperty *self) { - return PyUnicode_FromFormat("<bpy id prop: owner=\"%s\", name=\"%s\", address=%p>", - self->id ? self->id->name : "<NONE>", self->prop->name, self->prop); + return PyUnicode_FromFormat("<bpy id prop: owner=\"%s\", name=\"%s\", address=%p>", + self->id ? self->id->name : "<NONE>", + self->prop->name, + self->prop); } PyObject *BPy_IDGroup_WrapData(ID *id, IDProperty *prop, IDProperty *parent) { - switch (prop->type) { - case IDP_STRING: return idprop_py_from_idp_string(prop); - case IDP_INT: return idprop_py_from_idp_int(prop); - case IDP_FLOAT: return idprop_py_from_idp_float(prop); - case IDP_DOUBLE: return idprop_py_from_idp_double(prop); - case IDP_GROUP: return idprop_py_from_idp_group(id, prop, parent); - case IDP_ARRAY: return idprop_py_from_idp_array(id, prop); - case IDP_IDPARRAY: return idprop_py_from_idp_idparray(id, prop); /* this could be better a internal type */ - case IDP_ID: return idprop_py_from_idp_id(prop); - default: Py_RETURN_NONE; - } + switch (prop->type) { + case IDP_STRING: + return idprop_py_from_idp_string(prop); + case IDP_INT: + return idprop_py_from_idp_int(prop); + case IDP_FLOAT: + return idprop_py_from_idp_float(prop); + case IDP_DOUBLE: + return idprop_py_from_idp_double(prop); + case IDP_GROUP: + return idprop_py_from_idp_group(id, prop, parent); + case IDP_ARRAY: + return idprop_py_from_idp_array(id, prop); + case IDP_IDPARRAY: + return idprop_py_from_idp_idparray(id, prop); /* this could be better a internal type */ + case IDP_ID: + return idprop_py_from_idp_id(prop); + default: + Py_RETURN_NONE; + } } #if 0 /* UNUSED, currently assignment overwrites into new properties, rather than setting in-place */ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value) { - switch (prop->type) { - case IDP_STRING: - { - char *st; - if (!PyUnicode_Check(value)) { - PyErr_SetString(PyExc_TypeError, "expected a string!"); - return -1; - } - /* NOTE: if this code is enabled, bytes support needs to be added */ -#ifdef USE_STRING_COERCE - { - int alloc_len; - PyObject *value_coerce = NULL; - - st = (char *)PyC_UnicodeAsByte(value, &value_coerce); - alloc_len = strlen(st) + 1; - - st = _PyUnicode_AsString(value); - IDP_ResizeArray(prop, alloc_len); - memcpy(IDP_Array(prop), st, alloc_len); - Py_XDECREF(value_coerce); - } -#else - st = _PyUnicode_AsString(value); - IDP_ResizeArray(prop, strlen(st) + 1); - strcpy(IDP_Array(prop), st); -#endif - - return 0; - } - - case IDP_INT: - { - int ivalue = PyLong_AsSsize_t(value); - if (ivalue == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "expected an int type"); - return -1; - } - IDP_Int(prop) = ivalue; - break; - } - case IDP_FLOAT: - { - float fvalue = (float)PyFloat_AsDouble(value); - if (fvalue == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "expected a float"); - return -1; - } - IDP_Float(self->prop) = fvalue; - break; - } - case IDP_DOUBLE: - { - double dvalue = PyFloat_AsDouble(value); - if (dvalue == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "expected a float"); - return -1; - } - IDP_Double(self->prop) = dvalue; - break; - } - default: - PyErr_SetString(PyExc_AttributeError, "attempt to set read-only attribute!"); - return -1; - } - return 0; + switch (prop->type) { + case IDP_STRING: + { + char *st; + if (!PyUnicode_Check(value)) { + PyErr_SetString(PyExc_TypeError, "expected a string!"); + return -1; + } + /* NOTE: if this code is enabled, bytes support needs to be added */ +# ifdef USE_STRING_COERCE + { + int alloc_len; + PyObject *value_coerce = NULL; + + st = (char *)PyC_UnicodeAsByte(value, &value_coerce); + alloc_len = strlen(st) + 1; + + st = _PyUnicode_AsString(value); + IDP_ResizeArray(prop, alloc_len); + memcpy(IDP_Array(prop), st, alloc_len); + Py_XDECREF(value_coerce); + } +# else + st = _PyUnicode_AsString(value); + IDP_ResizeArray(prop, strlen(st) + 1); + strcpy(IDP_Array(prop), st); +# endif + + return 0; + } + + case IDP_INT: + { + int ivalue = PyLong_AsSsize_t(value); + if (ivalue == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "expected an int type"); + return -1; + } + IDP_Int(prop) = ivalue; + break; + } + case IDP_FLOAT: + { + float fvalue = (float)PyFloat_AsDouble(value); + if (fvalue == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "expected a float"); + return -1; + } + IDP_Float(self->prop) = fvalue; + break; + } + case IDP_DOUBLE: + { + double dvalue = PyFloat_AsDouble(value); + if (dvalue == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "expected a float"); + return -1; + } + IDP_Double(self->prop) = dvalue; + break; + } + default: + PyErr_SetString(PyExc_AttributeError, "attempt to set read-only attribute!"); + return -1; + } + return 0; } #endif static PyObject *BPy_IDGroup_GetName(BPy_IDProperty *self, void *UNUSED(closure)) { - return PyUnicode_FromString(self->prop->name); + return PyUnicode_FromString(self->prop->name); } static int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void *UNUSED(closure)) { - const char *name; - Py_ssize_t name_size; + const char *name; + Py_ssize_t name_size; - if (!PyUnicode_Check(value)) { - PyErr_SetString(PyExc_TypeError, "expected a string!"); - return -1; - } + if (!PyUnicode_Check(value)) { + PyErr_SetString(PyExc_TypeError, "expected a string!"); + return -1; + } - name = _PyUnicode_AsStringAndSize(value, &name_size); + name = _PyUnicode_AsStringAndSize(value, &name_size); - if (name_size > MAX_IDPROP_NAME) { - PyErr_SetString(PyExc_TypeError, "string length cannot exceed 63 characters!"); - return -1; - } + if (name_size > MAX_IDPROP_NAME) { + PyErr_SetString(PyExc_TypeError, "string length cannot exceed 63 characters!"); + return -1; + } - memcpy(self->prop->name, name, name_size); - return 0; + memcpy(self->prop->name, name, name_size); + return 0; } #if 0 static PyObject *BPy_IDGroup_GetType(BPy_IDProperty *self) { - return PyLong_FromLong(self->prop->type); + return PyLong_FromLong(self->prop->type); } #endif static PyGetSetDef BPy_IDGroup_getseters[] = { - {(char *)"name", (getter)BPy_IDGroup_GetName, (setter)BPy_IDGroup_SetName, (char *)"The name of this Group.", NULL}, - {NULL, NULL, NULL, NULL, NULL}, + {(char *)"name", + (getter)BPy_IDGroup_GetName, + (setter)BPy_IDGroup_SetName, + (char *)"The name of this Group.", + NULL}, + {NULL, NULL, NULL, NULL, NULL}, }; static Py_ssize_t BPy_IDGroup_Map_Len(BPy_IDProperty *self) { - if (self->prop->type != IDP_GROUP) { - PyErr_SetString(PyExc_TypeError, "len() of unsized object"); - return -1; - } + if (self->prop->type != IDP_GROUP) { + PyErr_SetString(PyExc_TypeError, "len() of unsized object"); + return -1; + } - return self->prop->len; + return self->prop->len; } static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item) { - IDProperty *idprop; - const char *name; + IDProperty *idprop; + const char *name; - if (self->prop->type != IDP_GROUP) { - PyErr_SetString(PyExc_TypeError, "unsubscriptable object"); - return NULL; - } + if (self->prop->type != IDP_GROUP) { + PyErr_SetString(PyExc_TypeError, "unsubscriptable object"); + return NULL; + } - name = _PyUnicode_AsString(item); + name = _PyUnicode_AsString(item); - if (name == NULL) { - PyErr_SetString(PyExc_TypeError, "only strings are allowed as keys of ID properties"); - return NULL; - } + if (name == NULL) { + PyErr_SetString(PyExc_TypeError, "only strings are allowed as keys of ID properties"); + return NULL; + } - idprop = IDP_GetPropertyFromGroup(self->prop, name); + idprop = IDP_GetPropertyFromGroup(self->prop, name); - if (idprop == NULL) { - PyErr_SetString(PyExc_KeyError, "key not in subgroup dict"); - return NULL; - } + if (idprop == NULL) { + PyErr_SetString(PyExc_KeyError, "key not in subgroup dict"); + return NULL; + } - return BPy_IDGroup_WrapData(self->id, idprop, self->prop); + return BPy_IDGroup_WrapData(self->id, idprop, self->prop); } /* returns NULL on success, error string on failure */ static char idp_sequence_type(PyObject *seq_fast) { - PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast); - PyObject *item; - char type = IDP_INT; - - Py_ssize_t i, len = PySequence_Fast_GET_SIZE(seq_fast); - - for (i = 0; i < len; i++) { - item = seq_fast_items[i]; - if (PyFloat_Check(item)) { - if (type == IDP_IDPARRAY) { /* mixed dict/int */ - return -1; - } - type = IDP_DOUBLE; - } - else if (PyLong_Check(item)) { - if (type == IDP_IDPARRAY) { /* mixed dict/int */ - return -1; - } - } - else if (PyMapping_Check(item)) { - if (i != 0 && (type != IDP_IDPARRAY)) { /* mixed dict/int */ - return -1; - } - type = IDP_IDPARRAY; - } - else { - return -1; - } - } - - return type; + PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast); + PyObject *item; + char type = IDP_INT; + + Py_ssize_t i, len = PySequence_Fast_GET_SIZE(seq_fast); + + for (i = 0; i < len; i++) { + item = seq_fast_items[i]; + if (PyFloat_Check(item)) { + if (type == IDP_IDPARRAY) { /* mixed dict/int */ + return -1; + } + type = IDP_DOUBLE; + } + else if (PyLong_Check(item)) { + if (type == IDP_IDPARRAY) { /* mixed dict/int */ + return -1; + } + } + else if (PyMapping_Check(item)) { + if (i != 0 && (type != IDP_IDPARRAY)) { /* mixed dict/int */ + return -1; + } + type = IDP_IDPARRAY; + } + else { + return -1; + } + } + + return type; } static const char *idp_try_read_name(PyObject *name_obj) { - const char *name = NULL; - if (name_obj) { - Py_ssize_t name_size; - name = _PyUnicode_AsStringAndSize(name_obj, &name_size); - - if (name == NULL) { - PyErr_Format(PyExc_KeyError, - "invalid id-property key, expected a string, not a %.200s", - Py_TYPE(name_obj)->tp_name); - return NULL; - } - - if (name_size > MAX_IDPROP_NAME) { - PyErr_SetString(PyExc_KeyError, "the length of IDProperty names is limited to 63 characters"); - return NULL; - } - } - else { - name = ""; - } - return name; + const char *name = NULL; + if (name_obj) { + Py_ssize_t name_size; + name = _PyUnicode_AsStringAndSize(name_obj, &name_size); + + if (name == NULL) { + PyErr_Format(PyExc_KeyError, + "invalid id-property key, expected a string, not a %.200s", + Py_TYPE(name_obj)->tp_name); + return NULL; + } + + if (name_size > MAX_IDPROP_NAME) { + PyErr_SetString(PyExc_KeyError, + "the length of IDProperty names is limited to 63 characters"); + return NULL; + } + } + else { + name = ""; + } + return name; } /* -------------------------------------------------------------------------- */ @@ -371,285 +386,280 @@ static const char *idp_try_read_name(PyObject *name_obj) static IDProperty *idp_from_PyFloat(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - val.d = PyFloat_AsDouble(ob); - return IDP_New(IDP_DOUBLE, &val, name); + IDPropertyTemplate val = {0}; + val.d = PyFloat_AsDouble(ob); + return IDP_New(IDP_DOUBLE, &val, name); } static IDProperty *idp_from_PyLong(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - val.i = PyC_Long_AsI32(ob); - if (val.i == -1 && PyErr_Occurred()) { - return NULL; - } - return IDP_New(IDP_INT, &val, name); + IDPropertyTemplate val = {0}; + val.i = PyC_Long_AsI32(ob); + if (val.i == -1 && PyErr_Occurred()) { + return NULL; + } + return IDP_New(IDP_INT, &val, name); } static IDProperty *idp_from_PyUnicode(const char *name, PyObject *ob) { - IDProperty *prop; - IDPropertyTemplate val = {0}; + IDProperty *prop; + IDPropertyTemplate val = {0}; #ifdef USE_STRING_COERCE - Py_ssize_t value_size; - PyObject *value_coerce = NULL; - val.string.str = PyC_UnicodeAsByteAndSize(ob, &value_size, &value_coerce); - val.string.len = (int)value_size + 1; - val.string.subtype = IDP_STRING_SUB_UTF8; - prop = IDP_New(IDP_STRING, &val, name); - Py_XDECREF(value_coerce); + Py_ssize_t value_size; + PyObject *value_coerce = NULL; + val.string.str = PyC_UnicodeAsByteAndSize(ob, &value_size, &value_coerce); + val.string.len = (int)value_size + 1; + val.string.subtype = IDP_STRING_SUB_UTF8; + prop = IDP_New(IDP_STRING, &val, name); + Py_XDECREF(value_coerce); #else - val.str = _PyUnicode_AsString(ob); - prop = IDP_New(IDP_STRING, val, name); + val.str = _PyUnicode_AsString(ob); + prop = IDP_New(IDP_STRING, val, name); #endif - return prop; + return prop; } static IDProperty *idp_from_PyBytes(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - val.string.str = PyBytes_AS_STRING(ob); - val.string.len = PyBytes_GET_SIZE(ob); - val.string.subtype = IDP_STRING_SUB_BYTE; - return IDP_New(IDP_STRING, &val, name); + IDPropertyTemplate val = {0}; + val.string.str = PyBytes_AS_STRING(ob); + val.string.len = PyBytes_GET_SIZE(ob); + val.string.subtype = IDP_STRING_SUB_BYTE; + return IDP_New(IDP_STRING, &val, name); } static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_t itemsize) { - char format = PyC_StructFmt_type_from_str(typestr); + char format = PyC_StructFmt_type_from_str(typestr); - if (PyC_StructFmt_type_is_float_any(format)) { - if (itemsize == 4) { - return IDP_FLOAT; - } - if (itemsize == 8) { - return IDP_DOUBLE; - } - } - if (PyC_StructFmt_type_is_int_any(format)) { - if (itemsize == 4) { - return IDP_INT; - } - } + if (PyC_StructFmt_type_is_float_any(format)) { + if (itemsize == 4) { + return IDP_FLOAT; + } + if (itemsize == 8) { + return IDP_DOUBLE; + } + } + if (PyC_StructFmt_type_is_int_any(format)) { + if (itemsize == 4) { + return IDP_INT; + } + } - return -1; + return -1; } static const char *idp_format_from_array_type(int type) { - if (type == IDP_INT) { - return "i"; - } - if (type == IDP_FLOAT) { - return "f"; - } - if (type == IDP_DOUBLE) { - return "d"; - } - return NULL; + if (type == IDP_INT) { + return "i"; + } + if (type == IDP_FLOAT) { + return "f"; + } + if (type == IDP_DOUBLE) { + return "d"; + } + return NULL; } static IDProperty *idp_from_PySequence_Buffer(const char *name, Py_buffer *buffer) { - IDProperty *prop; - IDPropertyTemplate val = {0}; + IDProperty *prop; + IDPropertyTemplate val = {0}; - int id_type = idp_array_type_from_formatstr_and_size(buffer->format, buffer->itemsize); - if (id_type == -1) { - /* should never happen as the type has been checked before */ - return NULL; - } - else { - val.array.type = id_type; - val.array.len = buffer->len / buffer->itemsize; - } - prop = IDP_New(IDP_ARRAY, &val, name); - memcpy(IDP_Array(prop), buffer->buf, buffer->len); - return prop; + int id_type = idp_array_type_from_formatstr_and_size(buffer->format, buffer->itemsize); + if (id_type == -1) { + /* should never happen as the type has been checked before */ + return NULL; + } + else { + val.array.type = id_type; + val.array.len = buffer->len / buffer->itemsize; + } + prop = IDP_New(IDP_ARRAY, &val, name); + memcpy(IDP_Array(prop), buffer->buf, buffer->len); + return prop; } static IDProperty *idp_from_PySequence_Fast(const char *name, PyObject *ob) { - IDProperty *prop; - IDPropertyTemplate val = {0}; - - PyObject **ob_seq_fast_items; - PyObject *item; - int i; - - ob_seq_fast_items = PySequence_Fast_ITEMS(ob); - - if ((val.array.type = idp_sequence_type(ob)) == (char)-1) { - PyErr_SetString(PyExc_TypeError, "only floats, ints and dicts are allowed in ID property arrays"); - return NULL; - } - - /* validate sequence and derive type. - * we assume IDP_INT unless we hit a float - * number; then we assume it's */ - - val.array.len = PySequence_Fast_GET_SIZE(ob); - - switch (val.array.type) { - case IDP_DOUBLE: - { - double *prop_data; - prop = IDP_New(IDP_ARRAY, &val, name); - prop_data = IDP_Array(prop); - for (i = 0; i < val.array.len; i++) { - item = ob_seq_fast_items[i]; - if (((prop_data[i] = PyFloat_AsDouble(item)) == -1.0) && PyErr_Occurred()) { - return NULL; - } - } - break; - } - case IDP_INT: - { - int *prop_data; - prop = IDP_New(IDP_ARRAY, &val, name); - prop_data = IDP_Array(prop); - for (i = 0; i < val.array.len; i++) { - item = ob_seq_fast_items[i]; - if (((prop_data[i] = PyC_Long_AsI32(item)) == -1) && PyErr_Occurred()) { - return NULL; - } - } - break; - } - case IDP_IDPARRAY: - { - prop = IDP_NewIDPArray(name); - for (i = 0; i < val.array.len; i++) { - item = ob_seq_fast_items[i]; - if (BPy_IDProperty_Map_ValidateAndCreate(NULL, prop, item) == false) { - return NULL; - } - } - break; - } - default: - /* should never happen */ - PyErr_SetString(PyExc_RuntimeError, "internal error with idp array.type"); - return NULL; - } - return prop; + IDProperty *prop; + IDPropertyTemplate val = {0}; + + PyObject **ob_seq_fast_items; + PyObject *item; + int i; + + ob_seq_fast_items = PySequence_Fast_ITEMS(ob); + + if ((val.array.type = idp_sequence_type(ob)) == (char)-1) { + PyErr_SetString(PyExc_TypeError, + "only floats, ints and dicts are allowed in ID property arrays"); + return NULL; + } + + /* validate sequence and derive type. + * we assume IDP_INT unless we hit a float + * number; then we assume it's */ + + val.array.len = PySequence_Fast_GET_SIZE(ob); + + switch (val.array.type) { + case IDP_DOUBLE: { + double *prop_data; + prop = IDP_New(IDP_ARRAY, &val, name); + prop_data = IDP_Array(prop); + for (i = 0; i < val.array.len; i++) { + item = ob_seq_fast_items[i]; + if (((prop_data[i] = PyFloat_AsDouble(item)) == -1.0) && PyErr_Occurred()) { + return NULL; + } + } + break; + } + case IDP_INT: { + int *prop_data; + prop = IDP_New(IDP_ARRAY, &val, name); + prop_data = IDP_Array(prop); + for (i = 0; i < val.array.len; i++) { + item = ob_seq_fast_items[i]; + if (((prop_data[i] = PyC_Long_AsI32(item)) == -1) && PyErr_Occurred()) { + return NULL; + } + } + break; + } + case IDP_IDPARRAY: { + prop = IDP_NewIDPArray(name); + for (i = 0; i < val.array.len; i++) { + item = ob_seq_fast_items[i]; + if (BPy_IDProperty_Map_ValidateAndCreate(NULL, prop, item) == false) { + return NULL; + } + } + break; + } + default: + /* should never happen */ + PyErr_SetString(PyExc_RuntimeError, "internal error with idp array.type"); + return NULL; + } + return prop; } - static IDProperty *idp_from_PySequence(const char *name, PyObject *ob) { - Py_buffer buffer; - bool use_buffer = false; - - if (PyObject_CheckBuffer(ob)) { - PyObject_GetBuffer(ob, &buffer, PyBUF_SIMPLE | PyBUF_FORMAT); - char format = PyC_StructFmt_type_from_str(buffer.format); - if (PyC_StructFmt_type_is_float_any(format) || - (PyC_StructFmt_type_is_int_any(format) && buffer.itemsize == 4)) - { - use_buffer = true; - } - else { - PyBuffer_Release(&buffer); - } - } - - if (use_buffer) { - IDProperty *prop = idp_from_PySequence_Buffer(name, &buffer); - PyBuffer_Release(&buffer); - return prop; - } - else { - PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop"); - if (ob_seq_fast != NULL) { - IDProperty *prop = idp_from_PySequence_Fast(name, ob_seq_fast); - Py_DECREF(ob_seq_fast); - return prop; - } - else { - return NULL; - } - } + Py_buffer buffer; + bool use_buffer = false; + + if (PyObject_CheckBuffer(ob)) { + PyObject_GetBuffer(ob, &buffer, PyBUF_SIMPLE | PyBUF_FORMAT); + char format = PyC_StructFmt_type_from_str(buffer.format); + if (PyC_StructFmt_type_is_float_any(format) || + (PyC_StructFmt_type_is_int_any(format) && buffer.itemsize == 4)) { + use_buffer = true; + } + else { + PyBuffer_Release(&buffer); + } + } + + if (use_buffer) { + IDProperty *prop = idp_from_PySequence_Buffer(name, &buffer); + PyBuffer_Release(&buffer); + return prop; + } + else { + PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop"); + if (ob_seq_fast != NULL) { + IDProperty *prop = idp_from_PySequence_Fast(name, ob_seq_fast); + Py_DECREF(ob_seq_fast); + return prop; + } + else { + return NULL; + } + } } static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob) { - IDProperty *prop; - IDPropertyTemplate val = {0}; - - PyObject *keys, *vals, *key, *pval; - int i, len; - /* yay! we get into recursive stuff now! */ - keys = PyMapping_Keys(ob); - vals = PyMapping_Values(ob); - - /* we allocate the group first; if we hit any invalid data, - * we can delete it easily enough.*/ - prop = IDP_New(IDP_GROUP, &val, name); - len = PyMapping_Length(ob); - for (i = 0; i < len; i++) { - key = PySequence_GetItem(keys, i); - pval = PySequence_GetItem(vals, i); - if (BPy_IDProperty_Map_ValidateAndCreate(key, prop, pval) == false) { - IDP_FreeProperty(prop); - MEM_freeN(prop); - Py_XDECREF(keys); - Py_XDECREF(vals); - Py_XDECREF(key); - Py_XDECREF(pval); - /* error is already set */ - return NULL; - } - Py_XDECREF(key); - Py_XDECREF(pval); - } - Py_XDECREF(keys); - Py_XDECREF(vals); - return prop; + IDProperty *prop; + IDPropertyTemplate val = {0}; + + PyObject *keys, *vals, *key, *pval; + int i, len; + /* yay! we get into recursive stuff now! */ + keys = PyMapping_Keys(ob); + vals = PyMapping_Values(ob); + + /* we allocate the group first; if we hit any invalid data, + * we can delete it easily enough.*/ + prop = IDP_New(IDP_GROUP, &val, name); + len = PyMapping_Length(ob); + for (i = 0; i < len; i++) { + key = PySequence_GetItem(keys, i); + pval = PySequence_GetItem(vals, i); + if (BPy_IDProperty_Map_ValidateAndCreate(key, prop, pval) == false) { + IDP_FreeProperty(prop); + MEM_freeN(prop); + Py_XDECREF(keys); + Py_XDECREF(vals); + Py_XDECREF(key); + Py_XDECREF(pval); + /* error is already set */ + return NULL; + } + Py_XDECREF(key); + Py_XDECREF(pval); + } + Py_XDECREF(keys); + Py_XDECREF(vals); + return prop; } static IDProperty *idp_from_DatablockPointer(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - pyrna_id_FromPyObject(ob, &val.id); - return IDP_New(IDP_ID, &val, name); + IDPropertyTemplate val = {0}; + pyrna_id_FromPyObject(ob, &val.id); + return IDP_New(IDP_ID, &val, name); } static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob) { - const char *name = idp_try_read_name(name_obj); - if (name == NULL) { - return NULL; - } - - if (PyFloat_Check(ob)) { - return idp_from_PyFloat(name, ob); - } - else if (PyLong_Check(ob)) { - return idp_from_PyLong(name, ob); - } - else if (PyUnicode_Check(ob)) { - return idp_from_PyUnicode(name, ob); - } - else if (PyBytes_Check(ob)) { - return idp_from_PyBytes(name, ob); - } - else if (PySequence_Check(ob)) { - return idp_from_PySequence(name, ob); - } - else if (ob == Py_None || pyrna_id_CheckPyObject(ob)) { - return idp_from_DatablockPointer(name, ob); - } - else if (PyMapping_Check(ob)) { - return idp_from_PyMapping(name, ob); - } - else { - PyErr_Format(PyExc_TypeError, - "invalid id-property type %.200s not supported", - Py_TYPE(ob)->tp_name); - return NULL; - } + const char *name = idp_try_read_name(name_obj); + if (name == NULL) { + return NULL; + } + + if (PyFloat_Check(ob)) { + return idp_from_PyFloat(name, ob); + } + else if (PyLong_Check(ob)) { + return idp_from_PyLong(name, ob); + } + else if (PyUnicode_Check(ob)) { + return idp_from_PyUnicode(name, ob); + } + else if (PyBytes_Check(ob)) { + return idp_from_PyBytes(name, ob); + } + else if (PySequence_Check(ob)) { + return idp_from_PySequence(name, ob); + } + else if (ob == Py_None || pyrna_id_CheckPyObject(ob)) { + return idp_from_DatablockPointer(name, ob); + } + else if (PyMapping_Check(ob)) { + return idp_from_PyMapping(name, ob); + } + else { + PyErr_Format( + PyExc_TypeError, "invalid id-property type %.200s not supported", Py_TYPE(ob)->tp_name); + return NULL; + } } /* -------------------------------------------------------------------------- */ @@ -661,1101 +671,1081 @@ static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob) */ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group, PyObject *ob) { - IDProperty *prop = idp_from_PyObject(name_obj, ob); - if (prop == NULL) { - return false; - } - - if (group->type == IDP_IDPARRAY) { - IDP_AppendArray(group, prop); - /* IDP_AppendArray does a shallow copy (memcpy), only free memory */ - MEM_freeN(prop); - } - else { - IDProperty *prop_exist; - - /* avoid freeing when types match in case they are referenced by the UI, see: T37073 - * obviously this isn't a complete solution, but helps for common cases. */ - prop_exist = IDP_GetPropertyFromGroup(group, prop->name); - if ((prop_exist != NULL) && - (prop_exist->type == prop->type) && - (prop_exist->subtype == prop->subtype)) - { - /* Preserve prev/next links!!! See T42593. */ - prop->prev = prop_exist->prev; - prop->next = prop_exist->next; - - IDP_FreeProperty(prop_exist); - *prop_exist = *prop; - MEM_freeN(prop); - } - else { - IDP_ReplaceInGroup_ex(group, prop, prop_exist); - } - } - - return true; + IDProperty *prop = idp_from_PyObject(name_obj, ob); + if (prop == NULL) { + return false; + } + + if (group->type == IDP_IDPARRAY) { + IDP_AppendArray(group, prop); + /* IDP_AppendArray does a shallow copy (memcpy), only free memory */ + MEM_freeN(prop); + } + else { + IDProperty *prop_exist; + + /* avoid freeing when types match in case they are referenced by the UI, see: T37073 + * obviously this isn't a complete solution, but helps for common cases. */ + prop_exist = IDP_GetPropertyFromGroup(group, prop->name); + if ((prop_exist != NULL) && (prop_exist->type == prop->type) && + (prop_exist->subtype == prop->subtype)) { + /* Preserve prev/next links!!! See T42593. */ + prop->prev = prop_exist->prev; + prop->next = prop_exist->next; + + IDP_FreeProperty(prop_exist); + *prop_exist = *prop; + MEM_freeN(prop); + } + else { + IDP_ReplaceInGroup_ex(group, prop, prop_exist); + } + } + + return true; } int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val) { - if (prop->type != IDP_GROUP) { - PyErr_SetString(PyExc_TypeError, "unsubscriptable object"); - return -1; - } - - if (val == NULL) { /* del idprop[key] */ - IDProperty *pkey; - const char *name = _PyUnicode_AsString(key); - - if (name == NULL) { - PyErr_Format(PyExc_KeyError, - "expected a string, not %.200s", - Py_TYPE(key)->tp_name); - return -1; - } - - pkey = IDP_GetPropertyFromGroup(prop, name); - if (pkey) { - IDP_FreeFromGroup(prop, pkey); - return 0; - } - else { - PyErr_SetString(PyExc_KeyError, "property not found in group"); - return -1; - } - } - else { - bool ok; - - ok = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val); - if (ok == false) { - return -1; - } - - return 0; - } + if (prop->type != IDP_GROUP) { + PyErr_SetString(PyExc_TypeError, "unsubscriptable object"); + return -1; + } + + if (val == NULL) { /* del idprop[key] */ + IDProperty *pkey; + const char *name = _PyUnicode_AsString(key); + + if (name == NULL) { + PyErr_Format(PyExc_KeyError, "expected a string, not %.200s", Py_TYPE(key)->tp_name); + return -1; + } + + pkey = IDP_GetPropertyFromGroup(prop, name); + if (pkey) { + IDP_FreeFromGroup(prop, pkey); + return 0; + } + else { + PyErr_SetString(PyExc_KeyError, "property not found in group"); + return -1; + } + } + else { + bool ok; + + ok = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val); + if (ok == false) { + return -1; + } + + return 0; + } } static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val) { - return BPy_Wrap_SetMapItem(self->prop, key, val); + return BPy_Wrap_SetMapItem(self->prop, key, val); } static PyObject *BPy_IDGroup_iter(BPy_IDProperty *self) { - BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &BPy_IDGroup_Iter_Type); - iter->group = self; - iter->mode = IDPROP_ITER_KEYS; - iter->cur = self->prop->data.group.first; - Py_XINCREF(iter); - return (PyObject *)iter; + BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &BPy_IDGroup_Iter_Type); + iter->group = self; + iter->mode = IDPROP_ITER_KEYS; + iter->cur = self->prop->data.group.first; + Py_XINCREF(iter); + return (PyObject *)iter; } /* for simple, non nested types this is the same as BPy_IDGroup_WrapData */ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop) { - switch (prop->type) { - case IDP_STRING: - return idprop_py_from_idp_string(prop); - case IDP_INT: - return idprop_py_from_idp_int(prop); - case IDP_FLOAT: - return idprop_py_from_idp_float(prop); - case IDP_DOUBLE: - return idprop_py_from_idp_double(prop); - case IDP_ID: - return idprop_py_from_idp_id(prop); - case IDP_ARRAY: - { - PyObject *seq = PyList_New(prop->len); - int i; - - if (!seq) { - PyErr_Format(PyExc_RuntimeError, - "%s: IDP_ARRAY: PyList_New(%d) failed", - __func__, prop->len); - return NULL; - } - - switch (prop->subtype) { - case IDP_FLOAT: - { - const float *array = (float *)IDP_Array(prop); - for (i = 0; i < prop->len; i++) { - PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i])); - } - break; - } - case IDP_DOUBLE: - { - const double *array = (double *)IDP_Array(prop); - for (i = 0; i < prop->len; i++) { - PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i])); - } - break; - } - case IDP_INT: - { - const int *array = (int *)IDP_Array(prop); - for (i = 0; i < prop->len; i++) { - PyList_SET_ITEM(seq, i, PyLong_FromLong(array[i])); - } - break; - } - default: - PyErr_Format(PyExc_RuntimeError, - "%s: invalid/corrupt array type '%d'!", - __func__, prop->subtype); - Py_DECREF(seq); - return NULL; - } - - return seq; - } - case IDP_IDPARRAY: - { - PyObject *seq = PyList_New(prop->len); - IDProperty *array = IDP_IDPArray(prop); - int i; - - if (!seq) { - PyErr_Format(PyExc_RuntimeError, - "%s: IDP_IDPARRAY: PyList_New(%d) failed", - __func__, prop->len); - return NULL; - } - - for (i = 0; i < prop->len; i++) { - PyObject *wrap = BPy_IDGroup_MapDataToPy(array++); - - /* BPy_IDGroup_MapDataToPy sets the error */ - if (UNLIKELY(wrap == NULL)) { - Py_DECREF(seq); - return NULL; - } - - PyList_SET_ITEM(seq, i, wrap); - } - return seq; - } - case IDP_GROUP: - { - PyObject *dict = _PyDict_NewPresized(prop->len); - IDProperty *loop; - - for (loop = prop->data.group.first; loop; loop = loop->next) { - PyObject *wrap = BPy_IDGroup_MapDataToPy(loop); - - /* BPy_IDGroup_MapDataToPy sets the error */ - if (UNLIKELY(wrap == NULL)) { - Py_DECREF(dict); - return NULL; - } - - PyDict_SetItemString(dict, loop->name, wrap); - Py_DECREF(wrap); - } - return dict; - } - } - - PyErr_Format(PyExc_RuntimeError, - "%s ERROR: '%s' property exists with a bad type code '%d'!", - __func__, prop->name, prop->type); - return NULL; -} - -PyDoc_STRVAR(BPy_IDGroup_pop_doc, -".. method:: pop(key, default)\n" -"\n" -" Remove an item from the group, returning a Python representation.\n" -"\n" -" :raises KeyError: When the item doesn't exist.\n" -"\n" -" :arg key: Name of item to remove.\n" -" :type key: string\n" -" :arg default: Value to return when key isn't found, otherwise raise an exception.\n" -" :type default: Undefined\n" -); + switch (prop->type) { + case IDP_STRING: + return idprop_py_from_idp_string(prop); + case IDP_INT: + return idprop_py_from_idp_int(prop); + case IDP_FLOAT: + return idprop_py_from_idp_float(prop); + case IDP_DOUBLE: + return idprop_py_from_idp_double(prop); + case IDP_ID: + return idprop_py_from_idp_id(prop); + case IDP_ARRAY: { + PyObject *seq = PyList_New(prop->len); + int i; + + if (!seq) { + PyErr_Format( + PyExc_RuntimeError, "%s: IDP_ARRAY: PyList_New(%d) failed", __func__, prop->len); + return NULL; + } + + switch (prop->subtype) { + case IDP_FLOAT: { + const float *array = (float *)IDP_Array(prop); + for (i = 0; i < prop->len; i++) { + PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i])); + } + break; + } + case IDP_DOUBLE: { + const double *array = (double *)IDP_Array(prop); + for (i = 0; i < prop->len; i++) { + PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i])); + } + break; + } + case IDP_INT: { + const int *array = (int *)IDP_Array(prop); + for (i = 0; i < prop->len; i++) { + PyList_SET_ITEM(seq, i, PyLong_FromLong(array[i])); + } + break; + } + default: + PyErr_Format( + PyExc_RuntimeError, "%s: invalid/corrupt array type '%d'!", __func__, prop->subtype); + Py_DECREF(seq); + return NULL; + } + + return seq; + } + case IDP_IDPARRAY: { + PyObject *seq = PyList_New(prop->len); + IDProperty *array = IDP_IDPArray(prop); + int i; + + if (!seq) { + PyErr_Format( + PyExc_RuntimeError, "%s: IDP_IDPARRAY: PyList_New(%d) failed", __func__, prop->len); + return NULL; + } + + for (i = 0; i < prop->len; i++) { + PyObject *wrap = BPy_IDGroup_MapDataToPy(array++); + + /* BPy_IDGroup_MapDataToPy sets the error */ + if (UNLIKELY(wrap == NULL)) { + Py_DECREF(seq); + return NULL; + } + + PyList_SET_ITEM(seq, i, wrap); + } + return seq; + } + case IDP_GROUP: { + PyObject *dict = _PyDict_NewPresized(prop->len); + IDProperty *loop; + + for (loop = prop->data.group.first; loop; loop = loop->next) { + PyObject *wrap = BPy_IDGroup_MapDataToPy(loop); + + /* BPy_IDGroup_MapDataToPy sets the error */ + if (UNLIKELY(wrap == NULL)) { + Py_DECREF(dict); + return NULL; + } + + PyDict_SetItemString(dict, loop->name, wrap); + Py_DECREF(wrap); + } + return dict; + } + } + + PyErr_Format(PyExc_RuntimeError, + "%s ERROR: '%s' property exists with a bad type code '%d'!", + __func__, + prop->name, + prop->type); + return NULL; +} + +PyDoc_STRVAR( + BPy_IDGroup_pop_doc, + ".. method:: pop(key, default)\n" + "\n" + " Remove an item from the group, returning a Python representation.\n" + "\n" + " :raises KeyError: When the item doesn't exist.\n" + "\n" + " :arg key: Name of item to remove.\n" + " :type key: string\n" + " :arg default: Value to return when key isn't found, otherwise raise an exception.\n" + " :type default: Undefined\n"); static PyObject *BPy_IDGroup_pop(BPy_IDProperty *self, PyObject *args) { - IDProperty *idprop; - PyObject *pyform; - - char *key; - PyObject *def = NULL; - - if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { - return NULL; - } - - idprop = IDP_GetPropertyFromGroup(self->prop, key); - if (idprop == NULL) { - if (def == NULL) { - PyErr_SetString(PyExc_KeyError, "item not in group"); - return NULL; - } - return Py_INCREF_RET(def); - } - - pyform = BPy_IDGroup_MapDataToPy(idprop); - if (pyform == NULL) { - /* ok something bad happened with the pyobject, - * so don't remove the prop from the group. if pyform is - * NULL, then it already should have raised an exception.*/ - return NULL; - } - - IDP_RemoveFromGroup(self->prop, idprop); - return pyform; -} - -PyDoc_STRVAR(BPy_IDGroup_iter_items_doc, -".. method:: iteritems()\n" -"\n" -" Iterate through the items in the dict; behaves like dictionary method iteritems.\n" -); + IDProperty *idprop; + PyObject *pyform; + + char *key; + PyObject *def = NULL; + + if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { + return NULL; + } + + idprop = IDP_GetPropertyFromGroup(self->prop, key); + if (idprop == NULL) { + if (def == NULL) { + PyErr_SetString(PyExc_KeyError, "item not in group"); + return NULL; + } + return Py_INCREF_RET(def); + } + + pyform = BPy_IDGroup_MapDataToPy(idprop); + if (pyform == NULL) { + /* ok something bad happened with the pyobject, + * so don't remove the prop from the group. if pyform is + * NULL, then it already should have raised an exception.*/ + return NULL; + } + + IDP_RemoveFromGroup(self->prop, idprop); + return pyform; +} + +PyDoc_STRVAR( + BPy_IDGroup_iter_items_doc, + ".. method:: iteritems()\n" + "\n" + " Iterate through the items in the dict; behaves like dictionary method iteritems.\n"); static PyObject *BPy_IDGroup_iter_items(BPy_IDProperty *self) { - BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &BPy_IDGroup_Iter_Type); - iter->group = self; - iter->mode = IDPROP_ITER_ITEMS; - iter->cur = self->prop->data.group.first; - Py_XINCREF(iter); - return (PyObject *)iter; + BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &BPy_IDGroup_Iter_Type); + iter->group = self; + iter->mode = IDPROP_ITER_ITEMS; + iter->cur = self->prop->data.group.first; + Py_XINCREF(iter); + return (PyObject *)iter; } /* utility function */ static void BPy_IDGroup_CorrectListLen(IDProperty *prop, PyObject *seq, int len, const char *func) { - int j; + int j; - printf("%s: ID Property Error found and corrected!\n", func); + printf("%s: ID Property Error found and corrected!\n", func); - /* fill rest of list with valid references to None */ - for (j = len; j < prop->len; j++) { - PyList_SET_ITEM(seq, j, Py_INCREF_RET(Py_None)); - } + /* fill rest of list with valid references to None */ + for (j = len; j < prop->len; j++) { + PyList_SET_ITEM(seq, j, Py_INCREF_RET(Py_None)); + } - /*set correct group length*/ - prop->len = len; + /*set correct group length*/ + prop->len = len; } PyObject *BPy_Wrap_GetKeys(IDProperty *prop) { - PyObject *list = PyList_New(prop->len); - IDProperty *loop; - int i; + PyObject *list = PyList_New(prop->len); + IDProperty *loop; + int i; - for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++) { - PyList_SET_ITEM(list, i, PyUnicode_FromString(loop->name)); - } + for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++) { + PyList_SET_ITEM(list, i, PyUnicode_FromString(loop->name)); + } - /* if the id prop is corrupt, count the remaining */ - for ( ; loop; loop = loop->next, i++) { - /* pass */ - } + /* if the id prop is corrupt, count the remaining */ + for (; loop; loop = loop->next, i++) { + /* pass */ + } - if (i != prop->len) { /* if the loop didn't finish, we know the length is wrong */ - BPy_IDGroup_CorrectListLen(prop, list, i, __func__); - Py_DECREF(list); /*free the list*/ - /*call self again*/ - return BPy_Wrap_GetKeys(prop); - } + if (i != prop->len) { /* if the loop didn't finish, we know the length is wrong */ + BPy_IDGroup_CorrectListLen(prop, list, i, __func__); + Py_DECREF(list); /*free the list*/ + /*call self again*/ + return BPy_Wrap_GetKeys(prop); + } - return list; + return list; } PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop) { - PyObject *list = PyList_New(prop->len); - IDProperty *loop; - int i; + PyObject *list = PyList_New(prop->len); + IDProperty *loop; + int i; - for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) { - PyList_SET_ITEM(list, i, BPy_IDGroup_WrapData(id, loop, prop)); - } + for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) { + PyList_SET_ITEM(list, i, BPy_IDGroup_WrapData(id, loop, prop)); + } - if (i != prop->len) { - BPy_IDGroup_CorrectListLen(prop, list, i, __func__); - Py_DECREF(list); /*free the list*/ - /*call self again*/ - return BPy_Wrap_GetValues(id, prop); - } + if (i != prop->len) { + BPy_IDGroup_CorrectListLen(prop, list, i, __func__); + Py_DECREF(list); /*free the list*/ + /*call self again*/ + return BPy_Wrap_GetValues(id, prop); + } - return list; + return list; } PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop) { - PyObject *seq = PyList_New(prop->len); - IDProperty *loop; - int i; + PyObject *seq = PyList_New(prop->len); + IDProperty *loop; + int i; - for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) { - PyObject *item = PyTuple_New(2); - PyTuple_SET_ITEMS(item, - PyUnicode_FromString(loop->name), - BPy_IDGroup_WrapData(id, loop, prop)); - PyList_SET_ITEM(seq, i, item); - } + for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) { + PyObject *item = PyTuple_New(2); + PyTuple_SET_ITEMS( + item, PyUnicode_FromString(loop->name), BPy_IDGroup_WrapData(id, loop, prop)); + PyList_SET_ITEM(seq, i, item); + } - if (i != prop->len) { - BPy_IDGroup_CorrectListLen(prop, seq, i, __func__); - Py_DECREF(seq); /*free the list*/ - /*call self again*/ - return BPy_Wrap_GetItems(id, prop); - } + if (i != prop->len) { + BPy_IDGroup_CorrectListLen(prop, seq, i, __func__); + Py_DECREF(seq); /*free the list*/ + /*call self again*/ + return BPy_Wrap_GetItems(id, prop); + } - return seq; + return seq; } PyDoc_STRVAR(BPy_IDGroup_keys_doc, -".. method:: keys()\n" -"\n" -" Return the keys associated with this group as a list of strings.\n" -); + ".. method:: keys()\n" + "\n" + " Return the keys associated with this group as a list of strings.\n"); static PyObject *BPy_IDGroup_keys(BPy_IDProperty *self) { - return BPy_Wrap_GetKeys(self->prop); + return BPy_Wrap_GetKeys(self->prop); } PyDoc_STRVAR(BPy_IDGroup_values_doc, -".. method:: values()\n" -"\n" -" Return the values associated with this group.\n" -); + ".. method:: values()\n" + "\n" + " Return the values associated with this group.\n"); static PyObject *BPy_IDGroup_values(BPy_IDProperty *self) { - return BPy_Wrap_GetValues(self->id, self->prop); + return BPy_Wrap_GetValues(self->id, self->prop); } PyDoc_STRVAR(BPy_IDGroup_items_doc, -".. method:: items()\n" -"\n" -" Return the items associated with this group.\n" -); + ".. method:: items()\n" + "\n" + " Return the items associated with this group.\n"); static PyObject *BPy_IDGroup_items(BPy_IDProperty *self) { - return BPy_Wrap_GetItems(self->id, self->prop); + return BPy_Wrap_GetItems(self->id, self->prop); } static int BPy_IDGroup_Contains(BPy_IDProperty *self, PyObject *value) { - const char *name = _PyUnicode_AsString(value); + const char *name = _PyUnicode_AsString(value); - if (!name) { - PyErr_Format(PyExc_TypeError, - "expected a string, not a %.200s", - Py_TYPE(value)->tp_name); - return -1; - } + if (!name) { + PyErr_Format(PyExc_TypeError, "expected a string, not a %.200s", Py_TYPE(value)->tp_name); + return -1; + } - return IDP_GetPropertyFromGroup(self->prop, name) ? 1 : 0; + return IDP_GetPropertyFromGroup(self->prop, name) ? 1 : 0; } PyDoc_STRVAR(BPy_IDGroup_update_doc, -".. method:: update(other)\n" -"\n" -" Update key, values.\n" -"\n" -" :arg other: Updates the values in the group with this.\n" -" :type other: :class:`IDPropertyGroup` or dict\n" -); + ".. method:: update(other)\n" + "\n" + " Update key, values.\n" + "\n" + " :arg other: Updates the values in the group with this.\n" + " :type other: :class:`IDPropertyGroup` or dict\n"); static PyObject *BPy_IDGroup_update(BPy_IDProperty *self, PyObject *value) { - PyObject *pkey, *pval; - Py_ssize_t i = 0; - - if (BPy_IDGroup_Check(value)) { - BPy_IDProperty *other = (BPy_IDProperty *)value; - if (UNLIKELY(self->prop == other->prop)) { - Py_RETURN_NONE; - } - - /* XXX, possible one is inside the other */ - IDP_MergeGroup(self->prop, other->prop, true); - } - else if (PyDict_Check(value)) { - while (PyDict_Next(value, &i, &pkey, &pval)) { - BPy_IDGroup_Map_SetItem(self, pkey, pval); - if (PyErr_Occurred()) { - return NULL; - } - } - } - else { - PyErr_Format(PyExc_TypeError, - "expected a dict or an IDPropertyGroup type, not a %.200s", - Py_TYPE(value)->tp_name); - return NULL; - } - - - Py_RETURN_NONE; + PyObject *pkey, *pval; + Py_ssize_t i = 0; + + if (BPy_IDGroup_Check(value)) { + BPy_IDProperty *other = (BPy_IDProperty *)value; + if (UNLIKELY(self->prop == other->prop)) { + Py_RETURN_NONE; + } + + /* XXX, possible one is inside the other */ + IDP_MergeGroup(self->prop, other->prop, true); + } + else if (PyDict_Check(value)) { + while (PyDict_Next(value, &i, &pkey, &pval)) { + BPy_IDGroup_Map_SetItem(self, pkey, pval); + if (PyErr_Occurred()) { + return NULL; + } + } + } + else { + PyErr_Format(PyExc_TypeError, + "expected a dict or an IDPropertyGroup type, not a %.200s", + Py_TYPE(value)->tp_name); + return NULL; + } + + Py_RETURN_NONE; } PyDoc_STRVAR(BPy_IDGroup_to_dict_doc, -".. method:: to_dict()\n" -"\n" -" Return a purely python version of the group.\n" -); + ".. method:: to_dict()\n" + "\n" + " Return a purely python version of the group.\n"); static PyObject *BPy_IDGroup_to_dict(BPy_IDProperty *self) { - return BPy_IDGroup_MapDataToPy(self->prop); + return BPy_IDGroup_MapDataToPy(self->prop); } PyDoc_STRVAR(BPy_IDGroup_clear_doc, -".. method:: clear()\n" -"\n" -" Clear all members from this group.\n" -); + ".. method:: clear()\n" + "\n" + " Clear all members from this group.\n"); static PyObject *BPy_IDGroup_clear(BPy_IDProperty *self) { - IDP_ClearProperty(self->prop); - Py_RETURN_NONE; + IDP_ClearProperty(self->prop); + Py_RETURN_NONE; } PyDoc_STRVAR(BPy_IDGroup_get_doc, -".. method:: get(key, default=None)\n" -"\n" -" Return the value for key, if it exists, else default.\n" -); + ".. method:: get(key, default=None)\n" + "\n" + " Return the value for key, if it exists, else default.\n"); static PyObject *BPy_IDGroup_get(BPy_IDProperty *self, PyObject *args) { - IDProperty *idprop; - const char *key; - PyObject *def = Py_None; + IDProperty *idprop; + const char *key; + PyObject *def = Py_None; - if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { + return NULL; + } - idprop = IDP_GetPropertyFromGroup(self->prop, key); - if (idprop) { - PyObject *pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop); - if (pyobj) { - return pyobj; - } - } + idprop = IDP_GetPropertyFromGroup(self->prop, key); + if (idprop) { + PyObject *pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop); + if (pyobj) { + return pyobj; + } + } - Py_INCREF(def); - return def; + Py_INCREF(def); + return def; } static struct PyMethodDef BPy_IDGroup_methods[] = { - {"pop", (PyCFunction)BPy_IDGroup_pop, METH_VARARGS, BPy_IDGroup_pop_doc}, - {"iteritems", (PyCFunction)BPy_IDGroup_iter_items, METH_NOARGS, BPy_IDGroup_iter_items_doc}, - {"keys", (PyCFunction)BPy_IDGroup_keys, METH_NOARGS, BPy_IDGroup_keys_doc}, - {"values", (PyCFunction)BPy_IDGroup_values, METH_NOARGS, BPy_IDGroup_values_doc}, - {"items", (PyCFunction)BPy_IDGroup_items, METH_NOARGS, BPy_IDGroup_items_doc}, - {"update", (PyCFunction)BPy_IDGroup_update, METH_O, BPy_IDGroup_update_doc}, - {"get", (PyCFunction)BPy_IDGroup_get, METH_VARARGS, BPy_IDGroup_get_doc}, - {"to_dict", (PyCFunction)BPy_IDGroup_to_dict, METH_NOARGS, BPy_IDGroup_to_dict_doc}, - {"clear", (PyCFunction)BPy_IDGroup_clear, METH_NOARGS, BPy_IDGroup_clear_doc}, - {NULL, NULL, 0, NULL}, + {"pop", (PyCFunction)BPy_IDGroup_pop, METH_VARARGS, BPy_IDGroup_pop_doc}, + {"iteritems", (PyCFunction)BPy_IDGroup_iter_items, METH_NOARGS, BPy_IDGroup_iter_items_doc}, + {"keys", (PyCFunction)BPy_IDGroup_keys, METH_NOARGS, BPy_IDGroup_keys_doc}, + {"values", (PyCFunction)BPy_IDGroup_values, METH_NOARGS, BPy_IDGroup_values_doc}, + {"items", (PyCFunction)BPy_IDGroup_items, METH_NOARGS, BPy_IDGroup_items_doc}, + {"update", (PyCFunction)BPy_IDGroup_update, METH_O, BPy_IDGroup_update_doc}, + {"get", (PyCFunction)BPy_IDGroup_get, METH_VARARGS, BPy_IDGroup_get_doc}, + {"to_dict", (PyCFunction)BPy_IDGroup_to_dict, METH_NOARGS, BPy_IDGroup_to_dict_doc}, + {"clear", (PyCFunction)BPy_IDGroup_clear, METH_NOARGS, BPy_IDGroup_clear_doc}, + {NULL, NULL, 0, NULL}, }; static PySequenceMethods BPy_IDGroup_Seq = { - (lenfunc) BPy_IDGroup_Map_Len, /* lenfunc sq_length */ - NULL, /* binaryfunc sq_concat */ - NULL, /* ssizeargfunc sq_repeat */ - NULL, /* ssizeargfunc sq_item */ /* TODO - setting this will allow PySequence_Check to return True */ - NULL, /* intintargfunc ***was_sq_slice*** */ - NULL, /* intobjargproc sq_ass_item */ - NULL, /* ssizeobjargproc ***was_sq_ass_slice*** */ - (objobjproc) BPy_IDGroup_Contains, /* objobjproc sq_contains */ - NULL, /* binaryfunc sq_inplace_concat */ - NULL, /* ssizeargfunc sq_inplace_repeat */ + (lenfunc)BPy_IDGroup_Map_Len, /* lenfunc sq_length */ + NULL, /* binaryfunc sq_concat */ + NULL, /* ssizeargfunc sq_repeat */ + NULL, + /* ssizeargfunc sq_item */ /* TODO - setting this will allow PySequence_Check to return True */ + NULL, /* intintargfunc ***was_sq_slice*** */ + NULL, /* intobjargproc sq_ass_item */ + NULL, /* ssizeobjargproc ***was_sq_ass_slice*** */ + (objobjproc)BPy_IDGroup_Contains, /* objobjproc sq_contains */ + NULL, /* binaryfunc sq_inplace_concat */ + NULL, /* ssizeargfunc sq_inplace_repeat */ }; static PyMappingMethods BPy_IDGroup_Mapping = { - (lenfunc)BPy_IDGroup_Map_Len, /*inquiry mp_length */ - (binaryfunc)BPy_IDGroup_Map_GetItem, /*binaryfunc mp_subscript */ - (objobjargproc)BPy_IDGroup_Map_SetItem, /*objobjargproc mp_ass_subscript */ + (lenfunc)BPy_IDGroup_Map_Len, /*inquiry mp_length */ + (binaryfunc)BPy_IDGroup_Map_GetItem, /*binaryfunc mp_subscript */ + (objobjargproc)BPy_IDGroup_Map_SetItem, /*objobjargproc mp_ass_subscript */ }; PyTypeObject BPy_IDGroup_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - /* For printing, in format "<module>.<name>" */ - "IDPropertyGroup", /* char *tp_name; */ - sizeof(BPy_IDProperty), /* int tp_basicsize; */ - 0, /* tp_itemsize; For allocation */ - - /* Methods to implement standard operations */ - - NULL, /* destructor tp_dealloc; */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* cmpfunc tp_compare; */ - (reprfunc)BPy_IDGroup_repr, /* reprfunc tp_repr; */ - - /* Method suites for standard classes */ - - NULL, /* PyNumberMethods *tp_as_number; */ - &BPy_IDGroup_Seq, /* PySequenceMethods *tp_as_sequence; */ - &BPy_IDGroup_Mapping, /* PyMappingMethods *tp_as_mapping; */ - - /* More standard operations (here for binary compatibility) */ - - (hashfunc)BPy_IDGroup_hash, /* hashfunc tp_hash; */ - NULL, /* ternaryfunc tp_call; */ - NULL, /* reprfunc tp_str; */ - NULL, /* getattrofunc tp_getattro; */ - NULL, /* setattrofunc tp_setattro; */ - - /* Functions to access object as input/output buffer */ - NULL, /* PyBufferProcs *tp_as_buffer; */ - - /*** Flags to define presence of optional/expanded features ***/ - Py_TPFLAGS_DEFAULT, /* long tp_flags; */ - - NULL, /* char *tp_doc; Documentation string */ - /*** Assigned meaning in release 2.0 ***/ - /* call function for all accessible objects */ - NULL, /* traverseproc tp_traverse; */ - - /* delete references to contained objects */ - NULL, /* inquiry tp_clear; */ - - /*** Assigned meaning in release 2.1 ***/ - /*** rich comparisons ***/ - NULL, /* richcmpfunc tp_richcompare; */ - - /*** weak reference enabler ***/ - 0, /* long tp_weaklistoffset; */ - - /*** Added in release 2.2 ***/ - /* Iterators */ - (getiterfunc)BPy_IDGroup_iter, /* getiterfunc tp_iter; */ - NULL, /* iternextfunc tp_iternext; */ - /*** Attribute descriptor and subclassing stuff ***/ - BPy_IDGroup_methods, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - BPy_IDGroup_getseters, /* struct PyGetSetDef *tp_getset; */ + PyVarObject_HEAD_INIT(NULL, 0) + /* For printing, in format "<module>.<name>" */ + "IDPropertyGroup", /* char *tp_name; */ + sizeof(BPy_IDProperty), /* int tp_basicsize; */ + 0, /* tp_itemsize; For allocation */ + + /* Methods to implement standard operations */ + + NULL, /* destructor tp_dealloc; */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* cmpfunc tp_compare; */ + (reprfunc)BPy_IDGroup_repr, /* reprfunc tp_repr; */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + &BPy_IDGroup_Seq, /* PySequenceMethods *tp_as_sequence; */ + &BPy_IDGroup_Mapping, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + (hashfunc)BPy_IDGroup_hash, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + (getiterfunc)BPy_IDGroup_iter, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + /*** Attribute descriptor and subclassing stuff ***/ + BPy_IDGroup_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + BPy_IDGroup_getseters, /* struct PyGetSetDef *tp_getset; */ }; /********Array Wrapper********/ static PyTypeObject *idp_array_py_type(BPy_IDArray *self, bool *r_is_double) { - switch (self->prop->subtype) { - case IDP_FLOAT: - *r_is_double = false; - return &PyFloat_Type; - case IDP_DOUBLE: - *r_is_double = true; - return &PyFloat_Type; - case IDP_INT: - *r_is_double = false; - return &PyLong_Type; - default: - *r_is_double = false; - return NULL; - } + switch (self->prop->subtype) { + case IDP_FLOAT: + *r_is_double = false; + return &PyFloat_Type; + case IDP_DOUBLE: + *r_is_double = true; + return &PyFloat_Type; + case IDP_INT: + *r_is_double = false; + return &PyLong_Type; + default: + *r_is_double = false; + return NULL; + } } static PyObject *BPy_IDArray_repr(BPy_IDArray *self) { - return PyUnicode_FromFormat("<bpy id property array [%d]>", self->prop->len); + return PyUnicode_FromFormat("<bpy id property array [%d]>", self->prop->len); } PyDoc_STRVAR(BPy_IDArray_get_typecode_doc, -"The type of the data in the array {'f': float, 'd': double, 'i': int}." -); + "The type of the data in the array {'f': float, 'd': double, 'i': int}."); static PyObject *BPy_IDArray_get_typecode(BPy_IDArray *self) { - switch (self->prop->subtype) { - case IDP_FLOAT: return PyUnicode_FromString("f"); - case IDP_DOUBLE: return PyUnicode_FromString("d"); - case IDP_INT: return PyUnicode_FromString("i"); - } + switch (self->prop->subtype) { + case IDP_FLOAT: + return PyUnicode_FromString("f"); + case IDP_DOUBLE: + return PyUnicode_FromString("d"); + case IDP_INT: + return PyUnicode_FromString("i"); + } - PyErr_Format(PyExc_RuntimeError, - "%s: invalid/corrupt array type '%d'!", - __func__, self->prop->subtype); + PyErr_Format( + PyExc_RuntimeError, "%s: invalid/corrupt array type '%d'!", __func__, self->prop->subtype); - return NULL; + return NULL; } static PyGetSetDef BPy_IDArray_getseters[] = { - /* matches pythons array.typecode */ - {(char *)"typecode", (getter)BPy_IDArray_get_typecode, (setter)NULL, BPy_IDArray_get_typecode_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL}, + /* matches pythons array.typecode */ + {(char *)"typecode", + (getter)BPy_IDArray_get_typecode, + (setter)NULL, + BPy_IDArray_get_typecode_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL}, }; PyDoc_STRVAR(BPy_IDArray_to_list_doc, -".. method:: to_list()\n" -"\n" -" Return the array as a list.\n" -); + ".. method:: to_list()\n" + "\n" + " Return the array as a list.\n"); static PyObject *BPy_IDArray_to_list(BPy_IDArray *self) { - return BPy_IDGroup_MapDataToPy(self->prop); + return BPy_IDGroup_MapDataToPy(self->prop); } static PyMethodDef BPy_IDArray_methods[] = { - {"to_list", (PyCFunction)BPy_IDArray_to_list, METH_NOARGS, BPy_IDArray_to_list_doc}, - {NULL, NULL, 0, NULL}, + {"to_list", (PyCFunction)BPy_IDArray_to_list, METH_NOARGS, BPy_IDArray_to_list_doc}, + {NULL, NULL, 0, NULL}, }; static int BPy_IDArray_Len(BPy_IDArray *self) { - return self->prop->len; + return self->prop->len; } static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index) { - if (index < 0 || index >= self->prop->len) { - PyErr_SetString(PyExc_IndexError, "index out of range!"); - return NULL; - } + if (index < 0 || index >= self->prop->len) { + PyErr_SetString(PyExc_IndexError, "index out of range!"); + return NULL; + } - switch (self->prop->subtype) { - case IDP_FLOAT: - return PyFloat_FromDouble(((float *)IDP_Array(self->prop))[index]); - case IDP_DOUBLE: - return PyFloat_FromDouble(((double *)IDP_Array(self->prop))[index]); - case IDP_INT: - return PyLong_FromLong((long)((int *)IDP_Array(self->prop))[index]); - } + switch (self->prop->subtype) { + case IDP_FLOAT: + return PyFloat_FromDouble(((float *)IDP_Array(self->prop))[index]); + case IDP_DOUBLE: + return PyFloat_FromDouble(((double *)IDP_Array(self->prop))[index]); + case IDP_INT: + return PyLong_FromLong((long)((int *)IDP_Array(self->prop))[index]); + } - PyErr_Format(PyExc_RuntimeError, - "%s: invalid/corrupt array type '%d'!", - __func__, self->prop->subtype); + PyErr_Format( + PyExc_RuntimeError, "%s: invalid/corrupt array type '%d'!", __func__, self->prop->subtype); - return NULL; + return NULL; } static int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *value) { - if (index < 0 || index >= self->prop->len) { - PyErr_SetString(PyExc_RuntimeError, "index out of range!"); - return -1; - } - - switch (self->prop->subtype) { - case IDP_FLOAT: - { - const float f = (float)PyFloat_AsDouble(value); - if (f == -1 && PyErr_Occurred()) { - return -1; - } - ((float *)IDP_Array(self->prop))[index] = f; - break; - } - case IDP_DOUBLE: - { - const double d = PyFloat_AsDouble(value); - if (d == -1 && PyErr_Occurred()) { - return -1; - } - ((double *)IDP_Array(self->prop))[index] = d; - break; - } - case IDP_INT: - { - const int i = PyC_Long_AsI32(value); - if (i == -1 && PyErr_Occurred()) { - return -1; - } - - ((int *)IDP_Array(self->prop))[index] = i; - break; - } - } - return 0; + if (index < 0 || index >= self->prop->len) { + PyErr_SetString(PyExc_RuntimeError, "index out of range!"); + return -1; + } + + switch (self->prop->subtype) { + case IDP_FLOAT: { + const float f = (float)PyFloat_AsDouble(value); + if (f == -1 && PyErr_Occurred()) { + return -1; + } + ((float *)IDP_Array(self->prop))[index] = f; + break; + } + case IDP_DOUBLE: { + const double d = PyFloat_AsDouble(value); + if (d == -1 && PyErr_Occurred()) { + return -1; + } + ((double *)IDP_Array(self->prop))[index] = d; + break; + } + case IDP_INT: { + const int i = PyC_Long_AsI32(value); + if (i == -1 && PyErr_Occurred()) { + return -1; + } + + ((int *)IDP_Array(self->prop))[index] = i; + break; + } + } + return 0; } static PySequenceMethods BPy_IDArray_Seq = { - (lenfunc) BPy_IDArray_Len, /* inquiry sq_length */ - NULL, /* binaryfunc sq_concat */ - NULL, /* intargfunc sq_repeat */ - (ssizeargfunc)BPy_IDArray_GetItem, /* intargfunc sq_item */ - NULL, /* intintargfunc sq_slice */ - (ssizeobjargproc)BPy_IDArray_SetItem, /* intobjargproc sq_ass_item */ - NULL, /* intintobjargproc sq_ass_slice */ - NULL, /* objobjproc sq_contains */ - /* Added in release 2.0 */ - NULL, /* binaryfunc sq_inplace_concat */ - NULL, /* intargfunc sq_inplace_repeat */ + (lenfunc)BPy_IDArray_Len, /* inquiry sq_length */ + NULL, /* binaryfunc sq_concat */ + NULL, /* intargfunc sq_repeat */ + (ssizeargfunc)BPy_IDArray_GetItem, /* intargfunc sq_item */ + NULL, /* intintargfunc sq_slice */ + (ssizeobjargproc)BPy_IDArray_SetItem, /* intobjargproc sq_ass_item */ + NULL, /* intintobjargproc sq_ass_slice */ + NULL, /* objobjproc sq_contains */ + /* Added in release 2.0 */ + NULL, /* binaryfunc sq_inplace_concat */ + NULL, /* intargfunc sq_inplace_repeat */ }; - - /* sequence slice (get): idparr[a:b] */ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end) { - IDProperty *prop = self->prop; - PyObject *tuple; - int count; - - CLAMP(begin, 0, prop->len); - if (end < 0) { - end = prop->len + end + 1; - } - CLAMP(end, 0, prop->len); - begin = MIN2(begin, end); - - tuple = PyTuple_New(end - begin); - - switch (prop->subtype) { - case IDP_FLOAT: - { - const float *array = (float *)IDP_Array(prop); - for (count = begin; count < end; count++) { - PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count])); - } - break; - } - case IDP_DOUBLE: - { - const double *array = (double *)IDP_Array(prop); - for (count = begin; count < end; count++) { - PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count])); - } - break; - } - case IDP_INT: - { - const int *array = (int *)IDP_Array(prop); - for (count = begin; count < end; count++) { - PyTuple_SET_ITEM(tuple, count - begin, PyLong_FromLong(array[count])); - } - break; - } - } - - return tuple; + IDProperty *prop = self->prop; + PyObject *tuple; + int count; + + CLAMP(begin, 0, prop->len); + if (end < 0) { + end = prop->len + end + 1; + } + CLAMP(end, 0, prop->len); + begin = MIN2(begin, end); + + tuple = PyTuple_New(end - begin); + + switch (prop->subtype) { + case IDP_FLOAT: { + const float *array = (float *)IDP_Array(prop); + for (count = begin; count < end; count++) { + PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count])); + } + break; + } + case IDP_DOUBLE: { + const double *array = (double *)IDP_Array(prop); + for (count = begin; count < end; count++) { + PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count])); + } + break; + } + case IDP_INT: { + const int *array = (int *)IDP_Array(prop); + for (count = begin; count < end; count++) { + PyTuple_SET_ITEM(tuple, count - begin, PyLong_FromLong(array[count])); + } + break; + } + } + + return tuple; } /* sequence slice (set): idparr[a:b] = value */ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject *seq) { - IDProperty *prop = self->prop; - bool is_double; - const PyTypeObject *py_type = idp_array_py_type(self, &is_double); - const size_t elem_size = is_double ? sizeof(double) : sizeof(float); - size_t alloc_len; - size_t size; - void *vec; + IDProperty *prop = self->prop; + bool is_double; + const PyTypeObject *py_type = idp_array_py_type(self, &is_double); + const size_t elem_size = is_double ? sizeof(double) : sizeof(float); + size_t alloc_len; + size_t size; + void *vec; - CLAMP(begin, 0, prop->len); - CLAMP(end, 0, prop->len); - begin = MIN2(begin, end); + CLAMP(begin, 0, prop->len); + CLAMP(end, 0, prop->len); + begin = MIN2(begin, end); - size = (end - begin); - alloc_len = size * elem_size; + size = (end - begin); + alloc_len = size * elem_size; - vec = MEM_mallocN(alloc_len, "array assignment"); /* NOTE: we count on int/float being the same size here */ - if (PyC_AsArray(vec, seq, size, py_type, is_double, "slice assignment: ") == -1) { - MEM_freeN(vec); - return -1; - } + vec = MEM_mallocN(alloc_len, + "array assignment"); /* NOTE: we count on int/float being the same size here */ + if (PyC_AsArray(vec, seq, size, py_type, is_double, "slice assignment: ") == -1) { + MEM_freeN(vec); + return -1; + } - memcpy((void *)(((char *)IDP_Array(prop)) + (begin * elem_size)), vec, alloc_len); + memcpy((void *)(((char *)IDP_Array(prop)) + (begin * elem_size)), vec, alloc_len); - MEM_freeN(vec); - return 0; + MEM_freeN(vec); + return 0; } static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item) { - if (PyIndex_Check(item)) { - Py_ssize_t i; - i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) { - return NULL; - } - if (i < 0) { - i += self->prop->len; - } - return BPy_IDArray_GetItem(self, i); - } - else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength; - - if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { - return NULL; - } - - if (slicelength <= 0) { - return PyTuple_New(0); - } - else if (step == 1) { - return BPy_IDArray_slice(self, start, stop); - } - else { - PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); - return NULL; - } - } - else { - PyErr_Format(PyExc_TypeError, - "vector indices must be integers, not %.200s", - __func__, Py_TYPE(item)->tp_name); - return NULL; - } + if (PyIndex_Check(item)) { + Py_ssize_t i; + i = PyNumber_AsSsize_t(item, PyExc_IndexError); + if (i == -1 && PyErr_Occurred()) { + return NULL; + } + if (i < 0) { + i += self->prop->len; + } + return BPy_IDArray_GetItem(self, i); + } + else if (PySlice_Check(item)) { + Py_ssize_t start, stop, step, slicelength; + + if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { + return NULL; + } + + if (slicelength <= 0) { + return PyTuple_New(0); + } + else if (step == 1) { + return BPy_IDArray_slice(self, start, stop); + } + else { + PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); + return NULL; + } + } + else { + PyErr_Format(PyExc_TypeError, + "vector indices must be integers, not %.200s", + __func__, + Py_TYPE(item)->tp_name); + return NULL; + } } static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject *value) { - if (PyIndex_Check(item)) { - Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) { - return -1; - } - if (i < 0) { - i += self->prop->len; - } - return BPy_IDArray_SetItem(self, i, value); - } - else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength; - - if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { - return -1; - } - - if (step == 1) { - return BPy_IDArray_ass_slice(self, start, stop, value); - } - else { - PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); - return -1; - } - } - else { - PyErr_Format(PyExc_TypeError, - "vector indices must be integers, not %.200s", - Py_TYPE(item)->tp_name); - return -1; - } + if (PyIndex_Check(item)) { + Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); + if (i == -1 && PyErr_Occurred()) { + return -1; + } + if (i < 0) { + i += self->prop->len; + } + return BPy_IDArray_SetItem(self, i, value); + } + else if (PySlice_Check(item)) { + Py_ssize_t start, stop, step, slicelength; + + if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { + return -1; + } + + if (step == 1) { + return BPy_IDArray_ass_slice(self, start, stop, value); + } + else { + PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); + return -1; + } + } + else { + PyErr_Format( + PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; + } } static PyMappingMethods BPy_IDArray_AsMapping = { - (lenfunc)BPy_IDArray_Len, - (binaryfunc)BPy_IDArray_subscript, - (objobjargproc)BPy_IDArray_ass_subscript, + (lenfunc)BPy_IDArray_Len, + (binaryfunc)BPy_IDArray_subscript, + (objobjargproc)BPy_IDArray_ass_subscript, }; static int itemsize_by_idarray_type(int array_type) { - if (array_type == IDP_INT) { return sizeof(int); } - if (array_type == IDP_FLOAT) { return sizeof(float); } - if (array_type == IDP_DOUBLE) { return sizeof(double); } - return -1; /* should never happen */ + if (array_type == IDP_INT) { + return sizeof(int); + } + if (array_type == IDP_FLOAT) { + return sizeof(float); + } + if (array_type == IDP_DOUBLE) { + return sizeof(double); + } + return -1; /* should never happen */ } static int BPy_IDArray_getbuffer(BPy_IDArray *self, Py_buffer *view, int flags) { - IDProperty *prop = self->prop; - int itemsize = itemsize_by_idarray_type(prop->subtype); - int length = itemsize * prop->len; + IDProperty *prop = self->prop; + int itemsize = itemsize_by_idarray_type(prop->subtype); + int length = itemsize * prop->len; - if (PyBuffer_FillInfo(view, (PyObject *)self, IDP_Array(prop), length, false, flags) == -1) { - return -1; - } + if (PyBuffer_FillInfo(view, (PyObject *)self, IDP_Array(prop), length, false, flags) == -1) { + return -1; + } - view->itemsize = itemsize; - view->format = (char *)idp_format_from_array_type(prop->subtype); + view->itemsize = itemsize; + view->format = (char *)idp_format_from_array_type(prop->subtype); - Py_ssize_t *shape = MEM_mallocN(sizeof(Py_ssize_t), __func__); - shape[0] = prop->len; - view->shape = shape; + Py_ssize_t *shape = MEM_mallocN(sizeof(Py_ssize_t), __func__); + shape[0] = prop->len; + view->shape = shape; - return 0; + return 0; } static void BPy_IDArray_releasebuffer(BPy_IDArray *UNUSED(self), Py_buffer *view) { - MEM_freeN(view->shape); + MEM_freeN(view->shape); } static PyBufferProcs BPy_IDArray_Buffer = { - (getbufferproc)BPy_IDArray_getbuffer, - (releasebufferproc)BPy_IDArray_releasebuffer, + (getbufferproc)BPy_IDArray_getbuffer, + (releasebufferproc)BPy_IDArray_releasebuffer, }; - PyTypeObject BPy_IDArray_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - /* For printing, in format "<module>.<name>" */ - "IDPropertyArray", /* char *tp_name; */ - sizeof(BPy_IDArray), /* int tp_basicsize; */ - 0, /* tp_itemsize; For allocation */ - - /* Methods to implement standard operations */ - - NULL, /* destructor tp_dealloc; */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* cmpfunc tp_compare; */ - (reprfunc)BPy_IDArray_repr, /* reprfunc tp_repr; */ - - /* Method suites for standard classes */ - - NULL, /* PyNumberMethods *tp_as_number; */ - &BPy_IDArray_Seq, /* PySequenceMethods *tp_as_sequence; */ - &BPy_IDArray_AsMapping, /* PyMappingMethods *tp_as_mapping; */ - - /* More standard operations (here for binary compatibility) */ - - NULL, /* hashfunc tp_hash; */ - NULL, /* ternaryfunc tp_call; */ - NULL, /* reprfunc tp_str; */ - NULL, /* getattrofunc tp_getattro; */ - NULL, /* setattrofunc tp_setattro; */ - - /* Functions to access object as input/output buffer */ - &BPy_IDArray_Buffer, /* PyBufferProcs *tp_as_buffer; */ - - /*** Flags to define presence of optional/expanded features ***/ - Py_TPFLAGS_DEFAULT, /* long tp_flags; */ - - NULL, /* char *tp_doc; Documentation string */ - /*** Assigned meaning in release 2.0 ***/ - /* call function for all accessible objects */ - NULL, /* traverseproc tp_traverse; */ - - /* delete references to contained objects */ - NULL, /* inquiry tp_clear; */ - - /*** Assigned meaning in release 2.1 ***/ - /*** rich comparisons ***/ - NULL, /* richcmpfunc tp_richcompare; */ - - /*** weak reference enabler ***/ - 0, /* long tp_weaklistoffset; */ - - /*** Added in release 2.2 ***/ - /* Iterators */ - NULL, /* getiterfunc tp_iter; */ - NULL, /* iternextfunc tp_iternext; */ - - /*** Attribute descriptor and subclassing stuff ***/ - BPy_IDArray_methods, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - BPy_IDArray_getseters, /* struct PyGetSetDef *tp_getset; */ - NULL, /* struct _typeobject *tp_base; */ - NULL, /* PyObject *tp_dict; */ - NULL, /* descrgetfunc tp_descr_get; */ - NULL, /* descrsetfunc tp_descr_set; */ - 0, /* long tp_dictoffset; */ - NULL, /* initproc tp_init; */ - NULL, /* allocfunc tp_alloc; */ - NULL, /* newfunc tp_new; */ - /* Low-level free-memory routine */ - NULL, /* freefunc tp_free; */ - /* For PyObject_IS_GC */ - NULL, /* inquiry tp_is_gc; */ - NULL, /* PyObject *tp_bases; */ - /* method resolution order */ - NULL, /* PyObject *tp_mro; */ - NULL, /* PyObject *tp_cache; */ - NULL, /* PyObject *tp_subclasses; */ - NULL, /* PyObject *tp_weaklist; */ - NULL, + PyVarObject_HEAD_INIT(NULL, 0) + /* For printing, in format "<module>.<name>" */ + "IDPropertyArray", /* char *tp_name; */ + sizeof(BPy_IDArray), /* int tp_basicsize; */ + 0, /* tp_itemsize; For allocation */ + + /* Methods to implement standard operations */ + + NULL, /* destructor tp_dealloc; */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* cmpfunc tp_compare; */ + (reprfunc)BPy_IDArray_repr, /* reprfunc tp_repr; */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + &BPy_IDArray_Seq, /* PySequenceMethods *tp_as_sequence; */ + &BPy_IDArray_AsMapping, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + NULL, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + &BPy_IDArray_Buffer, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + + /*** Attribute descriptor and subclassing stuff ***/ + BPy_IDArray_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + BPy_IDArray_getseters, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + NULL, /* newfunc tp_new; */ + /* Low-level free-memory routine */ + NULL, /* freefunc tp_free; */ + /* For PyObject_IS_GC */ + NULL, /* inquiry tp_is_gc; */ + NULL, /* PyObject *tp_bases; */ + /* method resolution order */ + NULL, /* PyObject *tp_mro; */ + NULL, /* PyObject *tp_cache; */ + NULL, /* PyObject *tp_subclasses; */ + NULL, /* PyObject *tp_weaklist; */ + NULL, }; /*********** ID Property Group iterator ********/ static PyObject *IDGroup_Iter_repr(BPy_IDGroup_Iter *self) { - return PyUnicode_FromFormat("(ID Property Group Iter \"%s\")", self->group->prop->name); + return PyUnicode_FromFormat("(ID Property Group Iter \"%s\")", self->group->prop->name); } static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self) { - if (self->cur) { - PyObject *ret; - IDProperty *cur; + if (self->cur) { + PyObject *ret; + IDProperty *cur; - cur = self->cur; - self->cur = self->cur->next; + cur = self->cur; + self->cur = self->cur->next; - if (self->mode == IDPROP_ITER_ITEMS) { - ret = PyTuple_New(2); - PyTuple_SET_ITEMS(ret, - PyUnicode_FromString(cur->name), - BPy_IDGroup_WrapData(self->group->id, cur, self->group->prop)); - return ret; - } - else { - return PyUnicode_FromString(cur->name); - } - } - else { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } + if (self->mode == IDPROP_ITER_ITEMS) { + ret = PyTuple_New(2); + PyTuple_SET_ITEMS(ret, + PyUnicode_FromString(cur->name), + BPy_IDGroup_WrapData(self->group->id, cur, self->group->prop)); + return ret; + } + else { + return PyUnicode_FromString(cur->name); + } + } + else { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } } PyTypeObject BPy_IDGroup_Iter_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - /* For printing, in format "<module>.<name>" */ - "IDPropertyGroupIter", /* char *tp_name; */ - sizeof(BPy_IDGroup_Iter), /* int tp_basicsize; */ - 0, /* tp_itemsize; For allocation */ + PyVarObject_HEAD_INIT(NULL, 0) + /* For printing, in format "<module>.<name>" */ + "IDPropertyGroupIter", /* char *tp_name; */ + sizeof(BPy_IDGroup_Iter), /* int tp_basicsize; */ + 0, /* tp_itemsize; For allocation */ - /* Methods to implement standard operations */ + /* Methods to implement standard operations */ - NULL, /* destructor tp_dealloc; */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* cmpfunc tp_compare; */ - (reprfunc) IDGroup_Iter_repr, /* reprfunc tp_repr; */ + NULL, /* destructor tp_dealloc; */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* cmpfunc tp_compare; */ + (reprfunc)IDGroup_Iter_repr, /* reprfunc tp_repr; */ - /* Method suites for standard classes */ + /* Method suites for standard classes */ - NULL, /* PyNumberMethods *tp_as_number; */ - NULL, /* PySequenceMethods *tp_as_sequence; */ - NULL, /* PyMappingMethods *tp_as_mapping; */ + NULL, /* PyNumberMethods *tp_as_number; */ + NULL, /* PySequenceMethods *tp_as_sequence; */ + NULL, /* PyMappingMethods *tp_as_mapping; */ - /* More standard operations (here for binary compatibility) */ + /* More standard operations (here for binary compatibility) */ - NULL, /* hashfunc tp_hash; */ - NULL, /* ternaryfunc tp_call; */ - NULL, /* reprfunc tp_str; */ - NULL, /* getattrofunc tp_getattro; */ - NULL, /* setattrofunc tp_setattro; */ + NULL, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ - /* Functions to access object as input/output buffer */ - NULL, /* PyBufferProcs *tp_as_buffer; */ + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ - /*** Flags to define presence of optional/expanded features ***/ - Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ - NULL, /* char *tp_doc; Documentation string */ - /*** Assigned meaning in release 2.0 ***/ - /* call function for all accessible objects */ - NULL, /* traverseproc tp_traverse; */ + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ - /* delete references to contained objects */ - NULL, /* inquiry tp_clear; */ + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ - /*** Assigned meaning in release 2.1 ***/ - /*** rich comparisons ***/ - NULL, /* richcmpfunc tp_richcompare; */ + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ - /*** weak reference enabler ***/ - 0, /* long tp_weaklistoffset; */ + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ - /*** Added in release 2.2 ***/ - /* Iterators */ - PyObject_SelfIter, /* getiterfunc tp_iter; */ - (iternextfunc) BPy_Group_Iter_Next, /* iternextfunc tp_iternext; */ + /*** Added in release 2.2 ***/ + /* Iterators */ + PyObject_SelfIter, /* getiterfunc tp_iter; */ + (iternextfunc)BPy_Group_Iter_Next, /* iternextfunc tp_iternext; */ }; void IDProp_Init_Types(void) { - PyType_Ready(&BPy_IDGroup_Type); - PyType_Ready(&BPy_IDGroup_Iter_Type); - PyType_Ready(&BPy_IDArray_Type); + PyType_Ready(&BPy_IDGroup_Type); + PyType_Ready(&BPy_IDGroup_Iter_Type); + PyType_Ready(&BPy_IDArray_Type); } /*----------------------------MODULE INIT-------------------------*/ @@ -1763,71 +1753,70 @@ void IDProp_Init_Types(void) /* --- */ static struct PyModuleDef IDProp_types_module_def = { - PyModuleDef_HEAD_INIT, - "idprop.types", /* m_name */ - NULL, /* m_doc */ - 0, /* m_size */ - NULL, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ + PyModuleDef_HEAD_INIT, + "idprop.types", /* m_name */ + NULL, /* m_doc */ + 0, /* m_size */ + NULL, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ }; static PyObject *BPyInit_idprop_types(void) { - PyObject *submodule; + PyObject *submodule; - submodule = PyModule_Create(&IDProp_types_module_def); + submodule = PyModule_Create(&IDProp_types_module_def); - IDProp_Init_Types(); + IDProp_Init_Types(); #define MODULE_TYPE_ADD(s, t) \ - PyModule_AddObject(s, t.tp_name, (PyObject *)&t); Py_INCREF((PyObject *)&t) + PyModule_AddObject(s, t.tp_name, (PyObject *)&t); \ + Py_INCREF((PyObject *)&t) - /* bmesh_py_types.c */ - MODULE_TYPE_ADD(submodule, BPy_IDGroup_Type); - MODULE_TYPE_ADD(submodule, BPy_IDGroup_Iter_Type); - MODULE_TYPE_ADD(submodule, BPy_IDArray_Type); + /* bmesh_py_types.c */ + MODULE_TYPE_ADD(submodule, BPy_IDGroup_Type); + MODULE_TYPE_ADD(submodule, BPy_IDGroup_Iter_Type); + MODULE_TYPE_ADD(submodule, BPy_IDArray_Type); #undef MODULE_TYPE_ADD - return submodule; + return submodule; } /* --- */ static PyMethodDef IDProp_methods[] = { - {NULL, NULL, 0, NULL}, + {NULL, NULL, 0, NULL}, }; - PyDoc_STRVAR(IDProp_module_doc, -"This module provides access id property types (currently mainly for docs)." -); + "This module provides access id property types (currently mainly for docs)."); static struct PyModuleDef IDProp_module_def = { - PyModuleDef_HEAD_INIT, - "idprop", /* m_name */ - IDProp_module_doc, /* m_doc */ - 0, /* m_size */ - IDProp_methods, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ + PyModuleDef_HEAD_INIT, + "idprop", /* m_name */ + IDProp_module_doc, /* m_doc */ + 0, /* m_size */ + IDProp_methods, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ }; PyObject *BPyInit_idprop(void) { - PyObject *mod; - PyObject *submodule; - PyObject *sys_modules = PyImport_GetModuleDict(); + PyObject *mod; + PyObject *submodule; + PyObject *sys_modules = PyImport_GetModuleDict(); - mod = PyModule_Create(&IDProp_module_def); + mod = PyModule_Create(&IDProp_module_def); - /* idprop.types */ - PyModule_AddObject(mod, "types", (submodule = BPyInit_idprop_types())); - PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); + /* idprop.types */ + PyModule_AddObject(mod, "types", (submodule = BPyInit_idprop_types())); + PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); - return mod; + return mod; } diff --git a/source/blender/python/generic/idprop_py_api.h b/source/blender/python/generic/idprop_py_api.h index 369b8359c55..49094f95ecb 100644 --- a/source/blender/python/generic/idprop_py_api.h +++ b/source/blender/python/generic/idprop_py_api.h @@ -18,7 +18,6 @@ * \ingroup pygen */ - #ifndef __IDPROP_PY_API_H__ #define __IDPROP_PY_API_H__ @@ -30,32 +29,29 @@ extern PyTypeObject BPy_IDArray_Type; extern PyTypeObject BPy_IDGroup_Iter_Type; extern PyTypeObject BPy_IDGroup_Type; -#define BPy_IDArray_Check(v) (PyObject_TypeCheck(v, &BPy_IDArray_Type)) -#define BPy_IDArray_CheckExact(v) (Py_TYPE(v) == &BPy_IDArray_Type) -#define BPy_IDGroup_Iter_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Iter_Type)) -#define BPy_IDGroup_Iter_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Iter_Type) -#define BPy_IDGroup_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Type)) -#define BPy_IDGroup_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Type) +#define BPy_IDArray_Check(v) (PyObject_TypeCheck(v, &BPy_IDArray_Type)) +#define BPy_IDArray_CheckExact(v) (Py_TYPE(v) == &BPy_IDArray_Type) +#define BPy_IDGroup_Iter_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Iter_Type)) +#define BPy_IDGroup_Iter_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Iter_Type) +#define BPy_IDGroup_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Type)) +#define BPy_IDGroup_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Type) typedef struct BPy_IDProperty { - PyObject_VAR_HEAD - struct ID *id; /* can be NULL */ - struct IDProperty *prop; /* must be second member */ - struct IDProperty *parent; - PyObject *data_wrap; + PyObject_VAR_HEAD struct ID *id; /* can be NULL */ + struct IDProperty *prop; /* must be second member */ + struct IDProperty *parent; + PyObject *data_wrap; } BPy_IDProperty; typedef struct BPy_IDArray { - PyObject_VAR_HEAD - struct ID *id; /* can be NULL */ - struct IDProperty *prop; /* must be second member */ + PyObject_VAR_HEAD struct ID *id; /* can be NULL */ + struct IDProperty *prop; /* must be second member */ } BPy_IDArray; typedef struct BPy_IDGroup_Iter { - PyObject_VAR_HEAD - BPy_IDProperty *group; - struct IDProperty *cur; - int mode; + PyObject_VAR_HEAD BPy_IDProperty *group; + struct IDProperty *cur; + int mode; } BPy_IDGroup_Iter; PyObject *BPy_Wrap_GetKeys(struct IDProperty *prop); @@ -63,7 +59,6 @@ PyObject *BPy_Wrap_GetValues(struct ID *id, struct IDProperty *prop); PyObject *BPy_Wrap_GetItems(struct ID *id, struct IDProperty *prop); int BPy_Wrap_SetMapItem(struct IDProperty *prop, PyObject *key, PyObject *val); - PyObject *BPy_IDGroup_WrapData(struct ID *id, struct IDProperty *prop, struct IDProperty *parent); bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *key, struct IDProperty *group, PyObject *ob); @@ -71,7 +66,7 @@ void IDProp_Init_Types(void); PyObject *BPyInit_idprop(void); -#define IDPROP_ITER_KEYS 0 -#define IDPROP_ITER_ITEMS 1 +#define IDPROP_ITER_KEYS 0 +#define IDPROP_ITER_ITEMS 1 #endif /* __IDPROP_PY_API_H__ */ diff --git a/source/blender/python/generic/imbuf_py_api.c b/source/blender/python/generic/imbuf_py_api.c index ed9994276c5..26e4e5bcf32 100644 --- a/source/blender/python/generic/imbuf_py_api.c +++ b/source/blender/python/generic/imbuf_py_api.c @@ -29,7 +29,7 @@ #include "python_utildefines.h" -#include "imbuf_py_api.h" /* own include */ +#include "imbuf_py_api.h" /* own include */ #include "../../imbuf/IMB_imbuf.h" #include "../../imbuf/IMB_imbuf_types.h" @@ -46,28 +46,33 @@ static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf); * \{ */ typedef struct Py_ImBuf { - PyObject_VAR_HEAD - /* can be NULL */ - ImBuf *ibuf; + PyObject_VAR_HEAD + /* can be NULL */ + ImBuf *ibuf; } Py_ImBuf; static int py_imbuf_valid_check(Py_ImBuf *self) { - if (LIKELY(self->ibuf)) { - return 0; - } - else { - PyErr_Format(PyExc_ReferenceError, - "ImBuf data of type %.200s has been freed", - Py_TYPE(self)->tp_name); - return -1; - } + if (LIKELY(self->ibuf)) { + return 0; + } + else { + PyErr_Format( + PyExc_ReferenceError, "ImBuf data of type %.200s has been freed", Py_TYPE(self)->tp_name); + return -1; + } } #define PY_IMBUF_CHECK_OBJ(obj) \ - if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { return NULL; } ((void)0) + if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \ + return NULL; \ + } \ + ((void)0) #define PY_IMBUF_CHECK_INT(obj) \ - if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { return -1; } ((void)0) + if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \ + return -1; \ + } \ + ((void)0) /** \} */ @@ -76,77 +81,72 @@ static int py_imbuf_valid_check(Py_ImBuf *self) * \{ */ PyDoc_STRVAR(py_imbuf_resize_doc, -".. method:: resize(size, method='FAST')\n" -"\n" -" Resize the image.\n" -"\n" -" :arg size: New size.\n" -" :type size: pair of ints\n" -" :arg method: Method of resizing (TODO)\n" -" :type method: str\n" -); + ".. method:: resize(size, method='FAST')\n" + "\n" + " Resize the image.\n" + "\n" + " :arg size: New size.\n" + " :type size: pair of ints\n" + " :arg method: Method of resizing (TODO)\n" + " :type method: str\n"); static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw) { - PY_IMBUF_CHECK_OBJ(self); - - uint size[2]; - char *method = NULL; - - static const char *_keywords[] = {"size", "method", NULL}; - static _PyArg_Parser _parser = {"(II)|s:resize", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast( - args, kw, &_parser, - &size[0], &size[1], - &method)) - { - return NULL; - } - IMB_scaleImBuf(self->ibuf, UNPACK2(size)); - Py_RETURN_NONE; + PY_IMBUF_CHECK_OBJ(self); + + uint size[2]; + char *method = NULL; + + static const char *_keywords[] = {"size", "method", NULL}; + static _PyArg_Parser _parser = {"(II)|s:resize", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], &size[1], &method)) { + return NULL; + } + IMB_scaleImBuf(self->ibuf, UNPACK2(size)); + Py_RETURN_NONE; } PyDoc_STRVAR(py_imbuf_copy_doc, -".. method:: copy()\n" -"\n" -" :return: A copy of the image.\n" -" :rtype: :class:`ImBuf`\n" -); + ".. method:: copy()\n" + "\n" + " :return: A copy of the image.\n" + " :rtype: :class:`ImBuf`\n"); static PyObject *py_imbuf_copy(Py_ImBuf *self) { - PY_IMBUF_CHECK_OBJ(self); - return Py_ImBuf_CreatePyObject(self->ibuf); + PY_IMBUF_CHECK_OBJ(self); + return Py_ImBuf_CreatePyObject(self->ibuf); } static PyObject *py_imbuf_deepcopy(Py_ImBuf *self, PyObject *args) { - if (!PyC_CheckArgs_DeepCopy(args)) { - return NULL; - } - return py_imbuf_copy(self); + if (!PyC_CheckArgs_DeepCopy(args)) { + return NULL; + } + return py_imbuf_copy(self); } - PyDoc_STRVAR(py_imbuf_free_doc, -".. method:: free()\n" -"\n" -" Clear image data immediately (causing an error on re-use).\n" -); + ".. method:: free()\n" + "\n" + " Clear image data immediately (causing an error on re-use).\n"); static PyObject *py_imbuf_free(Py_ImBuf *self) { - if (self->ibuf) { - IMB_freeImBuf(self->ibuf); - self->ibuf = NULL; - } - Py_RETURN_NONE; + if (self->ibuf) { + IMB_freeImBuf(self->ibuf); + self->ibuf = NULL; + } + Py_RETURN_NONE; } static struct PyMethodDef Py_ImBuf_methods[] = { - {"resize", (PyCFunction)py_imbuf_resize, METH_VARARGS | METH_KEYWORDS, (char *)py_imbuf_resize_doc}, - {"free", (PyCFunction)py_imbuf_free, METH_NOARGS, (char *)py_imbuf_free_doc}, - {"copy", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc}, - {"__copy__", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc}, - {"__deepcopy__", (PyCFunction)py_imbuf_deepcopy, METH_VARARGS, (char *)py_imbuf_copy_doc}, - {NULL, NULL, 0, NULL}, + {"resize", + (PyCFunction)py_imbuf_resize, + METH_VARARGS | METH_KEYWORDS, + (char *)py_imbuf_resize_doc}, + {"free", (PyCFunction)py_imbuf_free, METH_NOARGS, (char *)py_imbuf_free_doc}, + {"copy", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc}, + {"__copy__", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc}, + {"__deepcopy__", (PyCFunction)py_imbuf_deepcopy, METH_VARARGS, (char *)py_imbuf_copy_doc}, + {NULL, NULL, 0, NULL}, }; /** \} */ @@ -155,50 +155,50 @@ static struct PyMethodDef Py_ImBuf_methods[] = { /** \name Attributes * \{ */ -PyDoc_STRVAR(py_imbuf_size_doc, -"size of the image in pixels.\n\n:type: pair of ints" -); +PyDoc_STRVAR(py_imbuf_size_doc, "size of the image in pixels.\n\n:type: pair of ints"); static PyObject *py_imbuf_size_get(Py_ImBuf *self, void *UNUSED(closure)) { - PY_IMBUF_CHECK_OBJ(self); - ImBuf *ibuf = self->ibuf; - return PyC_Tuple_Pack_I32(ibuf->x, ibuf->y); + PY_IMBUF_CHECK_OBJ(self); + ImBuf *ibuf = self->ibuf; + return PyC_Tuple_Pack_I32(ibuf->x, ibuf->y); } -PyDoc_STRVAR(py_imbuf_ppm_doc, -"pixels per meter.\n\n:type: pair of floats" -); +PyDoc_STRVAR(py_imbuf_ppm_doc, "pixels per meter.\n\n:type: pair of floats"); static PyObject *py_imbuf_ppm_get(Py_ImBuf *self, void *UNUSED(closure)) { - PY_IMBUF_CHECK_OBJ(self); - ImBuf *ibuf = self->ibuf; - return PyC_Tuple_Pack_F64(ibuf->ppm[0], ibuf->ppm[1]); + PY_IMBUF_CHECK_OBJ(self); + ImBuf *ibuf = self->ibuf; + return PyC_Tuple_Pack_F64(ibuf->ppm[0], ibuf->ppm[1]); } static int py_imbuf_ppm_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure)) { - PY_IMBUF_CHECK_INT(self); - double ppm[2]; - - if (PyC_AsArray(ppm, value, 2, &PyFloat_Type, true, "ppm") == -1) { - return -1; - } - - if (ppm[0] <= 0.0 || ppm[1] <= 0.0) { - PyErr_SetString(PyExc_ValueError, "invalid ppm value"); - return -1; - } - - ImBuf *ibuf = self->ibuf; - ibuf->ppm[0] = ppm[0]; - ibuf->ppm[1] = ppm[1]; - return 0; + PY_IMBUF_CHECK_INT(self); + double ppm[2]; + + if (PyC_AsArray(ppm, value, 2, &PyFloat_Type, true, "ppm") == -1) { + return -1; + } + + if (ppm[0] <= 0.0 || ppm[1] <= 0.0) { + PyErr_SetString(PyExc_ValueError, "invalid ppm value"); + return -1; + } + + ImBuf *ibuf = self->ibuf; + ibuf->ppm[0] = ppm[0]; + ibuf->ppm[1] = ppm[1]; + return 0; } static PyGetSetDef Py_ImBuf_getseters[] = { - {(char *)"size", (getter)py_imbuf_size_get, (setter)NULL, (char *)py_imbuf_size_doc, NULL}, - {(char *)"ppm", (getter)py_imbuf_ppm_get, (setter)py_imbuf_ppm_set, (char *)py_imbuf_ppm_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"size", (getter)py_imbuf_size_get, (setter)NULL, (char *)py_imbuf_size_doc, NULL}, + {(char *)"ppm", + (getter)py_imbuf_ppm_get, + (setter)py_imbuf_ppm_set, + (char *)py_imbuf_ppm_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /** \} */ @@ -209,99 +209,97 @@ static PyGetSetDef Py_ImBuf_getseters[] = { static void py_imbuf_dealloc(Py_ImBuf *self) { - ImBuf *ibuf = self->ibuf; - if (ibuf != NULL) { - IMB_freeImBuf(self->ibuf); - self->ibuf = NULL; - } - PyObject_DEL(self); + ImBuf *ibuf = self->ibuf; + if (ibuf != NULL) { + IMB_freeImBuf(self->ibuf); + self->ibuf = NULL; + } + PyObject_DEL(self); } static PyObject *py_imbuf_repr(Py_ImBuf *self) { - const ImBuf *ibuf = self->ibuf; - if (ibuf != NULL) { - return PyUnicode_FromFormat( - "<imbuf: address=%p, filename='%s', size=(%d, %d)>", - ibuf, ibuf->name, ibuf->x, ibuf->y); - } - else { - return PyUnicode_FromString( - "<imbuf: address=0x0>"); - } + const ImBuf *ibuf = self->ibuf; + if (ibuf != NULL) { + return PyUnicode_FromFormat( + "<imbuf: address=%p, filename='%s', size=(%d, %d)>", ibuf, ibuf->name, ibuf->x, ibuf->y); + } + else { + return PyUnicode_FromString("<imbuf: address=0x0>"); + } } static Py_hash_t py_imbuf_hash(Py_ImBuf *self) { - return _Py_HashPointer(self->ibuf); + return _Py_HashPointer(self->ibuf); } PyTypeObject Py_ImBuf_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - /* For printing, in format "<module>.<name>" */ - "ImBuf", /* tp_name */ - sizeof(Py_ImBuf), /* int tp_basicsize; */ - 0, /* tp_itemsize; For allocation */ - - /* Methods to implement standard operations */ - - (destructor)py_imbuf_dealloc, /* destructor tp_dealloc; */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* cmpfunc tp_compare; */ - (reprfunc)py_imbuf_repr, /* reprfunc tp_repr; */ - - /* Method suites for standard classes */ - - NULL, /* PyNumberMethods *tp_as_number; */ - NULL, /* PySequenceMethods *tp_as_sequence; */ - NULL, /* PyMappingMethods *tp_as_mapping; */ - - /* More standard operations (here for binary compatibility) */ - - (hashfunc)py_imbuf_hash, /* hashfunc tp_hash; */ - NULL, /* ternaryfunc tp_call; */ - NULL, /* reprfunc tp_str; */ - NULL, /* getattrofunc tp_getattro; */ - NULL, /* setattrofunc tp_setattro; */ - - /* Functions to access object as input/output buffer */ - NULL, /* PyBufferProcs *tp_as_buffer; */ - - /*** Flags to define presence of optional/expanded features ***/ - Py_TPFLAGS_DEFAULT, /* long tp_flags; */ - - NULL, /* char *tp_doc; Documentation string */ - /*** Assigned meaning in release 2.0 ***/ - /* call function for all accessible objects */ - NULL, /* traverseproc tp_traverse; */ - - /* delete references to contained objects */ - NULL, /* inquiry tp_clear; */ - - /*** Assigned meaning in release 2.1 ***/ - /*** rich comparisons ***/ - NULL, /* richcmpfunc tp_richcompare; */ - - /*** weak reference enabler ***/ - 0, /* long tp_weaklistoffset; */ - - /*** Added in release 2.2 ***/ - /* Iterators */ - NULL, /* getiterfunc tp_iter; */ - NULL, /* iternextfunc tp_iternext; */ - /*** Attribute descriptor and subclassing stuff ***/ - Py_ImBuf_methods, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - Py_ImBuf_getseters, /* struct PyGetSetDef *tp_getset; */ + PyVarObject_HEAD_INIT(NULL, 0) + /* For printing, in format "<module>.<name>" */ + "ImBuf", /* tp_name */ + sizeof(Py_ImBuf), /* int tp_basicsize; */ + 0, /* tp_itemsize; For allocation */ + + /* Methods to implement standard operations */ + + (destructor)py_imbuf_dealloc, /* destructor tp_dealloc; */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* cmpfunc tp_compare; */ + (reprfunc)py_imbuf_repr, /* reprfunc tp_repr; */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + NULL, /* PySequenceMethods *tp_as_sequence; */ + NULL, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + (hashfunc)py_imbuf_hash, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + /*** Attribute descriptor and subclassing stuff ***/ + Py_ImBuf_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + Py_ImBuf_getseters, /* struct PyGetSetDef *tp_getset; */ }; static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf) { - Py_ImBuf *self = PyObject_New(Py_ImBuf, &Py_ImBuf_Type); - self->ibuf = ibuf; - return (PyObject *)self; + Py_ImBuf *self = PyObject_New(Py_ImBuf, &Py_ImBuf_Type); + self->ibuf = ibuf; + return (PyObject *)self; } /** \} */ @@ -311,118 +309,107 @@ static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf) * \{ */ PyDoc_STRVAR(M_imbuf_new_doc, -".. function:: new(size)\n" -"\n" -" Load a new image.\n" -"\n" -" :arg size: The size of the image in pixels.\n" -" :type size: pair of ints\n" -" :return: the newly loaded image.\n" -" :rtype: :class:`ImBuf`\n" -); + ".. function:: new(size)\n" + "\n" + " Load a new image.\n" + "\n" + " :arg size: The size of the image in pixels.\n" + " :type size: pair of ints\n" + " :return: the newly loaded image.\n" + " :rtype: :class:`ImBuf`\n"); static PyObject *M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { - int size[2]; - static const char *_keywords[] = {"size", NULL}; - static _PyArg_Parser _parser = {"(ii)|i:new", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast( - args, kw, &_parser, - &size[0], &size[1])) - { - return NULL; - } - - /* TODO, make options */ - uchar planes = 4; - uint flags = IB_rect; - - ImBuf *ibuf = IMB_allocImBuf(UNPACK2(size), planes, flags); - if (ibuf == NULL) { - PyErr_Format(PyExc_ValueError, "new: Unable to create image (%d, %d)", UNPACK2(size)); - return NULL; - } - return Py_ImBuf_CreatePyObject(ibuf); + int size[2]; + static const char *_keywords[] = {"size", NULL}; + static _PyArg_Parser _parser = {"(ii)|i:new", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], &size[1])) { + return NULL; + } + + /* TODO, make options */ + uchar planes = 4; + uint flags = IB_rect; + + ImBuf *ibuf = IMB_allocImBuf(UNPACK2(size), planes, flags); + if (ibuf == NULL) { + PyErr_Format(PyExc_ValueError, "new: Unable to create image (%d, %d)", UNPACK2(size)); + return NULL; + } + return Py_ImBuf_CreatePyObject(ibuf); } PyDoc_STRVAR(M_imbuf_load_doc, -".. function:: load(filename)\n" -"\n" -" Load an image from a file.\n" -"\n" -" :arg filename: the filename of the image.\n" -" :type filename: string\n" -" :return: the newly loaded image.\n" -" :rtype: :class:`ImBuf`\n" -); + ".. function:: load(filename)\n" + "\n" + " Load an image from a file.\n" + "\n" + " :arg filename: the filename of the image.\n" + " :type filename: string\n" + " :return: the newly loaded image.\n" + " :rtype: :class:`ImBuf`\n"); static PyObject *M_imbuf_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { - const char *filename; + const char *filename; - static const char *_keywords[] = {"filename", NULL}; - static _PyArg_Parser _parser = {"s:load", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast( - args, kw, &_parser, - &filename)) - { - return NULL; - } + static const char *_keywords[] = {"filename", NULL}; + static _PyArg_Parser _parser = {"s:load", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filename)) { + return NULL; + } - const int file = BLI_open(filename, O_BINARY | O_RDONLY, 0); - if (file == -1) { - PyErr_Format(PyExc_IOError, "load: %s, failed to open file '%s'", strerror(errno)); - return NULL; - } + const int file = BLI_open(filename, O_BINARY | O_RDONLY, 0); + if (file == -1) { + PyErr_Format(PyExc_IOError, "load: %s, failed to open file '%s'", strerror(errno)); + return NULL; + } - ImBuf *ibuf = IMB_loadifffile(file, filename, IB_rect, NULL, filename); + ImBuf *ibuf = IMB_loadifffile(file, filename, IB_rect, NULL, filename); - close(file); + close(file); - if (ibuf == NULL) { - PyErr_Format(PyExc_ValueError, "load: Unable to recognize image format for file '%s'", filename); - return NULL; - } + if (ibuf == NULL) { + PyErr_Format( + PyExc_ValueError, "load: Unable to recognize image format for file '%s'", filename); + return NULL; + } - BLI_strncpy(ibuf->name, filename, sizeof(ibuf->name)); + BLI_strncpy(ibuf->name, filename, sizeof(ibuf->name)); - return Py_ImBuf_CreatePyObject(ibuf); + return Py_ImBuf_CreatePyObject(ibuf); } PyDoc_STRVAR(M_imbuf_write_doc, -".. function:: write(image, filename)\n" -"\n" -" Write an image.\n" -"\n" -" :arg image: the image to write.\n" -" :type image: :class:`ImBuf`\n" -" :arg filename: the filename of the image.\n" -" :type filename: string\n" -); + ".. function:: write(image, filename)\n" + "\n" + " Write an image.\n" + "\n" + " :arg image: the image to write.\n" + " :type image: :class:`ImBuf`\n" + " :arg filename: the filename of the image.\n" + " :type filename: string\n"); static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { - Py_ImBuf *py_imb; - const char *filename = NULL; - - static const char *_keywords[] = {"image", "filename", NULL}; - static _PyArg_Parser _parser = {"O!|s:write", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast( - args, kw, &_parser, - &Py_ImBuf_Type, &py_imb, - &filename)) - { - return NULL; - } - - if (filename == NULL) { - filename = py_imb->ibuf->name; - } - - bool ok = IMB_saveiff(py_imb->ibuf, filename, IB_rect); - if (ok == false) { - PyErr_Format(PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filename); - return NULL; - } - - Py_RETURN_NONE; + Py_ImBuf *py_imb; + const char *filename = NULL; + + static const char *_keywords[] = {"image", "filename", NULL}; + static _PyArg_Parser _parser = {"O!|s:write", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &Py_ImBuf_Type, &py_imb, &filename)) { + return NULL; + } + + if (filename == NULL) { + filename = py_imb->ibuf->name; + } + + bool ok = IMB_saveiff(py_imb->ibuf, filename, IB_rect); + if (ok == false) { + PyErr_Format( + PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filename); + return NULL; + } + + Py_RETURN_NONE; } /** \} */ @@ -432,36 +419,34 @@ static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject * \{ */ static PyMethodDef IMB_methods[] = { - {"new", (PyCFunction) M_imbuf_new, METH_VARARGS | METH_KEYWORDS, M_imbuf_new_doc}, - {"load", (PyCFunction) M_imbuf_load, METH_VARARGS | METH_KEYWORDS, M_imbuf_load_doc}, - {"write", (PyCFunction) M_imbuf_write, METH_VARARGS | METH_KEYWORDS, M_imbuf_write_doc}, - {NULL, NULL, 0, NULL}, + {"new", (PyCFunction)M_imbuf_new, METH_VARARGS | METH_KEYWORDS, M_imbuf_new_doc}, + {"load", (PyCFunction)M_imbuf_load, METH_VARARGS | METH_KEYWORDS, M_imbuf_load_doc}, + {"write", (PyCFunction)M_imbuf_write, METH_VARARGS | METH_KEYWORDS, M_imbuf_write_doc}, + {NULL, NULL, 0, NULL}, }; -PyDoc_STRVAR(IMB_doc, -"This module provides access to Blender's image manipulation API." -); +PyDoc_STRVAR(IMB_doc, "This module provides access to Blender's image manipulation API."); static struct PyModuleDef IMB_module_def = { - PyModuleDef_HEAD_INIT, - "imbuf", /* m_name */ - IMB_doc, /* m_doc */ - 0, /* m_size */ - IMB_methods, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ + PyModuleDef_HEAD_INIT, + "imbuf", /* m_name */ + IMB_doc, /* m_doc */ + 0, /* m_size */ + IMB_methods, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ }; PyObject *BPyInit_imbuf(void) { - PyObject *submodule; + PyObject *submodule; - submodule = PyModule_Create(&IMB_module_def); + submodule = PyModule_Create(&IMB_module_def); - PyType_Ready(&Py_ImBuf_Type); + PyType_Ready(&Py_ImBuf_Type); - return submodule; + return submodule; } /** \} */ diff --git a/source/blender/python/generic/imbuf_py_api.h b/source/blender/python/generic/imbuf_py_api.h index c36c4ba11f6..2dea925a9f2 100644 --- a/source/blender/python/generic/imbuf_py_api.h +++ b/source/blender/python/generic/imbuf_py_api.h @@ -25,4 +25,4 @@ PyObject *BPyInit_imbuf(void); extern PyTypeObject Py_ImBuf_Type; -#endif /* __IMBUF_PY_API_H__ */ +#endif /* __IMBUF_PY_API_H__ */ diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 0c10737609c..191863a862d 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -28,7 +28,7 @@ #include <Python.h> #include <frameobject.h> -#include "BLI_utildefines.h" /* for bool */ +#include "BLI_utildefines.h" /* for bool */ #include "py_capi_utils.h" @@ -38,90 +38,97 @@ #ifndef MATH_STANDALONE /* only for BLI_strncpy_wchar_from_utf8, should replace with py funcs but too late in release now */ -#include "BLI_string_utf8.h" +# include "BLI_string_utf8.h" #endif #ifdef _WIN32 -#include "BLI_math_base.h" /* isfinite() */ +# include "BLI_math_base.h" /* isfinite() */ #endif /* array utility function */ -int PyC_AsArray_FAST( - void *array, PyObject *value_fast, const Py_ssize_t length, - const PyTypeObject *type, const bool is_double, const char *error_prefix) +int PyC_AsArray_FAST(void *array, + PyObject *value_fast, + const Py_ssize_t length, + const PyTypeObject *type, + const bool is_double, + const char *error_prefix) { - const Py_ssize_t value_len = PySequence_Fast_GET_SIZE(value_fast); - PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast); - Py_ssize_t i; - - BLI_assert(PyList_Check(value_fast) || PyTuple_Check(value_fast)); - - if (value_len != length) { - PyErr_Format(PyExc_TypeError, - "%.200s: invalid sequence length. expected %d, got %d", - error_prefix, length, value_len); - return -1; - } - - /* for each type */ - if (type == &PyFloat_Type) { - if (is_double) { - double *array_double = array; - for (i = 0; i < length; i++) { - array_double[i] = PyFloat_AsDouble(value_fast_items[i]); - } - } - else { - float *array_float = array; - for (i = 0; i < length; i++) { - array_float[i] = PyFloat_AsDouble(value_fast_items[i]); - } - } - } - else if (type == &PyLong_Type) { - /* could use is_double for 'long int' but no use now */ - int *array_int = array; - for (i = 0; i < length; i++) { - array_int[i] = PyC_Long_AsI32(value_fast_items[i]); - } - } - else if (type == &PyBool_Type) { - bool *array_bool = array; - for (i = 0; i < length; i++) { - array_bool[i] = (PyLong_AsLong(value_fast_items[i]) != 0); - } - } - else { - PyErr_Format(PyExc_TypeError, - "%s: internal error %s is invalid", - error_prefix, type->tp_name); - return -1; - } - - if (PyErr_Occurred()) { - PyErr_Format(PyExc_TypeError, - "%s: one or more items could not be used as a %s", - error_prefix, type->tp_name); - return -1; - } - - return 0; + const Py_ssize_t value_len = PySequence_Fast_GET_SIZE(value_fast); + PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast); + Py_ssize_t i; + + BLI_assert(PyList_Check(value_fast) || PyTuple_Check(value_fast)); + + if (value_len != length) { + PyErr_Format(PyExc_TypeError, + "%.200s: invalid sequence length. expected %d, got %d", + error_prefix, + length, + value_len); + return -1; + } + + /* for each type */ + if (type == &PyFloat_Type) { + if (is_double) { + double *array_double = array; + for (i = 0; i < length; i++) { + array_double[i] = PyFloat_AsDouble(value_fast_items[i]); + } + } + else { + float *array_float = array; + for (i = 0; i < length; i++) { + array_float[i] = PyFloat_AsDouble(value_fast_items[i]); + } + } + } + else if (type == &PyLong_Type) { + /* could use is_double for 'long int' but no use now */ + int *array_int = array; + for (i = 0; i < length; i++) { + array_int[i] = PyC_Long_AsI32(value_fast_items[i]); + } + } + else if (type == &PyBool_Type) { + bool *array_bool = array; + for (i = 0; i < length; i++) { + array_bool[i] = (PyLong_AsLong(value_fast_items[i]) != 0); + } + } + else { + PyErr_Format(PyExc_TypeError, "%s: internal error %s is invalid", error_prefix, type->tp_name); + return -1; + } + + if (PyErr_Occurred()) { + PyErr_Format(PyExc_TypeError, + "%s: one or more items could not be used as a %s", + error_prefix, + type->tp_name); + return -1; + } + + return 0; } -int PyC_AsArray( - void *array, PyObject *value, const Py_ssize_t length, - const PyTypeObject *type, const bool is_double, const char *error_prefix) +int PyC_AsArray(void *array, + PyObject *value, + const Py_ssize_t length, + const PyTypeObject *type, + const bool is_double, + const char *error_prefix) { - PyObject *value_fast; - int ret; + PyObject *value_fast; + int ret; - if (!(value_fast = PySequence_Fast(value, error_prefix))) { - return -1; - } + if (!(value_fast = PySequence_Fast(value, error_prefix))) { + return -1; + } - ret = PyC_AsArray_FAST(array, value_fast, length, type, is_double, error_prefix); - Py_DECREF(value_fast); - return ret; + ret = PyC_AsArray_FAST(array, value_fast, length, type, is_double, error_prefix); + Py_DECREF(value_fast); + return ret; } /* -------------------------------------------------------------------- */ @@ -134,47 +141,47 @@ int PyC_AsArray( /* array utility function */ PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len) { - PyObject *tuple = PyTuple_New(len); - for (uint i = 0; i < len; i++) { - PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array[i])); - } - return tuple; + PyObject *tuple = PyTuple_New(len); + for (uint i = 0; i < len; i++) { + PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array[i])); + } + return tuple; } PyObject *PyC_Tuple_PackArray_F64(const double *array, uint len) { - PyObject *tuple = PyTuple_New(len); - for (uint i = 0; i < len; i++) { - PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array[i])); - } - return tuple; + PyObject *tuple = PyTuple_New(len); + for (uint i = 0; i < len; i++) { + PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array[i])); + } + return tuple; } PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len) { - PyObject *tuple = PyTuple_New(len); - for (uint i = 0; i < len; i++) { - PyTuple_SET_ITEM(tuple, i, PyLong_FromLong(array[i])); - } - return tuple; + PyObject *tuple = PyTuple_New(len); + for (uint i = 0; i < len; i++) { + PyTuple_SET_ITEM(tuple, i, PyLong_FromLong(array[i])); + } + return tuple; } PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len) { - PyObject *tuple = PyTuple_New(len); - for (uint i = 0; i < len; i++) { - PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array[i])); - } - return tuple; + PyObject *tuple = PyTuple_New(len); + for (uint i = 0; i < len; i++) { + PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array[i])); + } + return tuple; } PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len) { - PyObject *tuple = PyTuple_New(len); - for (uint i = 0; i < len; i++) { - PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array[i])); - } - return tuple; + PyObject *tuple = PyTuple_New(len); + for (uint i = 0; i < len; i++) { + PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array[i])); + } + return tuple; } /** \} */ @@ -185,24 +192,24 @@ PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len) */ void PyC_Tuple_Fill(PyObject *tuple, PyObject *value) { - unsigned int tot = PyTuple_GET_SIZE(tuple); - unsigned int i; + unsigned int tot = PyTuple_GET_SIZE(tuple); + unsigned int i; - for (i = 0; i < tot; i++) { - PyTuple_SET_ITEM(tuple, i, value); - Py_INCREF(value); - } + for (i = 0; i < tot; i++) { + PyTuple_SET_ITEM(tuple, i, value); + Py_INCREF(value); + } } void PyC_List_Fill(PyObject *list, PyObject *value) { - unsigned int tot = PyList_GET_SIZE(list); - unsigned int i; + unsigned int tot = PyList_GET_SIZE(list); + unsigned int i; - for (i = 0; i < tot; i++) { - PyList_SET_ITEM(list, i, value); - Py_INCREF(value); - } + for (i = 0; i < tot; i++) { + PyList_SET_ITEM(list, i, value); + Py_INCREF(value); + } } /** @@ -212,24 +219,22 @@ void PyC_List_Fill(PyObject *list, PyObject *value) */ int PyC_ParseBool(PyObject *o, void *p) { - bool *bool_p = p; - long value; - if (((value = PyLong_AsLong(o)) == -1) || !ELEM(value, 0, 1)) { - PyErr_Format(PyExc_ValueError, - "expected a bool or int (0/1), got %s", - Py_TYPE(o)->tp_name); - return 0; - } - - *bool_p = value ? true : false; - return 1; + bool *bool_p = p; + long value; + if (((value = PyLong_AsLong(o)) == -1) || !ELEM(value, 0, 1)) { + PyErr_Format(PyExc_ValueError, "expected a bool or int (0/1), got %s", Py_TYPE(o)->tp_name); + return 0; + } + + *bool_p = value ? true : false; + return 1; } /* silly function, we dont use arg. just check its compatible with __deepcopy__ */ int PyC_CheckArgs_DeepCopy(PyObject *args) { - PyObject *dummy_pydict; - return PyArg_ParseTuple(args, "|O!:__deepcopy__", &PyDict_Type, &dummy_pydict) != 0; + PyObject *dummy_pydict; + return PyArg_ParseTuple(args, "|O!:__deepcopy__", &PyDict_Type, &dummy_pydict) != 0; } #ifndef MATH_STANDALONE @@ -237,18 +242,20 @@ int PyC_CheckArgs_DeepCopy(PyObject *args) /* for debugging */ void PyC_ObSpit(const char *name, PyObject *var) { - const char *null_str = "<null>"; - fprintf(stderr, "<%s> : ", name); - if (var == NULL) { - fprintf(stderr, "%s\n", null_str); - } - else { - PyObject_Print(var, stderr, 0); - const PyTypeObject *type = Py_TYPE(var); - fprintf(stderr, - " ref:%d, ptr:%p, type: %s\n", - (int)var->ob_refcnt, (void *)var, type ? type->tp_name : null_str); - } + const char *null_str = "<null>"; + fprintf(stderr, "<%s> : ", name); + if (var == NULL) { + fprintf(stderr, "%s\n", null_str); + } + else { + PyObject_Print(var, stderr, 0); + const PyTypeObject *type = Py_TYPE(var); + fprintf(stderr, + " ref:%d, ptr:%p, type: %s\n", + (int)var->ob_refcnt, + (void *)var, + type ? type->tp_name : null_str); + } } /** @@ -257,169 +264,167 @@ void PyC_ObSpit(const char *name, PyObject *var) */ void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var) { - /* No name, creator of string can manage that. */ - const char *null_str = "<null>"; - if (var == NULL) { - BLI_snprintf(result, result_len, "%s", null_str); - } - else { - const PyTypeObject *type = Py_TYPE(var); - PyObject *var_str = PyObject_Repr(var); - if (var_str == NULL) { - /* We could print error here, but this may be used for generating errors - so don't for now. */ - PyErr_Clear(); - } - BLI_snprintf( - result, result_len, - " ref=%d, ptr=%p, type=%s, value=%.200s", - (int)var->ob_refcnt, - (void *)var, - type ? type->tp_name : null_str, - var_str ? _PyUnicode_AsString(var_str) : "<error>"); - if (var_str != NULL) { - Py_DECREF(var_str); - } - } + /* No name, creator of string can manage that. */ + const char *null_str = "<null>"; + if (var == NULL) { + BLI_snprintf(result, result_len, "%s", null_str); + } + else { + const PyTypeObject *type = Py_TYPE(var); + PyObject *var_str = PyObject_Repr(var); + if (var_str == NULL) { + /* We could print error here, but this may be used for generating errors - so don't for now. */ + PyErr_Clear(); + } + BLI_snprintf(result, + result_len, + " ref=%d, ptr=%p, type=%s, value=%.200s", + (int)var->ob_refcnt, + (void *)var, + type ? type->tp_name : null_str, + var_str ? _PyUnicode_AsString(var_str) : "<error>"); + if (var_str != NULL) { + Py_DECREF(var_str); + } + } } void PyC_LineSpit(void) { - const char *filename; - int lineno; + const char *filename; + int lineno; - /* Note, allow calling from outside python (RNA) */ - if (!PyC_IsInterpreterActive()) { - fprintf(stderr, "python line lookup failed, interpreter inactive\n"); - return; - } + /* Note, allow calling from outside python (RNA) */ + if (!PyC_IsInterpreterActive()) { + fprintf(stderr, "python line lookup failed, interpreter inactive\n"); + return; + } - PyErr_Clear(); - PyC_FileAndNum(&filename, &lineno); + PyErr_Clear(); + PyC_FileAndNum(&filename, &lineno); - fprintf(stderr, "%s:%d\n", filename, lineno); + fprintf(stderr, "%s:%d\n", filename, lineno); } void PyC_StackSpit(void) { - /* Note, allow calling from outside python (RNA) */ - if (!PyC_IsInterpreterActive()) { - fprintf(stderr, "python line lookup failed, interpreter inactive\n"); - return; - } - else { - /* lame but handy */ - PyGILState_STATE gilstate = PyGILState_Ensure(); - PyRun_SimpleString("__import__('traceback').print_stack()"); - PyGILState_Release(gilstate); - } + /* Note, allow calling from outside python (RNA) */ + if (!PyC_IsInterpreterActive()) { + fprintf(stderr, "python line lookup failed, interpreter inactive\n"); + return; + } + else { + /* lame but handy */ + PyGILState_STATE gilstate = PyGILState_Ensure(); + PyRun_SimpleString("__import__('traceback').print_stack()"); + PyGILState_Release(gilstate); + } } void PyC_FileAndNum(const char **filename, int *lineno) { - PyFrameObject *frame; - - if (filename) { - *filename = NULL; - } - if (lineno) { - *lineno = -1; - } - - if (!(frame = PyThreadState_GET()->frame)) { - return; - } - - /* when executing a script */ - if (filename) { - *filename = _PyUnicode_AsString(frame->f_code->co_filename); - } - - /* when executing a module */ - if (filename && *filename == NULL) { - /* try an alternative method to get the filename - module based - * references below are all borrowed (double checked) */ - PyObject *mod_name = PyDict_GetItemString(PyEval_GetGlobals(), "__name__"); - if (mod_name) { - PyObject *mod = PyDict_GetItem(PyImport_GetModuleDict(), mod_name); - if (mod) { - PyObject *mod_file = PyModule_GetFilenameObject(mod); - if (mod_file) { - *filename = _PyUnicode_AsString(mod_name); - Py_DECREF(mod_file); - } - else { - PyErr_Clear(); - } - } - - /* unlikely, fallback */ - if (*filename == NULL) { - *filename = _PyUnicode_AsString(mod_name); - } - } - } - - if (lineno) { - *lineno = PyFrame_GetLineNumber(frame); - } + PyFrameObject *frame; + + if (filename) { + *filename = NULL; + } + if (lineno) { + *lineno = -1; + } + + if (!(frame = PyThreadState_GET()->frame)) { + return; + } + + /* when executing a script */ + if (filename) { + *filename = _PyUnicode_AsString(frame->f_code->co_filename); + } + + /* when executing a module */ + if (filename && *filename == NULL) { + /* try an alternative method to get the filename - module based + * references below are all borrowed (double checked) */ + PyObject *mod_name = PyDict_GetItemString(PyEval_GetGlobals(), "__name__"); + if (mod_name) { + PyObject *mod = PyDict_GetItem(PyImport_GetModuleDict(), mod_name); + if (mod) { + PyObject *mod_file = PyModule_GetFilenameObject(mod); + if (mod_file) { + *filename = _PyUnicode_AsString(mod_name); + Py_DECREF(mod_file); + } + else { + PyErr_Clear(); + } + } + + /* unlikely, fallback */ + if (*filename == NULL) { + *filename = _PyUnicode_AsString(mod_name); + } + } + } + + if (lineno) { + *lineno = PyFrame_GetLineNumber(frame); + } } void PyC_FileAndNum_Safe(const char **filename, int *lineno) { - if (!PyC_IsInterpreterActive()) { - return; - } + if (!PyC_IsInterpreterActive()) { + return; + } - PyC_FileAndNum(filename, lineno); + PyC_FileAndNum(filename, lineno); } /* Would be nice if python had this built in */ PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...) { - Py_ssize_t i; - PyObject *item = o; - const char *attr; - - va_list vargs; - - va_start(vargs, n); - for (i = 0; i < n; i++) { - attr = va_arg(vargs, char *); - item = PyObject_GetAttrString(item, attr); - - if (item) { - Py_DECREF(item); - } - else { - /* python will set the error value here */ - break; - } - - } - va_end(vargs); - - Py_XINCREF(item); /* final value has is increfed, to match PyObject_GetAttrString */ - return item; + Py_ssize_t i; + PyObject *item = o; + const char *attr; + + va_list vargs; + + va_start(vargs, n); + for (i = 0; i < n; i++) { + attr = va_arg(vargs, char *); + item = PyObject_GetAttrString(item, attr); + + if (item) { + Py_DECREF(item); + } + else { + /* python will set the error value here */ + break; + } + } + va_end(vargs); + + Py_XINCREF(item); /* final value has is increfed, to match PyObject_GetAttrString */ + return item; } PyObject *PyC_FrozenSetFromStrings(const char **strings) { - const char **str; - PyObject *ret; + const char **str; + PyObject *ret; - ret = PyFrozenSet_New(NULL); + ret = PyFrozenSet_New(NULL); - for (str = strings; *str; str++) { - PyObject *py_str = PyUnicode_FromString(*str); - PySet_Add(ret, py_str); - Py_DECREF(py_str); - } + for (str = strings; *str; str++) { + PyObject *py_str = PyUnicode_FromString(*str); + PySet_Add(ret, py_str); + Py_DECREF(py_str); + } - return ret; + return ret; } - /** * Similar to #PyErr_Format(), * @@ -429,45 +434,41 @@ PyObject *PyC_FrozenSetFromStrings(const char **strings) */ PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...) { - PyObject *error_value_prefix; - va_list args; - - va_start(args, format); - error_value_prefix = PyUnicode_FromFormatV(format, args); /* can fail and be NULL */ - va_end(args); - - if (PyErr_Occurred()) { - PyObject *error_type, *error_value, *error_traceback; - PyErr_Fetch(&error_type, &error_value, &error_traceback); - - if (PyUnicode_Check(error_value)) { - PyErr_Format(exception_type_prefix, - "%S, %S", - error_value_prefix, - error_value); - } - else { - PyErr_Format(exception_type_prefix, - "%S, %.200s(%S)", - error_value_prefix, - Py_TYPE(error_value)->tp_name, - error_value); - } - } - else { - PyErr_SetObject(exception_type_prefix, - error_value_prefix); - } - - Py_XDECREF(error_value_prefix); - - /* dumb to always return NULL but matches PyErr_Format */ - return NULL; + PyObject *error_value_prefix; + va_list args; + + va_start(args, format); + error_value_prefix = PyUnicode_FromFormatV(format, args); /* can fail and be NULL */ + va_end(args); + + if (PyErr_Occurred()) { + PyObject *error_type, *error_value, *error_traceback; + PyErr_Fetch(&error_type, &error_value, &error_traceback); + + if (PyUnicode_Check(error_value)) { + PyErr_Format(exception_type_prefix, "%S, %S", error_value_prefix, error_value); + } + else { + PyErr_Format(exception_type_prefix, + "%S, %.200s(%S)", + error_value_prefix, + Py_TYPE(error_value)->tp_name, + error_value); + } + } + else { + PyErr_SetObject(exception_type_prefix, error_value_prefix); + } + + Py_XDECREF(error_value_prefix); + + /* dumb to always return NULL but matches PyErr_Format */ + return NULL; } PyObject *PyC_Err_SetString_Prefix(PyObject *exception_type_prefix, const char *str) { - return PyC_Err_Format_Prefix(exception_type_prefix, "%s", str); + return PyC_Err_Format_Prefix(exception_type_prefix, "%s", str); } /** @@ -476,231 +477,228 @@ PyObject *PyC_Err_SetString_Prefix(PyObject *exception_type_prefix, const char * */ void PyC_Err_PrintWithFunc(PyObject *py_func) { - /* since we return to C code we can't leave the error */ - PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func); - PyErr_Print(); - PyErr_Clear(); - - /* use py style error */ - fprintf(stderr, "File \"%s\", line %d, in %s\n", - _PyUnicode_AsString(f_code->co_filename), - f_code->co_firstlineno, - _PyUnicode_AsString(((PyFunctionObject *)py_func)->func_name) - ); + /* since we return to C code we can't leave the error */ + PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func); + PyErr_Print(); + PyErr_Clear(); + + /* use py style error */ + fprintf(stderr, + "File \"%s\", line %d, in %s\n", + _PyUnicode_AsString(f_code->co_filename), + f_code->co_firstlineno, + _PyUnicode_AsString(((PyFunctionObject *)py_func)->func_name)); } - /* returns the exception string as a new PyUnicode object, depends on external traceback module */ -#if 0 +# if 0 /* this version uses traceback module but somehow fails on UI errors */ PyObject *PyC_ExceptionBuffer(void) { - PyObject *traceback_mod = NULL; - PyObject *format_tb_func = NULL; - PyObject *ret = NULL; + PyObject *traceback_mod = NULL; + PyObject *format_tb_func = NULL; + PyObject *ret = NULL; - if (!(traceback_mod = PyImport_ImportModule("traceback"))) { - goto error_cleanup; - } - else if (!(format_tb_func = PyObject_GetAttrString(traceback_mod, "format_exc"))) { - goto error_cleanup; - } + if (!(traceback_mod = PyImport_ImportModule("traceback"))) { + goto error_cleanup; + } + else if (!(format_tb_func = PyObject_GetAttrString(traceback_mod, "format_exc"))) { + goto error_cleanup; + } - ret = PyObject_CallObject(format_tb_func, NULL); + ret = PyObject_CallObject(format_tb_func, NULL); - if (ret == Py_None) { - Py_DECREF(ret); - ret = NULL; - } + if (ret == Py_None) { + Py_DECREF(ret); + ret = NULL; + } error_cleanup: - /* could not import the module so print the error and close */ - Py_XDECREF(traceback_mod); - Py_XDECREF(format_tb_func); + /* could not import the module so print the error and close */ + Py_XDECREF(traceback_mod); + Py_XDECREF(format_tb_func); - return ret; + return ret; } -#else /* verbose, non-threadsafe version */ +# else /* verbose, non-threadsafe version */ PyObject *PyC_ExceptionBuffer(void) { - PyObject *stdout_backup = PySys_GetObject("stdout"); /* borrowed */ - PyObject *stderr_backup = PySys_GetObject("stderr"); /* borrowed */ - PyObject *string_io = NULL; - PyObject *string_io_buf = NULL; - PyObject *string_io_mod = NULL; - PyObject *string_io_getvalue = NULL; - - PyObject *error_type, *error_value, *error_traceback; + PyObject *stdout_backup = PySys_GetObject("stdout"); /* borrowed */ + PyObject *stderr_backup = PySys_GetObject("stderr"); /* borrowed */ + PyObject *string_io = NULL; + PyObject *string_io_buf = NULL; + PyObject *string_io_mod = NULL; + PyObject *string_io_getvalue = NULL; - if (!PyErr_Occurred()) { - return NULL; - } + PyObject *error_type, *error_value, *error_traceback; - PyErr_Fetch(&error_type, &error_value, &error_traceback); + if (!PyErr_Occurred()) { + return NULL; + } - PyErr_Clear(); + PyErr_Fetch(&error_type, &error_value, &error_traceback); - /* import io - * string_io = io.StringIO() - */ + PyErr_Clear(); - if (!(string_io_mod = PyImport_ImportModule("io"))) { - goto error_cleanup; - } - else if (!(string_io = PyObject_CallMethod(string_io_mod, "StringIO", NULL))) { - goto error_cleanup; - } - else if (!(string_io_getvalue = PyObject_GetAttrString(string_io, "getvalue"))) { - goto error_cleanup; - } + /* import io + * string_io = io.StringIO() + */ - Py_INCREF(stdout_backup); // since these were borrowed we don't want them freed when replaced. - Py_INCREF(stderr_backup); + if (!(string_io_mod = PyImport_ImportModule("io"))) { + goto error_cleanup; + } + else if (!(string_io = PyObject_CallMethod(string_io_mod, "StringIO", NULL))) { + goto error_cleanup; + } + else if (!(string_io_getvalue = PyObject_GetAttrString(string_io, "getvalue"))) { + goto error_cleanup; + } - PySys_SetObject("stdout", string_io); // both of these are freed when restoring - PySys_SetObject("stderr", string_io); + Py_INCREF(stdout_backup); // since these were borrowed we don't want them freed when replaced. + Py_INCREF(stderr_backup); - PyErr_Restore(error_type, error_value, error_traceback); - PyErr_Print(); /* print the error */ - PyErr_Clear(); + PySys_SetObject("stdout", string_io); // both of these are freed when restoring + PySys_SetObject("stderr", string_io); - string_io_buf = PyObject_CallObject(string_io_getvalue, NULL); + PyErr_Restore(error_type, error_value, error_traceback); + PyErr_Print(); /* print the error */ + PyErr_Clear(); - PySys_SetObject("stdout", stdout_backup); - PySys_SetObject("stderr", stderr_backup); + string_io_buf = PyObject_CallObject(string_io_getvalue, NULL); - Py_DECREF(stdout_backup); /* now sys owns the ref again */ - Py_DECREF(stderr_backup); + PySys_SetObject("stdout", stdout_backup); + PySys_SetObject("stderr", stderr_backup); - Py_DECREF(string_io_mod); - Py_DECREF(string_io_getvalue); - Py_DECREF(string_io); /* free the original reference */ + Py_DECREF(stdout_backup); /* now sys owns the ref again */ + Py_DECREF(stderr_backup); - PyErr_Clear(); - return string_io_buf; + Py_DECREF(string_io_mod); + Py_DECREF(string_io_getvalue); + Py_DECREF(string_io); /* free the original reference */ + PyErr_Clear(); + return string_io_buf; error_cleanup: - /* could not import the module so print the error and close */ - Py_XDECREF(string_io_mod); - Py_XDECREF(string_io); + /* could not import the module so print the error and close */ + Py_XDECREF(string_io_mod); + Py_XDECREF(string_io); - PyErr_Restore(error_type, error_value, error_traceback); - PyErr_Print(); /* print the error */ - PyErr_Clear(); + PyErr_Restore(error_type, error_value, error_traceback); + PyErr_Print(); /* print the error */ + PyErr_Clear(); - return NULL; + return NULL; } -#endif +# endif PyObject *PyC_ExceptionBuffer_Simple(void) { - PyObject *string_io_buf; + PyObject *string_io_buf; - PyObject *error_type, *error_value, *error_traceback; + PyObject *error_type, *error_value, *error_traceback; - if (!PyErr_Occurred()) { - return NULL; - } + if (!PyErr_Occurred()) { + return NULL; + } - PyErr_Fetch(&error_type, &error_value, &error_traceback); + PyErr_Fetch(&error_type, &error_value, &error_traceback); - if (error_value == NULL) { - return NULL; - } + if (error_value == NULL) { + return NULL; + } - string_io_buf = PyObject_Str(error_value); - /* Python does this too */ - if (UNLIKELY(string_io_buf == NULL)) { - string_io_buf = PyUnicode_FromFormat( - "<unprintable %s object>", Py_TYPE(error_value)->tp_name); - } + string_io_buf = PyObject_Str(error_value); + /* Python does this too */ + if (UNLIKELY(string_io_buf == NULL)) { + string_io_buf = PyUnicode_FromFormat("<unprintable %s object>", Py_TYPE(error_value)->tp_name); + } - PyErr_Restore(error_type, error_value, error_traceback); + PyErr_Restore(error_type, error_value, error_traceback); - PyErr_Print(); - PyErr_Clear(); - return string_io_buf; + PyErr_Print(); + PyErr_Clear(); + return string_io_buf; } /* string conversion, escape non-unicode chars, coerce must be set to NULL */ const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce) { - const char *result; - - result = _PyUnicode_AsStringAndSize(py_str, size); - - if (result) { - /* 99% of the time this is enough but we better support non unicode - * chars since blender doesn't limit this */ - return result; - } - else { - PyErr_Clear(); - - if (PyBytes_Check(py_str)) { - *size = PyBytes_GET_SIZE(py_str); - return PyBytes_AS_STRING(py_str); - } - else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { - *size = PyBytes_GET_SIZE(*coerce); - return PyBytes_AS_STRING(*coerce); - } - else { - /* leave error raised from EncodeFS */ - return NULL; - } - } + const char *result; + + result = _PyUnicode_AsStringAndSize(py_str, size); + + if (result) { + /* 99% of the time this is enough but we better support non unicode + * chars since blender doesn't limit this */ + return result; + } + else { + PyErr_Clear(); + + if (PyBytes_Check(py_str)) { + *size = PyBytes_GET_SIZE(py_str); + return PyBytes_AS_STRING(py_str); + } + else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { + *size = PyBytes_GET_SIZE(*coerce); + return PyBytes_AS_STRING(*coerce); + } + else { + /* leave error raised from EncodeFS */ + return NULL; + } + } } const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) { - const char *result; - - result = _PyUnicode_AsString(py_str); - - if (result) { - /* 99% of the time this is enough but we better support non unicode - * chars since blender doesnt limit this */ - return result; - } - else { - PyErr_Clear(); - - if (PyBytes_Check(py_str)) { - return PyBytes_AS_STRING(py_str); - } - else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { - return PyBytes_AS_STRING(*coerce); - } - else { - /* leave error raised from EncodeFS */ - return NULL; - } - } + const char *result; + + result = _PyUnicode_AsString(py_str); + + if (result) { + /* 99% of the time this is enough but we better support non unicode + * chars since blender doesnt limit this */ + return result; + } + else { + PyErr_Clear(); + + if (PyBytes_Check(py_str)) { + return PyBytes_AS_STRING(py_str); + } + else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { + return PyBytes_AS_STRING(*coerce); + } + else { + /* leave error raised from EncodeFS */ + return NULL; + } + } } PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size) { - PyObject *result = PyUnicode_FromStringAndSize(str, size); - if (result) { - /* 99% of the time this is enough but we better support non unicode - * chars since blender doesn't limit this */ - return result; - } - else { - PyErr_Clear(); - /* this means paths will always be accessible once converted, on all OS's */ - result = PyUnicode_DecodeFSDefaultAndSize(str, size); - return result; - } + PyObject *result = PyUnicode_FromStringAndSize(str, size); + if (result) { + /* 99% of the time this is enough but we better support non unicode + * chars since blender doesn't limit this */ + return result; + } + else { + PyErr_Clear(); + /* this means paths will always be accessible once converted, on all OS's */ + result = PyUnicode_DecodeFSDefaultAndSize(str, size); + return result; + } } PyObject *PyC_UnicodeFromByte(const char *str) { - return PyC_UnicodeFromByteAndSize(str, strlen(str)); + return PyC_UnicodeFromByteAndSize(str, strlen(str)); } /***************************************************************************** @@ -717,107 +715,109 @@ PyObject *PyC_UnicodeFromByte(const char *str) ****************************************************************************/ PyObject *PyC_DefaultNameSpace(const char *filename) { - PyInterpreterState *interp = PyThreadState_GET()->interp; - PyObject *mod_main = PyModule_New("__main__"); - PyDict_SetItemString(interp->modules, "__main__", mod_main); - Py_DECREF(mod_main); /* sys.modules owns now */ - PyModule_AddStringConstant(mod_main, "__name__", "__main__"); - if (filename) { - /* __file__ mainly for nice UI'ness - * note: this wont map to a real file when executing text-blocks and buttons. */ - PyModule_AddObject(mod_main, "__file__", PyC_UnicodeFromByte(filename)); - } - PyModule_AddObject(mod_main, "__builtins__", interp->builtins); - Py_INCREF(interp->builtins); /* AddObject steals a reference */ - return PyModule_GetDict(mod_main); + PyInterpreterState *interp = PyThreadState_GET()->interp; + PyObject *mod_main = PyModule_New("__main__"); + PyDict_SetItemString(interp->modules, "__main__", mod_main); + Py_DECREF(mod_main); /* sys.modules owns now */ + PyModule_AddStringConstant(mod_main, "__name__", "__main__"); + if (filename) { + /* __file__ mainly for nice UI'ness + * note: this wont map to a real file when executing text-blocks and buttons. */ + PyModule_AddObject(mod_main, "__file__", PyC_UnicodeFromByte(filename)); + } + PyModule_AddObject(mod_main, "__builtins__", interp->builtins); + Py_INCREF(interp->builtins); /* AddObject steals a reference */ + return PyModule_GetDict(mod_main); } bool PyC_NameSpace_ImportArray(PyObject *py_dict, const char *imports[]) { - for (int i = 0; imports[i]; i++) { - PyObject *name = PyUnicode_FromString(imports[i]); - PyObject *mod = PyImport_ImportModuleLevelObject(name, NULL, NULL, 0, 0); - bool ok = false; - if (mod) { - PyDict_SetItem(py_dict, name, mod); - ok = true; - Py_DECREF(mod); - } - Py_DECREF(name); - - if (!ok) { - return false; - } - } - return true; + for (int i = 0; imports[i]; i++) { + PyObject *name = PyUnicode_FromString(imports[i]); + PyObject *mod = PyImport_ImportModuleLevelObject(name, NULL, NULL, 0, 0); + bool ok = false; + if (mod) { + PyDict_SetItem(py_dict, name, mod); + ok = true; + Py_DECREF(mod); + } + Py_DECREF(name); + + if (!ok) { + return false; + } + } + return true; } /* restore MUST be called after this */ void PyC_MainModule_Backup(PyObject **main_mod) { - PyInterpreterState *interp = PyThreadState_GET()->interp; - *main_mod = PyDict_GetItemString(interp->modules, "__main__"); - Py_XINCREF(*main_mod); /* don't free */ + PyInterpreterState *interp = PyThreadState_GET()->interp; + *main_mod = PyDict_GetItemString(interp->modules, "__main__"); + Py_XINCREF(*main_mod); /* don't free */ } void PyC_MainModule_Restore(PyObject *main_mod) { - PyInterpreterState *interp = PyThreadState_GET()->interp; - PyDict_SetItemString(interp->modules, "__main__", main_mod); - Py_XDECREF(main_mod); + PyInterpreterState *interp = PyThreadState_GET()->interp; + PyDict_SetItemString(interp->modules, "__main__", main_mod); + Py_XDECREF(main_mod); } /* must be called before Py_Initialize, expects output of BKE_appdir_folder_id(BLENDER_PYTHON, NULL) */ void PyC_SetHomePath(const char *py_path_bundle) { - if (py_path_bundle == NULL) { - /* Common enough to have bundled *nix python but complain on OSX/Win */ -#if defined(__APPLE__) || defined(_WIN32) - fprintf(stderr, "Warning! bundled python not found and is expected on this platform. " - "(if you built with CMake: 'install' target may have not been built)\n"); -#endif - return; - } - /* set the environment path */ - printf("found bundled python: %s\n", py_path_bundle); - -#ifdef __APPLE__ - /* OSX allow file/directory names to contain : character (represented as / in the Finder) - * but current Python lib (release 3.1.1) doesn't handle these correctly */ - if (strchr(py_path_bundle, ':')) { - printf("Warning : Blender application is located in a path containing : or / chars\ - \nThis may make python import function fail\n"); - } -#endif - - -#if 0 /* disable for now [#31506] - campbell */ -#ifdef _WIN32 - /* cmake/MSVC debug build crashes without this, why only - * in this case is unknown.. */ - { - /*BLI_setenv("PYTHONPATH", py_path_bundle)*/; - } -#endif -#endif - - { - static wchar_t py_path_bundle_wchar[1024]; - - /* cant use this, on linux gives bug: #23018, TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 22008 */ - /* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */ - - BLI_strncpy_wchar_from_utf8(py_path_bundle_wchar, py_path_bundle, ARRAY_SIZE(py_path_bundle_wchar)); - - Py_SetPythonHome(py_path_bundle_wchar); - // printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar); - } + if (py_path_bundle == NULL) { + /* Common enough to have bundled *nix python but complain on OSX/Win */ +# if defined(__APPLE__) || defined(_WIN32) + fprintf(stderr, + "Warning! bundled python not found and is expected on this platform. " + "(if you built with CMake: 'install' target may have not been built)\n"); +# endif + return; + } + /* set the environment path */ + printf("found bundled python: %s\n", py_path_bundle); + +# ifdef __APPLE__ + /* OSX allow file/directory names to contain : character (represented as / in the Finder) + * but current Python lib (release 3.1.1) doesn't handle these correctly */ + if (strchr(py_path_bundle, ':')) { + printf( + "Warning : Blender application is located in a path containing : or / chars\ + \nThis may make python import function fail\n"); + } +# endif + +# if 0 /* disable for now [#31506] - campbell */ +# ifdef _WIN32 + /* cmake/MSVC debug build crashes without this, why only + * in this case is unknown.. */ + { + /*BLI_setenv("PYTHONPATH", py_path_bundle)*/; + } +# endif +# endif + + { + static wchar_t py_path_bundle_wchar[1024]; + + /* cant use this, on linux gives bug: #23018, TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 22008 */ + /* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */ + + BLI_strncpy_wchar_from_utf8( + py_path_bundle_wchar, py_path_bundle, ARRAY_SIZE(py_path_bundle_wchar)); + + Py_SetPythonHome(py_path_bundle_wchar); + // printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar); + } } bool PyC_IsInterpreterActive(void) { - /* instead of PyThreadState_Get, which calls Py_FatalError */ - return (PyThreadState_GetDict() != NULL); + /* instead of PyThreadState_Get, which calls Py_FatalError */ + return (PyThreadState_GetDict() != NULL); } /* Would be nice if python had this built in @@ -825,433 +825,447 @@ bool PyC_IsInterpreterActive(void) */ void PyC_RunQuicky(const char *filepath, int n, ...) { - FILE *fp = fopen(filepath, "r"); - - if (fp) { - PyGILState_STATE gilstate = PyGILState_Ensure(); + FILE *fp = fopen(filepath, "r"); + + if (fp) { + PyGILState_STATE gilstate = PyGILState_Ensure(); - va_list vargs; + va_list vargs; - int *sizes = PyMem_MALLOC(sizeof(int) * (n / 2)); - int i; - - PyObject *py_dict = PyC_DefaultNameSpace(filepath); - PyObject *values = PyList_New(n / 2); /* namespace owns this, don't free */ - - PyObject *py_result, *ret; - - PyObject *struct_mod = PyImport_ImportModule("struct"); - PyObject *calcsize = PyObject_GetAttrString(struct_mod, "calcsize"); /* struct.calcsize */ - PyObject *pack = PyObject_GetAttrString(struct_mod, "pack"); /* struct.pack */ - PyObject *unpack = PyObject_GetAttrString(struct_mod, "unpack"); /* struct.unpack */ - - Py_DECREF(struct_mod); - - va_start(vargs, n); - for (i = 0; i * 2 < n; i++) { - const char *format = va_arg(vargs, char *); - void *ptr = va_arg(vargs, void *); - - ret = PyObject_CallFunction(calcsize, "s", format); - - if (ret) { - sizes[i] = PyLong_AsLong(ret); - Py_DECREF(ret); - ret = PyObject_CallFunction(unpack, "sy#", format, (char *)ptr, sizes[i]); - } - - if (ret == NULL) { - printf("%s error, line:%d\n", __func__, __LINE__); - PyErr_Print(); - PyErr_Clear(); - - PyList_SET_ITEM(values, i, Py_INCREF_RET(Py_None)); /* hold user */ - - sizes[i] = 0; - } - else { - if (PyTuple_GET_SIZE(ret) == 1) { - /* convenience, convert single tuples into single values */ - PyObject *tmp = PyTuple_GET_ITEM(ret, 0); - Py_INCREF(tmp); - Py_DECREF(ret); - ret = tmp; - } - - PyList_SET_ITEM(values, i, ret); /* hold user */ - } - } - va_end(vargs); - - /* set the value so we can access it */ - PyDict_SetItemString(py_dict, "values", values); - Py_DECREF(values); - - py_result = PyRun_File(fp, filepath, Py_file_input, py_dict, py_dict); - - fclose(fp); - - if (py_result) { - - /* we could skip this but then only slice assignment would work - * better not be so strict */ - values = PyDict_GetItemString(py_dict, "values"); - - if (values && PyList_Check(values)) { - - /* don't use the result */ - Py_DECREF(py_result); - py_result = NULL; - - /* now get the values back */ - va_start(vargs, n); - for (i = 0; i * 2 < n; i++) { - const char *format = va_arg(vargs, char *); - void *ptr = va_arg(vargs, void *); - - PyObject *item; - PyObject *item_new; - /* prepend the string formatting and remake the tuple */ - item = PyList_GET_ITEM(values, i); - if (PyTuple_CheckExact(item)) { - int ofs = PyTuple_GET_SIZE(item); - item_new = PyTuple_New(ofs + 1); - while (ofs--) { - PyObject *member = PyTuple_GET_ITEM(item, ofs); - PyTuple_SET_ITEM(item_new, ofs + 1, member); - Py_INCREF(member); - } - - PyTuple_SET_ITEM(item_new, 0, PyUnicode_FromString(format)); - } - else { - item_new = Py_BuildValue("sO", format, item); - } - - ret = PyObject_Call(pack, item_new, NULL); - - if (ret) { - /* copy the bytes back into memory */ - memcpy(ptr, PyBytes_AS_STRING(ret), sizes[i]); - Py_DECREF(ret); - } - else { - printf("%s error on arg '%d', line:%d\n", __func__, i, __LINE__); - PyC_ObSpit("failed converting:", item_new); - PyErr_Print(); - PyErr_Clear(); - } - - Py_DECREF(item_new); - } - va_end(vargs); - } - else { - printf("%s error, 'values' not a list, line:%d\n", __func__, __LINE__); - } - } - else { - printf("%s error line:%d\n", __func__, __LINE__); - PyErr_Print(); - PyErr_Clear(); - } - - Py_DECREF(calcsize); - Py_DECREF(pack); - Py_DECREF(unpack); - - PyMem_FREE(sizes); - - PyGILState_Release(gilstate); - } - else { - fprintf(stderr, "%s: '%s' missing\n", __func__, filepath); - } + int *sizes = PyMem_MALLOC(sizeof(int) * (n / 2)); + int i; + + PyObject *py_dict = PyC_DefaultNameSpace(filepath); + PyObject *values = PyList_New(n / 2); /* namespace owns this, don't free */ + + PyObject *py_result, *ret; + + PyObject *struct_mod = PyImport_ImportModule("struct"); + PyObject *calcsize = PyObject_GetAttrString(struct_mod, "calcsize"); /* struct.calcsize */ + PyObject *pack = PyObject_GetAttrString(struct_mod, "pack"); /* struct.pack */ + PyObject *unpack = PyObject_GetAttrString(struct_mod, "unpack"); /* struct.unpack */ + + Py_DECREF(struct_mod); + + va_start(vargs, n); + for (i = 0; i * 2 < n; i++) { + const char *format = va_arg(vargs, char *); + void *ptr = va_arg(vargs, void *); + + ret = PyObject_CallFunction(calcsize, "s", format); + + if (ret) { + sizes[i] = PyLong_AsLong(ret); + Py_DECREF(ret); + ret = PyObject_CallFunction(unpack, "sy#", format, (char *)ptr, sizes[i]); + } + + if (ret == NULL) { + printf("%s error, line:%d\n", __func__, __LINE__); + PyErr_Print(); + PyErr_Clear(); + + PyList_SET_ITEM(values, i, Py_INCREF_RET(Py_None)); /* hold user */ + + sizes[i] = 0; + } + else { + if (PyTuple_GET_SIZE(ret) == 1) { + /* convenience, convert single tuples into single values */ + PyObject *tmp = PyTuple_GET_ITEM(ret, 0); + Py_INCREF(tmp); + Py_DECREF(ret); + ret = tmp; + } + + PyList_SET_ITEM(values, i, ret); /* hold user */ + } + } + va_end(vargs); + + /* set the value so we can access it */ + PyDict_SetItemString(py_dict, "values", values); + Py_DECREF(values); + + py_result = PyRun_File(fp, filepath, Py_file_input, py_dict, py_dict); + + fclose(fp); + + if (py_result) { + + /* we could skip this but then only slice assignment would work + * better not be so strict */ + values = PyDict_GetItemString(py_dict, "values"); + + if (values && PyList_Check(values)) { + + /* don't use the result */ + Py_DECREF(py_result); + py_result = NULL; + + /* now get the values back */ + va_start(vargs, n); + for (i = 0; i * 2 < n; i++) { + const char *format = va_arg(vargs, char *); + void *ptr = va_arg(vargs, void *); + + PyObject *item; + PyObject *item_new; + /* prepend the string formatting and remake the tuple */ + item = PyList_GET_ITEM(values, i); + if (PyTuple_CheckExact(item)) { + int ofs = PyTuple_GET_SIZE(item); + item_new = PyTuple_New(ofs + 1); + while (ofs--) { + PyObject *member = PyTuple_GET_ITEM(item, ofs); + PyTuple_SET_ITEM(item_new, ofs + 1, member); + Py_INCREF(member); + } + + PyTuple_SET_ITEM(item_new, 0, PyUnicode_FromString(format)); + } + else { + item_new = Py_BuildValue("sO", format, item); + } + + ret = PyObject_Call(pack, item_new, NULL); + + if (ret) { + /* copy the bytes back into memory */ + memcpy(ptr, PyBytes_AS_STRING(ret), sizes[i]); + Py_DECREF(ret); + } + else { + printf("%s error on arg '%d', line:%d\n", __func__, i, __LINE__); + PyC_ObSpit("failed converting:", item_new); + PyErr_Print(); + PyErr_Clear(); + } + + Py_DECREF(item_new); + } + va_end(vargs); + } + else { + printf("%s error, 'values' not a list, line:%d\n", __func__, __LINE__); + } + } + else { + printf("%s error line:%d\n", __func__, __LINE__); + PyErr_Print(); + PyErr_Clear(); + } + + Py_DECREF(calcsize); + Py_DECREF(pack); + Py_DECREF(unpack); + + PyMem_FREE(sizes); + + PyGILState_Release(gilstate); + } + else { + fprintf(stderr, "%s: '%s' missing\n", __func__, filepath); + } } /* generic function to avoid depending on RNA */ void *PyC_RNA_AsPointer(PyObject *value, const char *type_name) { - PyObject *as_pointer; - PyObject *pointer; - - if (STREQ(Py_TYPE(value)->tp_name, type_name) && - (as_pointer = PyObject_GetAttrString(value, "as_pointer")) != NULL && - PyCallable_Check(as_pointer)) - { - void *result = NULL; - - /* must be a 'type_name' object */ - pointer = PyObject_CallObject(as_pointer, NULL); - Py_DECREF(as_pointer); - - if (!pointer) { - PyErr_SetString(PyExc_SystemError, "value.as_pointer() failed"); - return NULL; - } - result = PyLong_AsVoidPtr(pointer); - Py_DECREF(pointer); - if (!result) { - PyErr_SetString(PyExc_SystemError, "value.as_pointer() failed"); - } - - return result; - } - else { - PyErr_Format(PyExc_TypeError, - "expected '%.200s' type found '%.200s' instead", - type_name, Py_TYPE(value)->tp_name); - return NULL; - } + PyObject *as_pointer; + PyObject *pointer; + + if (STREQ(Py_TYPE(value)->tp_name, type_name) && + (as_pointer = PyObject_GetAttrString(value, "as_pointer")) != NULL && + PyCallable_Check(as_pointer)) { + void *result = NULL; + + /* must be a 'type_name' object */ + pointer = PyObject_CallObject(as_pointer, NULL); + Py_DECREF(as_pointer); + + if (!pointer) { + PyErr_SetString(PyExc_SystemError, "value.as_pointer() failed"); + return NULL; + } + result = PyLong_AsVoidPtr(pointer); + Py_DECREF(pointer); + if (!result) { + PyErr_SetString(PyExc_SystemError, "value.as_pointer() failed"); + } + + return result; + } + else { + PyErr_Format(PyExc_TypeError, + "expected '%.200s' type found '%.200s' instead", + type_name, + Py_TYPE(value)->tp_name); + return NULL; + } } - /* PyC_FlagSet_* functions - so flags/sets can be interchanged in a generic way */ -#include "BLI_dynstr.h" -#include "MEM_guardedalloc.h" +# include "BLI_dynstr.h" +# include "MEM_guardedalloc.h" char *PyC_FlagSet_AsString(PyC_FlagSet *item) { - DynStr *dynstr = BLI_dynstr_new(); - PyC_FlagSet *e; - char *cstring; + DynStr *dynstr = BLI_dynstr_new(); + PyC_FlagSet *e; + char *cstring; - for (e = item; item->identifier; item++) { - BLI_dynstr_appendf(dynstr, (e == item) ? "'%s'" : ", '%s'", item->identifier); - } + for (e = item; item->identifier; item++) { + BLI_dynstr_appendf(dynstr, (e == item) ? "'%s'" : ", '%s'", item->identifier); + } - cstring = BLI_dynstr_get_cstring(dynstr); - BLI_dynstr_free(dynstr); - return cstring; + cstring = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + return cstring; } int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value) { - for ( ; item->identifier; item++) { - if (STREQ(item->identifier, identifier)) { - *r_value = item->value; - return 1; - } - } - - return 0; + for (; item->identifier; item++) { + if (STREQ(item->identifier, identifier)) { + *r_value = item->value; + return 1; + } + } + + return 0; } -int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *identifier, int *r_value, const char *error_prefix) +int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, + const char *identifier, + int *r_value, + const char *error_prefix) { - if (PyC_FlagSet_ValueFromID_int(item, identifier, r_value) == 0) { - const char *enum_str = PyC_FlagSet_AsString(item); - PyErr_Format(PyExc_ValueError, - "%s: '%.200s' not found in (%s)", - error_prefix, identifier, enum_str); - MEM_freeN((void *)enum_str); - return -1; - } - - return 0; + if (PyC_FlagSet_ValueFromID_int(item, identifier, r_value) == 0) { + const char *enum_str = PyC_FlagSet_AsString(item); + PyErr_Format( + PyExc_ValueError, "%s: '%.200s' not found in (%s)", error_prefix, identifier, enum_str); + MEM_freeN((void *)enum_str); + return -1; + } + + return 0; } -int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix) +int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, + PyObject *value, + int *r_value, + const char *error_prefix) { - /* set of enum items, concatenate all values with OR */ - int ret, flag = 0; - - /* set looping */ - Py_ssize_t pos = 0; - Py_ssize_t hash = 0; - PyObject *key; - - if (!PySet_Check(value)) { - PyErr_Format(PyExc_TypeError, - "%.200s expected a set, not %.200s", - error_prefix, Py_TYPE(value)->tp_name); - return -1; - } - - *r_value = 0; - - while (_PySet_NextEntry(value, &pos, &key, &hash)) { - const char *param = _PyUnicode_AsString(key); - - if (param == NULL) { - PyErr_Format(PyExc_TypeError, - "%.200s set must contain strings, not %.200s", - error_prefix, Py_TYPE(key)->tp_name); - return -1; - } - - if (PyC_FlagSet_ValueFromID(items, param, &ret, error_prefix) < 0) { - return -1; - } - - flag |= ret; - } - - *r_value = flag; - return 0; + /* set of enum items, concatenate all values with OR */ + int ret, flag = 0; + + /* set looping */ + Py_ssize_t pos = 0; + Py_ssize_t hash = 0; + PyObject *key; + + if (!PySet_Check(value)) { + PyErr_Format(PyExc_TypeError, + "%.200s expected a set, not %.200s", + error_prefix, + Py_TYPE(value)->tp_name); + return -1; + } + + *r_value = 0; + + while (_PySet_NextEntry(value, &pos, &key, &hash)) { + const char *param = _PyUnicode_AsString(key); + + if (param == NULL) { + PyErr_Format(PyExc_TypeError, + "%.200s set must contain strings, not %.200s", + error_prefix, + Py_TYPE(key)->tp_name); + return -1; + } + + if (PyC_FlagSet_ValueFromID(items, param, &ret, error_prefix) < 0) { + return -1; + } + + flag |= ret; + } + + *r_value = flag; + return 0; } PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag) { - PyObject *ret = PySet_New(NULL); - PyObject *pystr; - - for ( ; items->identifier; items++) { - if (items->value & flag) { - pystr = PyUnicode_FromString(items->identifier); - PySet_Add(ret, pystr); - Py_DECREF(pystr); - } - } - - return ret; + PyObject *ret = PySet_New(NULL); + PyObject *pystr; + + for (; items->identifier; items++) { + if (items->value & flag) { + pystr = PyUnicode_FromString(items->identifier); + PySet_Add(ret, pystr); + Py_DECREF(pystr); + } + } + + return ret; } - /** * \return success * * \note it is caller's responsibility to acquire & release GIL! */ -bool PyC_RunString_AsNumber(const char *imports[], const char *expr, const char *filename, double *r_value) +bool PyC_RunString_AsNumber(const char *imports[], + const char *expr, + const char *filename, + double *r_value) { - PyObject *py_dict, *mod, *retval; - bool ok = true; - PyObject *main_mod = NULL; - - PyC_MainModule_Backup(&main_mod); - - py_dict = PyC_DefaultNameSpace(filename); - - mod = PyImport_ImportModule("math"); - if (mod) { - PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - don't overwrite existing values */ - Py_DECREF(mod); - } - else { /* highly unlikely but possibly */ - PyErr_Print(); - PyErr_Clear(); - } - - if (imports && (!PyC_NameSpace_ImportArray(py_dict, imports))) { - ok = false; - } - else if ((retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict)) == NULL) { - ok = false; - } - else { - double val; - - if (PyTuple_Check(retval)) { - /* Users my have typed in 10km, 2m - * add up all values */ - int i; - val = 0.0; - - for (i = 0; i < PyTuple_GET_SIZE(retval); i++) { - const double val_item = PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i)); - if (val_item == -1 && PyErr_Occurred()) { - val = -1; - break; - } - val += val_item; - } - } - else { - val = PyFloat_AsDouble(retval); - } - Py_DECREF(retval); - - if (val == -1 && PyErr_Occurred()) { - ok = false; - } - else if (!isfinite(val)) { - *r_value = 0.0; - } - else { - *r_value = val; - } - } - - PyC_MainModule_Restore(main_mod); - - return ok; + PyObject *py_dict, *mod, *retval; + bool ok = true; + PyObject *main_mod = NULL; + + PyC_MainModule_Backup(&main_mod); + + py_dict = PyC_DefaultNameSpace(filename); + + mod = PyImport_ImportModule("math"); + if (mod) { + PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - don't overwrite existing values */ + Py_DECREF(mod); + } + else { /* highly unlikely but possibly */ + PyErr_Print(); + PyErr_Clear(); + } + + if (imports && (!PyC_NameSpace_ImportArray(py_dict, imports))) { + ok = false; + } + else if ((retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict)) == NULL) { + ok = false; + } + else { + double val; + + if (PyTuple_Check(retval)) { + /* Users my have typed in 10km, 2m + * add up all values */ + int i; + val = 0.0; + + for (i = 0; i < PyTuple_GET_SIZE(retval); i++) { + const double val_item = PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i)); + if (val_item == -1 && PyErr_Occurred()) { + val = -1; + break; + } + val += val_item; + } + } + else { + val = PyFloat_AsDouble(retval); + } + Py_DECREF(retval); + + if (val == -1 && PyErr_Occurred()) { + ok = false; + } + else if (!isfinite(val)) { + *r_value = 0.0; + } + else { + *r_value = val; + } + } + + PyC_MainModule_Restore(main_mod); + + return ok; } -bool PyC_RunString_AsIntPtr(const char *imports[], const char *expr, const char *filename, intptr_t *r_value) +bool PyC_RunString_AsIntPtr(const char *imports[], + const char *expr, + const char *filename, + intptr_t *r_value) { - PyObject *py_dict, *retval; - bool ok = true; - PyObject *main_mod = NULL; + PyObject *py_dict, *retval; + bool ok = true; + PyObject *main_mod = NULL; - PyC_MainModule_Backup(&main_mod); + PyC_MainModule_Backup(&main_mod); - py_dict = PyC_DefaultNameSpace(filename); + py_dict = PyC_DefaultNameSpace(filename); - if (imports && (!PyC_NameSpace_ImportArray(py_dict, imports))) { - ok = false; - } - else if ((retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict)) == NULL) { - ok = false; - } - else { - intptr_t val; + if (imports && (!PyC_NameSpace_ImportArray(py_dict, imports))) { + ok = false; + } + else if ((retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict)) == NULL) { + ok = false; + } + else { + intptr_t val; - val = (intptr_t)PyLong_AsVoidPtr(retval); - if (val == 0 && PyErr_Occurred()) { - ok = false; - } - else { - *r_value = val; - } + val = (intptr_t)PyLong_AsVoidPtr(retval); + if (val == 0 && PyErr_Occurred()) { + ok = false; + } + else { + *r_value = val; + } - Py_DECREF(retval); - } + Py_DECREF(retval); + } - PyC_MainModule_Restore(main_mod); + PyC_MainModule_Restore(main_mod); - return ok; + return ok; } -bool PyC_RunString_AsString(const char *imports[], const char *expr, const char *filename, char **r_value) +bool PyC_RunString_AsString(const char *imports[], + const char *expr, + const char *filename, + char **r_value) { - PyObject *py_dict, *retval; - bool ok = true; - PyObject *main_mod = NULL; - - PyC_MainModule_Backup(&main_mod); - - py_dict = PyC_DefaultNameSpace(filename); - - if (imports && (!PyC_NameSpace_ImportArray(py_dict, imports))) { - ok = false; - } - else if ((retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict)) == NULL) { - ok = false; - } - else { - const char *val; - Py_ssize_t val_len; - - val = _PyUnicode_AsStringAndSize(retval, &val_len); - if (val == NULL && PyErr_Occurred()) { - ok = false; - } - else { - char *val_alloc = MEM_mallocN(val_len + 1, __func__); - memcpy(val_alloc, val, val_len + 1); - *r_value = val_alloc; - } - - Py_DECREF(retval); - } - - PyC_MainModule_Restore(main_mod); - - return ok; + PyObject *py_dict, *retval; + bool ok = true; + PyObject *main_mod = NULL; + + PyC_MainModule_Backup(&main_mod); + + py_dict = PyC_DefaultNameSpace(filename); + + if (imports && (!PyC_NameSpace_ImportArray(py_dict, imports))) { + ok = false; + } + else if ((retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict)) == NULL) { + ok = false; + } + else { + const char *val; + Py_ssize_t val_len; + + val = _PyUnicode_AsStringAndSize(retval, &val_len); + if (val == NULL && PyErr_Occurred()) { + ok = false; + } + else { + char *val_alloc = MEM_mallocN(val_len + 1, __func__); + memcpy(val_alloc, val, val_len + 1); + *r_value = val_alloc; + } + + Py_DECREF(retval); + } + + PyC_MainModule_Restore(main_mod); + + return ok; } -#endif /* #ifndef MATH_STANDALONE */ +#endif /* #ifndef MATH_STANDALONE */ /* -------------------------------------------------------------------- */ /** \name Int Conversion @@ -1271,35 +1285,32 @@ bool PyC_RunString_AsString(const char *imports[], const char *expr, const char */ int PyC_Long_AsBool(PyObject *value) { - int test = _PyLong_AsInt(value); - if (UNLIKELY((uint)test > 1)) { - PyErr_SetString(PyExc_TypeError, - "Python number not a bool (0/1)"); - return -1; - } - return test; + int test = _PyLong_AsInt(value); + if (UNLIKELY((uint)test > 1)) { + PyErr_SetString(PyExc_TypeError, "Python number not a bool (0/1)"); + return -1; + } + return test; } int8_t PyC_Long_AsI8(PyObject *value) { - int test = _PyLong_AsInt(value); - if (UNLIKELY(test < INT8_MIN || test > INT8_MAX)) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to C int8"); - return -1; - } - return (int8_t)test; + int test = _PyLong_AsInt(value); + if (UNLIKELY(test < INT8_MIN || test > INT8_MAX)) { + PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C int8"); + return -1; + } + return (int8_t)test; } int16_t PyC_Long_AsI16(PyObject *value) { - int test = _PyLong_AsInt(value); - if (UNLIKELY(test < INT16_MIN || test > INT16_MAX)) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to C int16"); - return -1; - } - return (int16_t)test; + int test = _PyLong_AsInt(value); + if (UNLIKELY(test < INT16_MIN || test > INT16_MAX)) { + PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C int16"); + return -1; + } + return (int16_t)test; } /* Inlined in header: @@ -1309,35 +1320,32 @@ int16_t PyC_Long_AsI16(PyObject *value) uint8_t PyC_Long_AsU8(PyObject *value) { - ulong test = PyLong_AsUnsignedLong(value); - if (UNLIKELY(test > UINT8_MAX)) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to C uint8"); - return (uint8_t)-1; - } - return (uint8_t)test; + ulong test = PyLong_AsUnsignedLong(value); + if (UNLIKELY(test > UINT8_MAX)) { + PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint8"); + return (uint8_t)-1; + } + return (uint8_t)test; } uint16_t PyC_Long_AsU16(PyObject *value) { - ulong test = PyLong_AsUnsignedLong(value); - if (UNLIKELY(test > UINT16_MAX)) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to C uint16"); - return (uint16_t)-1; - } - return (uint16_t)test; + ulong test = PyLong_AsUnsignedLong(value); + if (UNLIKELY(test > UINT16_MAX)) { + PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint16"); + return (uint16_t)-1; + } + return (uint16_t)test; } uint32_t PyC_Long_AsU32(PyObject *value) { - ulong test = PyLong_AsUnsignedLong(value); - if (UNLIKELY(test > UINT32_MAX)) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to C uint32"); - return (uint32_t)-1; - } - return (uint32_t)test; + ulong test = PyLong_AsUnsignedLong(value); + if (UNLIKELY(test > UINT32_MAX)) { + PyErr_SetString(PyExc_OverflowError, "Python int too large to convert to C uint32"); + return (uint32_t)-1; + } + return (uint32_t)test; } /* Inlined in header: @@ -1351,72 +1359,72 @@ uint32_t PyC_Long_AsU32(PyObject *value) char PyC_StructFmt_type_from_str(const char *typestr) { - switch (typestr[0]) { - case '!': - case '<': - case '=': - case '>': - case '@': - return typestr[1]; - default: - return typestr[0]; - } + switch (typestr[0]) { + case '!': + case '<': + case '=': + case '>': + case '@': + return typestr[1]; + default: + return typestr[0]; + } } bool PyC_StructFmt_type_is_float_any(char format) { - switch (format) { - case 'f': - case 'd': - case 'e': - return true; - default: - return false; - } + switch (format) { + case 'f': + case 'd': + case 'e': + return true; + default: + return false; + } } bool PyC_StructFmt_type_is_int_any(char format) { - switch (format) { - case 'i': - case 'I': - case 'l': - case 'L': - case 'h': - case 'H': - case 'b': - case 'B': - case 'q': - case 'Q': - case 'n': - case 'N': - case 'P': - return true; - default: - return false; - } + switch (format) { + case 'i': + case 'I': + case 'l': + case 'L': + case 'h': + case 'H': + case 'b': + case 'B': + case 'q': + case 'Q': + case 'n': + case 'N': + case 'P': + return true; + default: + return false; + } } bool PyC_StructFmt_type_is_byte(char format) { - switch (format) { - case 'c': - case 's': - case 'p': - return true; - default: - return false; - } + switch (format) { + case 'c': + case 's': + case 'p': + return true; + default: + return false; + } } bool PyC_StructFmt_type_is_bool(char format) { - switch (format) { - case '?': - return true; - default: - return false; - } + switch (format) { + case '?': + return true; + default: + return false; + } } /** \} */ diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 76c28e4a6f5..4454aa11d77 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -24,10 +24,10 @@ #include "BLI_sys_types.h" #include "BLI_utildefines_variadic.h" -void PyC_ObSpit(const char *name, PyObject *var); -void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var); -void PyC_LineSpit(void); -void PyC_StackSpit(void); +void PyC_ObSpit(const char *name, PyObject *var); +void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var); +void PyC_LineSpit(void); +void PyC_StackSpit(void); PyObject *PyC_ExceptionBuffer(void); PyObject *PyC_ExceptionBuffer_Simple(void); PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...); @@ -36,40 +36,46 @@ PyObject *PyC_FrozenSetFromStrings(const char **strings); PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...); PyObject *PyC_Err_SetString_Prefix(PyObject *exception_type_prefix, const char *str); -void PyC_Err_PrintWithFunc(PyObject *py_func); - -void PyC_FileAndNum(const char **filename, int *lineno); -void PyC_FileAndNum_Safe(const char **filename, int *lineno); /* checks python is running */ -int PyC_AsArray_FAST( - void *array, PyObject *value_fast, const Py_ssize_t length, - const PyTypeObject *type, const bool is_double, const char *error_prefix); -int PyC_AsArray( - void *array, PyObject *value, const Py_ssize_t length, - const PyTypeObject *type, const bool is_double, const char *error_prefix); - -PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len); -PyObject *PyC_Tuple_PackArray_F64(const double *array, uint len); -PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len); -PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len); -PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len); +void PyC_Err_PrintWithFunc(PyObject *py_func); + +void PyC_FileAndNum(const char **filename, int *lineno); +void PyC_FileAndNum_Safe(const char **filename, int *lineno); /* checks python is running */ +int PyC_AsArray_FAST(void *array, + PyObject *value_fast, + const Py_ssize_t length, + const PyTypeObject *type, + const bool is_double, + const char *error_prefix); +int PyC_AsArray(void *array, + PyObject *value, + const Py_ssize_t length, + const PyTypeObject *type, + const bool is_double, + const char *error_prefix); + +PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len); +PyObject *PyC_Tuple_PackArray_F64(const double *array, uint len); +PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len); +PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len); +PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len); #define PyC_Tuple_Pack_F32(...) \ - PyC_Tuple_PackArray_F32(((const float []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) + PyC_Tuple_PackArray_F32(((const float[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) #define PyC_Tuple_Pack_F64(...) \ - PyC_Tuple_PackArray_F64(((const double []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) + PyC_Tuple_PackArray_F64(((const double[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) #define PyC_Tuple_Pack_I32(...) \ - PyC_Tuple_PackArray_I32(((const int []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) + PyC_Tuple_PackArray_I32(((const int[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) #define PyC_Tuple_Pack_I32FromBool(...) \ - PyC_Tuple_PackArray_I32FromBool(((const int []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) + PyC_Tuple_PackArray_I32FromBool(((const int[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) #define PyC_Tuple_Pack_Bool(...) \ - PyC_Tuple_PackArray_Bool(((const bool []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) + PyC_Tuple_PackArray_Bool(((const bool[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) -void PyC_Tuple_Fill(PyObject *tuple, PyObject *value); -void PyC_List_Fill(PyObject *list, PyObject *value); +void PyC_Tuple_Fill(PyObject *tuple, PyObject *value); +void PyC_List_Fill(PyObject *list, PyObject *value); /* follow http://www.python.org/dev/peps/pep-0383/ */ -PyObject *PyC_UnicodeFromByte(const char *str); -PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size); +PyObject *PyC_UnicodeFromByte(const char *str); +PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size); const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */ const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce); @@ -89,34 +95,49 @@ void *PyC_RNA_AsPointer(PyObject *value, const char *type_name); /* flag / set --- interchange */ typedef struct PyC_FlagSet { - int value; - const char *identifier; + int value; + const char *identifier; } PyC_FlagSet; -char *PyC_FlagSet_AsString(PyC_FlagSet *item); -int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value); -int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *identifier, int *r_value, const char *error_prefix); -int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix); +char *PyC_FlagSet_AsString(PyC_FlagSet *item); +int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value); +int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, + const char *identifier, + int *r_value, + const char *error_prefix); +int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, + PyObject *value, + int *r_value, + const char *error_prefix); PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag); -bool PyC_RunString_AsNumber(const char **imports, const char *expr, const char *filename, double *r_value); -bool PyC_RunString_AsIntPtr(const char **imports, const char *expr, const char *filename, intptr_t *r_value); -bool PyC_RunString_AsString(const char **imports, const char *expr, const char *filename, char **r_value); +bool PyC_RunString_AsNumber(const char **imports, + const char *expr, + const char *filename, + double *r_value); +bool PyC_RunString_AsIntPtr(const char **imports, + const char *expr, + const char *filename, + intptr_t *r_value); +bool PyC_RunString_AsString(const char **imports, + const char *expr, + const char *filename, + char **r_value); int PyC_ParseBool(PyObject *o, void *p); int PyC_CheckArgs_DeepCopy(PyObject *args); /* Integer parsing (with overflow checks), -1 on error. */ -int PyC_Long_AsBool(PyObject *value); -int8_t PyC_Long_AsI8(PyObject *value); +int PyC_Long_AsBool(PyObject *value); +int8_t PyC_Long_AsI8(PyObject *value); int16_t PyC_Long_AsI16(PyObject *value); #if 0 /* inline */ int32_t PyC_Long_AsI32(PyObject *value); int64_t PyC_Long_AsI64(PyObject *value); #endif -uint8_t PyC_Long_AsU8(PyObject *value); +uint8_t PyC_Long_AsU8(PyObject *value); uint16_t PyC_Long_AsU16(PyObject *value); uint32_t PyC_Long_AsU32(PyObject *value); #if 0 /* inline */ @@ -124,9 +145,18 @@ uint64_t PyC_Long_AsU64(PyObject *value); #endif /* inline so type signatures match as expected */ -Py_LOCAL_INLINE(int32_t) PyC_Long_AsI32(PyObject *value) { return (int32_t)_PyLong_AsInt(value); } -Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value) { return (int64_t)PyLong_AsLongLong(value); } -Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value) { return (uint64_t)PyLong_AsUnsignedLongLong(value); } +Py_LOCAL_INLINE(int32_t) PyC_Long_AsI32(PyObject *value) +{ + return (int32_t)_PyLong_AsInt(value); +} +Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value) +{ + return (int64_t)PyLong_AsLongLong(value); +} +Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value) +{ + return (uint64_t)PyLong_AsUnsignedLongLong(value); +} /* utils for format string in `struct` module style syntax */ char PyC_StructFmt_type_from_str(const char *typestr); @@ -135,4 +165,4 @@ bool PyC_StructFmt_type_is_int_any(char format); bool PyC_StructFmt_type_is_byte(char format); bool PyC_StructFmt_type_is_bool(char format); -#endif /* __PY_CAPI_UTILS_H__ */ +#endif /* __PY_CAPI_UTILS_H__ */ diff --git a/source/blender/python/generic/python_utildefines.h b/source/blender/python/generic/python_utildefines.h index 70840e5ce34..40cec436dea 100644 --- a/source/blender/python/generic/python_utildefines.h +++ b/source/blender/python/generic/python_utildefines.h @@ -28,28 +28,33 @@ extern "C" { #endif #define PyTuple_SET_ITEMS(op_arg, ...) \ -{ \ - PyTupleObject *op = (PyTupleObject *)op_arg; \ - PyObject **ob_items = op->ob_item; \ - CHECK_TYPE_ANY(op_arg, PyObject *, PyTupleObject *); \ - BLI_assert(VA_NARGS_COUNT(__VA_ARGS__) == PyTuple_GET_SIZE(op)); \ - ARRAY_SET_ITEMS(ob_items, __VA_ARGS__); \ -} (void)0 + { \ + PyTupleObject *op = (PyTupleObject *)op_arg; \ + PyObject **ob_items = op->ob_item; \ + CHECK_TYPE_ANY(op_arg, PyObject *, PyTupleObject *); \ + BLI_assert(VA_NARGS_COUNT(__VA_ARGS__) == PyTuple_GET_SIZE(op)); \ + ARRAY_SET_ITEMS(ob_items, __VA_ARGS__); \ + } \ + (void)0 /* wrap Py_INCREF & return the result, * use sparingly to avoid comma operator or temp var assignment */ -Py_LOCAL_INLINE(PyObject *)Py_INCREF_RET(PyObject *op) { Py_INCREF(op); return op; } +Py_LOCAL_INLINE(PyObject *) Py_INCREF_RET(PyObject *op) +{ + Py_INCREF(op); + return op; +} /* append & transfer ownership to the list, avoids inline Py_DECREF all over (which is quite a large macro) */ Py_LOCAL_INLINE(int) PyList_APPEND(PyObject *op, PyObject *v) { - int ret = PyList_Append(op, v); - Py_DecRef(v); - return ret; + int ret = PyList_Append(op, v); + Py_DecRef(v); + return ret; } #ifdef __cplusplus } #endif -#endif /* __PYTHON_UTILDEFINES_H__ */ +#endif /* __PYTHON_UTILDEFINES_H__ */ |