Blender V5.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
8
9#include "BLI_utildefines.hh"
10#include <Python.h>
11
12#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
13
14#include "bpy_app_opensubdiv.hh"
15
17
18#ifdef WITH_OPENSUBDIV
19# include "opensubdiv_capi.hh"
20#endif
21
22namespace blender {
23
24static PyTypeObject BlenderAppOpenSubdivType;
25
26static PyStructSequence_Field app_opensubdiv_info_fields[] = {
27 {"supported", "Boolean, True when Blender is built with OpenSubdiv support"},
28 {"version", "The OpenSubdiv version as a tuple of 3 numbers"},
29 {"version_string", "The OpenSubdiv version formatted as a string"},
30 {nullptr},
31};
32
33static PyStructSequence_Desc app_opensubdiv_info_desc = {
34 /*name*/ "bpy.app.opensubdiv",
35 /*doc*/ "This module contains information about OpenSubdiv blender is linked against",
37 /*n_in_sequence*/ ARRAY_SIZE(app_opensubdiv_info_fields) - 1,
38};
39
40static PyObject *make_opensubdiv_info()
41{
42 PyObject *opensubdiv_info;
43 int pos = 0;
44
45 opensubdiv_info = PyStructSequence_New(&BlenderAppOpenSubdivType);
46 if (opensubdiv_info == nullptr) {
47 return nullptr;
48 }
49
50#ifndef WITH_OPENSUBDIV
51# define SetStrItem(str) \
52 PyStructSequence_SET_ITEM(opensubdiv_info, pos++, PyUnicode_FromString(str))
53#endif
54
55#define SetObjItem(obj) PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
56
57#ifdef WITH_OPENSUBDIV
58 const int curversion = openSubdiv_getVersionHex();
59 SetObjItem(PyBool_FromLong(1));
60 SetObjItem(PyC_Tuple_Pack_I32({curversion / 10000, (curversion / 100) % 100, curversion % 100}));
61 SetObjItem(PyUnicode_FromFormat(
62 "%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
63#else
64 SetObjItem(PyBool_FromLong(0));
66 SetStrItem("Unknown");
67#endif
68
69 if (PyErr_Occurred()) [[unlikely]] {
70 Py_DECREF(opensubdiv_info);
71 return nullptr;
72 }
73
74#undef SetStrItem
75#undef SetObjItem
76
77 return opensubdiv_info;
78}
79
81{
82 PyObject *ret;
83
84 PyStructSequence_InitType(&BlenderAppOpenSubdivType, &app_opensubdiv_info_desc);
85
87
88 /* prevent user from creating new instances */
89 BlenderAppOpenSubdivType.tp_init = nullptr;
90 BlenderAppOpenSubdivType.tp_new = nullptr;
91 /* Without this we can't do `set(sys.modules)` #29635. */
92 BlenderAppOpenSubdivType.tp_hash = reinterpret_cast<hashfunc>(Py_HashPointer);
93
94 return ret;
95}
96
97} // namespace blender
#define SetStrItem(str)
#define SetObjItem(obj)
BMesh Iterators.
static PyTypeObject BlenderAppOpenSubdivType
PyObject * PyC_Tuple_Pack_I32(const Span< int > values)
static PyStructSequence_Desc app_opensubdiv_info_desc
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
PyObject * BPY_app_opensubdiv_struct()
static PyStructSequence_Field app_opensubdiv_info_fields[]
static PyObject * make_opensubdiv_info()
int openSubdiv_getVersionHex()
header-only compatibility defines.
#define Py_HashPointer