Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10852,13 +10852,19 @@
PyThreadState *tstate = _PyThreadState_GET();
PyObject *func, *result;

func = PyObject_GetAttr((PyObject *)type, &_Py_ID(__new__));
if (func == NULL) {
_PyCStackRef c_stackref;
_PyThreadState_PushCStackRef(tstate, &c_stackref);
int meth_found = _PyObject_GetMethodStackRef(tstate, (PyObject *)type, &_Py_ID(__new__), &c_stackref.ref);
Comment thread
eendebakpt marked this conversation as resolved.
Outdated

if (PyStackRef_IsNull(c_stackref.ref)) {
_PyThreadState_PopCStackRef(tstate, &c_stackref);
return NULL;
}

assert(meth_found);
Comment thread
eendebakpt marked this conversation as resolved.
Outdated
func = PyStackRef_AsPyObjectBorrow(c_stackref.ref);
assert(func != NULL);
result = _PyObject_Call_Prepend(tstate, func, (PyObject *)type, args, kwds);
Py_DECREF(func);
_PyThreadState_PopCStackRef(tstate, &c_stackref);
return result;
}

Expand All @@ -10884,7 +10890,7 @@
else {
Py_DECREF(res);
}
}

Check warning on line 10893 in Objects/typeobject.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

unused variable ‘meth_found’ [-Wunused-variable]

Check warning on line 10893 in Objects/typeobject.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

unused variable ‘meth_found’ [-Wunused-variable]

_PyThreadState_PopCStackRef(tstate, &cref);

Expand Down
12 changes: 6 additions & 6 deletions Programs/test_frozenmain.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion Tools/ftscalingbench/ftscalingbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import threading
import time
from operator import methodcaller
from typing import NamedTuple
from collections import namedtuple

# The iterations in individual benchmarks are scaled by this factor.
WORK_SCALE = 100
Expand All @@ -38,11 +40,26 @@
in_queues = []
out_queues = []


def register_benchmark(func):
ALL_BENCHMARKS[func.__name__] = func
return func

class Foo(NamedTuple):
x: int


Bar = namedtuple('Bar', ['x'])

@register_benchmark
def typing_namedtuple():
for i in range(1000 * WORK_SCALE):
_ = Foo(x=1)

@register_benchmark
def namedtuple():
for i in range(1000 * WORK_SCALE):
_ = Bar(x=1)

@register_benchmark
def object_cfunction():
accu = 0
Expand Down
Loading