diff -r 642247a536d5 Modules/clinic/spwdmodule.c.h --- a/Modules/clinic/spwdmodule.c.h Sat Mar 14 20:17:38 2015 -0700 +++ b/Modules/clinic/spwdmodule.c.h Wed Mar 18 01:48:50 2015 -0700 @@ -36,10 +36,6 @@ #endif /* defined(HAVE_GETSPNAM) */ -#ifndef SPWD_GETSPNAM_METHODDEF - #define SPWD_GETSPNAM_METHODDEF -#endif /* !defined(SPWD_GETSPNAM_METHODDEF) */ - #if defined(HAVE_GETSPENT) PyDoc_STRVAR(spwd_getspall__doc__, @@ -64,7 +60,11 @@ #endif /* defined(HAVE_GETSPENT) */ +#ifndef SPWD_GETSPNAM_METHODDEF + #define SPWD_GETSPNAM_METHODDEF +#endif /* !defined(SPWD_GETSPNAM_METHODDEF) */ + #ifndef SPWD_GETSPALL_METHODDEF #define SPWD_GETSPALL_METHODDEF #endif /* !defined(SPWD_GETSPALL_METHODDEF) */ -/*[clinic end generated code: output=41fec4a15b0cd2a0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ab16125c5e5f2b1b input=a9049054013a1b77]*/ diff -r 642247a536d5 Modules/clinic/zlibmodule.c.h --- a/Modules/clinic/zlibmodule.c.h Sat Mar 14 20:17:38 2015 -0700 +++ b/Modules/clinic/zlibmodule.c.h Wed Mar 18 01:48:50 2015 -0700 @@ -314,10 +314,6 @@ #endif /* defined(HAVE_ZLIB_COPY) */ -#ifndef ZLIB_COMPRESS_COPY_METHODDEF - #define ZLIB_COMPRESS_COPY_METHODDEF -#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ - #if defined(HAVE_ZLIB_COPY) PyDoc_STRVAR(zlib_Decompress_copy__doc__, @@ -340,10 +336,6 @@ #endif /* defined(HAVE_ZLIB_COPY) */ -#ifndef ZLIB_DECOMPRESS_COPY_METHODDEF - #define ZLIB_DECOMPRESS_COPY_METHODDEF -#endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */ - PyDoc_STRVAR(zlib_Decompress_flush__doc__, "flush($self, length=zlib.DEF_BUF_SIZE, /)\n" "--\n" @@ -450,4 +442,8 @@ return return_value; } -/*[clinic end generated code: output=bc9473721ca7c962 input=a9049054013a1b77]*/ + +#ifndef ZLIB_COMPRESS_COPY_METHODDEF + #define ZLIB_COMPRESS_COPY_METHODDEF +#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ +/*[clinic end generated code: output=901c18189767dc08 input=a9049054013a1b77]*/ diff -r 642247a536d5 Modules/posixmodule.c --- a/Modules/posixmodule.c Sat Mar 14 20:17:38 2015 -0700 +++ b/Modules/posixmodule.c Wed Mar 18 01:48:50 2015 -0700 @@ -17212,10 +17212,6 @@ #define OS_SYSTEM_METHODDEF #endif /* !defined(OS_SYSTEM_METHODDEF) */ -#ifndef OS_SYSTEM_METHODDEF - #define OS_SYSTEM_METHODDEF -#endif /* !defined(OS_SYSTEM_METHODDEF) */ - #ifndef OS_UNAME_METHODDEF #define OS_UNAME_METHODDEF #endif /* !defined(OS_UNAME_METHODDEF) */ @@ -17388,10 +17384,6 @@ #define OS_WAITPID_METHODDEF #endif /* !defined(OS_WAITPID_METHODDEF) */ -#ifndef OS_WAITPID_METHODDEF - #define OS_WAITPID_METHODDEF -#endif /* !defined(OS_WAITPID_METHODDEF) */ - #ifndef OS_WAIT_METHODDEF #define OS_WAIT_METHODDEF #endif /* !defined(OS_WAIT_METHODDEF) */ @@ -17492,10 +17484,6 @@ #define OS_PUTENV_METHODDEF #endif /* !defined(OS_PUTENV_METHODDEF) */ -#ifndef OS_PUTENV_METHODDEF - #define OS_PUTENV_METHODDEF -#endif /* !defined(OS_PUTENV_METHODDEF) */ - #ifndef OS_UNSETENV_METHODDEF #define OS_UNSETENV_METHODDEF #endif /* !defined(OS_UNSETENV_METHODDEF) */ @@ -17603,7 +17591,7 @@ #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF #define OS_SET_HANDLE_INHERITABLE_METHODDEF #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ -/*[clinic end generated code: output=52a6140b0b052ce6 input=524ce2e021e4eba6]*/ +/*[clinic end generated code: output=b788c2d6010113e8 input=524ce2e021e4eba6]*/ static PyMethodDef posix_methods[] = { diff -r 642247a536d5 Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py Sat Mar 14 20:17:38 2015 -0700 +++ b/Tools/clinic/clinic.py Wed Mar 18 01:48:50 2015 -0700 @@ -66,6 +66,7 @@ unknown = Unknown() +_text_accumulator_nt = collections.namedtuple("_text_accumulator", "text append output") def _text_accumulator(): text = [] @@ -73,8 +74,10 @@ s = ''.join(text) text.clear() return s - return text, text.append, output - + return _text_accumulator_nt(text, text.append, output) + + +text_accumulator_nt = collections.namedtuple("text_accumulator", "text append") def text_accumulator(): """ @@ -88,7 +91,7 @@ empties the accumulator. """ text, append, output = _text_accumulator() - return append, output + return text_accumulator_nt(append, output) def warn_or_fail(fail=False, *args, filename=None, line_number=None): @@ -820,7 +823,8 @@ cpp_if = "#if " + conditional cpp_endif = "#endif /* " + conditional + " */" - if methoddef_define: + if methoddef_define and f.name not in clinic.ifndef_symbols: + clinic.ifndef_symbols.add(f.name) methoddef_ifndef = normalize_snippet(""" #ifndef {methoddef_name} #define {methoddef_name} @@ -1430,7 +1434,36 @@ if type == 'two-pass': self.id = None - self.text, self.append, self._dump = _text_accumulator() + # self.text, self.append, self._dump = _text_accumulator() + + self._start = 0 + self._array = [] + self.append = self[0].append + + def _constructor(self): + class SubDestination: + pass + + ta = _text_accumulator() + sd = SubDestination() + sd.append = ta.append + sd._output = ta.output + sd._text = ta.text + sd.dump = self.dump + sd._dump = self._dump + sd.clear = self.clear + return sd + + def __getitem__(self, i): + i -= self._start + if i < 0: + self._start = i + prefix = [self._constructor() for x in range(-i)] + self._array = prefix + self._array + i = 0 + while i >= len(self._array): + self._array.append(self._constructor()) + return self._array[i] def __repr__(self): if self.type == 'file': @@ -1442,7 +1475,12 @@ def clear(self): if self.type != 'buffer': fail("Can't clear destination" + self.name + " , it's not of type buffer") - self.text.clear() + for ta in self._array: + ta._text.clear() + + def _dump(self): + text = [ta._output() for ta in self._array] + return "".join(text) def dump(self): if self.type == 'two-pass': @@ -1493,7 +1531,7 @@ parser_prototype suppress cpp_if suppress cpp_endif suppress -methoddef_ifndef buffer +methoddef_ifndef buffer 1 preset original everything block @@ -1501,13 +1539,14 @@ parser_prototype suppress cpp_if suppress cpp_endif suppress -methoddef_ifndef buffer +methoddef_ifndef buffer 1 preset file everything file docstring_prototype suppress parser_prototype suppress impl_definition block +methoddef_ifndef file 1 preset buffer everything buffer @@ -1515,6 +1554,7 @@ impl_prototype suppress parser_prototype suppress impl_definition block +methoddef_ifndef buffer 1 preset partial-buffer everything buffer @@ -1523,6 +1563,7 @@ methoddef_define block parser_prototype block impl_definition block +methoddef_ifndef buffer 1 preset two-pass everything buffer @@ -1531,6 +1572,7 @@ methoddef_define two-pass parser_prototype two-pass impl_definition block +methoddef_ifndef buffer 1 """ @@ -1574,6 +1616,7 @@ )) self.field_destinations_stack = [] + self.ifndef_symbols = set() self.presets = {} preset = None @@ -1581,12 +1624,16 @@ line = line.strip() if not line: continue - name, value = line.split() + index = 0 + name, value, *options = line.split() if name == 'preset': self.presets[value] = preset = collections.OrderedDict() continue - destination = self.get_destination(value) + if len(options): + index = int(options[0]) + + destination = self.get_destination(value, index) if name == 'everything': for name in self.field_destinations: @@ -1599,13 +1646,11 @@ global clinic clinic = self - def get_destination(self, name, default=unspecified): + def get_destination(self, name, index=0): d = self.destinations.get(name) if not d: - if default is not unspecified: - return default fail("Destination does not exist: " + repr(name)) - return d + return d[index] def add_destination(self, name, type, *args): if name in self.destinations: @@ -3104,7 +3149,7 @@ fail("unknown destination command", repr(command)) - def directive_output(self, field, destination=''): + def directive_output(self, field, destination='', index=''): fd = self.clinic.field_destinations if field == "preset": @@ -3131,7 +3176,11 @@ self.block.output.append('\n') return - d = self.clinic.get_destination(destination) + if index != '': + index = int(index) + else: + index = 0 + d = self.clinic.get_destination(destination, index) if field == "everything": for name in list(fd):