Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4296,6 +4296,7 @@ def test_cli_converters(self):
int()
long()
object()
Py_hash_t()
Py_ssize_t()
size_t()
unsigned_int()
Expand Down
21 changes: 21 additions & 0 deletions Objects/clinic/weakrefobject.c.h

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

26 changes: 14 additions & 12 deletions Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include "pycore_pystate.h"
#include "pycore_weakref.h" // _PyWeakref_GET_REF()

/*[clinic input]
class weakref "PyWeakReference *" "&_PyWeakref_RefType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ad66c8b0acee6ad9]*/

#include "clinic/weakrefobject.c.h"

#ifdef Py_GIL_DISABLED
/*
* Thread-safety for free-threaded builds
Expand Down Expand Up @@ -186,8 +193,14 @@ weakref_vectorcall(PyObject *self, PyObject *const *args,
return obj;
}

/*[clinic input]
@critical_section
weakref.__hash__
[clinic start generated code]*/

static Py_hash_t
weakref_hash_lock_held(PyWeakReference *self)
weakref_hash_impl(PyWeakReference *self)
/*[clinic end generated code: output=4904eacaabf902c9 input=703596f4b120e47c]*/
{
if (self->hash != -1)
return self->hash;
Expand All @@ -201,17 +214,6 @@ weakref_hash_lock_held(PyWeakReference *self)
return self->hash;
}

static Py_hash_t
weakref_hash(PyObject *op)
{
PyWeakReference *self = _PyWeakref_CAST(op);
Py_hash_t hash;
Py_BEGIN_CRITICAL_SECTION(self);
hash = weakref_hash_lock_held(self);
Py_END_CRITICAL_SECTION();
return hash;
}

static PyObject *
weakref_repr(PyObject *self)
{
Expand Down
1 change: 0 additions & 1 deletion Tools/clinic/libclinic/dsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
__getattr__
__getattribute__
__gt__
__hash__
__iand__
__ifloordiv__
__ilshift__
Expand Down
6 changes: 6 additions & 0 deletions Tools/clinic/libclinic/return_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ class Py_ssize_t_return_converter(long_return_converter):
conversion_fn = 'PyLong_FromSsize_t'


class Py_hash_t_return_converter(long_return_converter):
type = 'Py_hash_t'
conversion_fn = 'PyLong_FromSsize_t'
cast = '(Py_ssize_t)'


class size_t_return_converter(long_return_converter):
type = 'size_t'
conversion_fn = 'PyLong_FromSize_t'
Expand Down
1 change: 1 addition & 0 deletions Tools/clinic/libclinic/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def make_return_converter(self) -> CReturnConverter:
'__bool__': SlotSpec(return_converter='int'),
'__contains__': SlotSpec(return_converter='int'),
'__getitem__': SlotSpec(return_converter='object'),
'__hash__': SlotSpec(return_converter='Py_hash_t'),
'__iadd__': SlotSpec(return_converter='object'),
'__imul__': SlotSpec(return_converter='object'),
'__len__': SlotSpec(return_converter='Py_ssize_t'),
Expand Down
Loading