8000 gh-93502: Add new C-API functions to trace object creation and destruction by pablogsal · Pull Request #115945 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-93502: Add new C-API functions to trace object creation and destruction #115945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 2, 2024
Merged
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into tracerefs_interface
  • Loading branch information
pablogsal committed May 1, 2024
commit 0c4265557f94ef15f44a056ab927f076a82d97f4
50 changes: 50 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2955,3 +2955,53 @@ PyRefTracer PyRefTracer_GetTracer(void** data) {
return _PyRuntime.ref_tracer.tracer_func;
}



static PyObject* constants[] = {
&_Py_NoneStruct, // Py_CONSTANT_NONE
(PyObject*)(&_Py_FalseStruct), // Py_CONSTANT_FALSE
(PyObject*)(&_Py_TrueStruct), // Py_CONSTANT_TRUE
&_Py_EllipsisObject, // Py_CONSTANT_ELLIPSIS
&_Py_NotImplementedStruct, // Py_CONSTANT_NOT_IMPLEMENTED
NULL, // Py_CONSTANT_ZERO
NULL, // Py_CONSTANT_ONE
NULL, // Py_CONSTANT_EMPTY_STR
NULL, // Py_CONSTANT_EMPTY_BYTES
NULL, // Py_CONSTANT_EMPTY_TUPLE
};

void
_Py_GetConstant_Init(void)
{
constants[Py_CONSTANT_ZERO] = _PyLong_GetZero();
constants[Py_CONSTANT_ONE] = _PyLong_GetOne();
constants[Py_CONSTANT_EMPTY_STR] = PyUnicode_New(0, 0);
constants[Py_CONSTANT_EMPTY_BYTES] = PyBytes_FromStringAndSize(NULL, 0);
constants[Py_CONSTANT_EMPTY_TUPLE] = PyTuple_New(0);
#ifndef NDEBUG
for (size_t i=0; i < Py_ARRAY_LENGTH(constants); i++) {
assert(constants[i] != NULL);
assert(_Py_IsImmortal(constants[i]));
}
#endif
}

PyObject*
Py_GetConstant(unsigned int constant_id)
{
if (constant_id < Py_ARRAY_LENGTH(constants)) {
return constants[constant_id];
}
else {
PyErr_BadInternalCall();
return NULL;
}
}


PyObject*
Py_GetConstantBorrowed(unsigned int constant_id)
{
// All constants are immortal
return Py_GetConstant(constant_id);
}
You are viewing a condensed version of this merge commit. You can view the full changes here.
0