Skip to content

Commit 065b56a

Browse files
Add braces for single-line statements
Co-authored-by: Andreas Gocht <andreas.gocht@tu-dresden.de>
1 parent 631618e commit 065b56a

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/classes.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ extern "C"
1717
{
1818
scorepy::PyRefObject empty_tuple(PyTuple_New(0), scorepy::adopt_object);
1919
if (!empty_tuple)
20+
{
2021
return nullptr;
22+
}
2123
scorepy::PyRefObject empty_dict(PyDict_New(), scorepy::adopt_object);
2224
if (!empty_dict)
25+
{
2326
return nullptr;
27+
}
2428
return PyBaseObject_Type.tp_new(type, empty_tuple, empty_dict);
2529
}
2630

@@ -37,14 +41,20 @@ extern "C"
3741

3842
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", const_cast<char**>(kwlist),
3943
&interface_cstring))
44+
{
4045
return -1;
46+
}
4147

4248
const std::string interface_string = interface_cstring;
4349
scorepy::InstrumenterInterface interface;
4450
if (interface_string == "Trace")
51+
{
4552
interface = scorepy::InstrumenterInterface::Trace;
53+
}
4654
else if (interface_string == "Profile")
55+
{
4756
interface = scorepy::InstrumenterInterface::Profile;
57+
}
4858
else
4959
{
5060
PyErr_Format(PyExc_TypeError, "Expected 'Trace' or 'Profile', got '%s'",
@@ -86,7 +96,9 @@ extern "C"
8696

8797
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!sO", const_cast<char**>(kwlist),
8898
&PyFrame_Type, &frame, &event, &arg))
99+
{
89100
return nullptr;
101+
}
90102
return (*self)(*frame, event, arg);
91103
}
92104
}

src/scorep_bindings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ PyMODINIT_FUNC PyInit__bindings(void)
2222

2323
auto* m = PyModule_Create(&scorepmodule);
2424
if (!m)
25+
{
2526
return nullptr;
27+
}
2628

2729
Py_INCREF(ctracerType);
2830
if (PyModule_AddObject(m, "CInstrumenter", (PyObject*)ctracerType) < 0)

src/scorepy/cInstrumenter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,25 @@ void CInstrumenter::enable_instrumenter()
3636
adopt_object);
3737
}
3838
if (interface == InstrumenterInterface::Trace)
39+
{
3940
PyEval_SetTrace(callback, to_PyObject());
41+
}
4042
else
43+
{
4144
PyEval_SetProfile(callback, to_PyObject());
45+
}
4246
}
4347

4448
void CInstrumenter::disable_instrumenter()
4549
{
4650
if (interface == InstrumenterInterface::Trace)
51+
{
4752
PyEval_SetTrace(nullptr, nullptr);
53+
}
4854
else
55+
{
4956
PyEval_SetProfile(nullptr, nullptr);
57+
}
5058
if (threading_set_instrumenter)
5159
{
5260
PyRefObject result(PyObject_CallFunction(threading_set_instrumenter, "O", Py_None),
@@ -65,9 +73,13 @@ int index_of(TCollection&& col, const TElement& element)
6573
{
6674
const auto it = std::find(col.cbegin(), col.cend(), element);
6775
if (it == col.end())
76+
{
6877
return -1;
78+
}
6979
else
80+
{
7081
return std::distance(col.begin(), it);
82+
}
7183
}
7284

7385
// Required because: `sys.getprofile()` returns the user object (2nd arg to PyEval_SetTrace)
@@ -81,14 +93,18 @@ PyObject* CInstrumenter::operator()(PyFrameObject& frame, const char* what_strin
8193
// But we might be inside a `sys.settrace` call where the user wanted to set another function
8294
// which would then be overwritten here. Hence use the CALL event which avoids the problem
8395
if (what == PyTrace_CALL)
96+
{
8497
enable_instrumenter();
98+
}
8599
if (on_event(frame, what, arg))
86100
{
87101
Py_INCREF(to_PyObject());
88102
return to_PyObject();
89103
}
90104
else
105+
{
91106
return nullptr;
107+
}
92108
}
93109

94110
bool CInstrumenter::on_event(PyFrameObject& frame, int what, PyObject*)

src/scorepy/pythonHelpers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ std::string get_file_name(const PyFrameObject& frame)
2222
{
2323
PyObject* filename = frame.f_code->co_filename;
2424
if (filename == Py_None)
25+
{
2526
return "None";
27+
}
2628
char actual_path[PATH_MAX];
2729
const char* full_file_name = realpath(PyUnicode_AsUTF8(filename), actual_path);
2830
return full_file_name ? full_file_name : "ErrorPath";

0 commit comments

Comments
 (0)