summaryrefslogtreecommitdiff
path: root/Tools/clinic/clinic.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/clinic/clinic.py')
-rwxr-xr-xTools/clinic/clinic.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 65bad5174c..23f6648595 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -1252,10 +1252,11 @@ class BlockParser:
match = self.start_re.match(line.lstrip())
return match.group(1) if match else None
- def _line(self):
+ def _line(self, lookahead=False):
self.line_number += 1
line = self.input.pop()
- self.language.parse_line(line)
+ if not lookahead:
+ self.language.parse_line(line)
return line
def parse_verbatim_block(self):
@@ -1311,7 +1312,7 @@ class BlockParser:
output_add, output_output = text_accumulator()
arguments = None
while self.input:
- line = self._line()
+ line = self._line(lookahead=True)
match = checksum_re.match(line.lstrip())
arguments = match.group(1) if match else None
if arguments:
@@ -2425,11 +2426,13 @@ class int_converter(CConverter):
format_unit = 'i'
c_ignored_default = "0"
- def converter_init(self, *, types='int'):
+ def converter_init(self, *, types='int', type=None):
if types == 'str':
self.format_unit = 'C'
elif types != 'int':
fail("int_converter: illegal 'types' argument")
+ if type != None:
+ self.type = type
class unsigned_int_converter(CConverter):
type = 'unsigned int'
@@ -2532,9 +2535,9 @@ class str_converter(CConverter):
length=False, nullable=False, zeroes=False):
types = set(types.strip().split())
- bytes_type = set(("bytes",))
- str_type = set(("str",))
- all_3_type = set(("bytearray",)) | bytes_type | str_type
+ bytes_type = {"bytes"}
+ str_type = {"str"}
+ all_3_type = {"bytearray"} | bytes_type | str_type
is_bytes = types == bytes_type
is_str = types == str_type
is_all_3 = types == all_3_type
@@ -2630,12 +2633,12 @@ class Py_buffer_converter(CConverter):
fail("The only legal default value for Py_buffer is None.")
self.c_default = self.c_ignored_default
types = set(types.strip().split())
- bytes_type = set(('bytes',))
- bytearray_type = set(('bytearray',))
- buffer_type = set(('buffer',))
- rwbuffer_type = set(('rwbuffer',))
- robuffer_type = set(('robuffer',))
- str_type = set(('str',))
+ bytes_type = {'bytes'}
+ bytearray_type = {'bytearray'}
+ buffer_type = {'buffer'}
+ rwbuffer_type = {'rwbuffer'}
+ robuffer_type = {'robuffer'}
+ str_type = {'str'}
bytes_bytearray_buffer_type = bytes_type | bytearray_type | buffer_type
format_unit = None
@@ -2864,10 +2867,11 @@ class long_return_converter(CReturnConverter):
type = 'long'
conversion_fn = 'PyLong_FromLong'
cast = ''
+ unsigned_cast = ''
def render(self, function, data):
self.declare(data)
- self.err_occurred_if("_return_value == -1", data)
+ self.err_occurred_if("_return_value == {}-1".format(self.unsigned_cast), data)
data.return_conversion.append(
''.join(('return_value = ', self.conversion_fn, '(', self.cast, '_return_value);\n')))
@@ -2888,10 +2892,12 @@ class init_return_converter(long_return_converter):
class unsigned_long_return_converter(long_return_converter):
type = 'unsigned long'
conversion_fn = 'PyLong_FromUnsignedLong'
+ unsigned_cast = '(unsigned long)'
class unsigned_int_return_converter(unsigned_long_return_converter):
type = 'unsigned int'
cast = '(unsigned long)'
+ unsigned_cast = '(unsigned int)'
class Py_ssize_t_return_converter(long_return_converter):
type = 'Py_ssize_t'
@@ -2900,6 +2906,7 @@ class Py_ssize_t_return_converter(long_return_converter):
class size_t_return_converter(long_return_converter):
type = 'size_t'
conversion_fn = 'PyLong_FromSize_t'
+ unsigned_cast = '(size_t)'
class double_return_converter(CReturnConverter):