Skip to content

Commit e00703c

Browse files
committed
Turn stats into properties (tp_members)
1 parent a7d2cba commit e00703c

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

Python/optimizer.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -458,22 +458,12 @@ uop_optimize(
458458
return 1;
459459
}
460460

461-
static PyObject *
462-
uop_get_traces(PyObject *self, PyObject *args)
463-
{
464-
return PyLong_FromLongLong(((UOpOptimizerObject *)self)->traces_executed);
465-
}
466-
467-
static PyObject *
468-
uop_get_instrs(PyObject *self, PyObject *args)
469-
{
470-
return PyLong_FromLongLong(((UOpOptimizerObject *)self)->instrs_executed);
471-
}
472-
473-
static PyMethodDef uop_methods[] = {
474-
{ "get_traces", uop_get_traces, METH_NOARGS, NULL },
475-
{ "get_instrs", uop_get_instrs, METH_NOARGS, NULL },
476-
{ NULL, NULL },
461+
static PyMemberDef uop_members[] = {
462+
{"traces_executed", Py_T_INT, offsetof(UOpOptimizerObject, traces_executed), 0,
463+
"Total number of traces executed since inception"},
464+
{"instrs_executed", Py_T_INT, offsetof(UOpOptimizerObject, instrs_executed), 0,
465+
"Total number of instructions executed since inception"},
466+
{NULL}
477467
};
478468

479469
static PyTypeObject UOpOptimizer_Type = {
@@ -482,12 +472,15 @@ static PyTypeObject UOpOptimizer_Type = {
482472
.tp_basicsize = sizeof(UOpOptimizerObject),
483473
.tp_itemsize = 0,
484474
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
485-
.tp_methods = uop_methods,
475+
.tp_members = uop_members,
486476
};
487477

488478
PyObject *
489479
PyUnstable_Optimizer_NewUOpOptimizer(void)
490480
{
481+
if (PyType_Ready(&UOpOptimizer_Type) < 0) {
482+
return NULL;
483+
}
491484
UOpOptimizerObject *opt = (UOpOptimizerObject *)_PyObject_New(&UOpOptimizer_Type);
492485
if (opt == NULL) {
493486
return NULL;

0 commit comments

Comments
 (0)