Skip to content

Commit 2096a8a

Browse files
try fix memleak?
1 parent 4573fca commit 2096a8a

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ int _Py_uop_analyze_and_optimize(_PyInterpreterFrame *frame,
1717
_PyBloomFilter *dependencies);
1818

1919

20-
static void
21-
clear_strong_refs_in_uops(_PyUOpInstruction *trace, Py_ssize_t uop_len)
22-
{
23-
for (Py_ssize_t i = 0; i < uop_len; i++) {
24-
if (trace[i].opcode == _LOAD_CONST_INLINE ||
25-
trace[i].opcode == _LOAD_CONST_INLINE_WITH_NULL) {
26-
PyObject *c = (PyObject*)trace[i].operand;
27-
Py_CLEAR(c);
28-
}
29-
if (trace[i].opcode == _JUMP_ABSOLUTE ||
30-
trace[i].opcode == _JUMP_TO_TOP ||
31-
trace[i].opcode == _EXIT_TRACE) {
32-
return;
33-
}
34-
}
35-
}
3620

3721

3822
extern PyTypeObject _PyCounterExecutor_Type;

Python/optimizer.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ static PyMethodDef executor_methods[] = {
226226

227227
///////////////////// Experimental UOp Optimizer /////////////////////
228228

229+
static void
230+
clear_strong_refs_in_uops(_PyUOpInstruction *trace, Py_ssize_t uop_len)
231+
{
232+
for (Py_ssize_t i = 0; i < uop_len; i++) {
233+
if (trace[i].opcode == _LOAD_CONST_INLINE ||
234+
trace[i].opcode == _LOAD_CONST_INLINE_WITH_NULL) {
235+
PyObject *c = (PyObject*)trace[i].operand;
236+
Py_CLEAR(c);
237+
}
238+
}
239+
}
240+
229241

230242
static void
231243
uop_dealloc(_PyExecutorObject *self) {

Python/optimizer_analysis.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,22 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
13831383
}
13841384
}
13851385

1386+
static void
1387+
clear_strong_refs_in_uops(_PyUOpInstruction *trace, Py_ssize_t uop_len)
1388+
{
1389+
for (Py_ssize_t i = 0; i < uop_len; i++) {
1390+
if (trace[i].opcode == _LOAD_CONST_INLINE ||
1391+
trace[i].opcode == _LOAD_CONST_INLINE_WITH_NULL) {
1392+
PyObject *c = (PyObject*)trace[i].operand;
1393+
Py_CLEAR(c);
1394+
}
1395+
if (trace[i].opcode == _JUMP_ABSOLUTE ||
1396+
trace[i].opcode == _JUMP_TO_TOP ||
1397+
trace[i].opcode == _EXIT_TRACE) {
1398+
return;
1399+
}
1400+
}
1401+
}
13861402

13871403
// 0 - failure, no error raised, just fall back to Tier 1
13881404
// -1 - failure, and raise error

0 commit comments

Comments
 (0)