Skip to content

Commit 0954b77

Browse files
committed
Fixes #174
1 parent da1ffd3 commit 0954b77

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/scorepy/pythonHelpers.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#include "pathUtils.hpp"
44
#include "pythoncapi_compat.h"
55

6-
#include <string>
6+
#include <cstdio>
77
#include <sstream>
88
#include <stdlib.h>
9-
#include <cstdio>
9+
#include <string>
1010

1111
namespace scorepy
1212
{
@@ -15,16 +15,18 @@ static PyObject* get_self_from_frame(PyFrameObject* frame)
1515
{
1616
PyObject* self = nullptr;
1717

18-
#if PY_VERSION_HEX >= 0x030C0000 // Python 3.12+
18+
#if PY_VERSION_HEX >= 0x030C0000 // Python 3.12+
1919
// Added in 3.12: directly fetch a local variable by name.
2020
self = PyFrame_GetVarString(frame, "self");
2121
if (!self && PyErr_Occurred())
2222
PyErr_Clear();
2323
#else
2424
PyObject* locals = PyFrame_GetLocals(frame); // New reference
25-
if (locals) {
26-
PyObject* tmp = PyDict_GetItemString(locals, "self"); // Borrowed
27-
if (tmp) {
25+
if (locals)
26+
{
27+
PyObject* tmp = PyDict_GetItemString(locals, "self"); // Borrowed
28+
if (tmp)
29+
{
2830
Py_INCREF(tmp);
2931
self = tmp;
3032
}
@@ -39,21 +41,23 @@ std::string get_module_name(PyFrameObject& frame)
3941
const char* self_name = nullptr;
4042

4143
PyObject* self = get_self_from_frame(&frame);
42-
if (self) {
44+
if (self)
45+
{
4346
PyTypeObject* type = Py_TYPE(self);
4447
self_name = _PyType_Name(type);
4548
Py_DECREF(self);
4649
}
4750

4851
// --- get module name from globals ---------------------------------------
49-
PyObject* globals = PyFrame_GetGlobals(&frame); // New reference
50-
PyObject* module_name = globals
51-
? PyDict_GetItemString(globals, "__name__") // Borrowed
52-
: nullptr;
52+
PyObject* globals = PyFrame_GetGlobals(&frame); // New reference
53+
PyObject* module_name = globals ? PyDict_GetItemString(globals, "__name__") // Borrowed
54+
:
55+
nullptr;
5356
if (globals)
5457
Py_DECREF(globals);
5558

56-
if (module_name) {
59+
if (module_name)
60+
{
5761
std::stringstream result;
5862
// compat::get_string_as_utf_8() is assumed to convert PyObject* → UTF-8 std::string
5963
result << compat::get_string_as_utf_8(module_name);

0 commit comments

Comments
 (0)