From 091bdef0cccb0a1a06b49ce88b386e3fd595bee5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 19 Aug 2026 21:10:34 +0300 Subject: [PATCH 1/2] gh-113318: Better implementation of @getter and @setter in Argument Clinic The value of a @setter is now a parameter, which can use a converter, and a @getter can define a return converter. Declaring the value is optional. The accessors of an attribute are now collected in a Property, so the entry of PyGetSetDef is identified by the Python name instead of the C basename, and is composed without the help of the preprocessor unless some accessor is compiled conditionally. --- Lib/test/clinic.test.c | 208 +++--- Lib/test/test_clinic.py | 336 +++++++-- ...-08-14-13-15-35.gh-issue-113318.oHjvUR.rst | 7 + Modules/_asynciomodule.c | 80 +-- Modules/_ctypes/_ctypes.c | 52 +- Modules/_ctypes/clinic/_ctypes.c.h | 244 ++----- Modules/_io/clinic/bufferedio.c.h | 38 +- Modules/_io/clinic/stringio.c.h | 38 +- Modules/_io/clinic/textio.c.h | 140 +--- Modules/_sqlite/clinic/cursor.c.h | 37 +- Modules/_sqlite/cursor.c | 8 +- Modules/_ssl.c | 103 ++- Modules/_zstd/clinic/decompressor.c.h | 18 +- Modules/_zstd/clinic/zstddict.c.h | 66 +- Modules/clinic/_asynciomodule.c.h | 291 +++----- Modules/clinic/_ssl.c.h | 675 ++++++------------ Modules/clinic/hmacmodule.c.h | 38 +- Objects/clinic/exceptions.c.h | 122 +--- Objects/clinic/frameobject.c.h | 212 +----- Objects/clinic/funcobject.c.h | 109 +-- Objects/frameobject.c | 20 +- Objects/funcobject.c | 8 +- Python/clinic/traceback.c.h | 32 +- Tools/clinic/libclinic/app.py | 8 +- Tools/clinic/libclinic/clanguage.py | 76 +- Tools/clinic/libclinic/converter.py | 12 +- Tools/clinic/libclinic/dsl_parser.py | 87 ++- Tools/clinic/libclinic/function.py | 45 ++ Tools/clinic/libclinic/language.py | 3 + Tools/clinic/libclinic/parse_args.py | 178 +++-- 30 files changed, 1358 insertions(+), 1933 deletions(-) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2026-08-14-13-15-35.gh-issue-113318.oHjvUR.rst diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 2ac153ac43e7029..5b8ce080bb118b1 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5381,133 +5381,164 @@ Test_meth_coexist_impl(TestObj *self) /*[clinic end generated code: output=7edf4e95b29f06fa input=2a1d75b5e6fec6dd]*/ /*[clinic input] -@getter -Test.property +@setter +@deleter +Test.settable [clinic start generated code]*/ -#if !defined(Test_property_DOCSTR) -# define Test_property_DOCSTR NULL -#endif -#if defined(TEST_PROPERTY_GETSETDEF) -# undef TEST_PROPERTY_GETSETDEF -# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR}, -#else -# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, Test_property_DOCSTR}, -#endif +static int +Test_settable_set_impl(TestObj *self, PyObject *value); -static PyObject * -Test_property_get_impl(TestObj *self); +static int +Test_settable_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) +{ + int return_value = -1; + PyObject *value = NULL; + + if (arg != NULL) { + value = arg; + } + return_value = Test_settable_set_impl((TestObj *)self, value); + + return return_value; +} + +static int +Test_settable_set_impl(TestObj *self, PyObject *value) +/*[clinic end generated code: output=46832806d93e5391 input=c5e1780ba116abdc]*/ + +/*[clinic input] +@getter +Test.int_property -> int +[clinic start generated code]*/ + +static int +Test_int_property_get_impl(TestObj *self); static PyObject * -Test_property_get(PyObject *self, void *Py_UNUSED(context)) +Test_int_property_get(PyObject *self, void *Py_UNUSED(context)) { - return Test_property_get_impl((TestObj *)self); + PyObject *return_value = NULL; + int _return_value; + + _return_value = Test_int_property_get_impl((TestObj *)self); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyLong_FromLong((long)_return_value); + +exit: + return return_value; } -static PyObject * -Test_property_get_impl(TestObj *self) -/*[clinic end generated code: output=b38d68abd3466a6e input=2d92b3449fbc7d2b]*/ +static int +Test_int_property_get_impl(TestObj *self) +/*[clinic end generated code: output=0d0b1028eefad645 input=d9617980a2010b06]*/ /*[clinic input] @setter -Test.property +Test.int_property + value: int [clinic start generated code]*/ -#if !defined(Test_property_DOCSTR) -# define Test_property_DOCSTR NULL -#endif -#if defined(TEST_PROPERTY_GETSETDEF) -# undef TEST_PROPERTY_GETSETDEF -# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR}, -#else -# define TEST_PROPERTY_GETSETDEF {"property", NULL, (setter)Test_property_set, NULL}, -#endif - static int -Test_property_set_impl(TestObj *self, PyObject *value); +Test_int_property_set_impl(TestObj *self, int value); static int -Test_property_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +Test_int_property_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + int value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, - "attribute 'property' of '%.100s' objects cannot be deleted", + "attribute 'int_property' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } - return_value = Test_property_set_impl((TestObj *)self, value); + value = PyLong_AsInt(arg); + if (value == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = Test_int_property_set_impl((TestObj *)self, value); +exit: return return_value; } static int -Test_property_set_impl(TestObj *self, PyObject *value) -/*[clinic end generated code: output=ec103a151cf51d25 input=3bc3f46a23c83a88]*/ +Test_int_property_set_impl(TestObj *self, int value) +/*[clinic end generated code: output=75d998b3c5aabb83 input=3830ff9462d00c65]*/ /*[clinic input] -@setter -@deleter -Test.settable_and_deletable +@getter +Test.property [clinic start generated code]*/ -#if !defined(Test_settable_and_deletable_DOCSTR) -# define Test_settable_and_deletable_DOCSTR NULL -#endif -#if defined(TEST_SETTABLE_AND_DELETABLE_GETSETDEF) -# undef TEST_SETTABLE_AND_DELETABLE_GETSETDEF -# define TEST_SETTABLE_AND_DELETABLE_GETSETDEF {"settable_and_deletable", (getter)Test_settable_and_deletable_get, (setter)Test_settable_and_deletable_set, Test_settable_and_deletable_DOCSTR}, -#else -# define TEST_SETTABLE_AND_DELETABLE_GETSETDEF {"settable_and_deletable", NULL, (setter)Test_settable_and_deletable_set, NULL}, -#endif +static PyObject * +Test_property_get_impl(TestObj *self); + +static PyObject * +Test_property_get(PyObject *self, void *Py_UNUSED(context)) +{ + return Test_property_get_impl((TestObj *)self); +} + +static PyObject * +Test_property_get_impl(TestObj *self) +/*[clinic end generated code: output=2b6f95ae685a9efc input=2d92b3449fbc7d2b]*/ + +/*[clinic input] +@setter +Test.property +[clinic start generated code]*/ static int -Test_settable_and_deletable_set_impl(TestObj *self, PyObject *value); +Test_property_set_impl(TestObj *self, PyObject *value); static int -Test_settable_and_deletable_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +Test_property_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - return_value = Test_settable_and_deletable_set_impl((TestObj *)self, value); + if (arg == NULL) { + PyErr_Format(PyExc_AttributeError, + "attribute 'property' of '%.100s' objects cannot be deleted", + Py_TYPE(self)->tp_name); + return -1; + } + value = arg; + return_value = Test_property_set_impl((TestObj *)self, value); return return_value; } static int -Test_settable_and_deletable_set_impl(TestObj *self, PyObject *value) -/*[clinic end generated code: output=479986d499b2f56d input=f5647f3511b9daea]*/ +Test_property_set_impl(TestObj *self, PyObject *value) +/*[clinic end generated code: output=b54a80ff88efca4c input=3bc3f46a23c83a88]*/ /*[clinic input] @setter Test.setter_first_with_docstr [clinic start generated code]*/ -#if !defined(Test_setter_first_with_docstr_DOCSTR) -# define Test_setter_first_with_docstr_DOCSTR NULL -#endif -#if defined(TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF) -# undef TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF -# define TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF {"setter_first_with_docstr", (getter)Test_setter_first_with_docstr_get, (setter)Test_setter_first_with_docstr_set, Test_setter_first_with_docstr_DOCSTR}, -#else -# define TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF {"setter_first_with_docstr", NULL, (setter)Test_setter_first_with_docstr_set, NULL}, -#endif - static int Test_setter_first_with_docstr_set_impl(TestObj *self, PyObject *value); static int -Test_setter_first_with_docstr_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +Test_setter_first_with_docstr_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'setter_first_with_docstr' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; return_value = Test_setter_first_with_docstr_set_impl((TestObj *)self, value); return return_value; @@ -5515,7 +5546,7 @@ Test_setter_first_with_docstr_set(PyObject *self, PyObject *value, void *Py_UNUS static int Test_setter_first_with_docstr_set_impl(TestObj *self, PyObject *value) -/*[clinic end generated code: output=eac8bafcaa50aa51 input=31a045ce11bbe961]*/ +/*[clinic end generated code: output=fdd579cfe3b261e4 input=31a045ce11bbe961]*/ /*[clinic input] @getter @@ -5526,20 +5557,6 @@ my silly docstring PyDoc_STRVAR(Test_setter_first_with_docstr__doc__, "my silly docstring"); -#if defined(Test_setter_first_with_docstr_DOCSTR) -# undef Test_setter_first_with_docstr_DOCSTR -#endif -#define Test_setter_first_with_docstr_DOCSTR Test_setter_first_with_docstr__doc__ - -#if !defined(Test_setter_first_with_docstr_DOCSTR) -# define Test_setter_first_with_docstr_DOCSTR NULL -#endif -#if defined(TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF) -# undef TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF -# define TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF {"setter_first_with_docstr", (getter)Test_setter_first_with_docstr_get, (setter)Test_setter_first_with_docstr_set, Test_setter_first_with_docstr_DOCSTR}, -#else -# define TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF {"setter_first_with_docstr", (getter)Test_setter_first_with_docstr_get, NULL, Test_setter_first_with_docstr_DOCSTR}, -#endif static PyObject * Test_setter_first_with_docstr_get_impl(TestObj *self); @@ -5552,7 +5569,20 @@ Test_setter_first_with_docstr_get(PyObject *self, void *Py_UNUSED(context)) static PyObject * Test_setter_first_with_docstr_get_impl(TestObj *self) -/*[clinic end generated code: output=fe6e3aa844a24920 input=10af4e43b3cb34dc]*/ +/*[clinic end generated code: output=e93e3e68b0473d74 input=10af4e43b3cb34dc]*/ + +/*[clinic input] +dump buffer +[clinic start generated code]*/ +#define TEST_SETTABLE_GETSETDEF {"settable", (getter)NULL, (setter)Test_settable_set, NULL}, + +#define TEST_INT_PROPERTY_GETSETDEF {"int_property", (getter)Test_int_property_get, (setter)Test_int_property_set, NULL}, + +#define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL}, + +#define TEST_SETTER_FIRST_WITH_DOCSTR_GETSETDEF {"setter_first_with_docstr", (getter)Test_setter_first_with_docstr_get, (setter)Test_setter_first_with_docstr_set, Test_setter_first_with_docstr__doc__}, + +/*[clinic end generated code: output=011497a4f5a2e835 input=524ce2e021e4eba6]*/ /*[clinic input] output push @@ -6395,3 +6425,13 @@ static PyObject * test_critical_section_object2_impl(PyObject *module, PyObject *a, PyObject *b) /*[clinic end generated code: output=d73a1657c18df17a input=638824e41419a466]*/ + +/*[clinic input] +dump buffer +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=524ce2e021e4eba6]*/ + +/*[clinic input] +dump buffer +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=524ce2e021e4eba6]*/ diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index f0dc62967f6a776..621be2cec7bc093 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -20,7 +20,8 @@ with test_tools.imports_under_tool('clinic'): import libclinic from libclinic import ClinicError, unspecified, NULL, fail - from libclinic.converters import int_converter, str_converter, self_converter + from libclinic.converters import ( + int_converter, object_converter, str_converter, self_converter) from libclinic.function import ( Module, Class, Function, FunctionKind, Parameter, permute_optional_groups, permute_right_option_groups, @@ -794,10 +795,22 @@ def test_ignore_preprocessor_in_comments(self): """) self.clinic.parse(raw) + def test_var_keyword_non_dict(self): + err = "'var_keyword_object' is not a valid converter" + block = """ + /*[clinic input] + my_test_func + + **kwds: object + [clinic start generated code]*/ + """ + self.expect_failure(block, err, lineno=4) + def test_getset_in_ifdef(self): block = """ /*[clinic input] output everything block + output methoddef_ifndef buffer class Foo "FooObject *" "&Foo_Type" [clinic start generated code]*/ #ifdef CONDITION @@ -808,54 +821,117 @@ class Foo "FooObject *" "&Foo_Type" /*[clinic input] @setter Foo.property + value: object [clinic start generated code]*/ #endif + /*[clinic input] + dump buffer + [clinic start generated code]*/ """ generated = self.clinic.parse(dedent(block)) self.assertIn("#if defined(CONDITION)", generated) # The getset is undefined if the condition is false. - self.assertIn("#ifndef FOO_PROPERTY_GETSETDEF\n" - " #define FOO_PROPERTY_GETSETDEF\n" - "#endif /* !defined(FOO_PROPERTY_GETSETDEF) */", + self.assertIn("#else\n" + "# define FOO_PROPERTY_GETSETDEF\n" + "#endif", generated) - def test_getset_duplicate(self): - for annotation in "@getter", "@setter": - with self.subTest(annotation=annotation): - self.clinic = _make_clinic(filename="test.c") - block = f""" - /*[clinic input] - class Foo "FooObject *" "&Foo_Type" - [clinic start generated code]*/ - /*[clinic input] - {annotation} - Foo.property - [clinic start generated code]*/ - /*[clinic input] - {annotation} - Foo.property - [clinic start generated code]*/ - """ - kind = 'setter' if annotation == '@setter' else 'getter' - err = f"Cannot apply @{kind} to 'Foo.property' twice" - self.expect_failure(block, err, lineno=10) + def test_getset_partially_in_ifdef(self): + block = """ + /*[clinic input] + output everything block + output methoddef_ifndef buffer + class Foo "FooObject *" "&Foo_Type" + [clinic start generated code]*/ + #ifdef CONDITION + /*[clinic input] + @getter + Foo.property + [clinic start generated code]*/ + #endif + /*[clinic input] + @setter + Foo.property + value: object + [clinic start generated code]*/ + /*[clinic input] + dump buffer + [clinic start generated code]*/ + """ + generated = self.clinic.parse(dedent(block)) + # Only the conditional getter announces itself. + self.assertIn("#if defined(CONDITION)\n" + "\n" + "#define FOO_PROPERTY_GETTER Foo_property_get\n", + generated) + self.assertIn("#define FOO_PROPERTY_SETTER Foo_property_set\n" + "#if defined(FOO_PROPERTY_GETTER) " + "|| defined(FOO_PROPERTY_SETTER)", + generated) + self.assertIn('# define FOO_PROPERTY_GETSETDEF {"property", ' + '(getter)FOO_PROPERTY_GETTER, ' + '(setter)FOO_PROPERTY_SETTER, FOO_PROPERTY_DOCSTR},', + generated) - def test_getset_different_c_basename(self): + def test_getset_several_implementations(self): block = """ /*[clinic input] + output everything block + output methoddef_ifndef buffer class Foo "FooObject *" "&Foo_Type" [clinic start generated code]*/ + #ifdef CONDITION /*[clinic input] @getter - Foo.property as foo_get + Foo.property as foo_property_special + [clinic start generated code]*/ + #else + /*[clinic input] + @getter + Foo.property as foo_property_generic + [clinic start generated code]*/ + #endif + /*[clinic input] + dump buffer + [clinic start generated code]*/ + """ + # Implementations guarded by preprocessor conditions can share the + # entry; which of them is compiled is only known to the preprocessor. + generated = self.clinic.parse(dedent(block)) + self.assertIn("#if defined(CONDITION)\n" + "\n" + "#define FOO_PROPERTY_GETTER " + "foo_property_special_get\n", + generated) + self.assertIn("#if !defined(CONDITION)\n" + "\n" + "#define FOO_PROPERTY_GETTER " + "foo_property_generic_get\n", + generated) + + def test_getset_after_dump(self): + block = """ + /*[clinic input] + output everything block + output methoddef_ifndef buffer + class Foo "FooObject *" "&Foo_Type" + [clinic start generated code]*/ + /*[clinic input] + @getter + Foo.property + [clinic start generated code]*/ + /*[clinic input] + dump buffer [clinic start generated code]*/ /*[clinic input] @setter - Foo.property as foo_set + Foo.property + value: object [clinic start generated code]*/ """ - err = "The accessors of 'Foo.property' must have the same C basename" - self.expect_failure(block, err, lineno=10) + err = ("All accessors of 'Foo.property' must be defined before " + "its PyGetSetDef entry is dumped") + self.expect_failure(block, err, lineno=15) def test_setter_deletion_check(self): block = """ @@ -866,10 +942,11 @@ class Foo "FooObject *" "&Foo_Type" /*[clinic input] @setter Foo.property + value: object [clinic start generated code]*/ """ generated = self.clinic.parse(dedent(block)) - self.assertIn("if (value == NULL) {", generated) + self.assertIn("if (arg == NULL) {", generated) self.assertIn("\"attribute 'property' of '%.100s' objects " "cannot be deleted\"", generated) @@ -885,21 +962,65 @@ class Foo "FooObject *" "&Foo_Type" @setter @deleter Foo.property + value: object = NULL [clinic start generated code]*/ """ generated = self.clinic.parse(dedent(block)) - self.assertNotIn("if (value == NULL) {", generated) + self.assertNotIn("if (arg == NULL) {", generated) - def test_var_keyword_non_dict(self): - err = "'var_keyword_object' is not a valid converter" + def test_getset_duplicate(self): + # Only a setter defines the new value. + for annotation, parameter, err in ( + ("@getter", "", "Cannot apply @getter to 'Foo.property' twice"), + ("@setter", "value: object", + "The setter of 'Foo.property' is already defined"), + ): + with self.subTest(annotation=annotation): + self.clinic = _make_clinic(filename="test.c") + block = f""" + /*[clinic input] + class Foo "FooObject *" "&Foo_Type" + [clinic start generated code]*/ + /*[clinic input] + {annotation} + Foo.property + {parameter} + [clinic start generated code]*/ + /*[clinic input] + {annotation} + Foo.property + {parameter} + [clinic start generated code]*/ + """ + self.expect_failure(block, err, lineno=11) + + def test_getset_different_c_basename(self): block = """ /*[clinic input] - my_test_func - - **kwds: object + output everything block + output methoddef_ifndef buffer + class Foo "FooObject *" "&Foo_Type" + [clinic start generated code]*/ + /*[clinic input] + @getter + Foo.property as foo_get + [clinic start generated code]*/ + /*[clinic input] + @setter + Foo.property as foo_set + value: object + [clinic start generated code]*/ + /*[clinic input] + dump buffer [clinic start generated code]*/ """ - self.expect_failure(block, err, lineno=4) + # The accessors are identified by the Python name, not by the + # C basename. + generated = self.clinic.parse(dedent(block)) + self.assertIn('#define FOO_PROPERTY_GETSETDEF {"property", ' + '(getter)foo_get_get, (setter)foo_set_set, NULL},', + generated) + class ParseFileUnitTest(TestCase): def expect_parsing_failure( @@ -2758,29 +2879,120 @@ class Foo "" "" self.expect_failure(block, expected_error, lineno=1) def test_invalid_getset(self): - annotations = ["@getter", "@setter"] - for annotation in annotations: - with self.subTest(annotation=annotation): + block = """ + module foo + class Foo "" "" + @setter + Foo.property -> int + """ + expected_error = "@setter methods cannot define a return type" + self.expect_failure(block, expected_error, lineno=3) + + block = """ + module foo + class Foo "" "" + @getter + Foo.property + obj: int + / + """ + expected_error = "@getter methods cannot define parameters" + self.expect_failure(block, expected_error) + + block = """ + module foo + class Foo "" "" + @setter + Foo.property + obj: int + value: int + / + """ + expected_error = "@setter methods must define exactly one parameter" + self.expect_failure(block, expected_error) + + def test_setter_value_default(self): + block = """ + module m + class Foo "" "" + @setter + Foo.property + value: object = None + """ + expected_error = "the value of @setter cannot have a default value" + self.expect_failure(block, expected_error) + + block = """ + module m + class Foo "" "" + @setter + @deleter + Foo.property + value: object + """ + expected_error = ("the value of @setter with @deleter must have " + "a default value, used to delete the attribute") + self.expect_failure(block, expected_error) + + def test_setter_value_kind(self): + expected_error = "the value of @setter must be a positional parameter" + block = """ + module m + class Foo "" "" + @setter + Foo.property + + * + value: object + """ + self.expect_failure(block, expected_error) + + for parameter in "*args: tuple", "**kwargs: dict": + with self.subTest(parameter=parameter): block = f""" - module foo + module m class Foo "" "" - {annotation} - Foo.property -> int - """ - expected_error = "@getter and @setter methods cannot define a return type" - self.expect_failure(block, expected_error, lineno=3) + @setter + Foo.property - block = f""" - module foo - class Foo "" "" - {annotation} - Foo.property - obj: int - / + {parameter} """ - expected_error = "@getter and @setter methods cannot define parameters" self.expect_failure(block, expected_error) + def test_setter_implicit_parameter(self): + function = self.parse_function(""" + module foo + class Foo "" "" + @setter + Foo.property + """, signatures_in_block=3, function_index=2) + self.assertEqual(function.kind, FunctionKind.SETTER) + value = function.parameters['value'] + self.assertIsInstance(value.converter, object_converter) + self.assertIs(value.default, unspecified) + + def test_setter_and_deleter_implicit_parameter(self): + function = self.parse_function(""" + module foo + class Foo "" "" + @setter + @deleter + Foo.property + """, signatures_in_block=3, function_index=2) + self.assertEqual(function.kind, FunctionKind.SETTER_AND_DELETER) + value = function.parameters['value'] + self.assertIsInstance(value.converter, object_converter) + self.assertIs(value.default, NULL) + + def test_getter_return_converter(self): + function = self.parse_function(""" + module foo + class Foo "" "" + @getter + Foo.property -> int + """, signatures_in_block=3, function_index=2) + self.assertEqual(function.return_converter.type, "int") + def test_setter_docstring(self): block = """ module foo @@ -2793,7 +3005,7 @@ class Foo "" "" bar [clinic start generated code]*/ """ - expected_error = "docstrings are only supported for @getter, not @setter" + expected_error = "docstrings are only supported for @getter" self.expect_failure(block, expected_error) def test_duplicate_getset(self): @@ -2821,8 +3033,8 @@ class Foo "" "" {dup[1]} Foo.property -> int """ - expected_error = (f"Can't set {dup[1]}, " - f"function is not a normal callable") + expected_error = (f"Can't set {dup[1]}, function is not " + f"a normal callable") self.expect_failure(block, expected_error, lineno=3) def test_deleter_without_setter(self): @@ -2856,16 +3068,6 @@ class Foo "" "" expected_error = "Cannot apply @deleter twice to the same function!" self.expect_failure(block, expected_error, lineno=4) - def test_setter_and_deleter(self): - function = self.parse_function(""" - module foo - class Foo "" "" - @setter - @deleter - Foo.property - """, signatures_in_block=3, function_index=2) - self.assertEqual(function.kind, FunctionKind.SETTER_AND_DELETER) - def test_getset_no_class(self): for annotation in "@getter", "@setter": with self.subTest(annotation=annotation): diff --git a/Misc/NEWS.d/next/Tools-Demos/2026-08-14-13-15-35.gh-issue-113318.oHjvUR.rst b/Misc/NEWS.d/next/Tools-Demos/2026-08-14-13-15-35.gh-issue-113318.oHjvUR.rst new file mode 100644 index 000000000000000..5af26352642a6ed --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2026-08-14-13-15-35.gh-issue-113318.oHjvUR.rst @@ -0,0 +1,7 @@ +The value of a setter generated by Argument Clinic is now a parameter, which +can use a converter, and a getter can define a return converter. +It is optional to declare the value of the setter. +The accessors of the same attribute are now identified by the Python name of +that attribute instead of the C basename, so they can use different C +basenames, and several implementations of the same accessor can be defined +in different preprocessor conditional blocks. diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index a380f8ac72b32f4..8c98ba51d24ee81 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -1354,85 +1354,67 @@ _asyncio_Future__asyncio_awaited_by_get_impl(FutureObj *self) /*[clinic input] @critical_section @getter -_asyncio.Future._asyncio_future_blocking +_asyncio.Future._asyncio_future_blocking -> bool [clinic start generated code]*/ -static PyObject * +static int _asyncio_Future__asyncio_future_blocking_get_impl(FutureObj *self) -/*[clinic end generated code: output=a558a2c51e38823b input=58da92efc03b617d]*/ +/*[clinic end generated code: output=32944de3df031979 input=2a51a0cf31a96826]*/ { - if (future_is_alive(self) && self->fut_blocking) { - Py_RETURN_TRUE; - } - else { - Py_RETURN_FALSE; - } + return future_is_alive(self) && self->fut_blocking; } /*[clinic input] @critical_section @setter _asyncio.Future._asyncio_future_blocking + value: bool [clinic start generated code]*/ static int -_asyncio_Future__asyncio_future_blocking_set_impl(FutureObj *self, - PyObject *value) -/*[clinic end generated code: output=0686d1cb024a7453 input=3fd4a5f95df788b7]*/ - +_asyncio_Future__asyncio_future_blocking_set_impl(FutureObj *self, int value) +/*[clinic end generated code: output=be2d5cb1cad6dd30 input=81780cb7b89f28e1]*/ { if (future_ensure_alive(self)) { return -1; } - - int is_true = PyObject_IsTrue(value); - if (is_true < 0) { - return -1; - } - self->fut_blocking = is_true; + self->fut_blocking = value; return 0; } /*[clinic input] @critical_section @getter -_asyncio.Future._log_traceback +_asyncio.Future._log_traceback -> bool [clinic start generated code]*/ -static PyObject * +static int _asyncio_Future__log_traceback_get_impl(FutureObj *self) -/*[clinic end generated code: output=2724433b238593c7 input=91e5144ea4117d8e]*/ +/*[clinic end generated code: output=ba1356634182ac25 input=50f4db8eca9d1fb4]*/ { - asyncio_state *state = get_asyncio_state_by_def((PyObject *)self); - ENSURE_FUTURE_ALIVE(state, self) - if (self->fut_log_tb) { - Py_RETURN_TRUE; - } - else { - Py_RETURN_FALSE; + if (future_ensure_alive(self)) { + return -1; } + return self->fut_log_tb; } /*[clinic input] @critical_section @setter _asyncio.Future._log_traceback + value: bool [clinic start generated code]*/ static int -_asyncio_Future__log_traceback_set_impl(FutureObj *self, PyObject *value) -/*[clinic end generated code: output=9ce8e19504f42f54 input=30ac8217754b08c2]*/ +_asyncio_Future__log_traceback_set_impl(FutureObj *self, int value) +/*[clinic end generated code: output=ad84ae67ef80e3ad input=30c0f841c945c73f]*/ { - int is_true = PyObject_IsTrue(value); - if (is_true < 0) { - return -1; - } - if (is_true) { + if (value) { PyErr_SetString(PyExc_ValueError, "_log_traceback can only be set to False"); return -1; } - self->fut_log_tb = is_true; + self->fut_log_tb = value; return 0; } /*[clinic input] @@ -2413,36 +2395,28 @@ TaskObj_traverse(PyObject *op, visitproc visit, void *arg) /*[clinic input] @critical_section @getter -_asyncio.Task._log_destroy_pending +_asyncio.Task._log_destroy_pending -> bool [clinic start generated code]*/ -static PyObject * +static int _asyncio_Task__log_destroy_pending_get_impl(TaskObj *self) -/*[clinic end generated code: output=e6c2a47d029ac93b input=17127298cd4c720b]*/ +/*[clinic end generated code: output=98b5f7bad24a2381 input=a87002bdf72e380b]*/ { - if (self->task_log_destroy_pending) { - Py_RETURN_TRUE; - } - else { - Py_RETURN_FALSE; - } + return self->task_log_destroy_pending; } /*[clinic input] @critical_section @setter _asyncio.Task._log_destroy_pending + value: bool [clinic start generated code]*/ static int -_asyncio_Task__log_destroy_pending_set_impl(TaskObj *self, PyObject *value) -/*[clinic end generated code: output=7ebc030bb92ec5ce input=49b759c97d1216a4]*/ +_asyncio_Task__log_destroy_pending_set_impl(TaskObj *self, int value) +/*[clinic end generated code: output=132bbf2b4c627777 input=533fea7776daa075]*/ { - int is_true = PyObject_IsTrue(value); - if (is_true < 0) { - return -1; - } - self->task_log_destroy_pending = is_true; + self->task_log_destroy_pending = value; return 0; } diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 034f26807f84aa8..d9fa9adaf32c597 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -600,12 +600,11 @@ _ctypes_CType_Type___pointer_type___get_impl(PyObject *self) @setter @deleter _ctypes.CType_Type.__pointer_type__ - [clinic start generated code]*/ static int _ctypes_CType_Type___pointer_type___set_impl(PyObject *self, PyObject *value) -/*[clinic end generated code: output=6259be8ea21693fa input=7e24bceb1676349b]*/ +/*[clinic end generated code: output=6259be8ea21693fa input=07e8b7a8fcc1efc1]*/ { ctypes_state *st = get_module_state_by_def(Py_TYPE(self)); StgInfo *info; @@ -1482,33 +1481,20 @@ class _ctypes.PyCArrayType_Type "CDataObject *" "clinic_state()->PyCArrayType_Ty @critical_section @setter _ctypes.PyCArrayType_Type.raw + value: Py_buffer [clinic start generated code]*/ static int -_ctypes_PyCArrayType_Type_raw_set_impl(CDataObject *self, PyObject *value) -/*[clinic end generated code: output=cf9b2a9fd92e9ecb input=a3717561efc45efd]*/ +_ctypes_PyCArrayType_Type_raw_set_impl(CDataObject *self, Py_buffer *value) +/*[clinic end generated code: output=273e537dc31f4bbd input=90775c9408b1bb59]*/ { - char *ptr; - Py_ssize_t size; - Py_buffer view; - - if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0) - return -1; - size = view.len; - ptr = view.buf; - if (size > self->b_size) { + if (value->len > self->b_size) { PyErr_SetString(PyExc_ValueError, "byte string too long"); - goto fail; + return -1; } - - memcpy(self->b_ptr, ptr, size); - - PyBuffer_Release(&view); + memcpy(self->b_ptr, value->buf, value->len); return 0; - fail: - PyBuffer_Release(&view); - return -1; } /*[clinic input] @@ -1549,42 +1535,30 @@ _ctypes_PyCArrayType_Type_value_get_impl(CDataObject *self) @setter @deleter _ctypes.PyCArrayType_Type.value + value: object(subclass_of='&PyBytes_Type', type='PyBytesObject *') = NULL [clinic start generated code]*/ static int -_ctypes_PyCArrayType_Type_value_set_impl(CDataObject *self, PyObject *value) -/*[clinic end generated code: output=39ad655636a28dd5 input=167f0935cbb8d489]*/ +_ctypes_PyCArrayType_Type_value_set_impl(CDataObject *self, + PyBytesObject *value) +/*[clinic end generated code: output=21cbd436230dc33e input=d35228bbfb2f5228]*/ { - const char *ptr; - Py_ssize_t size; - if (value == NULL) { PyErr_SetString(PyExc_TypeError, "can't delete attribute"); return -1; } - if (!PyBytes_Check(value)) { - PyErr_Format(PyExc_TypeError, - "bytes expected instead of %s instance", - Py_TYPE(value)->tp_name); - return -1; - } else - Py_INCREF(value); - size = PyBytes_GET_SIZE(value); + Py_ssize_t size = PyBytes_GET_SIZE(value); if (size > self->b_size) { PyErr_SetString(PyExc_ValueError, "byte string too long"); - Py_DECREF(value); return -1; } - ptr = PyBytes_AS_STRING(value); - memcpy(self->b_ptr, ptr, size); + memcpy(self->b_ptr, PyBytes_AS_STRING(value), size); if (size < self->b_size) self->b_ptr[size] = '\0'; - Py_DECREF(value); - return 0; } diff --git a/Modules/_ctypes/clinic/_ctypes.c.h b/Modules/_ctypes/clinic/_ctypes.c.h index 221b110cd15d2de..c017a45f70c95ad 100644 --- a/Modules/_ctypes/clinic/_ctypes.c.h +++ b/Modules/_ctypes/clinic/_ctypes.c.h @@ -31,16 +31,6 @@ _ctypes_CType_Type___sizeof__(PyObject *self, PyTypeObject *cls, PyObject *const return _ctypes_CType_Type___sizeof___impl(self, cls); } -#if !defined(_ctypes_CType_Type___pointer_type___DOCSTR) -# define _ctypes_CType_Type___pointer_type___DOCSTR NULL -#endif -#if defined(_CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF) -# undef _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF -# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, (setter)_ctypes_CType_Type___pointer_type___set, _ctypes_CType_Type___pointer_type___DOCSTR}, -#else -# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, NULL, _ctypes_CType_Type___pointer_type___DOCSTR}, -#endif - static PyObject * _ctypes_CType_Type___pointer_type___get_impl(PyObject *self); @@ -50,24 +40,18 @@ _ctypes_CType_Type___pointer_type___get(PyObject *self, void *Py_UNUSED(context) return _ctypes_CType_Type___pointer_type___get_impl(self); } -#if !defined(_ctypes_CType_Type___pointer_type___DOCSTR) -# define _ctypes_CType_Type___pointer_type___DOCSTR NULL -#endif -#if defined(_CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF) -# undef _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF -# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, (setter)_ctypes_CType_Type___pointer_type___set, _ctypes_CType_Type___pointer_type___DOCSTR}, -#else -# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", NULL, (setter)_ctypes_CType_Type___pointer_type___set, NULL}, -#endif - static int _ctypes_CType_Type___pointer_type___set_impl(PyObject *self, PyObject *value); static int -_ctypes_CType_Type___pointer_type___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ctypes_CType_Type___pointer_type___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } return_value = _ctypes_CType_Type___pointer_type___set_impl(self, value); return return_value; @@ -459,47 +443,37 @@ PyCPointerType_from_param(PyObject *type, PyTypeObject *cls, PyObject *const *ar return return_value; } -#if !defined(_ctypes_PyCArrayType_Type_raw_DOCSTR) -# define _ctypes_PyCArrayType_Type_raw_DOCSTR NULL -#endif -#if defined(_CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF) -# undef _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF -# define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", (getter)_ctypes_PyCArrayType_Type_raw_get, (setter)_ctypes_PyCArrayType_Type_raw_set, _ctypes_PyCArrayType_Type_raw_DOCSTR}, -#else -# define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", NULL, (setter)_ctypes_PyCArrayType_Type_raw_set, NULL}, -#endif - static int -_ctypes_PyCArrayType_Type_raw_set_impl(CDataObject *self, PyObject *value); +_ctypes_PyCArrayType_Type_raw_set_impl(CDataObject *self, Py_buffer *value); static int -_ctypes_PyCArrayType_Type_raw_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ctypes_PyCArrayType_Type_raw_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + Py_buffer value = {NULL, NULL}; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'raw' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + if (PyObject_GetBuffer(arg, &value, PyBUF_SIMPLE) != 0) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); - return_value = _ctypes_PyCArrayType_Type_raw_set_impl((CDataObject *)self, value); + return_value = _ctypes_PyCArrayType_Type_raw_set_impl((CDataObject *)self, &value); Py_END_CRITICAL_SECTION(); +exit: + /* Cleanup for value */ + if (value.obj) { + PyBuffer_Release(&value); + } + return return_value; } -#if !defined(_ctypes_PyCArrayType_Type_raw_DOCSTR) -# define _ctypes_PyCArrayType_Type_raw_DOCSTR NULL -#endif -#if defined(_CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF) -# undef _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF -# define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", (getter)_ctypes_PyCArrayType_Type_raw_get, (setter)_ctypes_PyCArrayType_Type_raw_set, _ctypes_PyCArrayType_Type_raw_DOCSTR}, -#else -# define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", (getter)_ctypes_PyCArrayType_Type_raw_get, NULL, _ctypes_PyCArrayType_Type_raw_DOCSTR}, -#endif - static PyObject * _ctypes_PyCArrayType_Type_raw_get_impl(CDataObject *self); @@ -515,16 +489,6 @@ _ctypes_PyCArrayType_Type_raw_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ctypes_PyCArrayType_Type_value_DOCSTR) -# define _ctypes_PyCArrayType_Type_value_DOCSTR NULL -#endif -#if defined(_CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF) -# undef _CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF -# define _CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF {"value", (getter)_ctypes_PyCArrayType_Type_value_get, (setter)_ctypes_PyCArrayType_Type_value_set, _ctypes_PyCArrayType_Type_value_DOCSTR}, -#else -# define _CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF {"value", (getter)_ctypes_PyCArrayType_Type_value_get, NULL, _ctypes_PyCArrayType_Type_value_DOCSTR}, -#endif - static PyObject * _ctypes_PyCArrayType_Type_value_get_impl(CDataObject *self); @@ -540,28 +504,28 @@ _ctypes_PyCArrayType_Type_value_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ctypes_PyCArrayType_Type_value_DOCSTR) -# define _ctypes_PyCArrayType_Type_value_DOCSTR NULL -#endif -#if defined(_CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF) -# undef _CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF -# define _CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF {"value", (getter)_ctypes_PyCArrayType_Type_value_get, (setter)_ctypes_PyCArrayType_Type_value_set, _ctypes_PyCArrayType_Type_value_DOCSTR}, -#else -# define _CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF {"value", NULL, (setter)_ctypes_PyCArrayType_Type_value_set, NULL}, -#endif - static int -_ctypes_PyCArrayType_Type_value_set_impl(CDataObject *self, PyObject *value); +_ctypes_PyCArrayType_Type_value_set_impl(CDataObject *self, + PyBytesObject *value); static int -_ctypes_PyCArrayType_Type_value_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ctypes_PyCArrayType_Type_value_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyBytesObject *value = NULL; + if (arg != NULL) { + if (!PyBytes_Check(arg)) { + PyErr_Format(PyExc_TypeError, "attribute 'value' must be bytes, not %T", arg); + goto exit; + } + value = (PyBytesObject *)arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ctypes_PyCArrayType_Type_value_set_impl((CDataObject *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } @@ -817,24 +781,18 @@ _ctypes_PyCData___ctypes_from_outparam__(PyObject *self, PyObject *Py_UNUSED(ign return _ctypes_PyCData___ctypes_from_outparam___impl(self); } -#if !defined(_ctypes_CFuncPtr_errcheck_DOCSTR) -# define _ctypes_CFuncPtr_errcheck_DOCSTR NULL -#endif -#if defined(_CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF) -# undef _CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF -# define _CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF {"errcheck", (getter)_ctypes_CFuncPtr_errcheck_get, (setter)_ctypes_CFuncPtr_errcheck_set, _ctypes_CFuncPtr_errcheck_DOCSTR}, -#else -# define _CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF {"errcheck", NULL, (setter)_ctypes_CFuncPtr_errcheck_set, NULL}, -#endif - static int _ctypes_CFuncPtr_errcheck_set_impl(PyCFuncPtrObject *self, PyObject *value); static int -_ctypes_CFuncPtr_errcheck_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ctypes_CFuncPtr_errcheck_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ctypes_CFuncPtr_errcheck_set_impl((PyCFuncPtrObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -844,20 +802,6 @@ _ctypes_CFuncPtr_errcheck_set(PyObject *self, PyObject *value, void *Py_UNUSED(c PyDoc_STRVAR(_ctypes_CFuncPtr_errcheck__doc__, "a function to check for errors"); -#if defined(_ctypes_CFuncPtr_errcheck_DOCSTR) -# undef _ctypes_CFuncPtr_errcheck_DOCSTR -#endif -#define _ctypes_CFuncPtr_errcheck_DOCSTR _ctypes_CFuncPtr_errcheck__doc__ - -#if !defined(_ctypes_CFuncPtr_errcheck_DOCSTR) -# define _ctypes_CFuncPtr_errcheck_DOCSTR NULL -#endif -#if defined(_CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF) -# undef _CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF -# define _CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF {"errcheck", (getter)_ctypes_CFuncPtr_errcheck_get, (setter)_ctypes_CFuncPtr_errcheck_set, _ctypes_CFuncPtr_errcheck_DOCSTR}, -#else -# define _CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF {"errcheck", (getter)_ctypes_CFuncPtr_errcheck_get, NULL, _ctypes_CFuncPtr_errcheck_DOCSTR}, -#endif static PyObject * _ctypes_CFuncPtr_errcheck_get_impl(PyCFuncPtrObject *self); @@ -874,24 +818,18 @@ _ctypes_CFuncPtr_errcheck_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ctypes_CFuncPtr_restype_DOCSTR) -# define _ctypes_CFuncPtr_restype_DOCSTR NULL -#endif -#if defined(_CTYPES_CFUNCPTR_RESTYPE_GETSETDEF) -# undef _CTYPES_CFUNCPTR_RESTYPE_GETSETDEF -# define _CTYPES_CFUNCPTR_RESTYPE_GETSETDEF {"restype", (getter)_ctypes_CFuncPtr_restype_get, (setter)_ctypes_CFuncPtr_restype_set, _ctypes_CFuncPtr_restype_DOCSTR}, -#else -# define _CTYPES_CFUNCPTR_RESTYPE_GETSETDEF {"restype", NULL, (setter)_ctypes_CFuncPtr_restype_set, NULL}, -#endif - static int _ctypes_CFuncPtr_restype_set_impl(PyCFuncPtrObject *self, PyObject *value); static int -_ctypes_CFuncPtr_restype_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ctypes_CFuncPtr_restype_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ctypes_CFuncPtr_restype_set_impl((PyCFuncPtrObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -901,20 +839,6 @@ _ctypes_CFuncPtr_restype_set(PyObject *self, PyObject *value, void *Py_UNUSED(co PyDoc_STRVAR(_ctypes_CFuncPtr_restype__doc__, "specify the result type"); -#if defined(_ctypes_CFuncPtr_restype_DOCSTR) -# undef _ctypes_CFuncPtr_restype_DOCSTR -#endif -#define _ctypes_CFuncPtr_restype_DOCSTR _ctypes_CFuncPtr_restype__doc__ - -#if !defined(_ctypes_CFuncPtr_restype_DOCSTR) -# define _ctypes_CFuncPtr_restype_DOCSTR NULL -#endif -#if defined(_CTYPES_CFUNCPTR_RESTYPE_GETSETDEF) -# undef _CTYPES_CFUNCPTR_RESTYPE_GETSETDEF -# define _CTYPES_CFUNCPTR_RESTYPE_GETSETDEF {"restype", (getter)_ctypes_CFuncPtr_restype_get, (setter)_ctypes_CFuncPtr_restype_set, _ctypes_CFuncPtr_restype_DOCSTR}, -#else -# define _CTYPES_CFUNCPTR_RESTYPE_GETSETDEF {"restype", (getter)_ctypes_CFuncPtr_restype_get, NULL, _ctypes_CFuncPtr_restype_DOCSTR}, -#endif static PyObject * _ctypes_CFuncPtr_restype_get_impl(PyCFuncPtrObject *self); @@ -931,24 +855,18 @@ _ctypes_CFuncPtr_restype_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ctypes_CFuncPtr_argtypes_DOCSTR) -# define _ctypes_CFuncPtr_argtypes_DOCSTR NULL -#endif -#if defined(_CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF) -# undef _CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF -# define _CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF {"argtypes", (getter)_ctypes_CFuncPtr_argtypes_get, (setter)_ctypes_CFuncPtr_argtypes_set, _ctypes_CFuncPtr_argtypes_DOCSTR}, -#else -# define _CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF {"argtypes", NULL, (setter)_ctypes_CFuncPtr_argtypes_set, NULL}, -#endif - static int _ctypes_CFuncPtr_argtypes_set_impl(PyCFuncPtrObject *self, PyObject *value); static int -_ctypes_CFuncPtr_argtypes_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ctypes_CFuncPtr_argtypes_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ctypes_CFuncPtr_argtypes_set_impl((PyCFuncPtrObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -958,20 +876,6 @@ _ctypes_CFuncPtr_argtypes_set(PyObject *self, PyObject *value, void *Py_UNUSED(c PyDoc_STRVAR(_ctypes_CFuncPtr_argtypes__doc__, "specify the argument types"); -#if defined(_ctypes_CFuncPtr_argtypes_DOCSTR) -# undef _ctypes_CFuncPtr_argtypes_DOCSTR -#endif -#define _ctypes_CFuncPtr_argtypes_DOCSTR _ctypes_CFuncPtr_argtypes__doc__ - -#if !defined(_ctypes_CFuncPtr_argtypes_DOCSTR) -# define _ctypes_CFuncPtr_argtypes_DOCSTR NULL -#endif -#if defined(_CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF) -# undef _CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF -# define _CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF {"argtypes", (getter)_ctypes_CFuncPtr_argtypes_get, (setter)_ctypes_CFuncPtr_argtypes_set, _ctypes_CFuncPtr_argtypes_DOCSTR}, -#else -# define _CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF {"argtypes", (getter)_ctypes_CFuncPtr_argtypes_get, NULL, _ctypes_CFuncPtr_argtypes_DOCSTR}, -#endif static PyObject * _ctypes_CFuncPtr_argtypes_get_impl(PyCFuncPtrObject *self); @@ -988,24 +892,18 @@ _ctypes_CFuncPtr_argtypes_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ctypes_Simple_value_DOCSTR) -# define _ctypes_Simple_value_DOCSTR NULL -#endif -#if defined(_CTYPES_SIMPLE_VALUE_GETSETDEF) -# undef _CTYPES_SIMPLE_VALUE_GETSETDEF -# define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, _ctypes_Simple_value_DOCSTR}, -#else -# define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", NULL, (setter)_ctypes_Simple_value_set, NULL}, -#endif - static int _ctypes_Simple_value_set_impl(CDataObject *self, PyObject *value); static int -_ctypes_Simple_value_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ctypes_Simple_value_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ctypes_Simple_value_set_impl((CDataObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -1013,16 +911,6 @@ _ctypes_Simple_value_set(PyObject *self, PyObject *value, void *Py_UNUSED(contex return return_value; } -#if !defined(_ctypes_Simple_value_DOCSTR) -# define _ctypes_Simple_value_DOCSTR NULL -#endif -#if defined(_CTYPES_SIMPLE_VALUE_GETSETDEF) -# undef _CTYPES_SIMPLE_VALUE_GETSETDEF -# define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, _ctypes_Simple_value_DOCSTR}, -#else -# define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, NULL, _ctypes_Simple_value_DOCSTR}, -#endif - static PyObject * _ctypes_Simple_value_get_impl(CDataObject *self); @@ -1058,4 +946,18 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py } return Simple_from_outparm_impl(self, cls); } -/*[clinic end generated code: output=b89feb50c654de3f input=a9049054013a1b77]*/ +#define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, (setter)_ctypes_CType_Type___pointer_type___set, NULL}, + +#define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", (getter)_ctypes_PyCArrayType_Type_raw_get, (setter)_ctypes_PyCArrayType_Type_raw_set, NULL}, + +#define _CTYPES_PYCARRAYTYPE_TYPE_VALUE_GETSETDEF {"value", (getter)_ctypes_PyCArrayType_Type_value_get, (setter)_ctypes_PyCArrayType_Type_value_set, NULL}, + +#define _CTYPES_CFUNCPTR_ERRCHECK_GETSETDEF {"errcheck", (getter)_ctypes_CFuncPtr_errcheck_get, (setter)_ctypes_CFuncPtr_errcheck_set, _ctypes_CFuncPtr_errcheck__doc__}, + +#define _CTYPES_CFUNCPTR_RESTYPE_GETSETDEF {"restype", (getter)_ctypes_CFuncPtr_restype_get, (setter)_ctypes_CFuncPtr_restype_set, _ctypes_CFuncPtr_restype__doc__}, + +#define _CTYPES_CFUNCPTR_ARGTYPES_GETSETDEF {"argtypes", (getter)_ctypes_CFuncPtr_argtypes_get, (setter)_ctypes_CFuncPtr_argtypes_set, _ctypes_CFuncPtr_argtypes__doc__}, + +#define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL}, + +/*[clinic end generated code: output=eaeb783d3d700160 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index b7c0ca2c4b919b6..3ca28c5a390736b 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -343,16 +343,6 @@ _io__Buffered_simple_flush(PyObject *self, PyObject *Py_UNUSED(ignored)) return return_value; } -#if !defined(_io__Buffered_closed_DOCSTR) -# define _io__Buffered_closed_DOCSTR NULL -#endif -#if defined(_IO__BUFFERED_CLOSED_GETSETDEF) -# undef _IO__BUFFERED_CLOSED_GETSETDEF -# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)_io__Buffered_closed_set, _io__Buffered_closed_DOCSTR}, -#else -# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, NULL, _io__Buffered_closed_DOCSTR}, -#endif - static PyObject * _io__Buffered_closed_get_impl(buffered *self); @@ -483,16 +473,6 @@ _io__Buffered_writable(PyObject *self, PyObject *Py_UNUSED(ignored)) return return_value; } -#if !defined(_io__Buffered_name_DOCSTR) -# define _io__Buffered_name_DOCSTR NULL -#endif -#if defined(_IO__BUFFERED_NAME_GETSETDEF) -# undef _IO__BUFFERED_NAME_GETSETDEF -# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)_io__Buffered_name_set, _io__Buffered_name_DOCSTR}, -#else -# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, NULL, _io__Buffered_name_DOCSTR}, -#endif - static PyObject * _io__Buffered_name_get_impl(buffered *self); @@ -508,16 +488,6 @@ _io__Buffered_name_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io__Buffered_mode_DOCSTR) -# define _io__Buffered_mode_DOCSTR NULL -#endif -#if defined(_IO__BUFFERED_MODE_GETSETDEF) -# undef _IO__BUFFERED_MODE_GETSETDEF -# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)_io__Buffered_mode_set, _io__Buffered_mode_DOCSTR}, -#else -# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, NULL, _io__Buffered_mode_DOCSTR}, -#endif - static PyObject * _io__Buffered_mode_get_impl(buffered *self); @@ -1265,4 +1235,10 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=3ee17211d2010462 input=a9049054013a1b77]*/ +#define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)NULL, NULL}, + +#define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)NULL, NULL}, + +#define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)NULL, NULL}, + +/*[clinic end generated code: output=cac02514680dfc60 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index d6d4afb9b63c624..e9c6c39dc64b049 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -477,16 +477,6 @@ _io_StringIO___setstate__(PyObject *self, PyObject *state) return return_value; } -#if !defined(_io_StringIO_closed_DOCSTR) -# define _io_StringIO_closed_DOCSTR NULL -#endif -#if defined(_IO_STRINGIO_CLOSED_GETSETDEF) -# undef _IO_STRINGIO_CLOSED_GETSETDEF -# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, (setter)_io_StringIO_closed_set, _io_StringIO_closed_DOCSTR}, -#else -# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, NULL, _io_StringIO_closed_DOCSTR}, -#endif - static PyObject * _io_StringIO_closed_get_impl(stringio *self); @@ -502,16 +492,6 @@ _io_StringIO_closed_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io_StringIO_line_buffering_DOCSTR) -# define _io_StringIO_line_buffering_DOCSTR NULL -#endif -#if defined(_IO_STRINGIO_LINE_BUFFERING_GETSETDEF) -# undef _IO_STRINGIO_LINE_BUFFERING_GETSETDEF -# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, (setter)_io_StringIO_line_buffering_set, _io_StringIO_line_buffering_DOCSTR}, -#else -# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, _io_StringIO_line_buffering_DOCSTR}, -#endif - static PyObject * _io_StringIO_line_buffering_get_impl(stringio *self); @@ -527,16 +507,6 @@ _io_StringIO_line_buffering_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io_StringIO_newlines_DOCSTR) -# define _io_StringIO_newlines_DOCSTR NULL -#endif -#if defined(_IO_STRINGIO_NEWLINES_GETSETDEF) -# undef _IO_STRINGIO_NEWLINES_GETSETDEF -# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)_io_StringIO_newlines_set, _io_StringIO_newlines_DOCSTR}, -#else -# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, NULL, _io_StringIO_newlines_DOCSTR}, -#endif - static PyObject * _io_StringIO_newlines_get_impl(stringio *self); @@ -551,4 +521,10 @@ _io_StringIO_newlines_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -/*[clinic end generated code: output=730c34b2a6c0500b input=a9049054013a1b77]*/ +#define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, (setter)NULL, NULL}, + +#define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, (setter)NULL, NULL}, + +#define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)NULL, NULL}, + +/*[clinic end generated code: output=6fa0c0dd69543304 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 10d0f1390cccbb4..f782ec197146636 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -209,20 +209,6 @@ PyDoc_STRVAR(_io__TextIOBase_encoding__doc__, "Encoding of the text stream.\n" "\n" "Subclasses should override."); -#if defined(_io__TextIOBase_encoding_DOCSTR) -# undef _io__TextIOBase_encoding_DOCSTR -#endif -#define _io__TextIOBase_encoding_DOCSTR _io__TextIOBase_encoding__doc__ - -#if !defined(_io__TextIOBase_encoding_DOCSTR) -# define _io__TextIOBase_encoding_DOCSTR NULL -#endif -#if defined(_IO__TEXTIOBASE_ENCODING_GETSETDEF) -# undef _IO__TEXTIOBASE_ENCODING_GETSETDEF -# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, (setter)_io__TextIOBase_encoding_set, _io__TextIOBase_encoding_DOCSTR}, -#else -# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, NULL, _io__TextIOBase_encoding_DOCSTR}, -#endif static PyObject * _io__TextIOBase_encoding_get_impl(PyObject *self); @@ -239,20 +225,6 @@ PyDoc_STRVAR(_io__TextIOBase_newlines__doc__, "Only line endings translated during reading are considered.\n" "\n" "Subclasses should override."); -#if defined(_io__TextIOBase_newlines_DOCSTR) -# undef _io__TextIOBase_newlines_DOCSTR -#endif -#define _io__TextIOBase_newlines_DOCSTR _io__TextIOBase_newlines__doc__ - -#if !defined(_io__TextIOBase_newlines_DOCSTR) -# define _io__TextIOBase_newlines_DOCSTR NULL -#endif -#if defined(_IO__TEXTIOBASE_NEWLINES_GETSETDEF) -# undef _IO__TEXTIOBASE_NEWLINES_GETSETDEF -# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, (setter)_io__TextIOBase_newlines_set, _io__TextIOBase_newlines_DOCSTR}, -#else -# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, NULL, _io__TextIOBase_newlines_DOCSTR}, -#endif static PyObject * _io__TextIOBase_newlines_get_impl(PyObject *self); @@ -267,20 +239,6 @@ PyDoc_STRVAR(_io__TextIOBase_errors__doc__, "The error setting of the decoder or encoder.\n" "\n" "Subclasses should override."); -#if defined(_io__TextIOBase_errors_DOCSTR) -# undef _io__TextIOBase_errors_DOCSTR -#endif -#define _io__TextIOBase_errors_DOCSTR _io__TextIOBase_errors__doc__ - -#if !defined(_io__TextIOBase_errors_DOCSTR) -# define _io__TextIOBase_errors_DOCSTR NULL -#endif -#if defined(_IO__TEXTIOBASE_ERRORS_GETSETDEF) -# undef _IO__TEXTIOBASE_ERRORS_GETSETDEF -# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, (setter)_io__TextIOBase_errors_set, _io__TextIOBase_errors_DOCSTR}, -#else -# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, NULL, _io__TextIOBase_errors_DOCSTR}, -#endif static PyObject * _io__TextIOBase_errors_get_impl(PyObject *self); @@ -1182,16 +1140,6 @@ _io_TextIOWrapper_close(PyObject *self, PyObject *Py_UNUSED(ignored)) return return_value; } -#if !defined(_io_TextIOWrapper_name_DOCSTR) -# define _io_TextIOWrapper_name_DOCSTR NULL -#endif -#if defined(_IO_TEXTIOWRAPPER_NAME_GETSETDEF) -# undef _IO_TEXTIOWRAPPER_NAME_GETSETDEF -# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)_io_TextIOWrapper_name_set, _io_TextIOWrapper_name_DOCSTR}, -#else -# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, NULL, _io_TextIOWrapper_name_DOCSTR}, -#endif - static PyObject * _io_TextIOWrapper_name_get_impl(textio *self); @@ -1207,16 +1155,6 @@ _io_TextIOWrapper_name_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io_TextIOWrapper_closed_DOCSTR) -# define _io_TextIOWrapper_closed_DOCSTR NULL -#endif -#if defined(_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF) -# undef _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF -# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)_io_TextIOWrapper_closed_set, _io_TextIOWrapper_closed_DOCSTR}, -#else -# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, NULL, _io_TextIOWrapper_closed_DOCSTR}, -#endif - static PyObject * _io_TextIOWrapper_closed_get_impl(textio *self); @@ -1232,16 +1170,6 @@ _io_TextIOWrapper_closed_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io_TextIOWrapper_newlines_DOCSTR) -# define _io_TextIOWrapper_newlines_DOCSTR NULL -#endif -#if defined(_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF) -# undef _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF -# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)_io_TextIOWrapper_newlines_set, _io_TextIOWrapper_newlines_DOCSTR}, -#else -# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, NULL, _io_TextIOWrapper_newlines_DOCSTR}, -#endif - static PyObject * _io_TextIOWrapper_newlines_get_impl(textio *self); @@ -1257,16 +1185,6 @@ _io_TextIOWrapper_newlines_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io_TextIOWrapper_errors_DOCSTR) -# define _io_TextIOWrapper_errors_DOCSTR NULL -#endif -#if defined(_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF) -# undef _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF -# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)_io_TextIOWrapper_errors_set, _io_TextIOWrapper_errors_DOCSTR}, -#else -# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, NULL, _io_TextIOWrapper_errors_DOCSTR}, -#endif - static PyObject * _io_TextIOWrapper_errors_get_impl(textio *self); @@ -1282,16 +1200,6 @@ _io_TextIOWrapper_errors_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io_TextIOWrapper__CHUNK_SIZE_DOCSTR) -# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL -#endif -#if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) -# undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE_DOCSTR}, -#else -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, NULL, _io_TextIOWrapper__CHUNK_SIZE_DOCSTR}, -#endif - static PyObject * _io_TextIOWrapper__CHUNK_SIZE_get_impl(textio *self); @@ -1307,30 +1215,22 @@ _io_TextIOWrapper__CHUNK_SIZE_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_io_TextIOWrapper__CHUNK_SIZE_DOCSTR) -# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL -#endif -#if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) -# undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE_DOCSTR}, -#else -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", NULL, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL}, -#endif - static int _io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, PyObject *value); static int -_io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute '_CHUNK_SIZE' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _io_TextIOWrapper__CHUNK_SIZE_set_impl((textio *)self, value); Py_END_CRITICAL_SECTION(); @@ -1338,16 +1238,6 @@ _io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *value, void *Py_UNUS return return_value; } -#if !defined(_io_TextIOWrapper_buffer_DOCSTR) -# define _io_TextIOWrapper_buffer_DOCSTR NULL -#endif -#if defined(_IO_TEXTIOWRAPPER_BUFFER_GETSETDEF) -# undef _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF -# define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)_io_TextIOWrapper_buffer_set, _io_TextIOWrapper_buffer_DOCSTR}, -#else -# define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, NULL, _io_TextIOWrapper_buffer_DOCSTR}, -#endif - static PyObject * _io_TextIOWrapper_buffer_get_impl(textio *self); @@ -1362,4 +1252,22 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -/*[clinic end generated code: output=e93032a0691ff0e4 input=a9049054013a1b77]*/ +#define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, (setter)NULL, _io__TextIOBase_encoding__doc__}, + +#define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, (setter)NULL, _io__TextIOBase_newlines__doc__}, + +#define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, (setter)NULL, _io__TextIOBase_errors__doc__}, + +#define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)NULL, NULL}, + +#define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)NULL, NULL}, + +#define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)NULL, NULL}, + +#define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)NULL, NULL}, + +#define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL}, + +#define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL}, + +/*[clinic end generated code: output=72ad4f1b23cc606f input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h index 689466b1c2b85a1..fcefc6535393b25 100644 --- a/Modules/_sqlite/clinic/cursor.c.h +++ b/Modules/_sqlite/clinic/cursor.c.h @@ -330,16 +330,6 @@ pysqlite_cursor_close(PyObject *self, PyObject *Py_UNUSED(ignored)) return pysqlite_cursor_close_impl((pysqlite_Cursor *)self); } -#if !defined(_sqlite3_Cursor_arraysize_DOCSTR) -# define _sqlite3_Cursor_arraysize_DOCSTR NULL -#endif -#if defined(_SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF) -# undef _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF -# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, (setter)_sqlite3_Cursor_arraysize_set, _sqlite3_Cursor_arraysize_DOCSTR}, -#else -# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, NULL, _sqlite3_Cursor_arraysize_DOCSTR}, -#endif - static PyObject * _sqlite3_Cursor_arraysize_get_impl(pysqlite_Cursor *self); @@ -349,32 +339,29 @@ _sqlite3_Cursor_arraysize_get(PyObject *self, void *Py_UNUSED(context)) return _sqlite3_Cursor_arraysize_get_impl((pysqlite_Cursor *)self); } -#if !defined(_sqlite3_Cursor_arraysize_DOCSTR) -# define _sqlite3_Cursor_arraysize_DOCSTR NULL -#endif -#if defined(_SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF) -# undef _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF -# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, (setter)_sqlite3_Cursor_arraysize_set, _sqlite3_Cursor_arraysize_DOCSTR}, -#else -# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", NULL, (setter)_sqlite3_Cursor_arraysize_set, NULL}, -#endif - static int -_sqlite3_Cursor_arraysize_set_impl(pysqlite_Cursor *self, PyObject *value); +_sqlite3_Cursor_arraysize_set_impl(pysqlite_Cursor *self, uint32_t value); static int -_sqlite3_Cursor_arraysize_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_sqlite3_Cursor_arraysize_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + uint32_t value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'arraysize' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + if (!_PyLong_UInt32_Converter(arg, &value)) { + goto exit; + } return_value = _sqlite3_Cursor_arraysize_set_impl((pysqlite_Cursor *)self, value); +exit: return return_value; } -/*[clinic end generated code: output=e7b20358f8213fd7 input=a9049054013a1b77]*/ +#define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, (setter)_sqlite3_Cursor_arraysize_set, NULL}, + +/*[clinic end generated code: output=e920343d84bd4976 input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 5a61e43617984d9..382953efb1cea2c 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -1372,13 +1372,15 @@ _sqlite3_Cursor_arraysize_get_impl(pysqlite_Cursor *self) /*[clinic input] @setter _sqlite3.Cursor.arraysize + value: uint32 [clinic start generated code]*/ static int -_sqlite3_Cursor_arraysize_set_impl(pysqlite_Cursor *self, PyObject *value) -/*[clinic end generated code: output=af59a6b09f8cce6e input=ace48cb114e26060]*/ +_sqlite3_Cursor_arraysize_set_impl(pysqlite_Cursor *self, uint32_t value) +/*[clinic end generated code: output=465c2db6df904802 input=80234ca4ec5cfb7c]*/ { - return PyLong_AsUInt32(value, &self->arraysize); + self->arraysize = value; + return 0; } static PyMethodDef cursor_methods[] = { diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 9f8a6a58cd9327e..ab6fd979bb3a90f 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -3973,12 +3973,12 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self, /*[clinic input] @critical_section @getter -_ssl._SSLContext.verify_mode +_ssl._SSLContext.verify_mode -> int [clinic start generated code]*/ -static PyObject * +static int _ssl__SSLContext_verify_mode_get_impl(PySSLContext *self) -/*[clinic end generated code: output=3e788736cc7229bc input=7e3c7f4454121d0a]*/ +/*[clinic end generated code: output=f588c0dc5c0bc414 input=9f74370037133ac3]*/ { /* ignore SSL_VERIFY_CLIENT_ONCE and SSL_VERIFY_POST_HANDSHAKE */ int mask = (SSL_VERIFY_NONE | SSL_VERIFY_PEER | @@ -3986,72 +3986,69 @@ _ssl__SSLContext_verify_mode_get_impl(PySSLContext *self) int verify_mode = SSL_CTX_get_verify_mode(self->ctx); switch (verify_mode & mask) { case SSL_VERIFY_NONE: - return PyLong_FromLong(PY_SSL_CERT_NONE); + return PY_SSL_CERT_NONE; case SSL_VERIFY_PEER: - return PyLong_FromLong(PY_SSL_CERT_OPTIONAL); + return PY_SSL_CERT_OPTIONAL; case SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT: - return PyLong_FromLong(PY_SSL_CERT_REQUIRED); + return PY_SSL_CERT_REQUIRED; } PyErr_SetString(get_state_ctx(self)->PySSLErrorObject, "invalid return value from SSL_CTX_get_verify_mode"); - return NULL; + return -1; } /*[clinic input] @critical_section @setter _ssl._SSLContext.verify_mode + value: int [clinic start generated code]*/ static int -_ssl__SSLContext_verify_mode_set_impl(PySSLContext *self, PyObject *value) -/*[clinic end generated code: output=d698e16c58db3118 input=3ee60057c3a22378]*/ +_ssl__SSLContext_verify_mode_set_impl(PySSLContext *self, int value) +/*[clinic end generated code: output=5ca6ec88aa4faed0 input=cb53415e79047735]*/ { - int n; - if (!PyArg_Parse(value, "i", &n)) - return -1; - if (n == PY_SSL_CERT_NONE && self->check_hostname) { + if (value == PY_SSL_CERT_NONE && self->check_hostname) { PyErr_SetString(PyExc_ValueError, "Cannot set verify_mode to CERT_NONE when " "check_hostname is enabled."); return -1; } - return _set_verify_mode(self, n); + return _set_verify_mode(self, value); } /*[clinic input] @critical_section @getter -_ssl._SSLContext.verify_flags +_ssl._SSLContext.verify_flags -> unsigned_long [clinic start generated code]*/ -static PyObject * +static unsigned long _ssl__SSLContext_verify_flags_get_impl(PySSLContext *self) -/*[clinic end generated code: output=fbbf8ba28ad6e56e input=c1ec36d610b3f391]*/ +/*[clinic end generated code: output=65df79ad8808f85d input=8a60274c619c3d29]*/ { X509_VERIFY_PARAM *ssl_verification_params; - unsigned long flags; ssl_verification_params = SSL_CTX_get0_param(self->ctx); - flags = X509_VERIFY_PARAM_get_flags(ssl_verification_params); - return PyLong_FromUnsignedLong(flags); + return X509_VERIFY_PARAM_get_flags(ssl_verification_params); } /*[clinic input] @critical_section @setter _ssl._SSLContext.verify_flags + value: unsigned_long(bitwise=True) [clinic start generated code]*/ static int -_ssl__SSLContext_verify_flags_set_impl(PySSLContext *self, PyObject *value) -/*[clinic end generated code: output=a3e3b2a0ce6c2e99 input=b2a0c42583d4f34e]*/ +_ssl__SSLContext_verify_flags_set_impl(PySSLContext *self, + unsigned long value) +/*[clinic end generated code: output=3a0dc3da11d16fc0 input=45ca63f1bfe14386]*/ { X509_VERIFY_PARAM *ssl_verification_params; - unsigned long new_flags, flags, set, clear; + unsigned long new_flags = value; + unsigned long flags, set, clear; - if (!PyArg_Parse(value, "k", &new_flags)) - return -1; ssl_verification_params = SSL_CTX_get0_param(self->ctx); flags = X509_VERIFY_PARAM_get_flags(ssl_verification_params); clear = flags & ~new_flags; @@ -4241,15 +4238,14 @@ _ssl__SSLContext_num_tickets_get_impl(PySSLContext *self) @critical_section @setter _ssl._SSLContext.num_tickets + value: long [clinic start generated code]*/ static int -_ssl__SSLContext_num_tickets_set_impl(PySSLContext *self, PyObject *value) -/*[clinic end generated code: output=ced81b46f3beab09 input=6ef8067ac55607e7]*/ +_ssl__SSLContext_num_tickets_set_impl(PySSLContext *self, long value) +/*[clinic end generated code: output=c2c97071a729b0ff input=6f7531a9d9cd4570]*/ { - long num; - if (!PyArg_Parse(value, "l", &num)) - return -1; + long num = value; if (num < 0) { PyErr_SetString(PyExc_ValueError, "value must be non-negative"); return -1; @@ -4301,11 +4297,13 @@ _ssl__SSLContext_options_get_impl(PySSLContext *self) @critical_section @setter _ssl._SSLContext.options + value: unsigned_long_long [clinic start generated code]*/ static int -_ssl__SSLContext_options_set_impl(PySSLContext *self, PyObject *value) -/*[clinic end generated code: output=92ca34731ece5dbb input=2b94bf789e9ae5dd]*/ +_ssl__SSLContext_options_set_impl(PySSLContext *self, + unsigned long long value) +/*[clinic end generated code: output=9bf1e7bf9ab9c49b input=143105581d4dfc86]*/ { unsigned long long new_opts_arg; uint64_t new_opts, opts, clear, set; @@ -4314,9 +4312,7 @@ _ssl__SSLContext_options_set_impl(PySSLContext *self, PyObject *value) SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3 ); - if (!PyArg_Parse(value, "O&", _PyLong_UnsignedLongLong_Converter, &new_opts_arg)) { - return -1; - } + new_opts_arg = value; Py_BUILD_ASSERT(sizeof(new_opts) >= sizeof(new_opts_arg)); new_opts = (uint64_t)new_opts_arg; @@ -4342,36 +4338,32 @@ _ssl__SSLContext_options_set_impl(PySSLContext *self, PyObject *value) /*[clinic input] @critical_section @getter -_ssl._SSLContext._host_flags +_ssl._SSLContext._host_flags -> unsigned_int [clinic start generated code]*/ -static PyObject * +static unsigned int _ssl__SSLContext__host_flags_get_impl(PySSLContext *self) -/*[clinic end generated code: output=0f9db6654ce32582 input=8e3c49499eefd0e5]*/ +/*[clinic end generated code: output=86ddaf5eeea5f355 input=1ccf5ae9b37de139]*/ { X509_VERIFY_PARAM *ssl_verification_params; - unsigned int host_flags; ssl_verification_params = SSL_CTX_get0_param(self->ctx); - host_flags = X509_VERIFY_PARAM_get_hostflags(ssl_verification_params); - return PyLong_FromUnsignedLong(host_flags); + return X509_VERIFY_PARAM_get_hostflags(ssl_verification_params); } /*[clinic input] @critical_section @setter _ssl._SSLContext._host_flags + value: unsigned_int(bitwise=True) [clinic start generated code]*/ static int -_ssl__SSLContext__host_flags_set_impl(PySSLContext *self, PyObject *value) -/*[clinic end generated code: output=1ed6f4027aaf2e3e input=28caf1fb9c32f6cb]*/ +_ssl__SSLContext__host_flags_set_impl(PySSLContext *self, unsigned int value) +/*[clinic end generated code: output=9986c48e63e6ba3e input=36d1b89df2884d81]*/ { X509_VERIFY_PARAM *ssl_verification_params; - unsigned int new_flags = 0; - - if (!PyArg_Parse(value, "I", &new_flags)) - return -1; + unsigned int new_flags = value; ssl_verification_params = SSL_CTX_get0_param(self->ctx); X509_VERIFY_PARAM_set_hostflags(ssl_verification_params, new_flags); @@ -4381,29 +4373,28 @@ _ssl__SSLContext__host_flags_set_impl(PySSLContext *self, PyObject *value) /*[clinic input] @critical_section @getter -_ssl._SSLContext.check_hostname +_ssl._SSLContext.check_hostname -> bool [clinic start generated code]*/ -static PyObject * +static int _ssl__SSLContext_check_hostname_get_impl(PySSLContext *self) -/*[clinic end generated code: output=e046d6eeefc76063 input=1b8341e705f9ecf5]*/ +/*[clinic end generated code: output=a5772c7e90e32c1d input=d5ae97abc5e0fb0b]*/ { - return PyBool_FromLong(self->check_hostname); + return self->check_hostname; } /*[clinic input] @critical_section @setter _ssl._SSLContext.check_hostname + value: bool [clinic start generated code]*/ static int -_ssl__SSLContext_check_hostname_set_impl(PySSLContext *self, PyObject *value) -/*[clinic end generated code: output=0e767b4784e7dc3f input=e6a771cb5919f74d]*/ +_ssl__SSLContext_check_hostname_set_impl(PySSLContext *self, int value) +/*[clinic end generated code: output=323bb94d7b54d471 input=9134aa868194a6c3]*/ { - int check_hostname; - if (!PyArg_Parse(value, "p", &check_hostname)) - return -1; + int check_hostname = value; int verify_mode = check_hostname ? SSL_CTX_get_verify_mode(self->ctx) : 0; if (check_hostname && verify_mode == SSL_VERIFY_NONE) { diff --git a/Modules/_zstd/clinic/decompressor.c.h b/Modules/_zstd/clinic/decompressor.c.h index fe3b76b8bb369df..83431363621ad64 100644 --- a/Modules/_zstd/clinic/decompressor.c.h +++ b/Modules/_zstd/clinic/decompressor.c.h @@ -93,20 +93,6 @@ PyDoc_STRVAR(_zstd_ZstdDecompressor_unused_data__doc__, "When ZstdDecompressor object stops after a frame is\n" "decompressed, unused input data after the frame. Otherwise this\n" "will be b\'\'."); -#if defined(_zstd_ZstdDecompressor_unused_data_DOCSTR) -# undef _zstd_ZstdDecompressor_unused_data_DOCSTR -#endif -#define _zstd_ZstdDecompressor_unused_data_DOCSTR _zstd_ZstdDecompressor_unused_data__doc__ - -#if !defined(_zstd_ZstdDecompressor_unused_data_DOCSTR) -# define _zstd_ZstdDecompressor_unused_data_DOCSTR NULL -#endif -#if defined(_ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF) -# undef _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF -# define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, (setter)_zstd_ZstdDecompressor_unused_data_set, _zstd_ZstdDecompressor_unused_data_DOCSTR}, -#else -# define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, NULL, _zstd_ZstdDecompressor_unused_data_DOCSTR}, -#endif static PyObject * _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self); @@ -222,4 +208,6 @@ _zstd_ZstdDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssiz return return_value; } -/*[clinic end generated code: output=70bc308e86463751 input=a9049054013a1b77]*/ +#define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, (setter)NULL, _zstd_ZstdDecompressor_unused_data__doc__}, + +/*[clinic end generated code: output=91b84afb07b1188c input=a9049054013a1b77]*/ diff --git a/Modules/_zstd/clinic/zstddict.c.h b/Modules/_zstd/clinic/zstddict.c.h index 18b049e3cbe37ef..30a1ed8ea9bfa8a 100644 --- a/Modules/_zstd/clinic/zstddict.c.h +++ b/Modules/_zstd/clinic/zstddict.c.h @@ -95,20 +95,6 @@ _zstd_ZstdDict_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) PyDoc_STRVAR(_zstd_ZstdDict_dict_content__doc__, "The content of a Zstandard dictionary, as a bytes object."); -#if defined(_zstd_ZstdDict_dict_content_DOCSTR) -# undef _zstd_ZstdDict_dict_content_DOCSTR -#endif -#define _zstd_ZstdDict_dict_content_DOCSTR _zstd_ZstdDict_dict_content__doc__ - -#if !defined(_zstd_ZstdDict_dict_content_DOCSTR) -# define _zstd_ZstdDict_dict_content_DOCSTR NULL -#endif -#if defined(_ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF) -# undef _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF -# define _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF {"dict_content", (getter)_zstd_ZstdDict_dict_content_get, (setter)_zstd_ZstdDict_dict_content_set, _zstd_ZstdDict_dict_content_DOCSTR}, -#else -# define _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF {"dict_content", (getter)_zstd_ZstdDict_dict_content_get, NULL, _zstd_ZstdDict_dict_content_DOCSTR}, -#endif static PyObject * _zstd_ZstdDict_dict_content_get_impl(ZstdDict *self); @@ -131,20 +117,6 @@ PyDoc_STRVAR(_zstd_ZstdDict_as_digested_dict__doc__, " level. It\'s faster when loading again a digested dictionary with\n" " the same compression level.\n" "3. No need to use this for decompression."); -#if defined(_zstd_ZstdDict_as_digested_dict_DOCSTR) -# undef _zstd_ZstdDict_as_digested_dict_DOCSTR -#endif -#define _zstd_ZstdDict_as_digested_dict_DOCSTR _zstd_ZstdDict_as_digested_dict__doc__ - -#if !defined(_zstd_ZstdDict_as_digested_dict_DOCSTR) -# define _zstd_ZstdDict_as_digested_dict_DOCSTR NULL -#endif -#if defined(_ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF) -# undef _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF -# define _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF {"as_digested_dict", (getter)_zstd_ZstdDict_as_digested_dict_get, (setter)_zstd_ZstdDict_as_digested_dict_set, _zstd_ZstdDict_as_digested_dict_DOCSTR}, -#else -# define _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF {"as_digested_dict", (getter)_zstd_ZstdDict_as_digested_dict_get, NULL, _zstd_ZstdDict_as_digested_dict_DOCSTR}, -#endif static PyObject * _zstd_ZstdDict_as_digested_dict_get_impl(ZstdDict *self); @@ -166,20 +138,6 @@ PyDoc_STRVAR(_zstd_ZstdDict_as_undigested_dict__doc__, "2. Loading an undigested dictionary is costly. If load an undigested\n" " dictionary multiple times, consider reusing a compressor object.\n" "3. No need to use this for decompression."); -#if defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR) -# undef _zstd_ZstdDict_as_undigested_dict_DOCSTR -#endif -#define _zstd_ZstdDict_as_undigested_dict_DOCSTR _zstd_ZstdDict_as_undigested_dict__doc__ - -#if !defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR) -# define _zstd_ZstdDict_as_undigested_dict_DOCSTR NULL -#endif -#if defined(_ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF) -# undef _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF -# define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, (setter)_zstd_ZstdDict_as_undigested_dict_set, _zstd_ZstdDict_as_undigested_dict_DOCSTR}, -#else -# define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, NULL, _zstd_ZstdDict_as_undigested_dict_DOCSTR}, -#endif static PyObject * _zstd_ZstdDict_as_undigested_dict_get_impl(ZstdDict *self); @@ -201,20 +159,6 @@ PyDoc_STRVAR(_zstd_ZstdDict_as_prefix__doc__, "2. It only works for the first frame, then the\n" " compressor/decompressor will return to no prefix state.\n" "3. When decompressing, must use the same prefix as when compressing."); -#if defined(_zstd_ZstdDict_as_prefix_DOCSTR) -# undef _zstd_ZstdDict_as_prefix_DOCSTR -#endif -#define _zstd_ZstdDict_as_prefix_DOCSTR _zstd_ZstdDict_as_prefix__doc__ - -#if !defined(_zstd_ZstdDict_as_prefix_DOCSTR) -# define _zstd_ZstdDict_as_prefix_DOCSTR NULL -#endif -#if defined(_ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF) -# undef _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF -# define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, (setter)_zstd_ZstdDict_as_prefix_set, _zstd_ZstdDict_as_prefix_DOCSTR}, -#else -# define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, NULL, _zstd_ZstdDict_as_prefix_DOCSTR}, -#endif static PyObject * _zstd_ZstdDict_as_prefix_get_impl(ZstdDict *self); @@ -224,4 +168,12 @@ _zstd_ZstdDict_as_prefix_get(PyObject *self, void *Py_UNUSED(context)) { return _zstd_ZstdDict_as_prefix_get_impl((ZstdDict *)self); } -/*[clinic end generated code: output=49b66061b4fcdb5f input=a9049054013a1b77]*/ +#define _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF {"dict_content", (getter)_zstd_ZstdDict_dict_content_get, (setter)NULL, _zstd_ZstdDict_dict_content__doc__}, + +#define _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF {"as_digested_dict", (getter)_zstd_ZstdDict_as_digested_dict_get, (setter)NULL, _zstd_ZstdDict_as_digested_dict__doc__}, + +#define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, (setter)NULL, _zstd_ZstdDict_as_undigested_dict__doc__}, + +#define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, (setter)NULL, _zstd_ZstdDict_as_prefix__doc__}, + +/*[clinic end generated code: output=aa4d4b8fd985ae08 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodule.c.h index 14cf5eebc5eec7a..6932dc3ccf17e03 100644 --- a/Modules/clinic/_asynciomodule.c.h +++ b/Modules/clinic/_asynciomodule.c.h @@ -516,16 +516,6 @@ _asyncio_Future_get_loop(PyObject *self, PyTypeObject *cls, PyObject *const *arg return return_value; } -#if !defined(_asyncio_Future__asyncio_awaited_by_DOCSTR) -# define _asyncio_Future__asyncio_awaited_by_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF) -# undef _ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF -# define _ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF {"_asyncio_awaited_by", (getter)_asyncio_Future__asyncio_awaited_by_get, (setter)_asyncio_Future__asyncio_awaited_by_set, _asyncio_Future__asyncio_awaited_by_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF {"_asyncio_awaited_by", (getter)_asyncio_Future__asyncio_awaited_by_get, NULL, _asyncio_Future__asyncio_awaited_by_DOCSTR}, -#endif - static PyObject * _asyncio_Future__asyncio_awaited_by_get_impl(FutureObj *self); @@ -541,129 +531,102 @@ _asyncio_Future__asyncio_awaited_by_get(PyObject *self, void *Py_UNUSED(context) return return_value; } -#if !defined(_asyncio_Future__asyncio_future_blocking_DOCSTR) -# define _asyncio_Future__asyncio_future_blocking_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF) -# undef _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF -# define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", (getter)_asyncio_Future__asyncio_future_blocking_get, (setter)_asyncio_Future__asyncio_future_blocking_set, _asyncio_Future__asyncio_future_blocking_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", (getter)_asyncio_Future__asyncio_future_blocking_get, NULL, _asyncio_Future__asyncio_future_blocking_DOCSTR}, -#endif - -static PyObject * +static int _asyncio_Future__asyncio_future_blocking_get_impl(FutureObj *self); static PyObject * _asyncio_Future__asyncio_future_blocking_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; + int _return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = _asyncio_Future__asyncio_future_blocking_get_impl((FutureObj *)self); + _return_value = _asyncio_Future__asyncio_future_blocking_get_impl((FutureObj *)self); Py_END_CRITICAL_SECTION(); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyBool_FromLong((long)_return_value); +exit: return return_value; } -#if !defined(_asyncio_Future__asyncio_future_blocking_DOCSTR) -# define _asyncio_Future__asyncio_future_blocking_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF) -# undef _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF -# define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", (getter)_asyncio_Future__asyncio_future_blocking_get, (setter)_asyncio_Future__asyncio_future_blocking_set, _asyncio_Future__asyncio_future_blocking_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", NULL, (setter)_asyncio_Future__asyncio_future_blocking_set, NULL}, -#endif - static int -_asyncio_Future__asyncio_future_blocking_set_impl(FutureObj *self, - PyObject *value); +_asyncio_Future__asyncio_future_blocking_set_impl(FutureObj *self, int value); static int -_asyncio_Future__asyncio_future_blocking_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_asyncio_Future__asyncio_future_blocking_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + int value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute '_asyncio_future_blocking' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = PyObject_IsTrue(arg); + if (value < 0) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _asyncio_Future__asyncio_future_blocking_set_impl((FutureObj *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_asyncio_Future__log_traceback_DOCSTR) -# define _asyncio_Future__log_traceback_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF) -# undef _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF -# define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", (getter)_asyncio_Future__log_traceback_get, (setter)_asyncio_Future__log_traceback_set, _asyncio_Future__log_traceback_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", (getter)_asyncio_Future__log_traceback_get, NULL, _asyncio_Future__log_traceback_DOCSTR}, -#endif - -static PyObject * +static int _asyncio_Future__log_traceback_get_impl(FutureObj *self); static PyObject * _asyncio_Future__log_traceback_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; + int _return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = _asyncio_Future__log_traceback_get_impl((FutureObj *)self); + _return_value = _asyncio_Future__log_traceback_get_impl((FutureObj *)self); Py_END_CRITICAL_SECTION(); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyBool_FromLong((long)_return_value); +exit: return return_value; } -#if !defined(_asyncio_Future__log_traceback_DOCSTR) -# define _asyncio_Future__log_traceback_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF) -# undef _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF -# define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", (getter)_asyncio_Future__log_traceback_get, (setter)_asyncio_Future__log_traceback_set, _asyncio_Future__log_traceback_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", NULL, (setter)_asyncio_Future__log_traceback_set, NULL}, -#endif - static int -_asyncio_Future__log_traceback_set_impl(FutureObj *self, PyObject *value); +_asyncio_Future__log_traceback_set_impl(FutureObj *self, int value); static int -_asyncio_Future__log_traceback_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_asyncio_Future__log_traceback_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + int value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute '_log_traceback' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = PyObject_IsTrue(arg); + if (value < 0) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _asyncio_Future__log_traceback_set_impl((FutureObj *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_asyncio_Future__loop_DOCSTR) -# define _asyncio_Future__loop_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__LOOP_GETSETDEF) -# undef _ASYNCIO_FUTURE__LOOP_GETSETDEF -# define _ASYNCIO_FUTURE__LOOP_GETSETDEF {"_loop", (getter)_asyncio_Future__loop_get, (setter)_asyncio_Future__loop_set, _asyncio_Future__loop_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__LOOP_GETSETDEF {"_loop", (getter)_asyncio_Future__loop_get, NULL, _asyncio_Future__loop_DOCSTR}, -#endif - static PyObject * _asyncio_Future__loop_get_impl(FutureObj *self); @@ -679,16 +642,6 @@ _asyncio_Future__loop_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Future__callbacks_DOCSTR) -# define _asyncio_Future__callbacks_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__CALLBACKS_GETSETDEF) -# undef _ASYNCIO_FUTURE__CALLBACKS_GETSETDEF -# define _ASYNCIO_FUTURE__CALLBACKS_GETSETDEF {"_callbacks", (getter)_asyncio_Future__callbacks_get, (setter)_asyncio_Future__callbacks_set, _asyncio_Future__callbacks_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__CALLBACKS_GETSETDEF {"_callbacks", (getter)_asyncio_Future__callbacks_get, NULL, _asyncio_Future__callbacks_DOCSTR}, -#endif - static PyObject * _asyncio_Future__callbacks_get_impl(FutureObj *self); @@ -704,16 +657,6 @@ _asyncio_Future__callbacks_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Future__result_DOCSTR) -# define _asyncio_Future__result_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__RESULT_GETSETDEF) -# undef _ASYNCIO_FUTURE__RESULT_GETSETDEF -# define _ASYNCIO_FUTURE__RESULT_GETSETDEF {"_result", (getter)_asyncio_Future__result_get, (setter)_asyncio_Future__result_set, _asyncio_Future__result_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__RESULT_GETSETDEF {"_result", (getter)_asyncio_Future__result_get, NULL, _asyncio_Future__result_DOCSTR}, -#endif - static PyObject * _asyncio_Future__result_get_impl(FutureObj *self); @@ -729,16 +672,6 @@ _asyncio_Future__result_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Future__exception_DOCSTR) -# define _asyncio_Future__exception_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__EXCEPTION_GETSETDEF) -# undef _ASYNCIO_FUTURE__EXCEPTION_GETSETDEF -# define _ASYNCIO_FUTURE__EXCEPTION_GETSETDEF {"_exception", (getter)_asyncio_Future__exception_get, (setter)_asyncio_Future__exception_set, _asyncio_Future__exception_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__EXCEPTION_GETSETDEF {"_exception", (getter)_asyncio_Future__exception_get, NULL, _asyncio_Future__exception_DOCSTR}, -#endif - static PyObject * _asyncio_Future__exception_get_impl(FutureObj *self); @@ -754,16 +687,6 @@ _asyncio_Future__exception_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Future__source_traceback_DOCSTR) -# define _asyncio_Future__source_traceback_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF) -# undef _ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF -# define _ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF {"_source_traceback", (getter)_asyncio_Future__source_traceback_get, (setter)_asyncio_Future__source_traceback_set, _asyncio_Future__source_traceback_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF {"_source_traceback", (getter)_asyncio_Future__source_traceback_get, NULL, _asyncio_Future__source_traceback_DOCSTR}, -#endif - static PyObject * _asyncio_Future__source_traceback_get_impl(FutureObj *self); @@ -779,16 +702,6 @@ _asyncio_Future__source_traceback_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Future__cancel_message_DOCSTR) -# define _asyncio_Future__cancel_message_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF) -# undef _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF -# define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", (getter)_asyncio_Future__cancel_message_get, (setter)_asyncio_Future__cancel_message_set, _asyncio_Future__cancel_message_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", (getter)_asyncio_Future__cancel_message_get, NULL, _asyncio_Future__cancel_message_DOCSTR}, -#endif - static PyObject * _asyncio_Future__cancel_message_get_impl(FutureObj *self); @@ -804,30 +717,22 @@ _asyncio_Future__cancel_message_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Future__cancel_message_DOCSTR) -# define _asyncio_Future__cancel_message_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF) -# undef _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF -# define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", (getter)_asyncio_Future__cancel_message_get, (setter)_asyncio_Future__cancel_message_set, _asyncio_Future__cancel_message_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", NULL, (setter)_asyncio_Future__cancel_message_set, NULL}, -#endif - static int _asyncio_Future__cancel_message_set_impl(FutureObj *self, PyObject *value); static int -_asyncio_Future__cancel_message_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_asyncio_Future__cancel_message_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute '_cancel_message' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _asyncio_Future__cancel_message_set_impl((FutureObj *)self, value); Py_END_CRITICAL_SECTION(); @@ -835,16 +740,6 @@ _asyncio_Future__cancel_message_set(PyObject *self, PyObject *value, void *Py_UN return return_value; } -#if !defined(_asyncio_Future__state_DOCSTR) -# define _asyncio_Future__state_DOCSTR NULL -#endif -#if defined(_ASYNCIO_FUTURE__STATE_GETSETDEF) -# undef _ASYNCIO_FUTURE__STATE_GETSETDEF -# define _ASYNCIO_FUTURE__STATE_GETSETDEF {"_state", (getter)_asyncio_Future__state_get, (setter)_asyncio_Future__state_set, _asyncio_Future__state_DOCSTR}, -#else -# define _ASYNCIO_FUTURE__STATE_GETSETDEF {"_state", (getter)_asyncio_Future__state_get, NULL, _asyncio_Future__state_DOCSTR}, -#endif - static PyObject * _asyncio_Future__state_get_impl(FutureObj *self); @@ -977,72 +872,54 @@ _asyncio_Task___init__(PyObject *self, PyObject *args, PyObject *kwargs) return return_value; } -#if !defined(_asyncio_Task__log_destroy_pending_DOCSTR) -# define _asyncio_Task__log_destroy_pending_DOCSTR NULL -#endif -#if defined(_ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF) -# undef _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF -# define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", (getter)_asyncio_Task__log_destroy_pending_get, (setter)_asyncio_Task__log_destroy_pending_set, _asyncio_Task__log_destroy_pending_DOCSTR}, -#else -# define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", (getter)_asyncio_Task__log_destroy_pending_get, NULL, _asyncio_Task__log_destroy_pending_DOCSTR}, -#endif - -static PyObject * +static int _asyncio_Task__log_destroy_pending_get_impl(TaskObj *self); static PyObject * _asyncio_Task__log_destroy_pending_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; + int _return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = _asyncio_Task__log_destroy_pending_get_impl((TaskObj *)self); + _return_value = _asyncio_Task__log_destroy_pending_get_impl((TaskObj *)self); Py_END_CRITICAL_SECTION(); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyBool_FromLong((long)_return_value); +exit: return return_value; } -#if !defined(_asyncio_Task__log_destroy_pending_DOCSTR) -# define _asyncio_Task__log_destroy_pending_DOCSTR NULL -#endif -#if defined(_ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF) -# undef _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF -# define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", (getter)_asyncio_Task__log_destroy_pending_get, (setter)_asyncio_Task__log_destroy_pending_set, _asyncio_Task__log_destroy_pending_DOCSTR}, -#else -# define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", NULL, (setter)_asyncio_Task__log_destroy_pending_set, NULL}, -#endif - static int -_asyncio_Task__log_destroy_pending_set_impl(TaskObj *self, PyObject *value); +_asyncio_Task__log_destroy_pending_set_impl(TaskObj *self, int value); static int -_asyncio_Task__log_destroy_pending_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_asyncio_Task__log_destroy_pending_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + int value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute '_log_destroy_pending' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = PyObject_IsTrue(arg); + if (value < 0) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _asyncio_Task__log_destroy_pending_set_impl((TaskObj *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_asyncio_Task__must_cancel_DOCSTR) -# define _asyncio_Task__must_cancel_DOCSTR NULL -#endif -#if defined(_ASYNCIO_TASK__MUST_CANCEL_GETSETDEF) -# undef _ASYNCIO_TASK__MUST_CANCEL_GETSETDEF -# define _ASYNCIO_TASK__MUST_CANCEL_GETSETDEF {"_must_cancel", (getter)_asyncio_Task__must_cancel_get, (setter)_asyncio_Task__must_cancel_set, _asyncio_Task__must_cancel_DOCSTR}, -#else -# define _ASYNCIO_TASK__MUST_CANCEL_GETSETDEF {"_must_cancel", (getter)_asyncio_Task__must_cancel_get, NULL, _asyncio_Task__must_cancel_DOCSTR}, -#endif - static PyObject * _asyncio_Task__must_cancel_get_impl(TaskObj *self); @@ -1058,16 +935,6 @@ _asyncio_Task__must_cancel_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Task__coro_DOCSTR) -# define _asyncio_Task__coro_DOCSTR NULL -#endif -#if defined(_ASYNCIO_TASK__CORO_GETSETDEF) -# undef _ASYNCIO_TASK__CORO_GETSETDEF -# define _ASYNCIO_TASK__CORO_GETSETDEF {"_coro", (getter)_asyncio_Task__coro_get, (setter)_asyncio_Task__coro_set, _asyncio_Task__coro_DOCSTR}, -#else -# define _ASYNCIO_TASK__CORO_GETSETDEF {"_coro", (getter)_asyncio_Task__coro_get, NULL, _asyncio_Task__coro_DOCSTR}, -#endif - static PyObject * _asyncio_Task__coro_get_impl(TaskObj *self); @@ -1083,16 +950,6 @@ _asyncio_Task__coro_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_asyncio_Task__fut_waiter_DOCSTR) -# define _asyncio_Task__fut_waiter_DOCSTR NULL -#endif -#if defined(_ASYNCIO_TASK__FUT_WAITER_GETSETDEF) -# undef _ASYNCIO_TASK__FUT_WAITER_GETSETDEF -# define _ASYNCIO_TASK__FUT_WAITER_GETSETDEF {"_fut_waiter", (getter)_asyncio_Task__fut_waiter_get, (setter)_asyncio_Task__fut_waiter_set, _asyncio_Task__fut_waiter_DOCSTR}, -#else -# define _ASYNCIO_TASK__FUT_WAITER_GETSETDEF {"_fut_waiter", (getter)_asyncio_Task__fut_waiter_get, NULL, _asyncio_Task__fut_waiter_DOCSTR}, -#endif - static PyObject * _asyncio_Task__fut_waiter_get_impl(TaskObj *self); @@ -2258,4 +2115,32 @@ _asyncio_future_discard_from_awaited_by(PyObject *module, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=46d50c477614b57e input=a9049054013a1b77]*/ +#define _ASYNCIO_FUTURE__ASYNCIO_AWAITED_BY_GETSETDEF {"_asyncio_awaited_by", (getter)_asyncio_Future__asyncio_awaited_by_get, (setter)NULL, NULL}, + +#define _ASYNCIO_FUTURE__ASYNCIO_FUTURE_BLOCKING_GETSETDEF {"_asyncio_future_blocking", (getter)_asyncio_Future__asyncio_future_blocking_get, (setter)_asyncio_Future__asyncio_future_blocking_set, NULL}, + +#define _ASYNCIO_FUTURE__LOG_TRACEBACK_GETSETDEF {"_log_traceback", (getter)_asyncio_Future__log_traceback_get, (setter)_asyncio_Future__log_traceback_set, NULL}, + +#define _ASYNCIO_FUTURE__LOOP_GETSETDEF {"_loop", (getter)_asyncio_Future__loop_get, (setter)NULL, NULL}, + +#define _ASYNCIO_FUTURE__CALLBACKS_GETSETDEF {"_callbacks", (getter)_asyncio_Future__callbacks_get, (setter)NULL, NULL}, + +#define _ASYNCIO_FUTURE__RESULT_GETSETDEF {"_result", (getter)_asyncio_Future__result_get, (setter)NULL, NULL}, + +#define _ASYNCIO_FUTURE__EXCEPTION_GETSETDEF {"_exception", (getter)_asyncio_Future__exception_get, (setter)NULL, NULL}, + +#define _ASYNCIO_FUTURE__SOURCE_TRACEBACK_GETSETDEF {"_source_traceback", (getter)_asyncio_Future__source_traceback_get, (setter)NULL, NULL}, + +#define _ASYNCIO_FUTURE__CANCEL_MESSAGE_GETSETDEF {"_cancel_message", (getter)_asyncio_Future__cancel_message_get, (setter)_asyncio_Future__cancel_message_set, NULL}, + +#define _ASYNCIO_FUTURE__STATE_GETSETDEF {"_state", (getter)_asyncio_Future__state_get, (setter)NULL, NULL}, + +#define _ASYNCIO_TASK__LOG_DESTROY_PENDING_GETSETDEF {"_log_destroy_pending", (getter)_asyncio_Task__log_destroy_pending_get, (setter)_asyncio_Task__log_destroy_pending_set, NULL}, + +#define _ASYNCIO_TASK__MUST_CANCEL_GETSETDEF {"_must_cancel", (getter)_asyncio_Task__must_cancel_get, (setter)NULL, NULL}, + +#define _ASYNCIO_TASK__CORO_GETSETDEF {"_coro", (getter)_asyncio_Task__coro_get, (setter)NULL, NULL}, + +#define _ASYNCIO_TASK__FUT_WAITER_GETSETDEF {"_fut_waiter", (getter)_asyncio_Task__fut_waiter_get, (setter)NULL, NULL}, + +/*[clinic end generated code: output=f56ee5ac44909b27 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 62d52fc5f1aa5dd..d8d267910434bcc 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -338,20 +338,6 @@ PyDoc_STRVAR(_ssl__SSLSocket_context__doc__, "sni_callback on the SSLContext to change the certificate information\n" "associated with the SSLSocket before the cryptographic exchange\n" "handshake messages."); -#if defined(_ssl__SSLSocket_context_DOCSTR) -# undef _ssl__SSLSocket_context_DOCSTR -#endif -#define _ssl__SSLSocket_context_DOCSTR _ssl__SSLSocket_context__doc__ - -#if !defined(_ssl__SSLSocket_context_DOCSTR) -# define _ssl__SSLSocket_context_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_CONTEXT_GETSETDEF) -# undef _SSL__SSLSOCKET_CONTEXT_GETSETDEF -# define _SSL__SSLSOCKET_CONTEXT_GETSETDEF {"context", (getter)_ssl__SSLSocket_context_get, (setter)_ssl__SSLSocket_context_set, _ssl__SSLSocket_context_DOCSTR}, -#else -# define _SSL__SSLSOCKET_CONTEXT_GETSETDEF {"context", (getter)_ssl__SSLSocket_context_get, NULL, _ssl__SSLSocket_context_DOCSTR}, -#endif static PyObject * _ssl__SSLSocket_context_get_impl(PySSLSocket *self); @@ -368,30 +354,22 @@ _ssl__SSLSocket_context_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLSocket_context_DOCSTR) -# define _ssl__SSLSocket_context_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_CONTEXT_GETSETDEF) -# undef _SSL__SSLSOCKET_CONTEXT_GETSETDEF -# define _SSL__SSLSOCKET_CONTEXT_GETSETDEF {"context", (getter)_ssl__SSLSocket_context_get, (setter)_ssl__SSLSocket_context_set, _ssl__SSLSocket_context_DOCSTR}, -#else -# define _SSL__SSLSOCKET_CONTEXT_GETSETDEF {"context", NULL, (setter)_ssl__SSLSocket_context_set, NULL}, -#endif - static int _ssl__SSLSocket_context_set_impl(PySSLSocket *self, PyObject *value); static int -_ssl__SSLSocket_context_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLSocket_context_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'context' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLSocket_context_set_impl((PySSLSocket *)self, value); Py_END_CRITICAL_SECTION(); @@ -401,20 +379,6 @@ _ssl__SSLSocket_context_set(PyObject *self, PyObject *value, void *Py_UNUSED(con PyDoc_STRVAR(_ssl__SSLSocket_server_side__doc__, "Whether this is a server-side socket."); -#if defined(_ssl__SSLSocket_server_side_DOCSTR) -# undef _ssl__SSLSocket_server_side_DOCSTR -#endif -#define _ssl__SSLSocket_server_side_DOCSTR _ssl__SSLSocket_server_side__doc__ - -#if !defined(_ssl__SSLSocket_server_side_DOCSTR) -# define _ssl__SSLSocket_server_side_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_SERVER_SIDE_GETSETDEF) -# undef _SSL__SSLSOCKET_SERVER_SIDE_GETSETDEF -# define _SSL__SSLSOCKET_SERVER_SIDE_GETSETDEF {"server_side", (getter)_ssl__SSLSocket_server_side_get, (setter)_ssl__SSLSocket_server_side_set, _ssl__SSLSocket_server_side_DOCSTR}, -#else -# define _SSL__SSLSOCKET_SERVER_SIDE_GETSETDEF {"server_side", (getter)_ssl__SSLSocket_server_side_get, NULL, _ssl__SSLSocket_server_side_DOCSTR}, -#endif static PyObject * _ssl__SSLSocket_server_side_get_impl(PySSLSocket *self); @@ -433,20 +397,6 @@ _ssl__SSLSocket_server_side_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(_ssl__SSLSocket_server_hostname__doc__, "The currently set server hostname (for SNI)."); -#if defined(_ssl__SSLSocket_server_hostname_DOCSTR) -# undef _ssl__SSLSocket_server_hostname_DOCSTR -#endif -#define _ssl__SSLSocket_server_hostname_DOCSTR _ssl__SSLSocket_server_hostname__doc__ - -#if !defined(_ssl__SSLSocket_server_hostname_DOCSTR) -# define _ssl__SSLSocket_server_hostname_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_SERVER_HOSTNAME_GETSETDEF) -# undef _SSL__SSLSOCKET_SERVER_HOSTNAME_GETSETDEF -# define _SSL__SSLSOCKET_SERVER_HOSTNAME_GETSETDEF {"server_hostname", (getter)_ssl__SSLSocket_server_hostname_get, (setter)_ssl__SSLSocket_server_hostname_set, _ssl__SSLSocket_server_hostname_DOCSTR}, -#else -# define _SSL__SSLSOCKET_SERVER_HOSTNAME_GETSETDEF {"server_hostname", (getter)_ssl__SSLSocket_server_hostname_get, NULL, _ssl__SSLSocket_server_hostname_DOCSTR}, -#endif static PyObject * _ssl__SSLSocket_server_hostname_get_impl(PySSLSocket *self); @@ -467,20 +417,6 @@ PyDoc_STRVAR(_ssl__SSLSocket_owner__doc__, "The Python-level owner of this object.\n" "\n" "Passed as \"self\" in servername callback."); -#if defined(_ssl__SSLSocket_owner_DOCSTR) -# undef _ssl__SSLSocket_owner_DOCSTR -#endif -#define _ssl__SSLSocket_owner_DOCSTR _ssl__SSLSocket_owner__doc__ - -#if !defined(_ssl__SSLSocket_owner_DOCSTR) -# define _ssl__SSLSocket_owner_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_OWNER_GETSETDEF) -# undef _SSL__SSLSOCKET_OWNER_GETSETDEF -# define _SSL__SSLSOCKET_OWNER_GETSETDEF {"owner", (getter)_ssl__SSLSocket_owner_get, (setter)_ssl__SSLSocket_owner_set, _ssl__SSLSocket_owner_DOCSTR}, -#else -# define _SSL__SSLSOCKET_OWNER_GETSETDEF {"owner", (getter)_ssl__SSLSocket_owner_get, NULL, _ssl__SSLSocket_owner_DOCSTR}, -#endif static PyObject * _ssl__SSLSocket_owner_get_impl(PySSLSocket *self); @@ -497,30 +433,22 @@ _ssl__SSLSocket_owner_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLSocket_owner_DOCSTR) -# define _ssl__SSLSocket_owner_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_OWNER_GETSETDEF) -# undef _SSL__SSLSOCKET_OWNER_GETSETDEF -# define _SSL__SSLSOCKET_OWNER_GETSETDEF {"owner", (getter)_ssl__SSLSocket_owner_get, (setter)_ssl__SSLSocket_owner_set, _ssl__SSLSocket_owner_DOCSTR}, -#else -# define _SSL__SSLSOCKET_OWNER_GETSETDEF {"owner", NULL, (setter)_ssl__SSLSocket_owner_set, NULL}, -#endif - static int _ssl__SSLSocket_owner_set_impl(PySSLSocket *self, PyObject *value); static int -_ssl__SSLSocket_owner_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLSocket_owner_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'owner' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLSocket_owner_set_impl((PySSLSocket *)self, value); Py_END_CRITICAL_SECTION(); @@ -878,20 +806,6 @@ _ssl__SSLSocket_verify_client_post_handshake(PyObject *self, PyObject *Py_UNUSED PyDoc_STRVAR(_ssl__SSLSocket_session__doc__, "The underlying SSLSession object."); -#if defined(_ssl__SSLSocket_session_DOCSTR) -# undef _ssl__SSLSocket_session_DOCSTR -#endif -#define _ssl__SSLSocket_session_DOCSTR _ssl__SSLSocket_session__doc__ - -#if !defined(_ssl__SSLSocket_session_DOCSTR) -# define _ssl__SSLSocket_session_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_SESSION_GETSETDEF) -# undef _SSL__SSLSOCKET_SESSION_GETSETDEF -# define _SSL__SSLSOCKET_SESSION_GETSETDEF {"session", (getter)_ssl__SSLSocket_session_get, (setter)_ssl__SSLSocket_session_set, _ssl__SSLSocket_session_DOCSTR}, -#else -# define _SSL__SSLSOCKET_SESSION_GETSETDEF {"session", (getter)_ssl__SSLSocket_session_get, NULL, _ssl__SSLSocket_session_DOCSTR}, -#endif static PyObject * _ssl__SSLSocket_session_get_impl(PySSLSocket *self); @@ -908,30 +822,22 @@ _ssl__SSLSocket_session_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLSocket_session_DOCSTR) -# define _ssl__SSLSocket_session_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_SESSION_GETSETDEF) -# undef _SSL__SSLSOCKET_SESSION_GETSETDEF -# define _SSL__SSLSOCKET_SESSION_GETSETDEF {"session", (getter)_ssl__SSLSocket_session_get, (setter)_ssl__SSLSocket_session_set, _ssl__SSLSocket_session_DOCSTR}, -#else -# define _SSL__SSLSOCKET_SESSION_GETSETDEF {"session", NULL, (setter)_ssl__SSLSocket_session_set, NULL}, -#endif - static int _ssl__SSLSocket_session_set_impl(PySSLSocket *self, PyObject *value); static int -_ssl__SSLSocket_session_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLSocket_session_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'session' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLSocket_session_set_impl((PySSLSocket *)self, value); Py_END_CRITICAL_SECTION(); @@ -941,20 +847,6 @@ _ssl__SSLSocket_session_set(PyObject *self, PyObject *value, void *Py_UNUSED(con PyDoc_STRVAR(_ssl__SSLSocket_session_reused__doc__, "Was the client session reused during handshake?"); -#if defined(_ssl__SSLSocket_session_reused_DOCSTR) -# undef _ssl__SSLSocket_session_reused_DOCSTR -#endif -#define _ssl__SSLSocket_session_reused_DOCSTR _ssl__SSLSocket_session_reused__doc__ - -#if !defined(_ssl__SSLSocket_session_reused_DOCSTR) -# define _ssl__SSLSocket_session_reused_DOCSTR NULL -#endif -#if defined(_SSL__SSLSOCKET_SESSION_REUSED_GETSETDEF) -# undef _SSL__SSLSOCKET_SESSION_REUSED_GETSETDEF -# define _SSL__SSLSOCKET_SESSION_REUSED_GETSETDEF {"session_reused", (getter)_ssl__SSLSocket_session_reused_get, (setter)_ssl__SSLSocket_session_reused_set, _ssl__SSLSocket_session_reused_DOCSTR}, -#else -# define _SSL__SSLSOCKET_SESSION_REUSED_GETSETDEF {"session_reused", (getter)_ssl__SSLSocket_session_reused_get, NULL, _ssl__SSLSocket_session_reused_DOCSTR}, -#endif static PyObject * _ssl__SSLSocket_session_reused_get_impl(PySSLSocket *self); @@ -1317,128 +1209,119 @@ _ssl__SSLContext__set_alpn_protocols(PyObject *self, PyObject *arg) return return_value; } -#if !defined(_ssl__SSLContext_verify_mode_DOCSTR) -# define _ssl__SSLContext_verify_mode_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF) -# undef _SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF -# define _SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF {"verify_mode", (getter)_ssl__SSLContext_verify_mode_get, (setter)_ssl__SSLContext_verify_mode_set, _ssl__SSLContext_verify_mode_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF {"verify_mode", (getter)_ssl__SSLContext_verify_mode_get, NULL, _ssl__SSLContext_verify_mode_DOCSTR}, -#endif - -static PyObject * +static int _ssl__SSLContext_verify_mode_get_impl(PySSLContext *self); static PyObject * _ssl__SSLContext_verify_mode_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; + int _return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = _ssl__SSLContext_verify_mode_get_impl((PySSLContext *)self); + _return_value = _ssl__SSLContext_verify_mode_get_impl((PySSLContext *)self); Py_END_CRITICAL_SECTION(); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyLong_FromLong((long)_return_value); +exit: return return_value; } -#if !defined(_ssl__SSLContext_verify_mode_DOCSTR) -# define _ssl__SSLContext_verify_mode_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF) -# undef _SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF -# define _SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF {"verify_mode", (getter)_ssl__SSLContext_verify_mode_get, (setter)_ssl__SSLContext_verify_mode_set, _ssl__SSLContext_verify_mode_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF {"verify_mode", NULL, (setter)_ssl__SSLContext_verify_mode_set, NULL}, -#endif - static int -_ssl__SSLContext_verify_mode_set_impl(PySSLContext *self, PyObject *value); +_ssl__SSLContext_verify_mode_set_impl(PySSLContext *self, int value); static int -_ssl__SSLContext_verify_mode_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_verify_mode_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + int value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'verify_mode' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = PyLong_AsInt(arg); + if (value == -1 && PyErr_Occurred()) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_verify_mode_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_ssl__SSLContext_verify_flags_DOCSTR) -# define _ssl__SSLContext_verify_flags_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF) -# undef _SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF -# define _SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF {"verify_flags", (getter)_ssl__SSLContext_verify_flags_get, (setter)_ssl__SSLContext_verify_flags_set, _ssl__SSLContext_verify_flags_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF {"verify_flags", (getter)_ssl__SSLContext_verify_flags_get, NULL, _ssl__SSLContext_verify_flags_DOCSTR}, -#endif - -static PyObject * +static unsigned long _ssl__SSLContext_verify_flags_get_impl(PySSLContext *self); static PyObject * _ssl__SSLContext_verify_flags_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; + unsigned long _return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = _ssl__SSLContext_verify_flags_get_impl((PySSLContext *)self); + _return_value = _ssl__SSLContext_verify_flags_get_impl((PySSLContext *)self); Py_END_CRITICAL_SECTION(); + if ((_return_value == (unsigned long)-1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyLong_FromUnsignedLong(_return_value); +exit: return return_value; } -#if !defined(_ssl__SSLContext_verify_flags_DOCSTR) -# define _ssl__SSLContext_verify_flags_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF) -# undef _SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF -# define _SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF {"verify_flags", (getter)_ssl__SSLContext_verify_flags_get, (setter)_ssl__SSLContext_verify_flags_set, _ssl__SSLContext_verify_flags_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF {"verify_flags", NULL, (setter)_ssl__SSLContext_verify_flags_set, NULL}, -#endif - static int -_ssl__SSLContext_verify_flags_set_impl(PySSLContext *self, PyObject *value); +_ssl__SSLContext_verify_flags_set_impl(PySSLContext *self, + unsigned long value); static int -_ssl__SSLContext_verify_flags_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_verify_flags_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + unsigned long value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'verify_flags' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + if (!PyIndex_Check(arg)) { + PyErr_Format(PyExc_TypeError, "attribute 'verify_flags' must be int, not %T", arg); + goto exit; + } + { + Py_ssize_t _bytes = PyLong_AsNativeBytes(arg, &value, sizeof(unsigned long), + Py_ASNATIVEBYTES_NATIVE_ENDIAN | + Py_ASNATIVEBYTES_ALLOW_INDEX | + Py_ASNATIVEBYTES_UNSIGNED_BUFFER); + if (_bytes < 0) { + goto exit; + } + if ((size_t)_bytes > sizeof(unsigned long)) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "integer value out of range", 1) < 0) + { + goto exit; + } + } + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_verify_flags_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_ssl__SSLContext_minimum_version_DOCSTR) -# define _ssl__SSLContext_minimum_version_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF) -# undef _SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF -# define _SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF {"minimum_version", (getter)_ssl__SSLContext_minimum_version_get, (setter)_ssl__SSLContext_minimum_version_set, _ssl__SSLContext_minimum_version_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF {"minimum_version", (getter)_ssl__SSLContext_minimum_version_get, NULL, _ssl__SSLContext_minimum_version_DOCSTR}, -#endif - static PyObject * _ssl__SSLContext_minimum_version_get_impl(PySSLContext *self); @@ -1454,31 +1337,23 @@ _ssl__SSLContext_minimum_version_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLContext_minimum_version_DOCSTR) -# define _ssl__SSLContext_minimum_version_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF) -# undef _SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF -# define _SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF {"minimum_version", (getter)_ssl__SSLContext_minimum_version_get, (setter)_ssl__SSLContext_minimum_version_set, _ssl__SSLContext_minimum_version_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF {"minimum_version", NULL, (setter)_ssl__SSLContext_minimum_version_set, NULL}, -#endif - static int _ssl__SSLContext_minimum_version_set_impl(PySSLContext *self, PyObject *value); static int -_ssl__SSLContext_minimum_version_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_minimum_version_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'minimum_version' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_minimum_version_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); @@ -1486,16 +1361,6 @@ _ssl__SSLContext_minimum_version_set(PyObject *self, PyObject *value, void *Py_U return return_value; } -#if !defined(_ssl__SSLContext_maximum_version_DOCSTR) -# define _ssl__SSLContext_maximum_version_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF) -# undef _SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF -# define _SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF {"maximum_version", (getter)_ssl__SSLContext_maximum_version_get, (setter)_ssl__SSLContext_maximum_version_set, _ssl__SSLContext_maximum_version_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF {"maximum_version", (getter)_ssl__SSLContext_maximum_version_get, NULL, _ssl__SSLContext_maximum_version_DOCSTR}, -#endif - static PyObject * _ssl__SSLContext_maximum_version_get_impl(PySSLContext *self); @@ -1511,31 +1376,23 @@ _ssl__SSLContext_maximum_version_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLContext_maximum_version_DOCSTR) -# define _ssl__SSLContext_maximum_version_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF) -# undef _SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF -# define _SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF {"maximum_version", (getter)_ssl__SSLContext_maximum_version_get, (setter)_ssl__SSLContext_maximum_version_set, _ssl__SSLContext_maximum_version_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF {"maximum_version", NULL, (setter)_ssl__SSLContext_maximum_version_set, NULL}, -#endif - static int _ssl__SSLContext_maximum_version_set_impl(PySSLContext *self, PyObject *value); static int -_ssl__SSLContext_maximum_version_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_maximum_version_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'maximum_version' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_maximum_version_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); @@ -1545,20 +1402,6 @@ _ssl__SSLContext_maximum_version_set(PyObject *self, PyObject *value, void *Py_U PyDoc_STRVAR(_ssl__SSLContext_num_tickets__doc__, "Control the number of TLSv1.3 session tickets."); -#if defined(_ssl__SSLContext_num_tickets_DOCSTR) -# undef _ssl__SSLContext_num_tickets_DOCSTR -#endif -#define _ssl__SSLContext_num_tickets_DOCSTR _ssl__SSLContext_num_tickets__doc__ - -#if !defined(_ssl__SSLContext_num_tickets_DOCSTR) -# define _ssl__SSLContext_num_tickets_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF) -# undef _SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF -# define _SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF {"num_tickets", (getter)_ssl__SSLContext_num_tickets_get, (setter)_ssl__SSLContext_num_tickets_set, _ssl__SSLContext_num_tickets_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF {"num_tickets", (getter)_ssl__SSLContext_num_tickets_get, NULL, _ssl__SSLContext_num_tickets_DOCSTR}, -#endif static PyObject * _ssl__SSLContext_num_tickets_get_impl(PySSLContext *self); @@ -1575,53 +1418,35 @@ _ssl__SSLContext_num_tickets_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLContext_num_tickets_DOCSTR) -# define _ssl__SSLContext_num_tickets_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF) -# undef _SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF -# define _SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF {"num_tickets", (getter)_ssl__SSLContext_num_tickets_get, (setter)_ssl__SSLContext_num_tickets_set, _ssl__SSLContext_num_tickets_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF {"num_tickets", NULL, (setter)_ssl__SSLContext_num_tickets_set, NULL}, -#endif - static int -_ssl__SSLContext_num_tickets_set_impl(PySSLContext *self, PyObject *value); +_ssl__SSLContext_num_tickets_set_impl(PySSLContext *self, long value); static int -_ssl__SSLContext_num_tickets_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_num_tickets_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + long value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'num_tickets' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = PyLong_AsLong(arg); + if (value == -1 && PyErr_Occurred()) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_num_tickets_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } PyDoc_STRVAR(_ssl__SSLContext_security_level__doc__, "The current security level."); -#if defined(_ssl__SSLContext_security_level_DOCSTR) -# undef _ssl__SSLContext_security_level_DOCSTR -#endif -#define _ssl__SSLContext_security_level_DOCSTR _ssl__SSLContext_security_level__doc__ - -#if !defined(_ssl__SSLContext_security_level_DOCSTR) -# define _ssl__SSLContext_security_level_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF) -# undef _SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF -# define _SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF {"security_level", (getter)_ssl__SSLContext_security_level_get, (setter)_ssl__SSLContext_security_level_set, _ssl__SSLContext_security_level_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF {"security_level", (getter)_ssl__SSLContext_security_level_get, NULL, _ssl__SSLContext_security_level_DOCSTR}, -#endif static PyObject * _ssl__SSLContext_security_level_get_impl(PySSLContext *self); @@ -1638,16 +1463,6 @@ _ssl__SSLContext_security_level_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLContext_options_DOCSTR) -# define _ssl__SSLContext_options_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_OPTIONS_GETSETDEF) -# undef _SSL__SSLCONTEXT_OPTIONS_GETSETDEF -# define _SSL__SSLCONTEXT_OPTIONS_GETSETDEF {"options", (getter)_ssl__SSLContext_options_get, (setter)_ssl__SSLContext_options_set, _ssl__SSLContext_options_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_OPTIONS_GETSETDEF {"options", (getter)_ssl__SSLContext_options_get, NULL, _ssl__SSLContext_options_DOCSTR}, -#endif - static PyObject * _ssl__SSLContext_options_get_impl(PySSLContext *self); @@ -1663,159 +1478,141 @@ _ssl__SSLContext_options_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLContext_options_DOCSTR) -# define _ssl__SSLContext_options_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_OPTIONS_GETSETDEF) -# undef _SSL__SSLCONTEXT_OPTIONS_GETSETDEF -# define _SSL__SSLCONTEXT_OPTIONS_GETSETDEF {"options", (getter)_ssl__SSLContext_options_get, (setter)_ssl__SSLContext_options_set, _ssl__SSLContext_options_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_OPTIONS_GETSETDEF {"options", NULL, (setter)_ssl__SSLContext_options_set, NULL}, -#endif - static int -_ssl__SSLContext_options_set_impl(PySSLContext *self, PyObject *value); +_ssl__SSLContext_options_set_impl(PySSLContext *self, + unsigned long long value); static int -_ssl__SSLContext_options_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_options_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + unsigned long long value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'options' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + if (!_PyLong_UnsignedLongLong_Converter(arg, &value)) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_options_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_ssl__SSLContext__host_flags_DOCSTR) -# define _ssl__SSLContext__host_flags_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF) -# undef _SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF -# define _SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF {"_host_flags", (getter)_ssl__SSLContext__host_flags_get, (setter)_ssl__SSLContext__host_flags_set, _ssl__SSLContext__host_flags_DOCSTR}, -#else -# define _SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF {"_host_flags", (getter)_ssl__SSLContext__host_flags_get, NULL, _ssl__SSLContext__host_flags_DOCSTR}, -#endif - -static PyObject * +static unsigned int _ssl__SSLContext__host_flags_get_impl(PySSLContext *self); static PyObject * _ssl__SSLContext__host_flags_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; + unsigned int _return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = _ssl__SSLContext__host_flags_get_impl((PySSLContext *)self); + _return_value = _ssl__SSLContext__host_flags_get_impl((PySSLContext *)self); Py_END_CRITICAL_SECTION(); + if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); +exit: return return_value; } -#if !defined(_ssl__SSLContext__host_flags_DOCSTR) -# define _ssl__SSLContext__host_flags_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF) -# undef _SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF -# define _SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF {"_host_flags", (getter)_ssl__SSLContext__host_flags_get, (setter)_ssl__SSLContext__host_flags_set, _ssl__SSLContext__host_flags_DOCSTR}, -#else -# define _SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF {"_host_flags", NULL, (setter)_ssl__SSLContext__host_flags_set, NULL}, -#endif - static int -_ssl__SSLContext__host_flags_set_impl(PySSLContext *self, PyObject *value); +_ssl__SSLContext__host_flags_set_impl(PySSLContext *self, unsigned int value); static int -_ssl__SSLContext__host_flags_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext__host_flags_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + unsigned int value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute '_host_flags' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + { + Py_ssize_t _bytes = PyLong_AsNativeBytes(arg, &value, sizeof(unsigned int), + Py_ASNATIVEBYTES_NATIVE_ENDIAN | + Py_ASNATIVEBYTES_ALLOW_INDEX | + Py_ASNATIVEBYTES_UNSIGNED_BUFFER); + if (_bytes < 0) { + goto exit; + } + if ((size_t)_bytes > sizeof(unsigned int)) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "integer value out of range", 1) < 0) + { + goto exit; + } + } + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext__host_flags_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_ssl__SSLContext_check_hostname_DOCSTR) -# define _ssl__SSLContext_check_hostname_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF) -# undef _SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF -# define _SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF {"check_hostname", (getter)_ssl__SSLContext_check_hostname_get, (setter)_ssl__SSLContext_check_hostname_set, _ssl__SSLContext_check_hostname_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF {"check_hostname", (getter)_ssl__SSLContext_check_hostname_get, NULL, _ssl__SSLContext_check_hostname_DOCSTR}, -#endif - -static PyObject * +static int _ssl__SSLContext_check_hostname_get_impl(PySSLContext *self); static PyObject * _ssl__SSLContext_check_hostname_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; + int _return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = _ssl__SSLContext_check_hostname_get_impl((PySSLContext *)self); + _return_value = _ssl__SSLContext_check_hostname_get_impl((PySSLContext *)self); Py_END_CRITICAL_SECTION(); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyBool_FromLong((long)_return_value); +exit: return return_value; } -#if !defined(_ssl__SSLContext_check_hostname_DOCSTR) -# define _ssl__SSLContext_check_hostname_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF) -# undef _SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF -# define _SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF {"check_hostname", (getter)_ssl__SSLContext_check_hostname_get, (setter)_ssl__SSLContext_check_hostname_set, _ssl__SSLContext_check_hostname_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF {"check_hostname", NULL, (setter)_ssl__SSLContext_check_hostname_set, NULL}, -#endif - static int -_ssl__SSLContext_check_hostname_set_impl(PySSLContext *self, PyObject *value); +_ssl__SSLContext_check_hostname_set_impl(PySSLContext *self, int value); static int -_ssl__SSLContext_check_hostname_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_check_hostname_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + int value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'check_hostname' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = PyObject_IsTrue(arg); + if (value < 0) { + goto exit; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_check_hostname_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } -#if !defined(_ssl__SSLContext_protocol_DOCSTR) -# define _ssl__SSLContext_protocol_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_PROTOCOL_GETSETDEF) -# undef _SSL__SSLCONTEXT_PROTOCOL_GETSETDEF -# define _SSL__SSLCONTEXT_PROTOCOL_GETSETDEF {"protocol", (getter)_ssl__SSLContext_protocol_get, (setter)_ssl__SSLContext_protocol_set, _ssl__SSLContext_protocol_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_PROTOCOL_GETSETDEF {"protocol", (getter)_ssl__SSLContext_protocol_get, NULL, _ssl__SSLContext_protocol_DOCSTR}, -#endif - static PyObject * _ssl__SSLContext_protocol_get_impl(PySSLContext *self); @@ -2283,20 +2080,6 @@ PyDoc_STRVAR(_ssl__SSLContext_sni_callback__doc__, "SSLContext object.\n" "\n" "See RFC 6066 for details of the SNI extension."); -#if defined(_ssl__SSLContext_sni_callback_DOCSTR) -# undef _ssl__SSLContext_sni_callback_DOCSTR -#endif -#define _ssl__SSLContext_sni_callback_DOCSTR _ssl__SSLContext_sni_callback__doc__ - -#if !defined(_ssl__SSLContext_sni_callback_DOCSTR) -# define _ssl__SSLContext_sni_callback_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF) -# undef _SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF -# define _SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF {"sni_callback", (getter)_ssl__SSLContext_sni_callback_get, (setter)_ssl__SSLContext_sni_callback_set, _ssl__SSLContext_sni_callback_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF {"sni_callback", (getter)_ssl__SSLContext_sni_callback_get, NULL, _ssl__SSLContext_sni_callback_DOCSTR}, -#endif static PyObject * _ssl__SSLContext_sni_callback_get_impl(PySSLContext *self); @@ -2313,30 +2096,22 @@ _ssl__SSLContext_sni_callback_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(_ssl__SSLContext_sni_callback_DOCSTR) -# define _ssl__SSLContext_sni_callback_DOCSTR NULL -#endif -#if defined(_SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF) -# undef _SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF -# define _SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF {"sni_callback", (getter)_ssl__SSLContext_sni_callback_get, (setter)_ssl__SSLContext_sni_callback_set, _ssl__SSLContext_sni_callback_DOCSTR}, -#else -# define _SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF {"sni_callback", NULL, (setter)_ssl__SSLContext_sni_callback_set, NULL}, -#endif - static int _ssl__SSLContext_sni_callback_set_impl(PySSLContext *self, PyObject *value); static int -_ssl__SSLContext_sni_callback_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +_ssl__SSLContext_sni_callback_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'sni_callback' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_sni_callback_set_impl((PySSLContext *)self, value); Py_END_CRITICAL_SECTION(); @@ -2620,20 +2395,6 @@ _ssl_MemoryBIO(PyTypeObject *type, PyObject *args, PyObject *kwargs) PyDoc_STRVAR(_ssl_MemoryBIO_pending__doc__, "The number of bytes pending in the memory BIO."); -#if defined(_ssl_MemoryBIO_pending_DOCSTR) -# undef _ssl_MemoryBIO_pending_DOCSTR -#endif -#define _ssl_MemoryBIO_pending_DOCSTR _ssl_MemoryBIO_pending__doc__ - -#if !defined(_ssl_MemoryBIO_pending_DOCSTR) -# define _ssl_MemoryBIO_pending_DOCSTR NULL -#endif -#if defined(_SSL_MEMORYBIO_PENDING_GETSETDEF) -# undef _SSL_MEMORYBIO_PENDING_GETSETDEF -# define _SSL_MEMORYBIO_PENDING_GETSETDEF {"pending", (getter)_ssl_MemoryBIO_pending_get, (setter)_ssl_MemoryBIO_pending_set, _ssl_MemoryBIO_pending_DOCSTR}, -#else -# define _SSL_MEMORYBIO_PENDING_GETSETDEF {"pending", (getter)_ssl_MemoryBIO_pending_get, NULL, _ssl_MemoryBIO_pending_DOCSTR}, -#endif static PyObject * _ssl_MemoryBIO_pending_get_impl(PySSLMemoryBIO *self); @@ -2652,20 +2413,6 @@ _ssl_MemoryBIO_pending_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(_ssl_MemoryBIO_eof__doc__, "Whether the memory BIO is at EOF."); -#if defined(_ssl_MemoryBIO_eof_DOCSTR) -# undef _ssl_MemoryBIO_eof_DOCSTR -#endif -#define _ssl_MemoryBIO_eof_DOCSTR _ssl_MemoryBIO_eof__doc__ - -#if !defined(_ssl_MemoryBIO_eof_DOCSTR) -# define _ssl_MemoryBIO_eof_DOCSTR NULL -#endif -#if defined(_SSL_MEMORYBIO_EOF_GETSETDEF) -# undef _SSL_MEMORYBIO_EOF_GETSETDEF -# define _SSL_MEMORYBIO_EOF_GETSETDEF {"eof", (getter)_ssl_MemoryBIO_eof_get, (setter)_ssl_MemoryBIO_eof_set, _ssl_MemoryBIO_eof_DOCSTR}, -#else -# define _SSL_MEMORYBIO_EOF_GETSETDEF {"eof", (getter)_ssl_MemoryBIO_eof_get, NULL, _ssl_MemoryBIO_eof_DOCSTR}, -#endif static PyObject * _ssl_MemoryBIO_eof_get_impl(PySSLMemoryBIO *self); @@ -2788,20 +2535,6 @@ _ssl_MemoryBIO_write_eof(PyObject *self, PyObject *Py_UNUSED(ignored)) PyDoc_STRVAR(_ssl_SSLSession_time__doc__, "Session creation time (seconds since epoch)."); -#if defined(_ssl_SSLSession_time_DOCSTR) -# undef _ssl_SSLSession_time_DOCSTR -#endif -#define _ssl_SSLSession_time_DOCSTR _ssl_SSLSession_time__doc__ - -#if !defined(_ssl_SSLSession_time_DOCSTR) -# define _ssl_SSLSession_time_DOCSTR NULL -#endif -#if defined(_SSL_SSLSESSION_TIME_GETSETDEF) -# undef _SSL_SSLSESSION_TIME_GETSETDEF -# define _SSL_SSLSESSION_TIME_GETSETDEF {"time", (getter)_ssl_SSLSession_time_get, (setter)_ssl_SSLSession_time_set, _ssl_SSLSession_time_DOCSTR}, -#else -# define _SSL_SSLSESSION_TIME_GETSETDEF {"time", (getter)_ssl_SSLSession_time_get, NULL, _ssl_SSLSession_time_DOCSTR}, -#endif static PyObject * _ssl_SSLSession_time_get_impl(PySSLSession *self); @@ -2820,20 +2553,6 @@ _ssl_SSLSession_time_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(_ssl_SSLSession_timeout__doc__, "Session timeout (delta in seconds)."); -#if defined(_ssl_SSLSession_timeout_DOCSTR) -# undef _ssl_SSLSession_timeout_DOCSTR -#endif -#define _ssl_SSLSession_timeout_DOCSTR _ssl_SSLSession_timeout__doc__ - -#if !defined(_ssl_SSLSession_timeout_DOCSTR) -# define _ssl_SSLSession_timeout_DOCSTR NULL -#endif -#if defined(_SSL_SSLSESSION_TIMEOUT_GETSETDEF) -# undef _SSL_SSLSESSION_TIMEOUT_GETSETDEF -# define _SSL_SSLSESSION_TIMEOUT_GETSETDEF {"timeout", (getter)_ssl_SSLSession_timeout_get, (setter)_ssl_SSLSession_timeout_set, _ssl_SSLSession_timeout_DOCSTR}, -#else -# define _SSL_SSLSESSION_TIMEOUT_GETSETDEF {"timeout", (getter)_ssl_SSLSession_timeout_get, NULL, _ssl_SSLSession_timeout_DOCSTR}, -#endif static PyObject * _ssl_SSLSession_timeout_get_impl(PySSLSession *self); @@ -2852,20 +2571,6 @@ _ssl_SSLSession_timeout_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(_ssl_SSLSession_ticket_lifetime_hint__doc__, "Ticket life time hint."); -#if defined(_ssl_SSLSession_ticket_lifetime_hint_DOCSTR) -# undef _ssl_SSLSession_ticket_lifetime_hint_DOCSTR -#endif -#define _ssl_SSLSession_ticket_lifetime_hint_DOCSTR _ssl_SSLSession_ticket_lifetime_hint__doc__ - -#if !defined(_ssl_SSLSession_ticket_lifetime_hint_DOCSTR) -# define _ssl_SSLSession_ticket_lifetime_hint_DOCSTR NULL -#endif -#if defined(_SSL_SSLSESSION_TICKET_LIFETIME_HINT_GETSETDEF) -# undef _SSL_SSLSESSION_TICKET_LIFETIME_HINT_GETSETDEF -# define _SSL_SSLSESSION_TICKET_LIFETIME_HINT_GETSETDEF {"ticket_lifetime_hint", (getter)_ssl_SSLSession_ticket_lifetime_hint_get, (setter)_ssl_SSLSession_ticket_lifetime_hint_set, _ssl_SSLSession_ticket_lifetime_hint_DOCSTR}, -#else -# define _SSL_SSLSESSION_TICKET_LIFETIME_HINT_GETSETDEF {"ticket_lifetime_hint", (getter)_ssl_SSLSession_ticket_lifetime_hint_get, NULL, _ssl_SSLSession_ticket_lifetime_hint_DOCSTR}, -#endif static PyObject * _ssl_SSLSession_ticket_lifetime_hint_get_impl(PySSLSession *self); @@ -2884,20 +2589,6 @@ _ssl_SSLSession_ticket_lifetime_hint_get(PyObject *self, void *Py_UNUSED(context PyDoc_STRVAR(_ssl_SSLSession_id__doc__, "Session ID."); -#if defined(_ssl_SSLSession_id_DOCSTR) -# undef _ssl_SSLSession_id_DOCSTR -#endif -#define _ssl_SSLSession_id_DOCSTR _ssl_SSLSession_id__doc__ - -#if !defined(_ssl_SSLSession_id_DOCSTR) -# define _ssl_SSLSession_id_DOCSTR NULL -#endif -#if defined(_SSL_SSLSESSION_ID_GETSETDEF) -# undef _SSL_SSLSESSION_ID_GETSETDEF -# define _SSL_SSLSESSION_ID_GETSETDEF {"id", (getter)_ssl_SSLSession_id_get, (setter)_ssl_SSLSession_id_set, _ssl_SSLSession_id_DOCSTR}, -#else -# define _SSL_SSLSESSION_ID_GETSETDEF {"id", (getter)_ssl_SSLSession_id_get, NULL, _ssl_SSLSession_id_DOCSTR}, -#endif static PyObject * _ssl_SSLSession_id_get_impl(PySSLSession *self); @@ -2916,20 +2607,6 @@ _ssl_SSLSession_id_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(_ssl_SSLSession_has_ticket__doc__, "Does the session contain a ticket?"); -#if defined(_ssl_SSLSession_has_ticket_DOCSTR) -# undef _ssl_SSLSession_has_ticket_DOCSTR -#endif -#define _ssl_SSLSession_has_ticket_DOCSTR _ssl_SSLSession_has_ticket__doc__ - -#if !defined(_ssl_SSLSession_has_ticket_DOCSTR) -# define _ssl_SSLSession_has_ticket_DOCSTR NULL -#endif -#if defined(_SSL_SSLSESSION_HAS_TICKET_GETSETDEF) -# undef _SSL_SSLSESSION_HAS_TICKET_GETSETDEF -# define _SSL_SSLSESSION_HAS_TICKET_GETSETDEF {"has_ticket", (getter)_ssl_SSLSession_has_ticket_get, (setter)_ssl_SSLSession_has_ticket_set, _ssl_SSLSession_has_ticket_DOCSTR}, -#else -# define _SSL_SSLSESSION_HAS_TICKET_GETSETDEF {"has_ticket", (getter)_ssl_SSLSession_has_ticket_get, NULL, _ssl_SSLSession_has_ticket_DOCSTR}, -#endif static PyObject * _ssl_SSLSession_has_ticket_get_impl(PySSLSession *self); @@ -3398,4 +3075,52 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje #ifndef _SSL_ENUM_CRLS_METHODDEF #define _SSL_ENUM_CRLS_METHODDEF #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */ -/*[clinic end generated code: output=3a5bdd8db17e32b1 input=a9049054013a1b77]*/ +#define _SSL__SSLSOCKET_CONTEXT_GETSETDEF {"context", (getter)_ssl__SSLSocket_context_get, (setter)_ssl__SSLSocket_context_set, _ssl__SSLSocket_context__doc__}, + +#define _SSL__SSLSOCKET_SERVER_SIDE_GETSETDEF {"server_side", (getter)_ssl__SSLSocket_server_side_get, (setter)NULL, _ssl__SSLSocket_server_side__doc__}, + +#define _SSL__SSLSOCKET_SERVER_HOSTNAME_GETSETDEF {"server_hostname", (getter)_ssl__SSLSocket_server_hostname_get, (setter)NULL, _ssl__SSLSocket_server_hostname__doc__}, + +#define _SSL__SSLSOCKET_OWNER_GETSETDEF {"owner", (getter)_ssl__SSLSocket_owner_get, (setter)_ssl__SSLSocket_owner_set, _ssl__SSLSocket_owner__doc__}, + +#define _SSL__SSLSOCKET_SESSION_GETSETDEF {"session", (getter)_ssl__SSLSocket_session_get, (setter)_ssl__SSLSocket_session_set, _ssl__SSLSocket_session__doc__}, + +#define _SSL__SSLSOCKET_SESSION_REUSED_GETSETDEF {"session_reused", (getter)_ssl__SSLSocket_session_reused_get, (setter)NULL, _ssl__SSLSocket_session_reused__doc__}, + +#define _SSL__SSLCONTEXT_VERIFY_MODE_GETSETDEF {"verify_mode", (getter)_ssl__SSLContext_verify_mode_get, (setter)_ssl__SSLContext_verify_mode_set, NULL}, + +#define _SSL__SSLCONTEXT_VERIFY_FLAGS_GETSETDEF {"verify_flags", (getter)_ssl__SSLContext_verify_flags_get, (setter)_ssl__SSLContext_verify_flags_set, NULL}, + +#define _SSL__SSLCONTEXT_MINIMUM_VERSION_GETSETDEF {"minimum_version", (getter)_ssl__SSLContext_minimum_version_get, (setter)_ssl__SSLContext_minimum_version_set, NULL}, + +#define _SSL__SSLCONTEXT_MAXIMUM_VERSION_GETSETDEF {"maximum_version", (getter)_ssl__SSLContext_maximum_version_get, (setter)_ssl__SSLContext_maximum_version_set, NULL}, + +#define _SSL__SSLCONTEXT_NUM_TICKETS_GETSETDEF {"num_tickets", (getter)_ssl__SSLContext_num_tickets_get, (setter)_ssl__SSLContext_num_tickets_set, _ssl__SSLContext_num_tickets__doc__}, + +#define _SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF {"security_level", (getter)_ssl__SSLContext_security_level_get, (setter)NULL, _ssl__SSLContext_security_level__doc__}, + +#define _SSL__SSLCONTEXT_OPTIONS_GETSETDEF {"options", (getter)_ssl__SSLContext_options_get, (setter)_ssl__SSLContext_options_set, NULL}, + +#define _SSL__SSLCONTEXT__HOST_FLAGS_GETSETDEF {"_host_flags", (getter)_ssl__SSLContext__host_flags_get, (setter)_ssl__SSLContext__host_flags_set, NULL}, + +#define _SSL__SSLCONTEXT_CHECK_HOSTNAME_GETSETDEF {"check_hostname", (getter)_ssl__SSLContext_check_hostname_get, (setter)_ssl__SSLContext_check_hostname_set, NULL}, + +#define _SSL__SSLCONTEXT_PROTOCOL_GETSETDEF {"protocol", (getter)_ssl__SSLContext_protocol_get, (setter)NULL, NULL}, + +#define _SSL__SSLCONTEXT_SNI_CALLBACK_GETSETDEF {"sni_callback", (getter)_ssl__SSLContext_sni_callback_get, (setter)_ssl__SSLContext_sni_callback_set, _ssl__SSLContext_sni_callback__doc__}, + +#define _SSL_MEMORYBIO_PENDING_GETSETDEF {"pending", (getter)_ssl_MemoryBIO_pending_get, (setter)NULL, _ssl_MemoryBIO_pending__doc__}, + +#define _SSL_MEMORYBIO_EOF_GETSETDEF {"eof", (getter)_ssl_MemoryBIO_eof_get, (setter)NULL, _ssl_MemoryBIO_eof__doc__}, + +#define _SSL_SSLSESSION_TIME_GETSETDEF {"time", (getter)_ssl_SSLSession_time_get, (setter)NULL, _ssl_SSLSession_time__doc__}, + +#define _SSL_SSLSESSION_TIMEOUT_GETSETDEF {"timeout", (getter)_ssl_SSLSession_timeout_get, (setter)NULL, _ssl_SSLSession_timeout__doc__}, + +#define _SSL_SSLSESSION_TICKET_LIFETIME_HINT_GETSETDEF {"ticket_lifetime_hint", (getter)_ssl_SSLSession_ticket_lifetime_hint_get, (setter)NULL, _ssl_SSLSession_ticket_lifetime_hint__doc__}, + +#define _SSL_SSLSESSION_ID_GETSETDEF {"id", (getter)_ssl_SSLSession_id_get, (setter)NULL, _ssl_SSLSession_id__doc__}, + +#define _SSL_SSLSESSION_HAS_TICKET_GETSETDEF {"has_ticket", (getter)_ssl_SSLSession_has_ticket_get, (setter)NULL, _ssl_SSLSession_has_ticket__doc__}, + +/*[clinic end generated code: output=500a87b27d32383c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/hmacmodule.c.h b/Modules/clinic/hmacmodule.c.h index a31d2ab7f04463c..bdff9c4bf8c1df6 100644 --- a/Modules/clinic/hmacmodule.c.h +++ b/Modules/clinic/hmacmodule.c.h @@ -204,16 +204,6 @@ _hmac_HMAC_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored)) return _hmac_HMAC_hexdigest_impl((HMACObject *)self); } -#if !defined(_hmac_HMAC_name_DOCSTR) -# define _hmac_HMAC_name_DOCSTR NULL -#endif -#if defined(_HMAC_HMAC_NAME_GETSETDEF) -# undef _HMAC_HMAC_NAME_GETSETDEF -# define _HMAC_HMAC_NAME_GETSETDEF {"name", (getter)_hmac_HMAC_name_get, (setter)_hmac_HMAC_name_set, _hmac_HMAC_name_DOCSTR}, -#else -# define _HMAC_HMAC_NAME_GETSETDEF {"name", (getter)_hmac_HMAC_name_get, NULL, _hmac_HMAC_name_DOCSTR}, -#endif - static PyObject * _hmac_HMAC_name_get_impl(HMACObject *self); @@ -223,16 +213,6 @@ _hmac_HMAC_name_get(PyObject *self, void *Py_UNUSED(context)) return _hmac_HMAC_name_get_impl((HMACObject *)self); } -#if !defined(_hmac_HMAC_block_size_DOCSTR) -# define _hmac_HMAC_block_size_DOCSTR NULL -#endif -#if defined(_HMAC_HMAC_BLOCK_SIZE_GETSETDEF) -# undef _HMAC_HMAC_BLOCK_SIZE_GETSETDEF -# define _HMAC_HMAC_BLOCK_SIZE_GETSETDEF {"block_size", (getter)_hmac_HMAC_block_size_get, (setter)_hmac_HMAC_block_size_set, _hmac_HMAC_block_size_DOCSTR}, -#else -# define _HMAC_HMAC_BLOCK_SIZE_GETSETDEF {"block_size", (getter)_hmac_HMAC_block_size_get, NULL, _hmac_HMAC_block_size_DOCSTR}, -#endif - static PyObject * _hmac_HMAC_block_size_get_impl(HMACObject *self); @@ -242,16 +222,6 @@ _hmac_HMAC_block_size_get(PyObject *self, void *Py_UNUSED(context)) return _hmac_HMAC_block_size_get_impl((HMACObject *)self); } -#if !defined(_hmac_HMAC_digest_size_DOCSTR) -# define _hmac_HMAC_digest_size_DOCSTR NULL -#endif -#if defined(_HMAC_HMAC_DIGEST_SIZE_GETSETDEF) -# undef _HMAC_HMAC_DIGEST_SIZE_GETSETDEF -# define _HMAC_HMAC_DIGEST_SIZE_GETSETDEF {"digest_size", (getter)_hmac_HMAC_digest_size_get, (setter)_hmac_HMAC_digest_size_set, _hmac_HMAC_digest_size_DOCSTR}, -#else -# define _HMAC_HMAC_DIGEST_SIZE_GETSETDEF {"digest_size", (getter)_hmac_HMAC_digest_size_get, NULL, _hmac_HMAC_digest_size_DOCSTR}, -#endif - static PyObject * _hmac_HMAC_digest_size_get_impl(HMACObject *self); @@ -670,4 +640,10 @@ _hmac_compute_blake2b_32(PyObject *module, PyObject *const *args, Py_ssize_t nar exit: return return_value; } -/*[clinic end generated code: output=6ec5948df1c5569a input=a9049054013a1b77]*/ +#define _HMAC_HMAC_NAME_GETSETDEF {"name", (getter)_hmac_HMAC_name_get, (setter)NULL, NULL}, + +#define _HMAC_HMAC_BLOCK_SIZE_GETSETDEF {"block_size", (getter)_hmac_HMAC_block_size_get, (setter)NULL, NULL}, + +#define _HMAC_HMAC_DIGEST_SIZE_GETSETDEF {"digest_size", (getter)_hmac_HMAC_digest_size_get, (setter)NULL, NULL}, + +/*[clinic end generated code: output=f63101faf6ff6bac input=a9049054013a1b77]*/ diff --git a/Objects/clinic/exceptions.c.h b/Objects/clinic/exceptions.c.h index 5047a673e579c66..79e29490129bf77 100644 --- a/Objects/clinic/exceptions.c.h +++ b/Objects/clinic/exceptions.c.h @@ -106,16 +106,6 @@ BaseException_add_note(PyObject *self, PyObject *arg) return return_value; } -#if !defined(BaseException_args_DOCSTR) -# define BaseException_args_DOCSTR NULL -#endif -#if defined(BASEEXCEPTION_ARGS_GETSETDEF) -# undef BASEEXCEPTION_ARGS_GETSETDEF -# define BASEEXCEPTION_ARGS_GETSETDEF {"args", (getter)BaseException_args_get, (setter)BaseException_args_set, BaseException_args_DOCSTR}, -#else -# define BASEEXCEPTION_ARGS_GETSETDEF {"args", (getter)BaseException_args_get, NULL, BaseException_args_DOCSTR}, -#endif - static PyObject * BaseException_args_get_impl(PyBaseExceptionObject *self); @@ -131,24 +121,18 @@ BaseException_args_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(BaseException_args_DOCSTR) -# define BaseException_args_DOCSTR NULL -#endif -#if defined(BASEEXCEPTION_ARGS_GETSETDEF) -# undef BASEEXCEPTION_ARGS_GETSETDEF -# define BASEEXCEPTION_ARGS_GETSETDEF {"args", (getter)BaseException_args_get, (setter)BaseException_args_set, BaseException_args_DOCSTR}, -#else -# define BASEEXCEPTION_ARGS_GETSETDEF {"args", NULL, (setter)BaseException_args_set, NULL}, -#endif - static int BaseException_args_set_impl(PyBaseExceptionObject *self, PyObject *value); static int -BaseException_args_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +BaseException_args_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = BaseException_args_set_impl((PyBaseExceptionObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -156,16 +140,6 @@ BaseException_args_set(PyObject *self, PyObject *value, void *Py_UNUSED(context) return return_value; } -#if !defined(BaseException___traceback___DOCSTR) -# define BaseException___traceback___DOCSTR NULL -#endif -#if defined(BASEEXCEPTION___TRACEBACK___GETSETDEF) -# undef BASEEXCEPTION___TRACEBACK___GETSETDEF -# define BASEEXCEPTION___TRACEBACK___GETSETDEF {"__traceback__", (getter)BaseException___traceback___get, (setter)BaseException___traceback___set, BaseException___traceback___DOCSTR}, -#else -# define BASEEXCEPTION___TRACEBACK___GETSETDEF {"__traceback__", (getter)BaseException___traceback___get, NULL, BaseException___traceback___DOCSTR}, -#endif - static PyObject * BaseException___traceback___get_impl(PyBaseExceptionObject *self); @@ -181,25 +155,19 @@ BaseException___traceback___get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(BaseException___traceback___DOCSTR) -# define BaseException___traceback___DOCSTR NULL -#endif -#if defined(BASEEXCEPTION___TRACEBACK___GETSETDEF) -# undef BASEEXCEPTION___TRACEBACK___GETSETDEF -# define BASEEXCEPTION___TRACEBACK___GETSETDEF {"__traceback__", (getter)BaseException___traceback___get, (setter)BaseException___traceback___set, BaseException___traceback___DOCSTR}, -#else -# define BASEEXCEPTION___TRACEBACK___GETSETDEF {"__traceback__", NULL, (setter)BaseException___traceback___set, NULL}, -#endif - static int BaseException___traceback___set_impl(PyBaseExceptionObject *self, PyObject *value); static int -BaseException___traceback___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +BaseException___traceback___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = BaseException___traceback___set_impl((PyBaseExceptionObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -207,16 +175,6 @@ BaseException___traceback___set(PyObject *self, PyObject *value, void *Py_UNUSED return return_value; } -#if !defined(BaseException___context___DOCSTR) -# define BaseException___context___DOCSTR NULL -#endif -#if defined(BASEEXCEPTION___CONTEXT___GETSETDEF) -# undef BASEEXCEPTION___CONTEXT___GETSETDEF -# define BASEEXCEPTION___CONTEXT___GETSETDEF {"__context__", (getter)BaseException___context___get, (setter)BaseException___context___set, BaseException___context___DOCSTR}, -#else -# define BASEEXCEPTION___CONTEXT___GETSETDEF {"__context__", (getter)BaseException___context___get, NULL, BaseException___context___DOCSTR}, -#endif - static PyObject * BaseException___context___get_impl(PyBaseExceptionObject *self); @@ -232,25 +190,19 @@ BaseException___context___get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(BaseException___context___DOCSTR) -# define BaseException___context___DOCSTR NULL -#endif -#if defined(BASEEXCEPTION___CONTEXT___GETSETDEF) -# undef BASEEXCEPTION___CONTEXT___GETSETDEF -# define BASEEXCEPTION___CONTEXT___GETSETDEF {"__context__", (getter)BaseException___context___get, (setter)BaseException___context___set, BaseException___context___DOCSTR}, -#else -# define BASEEXCEPTION___CONTEXT___GETSETDEF {"__context__", NULL, (setter)BaseException___context___set, NULL}, -#endif - static int BaseException___context___set_impl(PyBaseExceptionObject *self, PyObject *value); static int -BaseException___context___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +BaseException___context___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = BaseException___context___set_impl((PyBaseExceptionObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -258,16 +210,6 @@ BaseException___context___set(PyObject *self, PyObject *value, void *Py_UNUSED(c return return_value; } -#if !defined(BaseException___cause___DOCSTR) -# define BaseException___cause___DOCSTR NULL -#endif -#if defined(BASEEXCEPTION___CAUSE___GETSETDEF) -# undef BASEEXCEPTION___CAUSE___GETSETDEF -# define BASEEXCEPTION___CAUSE___GETSETDEF {"__cause__", (getter)BaseException___cause___get, (setter)BaseException___cause___set, BaseException___cause___DOCSTR}, -#else -# define BASEEXCEPTION___CAUSE___GETSETDEF {"__cause__", (getter)BaseException___cause___get, NULL, BaseException___cause___DOCSTR}, -#endif - static PyObject * BaseException___cause___get_impl(PyBaseExceptionObject *self); @@ -283,25 +225,19 @@ BaseException___cause___get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(BaseException___cause___DOCSTR) -# define BaseException___cause___DOCSTR NULL -#endif -#if defined(BASEEXCEPTION___CAUSE___GETSETDEF) -# undef BASEEXCEPTION___CAUSE___GETSETDEF -# define BASEEXCEPTION___CAUSE___GETSETDEF {"__cause__", (getter)BaseException___cause___get, (setter)BaseException___cause___set, BaseException___cause___DOCSTR}, -#else -# define BASEEXCEPTION___CAUSE___GETSETDEF {"__cause__", NULL, (setter)BaseException___cause___set, NULL}, -#endif - static int BaseException___cause___set_impl(PyBaseExceptionObject *self, PyObject *value); static int -BaseException___cause___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +BaseException___cause___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = BaseException___cause___set_impl((PyBaseExceptionObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -380,4 +316,12 @@ BaseExceptionGroup_subgroup(PyObject *self, PyObject *matcher_value) return return_value; } -/*[clinic end generated code: output=e63b88d0443b4f92 input=a9049054013a1b77]*/ +#define BASEEXCEPTION_ARGS_GETSETDEF {"args", (getter)BaseException_args_get, (setter)BaseException_args_set, NULL}, + +#define BASEEXCEPTION___TRACEBACK___GETSETDEF {"__traceback__", (getter)BaseException___traceback___get, (setter)BaseException___traceback___set, NULL}, + +#define BASEEXCEPTION___CONTEXT___GETSETDEF {"__context__", (getter)BaseException___context___get, (setter)BaseException___context___set, NULL}, + +#define BASEEXCEPTION___CAUSE___GETSETDEF {"__cause__", (getter)BaseException___cause___get, (setter)BaseException___cause___set, NULL}, + +/*[clinic end generated code: output=783fc5863a1eac1f input=a9049054013a1b77]*/ diff --git a/Objects/clinic/frameobject.c.h b/Objects/clinic/frameobject.c.h index 7b8dab1e015a6b0..5d4901833d1ba49 100644 --- a/Objects/clinic/frameobject.c.h +++ b/Objects/clinic/frameobject.c.h @@ -6,20 +6,6 @@ preserve PyDoc_STRVAR(frame_locals__doc__, "Return the mapping used by the frame to look up local variables."); -#if defined(frame_locals_DOCSTR) -# undef frame_locals_DOCSTR -#endif -#define frame_locals_DOCSTR frame_locals__doc__ - -#if !defined(frame_locals_DOCSTR) -# define frame_locals_DOCSTR NULL -#endif -#if defined(FRAME_LOCALS_GETSETDEF) -# undef FRAME_LOCALS_GETSETDEF -# define FRAME_LOCALS_GETSETDEF {"f_locals", (getter)frame_locals_get, (setter)frame_locals_set, frame_locals_DOCSTR}, -#else -# define FRAME_LOCALS_GETSETDEF {"f_locals", (getter)frame_locals_get, NULL, frame_locals_DOCSTR}, -#endif static PyObject * frame_locals_get_impl(PyFrameObject *self); @@ -38,20 +24,6 @@ frame_locals_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_lineno__doc__, "Return the current line number in the frame."); -#if defined(frame_lineno_DOCSTR) -# undef frame_lineno_DOCSTR -#endif -#define frame_lineno_DOCSTR frame_lineno__doc__ - -#if !defined(frame_lineno_DOCSTR) -# define frame_lineno_DOCSTR NULL -#endif -#if defined(FRAME_LINENO_GETSETDEF) -# undef FRAME_LINENO_GETSETDEF -# define FRAME_LINENO_GETSETDEF {"f_lineno", (getter)frame_lineno_get, (setter)frame_lineno_set, frame_lineno_DOCSTR}, -#else -# define FRAME_LINENO_GETSETDEF {"f_lineno", (getter)frame_lineno_get, NULL, frame_lineno_DOCSTR}, -#endif static PyObject * frame_lineno_get_impl(PyFrameObject *self); @@ -70,20 +42,6 @@ frame_lineno_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_lasti__doc__, "Return the index of the last attempted instruction in the frame."); -#if defined(frame_lasti_DOCSTR) -# undef frame_lasti_DOCSTR -#endif -#define frame_lasti_DOCSTR frame_lasti__doc__ - -#if !defined(frame_lasti_DOCSTR) -# define frame_lasti_DOCSTR NULL -#endif -#if defined(FRAME_LASTI_GETSETDEF) -# undef FRAME_LASTI_GETSETDEF -# define FRAME_LASTI_GETSETDEF {"f_lasti", (getter)frame_lasti_get, (setter)frame_lasti_set, frame_lasti_DOCSTR}, -#else -# define FRAME_LASTI_GETSETDEF {"f_lasti", (getter)frame_lasti_get, NULL, frame_lasti_DOCSTR}, -#endif static PyObject * frame_lasti_get_impl(PyFrameObject *self); @@ -102,20 +60,6 @@ frame_lasti_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_globals__doc__, "Return the global variables in the frame."); -#if defined(frame_globals_DOCSTR) -# undef frame_globals_DOCSTR -#endif -#define frame_globals_DOCSTR frame_globals__doc__ - -#if !defined(frame_globals_DOCSTR) -# define frame_globals_DOCSTR NULL -#endif -#if defined(FRAME_GLOBALS_GETSETDEF) -# undef FRAME_GLOBALS_GETSETDEF -# define FRAME_GLOBALS_GETSETDEF {"f_globals", (getter)frame_globals_get, (setter)frame_globals_set, frame_globals_DOCSTR}, -#else -# define FRAME_GLOBALS_GETSETDEF {"f_globals", (getter)frame_globals_get, NULL, frame_globals_DOCSTR}, -#endif static PyObject * frame_globals_get_impl(PyFrameObject *self); @@ -134,20 +78,6 @@ frame_globals_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_builtins__doc__, "Return the built-in variables in the frame."); -#if defined(frame_builtins_DOCSTR) -# undef frame_builtins_DOCSTR -#endif -#define frame_builtins_DOCSTR frame_builtins__doc__ - -#if !defined(frame_builtins_DOCSTR) -# define frame_builtins_DOCSTR NULL -#endif -#if defined(FRAME_BUILTINS_GETSETDEF) -# undef FRAME_BUILTINS_GETSETDEF -# define FRAME_BUILTINS_GETSETDEF {"f_builtins", (getter)frame_builtins_get, (setter)frame_builtins_set, frame_builtins_DOCSTR}, -#else -# define FRAME_BUILTINS_GETSETDEF {"f_builtins", (getter)frame_builtins_get, NULL, frame_builtins_DOCSTR}, -#endif static PyObject * frame_builtins_get_impl(PyFrameObject *self); @@ -166,20 +96,6 @@ frame_builtins_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_code__doc__, "Return the code object being executed in this frame."); -#if defined(frame_code_DOCSTR) -# undef frame_code_DOCSTR -#endif -#define frame_code_DOCSTR frame_code__doc__ - -#if !defined(frame_code_DOCSTR) -# define frame_code_DOCSTR NULL -#endif -#if defined(FRAME_CODE_GETSETDEF) -# undef FRAME_CODE_GETSETDEF -# define FRAME_CODE_GETSETDEF {"f_code", (getter)frame_code_get, (setter)frame_code_set, frame_code_DOCSTR}, -#else -# define FRAME_CODE_GETSETDEF {"f_code", (getter)frame_code_get, NULL, frame_code_DOCSTR}, -#endif static PyObject * frame_code_get_impl(PyFrameObject *self); @@ -190,16 +106,6 @@ frame_code_get(PyObject *self, void *Py_UNUSED(context)) return frame_code_get_impl((PyFrameObject *)self); } -#if !defined(frame_back_DOCSTR) -# define frame_back_DOCSTR NULL -#endif -#if defined(FRAME_BACK_GETSETDEF) -# undef FRAME_BACK_GETSETDEF -# define FRAME_BACK_GETSETDEF {"f_back", (getter)frame_back_get, (setter)frame_back_set, frame_back_DOCSTR}, -#else -# define FRAME_BACK_GETSETDEF {"f_back", (getter)frame_back_get, NULL, frame_back_DOCSTR}, -#endif - static PyObject * frame_back_get_impl(PyFrameObject *self); @@ -217,20 +123,6 @@ frame_back_get(PyObject *self, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_trace_opcodes__doc__, "Return True if opcode tracing is enabled, False otherwise."); -#if defined(frame_trace_opcodes_DOCSTR) -# undef frame_trace_opcodes_DOCSTR -#endif -#define frame_trace_opcodes_DOCSTR frame_trace_opcodes__doc__ - -#if !defined(frame_trace_opcodes_DOCSTR) -# define frame_trace_opcodes_DOCSTR NULL -#endif -#if defined(FRAME_TRACE_OPCODES_GETSETDEF) -# undef FRAME_TRACE_OPCODES_GETSETDEF -# define FRAME_TRACE_OPCODES_GETSETDEF {"f_trace_opcodes", (getter)frame_trace_opcodes_get, (setter)frame_trace_opcodes_set, frame_trace_opcodes_DOCSTR}, -#else -# define FRAME_TRACE_OPCODES_GETSETDEF {"f_trace_opcodes", (getter)frame_trace_opcodes_get, NULL, frame_trace_opcodes_DOCSTR}, -#endif static PyObject * frame_trace_opcodes_get_impl(PyFrameObject *self); @@ -247,30 +139,22 @@ frame_trace_opcodes_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(frame_trace_opcodes_DOCSTR) -# define frame_trace_opcodes_DOCSTR NULL -#endif -#if defined(FRAME_TRACE_OPCODES_GETSETDEF) -# undef FRAME_TRACE_OPCODES_GETSETDEF -# define FRAME_TRACE_OPCODES_GETSETDEF {"f_trace_opcodes", (getter)frame_trace_opcodes_get, (setter)frame_trace_opcodes_set, frame_trace_opcodes_DOCSTR}, -#else -# define FRAME_TRACE_OPCODES_GETSETDEF {"f_trace_opcodes", NULL, (setter)frame_trace_opcodes_set, NULL}, -#endif - static int frame_trace_opcodes_set_impl(PyFrameObject *self, PyObject *value); static int -frame_trace_opcodes_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +frame_trace_opcodes_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'f_trace_opcodes' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = frame_trace_opcodes_set_impl((PyFrameObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -278,30 +162,22 @@ frame_trace_opcodes_set(PyObject *self, PyObject *value, void *Py_UNUSED(context return return_value; } -#if !defined(frame_lineno_DOCSTR) -# define frame_lineno_DOCSTR NULL -#endif -#if defined(FRAME_LINENO_GETSETDEF) -# undef FRAME_LINENO_GETSETDEF -# define FRAME_LINENO_GETSETDEF {"f_lineno", (getter)frame_lineno_get, (setter)frame_lineno_set, frame_lineno_DOCSTR}, -#else -# define FRAME_LINENO_GETSETDEF {"f_lineno", NULL, (setter)frame_lineno_set, NULL}, -#endif - static int frame_lineno_set_impl(PyFrameObject *self, PyObject *value); static int -frame_lineno_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +frame_lineno_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value; - if (value == NULL) { + if (arg == NULL) { PyErr_Format(PyExc_AttributeError, "attribute 'f_lineno' of '%.100s' objects cannot be deleted", Py_TYPE(self)->tp_name); return -1; } + value = arg; Py_BEGIN_CRITICAL_SECTION(self); return_value = frame_lineno_set_impl((PyFrameObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -311,20 +187,6 @@ frame_lineno_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_trace__doc__, "Return the trace function for this frame, or None if no trace function is set."); -#if defined(frame_trace_DOCSTR) -# undef frame_trace_DOCSTR -#endif -#define frame_trace_DOCSTR frame_trace__doc__ - -#if !defined(frame_trace_DOCSTR) -# define frame_trace_DOCSTR NULL -#endif -#if defined(FRAME_TRACE_GETSETDEF) -# undef FRAME_TRACE_GETSETDEF -# define FRAME_TRACE_GETSETDEF {"f_trace", (getter)frame_trace_get, (setter)frame_trace_set, frame_trace_DOCSTR}, -#else -# define FRAME_TRACE_GETSETDEF {"f_trace", (getter)frame_trace_get, NULL, frame_trace_DOCSTR}, -#endif static PyObject * frame_trace_get_impl(PyFrameObject *self); @@ -341,24 +203,18 @@ frame_trace_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(frame_trace_DOCSTR) -# define frame_trace_DOCSTR NULL -#endif -#if defined(FRAME_TRACE_GETSETDEF) -# undef FRAME_TRACE_GETSETDEF -# define FRAME_TRACE_GETSETDEF {"f_trace", (getter)frame_trace_get, (setter)frame_trace_set, frame_trace_DOCSTR}, -#else -# define FRAME_TRACE_GETSETDEF {"f_trace", NULL, (setter)frame_trace_set, NULL}, -#endif - static int frame_trace_set_impl(PyFrameObject *self, PyObject *value); static int -frame_trace_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +frame_trace_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = frame_trace_set_impl((PyFrameObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -368,20 +224,6 @@ frame_trace_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) PyDoc_STRVAR(frame_generator__doc__, "Return the generator or coroutine associated with this frame, or None."); -#if defined(frame_generator_DOCSTR) -# undef frame_generator_DOCSTR -#endif -#define frame_generator_DOCSTR frame_generator__doc__ - -#if !defined(frame_generator_DOCSTR) -# define frame_generator_DOCSTR NULL -#endif -#if defined(FRAME_GENERATOR_GETSETDEF) -# undef FRAME_GENERATOR_GETSETDEF -# define FRAME_GENERATOR_GETSETDEF {"f_generator", (getter)frame_generator_get, (setter)frame_generator_set, frame_generator_DOCSTR}, -#else -# define FRAME_GENERATOR_GETSETDEF {"f_generator", (getter)frame_generator_get, NULL, frame_generator_DOCSTR}, -#endif static PyObject * frame_generator_get_impl(PyFrameObject *self); @@ -445,4 +287,24 @@ frame___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) return return_value; } -/*[clinic end generated code: output=a42421e56faa7a80 input=a9049054013a1b77]*/ +#define FRAME_F_LOCALS_GETSETDEF {"f_locals", (getter)frame_locals_get, (setter)NULL, frame_locals__doc__}, + +#define FRAME_F_LINENO_GETSETDEF {"f_lineno", (getter)frame_lineno_get, (setter)frame_lineno_set, frame_lineno__doc__}, + +#define FRAME_F_LASTI_GETSETDEF {"f_lasti", (getter)frame_lasti_get, (setter)NULL, frame_lasti__doc__}, + +#define FRAME_F_GLOBALS_GETSETDEF {"f_globals", (getter)frame_globals_get, (setter)NULL, frame_globals__doc__}, + +#define FRAME_F_BUILTINS_GETSETDEF {"f_builtins", (getter)frame_builtins_get, (setter)NULL, frame_builtins__doc__}, + +#define FRAME_F_CODE_GETSETDEF {"f_code", (getter)frame_code_get, (setter)NULL, frame_code__doc__}, + +#define FRAME_F_BACK_GETSETDEF {"f_back", (getter)frame_back_get, (setter)NULL, NULL}, + +#define FRAME_F_TRACE_OPCODES_GETSETDEF {"f_trace_opcodes", (getter)frame_trace_opcodes_get, (setter)frame_trace_opcodes_set, frame_trace_opcodes__doc__}, + +#define FRAME_F_TRACE_GETSETDEF {"f_trace", (getter)frame_trace_get, (setter)frame_trace_set, frame_trace__doc__}, + +#define FRAME_F_GENERATOR_GETSETDEF {"f_generator", (getter)frame_generator_get, (setter)NULL, frame_generator__doc__}, + +/*[clinic end generated code: output=dfa59114b6dbce08 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/funcobject.c.h b/Objects/clinic/funcobject.c.h index fec743146466a45..096af1bb832cb48 100644 --- a/Objects/clinic/funcobject.c.h +++ b/Objects/clinic/funcobject.c.h @@ -11,20 +11,6 @@ preserve PyDoc_STRVAR(function___annotate____doc__, "Get the code object for a function."); -#if defined(function___annotate___DOCSTR) -# undef function___annotate___DOCSTR -#endif -#define function___annotate___DOCSTR function___annotate____doc__ - -#if !defined(function___annotate___DOCSTR) -# define function___annotate___DOCSTR NULL -#endif -#if defined(FUNCTION___ANNOTATE___GETSETDEF) -# undef FUNCTION___ANNOTATE___GETSETDEF -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR}, -#else -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, NULL, function___annotate___DOCSTR}, -#endif static PyObject * function___annotate___get_impl(PyFunctionObject *self); @@ -41,24 +27,18 @@ function___annotate___get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(function___annotate___DOCSTR) -# define function___annotate___DOCSTR NULL -#endif -#if defined(FUNCTION___ANNOTATE___GETSETDEF) -# undef FUNCTION___ANNOTATE___GETSETDEF -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR}, -#else -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", NULL, (setter)function___annotate___set, NULL}, -#endif - static int function___annotate___set_impl(PyFunctionObject *self, PyObject *value); static int -function___annotate___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +function___annotate___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = function___annotate___set_impl((PyFunctionObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -68,20 +48,6 @@ function___annotate___set(PyObject *self, PyObject *value, void *Py_UNUSED(conte PyDoc_STRVAR(function___annotations____doc__, "Dict of annotations in a function object."); -#if defined(function___annotations___DOCSTR) -# undef function___annotations___DOCSTR -#endif -#define function___annotations___DOCSTR function___annotations____doc__ - -#if !defined(function___annotations___DOCSTR) -# define function___annotations___DOCSTR NULL -#endif -#if defined(FUNCTION___ANNOTATIONS___GETSETDEF) -# undef FUNCTION___ANNOTATIONS___GETSETDEF -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR}, -#else -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, NULL, function___annotations___DOCSTR}, -#endif static PyObject * function___annotations___get_impl(PyFunctionObject *self); @@ -98,24 +64,18 @@ function___annotations___get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(function___annotations___DOCSTR) -# define function___annotations___DOCSTR NULL -#endif -#if defined(FUNCTION___ANNOTATIONS___GETSETDEF) -# undef FUNCTION___ANNOTATIONS___GETSETDEF -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR}, -#else -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", NULL, (setter)function___annotations___set, NULL}, -#endif - static int function___annotations___set_impl(PyFunctionObject *self, PyObject *value); static int -function___annotations___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +function___annotations___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = function___annotations___set_impl((PyFunctionObject *)self, value); Py_END_CRITICAL_SECTION(); @@ -125,20 +85,6 @@ function___annotations___set(PyObject *self, PyObject *value, void *Py_UNUSED(co PyDoc_STRVAR(function___type_params____doc__, "Get the declared type parameters for a function."); -#if defined(function___type_params___DOCSTR) -# undef function___type_params___DOCSTR -#endif -#define function___type_params___DOCSTR function___type_params____doc__ - -#if !defined(function___type_params___DOCSTR) -# define function___type_params___DOCSTR NULL -#endif -#if defined(FUNCTION___TYPE_PARAMS___GETSETDEF) -# undef FUNCTION___TYPE_PARAMS___GETSETDEF -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR}, -#else -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, NULL, function___type_params___DOCSTR}, -#endif static PyObject * function___type_params___get_impl(PyFunctionObject *self); @@ -155,28 +101,27 @@ function___type_params___get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(function___type_params___DOCSTR) -# define function___type_params___DOCSTR NULL -#endif -#if defined(FUNCTION___TYPE_PARAMS___GETSETDEF) -# undef FUNCTION___TYPE_PARAMS___GETSETDEF -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR}, -#else -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", NULL, (setter)function___type_params___set, NULL}, -#endif - static int function___type_params___set_impl(PyFunctionObject *self, PyObject *value); static int -function___type_params___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +function___type_params___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + if (!PyTuple_Check(arg)) { + PyErr_Format(PyExc_TypeError, "attribute '__type_params__' must be tuple, not %T", arg); + goto exit; + } + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = function___type_params___set_impl((PyFunctionObject *)self, value); Py_END_CRITICAL_SECTION(); +exit: return return_value; } @@ -290,4 +235,10 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=12cb900088d41bdb input=a9049054013a1b77]*/ +#define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate____doc__}, + +#define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations____doc__}, + +#define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params____doc__}, + +/*[clinic end generated code: output=ab11c6500888e337 input=a9049054013a1b77]*/ diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 5889cdaf2aa1652..c920e6cfc89c3be 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -1906,16 +1906,16 @@ frame_generator_get_impl(PyFrameObject *self) static PyGetSetDef frame_getsetlist[] = { - FRAME_BACK_GETSETDEF - FRAME_LOCALS_GETSETDEF - FRAME_LINENO_GETSETDEF - FRAME_TRACE_GETSETDEF - FRAME_LASTI_GETSETDEF - FRAME_GLOBALS_GETSETDEF - FRAME_BUILTINS_GETSETDEF - FRAME_CODE_GETSETDEF - FRAME_TRACE_OPCODES_GETSETDEF - FRAME_GENERATOR_GETSETDEF + FRAME_F_BACK_GETSETDEF + FRAME_F_LOCALS_GETSETDEF + FRAME_F_LINENO_GETSETDEF + FRAME_F_TRACE_GETSETDEF + FRAME_F_LASTI_GETSETDEF + FRAME_F_GLOBALS_GETSETDEF + FRAME_F_BUILTINS_GETSETDEF + FRAME_F_CODE_GETSETDEF + FRAME_F_TRACE_OPCODES_GETSETDEF + FRAME_F_GENERATOR_GETSETDEF {0} }; diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 0481adadf668f8d..6ae0ed65a4e3c05 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -1029,15 +1029,15 @@ function___type_params___get_impl(PyFunctionObject *self) @setter @deleter function.__type_params__ + value: object(subclass_of='&PyTuple_Type') = NULL [clinic start generated code]*/ static int function___type_params___set_impl(PyFunctionObject *self, PyObject *value) -/*[clinic end generated code: output=038b4cda220e56fb input=c0e33abc5901a2f5]*/ +/*[clinic end generated code: output=038b4cda220e56fb input=62240698386aa632]*/ { - /* Not legal to del f.__type_params__ or to set it to anything - * other than a tuple object. */ - if (value == NULL || !PyTuple_Check(value)) { + /* Not legal to del f.__type_params__. */ + if (value == NULL) { PyErr_SetString(PyExc_TypeError, "__type_params__ must be set to a tuple"); return -1; diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h index deae2efa3eb28d2..dfce2a7d9d481fc 100644 --- a/Python/clinic/traceback.c.h +++ b/Python/clinic/traceback.c.h @@ -83,16 +83,6 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } -#if !defined(traceback_tb_next_DOCSTR) -# define traceback_tb_next_DOCSTR NULL -#endif -#if defined(TRACEBACK_TB_NEXT_GETSETDEF) -# undef TRACEBACK_TB_NEXT_GETSETDEF -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, traceback_tb_next_DOCSTR}, -#else -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, NULL, traceback_tb_next_DOCSTR}, -#endif - static PyObject * traceback_tb_next_get_impl(PyTracebackObject *self); @@ -108,28 +98,24 @@ traceback_tb_next_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } -#if !defined(traceback_tb_next_DOCSTR) -# define traceback_tb_next_DOCSTR NULL -#endif -#if defined(TRACEBACK_TB_NEXT_GETSETDEF) -# undef TRACEBACK_TB_NEXT_GETSETDEF -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, traceback_tb_next_DOCSTR}, -#else -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", NULL, (setter)traceback_tb_next_set, NULL}, -#endif - static int traceback_tb_next_set_impl(PyTracebackObject *self, PyObject *value); static int -traceback_tb_next_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +traceback_tb_next_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context)) { - int return_value; + int return_value = -1; + PyObject *value = NULL; + if (arg != NULL) { + value = arg; + } Py_BEGIN_CRITICAL_SECTION(self); return_value = traceback_tb_next_set_impl((PyTracebackObject *)self, value); Py_END_CRITICAL_SECTION(); return return_value; } -/*[clinic end generated code: output=5361141395da963e input=a9049054013a1b77]*/ +#define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, NULL}, + +/*[clinic end generated code: output=29ce9385d58eac46 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/libclinic/app.py b/Tools/clinic/libclinic/app.py index d8de3687a35ce64..e1d3ff38a2867ac 100644 --- a/Tools/clinic/libclinic/app.py +++ b/Tools/clinic/libclinic/app.py @@ -15,7 +15,7 @@ if TYPE_CHECKING: from libclinic.clanguage import CLanguage from libclinic.function import ( - Module, Function, ClassDict, ModuleDict) + Module, Function, Property, ClassDict, ModuleDict) from libclinic.codegen import DestinationDict @@ -103,6 +103,8 @@ def __init__( self.modules: ModuleDict = {} self.classes: ClassDict = {} self.functions: list[Function] = [] + # The attributes implemented by accessors, in the order of definition. + self.properties: list[Property] = [] self.codegen = CodeGen(self.limited_capi) self.line_prefix = self.line_suffix = '' @@ -195,6 +197,10 @@ def parse(self, input: str) -> str: parser.parse(block) printer.print_block(block) + # The entry of an attribute is composed of all its accessors, so it + # is rendered when the whole file is parsed. + self.language.render_properties(self) + # these are destinations not buffers for name, destination in self.destinations.items(): if destination.type == 'suppress': diff --git a/Tools/clinic/libclinic/clanguage.py b/Tools/clinic/libclinic/clanguage.py index ab77e7ad6603cdc..70adf643786a1d2 100644 --- a/Tools/clinic/libclinic/clanguage.py +++ b/Tools/clinic/libclinic/clanguage.py @@ -11,12 +11,14 @@ from libclinic.codegen import CRenderData, TemplateDict, CodeGen from libclinic.language import Language from libclinic.function import ( - Module, Class, Function, Parameter, ParamTuple, + Module, Class, Property, Function, Parameter, ParamTuple, permute_optional_groups, - GETTER, METHOD_INIT, + METHOD_INIT, ACCESSORS, SETTERS) from libclinic.converters import self_converter -from libclinic.parse_args import ParseArgsCodeGen +from libclinic.parse_args import ( + ParseArgsCodeGen, + GETSETDEF_PROTOTYPE_COMBINE, GETSETDEF_PROTOTYPE_DEFINE) if TYPE_CHECKING: from libclinic.app import Clinic @@ -96,6 +98,61 @@ def render( function = o return self.render_function(clinic, function) + def render_properties(self, clinic: Clinic) -> None: + """Compose the PyGetSetDef entry of every attribute not composed yet. + + All accessors of an attribute are only known when all blocks of the + file are rendered or the destination is dumped. + """ + destination = clinic.destination_buffers['methoddef_ifndef'] + for prop in clinic.properties: + if prop.rendered: + continue + prop.rendered = True + s = self.render_property(prop) + '\n' + if clinic.line_prefix: + s = libclinic.indent_all_lines(s, clinic.line_prefix) + if clinic.line_suffix: + s = libclinic.suffix_all_lines(s, clinic.line_suffix) + destination.append(s) + + def render_property(self, prop: Property) -> str: + getset_name = prop.getset_name + template_dict = { + 'name': prop.name, + 'getset_name': getset_name, + } + parts: list[str] = [] + if prop.is_plain: + getter = prop.getter[0] if prop.getter else None + setter = prop.setter[0] if prop.setter else None + template_dict['getter'] = (getter.accessor_basename if getter + else 'NULL') + template_dict['setter'] = (setter.accessor_basename if setter + else 'NULL') + template_dict['docstr'] = (f'{getter.c_basename}__doc__' + if getter and getter.docstring + else 'NULL') + parts.append(GETSETDEF_PROTOTYPE_DEFINE.format_map(template_dict) + + '\n') + else: + # Which of the conditionally compiled accessors are compiled is + # only known to the preprocessor. They announce themselves, so + # only the unconditional ones are announced here. + for suffix, funcs in (('GETTER', prop.getter), + ('SETTER', prop.setter)): + for func in funcs: + if func.condition: + continue + parts.append(f"#define {getset_name}_{suffix} " + f"{func.accessor_basename}\n") + if suffix == 'GETTER' and func.docstring: + parts.append(f"#define {getset_name}_DOCSTR " + f"{func.c_basename}__doc__\n") + parts.append(GETSETDEF_PROTOTYPE_COMBINE.format_map(template_dict) + + '\n') + return ''.join(parts) + def compiler_deprecated_warning( self, func: Function, @@ -480,15 +537,12 @@ def render_function( template_dict = {'full_name': full_name} template_dict['name'] = f.displayname if f.kind in ACCESSORS: - template_dict['getset_name'] = f.c_basename.upper() + # The accessors of the same attribute are rendered into a single + # PyGetSetDef entry, which is identified by the Python name. + assert f.property is not None + template_dict['getset_name'] = f.property.getset_name template_dict['getset_basename'] = f.c_basename - if f.kind is GETTER: - template_dict['c_basename'] = f.c_basename + "_get" - else: - template_dict['c_basename'] = f.c_basename + "_set" - # Implicitly add the setter value parameter. - data.impl_parameters.append("PyObject *value") - data.impl_arguments.append("value") + template_dict['c_basename'] = f.accessor_basename else: template_dict['methoddef_name'] = f.c_basename.upper() + "_METHODDEF" template_dict['c_basename'] = f.c_basename diff --git a/Tools/clinic/libclinic/converter.py b/Tools/clinic/libclinic/converter.py index c10235237d4b716..cbadfc327ecaa30 100644 --- a/Tools/clinic/libclinic/converter.py +++ b/Tools/clinic/libclinic/converter.py @@ -8,7 +8,7 @@ from libclinic import fail from libclinic import Sentinels, unspecified, unknown, NULL from libclinic.codegen import CRenderData, Include, TemplateDict -from libclinic.function import Function, Parameter +from libclinic.function import Function, Parameter, SETTERS CConverterClassT = TypeVar("CConverterClassT", bound=type["CConverter"]) @@ -468,6 +468,16 @@ def pre_render(self) -> None: def bad_argument(self, displayname: str, expected: str, *, limited_capi: bool, expected_literal: bool = True) -> str: assert '"' not in expected + if self.function.kind in SETTERS: + # The value of an attribute, not an argument of a function. + if expected_literal: + return (f'PyErr_Format(PyExc_TypeError, ' + f'"attribute \'{{{{name}}}}\' must be {expected}, not %T", ' + f'{{argname}});') + else: + return (f'PyErr_Format(PyExc_TypeError, ' + f'"attribute \'{{{{name}}}}\' must be %s, not %T", ' + f'"{expected}", {{argname}});') if limited_capi: if expected_literal: return (f'PyErr_Format(PyExc_TypeError, ' diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index a6b1d2bed5e5dee..771b3e0a58b6e8e 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -15,14 +15,15 @@ ClinicError, VersionTuple, fail, warn, unspecified, unknown, NULL) from libclinic.function import ( - Module, Class, Function, Parameter, + Module, Class, Property, Function, Parameter, FunctionKind, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW, + GETTER, SETTER, SETTER_AND_DELETER, ACCESSORS, SETTERS) from libclinic.converter import ( converters, legacy_converters) from libclinic.converters import ( - self_converter, defining_class_converter, + self_converter, defining_class_converter, object_converter, correct_name_for_self) from libclinic.return_converters import ( CReturnConverter, return_converters, @@ -411,6 +412,8 @@ def directive_output( fd[command_or_name] = d def directive_dump(self, name: str) -> None: + # The entries of attributes are composed before they are dumped. + self.clinic.language.render_properties(self.clinic) self.block.output.append(self.clinic.get_destination(name).dump()) def directive_printout(self, *args: str) -> None: @@ -615,8 +618,8 @@ def resolve_return_converter( self, full_name: str, forced_converter: str ) -> CReturnConverter: if forced_converter: - if self.kind in ACCESSORS: - fail("@getter and @setter methods cannot define a return type") + if self.kind in SETTERS: + fail("@setter methods cannot define a return type") if self.kind is METHOD_INIT: fail("__init__ methods cannot define a return type") ast_input = f"def x() -> {forced_converter}: pass" @@ -678,6 +681,9 @@ def parse_cloned_function(self, names: FunctionNames, existing: str) -> None: fail("'kind' of function and cloned function don't match! " "(@classmethod/@staticmethod/@coexist)") function = existing_function.copy(**overrides) + function.condition = self.clinic.language.cpp.condition() + if function.kind in ACCESSORS: + self.add_accessor(function) self.function = function self.block.signatures.append(function) (cls or module).functions.append(function) @@ -742,21 +748,9 @@ def state_modulename_name(self, line: str) -> None: self.next(self.state_parameters_start) def add_function(self, func: Function) -> None: + func.condition = self.clinic.language.cpp.condition() if func.kind in ACCESSORS: - # The accessors of the same attribute are rendered into a single - # PyGetSetDef entry, which is identified by the C basename, so - # they must share it. - for other in (func.cls or func.module).functions: - if (other.kind in ACCESSORS - and other.full_name == func.full_name): - if (other.kind is func.kind - or {other.kind, func.kind} <= SETTERS): - kind = 'setter' if func.kind in SETTERS else 'getter' - fail(f"Cannot apply @{kind} to " - f"{func.full_name!r} twice") - if other.c_basename != func.c_basename: - fail(f"The accessors of {func.full_name!r} " - f"must have the same C basename") + self.add_accessor(func) # Insert a self converter automatically. tp, name = correct_name_for_self(func) @@ -776,6 +770,28 @@ def add_function(self, func: Function) -> None: self.function = func (func.cls or func.module).functions.append(func) + def add_accessor(self, func: Function) -> None: + """Add an accessor to the attribute which it implements.""" + assert func.cls is not None + prop = func.cls.properties.get(func.name) + if prop is not None and prop.rendered: + fail(f"All accessors of {func.full_name!r} must be defined " + f"before its PyGetSetDef entry is dumped") + if prop is None: + prop = Property(func.name, func.full_name, func.cls) + func.cls.properties[func.name] = prop + self.clinic.properties.append(prop) + func.property = prop + slot = prop.getter if func.kind is GETTER else prop.setter + # Several implementations of the same accessor can share the slot if + # each of them is compiled under its own preprocessor condition. + if slot and (not func.condition + or any(not other.condition for other in slot)): + if func.kind is GETTER: + fail(f"Cannot apply @getter to {func.full_name!r} twice") + fail(f"The setter of {func.full_name!r} is already defined") + slot.append(func) + # Now entering the parameters section. The rules, formally stated: # # * All lines must be indented with spaces only. @@ -840,8 +856,8 @@ def state_parameters_start(self, line: str) -> None: return self.next(self.state_function_docstring, line) assert self.function is not None - if self.function.kind in ACCESSORS: - fail("@getter and @setter methods cannot define parameters") + if self.function.kind is GETTER: + fail("@getter methods cannot define parameters") self.parameter_continuation = '' return self.next(self.state_parameter, line) @@ -864,6 +880,10 @@ def state_parameter(self, line: str) -> None: if not self.valid_line(line): return + if self.function.kind in SETTERS and len(self.function.parameters) > 1: + # The only parameter of a setter is the new value. + fail("@setter methods must define exactly one parameter") + if self.parameter_continuation: line = self.parameter_continuation + ' ' + line.lstrip() self.parameter_continuation = '' @@ -1384,7 +1404,7 @@ def format_docstring_signature( if f.forced_text_signature: lines.append(f.forced_text_signature) elif f.kind in ACCESSORS: - # @getter and @setter do not need signatures like a method or a function. + # Accessors do not need signatures like a method or a function. return '' else: lines.append('(') @@ -1675,6 +1695,31 @@ def do_post_block_processing_cleanup(self, lineno: int) -> None: if not self.function: return + func = self.function + if func.kind in (SETTER, SETTER_AND_DELETER): + # The new value is the only parameter of a setter. The setter + # of a deletable attribute is also called to delete it, hence the + # default value. + optional = func.kind is SETTER_AND_DELETER + if len(func.parameters) == 1: + # It is optional to declare the value, which is usually + # a plain object. + default = NULL if optional else unspecified + converter = object_converter('value', 'value', func, default) + func.parameters['value'] = Parameter( + 'value', inspect.Parameter.POSITIONAL_ONLY, + function=func, converter=converter, default=default) + else: + p = list(func.parameters.values())[1] + if p.is_keyword_only() or p.is_variable_length(): + fail("the value of @setter must be a positional parameter") + if p.is_optional() != optional: + if optional: + fail("the value of @setter with @deleter must have " + "a default value, used to delete the attribute") + else: + fail("the value of @setter cannot have a default value") + self.check_remaining_star(lineno) try: self.function.docstring = self.format_docstring() diff --git a/Tools/clinic/libclinic/function.py b/Tools/clinic/libclinic/function.py index cad673045d1c26d..624d41909ce09c4 100644 --- a/Tools/clinic/libclinic/function.py +++ b/Tools/clinic/libclinic/function.py @@ -18,6 +18,7 @@ ClassDict = dict[str, "Class"] ModuleDict = dict[str, "Module"] ParamDict = dict[str, "Parameter"] +PropertyDict = dict[str, "Property"] @dc.dataclass(repr=False) @@ -47,11 +48,43 @@ def __post_init__(self) -> None: self.parent = self.cls or self.module self.classes: ClassDict = {} self.functions: list[Function] = [] + self.properties: PropertyDict = {} def __repr__(self) -> str: return "" +@dc.dataclass(repr=False) +class Property: + """An attribute implemented by accessors, rendered into a PyGetSetDef entry. + + A slot can contain several implementations if they are guarded by + preprocessor conditions. + """ + name: str + full_name: str + cls: Class + + def __post_init__(self) -> None: + self.getter: list[Function] = [] + self.setter: list[Function] = [] + self.rendered = False + + def __repr__(self) -> str: + return "" + + @property + def is_plain(self) -> bool: + """Can the entry be composed without the help of the preprocessor?""" + return all(len(funcs) <= 1 and not (funcs and funcs[0].condition) + for funcs in (self.getter, self.setter)) + + @property + def getset_name(self) -> str: + """The prefix of the names of the macros of the entry.""" + return self.full_name.replace('.', '_').upper() + + class FunctionKind(enum.Enum): CALLABLE = enum.auto() STATIC_METHOD = enum.auto() @@ -122,8 +155,20 @@ class Function: def __post_init__(self) -> None: self.parent = self.cls or self.module self.self_converter: self_converter | None = None + # The attribute implemented by an accessor, and the preprocessor + # condition under which it is compiled. + self.property: Property | None = None + self.condition: str = '' self.__render_parameters__: list[Parameter] | None = None + @functools.cached_property + def accessor_basename(self) -> str: + """The name of the C function which implements this accessor.""" + assert self.kind in ACCESSORS + if self.kind is GETTER: + return self.c_basename + "_get" + return self.c_basename + "_set" + @functools.cached_property def displayname(self) -> str: """Pretty-printable name.""" diff --git a/Tools/clinic/libclinic/language.py b/Tools/clinic/libclinic/language.py index 15975430c160220..c8da0c724f45ba2 100644 --- a/Tools/clinic/libclinic/language.py +++ b/Tools/clinic/libclinic/language.py @@ -35,6 +35,9 @@ def render( def parse_line(self, line: str) -> None: ... + def render_properties(self, clinic: Clinic) -> None: + ... + def validate(self) -> None: def assert_only_one( attr: str, diff --git a/Tools/clinic/libclinic/parse_args.py b/Tools/clinic/libclinic/parse_args.py index b08b949028205d2..6e35afe3fa91b67 100644 --- a/Tools/clinic/libclinic/parse_args.py +++ b/Tools/clinic/libclinic/parse_args.py @@ -5,8 +5,8 @@ from libclinic import fail, warn from libclinic.function import ( Function, Parameter, - GETTER, SETTER, METHOD_NEW, - ACCESSORS, SETTERS) + GETTER, SETTER, SETTER_AND_DELETER, ACCESSORS, SETTERS, + METHOD_NEW) from libclinic.converter import CConverter from libclinic.converters import ( defining_class_converter, object_converter, self_converter) @@ -133,7 +133,7 @@ def declare_parser( """) PARSER_PROTOTYPE_SETTER: Final[str] = libclinic.normalize_snippet(""" static int - {c_basename}({self_type}{self_name}, PyObject *value, void *Py_UNUSED(context)) + {c_basename}({self_type}{self_name}, PyObject *arg, void *Py_UNUSED(context)) """) METH_O_PROTOTYPE: Final[str] = libclinic.normalize_snippet(""" static PyObject * @@ -146,13 +146,20 @@ def declare_parser( PyDoc_STRVAR({c_basename}__doc__, {docstring}); """) +# The docstring of an attribute is defined by its getter. GETSET_DOCSTRING_PROTOTYPE_STRVAR: Final[str] = libclinic.normalize_snippet(""" PyDoc_STRVAR({getset_basename}__doc__, {docstring}); - #if defined({getset_basename}_DOCSTR) - # undef {getset_basename}_DOCSTR +""") +# If the getter is compiled conditionally, the entry refers to the docstring +# by a macro, because only the preprocessor knows which one is defined. +GETSET_DOCSTRING_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(""" + PyDoc_STRVAR({getset_basename}__doc__, + {docstring}); + #if defined({getset_name}_DOCSTR) + # undef {getset_name}_DOCSTR #endif - #define {getset_basename}_DOCSTR {getset_basename}__doc__ + #define {getset_name}_DOCSTR {getset_basename}__doc__ """) IMPL_DEFINITION_PROTOTYPE: Final[str] = libclinic.normalize_snippet(""" static {impl_return_type} @@ -162,48 +169,52 @@ def declare_parser( #define {methoddef_name} \ {{"{name}", {methoddef_cast}{c_basename}{methoddef_cast_end}, {methoddef_flags}, {c_basename}__doc__}}, """) -GETTERDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(r""" - #if !defined({getset_basename}_DOCSTR) - # define {getset_basename}_DOCSTR NULL - #endif - #if defined({getset_name}_GETSETDEF) - # undef {getset_name}_GETSETDEF - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}_DOCSTR}}, - #else - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, NULL, {getset_basename}_DOCSTR}}, - #endif -""") -SETTERDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(r""" - #if !defined({getset_basename}_DOCSTR) - # define {getset_basename}_DOCSTR NULL - #endif - #if defined({getset_name}_GETSETDEF) - # undef {getset_name}_GETSETDEF - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}_DOCSTR}}, - #else - # define {getset_name}_GETSETDEF {{"{name}", NULL, (setter){getset_basename}_set, NULL}}, - #endif -""") -METHODDEF_PROTOTYPE_IFNDEF: Final[str] = libclinic.normalize_snippet(""" - #ifndef {methoddef_name} - #define {methoddef_name} - #endif /* !defined({methoddef_name}) */ -""") -GETSETDEF_PROTOTYPE_IFNDEF: Final[str] = libclinic.normalize_snippet(""" - #ifndef {getset_name}_GETSETDEF - #define {getset_name}_GETSETDEF - #endif /* !defined({getset_name}_GETSETDEF) */ +# An accessor which is compiled conditionally announces the function which +# implements it. Only the preprocessor knows which of them are compiled, so +# the entry is composed of these announcements +# (see GETSETDEF_PROTOTYPE_COMBINE). +GETTERDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(""" + #define {getset_name}_GETTER {c_basename} """) -# The setter is called with NULL to delete the attribute. Unless @deleter is -# applied to it, deletion is rejected before the implementation is called. SETTER_PREAMBLE: Final[str] = libclinic.normalize_snippet(""" - if (value == NULL) {{ + if (arg == NULL) {{ PyErr_Format(PyExc_AttributeError, "attribute '{name}' of '%.100s' objects cannot be deleted", Py_TYPE({self_name})->tp_name); return -1; }} """, indent=4) +SETTERDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(""" + #define {getset_name}_SETTER {c_basename} +""") +METHODDEF_PROTOTYPE_IFNDEF: Final[str] = libclinic.normalize_snippet(""" + #ifndef {methoddef_name} + #define {methoddef_name} + #endif /* !defined({methoddef_name}) */ +""") +# The entry of an attribute whose accessors are all compiled unconditionally. +GETSETDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(""" + #define {getset_name}_GETSETDEF {{"{name}", (getter){getter}, (setter){setter}, {docstr}}}, +""") +# Composes the PyGetSetDef entry of an attribute. It must be rendered after +# all accessors of that attribute, so it is written to the same destination as +# the "ifndef" of a method, which is emptied at the end of the file. +GETSETDEF_PROTOTYPE_COMBINE: Final[str] = libclinic.normalize_snippet(""" + #if defined({getset_name}_GETTER) || defined({getset_name}_SETTER) + # if !defined({getset_name}_GETTER) + # define {getset_name}_GETTER NULL + # endif + # if !defined({getset_name}_SETTER) + # define {getset_name}_SETTER NULL + # endif + # if !defined({getset_name}_DOCSTR) + # define {getset_name}_DOCSTR NULL + # endif + # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_name}_GETTER, (setter){getset_name}_SETTER, {getset_name}_DOCSTR}}, + #else + # define {getset_name}_GETSETDEF + #endif +""") class ParseArgsCodeGen: @@ -341,14 +352,20 @@ def select_prototypes(self) -> None: if self.is_new_or_init() and not self.func.docstring: pass elif self.func.kind is GETTER: - self.methoddef_define = GETTERDEF_PROTOTYPE_DEFINE + # Only an accessor compiled conditionally announces itself. + self.methoddef_define = (GETTERDEF_PROTOTYPE_DEFINE + if self.func.condition else '') if self.func.docstring: - self.docstring_definition = GETSET_DOCSTRING_PROTOTYPE_STRVAR + self.docstring_definition = ( + GETSET_DOCSTRING_PROTOTYPE_DEFINE if self.func.condition + else GETSET_DOCSTRING_PROTOTYPE_STRVAR) elif self.func.kind in SETTERS: if self.func.docstring: - fail("docstrings are only supported for @getter, not @setter") - self.return_value_declaration = "int {parser_retval};" - self.methoddef_define = SETTERDEF_PROTOTYPE_DEFINE + fail("docstrings are only supported for @getter") + # The conversion of the value can fail before it is set. + self.return_value_declaration = "int {parser_retval} = -1;" + self.methoddef_define = (SETTERDEF_PROTOTYPE_DEFINE + if self.func.condition else '') else: self.docstring_prototype = DOCSTRING_PROTOTYPE_VAR self.docstring_definition = DOCSTRING_PROTOTYPE_STRVAR @@ -397,19 +414,48 @@ def parser_body( parser_declarations=self.declarations) self.parser_definition = code - def parse_no_args(self) -> None: - parser_code: list[str] | None - simple_return = self.use_simple_return() + def render_setter_value(self) -> str: + """Return the code which converts the new value of the attribute.""" + # The parser guarantees that the value is the only parameter. + assert len(self.parameters) == 1 + p = self.parameters[0] + parsearg = p.converter.parse_arg('arg', p.get_displayname(0), + limited_capi=self.limited_capi) + if parsearg is None: + p.converter.use_converter() + parsearg = """ + if (!PyArg_Parse(arg, "{format_units}:{name}", {parse_arguments})) {{ + goto exit; + }} + """ + if self.func.kind is not SETTER_AND_DELETER: + return libclinic.normalize_snippet(parsearg, indent=4) + # The value is only converted if the attribute is not deleted. + return "\n".join([ + libclinic.normalize_snippet("if (arg != NULL) {{", indent=4), + libclinic.normalize_snippet(parsearg, indent=8), + libclinic.normalize_snippet("}}", indent=4), + ]) + + def parse_accessor(self) -> None: + """Generate the code of a getter or a setter.""" + parser_code: list[str] = [] if self.func.kind is GETTER: self.parser_prototype = PARSER_PROTOTYPE_GETTER - parser_code = [] - elif self.func.kind in SETTERS: + else: self.parser_prototype = PARSER_PROTOTYPE_SETTER + # The setter is called with NULL to delete the attribute, which + # is checked before parsing, because NULL is not a value. if self.func.kind is SETTER: - parser_code = [SETTER_PREAMBLE] - else: - parser_code = [] - elif not self.requires_defining_class: + # The setter which is not the deleter rejects the deletion. + parser_code.append(SETTER_PREAMBLE) + parser_code.append(self.render_setter_value()) + self.finish_parser_body(parser_code) + + def parse_no_args(self) -> None: + parser_code: list[str] | None + simple_return = self.use_simple_return() + if not self.requires_defining_class: # no self.parameters, METH_NOARGS self.flags = "METH_NOARGS" self.parser_prototype = PARSER_PROTOTYPE_NOARGS @@ -428,7 +474,12 @@ def parse_no_args(self) -> None: }} """ % return_error, indent=4)] - if simple_return: + self.finish_parser_body(parser_code) + + def finish_parser_body(self, parser_code: list[str]) -> None: + """Generate the parsing function from the code which parses + the arguments.""" + if self.use_simple_return(): self.parser_definition = '\n'.join([ self.parser_prototype, '{{', @@ -931,19 +982,20 @@ def process_methoddef(self, clang: CLanguage) -> None: self.methoddef_define = self.methoddef_define.replace('{methoddef_cast}', methoddef_cast) self.methoddef_define = self.methoddef_define.replace('{methoddef_cast_end}', methoddef_cast_end) + # The entry of an attribute is composed when all its accessors are + # known (see render_properties). self.methoddef_ifndef = '' - conditional = clang.cpp.condition() + conditional = self.func.condition if not conditional: self.cpp_if = self.cpp_endif = '' else: self.cpp_if = "#if " + conditional self.cpp_endif = "#endif /* " + conditional + " */" - if self.methoddef_define and self.codegen.add_ifndef_symbol(self.func.full_name): - if self.func.kind in ACCESSORS: - self.methoddef_ifndef = GETSETDEF_PROTOTYPE_IFNDEF - else: - self.methoddef_ifndef = METHODDEF_PROTOTYPE_IFNDEF + if (self.func.kind not in ACCESSORS + and self.methoddef_define + and self.codegen.add_ifndef_symbol(self.func.full_name)): + self.methoddef_ifndef = METHODDEF_PROTOTYPE_IFNDEF def finalize(self, clang: CLanguage) -> None: # add ';' to the end of self.parser_prototype and self.impl_prototype @@ -1003,7 +1055,9 @@ def parse_args(self, clang: CLanguage) -> dict[str, str]: # previous call to parser_body. this is used for an awful hack. self.parser_body_fields: tuple[str, ...] = () - if not self.parameters and not self.varpos and not self.var_keyword: + if self.func.kind in ACCESSORS: + self.parse_accessor() + elif not self.parameters and not self.varpos and not self.var_keyword: self.parse_no_args() elif self.use_meth_o(): self.parse_one_arg() From 68a34fae15f8d95aff0278628dfbefa5d80e5094 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 20 Aug 2026 15:27:31 +0300 Subject: [PATCH 2/2] Forbid defaults other than NULL for the value of @setter with @deleter --- Lib/test/test_clinic.py | 12 ++++++++++++ Tools/clinic/libclinic/dsl_parser.py | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 4d45ed98c08d205..2f3ca814918d80f 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -2934,6 +2934,18 @@ class Foo "" "" "a default value, used to delete the attribute") self.expect_failure(block, expected_error) + block = """ + module m + class Foo "" "" + @setter + @deleter + Foo.property + value: object = None + """ + expected_error = ("the value of @setter with @deleter can only have " + "NULL as a default value") + self.expect_failure(block, expected_error) + def test_setter_value_kind(self): expected_error = "the value of @setter must be a positional parameter" block = """ diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index 622be36d05ebd33..e9ef1da21614402 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -1556,8 +1556,8 @@ def do_post_block_processing_cleanup(self, lineno: int) -> None: func = self.function if func.kind in (SETTER, SETTER_AND_DELETER): # The new value is the only parameter of a setter. The setter - # of a deletable attribute is also called to delete it, hence the - # default value. + # of a deletable attribute is also called with NULL to delete it, + # hence the default value. optional = func.kind is SETTER_AND_DELETER if len(func.parameters) == 1: # It is optional to declare the value, which is usually @@ -1577,6 +1577,9 @@ def do_post_block_processing_cleanup(self, lineno: int) -> None: "a default value, used to delete the attribute") else: fail("the value of @setter cannot have a default value") + if optional and p.default is not NULL: + fail("the value of @setter with @deleter can only have " + "NULL as a default value") self.check_remaining_star(lineno) try: