Blender V4.3
bpy_app_sdl.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_sdl.hh"
13
15
16#ifdef WITH_SDL
17/* SDL force defines __SSE__ and __SSE2__ flags, which generates warnings
18 * because we pass those defines via command line as well. For until there's
19 * proper `ifndef` added to SDL headers we ignore the redefinition warning.
20 */
21# ifdef _MSC_VER
22# pragma warning(push)
23# pragma warning(disable : 4005)
24# endif
25# include "SDL.h"
26# ifdef _MSC_VER
27# pragma warning(pop)
28# endif
29#endif
30
31static PyTypeObject BlenderAppSDLType;
32
33static PyStructSequence_Field app_sdl_info_fields[] = {
34 {"supported", ("Boolean, True when Blender is built with SDL support")},
35 {"version", ("The SDL version as a tuple of 3 numbers")},
36 {"version_string", ("The SDL version formatted as a string")},
37 {nullptr},
38};
39
40static PyStructSequence_Desc app_sdl_info_desc = {
41 /*name*/ "bpy.app.sdl",
42 /*doc*/ "This module contains information about SDL blender is linked against",
43 /*fields*/ app_sdl_info_fields,
44 /*n_in_sequence*/ ARRAY_SIZE(app_sdl_info_fields) - 1,
45};
46
47static PyObject *make_sdl_info()
48{
49 PyObject *sdl_info;
50 int pos = 0;
51#ifdef WITH_SDL
52 SDL_version version = {0, 0, 0};
53#endif
54
55 sdl_info = PyStructSequence_New(&BlenderAppSDLType);
56 if (sdl_info == nullptr) {
57 return nullptr;
58 }
59
60#define SetStrItem(str) PyStructSequence_SET_ITEM(sdl_info, pos++, PyUnicode_FromString(str))
61
62#define SetObjItem(obj) PyStructSequence_SET_ITEM(sdl_info, pos++, obj)
63
64#ifdef WITH_SDL
65 SetObjItem(PyBool_FromLong(1));
66# if SDL_MAJOR_VERSION >= 2
67 SDL_GetVersion(&version);
68# else
69 SDL_VERSION(&version);
70# endif
71
72 SetObjItem(PyC_Tuple_Pack_I32({version.major, version.minor, version.patch}));
73 SetObjItem(PyUnicode_FromFormat("%d.%d.%d", version.major, version.minor, version.patch));
74
75#else /* WITH_SDL=OFF */
76 SetObjItem(PyBool_FromLong(0));
78 SetStrItem("Unknown");
79#endif
80
81 if (UNLIKELY(PyErr_Occurred())) {
82 Py_DECREF(sdl_info);
83 return nullptr;
84 }
85
86#undef SetStrItem
87#undef SetObjItem
88
89 return sdl_info;
90}
91
93{
94 PyObject *ret;
95
96 PyStructSequence_InitType(&BlenderAppSDLType, &app_sdl_info_desc);
97
99
100 /* prevent user from creating new instances */
101 BlenderAppSDLType.tp_init = nullptr;
102 BlenderAppSDLType.tp_new = nullptr;
103 /* Without this we can't do `set(sys.modules)` #29635. */
104 BlenderAppSDLType.tp_hash = (hashfunc)_Py_HashPointer;
105
106 return ret;
107}
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Desc app_sdl_info_desc
PyObject * BPY_app_sdl_struct()
static PyStructSequence_Field app_sdl_info_fields[]
static PyTypeObject BlenderAppSDLType
#define SetStrItem(str)
#define SetObjItem(obj)
static PyObject * make_sdl_info()
PyObject * PyC_Tuple_Pack_I32(const blender::Span< int > values)
return ret