@@ -1281,17 +1281,29 @@ class CConverter(metaclass=CConverterAutoRegister):
12811281 # Or "unspecified" if there is no default.
12821282 default = unspecified
12831283
1284- # "default" converted into a str for rendering into Python code.
1285- py_default = None
1286-
12871284 # "default" as it should appear in the documentation, as a string.
12881285 # Or None if there is no default.
12891286 doc_default = None
12901287
1288+ # "default" converted into a str for rendering into Python code.
1289+ py_default = None
1290+
12911291 # "default" converted into a C value, as a string.
12921292 # Or None if there is no default.
12931293 c_default = None
12941294
1295+ # The default value used to initialize the C variable when
1296+ # there is no default, but not specifying a default may
1297+ # result in an "uninitialized variable" warning. This can
1298+ # easily happen when using option groups--although
1299+ # properly-written code won't actually use the variable,
1300+ # the variable does get passed in to the _impl. (Ah, if
1301+ # only dataflow analysis could inline the static function!)
1302+ #
1303+ # This value is specified as a string.
1304+ # Every non-abstract subclass should supply a valid value.
1305+ c_ignored_default = 'NULL'
1306+
12951307 # The C converter *function* to be used, if any.
12961308 # (If this is not None, format_unit must be 'O&'.)
12971309 converter = None
@@ -1327,6 +1339,7 @@ def render(self, parameter, data):
13271339 parameter is a clinic.Parameter instance.
13281340 data is a CRenderData instance.
13291341 """
1342+ self .parameter = parameter
13301343 name = ensure_legal_c_identifier (self .name )
13311344
13321345 # declarations
@@ -1401,9 +1414,12 @@ def declaration(self):
14011414 The C statement to declare this variable.
14021415 """
14031416 declaration = [self .simple_declaration ()]
1404- if self .c_default :
1417+ default = self .c_default
1418+ if not default and self .parameter .group :
1419+ default = self .c_ignored_default
1420+ if default :
14051421 declaration .append (" = " )
1406- declaration .append (self . c_default )
1422+ declaration .append (default )
14071423 declaration .append (";" )
14081424 return "" .join (declaration )
14091425
@@ -1427,6 +1443,7 @@ def cleanup(self):
14271443class bool_converter (CConverter ):
14281444 type = 'int'
14291445 format_unit = 'p'
1446+ c_ignored_default = '0'
14301447
14311448 def converter_init (self ):
14321449 self .default = bool (self .default )
@@ -1435,11 +1452,13 @@ def converter_init(self):
14351452class char_converter (CConverter ):
14361453 type = 'char'
14371454 format_unit = 'c'
1455+ c_ignored_default = "'\0 '"
14381456
14391457@add_legacy_c_converter ('B' , bitwise = True )
14401458class byte_converter (CConverter ):
14411459 type = 'byte'
14421460 format_unit = 'b'
1461+ c_ignored_default = "'\0 '"
14431462
14441463 def converter_init (self , * , bitwise = False ):
14451464 if bitwise :
@@ -1448,10 +1467,12 @@ def converter_init(self, *, bitwise=False):
14481467class short_converter (CConverter ):
14491468 type = 'short'
14501469 format_unit = 'h'
1470+ c_ignored_default = "0"
14511471
14521472class unsigned_short_converter (CConverter ):
14531473 type = 'unsigned short'
14541474 format_unit = 'H'
1475+ c_ignored_default = "0"
14551476
14561477 def converter_init (self , * , bitwise = False ):
14571478 if not bitwise :
@@ -1461,6 +1482,7 @@ def converter_init(self, *, bitwise=False):
14611482class int_converter (CConverter ):
14621483 type = 'int'
14631484 format_unit = 'i'
1485+ c_ignored_default = "0"
14641486
14651487 def converter_init (self , * , from_str = False ):
14661488 if from_str :
@@ -1469,6 +1491,7 @@ def converter_init(self, *, from_str=False):
14691491class unsigned_int_converter (CConverter ):
14701492 type = 'unsigned int'
14711493 format_unit = 'I'
1494+ c_ignored_default = "0"
14721495
14731496 def converter_init (self , * , bitwise = False ):
14741497 if not bitwise :
@@ -1477,10 +1500,12 @@ def converter_init(self, *, bitwise=False):
14771500class long_converter (CConverter ):
14781501 type = 'long'
14791502 format_unit = 'l'
1503+ c_ignored_default = "0"
14801504
14811505class unsigned_long_converter (CConverter ):
14821506 type = 'unsigned long'
14831507 format_unit = 'k'
1508+ c_ignored_default = "0"
14841509
14851510 def converter_init (self , * , bitwise = False ):
14861511 if not bitwise :
@@ -1489,10 +1514,12 @@ def converter_init(self, *, bitwise=False):
14891514class PY_LONG_LONG_converter (CConverter ):
14901515 type = 'PY_LONG_LONG'
14911516 format_unit = 'L'
1517+ c_ignored_default = "0"
14921518
14931519class unsigned_PY_LONG_LONG_converter (CConverter ):
14941520 type = 'unsigned PY_LONG_LONG'
14951521 format_unit = 'K'
1522+ c_ignored_default = "0"
14961523
14971524 def converter_init (self , * , bitwise = False ):
14981525 if not bitwise :
@@ -1501,20 +1528,24 @@ def converter_init(self, *, bitwise=False):
15011528class Py_ssize_t_converter (CConverter ):
15021529 type = 'Py_ssize_t'
15031530 format_unit = 'n'
1531+ c_ignored_default = "0"
15041532
15051533
15061534class float_converter (CConverter ):
15071535 type = 'float'
15081536 format_unit = 'f'
1537+ c_ignored_default = "0.0"
15091538
15101539class double_converter (CConverter ):
15111540 type = 'double'
15121541 format_unit = 'd'
1542+ c_ignored_default = "0.0"
15131543
15141544
15151545class Py_complex_converter (CConverter ):
15161546 type = 'Py_complex'
15171547 format_unit = 'D'
1548+ c_ignored_default = "{0.0, 0.0}"
15181549
15191550
15201551class object_converter (CConverter ):
@@ -1579,6 +1610,7 @@ class Py_buffer_converter(CConverter):
15791610 type = 'Py_buffer'
15801611 format_unit = 'y*'
15811612 impl_by_reference = True
1613+ c_ignored_default = "{NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL}"
15821614
15831615 def converter_init (self , * , str = False , zeroes = False , nullable = False , read_write = False ):
15841616 if not str :
0 commit comments