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
11 changes: 4 additions & 7 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import re
import sys
import unittest
from unittest import mock
import warnings

test_tools.skip_if_missing('clinic')
Expand All @@ -35,7 +34,7 @@
from libclinic.block_parser import Block, BlockParser
from libclinic.codegen import BlockPrinter, Destination
from libclinic.dsl_parser import DSLParser
from libclinic.slots import SlotSpec, SLOTS
from libclinic.slots import SLOTS
from libclinic.cli import parse_file, Clinic


Expand Down Expand Up @@ -856,9 +855,8 @@ class Foo "FooObject *" "&Foo_Type"
self.assertNotIn(text, generated)

def test_slot_with_parameters_and_return_type(self):
# Slots which take arguments or return something else than an
# object are not supported yet; check the machinery with them.
slots = {'__bool__': SlotSpec(return_converter='int')}
# Check the machinery with slots which take arguments or return
# something else than an object.
block = """
/*[clinic input]
output everything block
Expand All @@ -874,8 +872,7 @@ class Foo "FooObject *" "&Foo_Type"
Foo.__bool__
[clinic start generated code]*/
"""
with mock.patch.dict(SLOTS, slots):
generated = self.clinic.parse(dedent(block))
generated = self.clinic.parse(dedent(block))
self.assertIn(dedent("""
static int
Foo_contains(PyObject *self, PyObject *value)
Expand Down
20 changes: 8 additions & 12 deletions Modules/_dbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ dbm_length_impl(dbmobject *self)
return dp->di_size;
}

/*[clinic input]
@critical_section
_dbm.dbm.__bool__ as dbm_bool
[clinic start generated code]*/

static int
dbm_bool_lock_held(PyObject *self)
dbm_bool_impl(dbmobject *self)
/*[clinic end generated code: output=b550ce1ae52d6ad1 input=212af765b6e60719]*/
{
dbmobject *dp = dbmobject_CAST(self);
dbmobject *dp = self;
_dbm_state *state = PyType_GetModuleState(Py_TYPE(dp));
assert(state != NULL);

Expand Down Expand Up @@ -177,16 +183,6 @@ dbm_bool_lock_held(PyObject *self)
return 1;
}

static int
dbm_bool(PyObject *self)
{
int result;
Py_BEGIN_CRITICAL_SECTION(self);
result = dbm_bool_lock_held(self);
Py_END_CRITICAL_SECTION();
return result;
}

/*[clinic input]
@critical_section
_dbm.dbm.__getitem__ as dbm_subscript
Expand Down
20 changes: 8 additions & 12 deletions Modules/_gdbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,16 @@ gdbm_length_impl(gdbmobject *self)
return dp->di_size;
}

/*[clinic input]
@critical_section
_gdbm.gdbm.__bool__ as gdbm_bool
[clinic start generated code]*/

static int
gdbm_bool_lock_held(PyObject *op)
gdbm_bool_impl(gdbmobject *self)
/*[clinic end generated code: output=91316ca18acb945c input=bf2878ff5e311848]*/
{
gdbmobject *dp = _gdbmobject_CAST(op);
gdbmobject *dp = self;
_gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp));
if (dp->di_dbm == NULL) {
PyErr_SetString(state->gdbm_error, "GDBM object has already been closed");
Expand All @@ -219,16 +225,6 @@ gdbm_bool_lock_held(PyObject *op)
return 1;
}

static int
gdbm_bool(PyObject *op)
{
int result;
Py_BEGIN_CRITICAL_SECTION(op);
result = gdbm_bool_lock_held(op);
Py_END_CRITICAL_SECTION();
return result;
}

// Wrapper function for PyArg_Parse(o, "s#", &d.dptr, &d.size).
// This function is needed to support PY_SSIZE_T_CLEAN.
// Return 1 on success, same to PyArg_Parse().
Expand Down
17 changes: 16 additions & 1 deletion Modules/clinic/_dbmmodule.c.h

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

17 changes: 16 additions & 1 deletion Modules/clinic/_gdbmmodule.c.h

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

1 change: 1 addition & 0 deletions Tools/clinic/libclinic/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def make_return_converter(self) -> CReturnConverter:
# not be in dsl_parser.unsupported_special_methods.
SLOTS: Final[dict[str, SlotSpec]] = {
'__add__': SlotSpec(return_converter='object'),
'__bool__': SlotSpec(return_converter='int'),
'__contains__': SlotSpec(return_converter='int'),
'__getitem__': SlotSpec(return_converter='object'),
'__iadd__': SlotSpec(return_converter='object'),
Expand Down
Loading