Blender V5.3
python_compat.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <Python.h> /* IWYU pragma: keep. */
12
13#include "BLI_utildefines.hh" /* IWYU pragma: keep. */
14#include "python_compat.hh" /* IWYU pragma: keep. */
15
16int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t min, Py_ssize_t max)
17{
18 BLI_assert(min >= 0);
19 BLI_assert(min <= max);
20
21 if (nargs < min) {
22 if (name != nullptr) {
23 PyErr_Format(PyExc_TypeError,
24 "%.200s expected %s%zd argument%s, got %zd",
25 name,
26 (min == max ? "" : "at least "),
27 min,
28 min == 1 ? "" : "s",
29 nargs);
30 }
31 else {
32 PyErr_Format(PyExc_TypeError,
33 "unpacked tuple should have %s%zd element%s,"
34 " but has %zd",
35 (min == max ? "" : "at least "),
36 min,
37 min == 1 ? "" : "s",
38 nargs);
39 }
40 return 0;
41 }
42
43 if (nargs == 0) {
44 return 1;
45 }
46
47 if (nargs > max) {
48 if (name != nullptr) {
49 PyErr_Format(PyExc_TypeError,
50 "%.200s expected %s%zd argument%s, got %zd",
51 name,
52 (min == max ? "" : "at most "),
53 max,
54 max == 1 ? "" : "s",
55 nargs);
56 }
57 else {
58 PyErr_Format(PyExc_TypeError,
59 "unpacked tuple should have %s%zd element%s,"
60 " but has %zd",
61 (min == max ? "" : "at most "),
62 max,
63 max == 1 ? "" : "s",
64 nargs);
65 }
66 return 0;
67 }
68
69 return 1;
70}
#define BLI_assert(a)
btScalar max
int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t min, Py_ssize_t max)
header-only compatibility defines.
#define min(a, b)
Definition sort.cc:38