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