Skip to content

Commit 6630a95

Browse files
committed
add free
1 parent 89b6c37 commit 6630a95

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

Include/internal/pycore_code.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,18 @@ adaptive_counter_backoff(_Py_BackoffCounter counter) {
482482
/* Specialization Extensions */
483483

484484
/* callbacks for an external specialization */
485+
486+
struct _PyBinopSpecializationDescr;
487+
485488
typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
486-
typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
489+
typedef PyObject* (*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
490+
typedef void (*binaryopfreefunc)(struct _PyBinopSpecializationDescr *descr);
487491

488492
typedef struct _PyBinopSpecializationDescr {
489493
int oparg;
490494
binaryopguardfunc guard;
491495
binaryopactionfunc action;
496+
binaryopfreefunc free;
492497
} _PyBinaryOpSpecializationDescr;
493498

494499
/* Comparison bit masks. */

Modules/arraymodule.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,14 @@ array_subscr_action(PyObject *lhs, PyObject *rhs)
30243024
return array_subscr(lhs, rhs);
30253025
}
30263026

3027+
static void
3028+
array_subscr_free(_PyBinaryOpSpecializationDescr* descr)
3029+
{
3030+
if (descr != NULL) {
3031+
PyMem_Free(descr);
3032+
}
3033+
}
3034+
30273035
static int
30283036
array_binop_specialize(PyObject *v, PyObject *w, int oparg,
30293037
_PyBinaryOpSpecializationDescr **descr)
@@ -3048,6 +3056,7 @@ array_binop_specialize(PyObject *v, PyObject *w, int oparg,
30483056
.oparg = oparg,
30493057
.guard = array_subscr_guard,
30503058
.action = array_subscr_action,
3059+
.free = array_subscr_free,
30513060
};
30523061
return 1;
30533062
}

Python/bytecodes.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,12 @@ dummy_func(
805805
assert(d->guard);
806806
int res = d->guard(left_o, right_o);
807807
ERROR_IF(res < 0);
808-
DEOPT_IF(res == 0);
808+
if (res == 0) {
809+
if (d->free) {
810+
d->free(d);
811+
}
812+
DEOPT_IF(true);
813+
}
809814
}
810815

811816
pure op(_BINARY_OP_EXTEND, (descr/4, left, right -- res)) {

Python/executor_cases.c.h

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)