mirror of
https://github.com/johndoe6345789/typthon.git
synced 2026-04-24 21:55:26 +00:00
Rename Py_ to Ty_ throughout C API
Massive automated renaming of all Py_/PyObject/etc. prefixes to Ty_/TyObject/etc. This includes: - All public API types (TyObject, TyTypeObject, etc.) - All public API functions (Ty_Initialize, Ty_BuildValue, etc.) - All internal API (_Ty_ prefixes) - Reference counting macros (Ty_INCREF, Ty_DECREF, etc.) - Type flags (Ty_TPFLAGS_*) - Debug flags (Ty_DEBUG, Ty_TRACE_REFS, etc.) - All object type APIs (TyList_, TyDict_, TyUnicode_, etc.) This changes over 60,000 occurrences across 1000+ files. Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -3,17 +3,17 @@
|
||||
#include "pycore_object.h"
|
||||
#include "pycore_stackref.h"
|
||||
|
||||
#if !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
|
||||
#if !defined(Ty_GIL_DISABLED) && defined(Ty_STACKREF_DEBUG)
|
||||
|
||||
#if SIZEOF_VOID_P < 8
|
||||
#error "Py_STACKREF_DEBUG requires 64 bit machine"
|
||||
#error "Ty_STACKREF_DEBUG requires 64 bit machine"
|
||||
#endif
|
||||
|
||||
#include "pycore_interp.h"
|
||||
#include "pycore_hashtable.h"
|
||||
|
||||
typedef struct _table_entry {
|
||||
PyObject *obj;
|
||||
TyObject *obj;
|
||||
const char *classname;
|
||||
const char *filename;
|
||||
int linenumber;
|
||||
@@ -22,14 +22,14 @@ typedef struct _table_entry {
|
||||
} TableEntry;
|
||||
|
||||
TableEntry *
|
||||
make_table_entry(PyObject *obj, const char *filename, int linenumber)
|
||||
make_table_entry(TyObject *obj, const char *filename, int linenumber)
|
||||
{
|
||||
TableEntry *result = malloc(sizeof(TableEntry));
|
||||
if (result == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
result->obj = obj;
|
||||
result->classname = Py_TYPE(obj)->tp_name;
|
||||
result->classname = Ty_TYPE(obj)->tp_name;
|
||||
result->filename = filename;
|
||||
result->linenumber = linenumber;
|
||||
result->filename_borrow = NULL;
|
||||
@@ -37,20 +37,20 @@ make_table_entry(PyObject *obj, const char *filename, int linenumber)
|
||||
return result;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_Py_stackref_get_object(_PyStackRef ref)
|
||||
TyObject *
|
||||
_Ty_stackref_get_object(_PyStackRef ref)
|
||||
{
|
||||
if (ref.index == 0) {
|
||||
return NULL;
|
||||
}
|
||||
PyInterpreterState *interp = PyInterpreterState_Get();
|
||||
PyInterpreterState *interp = TyInterpreterState_Get();
|
||||
assert(interp != NULL);
|
||||
if (ref.index >= interp->next_stackref) {
|
||||
_Py_FatalErrorFormat(__func__, "Garbled stack ref with ID %" PRIu64 "\n", ref.index);
|
||||
_Ty_FatalErrorFormat(__func__, "Garbled stack ref with ID %" PRIu64 "\n", ref.index);
|
||||
}
|
||||
TableEntry *entry = _Py_hashtable_get(interp->open_stackrefs_table, (void *)ref.index);
|
||||
TableEntry *entry = _Ty_hashtable_get(interp->open_stackrefs_table, (void *)ref.index);
|
||||
if (entry == NULL) {
|
||||
_Py_FatalErrorFormat(__func__, "Accessing closed stack ref with ID %" PRIu64 "\n", ref.index);
|
||||
_Ty_FatalErrorFormat(__func__, "Accessing closed stack ref with ID %" PRIu64 "\n", ref.index);
|
||||
}
|
||||
return entry->obj;
|
||||
}
|
||||
@@ -58,48 +58,48 @@ _Py_stackref_get_object(_PyStackRef ref)
|
||||
int
|
||||
PyStackRef_Is(_PyStackRef a, _PyStackRef b)
|
||||
{
|
||||
return _Py_stackref_get_object(a) == _Py_stackref_get_object(b);
|
||||
return _Ty_stackref_get_object(a) == _Ty_stackref_get_object(b);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_Py_stackref_close(_PyStackRef ref, const char *filename, int linenumber)
|
||||
TyObject *
|
||||
_Ty_stackref_close(_PyStackRef ref, const char *filename, int linenumber)
|
||||
{
|
||||
PyInterpreterState *interp = PyInterpreterState_Get();
|
||||
PyInterpreterState *interp = TyInterpreterState_Get();
|
||||
if (ref.index >= interp->next_stackref) {
|
||||
_Py_FatalErrorFormat(__func__, "Invalid StackRef with ID %" PRIu64 " at %s:%d\n", (void *)ref.index, filename, linenumber);
|
||||
_Ty_FatalErrorFormat(__func__, "Invalid StackRef with ID %" PRIu64 " at %s:%d\n", (void *)ref.index, filename, linenumber);
|
||||
|
||||
}
|
||||
PyObject *obj;
|
||||
TyObject *obj;
|
||||
if (ref.index < INITIAL_STACKREF_INDEX) {
|
||||
if (ref.index == 0) {
|
||||
_Py_FatalErrorFormat(__func__, "Passing NULL to PyStackRef_CLOSE at %s:%d\n", filename, linenumber);
|
||||
_Ty_FatalErrorFormat(__func__, "Passing NULL to PyStackRef_CLOSE at %s:%d\n", filename, linenumber);
|
||||
}
|
||||
// Pre-allocated reference to None, False or True -- Do not clear
|
||||
TableEntry *entry = _Py_hashtable_get(interp->open_stackrefs_table, (void *)ref.index);
|
||||
TableEntry *entry = _Ty_hashtable_get(interp->open_stackrefs_table, (void *)ref.index);
|
||||
obj = entry->obj;
|
||||
}
|
||||
else {
|
||||
TableEntry *entry = _Py_hashtable_steal(interp->open_stackrefs_table, (void *)ref.index);
|
||||
TableEntry *entry = _Ty_hashtable_steal(interp->open_stackrefs_table, (void *)ref.index);
|
||||
if (entry == NULL) {
|
||||
#ifdef Py_STACKREF_CLOSE_DEBUG
|
||||
entry = _Py_hashtable_get(interp->closed_stackrefs_table, (void *)ref.index);
|
||||
#ifdef Ty_STACKREF_CLOSE_DEBUG
|
||||
entry = _Ty_hashtable_get(interp->closed_stackrefs_table, (void *)ref.index);
|
||||
if (entry != NULL) {
|
||||
_Py_FatalErrorFormat(__func__,
|
||||
_Ty_FatalErrorFormat(__func__,
|
||||
"Double close of ref ID %" PRIu64 " at %s:%d. Referred to instance of %s at %p. Closed at %s:%d\n",
|
||||
(void *)ref.index, filename, linenumber, entry->classname, entry->obj, entry->filename, entry->linenumber);
|
||||
}
|
||||
#endif
|
||||
_Py_FatalErrorFormat(__func__, "Invalid StackRef with ID %" PRIu64 "\n", (void *)ref.index);
|
||||
_Ty_FatalErrorFormat(__func__, "Invalid StackRef with ID %" PRIu64 "\n", (void *)ref.index);
|
||||
}
|
||||
obj = entry->obj;
|
||||
free(entry);
|
||||
#ifdef Py_STACKREF_CLOSE_DEBUG
|
||||
#ifdef Ty_STACKREF_CLOSE_DEBUG
|
||||
TableEntry *close_entry = make_table_entry(obj, filename, linenumber);
|
||||
if (close_entry == NULL) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
Ty_FatalError("No memory left for stackref debug table");
|
||||
}
|
||||
if (_Py_hashtable_set(interp->closed_stackrefs_table, (void *)ref.index, close_entry) < 0) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
if (_Ty_hashtable_set(interp->closed_stackrefs_table, (void *)ref.index, close_entry) < 0) {
|
||||
Ty_FatalError("No memory left for stackref debug table");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -107,42 +107,42 @@ _Py_stackref_close(_PyStackRef ref, const char *filename, int linenumber)
|
||||
}
|
||||
|
||||
_PyStackRef
|
||||
_Py_stackref_create(PyObject *obj, const char *filename, int linenumber)
|
||||
_Ty_stackref_create(TyObject *obj, const char *filename, int linenumber)
|
||||
{
|
||||
if (obj == NULL) {
|
||||
Py_FatalError("Cannot create a stackref for NULL");
|
||||
Ty_FatalError("Cannot create a stackref for NULL");
|
||||
}
|
||||
PyInterpreterState *interp = PyInterpreterState_Get();
|
||||
PyInterpreterState *interp = TyInterpreterState_Get();
|
||||
uint64_t new_id = interp->next_stackref;
|
||||
interp->next_stackref = new_id + 2;
|
||||
TableEntry *entry = make_table_entry(obj, filename, linenumber);
|
||||
if (entry == NULL) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
Ty_FatalError("No memory left for stackref debug table");
|
||||
}
|
||||
if (_Py_hashtable_set(interp->open_stackrefs_table, (void *)new_id, entry) < 0) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
if (_Ty_hashtable_set(interp->open_stackrefs_table, (void *)new_id, entry) < 0) {
|
||||
Ty_FatalError("No memory left for stackref debug table");
|
||||
}
|
||||
return (_PyStackRef){ .index = new_id };
|
||||
}
|
||||
|
||||
void
|
||||
_Py_stackref_record_borrow(_PyStackRef ref, const char *filename, int linenumber)
|
||||
_Ty_stackref_record_borrow(_PyStackRef ref, const char *filename, int linenumber)
|
||||
{
|
||||
if (ref.index < INITIAL_STACKREF_INDEX) {
|
||||
return;
|
||||
}
|
||||
PyInterpreterState *interp = PyInterpreterState_Get();
|
||||
TableEntry *entry = _Py_hashtable_get(interp->open_stackrefs_table, (void *)ref.index);
|
||||
PyInterpreterState *interp = TyInterpreterState_Get();
|
||||
TableEntry *entry = _Ty_hashtable_get(interp->open_stackrefs_table, (void *)ref.index);
|
||||
if (entry == NULL) {
|
||||
#ifdef Py_STACKREF_CLOSE_DEBUG
|
||||
entry = _Py_hashtable_get(interp->closed_stackrefs_table, (void *)ref.index);
|
||||
#ifdef Ty_STACKREF_CLOSE_DEBUG
|
||||
entry = _Ty_hashtable_get(interp->closed_stackrefs_table, (void *)ref.index);
|
||||
if (entry != NULL) {
|
||||
_Py_FatalErrorFormat(__func__,
|
||||
_Ty_FatalErrorFormat(__func__,
|
||||
"Borrow of closed ref ID %" PRIu64 " at %s:%d. Referred to instance of %s at %p. Closed at %s:%d\n",
|
||||
(void *)ref.index, filename, linenumber, entry->classname, entry->obj, entry->filename, entry->linenumber);
|
||||
}
|
||||
#endif
|
||||
_Py_FatalErrorFormat(__func__, "Invalid StackRef with ID %" PRIu64 " at %s:%d\n", (void *)ref.index, filename, linenumber);
|
||||
_Ty_FatalErrorFormat(__func__, "Invalid StackRef with ID %" PRIu64 " at %s:%d\n", (void *)ref.index, filename, linenumber);
|
||||
}
|
||||
entry->filename_borrow = filename;
|
||||
entry->linenumber_borrow = linenumber;
|
||||
@@ -150,24 +150,24 @@ _Py_stackref_record_borrow(_PyStackRef ref, const char *filename, int linenumber
|
||||
|
||||
|
||||
void
|
||||
_Py_stackref_associate(PyInterpreterState *interp, PyObject *obj, _PyStackRef ref)
|
||||
_Ty_stackref_associate(PyInterpreterState *interp, TyObject *obj, _PyStackRef ref)
|
||||
{
|
||||
assert(ref.index < INITIAL_STACKREF_INDEX);
|
||||
TableEntry *entry = make_table_entry(obj, "builtin-object", 0);
|
||||
if (entry == NULL) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
Ty_FatalError("No memory left for stackref debug table");
|
||||
}
|
||||
if (_Py_hashtable_set(interp->open_stackrefs_table, (void *)ref.index, (void *)entry) < 0) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
if (_Ty_hashtable_set(interp->open_stackrefs_table, (void *)ref.index, (void *)entry) < 0) {
|
||||
Ty_FatalError("No memory left for stackref debug table");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
report_leak(_Py_hashtable_t *ht, const void *key, const void *value, void *leak)
|
||||
report_leak(_Ty_hashtable_t *ht, const void *key, const void *value, void *leak)
|
||||
{
|
||||
TableEntry *entry = (TableEntry *)value;
|
||||
if (!_Py_IsStaticImmortal(entry->obj)) {
|
||||
if (!_Ty_IsStaticImmortal(entry->obj)) {
|
||||
*(int *)leak = 1;
|
||||
printf("Stackref leak. Refers to instance of %s at %p. Created at %s:%d",
|
||||
entry->classname, entry->obj, entry->filename, entry->linenumber);
|
||||
@@ -180,21 +180,21 @@ report_leak(_Py_hashtable_t *ht, const void *key, const void *value, void *leak)
|
||||
}
|
||||
|
||||
void
|
||||
_Py_stackref_report_leaks(PyInterpreterState *interp)
|
||||
_Ty_stackref_report_leaks(PyInterpreterState *interp)
|
||||
{
|
||||
int leak = 0;
|
||||
_Py_hashtable_foreach(interp->open_stackrefs_table, report_leak, &leak);
|
||||
_Ty_hashtable_foreach(interp->open_stackrefs_table, report_leak, &leak);
|
||||
if (leak) {
|
||||
fflush(stdout);
|
||||
Py_FatalError("Stackrefs leaked.");
|
||||
Ty_FatalError("Stackrefs leaked.");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct, const char *filename, int linenumber)
|
||||
{
|
||||
PyObject *obj = _Py_stackref_close(ref, filename, linenumber);
|
||||
_Py_DECREF_SPECIALIZED(obj, destruct);
|
||||
TyObject *obj = _Ty_stackref_close(ref, filename, linenumber);
|
||||
_Ty_DECREF_SPECIALIZED(obj, destruct);
|
||||
}
|
||||
|
||||
_PyStackRef PyStackRef_TagInt(intptr_t i)
|
||||
@@ -207,7 +207,7 @@ PyStackRef_UntagInt(_PyStackRef i)
|
||||
{
|
||||
assert(PyStackRef_IsTaggedInt(i));
|
||||
intptr_t val = (intptr_t)i.index;
|
||||
return Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 1);
|
||||
return Ty_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 1);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
Reference in New Issue
Block a user