Skip to content

Commit 798b1ba

Browse files
Prerak SinghPrerak Singh
authored andcommitted
bug fix
1 parent 30c6493 commit 798b1ba

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

pydatastructs/utils/_backend/cpp/utils.hpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,37 @@
66
#include <cstring>
77
#include <string>
88

9-
static PyObject *PyZero = PyLong_FromLong(0);
10-
static PyObject *PyOne = PyLong_FromLong(1);
11-
static PyObject *PyTwo = PyLong_FromLong(2);
12-
static PyObject *PyThree = PyLong_FromLong(3);
9+
static PyObject* get_PyZero() {
10+
static PyObject* PyZero = nullptr;
11+
if (PyZero == nullptr) {
12+
PyZero = PyLong_FromLong(0);
13+
}
14+
return PyZero;
15+
}
16+
17+
static PyObject* get_PyOne() {
18+
static PyObject* PyOne = nullptr;
19+
if (PyOne == nullptr) {
20+
PyOne = PyLong_FromLong(1);
21+
}
22+
return PyOne;
23+
}
24+
25+
static PyObject* get_PyTwo() {
26+
static PyObject* PyTwo = nullptr;
27+
if (PyTwo == nullptr) {
28+
PyTwo = PyLong_FromLong(2);
29+
}
30+
return PyTwo;
31+
}
32+
33+
static PyObject* get_PyThree() {
34+
static PyObject* PyThree = nullptr;
35+
if (PyThree == nullptr) {
36+
PyThree = PyLong_FromLong(3);
37+
}
38+
return PyThree;
39+
}
1340
static const char* _encoding = "utf-8";
1441
static const char* _invalid_char = "<invalid-character>";
1542

0 commit comments

Comments
 (0)