Blender  V3.3
bpy_app_openvdb.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2015 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_utildefines.h"
9 #include <Python.h>
10 
11 #include "bpy_app_openvdb.h"
12 
13 #include "../generic/py_capi_utils.h"
14 
15 #ifdef WITH_OPENVDB
16 # include "openvdb_capi.h"
17 #endif
18 
19 static PyTypeObject BlenderAppOVDBType;
20 
21 static PyStructSequence_Field app_openvdb_info_fields[] = {
22  {"supported", "Boolean, True when Blender is built with OpenVDB support"},
23  {"version", "The OpenVDB version as a tuple of 3 numbers"},
24  {"version_string", "The OpenVDB version formatted as a string"},
25  {NULL},
26 };
27 
28 static PyStructSequence_Desc app_openvdb_info_desc = {
29  "bpy.app.openvdb", /* name */
30  "This module contains information about OpenVDB blender is linked against", /* doc */
31  app_openvdb_info_fields, /* fields */
33 };
34 
35 static PyObject *make_openvdb_info(void)
36 {
37  PyObject *openvdb_info;
38  int pos = 0;
39 
40 #ifdef WITH_OPENVDB
41  int curversion;
42 #endif
43 
44  openvdb_info = PyStructSequence_New(&BlenderAppOVDBType);
45  if (openvdb_info == NULL) {
46  return NULL;
47  }
48 
49 #ifndef WITH_OPENVDB
50 # define SetStrItem(str) PyStructSequence_SET_ITEM(openvdb_info, pos++, PyUnicode_FromString(str))
51 #endif
52 
53 #define SetObjItem(obj) PyStructSequence_SET_ITEM(openvdb_info, pos++, obj)
54 
55 #ifdef WITH_OPENVDB
56  curversion = OpenVDB_getVersionHex();
57  SetObjItem(PyBool_FromLong(1));
58  SetObjItem(
59  PyC_Tuple_Pack_I32(curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
60  SetObjItem(PyUnicode_FromFormat(
61  "%2d, %2d, %2d", curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
62 #else
63  SetObjItem(PyBool_FromLong(0));
65  SetStrItem("Unknown");
66 #endif
67 
68  if (UNLIKELY(PyErr_Occurred())) {
69  Py_DECREF(openvdb_info);
70  return NULL;
71  }
72 
73 #undef SetStrItem
74 #undef SetObjItem
75 
76  return openvdb_info;
77 }
78 
79 PyObject *BPY_app_openvdb_struct(void)
80 {
81  PyObject *ret;
82 
83  PyStructSequence_InitType(&BlenderAppOVDBType, &app_openvdb_info_desc);
84 
86 
87  /* prevent user from creating new instances */
88  BlenderAppOVDBType.tp_init = NULL;
89  BlenderAppOVDBType.tp_new = NULL;
90  BlenderAppOVDBType.tp_hash = (hashfunc)
91  _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */
92 
93  return ret;
94 }
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Desc app_openvdb_info_desc
static PyObject * make_openvdb_info(void)
static PyTypeObject BlenderAppOVDBType
PyObject * BPY_app_openvdb_struct(void)
#define SetStrItem(str)
static PyStructSequence_Field app_openvdb_info_fields[]
#define SetObjItem(obj)
uint pos
int OpenVDB_getVersionHex()
Definition: openvdb_capi.cc:7
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:88
return ret