Blender  V3.3
bpy_app_opensubdiv.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_utildefines.h"
8 #include <Python.h>
9 
10 #include "bpy_app_opensubdiv.h"
11 
12 #include "../generic/py_capi_utils.h"
13 
14 #ifdef WITH_OPENSUBDIV
15 # include "opensubdiv_capi.h"
16 #endif
17 
18 static PyTypeObject BlenderAppOpenSubdivType;
19 
20 static PyStructSequence_Field app_opensubdiv_info_fields[] = {
21  {"supported", "Boolean, True when Blender is built with OpenSubdiv support"},
22  {"version", "The OpenSubdiv version as a tuple of 3 numbers"},
23  {"version_string", "The OpenSubdiv version formatted as a string"},
24  {NULL},
25 };
26 
27 static PyStructSequence_Desc app_opensubdiv_info_desc = {
28  "bpy.app.opensubdiv", /* name */
29  "This module contains information about OpenSubdiv blender is linked against", /* doc */
30  app_opensubdiv_info_fields, /* fields */
32 };
33 
34 static PyObject *make_opensubdiv_info(void)
35 {
36  PyObject *opensubdiv_info;
37  int pos = 0;
38 
39  opensubdiv_info = PyStructSequence_New(&BlenderAppOpenSubdivType);
40  if (opensubdiv_info == NULL) {
41  return NULL;
42  }
43 
44 #ifndef WITH_OPENSUBDIV
45 # define SetStrItem(str) \
46  PyStructSequence_SET_ITEM(opensubdiv_info, pos++, PyUnicode_FromString(str))
47 #endif
48 
49 #define SetObjItem(obj) PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
50 
51 #ifdef WITH_OPENSUBDIV
52  const int curversion = openSubdiv_getVersionHex();
53  SetObjItem(PyBool_FromLong(1));
54  SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
55  SetObjItem(PyUnicode_FromFormat(
56  "%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
57 #else
58  SetObjItem(PyBool_FromLong(0));
60  SetStrItem("Unknown");
61 #endif
62 
63  if (UNLIKELY(PyErr_Occurred())) {
64  Py_DECREF(opensubdiv_info);
65  return NULL;
66  }
67 
68 #undef SetStrItem
69 #undef SetObjItem
70 
71  return opensubdiv_info;
72 }
73 
75 {
76  PyObject *ret;
77 
78  PyStructSequence_InitType(&BlenderAppOpenSubdivType, &app_opensubdiv_info_desc);
79 
81 
82  /* prevent user from creating new instances */
85  /* without this we can't do set(sys.modules) T29635. */
86  BlenderAppOpenSubdivType.tp_hash = (hashfunc)_Py_HashPointer;
87 
88  return ret;
89 }
#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()
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:88
return ret