Blender  V2.93
bpy_app_opensubdiv.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_utildefines.h"
22 #include <Python.h>
23 
24 #include "bpy_app_opensubdiv.h"
25 
26 #include "../generic/py_capi_utils.h"
27 
28 #ifdef WITH_OPENSUBDIV
29 # include "opensubdiv_capi.h"
30 #endif
31 
32 static PyTypeObject BlenderAppOpenSubdivType;
33 
34 static PyStructSequence_Field app_opensubdiv_info_fields[] = {
35  {"supported", "Boolean, True when Blender is built with OpenSubdiv support"},
36  {"version", "The OpenSubdiv version as a tuple of 3 numbers"},
37  {"version_string", "The OpenSubdiv version formatted as a string"},
38  {NULL},
39 };
40 
41 static PyStructSequence_Desc app_opensubdiv_info_desc = {
42  "bpy.app.opensubdiv", /* name */
43  "This module contains information about OpenSubdiv blender is linked against", /* doc */
44  app_opensubdiv_info_fields, /* fields */
46 };
47 
48 static PyObject *make_opensubdiv_info(void)
49 {
50  PyObject *opensubdiv_info;
51  int pos = 0;
52 
53  opensubdiv_info = PyStructSequence_New(&BlenderAppOpenSubdivType);
54  if (opensubdiv_info == NULL) {
55  return NULL;
56  }
57 
58 #ifndef WITH_OPENSUBDIV
59 # define SetStrItem(str) \
60  PyStructSequence_SET_ITEM(opensubdiv_info, pos++, PyUnicode_FromString(str))
61 #endif
62 
63 #define SetObjItem(obj) PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
64 
65 #ifdef WITH_OPENSUBDIV
66  const int curversion = openSubdiv_getVersionHex();
67  SetObjItem(PyBool_FromLong(1));
68  SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
69  SetObjItem(PyUnicode_FromFormat(
70  "%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
71 #else
72  SetObjItem(PyBool_FromLong(0));
74  SetStrItem("Unknown");
75 #endif
76 
77  if (UNLIKELY(PyErr_Occurred())) {
78  Py_DECREF(opensubdiv_info);
79  return NULL;
80  }
81 
82 #undef SetStrItem
83 #undef SetObjItem
84 
85  return opensubdiv_info;
86 }
87 
89 {
90  PyObject *ret;
91 
92  PyStructSequence_InitType(&BlenderAppOpenSubdivType, &app_opensubdiv_info_desc);
93 
95 
96  /* prevent user from creating new instances */
99  /* without this we can't do set(sys.modules) T29635. */
100  BlenderAppOpenSubdivType.tp_hash = (hashfunc)_Py_HashPointer;
101 
102  return ret;
103 }
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
PyObject * BPY_app_opensubdiv_struct(void)
static PyStructSequence_Field app_opensubdiv_info_fields[]
static PyStructSequence_Desc app_opensubdiv_info_desc
static PyTypeObject BlenderAppOpenSubdivType
#define SetStrItem(str)
#define SetObjItem(obj)
static PyObject * make_opensubdiv_info(void)
uint pos
int openSubdiv_getVersionHex(void)
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:67
return ret