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