Commit 8fc27163 authored by Larry Hastings's avatar Larry Hastings

Issue #19474: Argument Clinic now always specifies a default value for

variables in option groups, to prevent "uninitialized value" warnings.
parent 34643c02
...@@ -608,11 +608,11 @@ curses_window_addch(PyObject *self, PyObject *args) ...@@ -608,11 +608,11 @@ curses_window_addch(PyObject *self, PyObject *args)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
int group_left_1 = 0; int group_left_1 = 0;
int x; int x = 0;
int y; int y = 0;
PyObject *ch; PyObject *ch;
int group_right_1 = 0; int group_right_1 = 0;
long attr; long attr = 0;
switch (PyTuple_Size(args)) { switch (PyTuple_Size(args)) {
case 1: case 1:
...@@ -646,7 +646,7 @@ curses_window_addch(PyObject *self, PyObject *args) ...@@ -646,7 +646,7 @@ curses_window_addch(PyObject *self, PyObject *args)
static PyObject * static PyObject *
curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr) curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr)
/*[clinic checksum: 98ade780397a48d0be48439763424b3b00c92089]*/ /*[clinic checksum: 094d012af1019387c0219a9c0bc76e90729c833f]*/
{ {
PyCursesWindowObject *cwself = (PyCursesWindowObject *)self; PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
int coordinates_group = group_left_1; int coordinates_group = group_left_1;
......
...@@ -1281,17 +1281,29 @@ class CConverter(metaclass=CConverterAutoRegister): ...@@ -1281,17 +1281,29 @@ class CConverter(metaclass=CConverterAutoRegister):
# Or "unspecified" if there is no default. # Or "unspecified" if there is no default.
default = unspecified default = unspecified
# "default" converted into a str for rendering into Python code.
py_default = None
# "default" as it should appear in the documentation, as a string. # "default" as it should appear in the documentation, as a string.
# Or None if there is no default. # Or None if there is no default.
doc_default = None doc_default = None
# "default" converted into a str for rendering into Python code.
py_default = None
# "default" converted into a C value, as a string. # "default" converted into a C value, as a string.
# Or None if there is no default. # Or None if there is no default.
c_default = None c_default = None
# The default value used to initialize the C variable when
# there is no default, but not specifying a default may
# result in an "uninitialized variable" warning. This can
# easily happen when using option groups--although
# properly-written code won't actually use the variable,
# the variable does get passed in to the _impl. (Ah, if
# only dataflow analysis could inline the static function!)
#
# This value is specified as a string.
# Every non-abstract subclass should supply a valid value.
c_ignored_default = 'NULL'
# The C converter *function* to be used, if any. # The C converter *function* to be used, if any.
# (If this is not None, format_unit must be 'O&'.) # (If this is not None, format_unit must be 'O&'.)
converter = None converter = None
...@@ -1327,6 +1339,7 @@ class CConverter(metaclass=CConverterAutoRegister): ...@@ -1327,6 +1339,7 @@ class CConverter(metaclass=CConverterAutoRegister):
parameter is a clinic.Parameter instance. parameter is a clinic.Parameter instance.
data is a CRenderData instance. data is a CRenderData instance.
""" """
self.parameter = parameter
name = ensure_legal_c_identifier(self.name) name = ensure_legal_c_identifier(self.name)
# declarations # declarations
...@@ -1401,9 +1414,12 @@ class CConverter(metaclass=CConverterAutoRegister): ...@@ -1401,9 +1414,12 @@ class CConverter(metaclass=CConverterAutoRegister):
The C statement to declare this variable. The C statement to declare this variable.
""" """
declaration = [self.simple_declaration()] declaration = [self.simple_declaration()]
if self.c_default: default = self.c_default
if not default and self.parameter.group:
default = self.c_ignored_default
if default:
declaration.append(" = ") declaration.append(" = ")
declaration.append(self.c_default) declaration.append(default)
declaration.append(";") declaration.append(";")
return "".join(declaration) return "".join(declaration)
...@@ -1427,6 +1443,7 @@ class CConverter(metaclass=CConverterAutoRegister): ...@@ -1427,6 +1443,7 @@ class CConverter(metaclass=CConverterAutoRegister):
class bool_converter(CConverter): class bool_converter(CConverter):
type = 'int' type = 'int'
format_unit = 'p' format_unit = 'p'
c_ignored_default = '0'
def converter_init(self): def converter_init(self):
self.default = bool(self.default) self.default = bool(self.default)
...@@ -1435,11 +1452,13 @@ class bool_converter(CConverter): ...@@ -1435,11 +1452,13 @@ class bool_converter(CConverter):
class char_converter(CConverter): class char_converter(CConverter):
type = 'char' type = 'char'
format_unit = 'c' format_unit = 'c'
c_ignored_default = "'\0'"
@add_legacy_c_converter('B', bitwise=True) @add_legacy_c_converter('B', bitwise=True)
class byte_converter(CConverter): class byte_converter(CConverter):
type = 'byte' type = 'byte'
format_unit = 'b' format_unit = 'b'
c_ignored_default = "'\0'"
def converter_init(self, *, bitwise=False): def converter_init(self, *, bitwise=False):
if bitwise: if bitwise:
...@@ -1448,10 +1467,12 @@ class byte_converter(CConverter): ...@@ -1448,10 +1467,12 @@ class byte_converter(CConverter):
class short_converter(CConverter): class short_converter(CConverter):
type = 'short' type = 'short'
format_unit = 'h' format_unit = 'h'
c_ignored_default = "0"
class unsigned_short_converter(CConverter): class unsigned_short_converter(CConverter):
type = 'unsigned short' type = 'unsigned short'
format_unit = 'H' format_unit = 'H'
c_ignored_default = "0"
def converter_init(self, *, bitwise=False): def converter_init(self, *, bitwise=False):
if not bitwise: if not bitwise:
...@@ -1461,6 +1482,7 @@ class unsigned_short_converter(CConverter): ...@@ -1461,6 +1482,7 @@ class unsigned_short_converter(CConverter):
class int_converter(CConverter): class int_converter(CConverter):
type = 'int' type = 'int'
format_unit = 'i' format_unit = 'i'
c_ignored_default = "0"
def converter_init(self, *, from_str=False): def converter_init(self, *, from_str=False):
if from_str: if from_str:
...@@ -1469,6 +1491,7 @@ class int_converter(CConverter): ...@@ -1469,6 +1491,7 @@ class int_converter(CConverter):
class unsigned_int_converter(CConverter): class unsigned_int_converter(CConverter):
type = 'unsigned int' type = 'unsigned int'
format_unit = 'I' format_unit = 'I'
c_ignored_default = "0"
def converter_init(self, *, bitwise=False): def converter_init(self, *, bitwise=False):
if not bitwise: if not bitwise:
...@@ -1477,10 +1500,12 @@ class unsigned_int_converter(CConverter): ...@@ -1477,10 +1500,12 @@ class unsigned_int_converter(CConverter):
class long_converter(CConverter): class long_converter(CConverter):
type = 'long' type = 'long'
format_unit = 'l' format_unit = 'l'
c_ignored_default = "0"
class unsigned_long_converter(CConverter): class unsigned_long_converter(CConverter):
type = 'unsigned long' type = 'unsigned long'
format_unit = 'k' format_unit = 'k'
c_ignored_default = "0"
def converter_init(self, *, bitwise=False): def converter_init(self, *, bitwise=False):
if not bitwise: if not bitwise:
...@@ -1489,10 +1514,12 @@ class unsigned_long_converter(CConverter): ...@@ -1489,10 +1514,12 @@ class unsigned_long_converter(CConverter):
class PY_LONG_LONG_converter(CConverter): class PY_LONG_LONG_converter(CConverter):
type = 'PY_LONG_LONG' type = 'PY_LONG_LONG'
format_unit = 'L' format_unit = 'L'
c_ignored_default = "0"
class unsigned_PY_LONG_LONG_converter(CConverter): class unsigned_PY_LONG_LONG_converter(CConverter):
type = 'unsigned PY_LONG_LONG' type = 'unsigned PY_LONG_LONG'
format_unit = 'K' format_unit = 'K'
c_ignored_default = "0"
def converter_init(self, *, bitwise=False): def converter_init(self, *, bitwise=False):
if not bitwise: if not bitwise:
...@@ -1501,20 +1528,24 @@ class unsigned_PY_LONG_LONG_converter(CConverter): ...@@ -1501,20 +1528,24 @@ class unsigned_PY_LONG_LONG_converter(CConverter):
class Py_ssize_t_converter(CConverter): class Py_ssize_t_converter(CConverter):
type = 'Py_ssize_t' type = 'Py_ssize_t'
format_unit = 'n' format_unit = 'n'
c_ignored_default = "0"
class float_converter(CConverter): class float_converter(CConverter):
type = 'float' type = 'float'
format_unit = 'f' format_unit = 'f'
c_ignored_default = "0.0"
class double_converter(CConverter): class double_converter(CConverter):
type = 'double' type = 'double'
format_unit = 'd' format_unit = 'd'
c_ignored_default = "0.0"
class Py_complex_converter(CConverter): class Py_complex_converter(CConverter):
type = 'Py_complex' type = 'Py_complex'
format_unit = 'D' format_unit = 'D'
c_ignored_default = "{0.0, 0.0}"
class object_converter(CConverter): class object_converter(CConverter):
...@@ -1579,6 +1610,7 @@ class Py_buffer_converter(CConverter): ...@@ -1579,6 +1610,7 @@ class Py_buffer_converter(CConverter):
type = 'Py_buffer' type = 'Py_buffer'
format_unit = 'y*' format_unit = 'y*'
impl_by_reference = True impl_by_reference = True
c_ignored_default = "{NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL}"
def converter_init(self, *, str=False, zeroes=False, nullable=False, read_write=False): def converter_init(self, *, str=False, zeroes=False, nullable=False, read_write=False):
if not str: if not str:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment