diff --git a/Doc/Makefile.deps b/Doc/Makefile.deps index 11c6de0414e..2fc3250ce48 100644 --- a/Doc/Makefile.deps +++ b/Doc/Makefile.deps @@ -262,6 +262,7 @@ LIBFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \ lib/libsimplexmlrpc.tex \ lib/libdocxmlrpc.tex \ lib/libpyexpat.tex \ + lib/libfunctools.tex \ lib/xmldom.tex \ lib/xmldomminidom.tex \ lib/xmldompulldom.tex \ diff --git a/Doc/lib/lib.tex b/Doc/lib/lib.tex index cf657c3d1bd..0691179acb5 100644 --- a/Doc/lib/lib.tex +++ b/Doc/lib/lib.tex @@ -129,8 +129,8 @@ and how to embed it in other applications. % Functions, Functional, Generators and Iterators % XXX intro functional \input{libitertools} -\input{libfunctional} -\input{liboperator} % from runtime - better with itertools and functional +\input{libfunctools} +\input{liboperator} % from runtime - better with itertools and functools % ============= diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index 73b29ad71cd..f9a97fa6193 100644 --- a/Doc/lib/libdoctest.tex +++ b/Doc/lib/libdoctest.tex @@ -868,7 +868,7 @@ sections \ref{doctest-simple-testmod} and globs}\optional{, verbose}\optional{, report}\optional{, optionflags}\optional{, extraglobs}\optional{, raise_on_error}\optional{, - parser}} + parser}\optional{, encoding}} All arguments except \var{filename} are optional, and should be specified in keyword form. @@ -941,7 +941,13 @@ sections \ref{doctest-simple-testmod} and subclass) that should be used to extract tests from the files. It defaults to a normal parser (i.e., \code{\class{DocTestParser}()}). + Optional argument \var{encoding} specifies an encoding that should + be used to convert the file to unicode. + \versionadded{2.4} + + \versionchanged[The parameter \var{encoding} was added]{2.5} + \end{funcdesc} \begin{funcdesc}{testmod}{\optional{m}\optional{, name}\optional{, @@ -1061,7 +1067,8 @@ instances from text files and modules with doctests: \begin{funcdesc}{DocFileSuite}{\optional{module_relative}\optional{, package}\optional{, setUp}\optional{, tearDown}\optional{, globs}\optional{, - optionflags}\optional{, parser}} + optionflags}\optional{, parser}\optional{, + encoding}} Convert doctest tests from one or more text files to a \class{\refmodule{unittest}.TestSuite}. @@ -1128,11 +1135,17 @@ instances from text files and modules with doctests: subclass) that should be used to extract tests from the files. It defaults to a normal parser (i.e., \code{\class{DocTestParser}()}). + Optional argument \var{encoding} specifies an encoding that should + be used to convert the file to unicode. + \versionadded{2.4} \versionchanged[The global \code{__file__} was added to the globals provided to doctests loaded from a text file using \function{DocFileSuite()}]{2.5} + + \versionchanged[The parameter \var{encoding} was added]{2.5} + \end{funcdesc} \begin{funcdesc}{DocTestSuite}{\optional{module}\optional{, diff --git a/Doc/lib/libfunctional.tex b/Doc/lib/libfunctools.tex similarity index 92% rename from Doc/lib/libfunctional.tex rename to Doc/lib/libfunctools.tex index 9218454fe3e..a25a23a4b83 100644 --- a/Doc/lib/libfunctional.tex +++ b/Doc/lib/libfunctools.tex @@ -1,7 +1,7 @@ -\section{\module{functional} --- +\section{\module{functools} --- Higher order functions and operations on callable objects.} -\declaremodule{standard}{functional} % standard library, in Python +\declaremodule{standard}{functools} % standard library, in Python \moduleauthor{Peter Harris}{scav@blueyonder.co.uk} \moduleauthor{Raymond Hettinger}{python@rcn.com} @@ -11,12 +11,12 @@ \versionadded{2.5} -The \module{functional} module is for higher-order functions: functions +The \module{functools} module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for the purposes of this module. -The \module{functional} module defines the following function: +The \module{functools} module defines the following function: \begin{funcdesc}{partial}{func\optional{,*args}\optional{, **keywords}} Return a new \class{partial} object which when called will behave like diff --git a/Doc/lib/libpprint.tex b/Doc/lib/libpprint.tex index 45d9c873ac0..fd030389b32 100644 --- a/Doc/lib/libpprint.tex +++ b/Doc/lib/libpprint.tex @@ -20,6 +20,10 @@ and breaks them onto multiple lines if they don't fit within the allowed width. Construct \class{PrettyPrinter} objects explicitly if you need to adjust the width constraint. +\versionchanged[Dictionaries are sorted by key before the display is +computed; before 2.5, a dictionary was sorted only if its display +required more than one line, although that wasn't documented]{2.5} + The \module{pprint} module defines one class: diff --git a/Doc/lib/libsimplexmlrpc.tex b/Doc/lib/libsimplexmlrpc.tex index a25cabf6d58..7a9786125d5 100644 --- a/Doc/lib/libsimplexmlrpc.tex +++ b/Doc/lib/libsimplexmlrpc.tex @@ -111,6 +111,15 @@ simple, stand alone XML-RPC servers. Registers the XML-RPC multicall function system.multicall. \end{methoddesc} +\begin{memberdesc}[SimpleXMLRPCServer]{rpc_paths} +An attribute value that must be a tuple listing valid path portions of +the URL for receiving XML-RPC requests. Requests posted to other +paths will result in a 404 ``no such page'' HTTP error. If this +tuple is empty, all paths will be considered valid. +The default value is \code{('/', '/RPC2')}. + \versionadded{2.5} +\end{memberdesc} + Example: \begin{verbatim} diff --git a/Doc/lib/libtime.tex b/Doc/lib/libtime.tex index 8045a63ef21..b39b65063c6 100644 --- a/Doc/lib/libtime.tex +++ b/Doc/lib/libtime.tex @@ -314,7 +314,8 @@ returned by \function{ctime()}. If \var{string} cannot be parsed according to \var{format}, \exception{ValueError} is raised. If the string to be parsed has excess data after parsing, \exception{ValueError} is raised. The default values used to fill in -any missing data are \code{(1900, 1, 1, 0, 0, 0, 0, 1, -1)} . +any missing data when more accurate values cannot be inferred are +\code{(1900, 1, 1, 0, 0, 0, 0, 1, -1)} . Support for the \code{\%Z} directive is based on the values contained in \code{tzname} and whether \code{daylight} is true. Because of this, diff --git a/Doc/lib/liburllib2.tex b/Doc/lib/liburllib2.tex index 7c8ad5dce26..f77ed253536 100644 --- a/Doc/lib/liburllib2.tex +++ b/Doc/lib/liburllib2.tex @@ -65,9 +65,7 @@ exists), \class{HTTPSHandler} will also be added. Beginning in Python 2.3, a \class{BaseHandler} subclass may also change its \member{handler_order} member variable to modify its -position in the handlers list. Besides \class{ProxyHandler}, which has -\member{handler_order} of \code{100}, all handlers currently have it -set to \code{500}. +position in the handlers list. \end{funcdesc} diff --git a/Doc/whatsnew/whatsnew25.tex b/Doc/whatsnew/whatsnew25.tex index 3006624dcb6..5bee789c4ea 100644 --- a/Doc/whatsnew/whatsnew25.tex +++ b/Doc/whatsnew/whatsnew25.tex @@ -125,7 +125,7 @@ Wouters.} %====================================================================== \section{PEP 309: Partial Function Application\label{pep-309}} -The \module{functional} module is intended to contain tools for +The \module{functools} module is intended to contain tools for functional-style programming. Currently it only contains a \class{partial()} function, but new functions will probably be added in future versions of Python. @@ -136,7 +136,7 @@ parameters filled in. Consider a Python function \code{f(a, b, c)}; you could create a new function \code{g(b, c)} that was equivalent to \code{f(1, b, c)}. This is called ``partial function application'', and is provided by the \class{partial} class in the new -\module{functional} module. +\module{functools} module. The constructor for \class{partial} takes the arguments \code{(\var{function}, \var{arg1}, \var{arg2}, ... @@ -147,18 +147,18 @@ with the filled-in arguments. Here's a small but realistic example: \begin{verbatim} -import functional +import functools def log (message, subsystem): "Write the contents of 'message' to the specified subsystem." print '%s: %s' % (subsystem, message) ... -server_log = functional.partial(log, subsystem='server') +server_log = functools.partial(log, subsystem='server') server_log('Unable to open socket') \end{verbatim} -Here's another example, from a program that uses PyGTk. Here a +Here's another example, from a program that uses PyGTK. Here a context-sensitive pop-up menu is being constructed dynamically. The callback provided for the menu option is a partially applied version of the \method{open_item()} method, where the first argument has been @@ -170,7 +170,7 @@ class Application: def open_item(self, path): ... def init (self): - open_func = functional.partial(self.open_item, item_path) + open_func = functools.partial(self.open_item, item_path) popup_menu.append( ("Open", open_func, 1) ) \end{verbatim} @@ -1508,6 +1508,14 @@ therefore now works on non-{\UNIX} platforms. (Patch from Robert Kiendl.) % Patch #1472854 +\item The \module{SimpleXMLRPCServer} and \module{DocXMLRPCServer} +classes now have a \member{rpc_paths} attribute that constrains +XML-RPC operations to a limited set of URL paths; the default is +to allow only \code{'/'} and \code{'/RPC2'}. Setting +\member{rpc_paths} to \code{None} or an empty tuple disables +this path checking. +% Bug #1473048 + \item The \module{socket} module now supports \constant{AF_NETLINK} sockets on Linux, thanks to a patch from Philippe Biondi. Netlink sockets are a Linux-specific mechanism for communications @@ -2163,6 +2171,13 @@ longer accept a return value of \code{None} from the arguments instead. The modules also no longer accept the deprecated \var{bin} keyword parameter. +\item Library: The \module{SimpleXMLRPCServer} and \module{DocXMLRPCServer} +classes now have a \member{rpc_paths} attribute that constrains +XML-RPC operations to a limited set of URL paths; the default is +to allow only \code{'/'} and \code{'/RPC2'}. Setting +\member{rpc_paths} to \code{None} or an empty tuple disables +this path checking. + \item C API: Many functions now use \ctype{Py_ssize_t} instead of \ctype{int} to allow processing more data on 64-bit machines. Extension code may need to make the same change to avoid diff --git a/Include/dictobject.h b/Include/dictobject.h index c917782b3ee..fd3d1fc3529 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -8,7 +8,7 @@ extern "C" { /* Dictionary object type -- mapping from hashable object to object */ /* The distribution includes a separate file, Objects/dictnotes.txt, - describing explorations into dictionary design and optimization. + describing explorations into dictionary design and optimization. It covers typical dictionary use patterns, the parameters for tuning dictionaries, and several ideas for possible optimizations. */ @@ -48,7 +48,11 @@ meaning otherwise. #define PyDict_MINSIZE 8 typedef struct { - long me_hash; /* cached hash code of me_key */ + /* Cached hash code of me_key. Note that hash codes are C longs. + * We have to use Py_ssize_t instead because dict_popitem() abuses + * me_hash to hold a search finger. + */ + Py_ssize_t me_hash; PyObject *me_key; PyObject *me_value; } PyDictEntry; @@ -65,14 +69,14 @@ it's two-thirds full. typedef struct _dictobject PyDictObject; struct _dictobject { PyObject_HEAD - int ma_fill; /* # Active + # Dummy */ - int ma_used; /* # Active */ + Py_ssize_t ma_fill; /* # Active + # Dummy */ + Py_ssize_t ma_used; /* # Active */ /* The table contains ma_mask + 1 slots, and that's a power of 2. * We store the mask instead of the size because the mask is more * frequently needed. */ - int ma_mask; + Py_ssize_t ma_mask; /* ma_table points to ma_smalltable for small tables, else to * additional malloc'ed memory. ma_table is never NULL! This rule diff --git a/Include/pyport.h b/Include/pyport.h index 74ce9934971..47b9f70628d 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -174,6 +174,27 @@ typedef Py_intptr_t Py_ssize_t; #define Py_LOCAL_INLINE(type) static type #endif +/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks + * are often very short. While most platforms have highly optimized code for + * large transfers, the setup costs for memcpy are often quite high. MEMCPY + * solves this by doing short copies "in line". + */ + +#if defined(_MSC_VER) +#define Py_MEMCPY(target, source, length) do { \ + size_t i_, n_ = (length); \ + char *t_ = (void*) (target); \ + const char *s_ = (void*) (source); \ + if (n_ >= 16) \ + memcpy(t_, s_, n_); \ + else \ + for (i_ = 0; i_ < n_; i_++) \ + t_[i_] = s_[i_]; \ + } while (0) +#else +#define Py_MEMCPY memcpy +#endif + #include #include /* Moved here from the math section, before extern "C" */ diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 0531aedb30d..8c39cfe2d63 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -357,15 +357,8 @@ typedef PY_UNICODE_TYPE Py_UNICODE; Py_UNICODE_ISDIGIT(ch) || \ Py_UNICODE_ISNUMERIC(ch)) -/* memcpy has a considerable setup overhead on many platforms; use a - loop for short strings (the "16" below is pretty arbitary) */ -#define Py_UNICODE_COPY(target, source, length) do\ - {Py_ssize_t i_; Py_UNICODE *t_ = (target); const Py_UNICODE *s_ = (source);\ - if (length > 16)\ - memcpy(t_, s_, (length)*sizeof(Py_UNICODE));\ - else\ - for (i_ = 0; i_ < (length); i_++) t_[i_] = s_[i_];\ - } while (0) +#define Py_UNICODE_COPY(target, source, length) \ + Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE)) #define Py_UNICODE_FILL(target, value, length) do\ {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\ diff --git a/Lib/DocXMLRPCServer.py b/Lib/DocXMLRPCServer.py index 259fb18b863..86ed32b6fc1 100644 --- a/Lib/DocXMLRPCServer.py +++ b/Lib/DocXMLRPCServer.py @@ -227,6 +227,10 @@ class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): Interpret all HTTP GET requests as requests for server documentation. """ + # Check that the path is legal + if not self.is_rpc_path_valid(): + self.report_404() + return response = self.server.generate_html_documentation() self.send_response(200) diff --git a/Lib/SimpleXMLRPCServer.py b/Lib/SimpleXMLRPCServer.py index 1d4f00f2e3a..0846a68ce6a 100644 --- a/Lib/SimpleXMLRPCServer.py +++ b/Lib/SimpleXMLRPCServer.py @@ -247,10 +247,10 @@ class SimpleXMLRPCDispatcher: of changing method dispatch behavior. """ - params, method = xmlrpclib.loads(data) - - # generate response try: + params, method = xmlrpclib.loads(data) + + # generate response if dispatch_method is not None: response = dispatch_method(method, params) else: @@ -423,6 +423,17 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): XML-RPC requests. """ + # Class attribute listing the accessible path components; + # paths not on this list will result in a 404 error. + rpc_paths = ('/', '/RPC2') + + def is_rpc_path_valid(self): + if self.rpc_paths: + return self.path in self.rpc_paths + else: + # If .rpc_paths is empty, just assume all paths are legal + return True + def do_POST(self): """Handles the HTTP POST request. @@ -430,6 +441,11 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): which are forwarded to the server's _dispatch method for handling. """ + # Check that the path is legal + if not self.is_rpc_path_valid(): + self.report_404() + return + try: # Get arguments by reading body of request. # We read this in chunks to avoid straining @@ -468,6 +484,18 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.wfile.flush() self.connection.shutdown(1) + def report_404 (self): + # Report a 404 error + self.send_response(404) + response = 'No such page' + self.send_header("Content-type", "text/plain") + self.send_header("Content-length", str(len(response))) + self.end_headers() + self.wfile.write(response) + # shut down the connection + self.wfile.flush() + self.connection.shutdown(1) + def log_request(self, code='-', size='-'): """Selectively log an accepted request.""" diff --git a/Lib/aifc.py b/Lib/aifc.py index 781d77cee40..a5f86be455b 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -201,6 +201,8 @@ def _write_long(f, x): f.write(struct.pack('>L', x)) def _write_string(f, s): + if len(s) > 255: + raise ValueError("string exceeds maximum pstring length") f.write(chr(len(s))) f.write(s) if len(s) & 1 == 0: diff --git a/Lib/base64.py b/Lib/base64.py index 8914acce923..c196cd8a841 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -126,7 +126,9 @@ _b32alphabet = { 8: 'I', 17: 'R', 26: '2', } -_b32tab = [v for v in _b32alphabet.values()] +_b32tab = _b32alphabet.items() +_b32tab.sort() +_b32tab = [v for k, v in _b32tab] _b32rev = dict([(v, long(k)) for k, v in _b32alphabet.items()]) diff --git a/Lib/doctest.py b/Lib/doctest.py index 857bc1a6eb4..d5491635e8d 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -1056,12 +1056,13 @@ class DocTestRunner: >>> tests = DocTestFinder().find(_TestClass) >>> runner = DocTestRunner(verbose=False) + >>> tests.sort(key = lambda test: test.name) >>> for test in tests: - ... print runner.run(test) - (0, 2) - (0, 1) - (0, 2) - (0, 2) + ... print test.name, '->', runner.run(test) + _TestClass -> (0, 2) + _TestClass.__init__ -> (0, 2) + _TestClass.get -> (0, 2) + _TestClass.square -> (0, 1) The `summarize` method prints a summary of all the test cases that have been run by the runner, and returns an aggregated `(f, t)` @@ -1869,7 +1870,8 @@ def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None, def testfile(filename, module_relative=True, name=None, package=None, globs=None, verbose=None, report=True, optionflags=0, - extraglobs=None, raise_on_error=False, parser=DocTestParser()): + extraglobs=None, raise_on_error=False, parser=DocTestParser(), + encoding=None): """ Test examples in the given file. Return (#failures, #tests). @@ -1935,6 +1937,9 @@ def testfile(filename, module_relative=True, name=None, package=None, Optional keyword arg "parser" specifies a DocTestParser (or subclass) that should be used to extract tests from the files. + Optional keyword arg "encoding" specifies an encoding that should + be used to convert the file to unicode. + Advanced tomfoolery: testmod runs methods of a local instance of class doctest.Tester, then merges the results into (or creates) global Tester instance doctest.master. Methods of doctest.master @@ -1969,6 +1974,9 @@ def testfile(filename, module_relative=True, name=None, package=None, else: runner = DocTestRunner(verbose=verbose, optionflags=optionflags) + if encoding is not None: + text = text.decode(encoding) + # Read the file, convert it to a test, and run it. test = parser.get_doctest(text, globs, name, filename, 0) runner.run(test) @@ -2339,7 +2347,8 @@ class DocFileCase(DocTestCase): ) def DocFileTest(path, module_relative=True, package=None, - globs=None, parser=DocTestParser(), **options): + globs=None, parser=DocTestParser(), + encoding=None, **options): if globs is None: globs = {} else: @@ -2358,6 +2367,10 @@ def DocFileTest(path, module_relative=True, package=None, # Find the file and read it. name = os.path.basename(path) + # If an encoding is specified, use it to convert the file to unicode + if encoding is not None: + doc = doc.decode(encoding) + # Convert it to a test, and wrap it in a DocFileCase. test = parser.get_doctest(doc, globs, name, path, 0) return DocFileCase(test, **options) @@ -2414,6 +2427,9 @@ def DocFileSuite(*paths, **kw): parser A DocTestParser (or subclass) that should be used to extract tests from the files. + + encoding + An encoding that will be used to convert the files to unicode. """ suite = unittest.TestSuite() diff --git a/Lib/functools.py b/Lib/functools.py new file mode 100644 index 00000000000..4935c9f68e8 --- /dev/null +++ b/Lib/functools.py @@ -0,0 +1,26 @@ +"""functools.py - Tools for working with functions +""" +# Python module wrapper for _functools C module +# to allow utilities written in Python to be added +# to the functools module. +# Written by Nick Coghlan +# Copyright (c) 2006 Python Software Foundation. + +from _functools import partial +__all__ = [ + "partial", +] + +# Still to come here (need to write tests and docs): +# update_wrapper - utility function to transfer basic function +# metadata to wrapper functions +# WRAPPER_ASSIGNMENTS & WRAPPER_UPDATES - defaults args to above +# (update_wrapper has been approved by BDFL) +# wraps - decorator factory equivalent to: +# def wraps(f): +# return partial(update_wrapper, wrapped=f) +# +# The wraps function makes it easy to avoid the bug that afflicts the +# decorator example in the python-dev email proposing the +# update_wrapper function: +# http://mail.python.org/pipermail/python-dev/2006-May/064775.html diff --git a/Lib/optparse.py b/Lib/optparse.py index 9ac987e819c..6b8f5d10b8d 100644 --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -611,8 +611,10 @@ class Option: else: setattr(self, attr, None) if attrs: + attrs = attrs.keys() + attrs.sort() raise OptionError( - "invalid keyword arguments: %s" % ", ".join(attrs.keys()), + "invalid keyword arguments: %s" % ", ".join(attrs), self) @@ -1661,6 +1663,7 @@ def _match_abbrev(s, wordmap): raise BadOptionError(s) else: # More than one possible completion: ambiguous prefix. + possibilities.sort() raise AmbiguousOptionError(s, possibilities) diff --git a/Lib/pprint.py b/Lib/pprint.py index f77a0e22483..19a3dc249ce 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -246,7 +246,7 @@ def _safe_repr(object, context, maxlevels, level): append = components.append level += 1 saferepr = _safe_repr - for k, v in object.iteritems(): + for k, v in sorted(object.items()): krepr, kreadable, krecur = saferepr(k, context, maxlevels, level) vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level) append("%s: %s" % (krepr, vrepr)) diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py index 0812e22ff47..073122417d7 100644 --- a/Lib/pyclbr.py +++ b/Lib/pyclbr.py @@ -42,7 +42,7 @@ Instances of this class have the following instance variables: import sys import imp import tokenize # Python tokenizer -from token import NAME, DEDENT, NEWLINE +from token import NAME, DEDENT, NEWLINE, OP from operator import itemgetter __all__ = ["readmodule", "readmodule_ex", "Class", "Function"] @@ -219,8 +219,10 @@ def _readmodule(module, path, inpackage=None): break elif token == ',' and level == 1: pass - else: + # only use NAME and OP (== dot) tokens for type name + elif tokentype in (NAME, OP) and level == 1: super.append(token) + # expressions in the base list are not supported inherit = names cur_class = Class(fullmodule, class_name, inherit, file, lineno) if not stack: diff --git a/Lib/test/crashers/dictresize_attack.py b/Lib/test/crashers/dictresize_attack.py deleted file mode 100644 index 1895791387f..00000000000 --- a/Lib/test/crashers/dictresize_attack.py +++ /dev/null @@ -1,32 +0,0 @@ -# http://www.python.org/sf/1456209 - -# A dictresize() attack. If oldtable == mp->ma_smalltable then pure -# Python code can mangle with mp->ma_smalltable while it is being walked -# over. - -class X(object): - - def __hash__(self): - return 5 - - def __eq__(self, other): - if resizing: - d.clear() - return False - - -d = {} - -resizing = False - -d[X()] = 1 -d[X()] = 2 -d[X()] = 3 -d[X()] = 4 -d[X()] = 5 - -# now trigger a resize -resizing = True -d[9] = 6 - -# ^^^ I get Segmentation fault or Illegal instruction here. diff --git a/Lib/test/output/test_exceptions b/Lib/test/output/test_exceptions deleted file mode 100644 index 28a7aa8390f..00000000000 --- a/Lib/test/output/test_exceptions +++ /dev/null @@ -1,52 +0,0 @@ -test_exceptions -5. Built-in exceptions -spam -AttributeError -spam -EOFError -spam -IOError -spam -ImportError -spam -IndexError -'spam' -KeyError -spam -KeyboardInterrupt -(not testable in a script) -spam -MemoryError -(not safe to test) -spam -NameError -spam -OverflowError -spam -RuntimeError -(not used any more?) -spam -SyntaxError -'continue' not supported inside 'finally' clause -ok -'continue' not properly in loop -ok -'continue' not properly in loop -ok -spam -IndentationError -spam -TabError -spam -SystemError -(hard to reproduce) -spam -SystemExit -spam -TypeError -spam -ValueError -spam -ZeroDivisionError -spam -Exception diff --git a/Lib/test/output/test_operations b/Lib/test/output/test_operations index 32eff3f21a8..8a1bc2a229c 100644 --- a/Lib/test/output/test_operations +++ b/Lib/test/output/test_operations @@ -1,6 +1,21 @@ test_operations 3. Operations XXX Mostly not yet implemented -3.1 Dictionary lookups succeed even if __cmp__() raises an exception +3.1 Dictionary lookups fail if __cmp__() raises an exception raising error -No exception passed through. +d[x2] = 2: caught the RuntimeError outside +raising error +z = d[x2]: caught the RuntimeError outside +raising error +x2 in d: caught the RuntimeError outside +raising error +d.has_key(x2): caught the RuntimeError outside +raising error +d.get(x2): caught the RuntimeError outside +raising error +d.setdefault(x2, 42): caught the RuntimeError outside +raising error +d.pop(x2): caught the RuntimeError outside +raising error +d.update({x2: 2}): caught the RuntimeError outside +resize bugs not triggered. diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 86961b08aac..314e7e15319 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -513,6 +513,9 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False): else: cfp = cStringIO.StringIO() if huntrleaks: + if not hasattr(sys, 'gettotalrefcount'): + raise Exception("Tracking reference leaks requires a debug build " + "of Python") refrep = open(huntrleaks[2], "a") try: save_stdout = sys.stdout diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 489af20a16d..aaa2dc20a92 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -106,10 +106,19 @@ class CommonTest(unittest.TestCase): self.checkequal(3, 'aaa', 'count', 'a') self.checkequal(0, 'aaa', 'count', 'b') self.checkequal(0, 'aaa', 'count', 'b') + self.checkequal(2, 'aaa', 'count', 'a', 1) + self.checkequal(0, 'aaa', 'count', 'a', 10) self.checkequal(1, 'aaa', 'count', 'a', -1) self.checkequal(3, 'aaa', 'count', 'a', -10) + self.checkequal(1, 'aaa', 'count', 'a', 0, 1) + self.checkequal(3, 'aaa', 'count', 'a', 0, 10) self.checkequal(2, 'aaa', 'count', 'a', 0, -1) self.checkequal(0, 'aaa', 'count', 'a', 0, -10) + self.checkequal(3, 'aaa', 'count', '', 1) + self.checkequal(1, 'aaa', 'count', '', 3) + self.checkequal(0, 'aaa', 'count', '', 10) + self.checkequal(2, 'aaa', 'count', '', -1) + self.checkequal(4, 'aaa', 'count', '', -10) self.checkraises(TypeError, 'hello', 'count') self.checkraises(TypeError, 'hello', 'count', 42) @@ -146,6 +155,10 @@ class CommonTest(unittest.TestCase): self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1) self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4) + self.checkequal(0, 'abc', 'find', '', 0) + self.checkequal(3, 'abc', 'find', '', 3) + self.checkequal(-1, 'abc', 'find', '', 4) + self.checkraises(TypeError, 'hello', 'find') self.checkraises(TypeError, 'hello', 'find', 42) @@ -180,6 +193,10 @@ class CommonTest(unittest.TestCase): self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd') self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz') + self.checkequal(3, 'abc', 'rfind', '', 0) + self.checkequal(3, 'abc', 'rfind', '', 3) + self.checkequal(-1, 'abc', 'rfind', '', 4) + self.checkraises(TypeError, 'hello', 'rfind') self.checkraises(TypeError, 'hello', 'rfind', 42) @@ -477,12 +494,7 @@ class CommonTest(unittest.TestCase): # Operations on the empty string EQ("", "", "replace", "", "") - - #EQ("A", "", "replace", "", "A") - # That was the correct result; this is the result we actually get - # now (for str, but not for unicode): - #EQ("", "", "replace", "", "A") - + EQ("A", "", "replace", "", "A") EQ("", "", "replace", "A", "") EQ("", "", "replace", "A", "A") EQ("", "", "replace", "", "", 100) diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 8511a5ae97d..feb6ddf6139 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -875,7 +875,10 @@ Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back def test_delimiters(self): sniffer = csv.Sniffer() dialect = sniffer.sniff(self.sample3) - self.assertEqual(dialect.delimiter, "0") + # given that all three lines in sample3 are equal, + # I think that any character could have been 'guessed' as the + # delimiter, depending on dictionary order + self.assert_(dialect.delimiter in self.sample3) dialect = sniffer.sniff(self.sample3, delimiters="?,") self.assertEqual(dialect.delimiter, "?") dialect = sniffer.sniff(self.sample3, delimiters="/,") diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 443c9624987..92d2d74eafd 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -1937,9 +1937,10 @@ def test_DocFileSuite(): >>> import unittest >>> suite = doctest.DocFileSuite('test_doctest.txt', - ... 'test_doctest2.txt') + ... 'test_doctest2.txt', + ... 'test_doctest4.txt') >>> suite.run(unittest.TestResult()) - + The test files are looked for in the directory containing the calling module. A package keyword argument can be provided to @@ -1948,9 +1949,10 @@ def test_DocFileSuite(): >>> import unittest >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', + ... 'test_doctest4.txt', ... package='test') >>> suite.run(unittest.TestResult()) - + '/' should be used as a path separator. It will be converted to a native separator at run time: @@ -1995,19 +1997,21 @@ def test_DocFileSuite(): >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', + ... 'test_doctest4.txt', ... globs={'favorite_color': 'blue'}) >>> suite.run(unittest.TestResult()) - + In this case, we supplied a missing favorite color. You can provide doctest options: >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', + ... 'test_doctest4.txt', ... optionflags=doctest.DONT_ACCEPT_BLANKLINE, ... globs={'favorite_color': 'blue'}) >>> suite.run(unittest.TestResult()) - + And, you can provide setUp and tearDown functions: @@ -2025,9 +2029,10 @@ def test_DocFileSuite(): >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', + ... 'test_doctest4.txt', ... setUp=setUp, tearDown=tearDown) >>> suite.run(unittest.TestResult()) - + But the tearDown restores sanity: @@ -2060,6 +2065,17 @@ def test_DocFileSuite(): >>> suite.run(unittest.TestResult()) + If the tests contain non-ASCII characters, we have to specify which + encoding the file is encoded with. We do so by using the `encoding` + parameter: + + >>> suite = doctest.DocFileSuite('test_doctest.txt', + ... 'test_doctest2.txt', + ... 'test_doctest4.txt', + ... encoding='utf-8') + >>> suite.run(unittest.TestResult()) + + """ def test_trailing_space_in_test(): @@ -2266,6 +2282,32 @@ debugging): Traceback (most recent call last): UnexpectedException: ... >>> doctest.master = None # Reset master. + +If the tests contain non-ASCII characters, the tests might fail, since +it's unknown which encoding is used. The encoding can be specified +using the optional keyword argument `encoding`: + + >>> doctest.testfile('test_doctest4.txt') # doctest: +ELLIPSIS + ********************************************************************** + File "...", line 7, in test_doctest4.txt + Failed example: + u'...' + Expected: + u'f\xf6\xf6' + Got: + u'f\xc3\xb6\xc3\xb6' + ********************************************************************** + ... + ********************************************************************** + 1 items had failures: + 2 of 4 in test_doctest4.txt + ***Test Failed*** 2 failures. + (2, 4) + >>> doctest.master = None # Reset master. + + >>> doctest.testfile('test_doctest4.txt', encoding='utf-8') + (0, 4) + >>> doctest.master = None # Reset master. """ # old_test1, ... used to live in doctest.py, but cluttered it. Note diff --git a/Lib/test/test_doctest4.txt b/Lib/test/test_doctest4.txt new file mode 100644 index 00000000000..a219d16a6ea --- /dev/null +++ b/Lib/test/test_doctest4.txt @@ -0,0 +1,17 @@ +This is a sample doctest in a text file that contains non-ASCII characters. +This file is encoded using UTF-8. + +In order to get this test to pass, we have to manually specify the +encoding. + + >>> u'föö' + u'f\xf6\xf6' + + >>> u'bąr' + u'b\u0105r' + + >>> 'föö' + 'f\xc3\xb6\xc3\xb6' + + >>> 'bąr' + 'b\xc4\x85r' diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 8f995f7fcc3..ebab91384b3 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1,303 +1,310 @@ # Python test set -- part 5, built-in exceptions -from test.test_support import TestFailed, TESTFN, unlink -from types import ClassType +from test.test_support import TESTFN, unlink, run_unittest import warnings import sys, traceback, os +import unittest -print '5. Built-in exceptions' # XXX This is not really enough, each *operation* should be tested! -# Reloading the built-in exceptions module failed prior to Py2.2, while it -# should act the same as reloading built-in sys. -try: - import exceptions - reload(exceptions) -except ImportError, e: - raise TestFailed, e +class ExceptionTests(unittest.TestCase): -def test_raise_catch(exc): - try: - raise exc, "spam" - except exc, err: - buf = str(err) - try: - raise exc("spam") - except exc, err: - buf = str(err) - print buf + def testReload(self): + # Reloading the built-in exceptions module failed prior to Py2.2, while it + # should act the same as reloading built-in sys. + try: + import exceptions + reload(exceptions) + except ImportError, e: + self.fail("reloading exceptions: %s" % e) -def r(thing): - test_raise_catch(thing) - print getattr(thing, '__name__', thing) + def raise_catch(self, exc, excname): + try: + raise exc, "spam" + except exc, err: + buf1 = str(err) + try: + raise exc("spam") + except exc, err: + buf2 = str(err) + self.assertEquals(buf1, buf2) + self.assertEquals(exc.__name__, excname) -r(AttributeError) -import sys -try: x = sys.undefined_attribute -except AttributeError: pass + def testRaising(self): + self.raise_catch(AttributeError, "AttributeError") + self.assertRaises(AttributeError, getattr, sys, "undefined_attribute") -r(EOFError) -import sys -fp = open(TESTFN, 'w') -fp.close() -fp = open(TESTFN, 'r') -savestdin = sys.stdin -try: - try: - import marshal - marshal.loads('') - except EOFError: - pass -finally: - sys.stdin = savestdin - fp.close() + self.raise_catch(EOFError, "EOFError") + fp = open(TESTFN, 'w') + fp.close() + fp = open(TESTFN, 'r') + savestdin = sys.stdin + try: + try: + import marshal + marshal.loads('') + except EOFError: + pass + finally: + sys.stdin = savestdin + fp.close() + unlink(TESTFN) -r(IOError) -try: open('this file does not exist', 'r') -except IOError: pass + self.raise_catch(IOError, "IOError") + self.assertRaises(IOError, open, 'this file does not exist', 'r') -r(ImportError) -try: import undefined_module -except ImportError: pass + self.raise_catch(ImportError, "ImportError") + self.assertRaises(ImportError, __import__, "undefined_module") -r(IndexError) -x = [] -try: a = x[10] -except IndexError: pass + self.raise_catch(IndexError, "IndexError") + x = [] + self.assertRaises(IndexError, x.__getitem__, 10) -r(KeyError) -x = {} -try: a = x['key'] -except KeyError: pass + self.raise_catch(KeyError, "KeyError") + x = {} + self.assertRaises(KeyError, x.__getitem__, 'key') -r(KeyboardInterrupt) -print '(not testable in a script)' + self.raise_catch(KeyboardInterrupt, "KeyboardInterrupt") -r(MemoryError) -print '(not safe to test)' + self.raise_catch(MemoryError, "MemoryError") -r(NameError) -try: x = undefined_variable -except NameError: pass + self.raise_catch(NameError, "NameError") + try: x = undefined_variable + except NameError: pass -r(OverflowError) -x = 1 -for dummy in range(128): - x += x # this simply shouldn't blow up + self.raise_catch(OverflowError, "OverflowError") + x = 1 + for dummy in range(128): + x += x # this simply shouldn't blow up -r(RuntimeError) -print '(not used any more?)' + self.raise_catch(RuntimeError, "RuntimeError") -r(SyntaxError) -try: exec '/\n' -except SyntaxError: pass + self.raise_catch(SyntaxError, "SyntaxError") + try: exec '/\n' + except SyntaxError: pass -# make sure the right exception message is raised for each of these -# code fragments: + self.raise_catch(IndentationError, "IndentationError") -def ckmsg(src, msg): - try: - compile(src, '', 'exec') - except SyntaxError, e: - print e.msg - if e.msg == msg: - print "ok" - else: - print "expected:", msg - else: - print "failed to get expected SyntaxError" + self.raise_catch(TabError, "TabError") + # can only be tested under -tt, and is the only test for -tt + #try: compile("try:\n\t1/0\n \t1/0\nfinally:\n pass\n", '', 'exec') + #except TabError: pass + #else: self.fail("TabError not raised") -s = '''\ -while 1: - try: - pass - finally: - continue -''' -if sys.platform.startswith('java'): - print "'continue' not supported inside 'finally' clause" - print "ok" -else: - ckmsg(s, "'continue' not supported inside 'finally' clause") -s = '''\ -try: - continue -except: - pass -''' -ckmsg(s, "'continue' not properly in loop") -ckmsg("continue\n", "'continue' not properly in loop") + self.raise_catch(SystemError, "SystemError") -r(IndentationError) + self.raise_catch(SystemExit, "SystemExit") + self.assertRaises(SystemExit, sys.exit, 0) -r(TabError) -# can only be tested under -tt, and is the only test for -tt -#try: compile("try:\n\t1/0\n \t1/0\nfinally:\n pass\n", '', 'exec') -#except TabError: pass -#else: raise TestFailed + self.raise_catch(TypeError, "TypeError") + try: [] + () + except TypeError: pass -r(SystemError) -print '(hard to reproduce)' + self.raise_catch(ValueError, "ValueError") + self.assertRaises(ValueError, chr, 10000) -r(SystemExit) -import sys -try: sys.exit(0) -except SystemExit: pass + self.raise_catch(ZeroDivisionError, "ZeroDivisionError") + try: x = 1/0 + except ZeroDivisionError: pass -r(TypeError) -try: [] + () -except TypeError: pass + self.raise_catch(Exception, "Exception") + try: x = 1/0 + except Exception, e: pass -r(ValueError) -try: x = chr(10000) -except ValueError: pass + def testSyntaxErrorMessage(self): + # make sure the right exception message is raised for each of + # these code fragments -r(ZeroDivisionError) -try: x = 1/0 -except ZeroDivisionError: pass + def ckmsg(src, msg): + try: + compile(src, '', 'exec') + except SyntaxError, e: + if e.msg != msg: + self.fail("expected %s, got %s" % (msg, e.msg)) + else: + self.fail("failed to get expected SyntaxError") -r(Exception) -try: x = 1/0 -except Exception, e: pass + s = '''while 1: + try: + pass + finally: + continue''' -# test that setting an exception at the C level works even if the -# exception object can't be constructed. + if not sys.platform.startswith('java'): + ckmsg(s, "'continue' not supported inside 'finally' clause") -class BadException(Exception): - def __init__(self): - raise RuntimeError, "can't instantiate BadException" + s = '''if 1: + try: + continue + except: + pass''' -# Exceptions must inherit from BaseException, raising invalid exception -# should instead raise SystemError -class InvalidException: - pass + ckmsg(s, "'continue' not properly in loop") + ckmsg("continue\n", "'continue' not properly in loop") -def test_capi1(): - import _testcapi - try: - _testcapi.raise_exception(BadException, 1) - except TypeError, err: - exc, err, tb = sys.exc_info() - co = tb.tb_frame.f_code - assert co.co_name == "test_capi1" - assert co.co_filename.endswith('test_exceptions'+os.extsep+'py') - else: - print "Expected exception" + def testSettingException(self): + # test that setting an exception at the C level works even if the + # exception object can't be constructed. -def test_capi2(): - import _testcapi - try: - _testcapi.raise_exception(BadException, 0) - except RuntimeError, err: - exc, err, tb = sys.exc_info() - co = tb.tb_frame.f_code - assert co.co_name == "__init__" - assert co.co_filename.endswith('test_exceptions'+os.extsep+'py') - co2 = tb.tb_frame.f_back.f_code - assert co2.co_name == "test_capi2" - else: - print "Expected exception" + class BadException(Exception): + def __init__(self_): + raise RuntimeError, "can't instantiate BadException" -def test_capi3(): - import _testcapi - try: - _testcapi.raise_exception(InvalidException, 1) - except SystemError: - pass - except InvalidException: - raise AssertionError("Managed to raise InvalidException"); - else: - print "Expected SystemError exception" - + class InvalidException: + pass -if not sys.platform.startswith('java'): - test_capi1() - test_capi2() - test_capi3() + def test_capi1(): + import _testcapi + try: + _testcapi.raise_exception(BadException, 1) + except TypeError, err: + exc, err, tb = sys.exc_info() + co = tb.tb_frame.f_code + self.assertEquals(co.co_name, "test_capi1") + self.assert_(co.co_filename.endswith('test_exceptions'+os.extsep+'py')) + else: + self.fail("Expected exception") -unlink(TESTFN) + def test_capi2(): + import _testcapi + try: + _testcapi.raise_exception(BadException, 0) + except RuntimeError, err: + exc, err, tb = sys.exc_info() + co = tb.tb_frame.f_code + self.assertEquals(co.co_name, "__init__") + self.assert_(co.co_filename.endswith('test_exceptions'+os.extsep+'py')) + co2 = tb.tb_frame.f_back.f_code + self.assertEquals(co2.co_name, "test_capi2") + else: + self.fail("Expected exception") -# test that exception attributes are happy. -try: str(u'Hello \u00E1') -except Exception, e: sampleUnicodeEncodeError = e -try: unicode('\xff') -except Exception, e: sampleUnicodeDecodeError = e -exceptionList = [ - ( BaseException, (), { 'message' : '', 'args' : () }), - ( BaseException, (1, ), { 'message' : 1, 'args' : ( 1, ) }), - ( BaseException, ('foo', ), { 'message' : 'foo', 'args' : ( 'foo', ) }), - ( BaseException, ('foo', 1), { 'message' : '', 'args' : ( 'foo', 1 ) }), - ( SystemExit, ('foo',), { 'message' : 'foo', 'args' : ( 'foo', ), - 'code' : 'foo' }), - ( IOError, ('foo',), { 'message' : 'foo', 'args' : ( 'foo', ), }), - ( IOError, ('foo', 'bar'), { 'message' : '', - 'args' : ('foo', 'bar'), }), - ( IOError, ('foo', 'bar', 'baz'), - { 'message' : '', 'args' : ('foo', 'bar'), }), - ( EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'), - { 'message' : '', 'args' : ('errnoStr', 'strErrorStr'), - 'strerror' : 'strErrorStr', - 'errno' : 'errnoStr', 'filename' : 'filenameStr' }), - ( EnvironmentError, (1, 'strErrorStr', 'filenameStr'), - { 'message' : '', 'args' : (1, 'strErrorStr'), - 'strerror' : 'strErrorStr', 'errno' : 1, - 'filename' : 'filenameStr' }), - ( SyntaxError, ('msgStr',), - { 'message' : 'msgStr', 'args' : ('msgStr', ), - 'print_file_and_line' : None, 'msg' : 'msgStr', - 'filename' : None, 'lineno' : None, 'offset' : None, - 'text' : None }), - ( SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr', - 'textStr')), - { 'message' : '', 'args' : ('msgStr', ('filenameStr', - 'linenoStr', 'offsetStr', 'textStr' )), - 'print_file_and_line' : None, 'msg' : 'msgStr', - 'filename' : 'filenameStr', 'lineno' : 'linenoStr', - 'offset' : 'offsetStr', 'text' : 'textStr' }), - ( SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', - 'textStr', 'print_file_and_lineStr'), - { 'message' : '', 'args' : ('msgStr', 'filenameStr', - 'linenoStr', 'offsetStr', 'textStr', - 'print_file_and_lineStr'), - 'print_file_and_line' : None, 'msg' : 'msgStr', - 'filename' : None, 'lineno' : None, 'offset' : None, - 'text' : None }), - ( UnicodeError, (), - { 'message' : '', 'args' : (), }), - ( sampleUnicodeEncodeError, - { 'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7, - 'ordinal not in range(128)'), - 'encoding' : 'ascii', 'object' : u'Hello \xe1', - 'start' : 6, 'reason' : 'ordinal not in range(128)' }), - ( sampleUnicodeDecodeError, - { 'message' : '', 'args' : ('ascii', '\xff', 0, 1, - 'ordinal not in range(128)'), - 'encoding' : 'ascii', 'object' : '\xff', - 'start' : 0, 'reason' : 'ordinal not in range(128)' }), - ( UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"), - { 'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'), - 'object' : u'\u3042', 'reason' : 'ouch', - 'start' : 0, 'end' : 1 }), + def test_capi3(): + import _testcapi + self.assertRaises(SystemError, _testcapi.raise_exception, + InvalidException, 1) + + if not sys.platform.startswith('java'): + test_capi1() + test_capi2() + test_capi3() + + def testAttributes(self): + # test that exception attributes are happy + try: str(u'Hello \u00E1') + except Exception, e: sampleUnicodeEncodeError = e + + try: unicode('\xff') + except Exception, e: sampleUnicodeDecodeError = e + + exceptionList = [ + (BaseException, (), {'message' : '', 'args' : ()}), + (BaseException, (1, ), {'message' : 1, 'args' : (1,)}), + (BaseException, ('foo',), + {'message' : 'foo', 'args' : ('foo',)}), + (BaseException, ('foo', 1), + {'message' : '', 'args' : ('foo', 1)}), + (SystemExit, ('foo',), + {'message' : 'foo', 'args' : ('foo',), 'code' : 'foo'}), + (IOError, ('foo',), + {'message' : 'foo', 'args' : ('foo',)}), + (IOError, ('foo', 'bar'), + {'message' : '', 'args' : ('foo', 'bar')}), + (IOError, ('foo', 'bar', 'baz'), + {'message' : '', 'args' : ('foo', 'bar')}), + (EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'), + {'message' : '', 'args' : ('errnoStr', 'strErrorStr'), + 'strerror' : 'strErrorStr', 'errno' : 'errnoStr', + 'filename' : 'filenameStr'}), + (EnvironmentError, (1, 'strErrorStr', 'filenameStr'), + {'message' : '', 'args' : (1, 'strErrorStr'), 'errno' : 1, + 'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}), + (SyntaxError, ('msgStr',), + {'message' : 'msgStr', 'args' : ('msgStr',), 'text' : None, + 'print_file_and_line' : None, 'msg' : 'msgStr', + 'filename' : None, 'lineno' : None, 'offset' : None}), + (SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr', + 'textStr')), + {'message' : '', 'offset' : 'offsetStr', 'text' : 'textStr', + 'args' : ('msgStr', ('filenameStr', 'linenoStr', + 'offsetStr', 'textStr')), + 'print_file_and_line' : None, 'msg' : 'msgStr', + 'filename' : 'filenameStr', 'lineno' : 'linenoStr'}), + (SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', + 'textStr', 'print_file_and_lineStr'), + {'message' : '', 'text' : None, + 'args' : ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', + 'textStr', 'print_file_and_lineStr'), + 'print_file_and_line' : None, 'msg' : 'msgStr', + 'filename' : None, 'lineno' : None, 'offset' : None}), + (UnicodeError, (), {'message' : '', 'args' : (),}), + (sampleUnicodeEncodeError, + {'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7, + 'ordinal not in range(128)'), + 'encoding' : 'ascii', 'object' : u'Hello \xe1', + 'start' : 6, 'reason' : 'ordinal not in range(128)'}), + (sampleUnicodeDecodeError, + {'message' : '', 'args' : ('ascii', '\xff', 0, 1, + 'ordinal not in range(128)'), + 'encoding' : 'ascii', 'object' : '\xff', + 'start' : 0, 'reason' : 'ordinal not in range(128)'}), + (UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"), + {'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'), + 'object' : u'\u3042', 'reason' : 'ouch', + 'start' : 0, 'end' : 1}), ] -try: - exceptionList.append( - ( WindowsError, (1, 'strErrorStr', 'filenameStr'), - { 'message' : '', 'args' : (1, 'strErrorStr'), - 'strerror' : 'strErrorStr', - 'errno' : 22, 'filename' : 'filenameStr', - 'winerror' : 1 })) -except NameError: pass + try: + exceptionList.append( + (WindowsError, (1, 'strErrorStr', 'filenameStr'), + {'message' : '', 'args' : (1, 'strErrorStr'), + 'strerror' : 'strErrorStr', 'winerror' : 1, + 'errno' : 22, 'filename' : 'filenameStr'}) + ) + except NameError: pass -for args in exceptionList: - expected = args[-1] - try: - if len(args) == 2: raise args[0] - else: raise apply(args[0], args[1]) - except BaseException, e: - for checkArgName in expected.keys(): - if repr(getattr(e, checkArgName)) != repr(expected[checkArgName]): - raise TestFailed('Checking exception arguments, exception ' - '"%s", attribute "%s" expected %s got %s.' % - ( repr(e), checkArgName, - repr(expected[checkArgName]), - repr(getattr(e, checkArgName)) )) + import pickle, random + + for args in exceptionList: + expected = args[-1] + try: + exc = args[0] + if len(args) == 2: raise exc + else: raise exc(*args[1]) + except BaseException, e: + if (e is not exc and # needed for sampleUnicode errors + type(e) is not exc): + raise + # Verify no ref leaks in Exc_str() + s = str(e) + for checkArgName in expected: + self.assertEquals(repr(getattr(e, checkArgName)), + repr(expected[checkArgName]), + 'exception "%s", attribute "%s"' % + (repr(e), checkArgName)) + + # test for pickling support + new = pickle.loads(pickle.dumps(e, random.randint(0, 2))) + for checkArgName in expected: + self.assertEquals(repr(getattr(e, checkArgName)), + repr(expected[checkArgName]), + 'pickled exception "%s", attribute "%s' % + (repr(e), checkArgName)) + + def testKeywordArgs(self): + # test that builtin exception don't take keyword args, + # but user-defined subclasses can if they want + self.assertRaises(TypeError, BaseException, a=1) + + class DerivedException(BaseException): + def __init__(self, fancy_arg): + BaseException.__init__(self) + self.fancy_arg = fancy_arg + + x = DerivedException(fancy_arg=42) + self.assertEquals(x.fancy_arg, 42) + +def test_main(): + run_unittest(ExceptionTests) + +if __name__ == '__main__': + test_main() diff --git a/Lib/test/test_functional.py b/Lib/test/test_functools.py similarity index 98% rename from Lib/test/test_functional.py rename to Lib/test/test_functools.py index 5078a2e94f1..609e8f463d6 100644 --- a/Lib/test/test_functional.py +++ b/Lib/test/test_functools.py @@ -1,4 +1,4 @@ -import functional +import functools import unittest from test import test_support from weakref import proxy @@ -21,7 +21,7 @@ def capture(*args, **kw): class TestPartial(unittest.TestCase): - thetype = functional.partial + thetype = functools.partial def test_basic_examples(self): p = self.thetype(capture, 1, 2, a=10, b=20) @@ -140,7 +140,7 @@ class TestPartial(unittest.TestCase): join = self.thetype(''.join) self.assertEqual(join(data), '0123456789') -class PartialSubclass(functional.partial): +class PartialSubclass(functools.partial): pass class TestPartialSubclass(TestPartial): diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index c4ed3bc7dbb..b2a9b55655a 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -766,7 +766,7 @@ Samuele >>> from operator import itemgetter >>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3) ->>> di = sorted(d.iteritems(), key=itemgetter(1)) +>>> di = sorted(sorted(d.iteritems()), key=itemgetter(1)) >>> for k, g in groupby(di, itemgetter(1)): ... print k, map(itemgetter(0), g) ... diff --git a/Lib/test/test_operations.py b/Lib/test/test_operations.py index b599c9da9e3..fafc0622119 100644 --- a/Lib/test/test_operations.py +++ b/Lib/test/test_operations.py @@ -5,27 +5,16 @@ print '3. Operations' print 'XXX Mostly not yet implemented' -print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception' - -# SourceForge bug #112558: -# http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470 +print '3.1 Dictionary lookups fail if __cmp__() raises an exception' class BadDictKey: - already_printed_raising_error = 0 def __hash__(self): return hash(self.__class__) def __cmp__(self, other): if isinstance(other, self.__class__): - if not BadDictKey.already_printed_raising_error: - # How many times __cmp__ gets called depends on the hash - # code and the internals of the dict implementation; we - # know it will be called at least once, but that's it. - # already_printed_raising_error makes sure the expected- - # output file prints the msg at most once. - BadDictKey.already_printed_raising_error = 1 - print "raising error" + print "raising error" raise RuntimeError, "gotcha" return other @@ -33,8 +22,21 @@ d = {} x1 = BadDictKey() x2 = BadDictKey() d[x1] = 1 -d[x2] = 2 -print "No exception passed through." +for stmt in ['d[x2] = 2', + 'z = d[x2]', + 'x2 in d', + 'd.has_key(x2)', + 'd.get(x2)', + 'd.setdefault(x2, 42)', + 'd.pop(x2)', + 'd.update({x2: 2})']: + try: + exec stmt + except RuntimeError: + print "%s: caught the RuntimeError outside" % (stmt,) + else: + print "%s: No exception passed through!" # old CPython behavior + # Dict resizing bug, found by Jack Jansen in 2.2 CVS development. # This version got an assert failure in debug build, infinite loop in @@ -50,3 +52,27 @@ for i in range(5): del d[i] for i in range(5, 9): # i==8 was the problem d[i] = i + + +# Another dict resizing bug (SF bug #1456209). +# This caused Segmentation faults or Illegal instructions. + +class X(object): + def __hash__(self): + return 5 + def __eq__(self, other): + if resizing: + d.clear() + return False +d = {} +resizing = False +d[X()] = 1 +d[X()] = 2 +d[X()] = 3 +d[X()] = 4 +d[X()] = 5 +# now trigger a resize +resizing = True +d[9] = 6 + +print 'resize bugs not triggered.' diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py index 991c06d4477..79df9066e2c 100644 --- a/Lib/test/test_optparse.py +++ b/Lib/test/test_optparse.py @@ -230,7 +230,7 @@ class TestOptionChecks(BaseTest): def test_attr_invalid(self): self.assertOptionError( - "option -b: invalid keyword arguments: foo, bar", + "option -b: invalid keyword arguments: bar, foo", ["-b"], {'foo': None, 'bar': None}) def test_action_invalid(self): @@ -718,9 +718,8 @@ class TestStandard(BaseTest): def test_ambiguous_option(self): self.parser.add_option("--foz", action="store", type="string", dest="foo") - possibilities = ", ".join({"--foz": None, "--foo": None}.keys()) self.assertParseFail(["--f=bar"], - "ambiguous option: --f (%s?)" % possibilities) + "ambiguous option: --f (--foo, --foz?)") def test_short_and_long_option_split(self): @@ -1537,10 +1536,9 @@ class TestMatchAbbrev(BaseTest): def test_match_abbrev_error(self): s = "--f" wordmap = {"--foz": None, "--foo": None, "--fie": None} - possibilities = ", ".join(wordmap.keys()) self.assertRaises( _match_abbrev, (s, wordmap), None, - BadOptionError, "ambiguous option: --f (%s?)" % possibilities) + BadOptionError, "ambiguous option: --f (--fie, --foo, --foz?)") class TestParseNumber(BaseTest): diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 27d6b520847..09ba268f714 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -11,16 +11,21 @@ except NameError: # list, tuple and dict subclasses that do or don't overwrite __repr__ class list2(list): pass + class list3(list): def __repr__(self): return list.__repr__(self) + class tuple2(tuple): pass + class tuple3(tuple): def __repr__(self): return tuple.__repr__(self) + class dict2(dict): pass + class dict3(dict): def __repr__(self): return dict.__repr__(self) @@ -101,7 +106,13 @@ class QueryTestCase(unittest.TestCase): def test_same_as_repr(self): # Simple objects, small containers and classes that overwrite __repr__ - # For those the result should be the same as repr() + # For those the result should be the same as repr(). + # Ahem. The docs don't say anything about that -- this appears to + # be testing an implementation quirk. Starting in Python 2.5, it's + # not true for dicts: pprint always sorts dicts by key now; before, + # it sorted a dict display if and only if the display required + # multiple lines. For that reason, dicts with more than one element + # aren't tested here. verify = self.assert_ for simple in (0, 0L, 0+0j, 0.0, "", uni(""), (), tuple2(), tuple3(), @@ -112,9 +123,7 @@ class QueryTestCase(unittest.TestCase): (1,2), [3,4], {5: 6, 7: 8}, tuple2((1,2)), tuple3((1,2)), tuple3(range(100)), [3,4], list2([3,4]), list3([3,4]), list3(range(100)), - {5: 6, 7: 8}, dict2({5: 6, 7: 8}), dict3({5: 6, 7: 8}), - dict3([(x,x) for x in range(100)]), - {"xy\tab\n": (3,), 5: [[]], (): {}}, + {5: 6, 7: 8}, dict2({5: 6}), dict3({5: 6}), range(10, -11, -1) ): native = repr(simple) @@ -160,6 +169,24 @@ class QueryTestCase(unittest.TestCase): for type in [list, list2]: self.assertEqual(pprint.pformat(type(o), indent=4), exp) + def test_sorted_dict(self): + # Starting in Python 2.5, pprint sorts dict displays by key regardless + # of how small the dictionary may be. + # Before the change, on 32-bit Windows pformat() gave order + # 'a', 'c', 'b' here, so this test failed. + d = {'a': 1, 'b': 1, 'c': 1} + self.assertEqual(pprint.pformat(d), "{'a': 1, 'b': 1, 'c': 1}") + self.assertEqual(pprint.pformat([d, d]), + "[{'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 1}]") + + # The next one is kind of goofy. The sorted order depends on the + # alphabetic order of type names: "int" < "str" < "tuple". Before + # Python 2.5, this was in the test_same_as_repr() test. It's worth + # keeping around for now because it's one of few tests of pprint + # against a crazy mix of types. + self.assertEqual(pprint.pformat({"xy\tab\n": (3,), 5: [[]], (): {}}), + r"{5: [[]], 'xy\tab\n': (3,), (): {}}") + def test_subclassing(self): o = {'names with spaces': 'should be presented using repr()', 'others.should.not.be': 'like.this'} diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index 912858539c8..1dfa2821104 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -5,6 +5,7 @@ import sys import os +import shutil import unittest from test.test_support import run_unittest @@ -198,8 +199,10 @@ class LongReprTest(unittest.TestCase): self.pkgname = os.path.join(longname) self.subpkgname = os.path.join(longname, longname) # Make the package and subpackage + shutil.rmtree(self.pkgname, ignore_errors=True) os.mkdir(self.pkgname) touch(os.path.join(self.pkgname, '__init__'+os.extsep+'py')) + shutil.rmtree(self.subpkgname, ignore_errors=True) os.mkdir(self.subpkgname) touch(os.path.join(self.subpkgname, '__init__'+os.extsep+'py')) # Remember where we are diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 7981a5245a7..af835f7a6fb 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -2,7 +2,7 @@ from test.test_support import TestFailed, verbose, verify import test.test_support import struct import array -import unittest +import warnings import sys ISBIGENDIAN = sys.byteorder == "big" @@ -10,7 +10,14 @@ del sys verify((struct.pack('=i', 1)[0] == chr(0)) == ISBIGENDIAN, "bigendian determination appears wrong") -PY_STRUCT_RANGE_CHECKING = 1 +try: + import _struct +except ImportError: + PY_STRUCT_RANGE_CHECKING = 0 + PY_STRUCT_OVERFLOW_MASKING = 1 +else: + PY_STRUCT_RANGE_CHECKING = getattr(_struct, '_PY_STRUCT_RANGE_CHECKING', 0) + PY_STRUCT_OVERFLOW_MASKING = getattr(_struct, '_PY_STRUCT_OVERFLOW_MASKING', 0) def string_reverse(s): chars = list(s) @@ -35,12 +42,39 @@ def simple_err(func, *args): def any_err(func, *args): try: func(*args) - except (struct.error, OverflowError, TypeError): + except (struct.error, TypeError): pass else: raise TestFailed, "%s%s did not raise error" % ( func.__name__, args) +def deprecated_err(func, *args): + # The `warnings` module doesn't have an advertised way to restore + # its filter list. Cheat. + save_warnings_filters = warnings.filters[:] + # Grrr, we need this function to warn every time. Without removing + # the warningregistry, running test_tarfile then test_struct would fail + # on 64-bit platforms. + globals = func.func_globals + if '__warningregistry__' in globals: + del globals['__warningregistry__'] + warnings.filterwarnings("error", r"""^struct.*""", DeprecationWarning) + warnings.filterwarnings("error", r""".*format requires.*""", + DeprecationWarning) + try: + try: + func(*args) + except (struct.error, TypeError): + pass + except DeprecationWarning: + if not PY_STRUCT_OVERFLOW_MASKING: + raise TestFailed, "%s%s expected to raise struct.error" % ( + func.__name__, args) + else: + raise TestFailed, "%s%s did not raise error" % ( + func.__name__, args) + finally: + warnings.filters[:] = save_warnings_filters[:] simple_err(struct.calcsize, 'Z') @@ -272,8 +306,8 @@ class IntTester: if verbose: print "Skipping buggy range check for code", code else: - any_err(pack, ">" + code, x) - any_err(pack, "<" + code, x) + deprecated_err(pack, ">" + code, x) + deprecated_err(pack, "<" + code, x) # Much the same for unsigned. code = self.unsigned_code @@ -327,8 +361,8 @@ class IntTester: if verbose: print "Skipping buggy range check for code", code else: - any_err(pack, ">" + code, x) - any_err(pack, "<" + code, x) + deprecated_err(pack, ">" + code, x) + deprecated_err(pack, "<" + code, x) def run(self): from random import randrange @@ -448,91 +482,98 @@ def test_1229380(): for endian in ('', '>', '<'): for cls in (int, long): for fmt in ('B', 'H', 'I', 'L'): - any_err(struct.pack, endian + fmt, cls(-1)) + deprecated_err(struct.pack, endian + fmt, cls(-1)) - any_err(struct.pack, endian + 'B', cls(300)) - any_err(struct.pack, endian + 'H', cls(70000)) + deprecated_err(struct.pack, endian + 'B', cls(300)) + deprecated_err(struct.pack, endian + 'H', cls(70000)) - any_err(struct.pack, endian + 'I', sys.maxint * 4L) - any_err(struct.pack, endian + 'L', sys.maxint * 4L) + deprecated_err(struct.pack, endian + 'I', sys.maxint * 4L) + deprecated_err(struct.pack, endian + 'L', sys.maxint * 4L) if PY_STRUCT_RANGE_CHECKING: test_1229380() -class PackBufferTestCase(unittest.TestCase): - """ - Test the packing methods that work on buffers. - """ - def test_unpack_from( self ): - test_string = 'abcd01234' - fmt = '4s' - s = struct.Struct(fmt) - for cls in (str, buffer): - data = cls(test_string) - self.assertEquals(s.unpack_from(data), ('abcd',)) - self.assertEquals(s.unpack_from(data, 2), ('cd01',)) - self.assertEquals(s.unpack_from(data, 4), ('0123',)) - for i in xrange(6): - self.assertEquals(s.unpack_from(data, i), (data[i:i+4],)) - for i in xrange(6, len(test_string) + 1): - simple_err(s.unpack_from, data, i) - for cls in (str, buffer): - data = cls(test_string) - self.assertEquals(struct.unpack_from(fmt, data), ('abcd',)) - self.assertEquals(struct.unpack_from(fmt, data, 2), ('cd01',)) - self.assertEquals(struct.unpack_from(fmt, data, 4), ('0123',)) - for i in xrange(6): - self.assertEquals(struct.unpack_from(fmt, data, i), - (data[i:i+4],)) - for i in xrange(6, len(test_string) + 1): - simple_err(struct.unpack_from, fmt, data, i) +########################################################################### +# Packing and unpacking to/from buffers. - def test_pack_to( self ): - test_string = 'Reykjavik rocks, eow!' - writable_buf = array.array('c', ' '*100) - fmt = '21s' - s = struct.Struct(fmt) +# Copied and modified from unittest. +def assertRaises(excClass, callableObj, *args, **kwargs): + try: + callableObj(*args, **kwargs) + except excClass: + return + else: + raise RuntimeError("%s not raised." % excClass) - # Test without offset - s.pack_to(writable_buf, 0, test_string) - from_buf = writable_buf.tostring()[:len(test_string)] - self.assertEquals(from_buf, test_string) +def test_unpack_from(): + test_string = 'abcd01234' + fmt = '4s' + s = struct.Struct(fmt) + for cls in (str, buffer): + data = cls(test_string) + assert s.unpack_from(data) == ('abcd',) + assert s.unpack_from(data, 2) == ('cd01',) + assert s.unpack_from(data, 4) == ('0123',) + for i in xrange(6): + assert s.unpack_from(data, i) == (data[i:i+4],) + for i in xrange(6, len(test_string) + 1): + simple_err(s.unpack_from, data, i) + for cls in (str, buffer): + data = cls(test_string) + assert struct.unpack_from(fmt, data) == ('abcd',) + assert struct.unpack_from(fmt, data, 2) == ('cd01',) + assert struct.unpack_from(fmt, data, 4) == ('0123',) + for i in xrange(6): + assert (struct.unpack_from(fmt, data, i) == (data[i:i+4],)) + for i in xrange(6, len(test_string) + 1): + simple_err(struct.unpack_from, fmt, data, i) - # Test with offset. - s.pack_to(writable_buf, 10, test_string) - from_buf = writable_buf.tostring()[:len(test_string)+10] - self.assertEquals(from_buf, (test_string[:10] + test_string)) +def test_pack_to(): + test_string = 'Reykjavik rocks, eow!' + writable_buf = array.array('c', ' '*100) + fmt = '21s' + s = struct.Struct(fmt) - # Go beyond boundaries. - small_buf = array.array('c', ' '*10) - self.assertRaises(struct.error, s.pack_to, small_buf, 0, test_string) - self.assertRaises(struct.error, s.pack_to, small_buf, 2, test_string) + # Test without offset + s.pack_to(writable_buf, 0, test_string) + from_buf = writable_buf.tostring()[:len(test_string)] + assert from_buf == test_string - def test_pack_to_fn( self ): - test_string = 'Reykjavik rocks, eow!' - writable_buf = array.array('c', ' '*100) - fmt = '21s' - pack_to = lambda *args: struct.pack_to(fmt, *args) + # Test with offset. + s.pack_to(writable_buf, 10, test_string) + from_buf = writable_buf.tostring()[:len(test_string)+10] + assert from_buf == (test_string[:10] + test_string) - # Test without offset - pack_to(writable_buf, 0, test_string) - from_buf = writable_buf.tostring()[:len(test_string)] - self.assertEquals(from_buf, test_string) + # Go beyond boundaries. + small_buf = array.array('c', ' '*10) + assertRaises(struct.error, s.pack_to, small_buf, 0, test_string) + assertRaises(struct.error, s.pack_to, small_buf, 2, test_string) - # Test with offset. - pack_to(writable_buf, 10, test_string) - from_buf = writable_buf.tostring()[:len(test_string)+10] - self.assertEquals(from_buf, (test_string[:10] + test_string)) +def test_pack_to_fn(): + test_string = 'Reykjavik rocks, eow!' + writable_buf = array.array('c', ' '*100) + fmt = '21s' + pack_to = lambda *args: struct.pack_to(fmt, *args) - # Go beyond boundaries. - small_buf = array.array('c', ' '*10) - self.assertRaises(struct.error, pack_to, small_buf, 0, test_string) - self.assertRaises(struct.error, pack_to, small_buf, 2, test_string) + # Test without offset + pack_to(writable_buf, 0, test_string) + from_buf = writable_buf.tostring()[:len(test_string)] + assert from_buf == test_string + # Test with offset. + pack_to(writable_buf, 10, test_string) + from_buf = writable_buf.tostring()[:len(test_string)+10] + assert from_buf == (test_string[:10] + test_string) -def test_main(): - test.test_support.run_unittest(PackBufferTestCase) + # Go beyond boundaries. + small_buf = array.array('c', ' '*10) + assertRaises(struct.error, pack_to, small_buf, 0, test_string) + assertRaises(struct.error, pack_to, small_buf, 2, test_string) + + +# Test methods to pack and unpack from buffers rather than strings. +test_unpack_from() +test_pack_to() +test_pack_to_fn() -if __name__ == "__main__": - test_main() diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index c8f19bcab02..034b9d0316d 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -76,10 +76,11 @@ def test_password_manager(self): >>> mgr.find_user_password("c", "http://example.com/bar") ('bar', 'nini') - Currently, we use the highest-level path where more than one match: + Actually, this is really undefined ATM +## Currently, we use the highest-level path where more than one match: - >>> mgr.find_user_password("Some Realm", "http://example.com/ni") - ('joe', 'password') +## >>> mgr.find_user_password("Some Realm", "http://example.com/ni") +## ('joe', 'password') Use latest add_password() in case of conflict: @@ -110,6 +111,53 @@ def test_password_manager(self): pass +def test_password_manager_default_port(self): + """ + >>> mgr = urllib2.HTTPPasswordMgr() + >>> add = mgr.add_password + + The point to note here is that we can't guess the default port if there's + no scheme. This applies to both add_password and find_user_password. + + >>> add("f", "http://g.example.com:80", "10", "j") + >>> add("g", "http://h.example.com", "11", "k") + >>> add("h", "i.example.com:80", "12", "l") + >>> add("i", "j.example.com", "13", "m") + >>> mgr.find_user_password("f", "g.example.com:100") + (None, None) + >>> mgr.find_user_password("f", "g.example.com:80") + ('10', 'j') + >>> mgr.find_user_password("f", "g.example.com") + (None, None) + >>> mgr.find_user_password("f", "http://g.example.com:100") + (None, None) + >>> mgr.find_user_password("f", "http://g.example.com:80") + ('10', 'j') + >>> mgr.find_user_password("f", "http://g.example.com") + ('10', 'j') + >>> mgr.find_user_password("g", "h.example.com") + ('11', 'k') + >>> mgr.find_user_password("g", "h.example.com:80") + ('11', 'k') + >>> mgr.find_user_password("g", "http://h.example.com:80") + ('11', 'k') + >>> mgr.find_user_password("h", "i.example.com") + (None, None) + >>> mgr.find_user_password("h", "i.example.com:80") + ('12', 'l') + >>> mgr.find_user_password("h", "http://i.example.com:80") + ('12', 'l') + >>> mgr.find_user_password("i", "j.example.com") + ('13', 'm') + >>> mgr.find_user_password("i", "j.example.com:80") + (None, None) + >>> mgr.find_user_password("i", "http://j.example.com") + ('13', 'm') + >>> mgr.find_user_password("i", "http://j.example.com:80") + (None, None) + + """ + class MockOpener: addheaders = [] def open(self, req, data=None): @@ -270,6 +318,27 @@ class MockPasswordManager: class OpenerDirectorTests(unittest.TestCase): + def test_badly_named_methods(self): + # test work-around for three methods that accidentally follow the + # naming conventions for handler methods + # (*_open() / *_request() / *_response()) + + # These used to call the accidentally-named methods, causing a + # TypeError in real code; here, returning self from these mock + # methods would either cause no exception, or AttributeError. + + from urllib2 import URLError + + o = OpenerDirector() + meth_spec = [ + [("do_open", "return self"), ("proxy_open", "return self")], + [("redirect_request", "return self")], + ] + handlers = add_ordered_mock_handlers(o, meth_spec) + o.add_handler(urllib2.UnknownHandler()) + for scheme in "do", "proxy", "redirect": + self.assertRaises(URLError, o.open, scheme+"://example.com/") + def test_handled(self): # handler returning non-None means no more handlers will be called o = OpenerDirector() @@ -560,6 +629,7 @@ class HandlerTests(unittest.TestCase): self.method = method self.selector = url self.req_headers += headers.items() + self.req_headers.sort() if body: self.data = body if self.raise_on_endheaders: @@ -758,6 +828,8 @@ class HandlerTests(unittest.TestCase): realm = "ACME Widget Store" http_handler = MockHTTPHandler( 401, 'WWW-Authenticate: Basic realm="%s"\r\n\r\n' % realm) + opener.add_handler(auth_handler) + opener.add_handler(http_handler) self._test_basic_auth(opener, auth_handler, "Authorization", realm, http_handler, password_manager, "http://acme.example.com/protected", @@ -773,6 +845,8 @@ class HandlerTests(unittest.TestCase): realm = "ACME Networks" http_handler = MockHTTPHandler( 407, 'Proxy-Authenticate: Basic realm="%s"\r\n\r\n' % realm) + opener.add_handler(auth_handler) + opener.add_handler(http_handler) self._test_basic_auth(opener, auth_handler, "Proxy-authorization", realm, http_handler, password_manager, "http://acme.example.com:3128/protected", @@ -784,29 +858,53 @@ class HandlerTests(unittest.TestCase): # response (http://python.org/sf/1479302), where it should instead # return None to allow another handler (especially # HTTPBasicAuthHandler) to handle the response. + + # Also (http://python.org/sf/14797027, RFC 2617 section 1.2), we must + # try digest first (since it's the strongest auth scheme), so we record + # order of calls here to check digest comes first: + class RecordingOpenerDirector(OpenerDirector): + def __init__(self): + OpenerDirector.__init__(self) + self.recorded = [] + def record(self, info): + self.recorded.append(info) class TestDigestAuthHandler(urllib2.HTTPDigestAuthHandler): - handler_order = 400 # strictly before HTTPBasicAuthHandler - opener = OpenerDirector() + def http_error_401(self, *args, **kwds): + self.parent.record("digest") + urllib2.HTTPDigestAuthHandler.http_error_401(self, + *args, **kwds) + class TestBasicAuthHandler(urllib2.HTTPBasicAuthHandler): + def http_error_401(self, *args, **kwds): + self.parent.record("basic") + urllib2.HTTPBasicAuthHandler.http_error_401(self, + *args, **kwds) + + opener = RecordingOpenerDirector() password_manager = MockPasswordManager() digest_handler = TestDigestAuthHandler(password_manager) - basic_handler = urllib2.HTTPBasicAuthHandler(password_manager) - opener.add_handler(digest_handler) + basic_handler = TestBasicAuthHandler(password_manager) realm = "ACME Networks" http_handler = MockHTTPHandler( 401, 'WWW-Authenticate: Basic realm="%s"\r\n\r\n' % realm) + opener.add_handler(basic_handler) + opener.add_handler(digest_handler) + opener.add_handler(http_handler) + + # check basic auth isn't blocked by digest handler failing self._test_basic_auth(opener, basic_handler, "Authorization", realm, http_handler, password_manager, "http://acme.example.com/protected", "http://acme.example.com/protected", ) + # check digest was tried before basic (twice, because + # _test_basic_auth called .open() twice) + self.assertEqual(opener.recorded, ["digest", "basic"]*2) def _test_basic_auth(self, opener, auth_handler, auth_header, realm, http_handler, password_manager, request_url, protected_url): import base64, httplib user, password = "wile", "coyote" - opener.add_handler(auth_handler) - opener.add_handler(http_handler) # .add_password() fed through to password manager auth_handler.add_password(realm, request_url, user, password) diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 392e5fa34b9..18ab4012fb7 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -1053,8 +1053,8 @@ libreftest = """ Doctest for examples in the library reference: libweakref.tex ... >>> obj = Dict(red=1, green=2, blue=3) # this object is weak referencable >>> r = weakref.ref(obj) ->>> print r() -{'blue': 3, 'green': 2, 'red': 1} +>>> print r() is obj +True >>> import weakref >>> class Object: diff --git a/Lib/urllib2.py b/Lib/urllib2.py index cdb3a22b379..227311c3126 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -297,6 +297,10 @@ class OpenerDirector: def add_handler(self, handler): added = False for meth in dir(handler): + if meth in ["redirect_request", "do_open", "proxy_open"]: + # oops, coincidental match + continue + i = meth.find("_") protocol = meth[:i] condition = meth[i+1:] @@ -695,32 +699,45 @@ class HTTPPasswordMgr: # uri could be a single URI or a sequence if isinstance(uri, basestring): uri = [uri] - uri = tuple(map(self.reduce_uri, uri)) if not realm in self.passwd: self.passwd[realm] = {} - self.passwd[realm][uri] = (user, passwd) + for default_port in True, False: + reduced_uri = tuple( + [self.reduce_uri(u, default_port) for u in uri]) + self.passwd[realm][reduced_uri] = (user, passwd) def find_user_password(self, realm, authuri): domains = self.passwd.get(realm, {}) - authuri = self.reduce_uri(authuri) - for uris, authinfo in domains.iteritems(): - for uri in uris: - if self.is_suburi(uri, authuri): - return authinfo + for default_port in True, False: + reduced_authuri = self.reduce_uri(authuri, default_port) + for uris, authinfo in domains.iteritems(): + for uri in uris: + if self.is_suburi(uri, reduced_authuri): + return authinfo return None, None - def reduce_uri(self, uri): - """Accept netloc or URI and extract only the netloc and path""" + def reduce_uri(self, uri, default_port=True): + """Accept authority or URI and extract only the authority and path.""" + # note HTTP URLs do not have a userinfo component parts = urlparse.urlsplit(uri) if parts[1]: # URI - return parts[1], parts[2] or '/' - elif parts[0]: - # host:port - return uri, '/' + scheme = parts[0] + authority = parts[1] + path = parts[2] or '/' else: - # host - return parts[2], '/' + # host or host:port + scheme = None + authority = uri + path = '/' + host, port = splitport(authority) + if default_port and port is None and scheme is not None: + dport = {"http": 80, + "https": 443, + }.get(scheme) + if dport is not None: + authority = "%s:%d" % (host, dport) + return authority, path def is_suburi(self, base, test): """Check if test is below base in a URI tree @@ -755,6 +772,10 @@ class AbstractBasicAuthHandler: # www-authenticate header. should probably be a lot more careful # in parsing them to extract multiple alternatives + # XXX could pre-emptively send auth info already accepted (RFC 2617, + # end of section 2, and section 1.2 immediately after "credentials" + # production). + def __init__(self, password_mgr=None): if password_mgr is None: password_mgr = HTTPPasswordMgr() @@ -964,6 +985,7 @@ class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): """ auth_header = 'Authorization' + handler_order = 490 # before Basic auth def http_error_401(self, req, fp, code, msg, headers): host = urlparse.urlparse(req.get_full_url())[1] @@ -976,6 +998,7 @@ class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): auth_header = 'Proxy-Authorization' + handler_order = 490 # before Basic auth def http_error_407(self, req, fp, code, msg, headers): host = req.get_host() diff --git a/Mac/Modules/dlg/_Dlgmodule.c b/Mac/Modules/dlg/_Dlgmodule.c index 64ddac8d339..46009a8c67a 100644 --- a/Mac/Modules/dlg/_Dlgmodule.c +++ b/Mac/Modules/dlg/_Dlgmodule.c @@ -139,7 +139,7 @@ typedef struct DialogObject { PyObject *DlgObj_New(DialogPtr itself) { DialogObject *it; - if (itself == NULL) return Py_None; + if (itself == NULL) { Py_INCREF(Py_None); return Py_None; } it = PyObject_NEW(DialogObject, &Dialog_Type); if (it == NULL) return NULL; it->ob_itself = itself; diff --git a/Mac/Modules/dlg/dlgsupport.py b/Mac/Modules/dlg/dlgsupport.py index 1c0cc6a9f94..fa1442ec37b 100644 --- a/Mac/Modules/dlg/dlgsupport.py +++ b/Mac/Modules/dlg/dlgsupport.py @@ -202,7 +202,7 @@ class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition): Output("SetWRefCon(GetDialogWindow(itself), (long)it);") def outputCheckNewArg(self): - Output("if (itself == NULL) return Py_None;") + Output("if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }") def outputCheckConvertArg(self): Output("if (v == Py_None) { *p_itself = NULL; return 1; }") diff --git a/Mac/Modules/file/_Filemodule.c b/Mac/Modules/file/_Filemodule.c index c211de136fa..07bd3412976 100644 --- a/Mac/Modules/file/_Filemodule.c +++ b/Mac/Modules/file/_Filemodule.c @@ -153,7 +153,7 @@ typedef struct FSCatalogInfoObject { static PyObject *FSCatalogInfo_New(FSCatalogInfo *itself) { FSCatalogInfoObject *it; - if (itself == NULL) return Py_None; + if (itself == NULL) { Py_INCREF(Py_None); return Py_None; } it = PyObject_NEW(FSCatalogInfoObject, &FSCatalogInfo_Type); if (it == NULL) return NULL; it->ob_itself = *itself; diff --git a/Mac/Modules/file/filesupport.py b/Mac/Modules/file/filesupport.py index f2d419328b2..37aeb508a09 100644 --- a/Mac/Modules/file/filesupport.py +++ b/Mac/Modules/file/filesupport.py @@ -475,7 +475,7 @@ class FSCatalogInfoDefinition(PEP253Mixin, ObjectDefinition): self.argref = "*" # Store FSSpecs, but pass them by address def outputCheckNewArg(self): - Output("if (itself == NULL) return Py_None;") + Output("if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }") def output_tp_newBody(self): Output("PyObject *self;"); diff --git a/Mac/Modules/gestaltmodule.c b/Mac/Modules/gestaltmodule.c index 6d8673f8f7e..ddfa94a181d 100644 --- a/Mac/Modules/gestaltmodule.c +++ b/Mac/Modules/gestaltmodule.c @@ -35,7 +35,7 @@ gestalt_gestalt(PyObject *self, PyObject *args) OSErr iErr; OSType selector; long response; - if (!PyArg_Parse(args, "O&", PyMac_GetOSType, &selector)) + if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &selector)) return NULL; iErr = Gestalt ( selector, &response ); if (iErr != 0) @@ -44,7 +44,7 @@ gestalt_gestalt(PyObject *self, PyObject *args) } static struct PyMethodDef gestalt_methods[] = { - {"gestalt", gestalt_gestalt}, + {"gestalt", gestalt_gestalt, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; diff --git a/Misc/NEWS b/Misc/NEWS index 7a143635d21..0c97898f667 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -6,6 +6,7 @@ Python News What's New in Python 3000? ========================== + Build ----- diff --git a/Misc/developers.txt b/Misc/developers.txt index c2c2275ea49..c0859081564 100644 --- a/Misc/developers.txt +++ b/Misc/developers.txt @@ -17,13 +17,19 @@ the format to accommodate documentation needs as they arise. Permissions History ------------------- -- 2006 Summer of Code entries: Matt Fleming was added on 25 May 2006 - by AMK; he'll be working on enhancing the Python debugger. Jackilyn - Hoxworth was added on 25 May 2005 by AMK; she'll be adding logging - to the standard library. SoC developers are expected to work +- 2006 Summer of Code entries: SoC developers are expected to work primarily in nondist/sandbox or on a branch of their own, and will have their work reviewed before changes are accepted into the trunk. + - Matt Fleming was added on 25 May 2006 by AMK; he'll be working on + enhancing the Python debugger. + + - Jackilyn Hoxworth was added on 25 May 2006 by AMK; she'll be adding logging + to the standard library. + + - Mateusz Rukowicz was added on 30 May 2006 by AMK; he'll be + translating the decimal module into C. + - SVN access granted to the "Need for Speed" Iceland sprint attendees, between May 17 and 21, 2006, by Tim Peters. All work is to be done in new sandbox projects or on new branches, with merging to the diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index 1641e20b909..e18e0720527 100644 --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -1041,7 +1041,7 @@ DB_append(DBObject* self, PyObject* args) DBT key, data; DB_TXN *txn = NULL; - if (!PyArg_ParseTuple(args, "O|O:append", &dataobj, &txnobj)) + if (!PyArg_UnpackTuple(args, "append", 1, 2, &dataobj, &txnobj)) return NULL; CHECK_DB_NOT_CLOSED(self); @@ -2895,7 +2895,7 @@ DB_keys(DBObject* self, PyObject* args) PyObject* txnobj = NULL; DB_TXN *txn = NULL; - if (!PyArg_ParseTuple(args,"|O:keys", &txnobj)) + if (!PyArg_UnpackTuple(args, "keys", 0, 1, &txnobj)) return NULL; if (!checkTxnObj(txnobj, &txn)) return NULL; @@ -2909,7 +2909,7 @@ DB_items(DBObject* self, PyObject* args) PyObject* txnobj = NULL; DB_TXN *txn = NULL; - if (!PyArg_ParseTuple(args,"|O:items", &txnobj)) + if (!PyArg_UnpackTuple(args, "items", 0, 1, &txnobj)) return NULL; if (!checkTxnObj(txnobj, &txn)) return NULL; @@ -2923,7 +2923,7 @@ DB_values(DBObject* self, PyObject* args) PyObject* txnobj = NULL; DB_TXN *txn = NULL; - if (!PyArg_ParseTuple(args,"|O:values", &txnobj)) + if (!PyArg_UnpackTuple(args, "values", 0, 1, &txnobj)) return NULL; if (!checkTxnObj(txnobj, &txn)) return NULL; diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index d8d23c4050f..080fa74c106 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -48,21 +48,12 @@ one argument, the encoding name in all lower case letters, and return\n\ a tuple of functions (encoder, decoder, stream_reader, stream_writer)."); static -PyObject *codec_register(PyObject *self, PyObject *args) +PyObject *codec_register(PyObject *self, PyObject *search_function) { - PyObject *search_function; - - if (!PyArg_ParseTuple(args, "O:register", &search_function)) - goto onError; - if (PyCodec_Register(search_function)) - goto onError; + return NULL; - Py_INCREF(Py_None); - return Py_None; - - onError: - return NULL; + Py_RETURN_NONE; } PyDoc_STRVAR(lookup__doc__, @@ -77,12 +68,9 @@ PyObject *codec_lookup(PyObject *self, PyObject *args) char *encoding; if (!PyArg_ParseTuple(args, "s:lookup", &encoding)) - goto onError; + return NULL; return _PyCodec_Lookup(encoding); - - onError: - return NULL; } PyDoc_STRVAR(encode__doc__, @@ -116,13 +104,7 @@ codec_encode(PyObject *self, PyObject *args) #endif /* Encode via the codec registry */ - v = PyCodec_Encode(v, encoding, errors); - if (v == NULL) - goto onError; - return v; - - onError: - return NULL; + return PyCodec_Encode(v, encoding, errors); } PyDoc_STRVAR(decode__doc__, @@ -156,13 +138,7 @@ codec_decode(PyObject *self, PyObject *args) #endif /* Decode via the codec registry */ - v = PyCodec_Decode(v, encoding, errors); - if (v == NULL) - goto onError; - return v; - - onError: - return NULL; + return PyCodec_Decode(v, encoding, errors); } /* --- Helpers ------------------------------------------------------------ */ @@ -171,22 +147,11 @@ static PyObject *codec_tuple(PyObject *unicode, Py_ssize_t len) { - PyObject *v,*w; - + PyObject *v; if (unicode == NULL) - return NULL; - v = PyTuple_New(2); - if (v == NULL) { - Py_DECREF(unicode); - return NULL; - } - PyTuple_SET_ITEM(v,0,unicode); - w = PyInt_FromSsize_t(len); - if (w == NULL) { - Py_DECREF(v); - return NULL; - } - PyTuple_SET_ITEM(v,1,w); + return NULL; + v = Py_BuildValue("On", unicode, len); + Py_DECREF(unicode); return v; } @@ -419,7 +384,7 @@ utf_16_ex_decode(PyObject *self, final ? NULL : &consumed); if (unicode == NULL) return NULL; - tuple = Py_BuildValue("Oii", unicode, consumed, byteorder); + tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); Py_DECREF(unicode); return tuple; } @@ -604,8 +569,8 @@ utf_7_encode(PyObject *self, return NULL; v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str), PyUnicode_GET_SIZE(str), - 0, - 0, + 0, + 0, errors), PyUnicode_GET_SIZE(str)); Py_DECREF(str); @@ -876,8 +841,7 @@ static PyObject *register_error(PyObject *self, PyObject *args) return NULL; if (PyCodec_RegisterError(name, handler)) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(lookup_error__doc__, @@ -899,7 +863,7 @@ static PyObject *lookup_error(PyObject *self, PyObject *args) /* --- Module API --------------------------------------------------------- */ static PyMethodDef _codecs_functions[] = { - {"register", codec_register, METH_VARARGS, + {"register", codec_register, METH_O, register__doc__}, {"lookup", codec_lookup, METH_VARARGS, lookup__doc__}, diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index eaa3cedeab6..a0744ff716a 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2185,7 +2185,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value, only it's object list. So we create a tuple, containing b_objects list PLUS the array itself, and return that! */ - return PyTuple_Pack(2, keep, value); + return Py_BuildValue("(OO)", keep, value); } PyErr_Format(PyExc_TypeError, "incompatible types, %s instance instead of %s instance", diff --git a/Modules/functionalmodule.c b/Modules/_functoolsmodule.c similarity index 95% rename from Modules/functionalmodule.c rename to Modules/_functoolsmodule.c index 38ef43a7193..54abb89d81d 100644 --- a/Modules/functionalmodule.c +++ b/Modules/_functoolsmodule.c @@ -2,10 +2,10 @@ #include "Python.h" #include "structmember.h" -/* Functional module written and maintained +/* _functools module written and maintained by Hye-Shik Chang with adaptations by Raymond Hettinger - Copyright (c) 2004, 2005 Python Software Foundation. + Copyright (c) 2004, 2005, 2006 Python Software Foundation. All rights reserved. */ @@ -199,7 +199,7 @@ static PyGetSetDef partial_getsetlist[] = { static PyTypeObject partial_type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ - "functional.partial", /* tp_name */ + "functools.partial", /* tp_name */ sizeof(partialobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -245,14 +245,14 @@ static PyTypeObject partial_type = { /* module level code ********************************************************/ PyDoc_STRVAR(module_doc, -"Tools for functional programming."); +"Tools that operate on functions."); static PyMethodDef module_methods[] = { {NULL, NULL} /* sentinel */ }; PyMODINIT_FUNC -initfunctional(void) +init_functools(void) { int i; PyObject *m; @@ -262,7 +262,7 @@ initfunctional(void) NULL }; - m = Py_InitModule3("functional", module_methods, module_doc); + m = Py_InitModule3("_functools", module_methods, module_doc); if (m == NULL) return; diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index a7d627b2c9a..859644fc70d 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -77,13 +77,10 @@ EVP_dealloc(PyObject *ptr) PyDoc_STRVAR(EVP_copy__doc__, "Return a copy of the hash object."); static PyObject * -EVP_copy(EVPobject *self, PyObject *args) +EVP_copy(EVPobject *self, PyObject *unused) { EVPobject *newobj; - if (!PyArg_ParseTuple(args, ":copy")) - return NULL; - if ( (newobj = newEVPobject(self->name))==NULL) return NULL; @@ -95,16 +92,13 @@ PyDoc_STRVAR(EVP_digest__doc__, "Return the digest value as a string of binary data."); static PyObject * -EVP_digest(EVPobject *self, PyObject *args) +EVP_digest(EVPobject *self, PyObject *unused) { unsigned char digest[EVP_MAX_MD_SIZE]; EVP_MD_CTX temp_ctx; PyObject *retval; unsigned int digest_size; - if (!PyArg_ParseTuple(args, ":digest")) - return NULL; - EVP_MD_CTX_copy(&temp_ctx, &self->ctx); digest_size = EVP_MD_CTX_size(&temp_ctx); EVP_DigestFinal(&temp_ctx, digest, NULL); @@ -118,7 +112,7 @@ PyDoc_STRVAR(EVP_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); static PyObject * -EVP_hexdigest(EVPobject *self, PyObject *args) +EVP_hexdigest(EVPobject *self, PyObject *unused) { unsigned char digest[EVP_MAX_MD_SIZE]; EVP_MD_CTX temp_ctx; @@ -126,9 +120,6 @@ EVP_hexdigest(EVPobject *self, PyObject *args) char *hex_digest; unsigned int i, j, digest_size; - if (!PyArg_ParseTuple(args, ":hexdigest")) - return NULL; - /* Get the raw (binary) digest value */ EVP_MD_CTX_copy(&temp_ctx, &self->ctx); digest_size = EVP_MD_CTX_size(&temp_ctx); @@ -182,9 +173,9 @@ EVP_update(EVPobject *self, PyObject *args) static PyMethodDef EVP_methods[] = { {"update", (PyCFunction)EVP_update, METH_VARARGS, EVP_update__doc__}, - {"digest", (PyCFunction)EVP_digest, METH_VARARGS, EVP_digest__doc__}, - {"hexdigest", (PyCFunction)EVP_hexdigest, METH_VARARGS, EVP_hexdigest__doc__}, - {"copy", (PyCFunction)EVP_copy, METH_VARARGS, EVP_copy__doc__}, + {"digest", (PyCFunction)EVP_digest, METH_NOARGS, EVP_digest__doc__}, + {"hexdigest", (PyCFunction)EVP_hexdigest, METH_NOARGS, EVP_hexdigest__doc__}, + {"copy", (PyCFunction)EVP_copy, METH_NOARGS, EVP_copy__doc__}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c index 3ad0a9ef369..5a81bfbaaf5 100644 --- a/Modules/_hotshot.c +++ b/Modules/_hotshot.c @@ -1058,7 +1058,7 @@ profiler_runcall(ProfilerObject *self, PyObject *args) PyObject *callkw = NULL; PyObject *callable; - if (PyArg_ParseTuple(args, "O|OO:runcall", + if (PyArg_UnpackTuple(args, "runcall", 1, 3, &callable, &callargs, &callkw)) { if (is_available(self)) { do_start(self); @@ -1575,23 +1575,18 @@ PyDoc_STR( ; static PyObject * -hotshot_resolution(PyObject *unused, PyObject *args) +hotshot_resolution(PyObject *self, PyObject *unused) { - PyObject *result = NULL; - - if (PyArg_ParseTuple(args, ":resolution")) { - if (timeofday_diff == 0) { - calibrate(); - calibrate(); - calibrate(); - } -#ifdef MS_WINDOWS - result = Py_BuildValue("ii", timeofday_diff, frequency.LowPart); -#else - result = Py_BuildValue("ii", timeofday_diff, rusage_diff); -#endif + if (timeofday_diff == 0) { + calibrate(); + calibrate(); + calibrate(); } - return result; +#ifdef MS_WINDOWS + return Py_BuildValue("ii", timeofday_diff, frequency.LowPart); +#else + return Py_BuildValue("ii", timeofday_diff, rusage_diff); +#endif } @@ -1599,7 +1594,7 @@ static PyMethodDef functions[] = { {"coverage", hotshot_coverage, METH_VARARGS, coverage__doc__}, {"profiler", hotshot_profiler, METH_VARARGS, profiler__doc__}, {"logreader", hotshot_logreader, METH_VARARGS, logreader__doc__}, - {"resolution", hotshot_resolution, METH_VARARGS, resolution__doc__}, + {"resolution", hotshot_resolution, METH_NOARGS, resolution__doc__}, {NULL, NULL} }; diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 58beb5c3039..c016cd7341b 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -281,7 +281,7 @@ PyLocale_strcoll(PyObject* self, PyObject* args) wchar_t *ws1 = NULL, *ws2 = NULL; int rel1 = 0, rel2 = 0, len1, len2; - if (!PyArg_ParseTuple(args, "OO:strcoll", &os1, &os2)) + if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2)) return NULL; /* If both arguments are byte strings, use strcoll. */ if (PyString_Check(os1) && PyString_Check(os2)) diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index fb6eb065001..71d0aaa70b1 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -280,21 +280,25 @@ PyMODINIT_FUNC init_sqlite3(void) goto error; } PyDict_SetItemString(dict, "PARSE_DECLTYPES", tmp_obj); + Py_DECREF(tmp_obj); if (!(tmp_obj = PyInt_FromLong(PARSE_COLNAMES))) { goto error; } PyDict_SetItemString(dict, "PARSE_COLNAMES", tmp_obj); + Py_DECREF(tmp_obj); if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) { goto error; } PyDict_SetItemString(dict, "version", tmp_obj); + Py_DECREF(tmp_obj); if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) { goto error; } PyDict_SetItemString(dict, "sqlite_version", tmp_obj); + Py_DECREF(tmp_obj); /* initialize microprotocols layer */ microprotocols_init(dict); diff --git a/Modules/_sre.c b/Modules/_sre.c index 06acb6815d0..42e0c202ff1 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1623,7 +1623,7 @@ static PyObject*pattern_new_match(PatternObject*, SRE_STATE*, int); static PyObject*pattern_scanner(PatternObject*, PyObject*); static PyObject * -sre_codesize(PyObject* self, PyObject* args) +sre_codesize(PyObject* self, PyObject *unused) { return Py_BuildValue("i", sizeof(SRE_CODE)); } @@ -2467,15 +2467,12 @@ pattern_subn(PatternObject* self, PyObject* args, PyObject* kw) } static PyObject* -pattern_copy(PatternObject* self, PyObject* args) +pattern_copy(PatternObject* self, PyObject *unused) { #ifdef USE_BUILTIN_COPY PatternObject* copy; int offset; - if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__")) - return NULL; - copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize); if (!copy) return NULL; @@ -2498,16 +2495,12 @@ pattern_copy(PatternObject* self, PyObject* args) } static PyObject* -pattern_deepcopy(PatternObject* self, PyObject* args) +pattern_deepcopy(PatternObject* self, PyObject* memo) { #ifdef USE_BUILTIN_COPY PatternObject* copy; - PyObject* memo; - if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo)) - return NULL; - - copy = (PatternObject*) pattern_copy(self, Py_None); + copy = (PatternObject*) pattern_copy(self); if (!copy) return NULL; @@ -2578,8 +2571,8 @@ static PyMethodDef pattern_methods[] = { pattern_finditer_doc}, #endif {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS}, - {"__copy__", (PyCFunction) pattern_copy, METH_VARARGS}, - {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_VARARGS}, + {"__copy__", (PyCFunction) pattern_copy, METH_NOARGS}, + {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O}, {NULL, NULL} }; @@ -2772,12 +2765,8 @@ match_getslice(MatchObject* self, PyObject* index, PyObject* def) } static PyObject* -match_expand(MatchObject* self, PyObject* args) +match_expand(MatchObject* self, PyObject* ptemplate) { - PyObject* ptemplate; - if (!PyArg_ParseTuple(args, "O:expand", &ptemplate)) - return NULL; - /* delegate to Python code */ return call( SRE_PY_MODULE, "_expand", @@ -2902,7 +2891,7 @@ match_start(MatchObject* self, PyObject* args) int index; PyObject* index_ = Py_False; /* zero */ - if (!PyArg_ParseTuple(args, "|O:start", &index_)) + if (!PyArg_UnpackTuple(args, "start", 0, 1, &index_)) return NULL; index = match_getindex(self, index_); @@ -2925,7 +2914,7 @@ match_end(MatchObject* self, PyObject* args) int index; PyObject* index_ = Py_False; /* zero */ - if (!PyArg_ParseTuple(args, "|O:end", &index_)) + if (!PyArg_UnpackTuple(args, "end", 0, 1, &index_)) return NULL; index = match_getindex(self, index_); @@ -2975,7 +2964,7 @@ match_span(MatchObject* self, PyObject* args) int index; PyObject* index_ = Py_False; /* zero */ - if (!PyArg_ParseTuple(args, "|O:span", &index_)) + if (!PyArg_UnpackTuple(args, "span", 0, 1, &index_)) return NULL; index = match_getindex(self, index_); @@ -3019,15 +3008,12 @@ match_regs(MatchObject* self) } static PyObject* -match_copy(MatchObject* self, PyObject* args) +match_copy(MatchObject* self, PyObject *unused) { #ifdef USE_BUILTIN_COPY MatchObject* copy; int slots, offset; - if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__")) - return NULL; - slots = 2 * (self->pattern->groups+1); copy = PyObject_NEW_VAR(MatchObject, &Match_Type, slots); @@ -3053,16 +3039,12 @@ match_copy(MatchObject* self, PyObject* args) } static PyObject* -match_deepcopy(MatchObject* self, PyObject* args) +match_deepcopy(MatchObject* self, PyObject* memo) { #ifdef USE_BUILTIN_COPY MatchObject* copy; - PyObject* memo; - if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo)) - return NULL; - - copy = (MatchObject*) match_copy(self, Py_None); + copy = (MatchObject*) match_copy(self); if (!copy) return NULL; @@ -3086,9 +3068,9 @@ static PyMethodDef match_methods[] = { {"span", (PyCFunction) match_span, METH_VARARGS}, {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS}, {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS}, - {"expand", (PyCFunction) match_expand, METH_VARARGS}, - {"__copy__", (PyCFunction) match_copy, METH_VARARGS}, - {"__deepcopy__", (PyCFunction) match_deepcopy, METH_VARARGS}, + {"expand", (PyCFunction) match_expand, METH_O}, + {"__copy__", (PyCFunction) match_copy, METH_NOARGS}, + {"__deepcopy__", (PyCFunction) match_deepcopy, METH_O}, {NULL, NULL} }; @@ -3243,7 +3225,7 @@ scanner_dealloc(ScannerObject* self) } static PyObject* -scanner_match(ScannerObject* self, PyObject* args) +scanner_match(ScannerObject* self, PyObject *unused) { SRE_STATE* state = &self->state; PyObject* match; @@ -3274,7 +3256,7 @@ scanner_match(ScannerObject* self, PyObject* args) static PyObject* -scanner_search(ScannerObject* self, PyObject* args) +scanner_search(ScannerObject* self, PyObject *unused) { SRE_STATE* state = &self->state; PyObject* match; @@ -3304,10 +3286,8 @@ scanner_search(ScannerObject* self, PyObject* args) } static PyMethodDef scanner_methods[] = { - /* FIXME: use METH_OLDARGS instead of 0 or fix to use METH_VARARGS */ - /* METH_OLDARGS is not in Python 1.5.2 */ - {"match", (PyCFunction) scanner_match, 0}, - {"search", (PyCFunction) scanner_search, 0}, + {"match", (PyCFunction) scanner_match, METH_NOARGS}, + {"search", (PyCFunction) scanner_search, METH_NOARGS}, {NULL, NULL} }; @@ -3373,7 +3353,7 @@ pattern_scanner(PatternObject* pattern, PyObject* args) static PyMethodDef _functions[] = { {"compile", _compile, METH_VARARGS}, - {"getcodesize", sre_codesize, METH_VARARGS}, + {"getcodesize", sre_codesize, METH_NOARGS}, {"getlower", sre_getlower, METH_VARARGS}, {NULL, NULL} }; diff --git a/Modules/_struct.c b/Modules/_struct.c index cb2e5380d59..fd550c96505 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -17,6 +17,20 @@ static PyTypeObject PyStructType; typedef int Py_ssize_t; #endif +/* If PY_STRUCT_OVERFLOW_MASKING is defined, the struct module will wrap all input + numbers for explicit endians such that they fit in the given type, much + like explicit casting in C. A warning will be raised if the number did + not originally fit within the range of the requested type. If it is + not defined, then all range errors and overflow will be struct.error + exceptions. */ + +#define PY_STRUCT_OVERFLOW_MASKING 1 + +#ifdef PY_STRUCT_OVERFLOW_MASKING +static PyObject *pylong_ulong_mask = NULL; +static PyObject *pyint_zero = NULL; +#endif + /* The translation function for each format character is table driven */ typedef struct _formatdef { char format; @@ -195,6 +209,75 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p) #endif +#ifdef PY_STRUCT_OVERFLOW_MASKING + +/* Helper routine to get a Python integer and raise the appropriate error + if it isn't one */ + +static int +get_wrapped_long(PyObject *v, long *p) +{ + if (get_long(v, p) < 0) { + if (PyLong_Check(v) && PyErr_ExceptionMatches(PyExc_OverflowError)) { + PyObject *wrapped; + long x; + PyErr_Clear(); + if (PyErr_Warn(PyExc_DeprecationWarning, "struct integer overflow masking is deprecated") < 0) + return -1; + wrapped = PyNumber_And(v, pylong_ulong_mask); + if (wrapped == NULL) + return -1; + x = (long)PyLong_AsUnsignedLong(wrapped); + Py_DECREF(wrapped); + if (x == -1 && PyErr_Occurred()) + return -1; + *p = x; + } else { + return -1; + } + } + return 0; +} + +static int +get_wrapped_ulong(PyObject *v, unsigned long *p) +{ + long x = (long)PyLong_AsUnsignedLong(v); + if (x == -1 && PyErr_Occurred()) { + PyObject *wrapped; + PyErr_Clear(); + wrapped = PyNumber_And(v, pylong_ulong_mask); + if (wrapped == NULL) + return -1; + if (PyErr_Warn(PyExc_DeprecationWarning, "struct integer overflow masking is deprecated") < 0) { + Py_DECREF(wrapped); + return -1; + } + x = (long)PyLong_AsUnsignedLong(wrapped); + Py_DECREF(wrapped); + if (x == -1 && PyErr_Occurred()) + return -1; + } + *p = (unsigned long)x; + return 0; +} + +#define RANGE_ERROR(x, f, flag, mask) \ + do { \ + if (_range_error(f, flag) < 0) \ + return -1; \ + else \ + (x) &= (mask); \ + } while (0) + +#else + +#define get_wrapped_long get_long +#define get_wrapped_ulong get_ulong +#define RANGE_ERROR(x, f, flag, mask) return _range_error(f, flag) + +#endif + /* Floating point helpers */ static PyObject * @@ -223,30 +306,51 @@ unpack_double(const char *p, /* start of 8-byte string */ /* Helper to format the range error exceptions */ static int -_range_error(char format, Py_ssize_t size, int is_unsigned) +_range_error(const formatdef *f, int is_unsigned) { - if (is_unsigned == 0) { - long smallest = 0, largest = 0; - Py_ssize_t i = size * 8; - while (--i > 0) { - smallest = (smallest * 2) - 1; - largest = (largest * 2) + 1; - } + /* ulargest is the largest unsigned value with f->size bytes. + * Note that the simpler: + * ((size_t)1 << (f->size * 8)) - 1 + * doesn't work when f->size == sizeof(size_t) because C doesn't + * define what happens when a left shift count is >= the number of + * bits in the integer being shifted; e.g., on some boxes it doesn't + * shift at all when they're equal. + */ + const size_t ulargest = (size_t)-1 >> ((SIZEOF_SIZE_T - f->size)*8); + assert(f->size >= 1 && f->size <= SIZEOF_SIZE_T); + if (is_unsigned) PyErr_Format(StructError, - "'%c' format requires %ld <= number <= %ld", - format, - smallest, - largest); - } else { - unsigned long largest = 0; - Py_ssize_t i = size * 8; - while (--i >= 0) - largest = (largest * 2) + 1; + "'%c' format requires 0 <= number <= %zu", + f->format, + ulargest); + else { + const Py_ssize_t largest = (Py_ssize_t)(ulargest >> 1); PyErr_Format(StructError, - "'%c' format requires 0 <= number <= %lu", - format, + "'%c' format requires %zd <= number <= %zd", + f->format, + ~ largest, largest); } +#ifdef PY_STRUCT_OVERFLOW_MASKING + { + PyObject *ptype, *pvalue, *ptraceback; + PyObject *msg; + int rval; + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + assert(pvalue != NULL); + msg = PyObject_Str(pvalue); + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + if (msg == NULL) + return -1; + rval = PyErr_Warn(PyExc_DeprecationWarning, + PyString_AS_STRING(msg)); + Py_DECREF(msg); + if (rval == 0) + return 0; + } +#endif return -1; } @@ -482,7 +586,7 @@ np_int(char *p, PyObject *v, const formatdef *f) return -1; #if (SIZEOF_LONG > SIZEOF_INT) if ((x < ((long)INT_MIN)) || (x > ((long)INT_MAX))) - return _range_error(f->format, sizeof(y), 0); + return _range_error(f, 0); #endif y = (int)x; memcpy(p, (char *)&y, sizeof y); @@ -495,11 +599,11 @@ np_uint(char *p, PyObject *v, const formatdef *f) unsigned long x; unsigned int y; if (get_ulong(v, &x) < 0) - return _range_error(f->format, sizeof(y), 1); + return _range_error(f, 1); y = (unsigned int)x; #if (SIZEOF_LONG > SIZEOF_INT) if (x > ((unsigned long)UINT_MAX)) - return _range_error(f->format, sizeof(y), 1); + return _range_error(f, 1); #endif memcpy(p, (char *)&y, sizeof y); return 0; @@ -520,7 +624,7 @@ np_ulong(char *p, PyObject *v, const formatdef *f) { unsigned long x; if (get_ulong(v, &x) < 0) - return _range_error(f->format, sizeof(x), 1); + return _range_error(f, 1); memcpy(p, (char *)&x, sizeof x); return 0; } @@ -621,8 +725,9 @@ bu_int(const char *p, const formatdef *f) { long x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (*p++ & 0xFF); + x = (x<<8) | *bytes++; } while (--i > 0); /* Extend the sign bit. */ if (SIZEOF_LONG > f->size) @@ -635,8 +740,9 @@ bu_uint(const char *p, const formatdef *f) { unsigned long x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (*p++ & 0xFF); + x = (x<<8) | *bytes++; } while (--i > 0); if (x <= LONG_MAX) return PyInt_FromLong((long)x); @@ -649,8 +755,9 @@ bu_longlong(const char *p, const formatdef *f) #ifdef HAVE_LONG_LONG PY_LONG_LONG x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (*p++ & 0xFF); + x = (x<<8) | *bytes++; } while (--i > 0); /* Extend the sign bit. */ if (SIZEOF_LONG_LONG > f->size) @@ -672,8 +779,9 @@ bu_ulonglong(const char *p, const formatdef *f) #ifdef HAVE_LONG_LONG unsigned PY_LONG_LONG x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (*p++ & 0xFF); + x = (x<<8) | *bytes++; } while (--i > 0); if (x <= LONG_MAX) return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long)); @@ -703,15 +811,19 @@ bp_int(char *p, PyObject *v, const formatdef *f) { long x; Py_ssize_t i; - if (get_long(v, &x) < 0) + if (get_wrapped_long(v, &x) < 0) return -1; i = f->size; if (i != SIZEOF_LONG) { if ((i == 2) && (x < -32768 || x > 32767)) - return _range_error(f->format, i, 0); + RANGE_ERROR(x, f, 0, 0xffffL); #if (SIZEOF_LONG != 4) else if ((i == 4) && (x < -2147483648L || x > 2147483647L)) - return _range_error(f->format, i, 0); + RANGE_ERROR(x, f, 0, 0xffffffffL); +#endif +#ifdef PY_STRUCT_OVERFLOW_MASKING + else if ((i == 1) && (x < -128 || x > 127)) + RANGE_ERROR(x, f, 0, 0xffL); #endif } do { @@ -726,14 +838,14 @@ bp_uint(char *p, PyObject *v, const formatdef *f) { unsigned long x; Py_ssize_t i; - if (get_ulong(v, &x) < 0) + if (get_wrapped_ulong(v, &x) < 0) return -1; i = f->size; if (i != SIZEOF_LONG) { unsigned long maxint = 1; maxint <<= (unsigned long)(i * 8); if (x >= maxint) - return _range_error(f->format, f->size, 1); + RANGE_ERROR(x, f, 1, maxint - 1); } do { p[--i] = (char)x; @@ -800,8 +912,14 @@ bp_double(char *p, PyObject *v, const formatdef *f) static formatdef bigendian_table[] = { {'x', 1, 0, NULL}, +#ifdef PY_STRUCT_OVERFLOW_MASKING + /* Native packers do range checking without overflow masking. */ + {'b', 1, 0, nu_byte, bp_int}, + {'B', 1, 0, nu_ubyte, bp_uint}, +#else {'b', 1, 0, nu_byte, np_byte}, {'B', 1, 0, nu_ubyte, np_ubyte}, +#endif {'c', 1, 0, nu_char, np_char}, {'s', 1, 0, NULL}, {'p', 1, 0, NULL}, @@ -825,8 +943,9 @@ lu_int(const char *p, const formatdef *f) { long x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (p[--i] & 0xFF); + x = (x<<8) | bytes[--i]; } while (i > 0); /* Extend the sign bit. */ if (SIZEOF_LONG > f->size) @@ -839,8 +958,9 @@ lu_uint(const char *p, const formatdef *f) { unsigned long x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (p[--i] & 0xFF); + x = (x<<8) | bytes[--i]; } while (i > 0); if (x <= LONG_MAX) return PyInt_FromLong((long)x); @@ -853,8 +973,9 @@ lu_longlong(const char *p, const formatdef *f) #ifdef HAVE_LONG_LONG PY_LONG_LONG x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (p[--i] & 0xFF); + x = (x<<8) | bytes[--i]; } while (i > 0); /* Extend the sign bit. */ if (SIZEOF_LONG_LONG > f->size) @@ -876,8 +997,9 @@ lu_ulonglong(const char *p, const formatdef *f) #ifdef HAVE_LONG_LONG unsigned PY_LONG_LONG x = 0; Py_ssize_t i = f->size; + const unsigned char *bytes = (const unsigned char *)p; do { - x = (x<<8) | (p[--i] & 0xFF); + x = (x<<8) | bytes[--i]; } while (i > 0); if (x <= LONG_MAX) return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long)); @@ -907,15 +1029,19 @@ lp_int(char *p, PyObject *v, const formatdef *f) { long x; Py_ssize_t i; - if (get_long(v, &x) < 0) + if (get_wrapped_long(v, &x) < 0) return -1; i = f->size; if (i != SIZEOF_LONG) { if ((i == 2) && (x < -32768 || x > 32767)) - return _range_error(f->format, i, 0); + RANGE_ERROR(x, f, 0, 0xffffL); #if (SIZEOF_LONG != 4) else if ((i == 4) && (x < -2147483648L || x > 2147483647L)) - return _range_error(f->format, i, 0); + RANGE_ERROR(x, f, 0, 0xffffffffL); +#endif +#ifdef PY_STRUCT_OVERFLOW_MASKING + else if ((i == 1) && (x < -128 || x > 127)) + RANGE_ERROR(x, f, 0, 0xffL); #endif } do { @@ -930,14 +1056,14 @@ lp_uint(char *p, PyObject *v, const formatdef *f) { unsigned long x; Py_ssize_t i; - if (get_ulong(v, &x) < 0) + if (get_wrapped_ulong(v, &x) < 0) return -1; i = f->size; if (i != SIZEOF_LONG) { unsigned long maxint = 1; maxint <<= (unsigned long)(i * 8); if (x >= maxint) - return _range_error(f->format, f->size, 1); + RANGE_ERROR(x, f, 1, maxint - 1); } do { *p++ = (char)x; @@ -1004,8 +1130,14 @@ lp_double(char *p, PyObject *v, const formatdef *f) static formatdef lilendian_table[] = { {'x', 1, 0, NULL}, +#ifdef PY_STRUCT_OVERFLOW_MASKING + /* Native packers do range checking without overflow masking. */ + {'b', 1, 0, nu_byte, lp_int}, + {'B', 1, 0, nu_ubyte, lp_uint}, +#else {'b', 1, 0, nu_byte, np_byte}, {'B', 1, 0, nu_ubyte, np_ubyte}, +#endif {'c', 1, 0, nu_char, np_char}, {'s', 1, 0, NULL}, {'p', 1, 0, NULL}, @@ -1089,7 +1221,7 @@ prepare_s(PyStructObject *self) const formatdef *f; const formatdef *e; formatcode *codes; - + const char *s; const char *fmt; char c; @@ -1098,7 +1230,7 @@ prepare_s(PyStructObject *self) fmt = PyString_AS_STRING(self->s_format); f = whichtable((char **)&fmt); - + s = fmt; size = 0; len = 0; @@ -1126,7 +1258,7 @@ prepare_s(PyStructObject *self) e = getentry(c, f); if (e == NULL) return -1; - + switch (c) { case 's': /* fall through */ case 'p': len++; break; @@ -1153,7 +1285,7 @@ prepare_s(PyStructObject *self) return -1; } self->s_codes = codes; - + s = fmt; size = 0; while ((c = *s++) != '\0') { @@ -1170,7 +1302,7 @@ prepare_s(PyStructObject *self) num = 1; e = getentry(c, f); - + size = align(size, c, e); if (c == 's' || c == 'p') { codes->offset = size; @@ -1193,7 +1325,7 @@ prepare_s(PyStructObject *self) codes->fmtdef = NULL; codes->offset = size; codes->size = 0; - + return 0; } @@ -1233,7 +1365,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds) Py_INCREF(o_format); Py_XDECREF(soself->s_format); soself->s_format = o_format; - + ret = prepare_s(soself); return ret; } @@ -1302,7 +1434,7 @@ s_unpack(PyObject *self, PyObject *inputstr) { PyStructObject *soself = (PyStructObject *)self; assert(PyStruct_Check(self)); - assert(soself->s_codes != NULL); + assert(soself->s_codes != NULL); if (inputstr == NULL || !PyString_Check(inputstr) || PyString_GET_SIZE(inputstr) != soself->s_size) { PyErr_Format(StructError, @@ -1344,7 +1476,7 @@ s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds) "unpack_from requires a buffer argument"); return NULL; } - + if (offset < 0) offset += buffer_len; @@ -1410,11 +1542,15 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf) *res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char); } else { v = PyTuple_GET_ITEM(args, i++); - if (e->pack(res, v, e) < 0) + if (e->pack(res, v, e) < 0) { + if (PyLong_Check(v) && PyErr_ExceptionMatches(PyExc_OverflowError)) + PyErr_SetString(StructError, + "long too large to convert to int"); return -1; + } } } - + /* Success */ return 0; } @@ -1443,12 +1579,12 @@ s_pack(PyObject *self, PyObject *args) "pack requires exactly %zd arguments", soself->s_len); return NULL; } - + /* Allocate a new string */ result = PyString_FromStringAndSize((char *)NULL, soself->s_size); if (result == NULL) return NULL; - + /* Call the guts */ if ( s_pack_internal(soself, args, 0, PyString_AS_STRING(result)) != 0 ) { Py_DECREF(result); @@ -1481,14 +1617,14 @@ s_pack_to(PyObject *self, PyObject *args) PyTuple_GET_SIZE(args) != (soself->s_len + 2)) { PyErr_Format(StructError, - "pack_to requires exactly %zd arguments", + "pack_to requires exactly %zd arguments", (soself->s_len + 2)); return NULL; } /* Extract a writable memory buffer from the first argument */ - if ( PyObject_AsWriteBuffer(PyTuple_GET_ITEM(args, 0), - (void**)&buffer, &buffer_len) == -1 ) { + if ( PyObject_AsWriteBuffer(PyTuple_GET_ITEM(args, 0), + (void**)&buffer, &buffer_len) == -1 ) { return NULL; } assert( buffer_len >= 0 ); @@ -1507,13 +1643,13 @@ s_pack_to(PyObject *self, PyObject *args) soself->s_size); return NULL; } - + /* Call the guts */ if ( s_pack_internal(soself, args, 2, buffer + offset) != 0 ) { return NULL; } - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1533,7 +1669,7 @@ s_get_size(PyStructObject *self, void *unused) static struct PyMethodDef s_methods[] = { {"pack", (PyCFunction)s_pack, METH_VARARGS, s_pack__doc__}, - {"pack_to", (PyCFunction)s_pack_to, METH_VARARGS, s_pack_to__doc__}, + {"pack_to", (PyCFunction)s_pack_to, METH_VARARGS, s_pack_to__doc__}, {"unpack", (PyCFunction)s_unpack, METH_O, s_unpack__doc__}, {"unpack_from", (PyCFunction)s_unpack_from, METH_KEYWORDS, s_unpack_from__doc__}, {NULL, NULL} /* sentinel */ @@ -1606,6 +1742,26 @@ init_struct(void) if (PyType_Ready(&PyStructType) < 0) return; +#ifdef PY_STRUCT_OVERFLOW_MASKING + if (pyint_zero == NULL) { + pyint_zero = PyInt_FromLong(0); + if (pyint_zero == NULL) + return; + } + if (pylong_ulong_mask == NULL) { +#if (SIZEOF_LONG == 4) + pylong_ulong_mask = PyLong_FromString("FFFFFFFF", NULL, 16); +#else + pylong_ulong_mask = PyLong_FromString("FFFFFFFFFFFFFFFF", NULL, 16); +#endif + if (pylong_ulong_mask == NULL) + return; + } + +#else + /* This speed trick can't be used until overflow masking goes away, because + native endian always raises exceptions instead of overflow masking. */ + /* Check endian and swap in faster functions */ { int one = 1; @@ -1627,7 +1783,7 @@ init_struct(void) listed in the same order */ if (ptr == other) other++; - /* Only use the trick if the + /* Only use the trick if the size matches */ if (ptr->size != native->size) break; @@ -1644,7 +1800,8 @@ init_struct(void) native++; } } - +#endif + /* Add some symbolic constants to the module */ if (StructError == NULL) { StructError = PyErr_NewException("struct.error", NULL, NULL); @@ -1657,4 +1814,9 @@ init_struct(void) Py_INCREF((PyObject*)&PyStructType); PyModule_AddObject(m, "Struct", (PyObject*)&PyStructType); + + PyModule_AddIntConstant(m, "_PY_STRUCT_RANGE_CHECKING", 1); +#ifdef PY_STRUCT_OVERFLOW_MASKING + PyModule_AddIntConstant(m, "_PY_STRUCT_OVERFLOW_MASKING", 1); +#endif } diff --git a/Modules/audioop.c b/Modules/audioop.c index ed70cdf48ab..8f5d30c8058 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -302,7 +302,7 @@ audioop_getsample(PyObject *self, PyObject *args) int len, size, val = 0; int i; - if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &size, &i) ) + if ( !PyArg_ParseTuple(args, "s#ii:getsample", &cp, &len, &size, &i) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -326,7 +326,7 @@ audioop_max(PyObject *self, PyObject *args) int i; int max = 0; - if ( !PyArg_Parse(args, "(s#i)", &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:max", &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -350,7 +350,7 @@ audioop_minmax(PyObject *self, PyObject *args) int i; int min = 0x7fffffff, max = -0x7fffffff; - if (!PyArg_Parse(args, "(s#i)", &cp, &len, &size)) + if (!PyArg_ParseTuple(args, "s#i:minmax", &cp, &len, &size)) return NULL; if (size != 1 && size != 2 && size != 4) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -374,7 +374,7 @@ audioop_avg(PyObject *self, PyObject *args) int i; double avg = 0.0; - if ( !PyArg_Parse(args, "(s#i)", &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:avg", &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -401,7 +401,7 @@ audioop_rms(PyObject *self, PyObject *args) int i; double sum_squares = 0.0; - if ( !PyArg_Parse(args, "(s#i)", &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:rms", &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -472,7 +472,8 @@ audioop_findfit(PyObject *self, PyObject *args) double aj_m1, aj_lm1; double sum_ri_2, sum_aij_2, sum_aij_ri, result, best_result, factor; - if ( !PyArg_Parse(args, "(s#s#)", &cp1, &len1, &cp2, &len2) ) + if ( !PyArg_ParseTuple(args, "s#s#:findfit", + &cp1, &len1, &cp2, &len2) ) return 0; if ( len1 & 1 || len2 & 1 ) { PyErr_SetString(AudioopError, "Strings should be even-sized"); @@ -528,7 +529,8 @@ audioop_findfactor(PyObject *self, PyObject *args) int len1, len2; double sum_ri_2, sum_aij_ri, result; - if ( !PyArg_Parse(args, "(s#s#)", &cp1, &len1, &cp2, &len2) ) + if ( !PyArg_ParseTuple(args, "s#s#:findfactor", + &cp1, &len1, &cp2, &len2) ) return 0; if ( len1 & 1 || len2 & 1 ) { PyErr_SetString(AudioopError, "Strings should be even-sized"); @@ -560,7 +562,7 @@ audioop_findmax(PyObject *self, PyObject *args) double aj_m1, aj_lm1; double result, best_result; - if ( !PyArg_Parse(args, "(s#i)", &cp1, &len1, &len2) ) + if ( !PyArg_ParseTuple(args, "s#i:findmax", &cp1, &len1, &len2) ) return 0; if ( len1 & 1 ) { PyErr_SetString(AudioopError, "Strings should be even-sized"); @@ -605,7 +607,7 @@ audioop_avgpp(PyObject *self, PyObject *args) double avg = 0.0; int diff, prevdiff, extremediff, nextreme = 0; - if ( !PyArg_Parse(args, "(s#i)", &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:avgpp", &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -662,7 +664,7 @@ audioop_maxpp(PyObject *self, PyObject *args) int max = 0; int diff, prevdiff, extremediff; - if ( !PyArg_Parse(args, "(s#i)", &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:maxpp", &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -713,7 +715,7 @@ audioop_cross(PyObject *self, PyObject *args) int i; int prevval, ncross; - if ( !PyArg_Parse(args, "(s#i)", &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:cross", &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4 ) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -741,7 +743,7 @@ audioop_mul(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#id)", &cp, &len, &size, &factor ) ) + if ( !PyArg_ParseTuple(args, "s#id:mul", &cp, &len, &size, &factor ) ) return 0; if ( size == 1 ) maxval = (double) 0x7f; @@ -782,7 +784,8 @@ audioop_tomono(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#idd)", &cp, &len, &size, &fac1, &fac2 ) ) + if ( !PyArg_ParseTuple(args, "s#idd:tomono", + &cp, &len, &size, &fac1, &fac2 ) ) return 0; if ( size == 1 ) maxval = (double) 0x7f; @@ -826,7 +829,8 @@ audioop_tostereo(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#idd)", &cp, &len, &size, &fac1, &fac2 ) ) + if ( !PyArg_ParseTuple(args, "s#idd:tostereo", + &cp, &len, &size, &fac1, &fac2 ) ) return 0; if ( size == 1 ) maxval = (double) 0x7f; @@ -877,7 +881,7 @@ audioop_add(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#s#i)", + if ( !PyArg_ParseTuple(args, "s#s#i:add", &cp1, &len1, &cp2, &len2, &size ) ) return 0; @@ -931,7 +935,7 @@ audioop_bias(PyObject *self, PyObject *args) int i; int bias; - if ( !PyArg_Parse(args, "(s#ii)", + if ( !PyArg_ParseTuple(args, "s#ii:bias", &cp, &len, &size , &bias) ) return 0; @@ -967,7 +971,7 @@ audioop_reverse(PyObject *self, PyObject *args) PyObject *rv; int i, j; - if ( !PyArg_Parse(args, "(s#i)", + if ( !PyArg_ParseTuple(args, "s#i:reverse", &cp, &len, &size) ) return 0; @@ -1004,7 +1008,7 @@ audioop_lin2lin(PyObject *self, PyObject *args) PyObject *rv; int i, j; - if ( !PyArg_Parse(args, "(s#ii)", + if ( !PyArg_ParseTuple(args, "s#ii:lin2lin", &cp, &len, &size, &size2) ) return 0; @@ -1053,8 +1057,9 @@ audioop_ratecv(PyObject *self, PyObject *args) weightA = 1; weightB = 0; - if (!PyArg_ParseTuple(args, "s#iiiiO|ii:ratecv", &cp, &len, &size, &nchannels, - &inrate, &outrate, &state, &weightA, &weightB)) + if (!PyArg_ParseTuple(args, "s#iiiiO|ii:ratecv", &cp, &len, &size, + &nchannels, &inrate, &outrate, &state, + &weightA, &weightB)) return NULL; if (size != 1 && size != 2 && size != 4) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -1117,7 +1122,8 @@ audioop_ratecv(PyObject *self, PyObject *args) } for (chan = 0; chan < nchannels; chan++) { if (!PyArg_ParseTuple(PyTuple_GetItem(samps, chan), - "ii:ratecv",&prev_i[chan],&cur_i[chan])) + "ii:ratecv", &prev_i[chan], + &cur_i[chan])) goto exit; } } @@ -1235,9 +1241,9 @@ audioop_lin2ulaw(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#i)", - &cp, &len, &size) ) - return 0; + if ( !PyArg_ParseTuple(args, "s#i:lin2ulaw", + &cp, &len, &size) ) + return 0 ; if ( size != 1 && size != 2 && size != 4) { PyErr_SetString(AudioopError, "Size should be 1, 2 or 4"); @@ -1269,8 +1275,8 @@ audioop_ulaw2lin(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#i)", - &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:ulaw2lin", + &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4) { @@ -1303,8 +1309,8 @@ audioop_lin2alaw(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#i)", - &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:lin2alaw", + &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4) { @@ -1337,8 +1343,8 @@ audioop_alaw2lin(PyObject *self, PyObject *args) PyObject *rv; int i; - if ( !PyArg_Parse(args, "(s#i)", - &cp, &len, &size) ) + if ( !PyArg_ParseTuple(args, "s#i:alaw2lin", + &cp, &len, &size) ) return 0; if ( size != 1 && size != 2 && size != 4) { @@ -1372,8 +1378,8 @@ audioop_lin2adpcm(PyObject *self, PyObject *args) PyObject *rv, *state, *str; int i, outputbuffer = 0, bufferstep; - if ( !PyArg_Parse(args, "(s#iO)", - &cp, &len, &size, &state) ) + if ( !PyArg_ParseTuple(args, "s#iO:lin2adpcm", + &cp, &len, &size, &state) ) return 0; @@ -1393,7 +1399,7 @@ audioop_lin2adpcm(PyObject *self, PyObject *args) valpred = 0; step = 7; index = 0; - } else if ( !PyArg_Parse(state, "(ii)", &valpred, &index) ) + } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) ) return 0; step = stepsizeTable[index]; @@ -1480,8 +1486,8 @@ audioop_adpcm2lin(PyObject *self, PyObject *args) PyObject *rv, *str, *state; int i, inputbuffer = 0, bufferstep; - if ( !PyArg_Parse(args, "(s#iO)", - &cp, &len, &size, &state) ) + if ( !PyArg_ParseTuple(args, "s#iO:adpcm2lin", + &cp, &len, &size, &state) ) return 0; if ( size != 1 && size != 2 && size != 4) { @@ -1495,7 +1501,7 @@ audioop_adpcm2lin(PyObject *self, PyObject *args) valpred = 0; step = 7; index = 0; - } else if ( !PyArg_Parse(state, "(ii)", &valpred, &index) ) + } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) ) return 0; str = PyString_FromStringAndSize(NULL, len*size*2); @@ -1562,30 +1568,30 @@ audioop_adpcm2lin(PyObject *self, PyObject *args) } static PyMethodDef audioop_methods[] = { - { "max", audioop_max, METH_OLDARGS }, - { "minmax", audioop_minmax, METH_OLDARGS }, - { "avg", audioop_avg, METH_OLDARGS }, - { "maxpp", audioop_maxpp, METH_OLDARGS }, - { "avgpp", audioop_avgpp, METH_OLDARGS }, - { "rms", audioop_rms, METH_OLDARGS }, - { "findfit", audioop_findfit, METH_OLDARGS }, - { "findmax", audioop_findmax, METH_OLDARGS }, - { "findfactor", audioop_findfactor, METH_OLDARGS }, - { "cross", audioop_cross, METH_OLDARGS }, - { "mul", audioop_mul, METH_OLDARGS }, - { "add", audioop_add, METH_OLDARGS }, - { "bias", audioop_bias, METH_OLDARGS }, - { "ulaw2lin", audioop_ulaw2lin, METH_OLDARGS }, - { "lin2ulaw", audioop_lin2ulaw, METH_OLDARGS }, - { "alaw2lin", audioop_alaw2lin, METH_OLDARGS }, - { "lin2alaw", audioop_lin2alaw, METH_OLDARGS }, - { "lin2lin", audioop_lin2lin, METH_OLDARGS }, - { "adpcm2lin", audioop_adpcm2lin, METH_OLDARGS }, - { "lin2adpcm", audioop_lin2adpcm, METH_OLDARGS }, - { "tomono", audioop_tomono, METH_OLDARGS }, - { "tostereo", audioop_tostereo, METH_OLDARGS }, - { "getsample", audioop_getsample, METH_OLDARGS }, - { "reverse", audioop_reverse, METH_OLDARGS }, + { "max", audioop_max, METH_VARARGS }, + { "minmax", audioop_minmax, METH_VARARGS }, + { "avg", audioop_avg, METH_VARARGS }, + { "maxpp", audioop_maxpp, METH_VARARGS }, + { "avgpp", audioop_avgpp, METH_VARARGS }, + { "rms", audioop_rms, METH_VARARGS }, + { "findfit", audioop_findfit, METH_VARARGS }, + { "findmax", audioop_findmax, METH_VARARGS }, + { "findfactor", audioop_findfactor, METH_VARARGS }, + { "cross", audioop_cross, METH_VARARGS }, + { "mul", audioop_mul, METH_VARARGS }, + { "add", audioop_add, METH_VARARGS }, + { "bias", audioop_bias, METH_VARARGS }, + { "ulaw2lin", audioop_ulaw2lin, METH_VARARGS }, + { "lin2ulaw", audioop_lin2ulaw, METH_VARARGS }, + { "alaw2lin", audioop_alaw2lin, METH_VARARGS }, + { "lin2alaw", audioop_lin2alaw, METH_VARARGS }, + { "lin2lin", audioop_lin2lin, METH_VARARGS }, + { "adpcm2lin", audioop_adpcm2lin, METH_VARARGS }, + { "lin2adpcm", audioop_lin2adpcm, METH_VARARGS }, + { "tomono", audioop_tomono, METH_VARARGS }, + { "tostereo", audioop_tostereo, METH_VARARGS }, + { "getsample", audioop_getsample, METH_VARARGS }, + { "reverse", audioop_reverse, METH_VARARGS }, { "ratecv", audioop_ratecv, METH_VARARGS }, { 0, 0 } }; diff --git a/Modules/binascii.c b/Modules/binascii.c index 4623b7cd61f..71a962452ec 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -644,7 +644,7 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args) /* Empty string is a special case */ if ( in_len == 0 ) - return Py_BuildValue("s", ""); + return PyString_FromString(""); /* Allocate a buffer of reasonable size. Resized when needed */ out_len = in_len*2; diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 85fd459318e..0d293627afe 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -5110,29 +5110,23 @@ noload(Unpicklerobject *self) static PyObject * -Unpickler_load(Unpicklerobject *self, PyObject *args) +Unpickler_load(Unpicklerobject *self, PyObject *unused) { - if (!( PyArg_ParseTuple(args, ":load"))) - return NULL; - return load(self); } static PyObject * -Unpickler_noload(Unpicklerobject *self, PyObject *args) +Unpickler_noload(Unpicklerobject *self, PyObject *unused) { - if (!( PyArg_ParseTuple(args, ":noload"))) - return NULL; - return noload(self); } static struct PyMethodDef Unpickler_methods[] = { - {"load", (PyCFunction)Unpickler_load, METH_VARARGS, + {"load", (PyCFunction)Unpickler_load, METH_NOARGS, PyDoc_STR("load() -- Load a pickle") }, - {"noload", (PyCFunction)Unpickler_noload, METH_VARARGS, + {"noload", (PyCFunction)Unpickler_noload, METH_NOARGS, PyDoc_STR( "noload() -- not load a pickle, but go through most of the motions\n" "\n" @@ -5214,12 +5208,8 @@ newUnpicklerobject(PyObject *f) static PyObject * -get_Unpickler(PyObject *self, PyObject *args) +get_Unpickler(PyObject *self, PyObject *file) { - PyObject *file; - - if (!( PyArg_ParseTuple(args, "O:Unpickler", &file))) - return NULL; return (PyObject *)newUnpicklerobject(file); } @@ -5428,13 +5418,10 @@ cpm_dumps(PyObject *self, PyObject *args, PyObject *kwds) /* load(fileobj). */ static PyObject * -cpm_load(PyObject *self, PyObject *args) +cpm_load(PyObject *self, PyObject *ob) { Unpicklerobject *unpickler = 0; - PyObject *ob, *res = NULL; - - if (!( PyArg_ParseTuple(args, "O:load", &ob))) - goto finally; + PyObject *res = NULL; if (!( unpickler = newUnpicklerobject(ob))) goto finally; @@ -5519,7 +5506,7 @@ static struct PyMethodDef cPickle_methods[] = { "See the Pickler docstring for the meaning of optional argument proto.") }, - {"load", (PyCFunction)cpm_load, METH_VARARGS, + {"load", (PyCFunction)cpm_load, METH_O, PyDoc_STR("load(file) -- Load a pickle from the given file")}, {"loads", (PyCFunction)cpm_loads, METH_VARARGS, @@ -5550,7 +5537,7 @@ static struct PyMethodDef cPickle_methods[] = { "object, or any other custom object that meets this interface.\n") }, - {"Unpickler", (PyCFunction)get_Unpickler, METH_VARARGS, + {"Unpickler", (PyCFunction)get_Unpickler, METH_O, PyDoc_STR("Unpickler(file) -- Create an unpickler.")}, { NULL, NULL } diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 7e6aedc0376..7c6b989355a 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -1302,7 +1302,7 @@ mbstreamreader_read(MultibyteStreamReaderObject *self, PyObject *args) PyObject *sizeobj = NULL; Py_ssize_t size; - if (!PyArg_ParseTuple(args, "|O:read", &sizeobj)) + if (!PyArg_UnpackTuple(args, "read", 0, 1, &sizeobj)) return NULL; if (sizeobj == Py_None || sizeobj == NULL) @@ -1323,7 +1323,7 @@ mbstreamreader_readline(MultibyteStreamReaderObject *self, PyObject *args) PyObject *sizeobj = NULL; Py_ssize_t size; - if (!PyArg_ParseTuple(args, "|O:readline", &sizeobj)) + if (!PyArg_UnpackTuple(args, "readline", 0, 1, &sizeobj)) return NULL; if (sizeobj == Py_None || sizeobj == NULL) @@ -1344,7 +1344,7 @@ mbstreamreader_readlines(MultibyteStreamReaderObject *self, PyObject *args) PyObject *sizehintobj = NULL, *r, *sr; Py_ssize_t sizehint; - if (!PyArg_ParseTuple(args, "|O:readlines", &sizehintobj)) + if (!PyArg_UnpackTuple(args, "readlines", 0, 1, &sizehintobj)) return NULL; if (sizehintobj == Py_None || sizehintobj == NULL) @@ -1532,13 +1532,8 @@ mbstreamwriter_iwrite(MultibyteStreamWriterObject *self, } static PyObject * -mbstreamwriter_write(MultibyteStreamWriterObject *self, PyObject *args) +mbstreamwriter_write(MultibyteStreamWriterObject *self, PyObject *strobj) { - PyObject *strobj; - - if (!PyArg_ParseTuple(args, "O:write", &strobj)) - return NULL; - if (mbstreamwriter_iwrite(self, strobj)) return NULL; else @@ -1546,14 +1541,11 @@ mbstreamwriter_write(MultibyteStreamWriterObject *self, PyObject *args) } static PyObject * -mbstreamwriter_writelines(MultibyteStreamWriterObject *self, PyObject *args) +mbstreamwriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines) { - PyObject *lines, *strobj; + PyObject *strobj; int i, r; - if (!PyArg_ParseTuple(args, "O:writelines", &lines)) - return NULL; - if (!PySequence_Check(lines)) { PyErr_SetString(PyExc_TypeError, "arg must be a sequence object"); @@ -1676,9 +1668,9 @@ mbstreamwriter_dealloc(MultibyteStreamWriterObject *self) static struct PyMethodDef mbstreamwriter_methods[] = { {"write", (PyCFunction)mbstreamwriter_write, - METH_VARARGS, NULL}, + METH_O, NULL}, {"writelines", (PyCFunction)mbstreamwriter_writelines, - METH_VARARGS, NULL}, + METH_O, NULL}, {"reset", (PyCFunction)mbstreamwriter_reset, METH_NOARGS, NULL}, {NULL, NULL}, diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c index 8bfbbcda45b..9086c847702 100644 --- a/Modules/dbmmodule.c +++ b/Modules/dbmmodule.c @@ -168,10 +168,8 @@ static PyMappingMethods dbm_as_mapping = { }; static PyObject * -dbm__close(register dbmobject *dp, PyObject *args) +dbm__close(register dbmobject *dp, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":close")) - return NULL; if (dp->di_dbm) dbm_close(dp->di_dbm); dp->di_dbm = NULL; @@ -180,14 +178,12 @@ dbm__close(register dbmobject *dp, PyObject *args) } static PyObject * -dbm_keys(register dbmobject *dp, PyObject *args) +dbm_keys(register dbmobject *dp, PyObject *unused) { register PyObject *v, *item; datum key; int err; - if (!PyArg_ParseTuple(args, ":keys")) - return NULL; check_dbmobject_open(dp); v = PyList_New(0); if (v == NULL) @@ -277,9 +273,9 @@ dbm_setdefault(register dbmobject *dp, PyObject *args) } static PyMethodDef dbm_methods[] = { - {"close", (PyCFunction)dbm__close, METH_VARARGS, + {"close", (PyCFunction)dbm__close, METH_NOARGS, "close()\nClose the database."}, - {"keys", (PyCFunction)dbm_keys, METH_VARARGS, + {"keys", (PyCFunction)dbm_keys, METH_NOARGS, "keys() -> list\nReturn a list of all keys in the database."}, {"has_key", (PyCFunction)dbm_has_key, METH_VARARGS, "has_key(key} -> boolean\nReturn true iff key is in the database."}, diff --git a/Modules/flmodule.c b/Modules/flmodule.c index aa0d04e4059..e507c9fb586 100644 --- a/Modules/flmodule.c +++ b/Modules/flmodule.c @@ -148,22 +148,21 @@ releaseobjects(FL_FORM *form) static PyObject * generic_set_call_back(genericobject *g, PyObject *args) { - if (args == NULL) { + if (PyTuple_GET_SIZE(args) == 0) { Py_XDECREF(g->ob_callback); Py_XDECREF(g->ob_callback_arg); g->ob_callback = NULL; g->ob_callback_arg = NULL; } else { - if (!PyTuple_Check(args) || PyTuple_Size(args) != 2) { - PyErr_BadArgument(); - return NULL; - } + PyObject *a, *b; + if (!PyArg_UnpackTuple(args, "set_call_back", 2, 2, &a, &b) + return NULL; Py_XDECREF(g->ob_callback); Py_XDECREF(g->ob_callback_arg); - g->ob_callback = PyTuple_GetItem(args, 0); + g->ob_callback = a; Py_INCREF(g->ob_callback); - g->ob_callback_arg = PyTuple_GetItem(args, 1); + g->ob_callback_arg = b; Py_INCREF(g->ob_callback_arg); } Py_INCREF(Py_None); @@ -250,7 +249,7 @@ generic_set_object_shortcut(genericobject *g, PyObject *args) } static PyMethodDef generic_methods[] = { - {"set_call_back", (PyCFunction)generic_set_call_back, METH_OLDARGS}, + {"set_call_back", (PyCFunction)generic_set_call_back, METH_VARARGS}, {"delete_object", (PyCFunction)generic_delete_object, METH_NOARGS}, {"show_object", (PyCFunction)generic_show_object, METH_NOARGS}, {"hide_object", (PyCFunction)generic_hide_object, METH_NOARGS}, @@ -261,7 +260,7 @@ static PyMethodDef generic_methods[] = { #endif {"activate_object", (PyCFunction)generic_activate_object, METH_NOARGS}, {"deactivate_object", (PyCFunction)generic_deactivate_object, METH_NOARGS}, - {"set_object_shortcut", (PyCFunction)generic_set_object_shortcut, METH_OLDARGS}, + {"set_object_shortcut", (PyCFunction)generic_set_object_shortcut, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/fmmodule.c b/Modules/fmmodule.c index 01753909111..1f7edb68732 100644 --- a/Modules/fmmodule.c +++ b/Modules/fmmodule.c @@ -41,7 +41,7 @@ static PyObject * fh_scalefont(fhobject *self, PyObject *args) { double size; - if (!PyArg_Parse(args, "d", &size)) + if (!PyArg_ParseTuple(args, "d", &size)) return NULL; return newfhobject(fmscalefont(self->fh_fh, size)); } @@ -112,21 +112,21 @@ static PyObject * fh_getstrwidth(fhobject *self, PyObject *args) { char *str; - if (!PyArg_Parse(args, "s", &str)) + if (!PyArg_ParseTuple(args, "s", &str)) return NULL; return PyInt_FromLong(fmgetstrwidth(self->fh_fh, str)); } static PyMethodDef fh_methods[] = { - {"scalefont", (PyCFunction)fh_scalefont, METH_OLDARGS}, + {"scalefont", (PyCFunction)fh_scalefont, METH_VARARGS}, {"setfont", (PyCFunction)fh_setfont, METH_NOARGS}, {"getfontname", (PyCFunction)fh_getfontname, METH_NOARGS}, {"getcomment", (PyCFunction)fh_getcomment, METH_NOARGS}, {"getfontinfo", (PyCFunction)fh_getfontinfo, METH_NOARGS}, #if 0 - {"getwholemetrics", (PyCFunction)fh_getwholemetrics, METH_OLDARGS}, + {"getwholemetrics", (PyCFunction)fh_getwholemetrics, METH_VARARGS}, #endif - {"getstrwidth", (PyCFunction)fh_getstrwidth, METH_OLDARGS}, + {"getstrwidth", (PyCFunction)fh_getstrwidth, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; @@ -173,7 +173,7 @@ static PyObject * fm_findfont(PyObject *self, PyObject *args) { char *str; - if (!PyArg_Parse(args, "s", &str)) + if (!PyArg_ParseTuple(args, "s", &str)) return NULL; return newfhobject(fmfindfont(str)); } @@ -182,7 +182,7 @@ static PyObject * fm_prstr(PyObject *self, PyObject *args) { char *str; - if (!PyArg_Parse(args, "s", &str)) + if (!PyArg_ParseTuple(args, "s", &str)) return NULL; fmprstr(str); Py_INCREF(Py_None); @@ -230,7 +230,7 @@ static PyObject * fm_setpath(PyObject *self, PyObject *args) { char *str; - if (!PyArg_Parse(args, "s", &str)) + if (!PyArg_ParseTuple(args, "s", &str)) return NULL; fmsetpath(str); Py_INCREF(Py_None); @@ -245,10 +245,10 @@ fm_fontpath(PyObject *self) static PyMethodDef fm_methods[] = { {"init", fm_init, METH_NOARGS}, - {"findfont", fm_findfont, METH_OLDARGS}, + {"findfont", fm_findfont, METH_VARARGS}, {"enumerate", fm_enumerate, METH_NOARGS}, - {"prstr", fm_prstr, METH_OLDARGS}, - {"setpath", fm_setpath, METH_OLDARGS}, + {"prstr", fm_prstr, METH_VARARGS}, + {"setpath", fm_setpath, METH_VARARGS}, {"fontpath", fm_fontpath, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c index 76d54f820b1..cfc6abc37f5 100644 --- a/Modules/gdbmmodule.c +++ b/Modules/gdbmmodule.c @@ -189,10 +189,8 @@ PyDoc_STRVAR(dbm_close__doc__, Closes the database."); static PyObject * -dbm_close(register dbmobject *dp, PyObject *args) +dbm_close(register dbmobject *dp, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":close")) - return NULL; if (dp->di_dbm) gdbm_close(dp->di_dbm); dp->di_dbm = NULL; @@ -205,7 +203,7 @@ PyDoc_STRVAR(dbm_keys__doc__, Get a list of all keys in the database."); static PyObject * -dbm_keys(register dbmobject *dp, PyObject *args) +dbm_keys(register dbmobject *dp, PyObject *unused) { register PyObject *v, *item; datum key, nextkey; @@ -215,9 +213,6 @@ dbm_keys(register dbmobject *dp, PyObject *args) PyErr_BadInternalCall(); return NULL; } - if (!PyArg_ParseTuple(args, ":keys")) - return NULL; - check_dbmobject_open(dp); v = PyList_New(0); @@ -269,13 +264,11 @@ hash values, and won't be sorted by the key values. This method\n\ returns the starting key."); static PyObject * -dbm_firstkey(register dbmobject *dp, PyObject *args) +dbm_firstkey(register dbmobject *dp, PyObject *unused) { register PyObject *v; datum key; - if (!PyArg_ParseTuple(args, ":firstkey")) - return NULL; check_dbmobject_open(dp); key = gdbm_firstkey(dp->di_dbm); if (key.dptr) { @@ -330,10 +323,8 @@ by using this reorganization; otherwise, deleted file space will be\n\ kept and reused as new (key,value) pairs are added."); static PyObject * -dbm_reorganize(register dbmobject *dp, PyObject *args) +dbm_reorganize(register dbmobject *dp, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":reorganize")) - return NULL; check_dbmobject_open(dp); errno = 0; if (gdbm_reorganize(dp->di_dbm) < 0) { @@ -353,10 +344,8 @@ When the database has been opened in fast mode, this method forces\n\ any unwritten data to be written to the disk."); static PyObject * -dbm_sync(register dbmobject *dp, PyObject *args) +dbm_sync(register dbmobject *dp, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":sync")) - return NULL; check_dbmobject_open(dp); gdbm_sync(dp->di_dbm); Py_INCREF(Py_None); @@ -364,13 +353,13 @@ dbm_sync(register dbmobject *dp, PyObject *args) } static PyMethodDef dbm_methods[] = { - {"close", (PyCFunction)dbm_close, METH_VARARGS, dbm_close__doc__}, - {"keys", (PyCFunction)dbm_keys, METH_VARARGS, dbm_keys__doc__}, + {"close", (PyCFunction)dbm_close, METH_NOARGS, dbm_close__doc__}, + {"keys", (PyCFunction)dbm_keys, METH_NOARGS, dbm_keys__doc__}, {"has_key", (PyCFunction)dbm_has_key, METH_VARARGS, dbm_has_key__doc__}, - {"firstkey", (PyCFunction)dbm_firstkey,METH_VARARGS, dbm_firstkey__doc__}, + {"firstkey", (PyCFunction)dbm_firstkey,METH_NOARGS, dbm_firstkey__doc__}, {"nextkey", (PyCFunction)dbm_nextkey, METH_VARARGS, dbm_nextkey__doc__}, - {"reorganize",(PyCFunction)dbm_reorganize,METH_VARARGS, dbm_reorganize__doc__}, - {"sync", (PyCFunction)dbm_sync, METH_VARARGS, dbm_sync__doc__}, + {"reorganize",(PyCFunction)dbm_reorganize,METH_NOARGS, dbm_reorganize__doc__}, + {"sync", (PyCFunction)dbm_sync, METH_NOARGS, dbm_sync__doc__}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/linuxaudiodev.c b/Modules/linuxaudiodev.c index 769451af850..c1c7363c83b 100644 --- a/Modules/linuxaudiodev.c +++ b/Modules/linuxaudiodev.c @@ -219,24 +219,18 @@ lad_write(lad_t *self, PyObject *args) } static PyObject * -lad_close(lad_t *self, PyObject *args) +lad_close(lad_t *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":close")) - return NULL; - if (self->x_fd >= 0) { close(self->x_fd); self->x_fd = -1; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * -lad_fileno(lad_t *self, PyObject *args) +lad_fileno(lad_t *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":fileno")) - return NULL; return PyInt_FromLong(self->x_fd); } @@ -341,13 +335,11 @@ _ssize(lad_t *self, int *nchannels, int *ssize) /* bufsize returns the size of the hardware audio buffer in number of samples */ static PyObject * -lad_bufsize(lad_t *self, PyObject *args) +lad_bufsize(lad_t *self, PyObject *unused) { audio_buf_info ai; int nchannels=0, ssize=0; - if (!PyArg_ParseTuple(args, ":bufsize")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { PyErr_SetFromErrno(LinuxAudioError); return NULL; @@ -362,14 +354,11 @@ lad_bufsize(lad_t *self, PyObject *args) /* obufcount returns the number of samples that are available in the hardware for playing */ static PyObject * -lad_obufcount(lad_t *self, PyObject *args) +lad_obufcount(lad_t *self, PyObject *unused) { audio_buf_info ai; int nchannels=0, ssize=0; - if (!PyArg_ParseTuple(args, ":obufcount")) - return NULL; - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { PyErr_SetFromErrno(LinuxAudioError); return NULL; @@ -385,14 +374,11 @@ lad_obufcount(lad_t *self, PyObject *args) /* obufcount returns the number of samples that can be played without blocking */ static PyObject * -lad_obuffree(lad_t *self, PyObject *args) +lad_obuffree(lad_t *self, PyObject *unused) { audio_buf_info ai; int nchannels=0, ssize=0; - if (!PyArg_ParseTuple(args, ":obuffree")) - return NULL; - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { PyErr_SetFromErrno(LinuxAudioError); return NULL; @@ -406,27 +392,21 @@ lad_obuffree(lad_t *self, PyObject *args) /* Flush the device */ static PyObject * -lad_flush(lad_t *self, PyObject *args) +lad_flush(lad_t *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":flush")) return NULL; - if (ioctl(self->x_fd, SNDCTL_DSP_SYNC, NULL) == -1) { PyErr_SetFromErrno(LinuxAudioError); return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * -lad_getptr(lad_t *self, PyObject *args) +lad_getptr(lad_t *self, PyObject *unused) { count_info info; int req; - if (!PyArg_ParseTuple(args, ":getptr")) - return NULL; - if (self->x_mode == O_RDONLY) req = SNDCTL_DSP_GETIPTR; else @@ -443,12 +423,12 @@ static PyMethodDef lad_methods[] = { { "write", (PyCFunction)lad_write, METH_VARARGS }, { "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS }, { "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS }, - { "obufcount", (PyCFunction)lad_obufcount, METH_VARARGS }, - { "obuffree", (PyCFunction)lad_obuffree, METH_VARARGS }, - { "flush", (PyCFunction)lad_flush, METH_VARARGS }, - { "close", (PyCFunction)lad_close, METH_VARARGS }, - { "fileno", (PyCFunction)lad_fileno, METH_VARARGS }, - { "getptr", (PyCFunction)lad_getptr, METH_VARARGS }, + { "obufcount", (PyCFunction)lad_obufcount, METH_NOARGS }, + { "obuffree", (PyCFunction)lad_obuffree, METH_NOARGS }, + { "flush", (PyCFunction)lad_flush, METH_NOARGS }, + { "close", (PyCFunction)lad_close, METH_NOARGS }, + { "fileno", (PyCFunction)lad_fileno, METH_NOARGS }, + { "getptr", (PyCFunction)lad_getptr, METH_NOARGS }, { NULL, NULL} /* sentinel */ }; diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 2e34a9f7fd0..19970c9fb61 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -114,10 +114,8 @@ mmap_object_dealloc(mmap_object *m_obj) } static PyObject * -mmap_close_method(mmap_object *self, PyObject *args) +mmap_close_method(mmap_object *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":close")) - return NULL; #ifdef MS_WINDOWS /* For each resource we maintain, we need to check the value is valid, and if so, free the resource @@ -175,11 +173,9 @@ do { \ static PyObject * mmap_read_byte_method(mmap_object *self, - PyObject *args) + PyObject *unused) { CHECK_VALID(NULL); - if (!PyArg_ParseTuple(args, ":read_byte")) - return NULL; if (self->pos < self->size) { char value = self->data[self->pos]; self->pos += 1; @@ -192,7 +188,7 @@ mmap_read_byte_method(mmap_object *self, static PyObject * mmap_read_line_method(mmap_object *self, - PyObject *args) + PyObject *unused) { char *start = self->data+self->pos; char *eof = self->data+self->size; @@ -200,8 +196,6 @@ mmap_read_line_method(mmap_object *self, PyObject *result; CHECK_VALID(NULL); - if (!PyArg_ParseTuple(args, ":readline")) - return NULL; eol = memchr(start, '\n', self->size - self->pos); if (!eol) @@ -332,11 +326,9 @@ mmap_write_byte_method(mmap_object *self, static PyObject * mmap_size_method(mmap_object *self, - PyObject *args) + PyObject *unused) { CHECK_VALID(NULL); - if (!PyArg_ParseTuple(args, ":size")) - return NULL; #ifdef MS_WINDOWS if (self->file_handle != INVALID_HANDLE_VALUE) { @@ -472,12 +464,10 @@ mmap_resize_method(mmap_object *self, } static PyObject * -mmap_tell_method(mmap_object *self, PyObject *args) +mmap_tell_method(mmap_object *self, PyObject *unused) { CHECK_VALID(NULL); - if (!PyArg_ParseTuple(args, ":tell")) - return NULL; - return Py_BuildValue("l", (long) self->pos); + return PyInt_FromLong((long) self->pos); } static PyObject * @@ -493,7 +483,7 @@ mmap_flush_method(mmap_object *self, PyObject *args) return NULL; } else { #ifdef MS_WINDOWS - return Py_BuildValue("l", (long) + return PyInt_FromLong((long) FlushViewOfFile(self->data+offset, size)); #endif /* MS_WINDOWS */ #ifdef UNIX @@ -505,7 +495,7 @@ mmap_flush_method(mmap_object *self, PyObject *args) PyErr_SetFromErrno(mmap_module_error); return NULL; } - return Py_BuildValue("l", (long) 0); + return PyInt_FromLong(0); #endif /* UNIX */ } } @@ -578,17 +568,17 @@ mmap_move_method(mmap_object *self, PyObject *args) } static struct PyMethodDef mmap_object_methods[] = { - {"close", (PyCFunction) mmap_close_method, METH_VARARGS}, + {"close", (PyCFunction) mmap_close_method, METH_NOARGS}, {"find", (PyCFunction) mmap_find_method, METH_VARARGS}, {"flush", (PyCFunction) mmap_flush_method, METH_VARARGS}, {"move", (PyCFunction) mmap_move_method, METH_VARARGS}, {"read", (PyCFunction) mmap_read_method, METH_VARARGS}, - {"read_byte", (PyCFunction) mmap_read_byte_method, METH_VARARGS}, - {"readline", (PyCFunction) mmap_read_line_method, METH_VARARGS}, + {"read_byte", (PyCFunction) mmap_read_byte_method, METH_NOARGS}, + {"readline", (PyCFunction) mmap_read_line_method, METH_NOARGS}, {"resize", (PyCFunction) mmap_resize_method, METH_VARARGS}, {"seek", (PyCFunction) mmap_seek_method, METH_VARARGS}, - {"size", (PyCFunction) mmap_size_method, METH_VARARGS}, - {"tell", (PyCFunction) mmap_tell_method, METH_VARARGS}, + {"size", (PyCFunction) mmap_size_method, METH_NOARGS}, + {"tell", (PyCFunction) mmap_tell_method, METH_NOARGS}, {"write", (PyCFunction) mmap_write_method, METH_VARARGS}, {"write_byte", (PyCFunction) mmap_write_byte_method, METH_VARARGS}, {NULL, NULL} /* sentinel */ diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c index 563620cbea3..9716838ba23 100644 --- a/Modules/ossaudiodev.c +++ b/Modules/ossaudiodev.c @@ -296,12 +296,10 @@ _do_ioctl_0(int fd, PyObject *args, char *fname, int cmd) */ static PyObject * -oss_nonblock(oss_audio_t *self, PyObject *args) +oss_nonblock(oss_audio_t *self, PyObject *unused) { /* Hmmm: it doesn't appear to be possible to return to blocking mode once we're in non-blocking mode! */ - if (!PyArg_ParseTuple(args, ":nonblock")) - return NULL; if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); @@ -315,11 +313,9 @@ oss_setfmt(oss_audio_t *self, PyObject *args) } static PyObject * -oss_getfmts(oss_audio_t *self, PyObject *args) +oss_getfmts(oss_audio_t *self, PyObject *unused) { int mask; - if (!PyArg_ParseTuple(args, ":getfmts")) - return NULL; if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1) return PyErr_SetFromErrno(PyExc_IOError); return PyInt_FromLong(mask); @@ -459,11 +455,8 @@ oss_writeall(oss_audio_t *self, PyObject *args) } static PyObject * -oss_close(oss_audio_t *self, PyObject *args) +oss_close(oss_audio_t *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":close")) - return NULL; - if (self->fd >= 0) { Py_BEGIN_ALLOW_THREADS close(self->fd); @@ -475,10 +468,8 @@ oss_close(oss_audio_t *self, PyObject *args) } static PyObject * -oss_fileno(oss_audio_t *self, PyObject *args) +oss_fileno(oss_audio_t *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":fileno")) - return NULL; return PyInt_FromLong(self->fd); } @@ -578,13 +569,11 @@ _ssize(oss_audio_t *self, int *nchannels, int *ssize) /* bufsize returns the size of the hardware audio buffer in number of samples */ static PyObject * -oss_bufsize(oss_audio_t *self, PyObject *args) +oss_bufsize(oss_audio_t *self, PyObject *unused) { audio_buf_info ai; int nchannels=0, ssize=0; - if (!PyArg_ParseTuple(args, ":bufsize")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { PyErr_SetFromErrno(PyExc_IOError); return NULL; @@ -599,14 +588,11 @@ oss_bufsize(oss_audio_t *self, PyObject *args) /* obufcount returns the number of samples that are available in the hardware for playing */ static PyObject * -oss_obufcount(oss_audio_t *self, PyObject *args) +oss_obufcount(oss_audio_t *self, PyObject *unused) { audio_buf_info ai; int nchannels=0, ssize=0; - if (!PyArg_ParseTuple(args, ":obufcount")) - return NULL; - if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { PyErr_SetFromErrno(PyExc_IOError); return NULL; @@ -622,14 +608,11 @@ oss_obufcount(oss_audio_t *self, PyObject *args) /* obufcount returns the number of samples that can be played without blocking */ static PyObject * -oss_obuffree(oss_audio_t *self, PyObject *args) +oss_obuffree(oss_audio_t *self, PyObject *unused) { audio_buf_info ai; int nchannels=0, ssize=0; - if (!PyArg_ParseTuple(args, ":obuffree")) - return NULL; - if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { PyErr_SetFromErrno(PyExc_IOError); return NULL; @@ -642,14 +625,11 @@ oss_obuffree(oss_audio_t *self, PyObject *args) } static PyObject * -oss_getptr(oss_audio_t *self, PyObject *args) +oss_getptr(oss_audio_t *self, PyObject *unused) { count_info info; int req; - if (!PyArg_ParseTuple(args, ":getptr")) - return NULL; - if (self->mode == O_RDONLY) req = SNDCTL_DSP_GETIPTR; else @@ -667,11 +647,8 @@ oss_getptr(oss_audio_t *self, PyObject *args) */ static PyObject * -oss_mixer_close(oss_mixer_t *self, PyObject *args) +oss_mixer_close(oss_mixer_t *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":close")) - return NULL; - if (self->fd >= 0) { close(self->fd); self->fd = -1; @@ -681,10 +658,8 @@ oss_mixer_close(oss_mixer_t *self, PyObject *args) } static PyObject * -oss_mixer_fileno(oss_mixer_t *self, PyObject *args) +oss_mixer_fileno(oss_mixer_t *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":fileno")) - return NULL; return PyInt_FromLong(self->fd); } @@ -782,13 +757,13 @@ static PyMethodDef oss_methods[] = { { "read", (PyCFunction)oss_read, METH_VARARGS }, { "write", (PyCFunction)oss_write, METH_VARARGS }, { "writeall", (PyCFunction)oss_writeall, METH_VARARGS }, - { "close", (PyCFunction)oss_close, METH_VARARGS }, - { "fileno", (PyCFunction)oss_fileno, METH_VARARGS }, + { "close", (PyCFunction)oss_close, METH_NOARGS }, + { "fileno", (PyCFunction)oss_fileno, METH_NOARGS }, /* Simple ioctl wrappers */ - { "nonblock", (PyCFunction)oss_nonblock, METH_VARARGS }, + { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS }, { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS }, - { "getfmts", (PyCFunction)oss_getfmts, METH_VARARGS }, + { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS }, { "channels", (PyCFunction)oss_channels, METH_VARARGS }, { "speed", (PyCFunction)oss_speed, METH_VARARGS }, { "sync", (PyCFunction)oss_sync, METH_VARARGS }, @@ -797,10 +772,10 @@ static PyMethodDef oss_methods[] = { /* Convenience methods -- wrap a couple of ioctls together */ { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS }, - { "bufsize", (PyCFunction)oss_bufsize, METH_VARARGS }, - { "obufcount", (PyCFunction)oss_obufcount, METH_VARARGS }, - { "obuffree", (PyCFunction)oss_obuffree, METH_VARARGS }, - { "getptr", (PyCFunction)oss_getptr, METH_VARARGS }, + { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS }, + { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS }, + { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS }, + { "getptr", (PyCFunction)oss_getptr, METH_NOARGS }, /* Aliases for backwards compatibility */ { "flush", (PyCFunction)oss_sync, METH_VARARGS }, @@ -810,8 +785,8 @@ static PyMethodDef oss_methods[] = { static PyMethodDef oss_mixer_methods[] = { /* Regular file method - OSS mixers are ioctl-only interface */ - { "close", (PyCFunction)oss_mixer_close, METH_VARARGS }, - { "fileno", (PyCFunction)oss_mixer_fileno, METH_VARARGS }, + { "close", (PyCFunction)oss_mixer_close, METH_NOARGS }, + { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS }, /* Simple ioctl wrappers */ { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS }, diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7f0a2618efc..c0280de81e7 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5282,14 +5282,11 @@ PyDoc_STRVAR(posix_setgroups__doc__, Set the groups of the current process to list."); static PyObject * -posix_setgroups(PyObject *self, PyObject *args) +posix_setgroups(PyObject *self, PyObject *groups) { - PyObject *groups; int i, len; gid_t grouplist[MAX_GROUPS]; - if (!PyArg_ParseTuple(args, "O:setgid", &groups)) - return NULL; if (!PySequence_Check(groups)) { PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence"); return NULL; @@ -8020,7 +8017,7 @@ static PyMethodDef posix_methods[] = { {"setgid", posix_setgid, METH_VARARGS, posix_setgid__doc__}, #endif /* HAVE_SETGID */ #ifdef HAVE_SETGROUPS - {"setgroups", posix_setgroups, METH_VARARGS, posix_setgroups__doc__}, + {"setgroups", posix_setgroups, METH_O, posix_setgroups__doc__}, #endif /* HAVE_SETGROUPS */ #ifdef HAVE_GETPGID {"getpgid", posix_getpgid, METH_VARARGS, posix_getpgid__doc__}, diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index fe50e361f64..8a10babde3b 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -981,16 +981,12 @@ PyDoc_STRVAR(xmlparse_ParseFile__doc__, Parse XML data from file-like object."); static PyObject * -xmlparse_ParseFile(xmlparseobject *self, PyObject *args) +xmlparse_ParseFile(xmlparseobject *self, PyObject *f) { int rv = 1; - PyObject *f; FILE *fp; PyObject *readmethod = NULL; - if (!PyArg_ParseTuple(args, "O:ParseFile", &f)) - return NULL; - if (PyFile_Check(f)) { fp = PyFile_AsFile(f); } @@ -1062,11 +1058,8 @@ PyDoc_STRVAR(xmlparse_GetBase__doc__, Return base URL string for the parser."); static PyObject * -xmlparse_GetBase(xmlparseobject *self, PyObject *args) +xmlparse_GetBase(xmlparseobject *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":GetBase")) - return NULL; - return Py_BuildValue("z", XML_GetBase(self->itself)); } @@ -1077,29 +1070,21 @@ If the event was generated by a large amount of text (such as a start tag\n\ for an element with many attributes), not all of the text may be available."); static PyObject * -xmlparse_GetInputContext(xmlparseobject *self, PyObject *args) +xmlparse_GetInputContext(xmlparseobject *self, PyObject *unused) { - PyObject *result = NULL; + if (self->in_callback) { + int offset, size; + const char *buffer + = XML_GetInputContext(self->itself, &offset, &size); - if (PyArg_ParseTuple(args, ":GetInputContext")) { - if (self->in_callback) { - int offset, size; - const char *buffer - = XML_GetInputContext(self->itself, &offset, &size); - - if (buffer != NULL) - result = PyString_FromStringAndSize(buffer + offset, size - offset); - else { - result = Py_None; - Py_INCREF(result); - } - } - else { - result = Py_None; - Py_INCREF(result); - } + if (buffer != NULL) + return PyString_FromStringAndSize(buffer + offset, + size - offset); + else + Py_RETURN_NONE; } - return result; + else + Py_RETURN_NONE; } PyDoc_STRVAR(xmlparse_ExternalEntityParserCreate__doc__, @@ -1228,7 +1213,7 @@ xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) PyObject *flagobj = NULL; XML_Bool flag = XML_TRUE; enum XML_Error rc; - if (!PyArg_ParseTuple(args, "|O:UseForeignDTD", &flagobj)) + if (!PyArg_UnpackTuple(args, "UseForeignDTD", 0, 1, &flagobj)) return NULL; if (flagobj != NULL) flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE; @@ -1245,17 +1230,17 @@ static struct PyMethodDef xmlparse_methods[] = { {"Parse", (PyCFunction)xmlparse_Parse, METH_VARARGS, xmlparse_Parse__doc__}, {"ParseFile", (PyCFunction)xmlparse_ParseFile, - METH_VARARGS, xmlparse_ParseFile__doc__}, + METH_O, xmlparse_ParseFile__doc__}, {"SetBase", (PyCFunction)xmlparse_SetBase, METH_VARARGS, xmlparse_SetBase__doc__}, {"GetBase", (PyCFunction)xmlparse_GetBase, - METH_VARARGS, xmlparse_GetBase__doc__}, + METH_NOARGS, xmlparse_GetBase__doc__}, {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCreate, METH_VARARGS, xmlparse_ExternalEntityParserCreate__doc__}, {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing, METH_VARARGS, xmlparse_SetParamEntityParsing__doc__}, {"GetInputContext", (PyCFunction)xmlparse_GetInputContext, - METH_VARARGS, xmlparse_GetInputContext__doc__}, + METH_NOARGS, xmlparse_GetInputContext__doc__}, #if XML_COMBINED_VERSION >= 19505 {"UseForeignDTD", (PyCFunction)xmlparse_UseForeignDTD, METH_VARARGS, xmlparse_UseForeignDTD__doc__}, diff --git a/Modules/resource.c b/Modules/resource.c index e73c8781581..fe6f3b6a25f 100644 --- a/Modules/resource.c +++ b/Modules/resource.c @@ -194,12 +194,9 @@ resource_setrlimit(PyObject *self, PyObject *args) } static PyObject * -resource_getpagesize(PyObject *self, PyObject *args) +resource_getpagesize(PyObject *self, PyObject *unused) { long pagesize = 0; - if (!PyArg_ParseTuple(args, ":getpagesize")) - return NULL; - #if defined(HAVE_GETPAGESIZE) pagesize = getpagesize(); #elif defined(HAVE_SYSCONF) @@ -221,7 +218,7 @@ resource_methods[] = { {"getrusage", resource_getrusage, METH_VARARGS}, {"getrlimit", resource_getrlimit, METH_VARARGS}, {"setrlimit", resource_setrlimit, METH_VARARGS}, - {"getpagesize", resource_getpagesize, METH_VARARGS}, + {"getpagesize", resource_getpagesize, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 4a04af179c4..dfa4e85e3bd 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -218,7 +218,7 @@ select_select(PyObject *self, PyObject *args) int n; /* convert arguments */ - if (!PyArg_ParseTuple(args, "OOO|O:select", + if (!PyArg_UnpackTuple(args, "select", 3, 4, &ifdlist, &ofdlist, &efdlist, &tout)) return NULL; @@ -415,15 +415,11 @@ PyDoc_STRVAR(poll_unregister_doc, Remove a file descriptor being tracked by the polling object."); static PyObject * -poll_unregister(pollObject *self, PyObject *args) +poll_unregister(pollObject *self, PyObject *o) { - PyObject *o, *key; + PyObject *key; int fd; - if (!PyArg_ParseTuple(args, "O:unregister", &o)) { - return NULL; - } - fd = PyObject_AsFileDescriptor( o ); if (fd == -1) return NULL; @@ -459,7 +455,7 @@ poll_poll(pollObject *self, PyObject *args) int timeout = 0, poll_result, i, j; PyObject *value = NULL, *num = NULL; - if (!PyArg_ParseTuple(args, "|O:poll", &tout)) { + if (!PyArg_UnpackTuple(args, "poll", 0, 1, &tout)) { return NULL; } @@ -548,7 +544,7 @@ static PyMethodDef poll_methods[] = { {"register", (PyCFunction)poll_register, METH_VARARGS, poll_register_doc}, {"unregister", (PyCFunction)poll_unregister, - METH_VARARGS, poll_unregister_doc}, + METH_O, poll_unregister_doc}, {"poll", (PyCFunction)poll_poll, METH_VARARGS, poll_poll_doc}, {NULL, NULL} /* sentinel */ @@ -614,16 +610,9 @@ PyDoc_STRVAR(poll_doc, unregistering file descriptors, and then polling them for I/O events."); static PyObject * -select_poll(PyObject *self, PyObject *args) +select_poll(PyObject *self, PyObject *unused) { - pollObject *rv; - - if (!PyArg_ParseTuple(args, ":poll")) - return NULL; - rv = newPollObject(); - if ( rv == NULL ) - return NULL; - return (PyObject *)rv; + return (PyObject *)newPollObject(); } #ifdef __APPLE__ @@ -684,7 +673,7 @@ On Windows, only sockets are supported; on Unix, all file descriptors."); static PyMethodDef select_methods[] = { {"select", select_select, METH_VARARGS, select_doc}, #if defined(HAVE_POLL) - {"poll", select_poll, METH_VARARGS, poll_doc}, + {"poll", select_poll, METH_NOARGS, poll_doc}, #endif /* HAVE_POLL */ {0, 0}, /* sentinel */ }; diff --git a/Modules/sha256module.c b/Modules/sha256module.c index 7037ca0f58d..0effb0734c6 100644 --- a/Modules/sha256module.c +++ b/Modules/sha256module.c @@ -405,14 +405,10 @@ SHA_dealloc(PyObject *ptr) PyDoc_STRVAR(SHA256_copy__doc__, "Return a copy of the hash object."); static PyObject * -SHA256_copy(SHAobject *self, PyObject *args) +SHA256_copy(SHAobject *self, PyObject *unused) { SHAobject *newobj; - if (!PyArg_ParseTuple(args, ":copy")) { - return NULL; - } - if (((PyObject*)self)->ob_type == &SHA256type) { if ( (newobj = newSHA256object())==NULL) return NULL; @@ -429,14 +425,11 @@ PyDoc_STRVAR(SHA256_digest__doc__, "Return the digest value as a string of binary data."); static PyObject * -SHA256_digest(SHAobject *self, PyObject *args) +SHA256_digest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; - if (!PyArg_ParseTuple(args, ":digest")) - return NULL; - SHAcopy(self, &temp); sha_final(digest, &temp); return PyString_FromStringAndSize((const char *)digest, self->digestsize); @@ -446,7 +439,7 @@ PyDoc_STRVAR(SHA256_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); static PyObject * -SHA256_hexdigest(SHAobject *self, PyObject *args) +SHA256_hexdigest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -454,9 +447,6 @@ SHA256_hexdigest(SHAobject *self, PyObject *args) char *hex_digest; int i, j; - if (!PyArg_ParseTuple(args, ":hexdigest")) - return NULL; - /* Get the raw (binary) digest value */ SHAcopy(self, &temp); sha_final(digest, &temp); @@ -503,9 +493,9 @@ SHA256_update(SHAobject *self, PyObject *args) } static PyMethodDef SHA_methods[] = { - {"copy", (PyCFunction)SHA256_copy, METH_VARARGS, SHA256_copy__doc__}, - {"digest", (PyCFunction)SHA256_digest, METH_VARARGS, SHA256_digest__doc__}, - {"hexdigest", (PyCFunction)SHA256_hexdigest, METH_VARARGS, SHA256_hexdigest__doc__}, + {"copy", (PyCFunction)SHA256_copy, METH_NOARGS, SHA256_copy__doc__}, + {"digest", (PyCFunction)SHA256_digest, METH_NOARGS, SHA256_digest__doc__}, + {"hexdigest", (PyCFunction)SHA256_hexdigest, METH_NOARGS, SHA256_hexdigest__doc__}, {"update", (PyCFunction)SHA256_update, METH_VARARGS, SHA256_update__doc__}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/sha512module.c b/Modules/sha512module.c index c5a85ff5892..9f47b6128b8 100644 --- a/Modules/sha512module.c +++ b/Modules/sha512module.c @@ -471,14 +471,10 @@ SHA512_dealloc(PyObject *ptr) PyDoc_STRVAR(SHA512_copy__doc__, "Return a copy of the hash object."); static PyObject * -SHA512_copy(SHAobject *self, PyObject *args) +SHA512_copy(SHAobject *self, PyObject *unused) { SHAobject *newobj; - if (!PyArg_ParseTuple(args, ":copy")) { - return NULL; - } - if (((PyObject*)self)->ob_type == &SHA512type) { if ( (newobj = newSHA512object())==NULL) return NULL; @@ -495,14 +491,11 @@ PyDoc_STRVAR(SHA512_digest__doc__, "Return the digest value as a string of binary data."); static PyObject * -SHA512_digest(SHAobject *self, PyObject *args) +SHA512_digest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; - if (!PyArg_ParseTuple(args, ":digest")) - return NULL; - SHAcopy(self, &temp); sha512_final(digest, &temp); return PyString_FromStringAndSize((const char *)digest, self->digestsize); @@ -512,7 +505,7 @@ PyDoc_STRVAR(SHA512_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); static PyObject * -SHA512_hexdigest(SHAobject *self, PyObject *args) +SHA512_hexdigest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -520,9 +513,6 @@ SHA512_hexdigest(SHAobject *self, PyObject *args) char *hex_digest; int i, j; - if (!PyArg_ParseTuple(args, ":hexdigest")) - return NULL; - /* Get the raw (binary) digest value */ SHAcopy(self, &temp); sha512_final(digest, &temp); @@ -538,7 +528,7 @@ SHA512_hexdigest(SHAobject *self, PyObject *args) } /* Make hex version of the digest */ - for(i=j=0; idigestsize; i++) { + for (i=j=0; idigestsize; i++) { char c; c = (digest[i] >> 4) & 0xf; c = (c>9) ? c+'a'-10 : c + '0'; @@ -569,9 +559,9 @@ SHA512_update(SHAobject *self, PyObject *args) } static PyMethodDef SHA_methods[] = { - {"copy", (PyCFunction)SHA512_copy, METH_VARARGS, SHA512_copy__doc__}, - {"digest", (PyCFunction)SHA512_digest, METH_VARARGS, SHA512_digest__doc__}, - {"hexdigest", (PyCFunction)SHA512_hexdigest, METH_VARARGS, SHA512_hexdigest__doc__}, + {"copy", (PyCFunction)SHA512_copy, METH_NOARGS, SHA512_copy__doc__}, + {"digest", (PyCFunction)SHA512_digest, METH_NOARGS, SHA512_digest__doc__}, + {"hexdigest", (PyCFunction)SHA512_hexdigest, METH_NOARGS, SHA512_hexdigest__doc__}, {"update", (PyCFunction)SHA512_update, METH_VARARGS, SHA512_update__doc__}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/shamodule.c b/Modules/shamodule.c index 058391d565f..8d68d16eac6 100644 --- a/Modules/shamodule.c +++ b/Modules/shamodule.c @@ -358,13 +358,10 @@ SHA_dealloc(PyObject *ptr) PyDoc_STRVAR(SHA_copy__doc__, "Return a copy of the hashing object."); static PyObject * -SHA_copy(SHAobject *self, PyObject *args) +SHA_copy(SHAobject *self, PyObject *unused) { SHAobject *newobj; - if (!PyArg_ParseTuple(args, ":copy")) { - return NULL; - } if ( (newobj = newSHAobject())==NULL) return NULL; @@ -376,14 +373,11 @@ PyDoc_STRVAR(SHA_digest__doc__, "Return the digest value as a string of binary data."); static PyObject * -SHA_digest(SHAobject *self, PyObject *args) +SHA_digest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; - if (!PyArg_ParseTuple(args, ":digest")) - return NULL; - SHAcopy(self, &temp); sha_final(digest, &temp); return PyString_FromStringAndSize((const char *)digest, sizeof(digest)); @@ -393,7 +387,7 @@ PyDoc_STRVAR(SHA_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); static PyObject * -SHA_hexdigest(SHAobject *self, PyObject *args) +SHA_hexdigest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -401,9 +395,6 @@ SHA_hexdigest(SHAobject *self, PyObject *args) char *hex_digest; int i, j; - if (!PyArg_ParseTuple(args, ":hexdigest")) - return NULL; - /* Get the raw (binary) digest value */ SHAcopy(self, &temp); sha_final(digest, &temp); @@ -450,9 +441,9 @@ SHA_update(SHAobject *self, PyObject *args) } static PyMethodDef SHA_methods[] = { - {"copy", (PyCFunction)SHA_copy, METH_VARARGS, SHA_copy__doc__}, - {"digest", (PyCFunction)SHA_digest, METH_VARARGS, SHA_digest__doc__}, - {"hexdigest", (PyCFunction)SHA_hexdigest, METH_VARARGS, SHA_hexdigest__doc__}, + {"copy", (PyCFunction)SHA_copy, METH_NOARGS, SHA_copy__doc__}, + {"digest", (PyCFunction)SHA_digest, METH_NOARGS, SHA_digest__doc__}, + {"hexdigest", (PyCFunction)SHA_hexdigest, METH_NOARGS, SHA_hexdigest__doc__}, {"update", (PyCFunction)SHA_update, METH_VARARGS, SHA_update__doc__}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 164a5d12c54..847a1948b82 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2472,7 +2472,7 @@ sock_recvfrom_buf(PySocketSockObject *s, PyObject *args, PyObject* kwds) /* Return the number of bytes read and the address. Note that we do not do anything special here in the case that readlen < recvlen. */ - ret = PyTuple_Pack(2, PyInt_FromLong(readlen), addr); + ret = Py_BuildValue("lO", readlen, addr); finally: Py_XDECREF(addr); @@ -2889,12 +2889,10 @@ static PyTypeObject sock_type = { /*ARGSUSED*/ static PyObject * -socket_gethostname(PyObject *self, PyObject *args) +socket_gethostname(PyObject *self, PyObject *unused) { char buf[1024]; int res; - if (!PyArg_ParseTuple(args, ":gethostname")) - return NULL; Py_BEGIN_ALLOW_THREADS res = gethostname(buf, (int) sizeof buf - 1); Py_END_ALLOW_THREADS @@ -3986,13 +3984,13 @@ static PyMethodDef socket_methods[] = { {"gethostbyaddr", socket_gethostbyaddr, METH_VARARGS, gethostbyaddr_doc}, {"gethostname", socket_gethostname, - METH_VARARGS, gethostname_doc}, + METH_NOARGS, gethostname_doc}, {"getservbyname", socket_getservbyname, METH_VARARGS, getservbyname_doc}, {"getservbyport", socket_getservbyport, METH_VARARGS, getservbyport_doc}, {"getprotobyname", socket_getprotobyname, - METH_VARARGS,getprotobyname_doc}, + METH_VARARGS, getprotobyname_doc}, #ifndef NO_DUP {"fromfd", socket_fromfd, METH_VARARGS, fromfd_doc}, @@ -4364,8 +4362,8 @@ init_socket(void) PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO); #endif PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM); - PyModule_AddObject(m, "BDADDR_ANY", Py_BuildValue("s", "00:00:00:00:00:00")); - PyModule_AddObject(m, "BDADDR_LOCAL", Py_BuildValue("s", "00:00:00:FF:FF:FF")); + PyModule_AddStringConstant(m, "BDADDR_ANY", "00:00:00:00:00:00"); + PyModule_AddStringConstant(m, "BDADDR_LOCAL", "00:00:00:FF:FF:FF"); #endif #ifdef HAVE_NETPACKET_PACKET_H diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c index dd35923139a..4a77916942b 100644 --- a/Modules/syslogmodule.c +++ b/Modules/syslogmodule.c @@ -98,10 +98,8 @@ syslog_syslog(PyObject * self, PyObject * args) } static PyObject * -syslog_closelog(PyObject *self, PyObject *args) +syslog_closelog(PyObject *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":closelog")) - return NULL; closelog(); Py_XDECREF(S_ident_o); S_ident_o = NULL; @@ -146,7 +144,7 @@ syslog_log_upto(PyObject *self, PyObject *args) static PyMethodDef syslog_methods[] = { {"openlog", syslog_openlog, METH_VARARGS}, - {"closelog", syslog_closelog, METH_VARARGS}, + {"closelog", syslog_closelog, METH_NOARGS}, {"syslog", syslog_syslog, METH_VARARGS}, {"setlogmask", syslog_setlogmask, METH_VARARGS}, {"LOG_MASK", syslog_log_mask, METH_VARARGS}, diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c index 9ac9881d9c1..6169658f93f 100644 --- a/Modules/threadmodule.c +++ b/Modules/threadmodule.c @@ -456,7 +456,8 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) struct bootstate *boot; long ident; - if (!PyArg_ParseTuple(fargs, "OO|O:start_new_thread", &func, &args, &keyw)) + if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3, + &func, &args, &keyw)) return NULL; if (!PyCallable_Check(func)) { PyErr_SetString(PyExc_TypeError, diff --git a/Modules/timemodule.c b/Modules/timemodule.c index e03b7e13917..87e543f788e 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -123,11 +123,9 @@ _PyTime_DoubleToTimet(double x) } static PyObject * -time_time(PyObject *self, PyObject *args) +time_time(PyObject *self, PyObject *unused) { double secs; - if (!PyArg_ParseTuple(args, ":time")) - return NULL; secs = floattime(); if (secs == 0.0) { PyErr_SetFromErrno(PyExc_IOError); @@ -153,10 +151,8 @@ Fractions of a second may be present if the system clock provides them."); #endif static PyObject * -time_clock(PyObject *self, PyObject *args) +time_clock(PyObject *self, PyObject *unused) { - if (!PyArg_ParseTuple(args, ":clock")) - return NULL; return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC); } #endif /* HAVE_CLOCK */ @@ -164,16 +160,13 @@ time_clock(PyObject *self, PyObject *args) #if defined(MS_WINDOWS) && !defined(__BORLANDC__) /* Due to Mark Hammond and Tim Peters */ static PyObject * -time_clock(PyObject *self, PyObject *args) +time_clock(PyObject *self, PyObject *unused) { static LARGE_INTEGER ctrStart; static double divisor = 0.0; LARGE_INTEGER now; double diff; - if (!PyArg_ParseTuple(args, ":clock")) - return NULL; - if (divisor == 0.0) { LARGE_INTEGER freq; QueryPerformanceCounter(&ctrStart); @@ -509,7 +502,7 @@ time_asctime(PyObject *self, PyObject *args) PyObject *tup = NULL; struct tm buf; char *p; - if (!PyArg_ParseTuple(args, "|O:asctime", &tup)) + if (!PyArg_UnpackTuple(args, "asctime", 0, 1, &tup)) return NULL; if (tup == NULL) { time_t tt = time(NULL); @@ -536,7 +529,7 @@ time_ctime(PyObject *self, PyObject *args) time_t tt; char *p; - if (!PyArg_ParseTuple(args, "|O:ctime", &ot)) + if (!PyArg_UnpackTuple(args, "ctime", 0, 1, &ot)) return NULL; if (ot == NULL || ot == Py_None) tt = time(NULL); @@ -567,13 +560,10 @@ not present, current time as returned by localtime() is used."); #ifdef HAVE_MKTIME static PyObject * -time_mktime(PyObject *self, PyObject *args) +time_mktime(PyObject *self, PyObject *tup) { - PyObject *tup; struct tm buf; time_t tt; - if (!PyArg_ParseTuple(args, "O:mktime", &tup)) - return NULL; tt = time(&tt); buf = *localtime(&tt); if (!gettmarg(tup, &buf)) @@ -597,13 +587,10 @@ Convert a time tuple in local time to seconds since the Epoch."); void inittimezone(PyObject *module); static PyObject * -time_tzset(PyObject *self, PyObject *args) +time_tzset(PyObject *self, PyObject *unused) { PyObject* m; - if (!PyArg_ParseTuple(args, ":tzset")) - return NULL; - m = PyImport_ImportModule("time"); if (m == NULL) { return NULL; @@ -722,9 +709,9 @@ void inittimezone(PyObject *m) { static PyMethodDef time_methods[] = { - {"time", time_time, METH_VARARGS, time_doc}, + {"time", time_time, METH_NOARGS, time_doc}, #ifdef HAVE_CLOCK - {"clock", time_clock, METH_VARARGS, clock_doc}, + {"clock", time_clock, METH_NOARGS, clock_doc}, #endif {"sleep", time_sleep, METH_VARARGS, sleep_doc}, {"gmtime", time_gmtime, METH_VARARGS, gmtime_doc}, @@ -732,14 +719,14 @@ static PyMethodDef time_methods[] = { {"asctime", time_asctime, METH_VARARGS, asctime_doc}, {"ctime", time_ctime, METH_VARARGS, ctime_doc}, #ifdef HAVE_MKTIME - {"mktime", time_mktime, METH_VARARGS, mktime_doc}, + {"mktime", time_mktime, METH_O, mktime_doc}, #endif #ifdef HAVE_STRFTIME {"strftime", time_strftime, METH_VARARGS, strftime_doc}, #endif {"strptime", time_strptime, METH_VARARGS, strptime_doc}, #ifdef HAVE_WORKING_TZSET - {"tzset", time_tzset, METH_VARARGS, tzset_doc}, + {"tzset", time_tzset, METH_NOARGS, tzset_doc}, #endif {NULL, NULL} /* sentinel */ }; diff --git a/Objects/classobject.c b/Objects/classobject.c index 9cfdf0e8460..79656f56dfd 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -1136,9 +1136,9 @@ instance_ass_item(PyInstanceObject *inst, Py_ssize_t i, PyObject *item) if (func == NULL) return -1; if (item == NULL) - arg = Py_BuildValue("i", i); + arg = PyInt_FromSsize_t(i); else - arg = Py_BuildValue("(iO)", i, item); + arg = Py_BuildValue("(nO)", i, item); if (arg == NULL) { Py_DECREF(func); return -1; diff --git a/Objects/complexobject.c b/Objects/complexobject.c index c6021e903c8..d1217df052e 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -188,7 +188,7 @@ complex_subtype_from_c_complex(PyTypeObject *type, Py_complex cval) { PyObject *op; - op = PyType_GenericAlloc(type, 0); + op = type->tp_alloc(type, 0); if (op != NULL) ((PyComplexObject *)op)->cval = cval; return op; @@ -1000,7 +1000,7 @@ PyTypeObject PyComplex_Type = { 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ - 0, /* tp_alloc */ + PyType_GenericAlloc, /* tp_alloc */ complex_new, /* tp_new */ PyObject_Del, /* tp_free */ }; diff --git a/Objects/dictobject.c b/Objects/dictobject.c index f5799ee09ff..f9e45fd8624 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -110,6 +110,16 @@ above, and then shifting perturb can be done while the table index is being masked); and the dictobject struct required a member to hold the table's polynomial. In Tim's experiments the current scheme ran faster, produced equally good collision statistics, needed less code & used less memory. + +Theoretical Python 2.5 headache: hash codes are only C "long", but +sizeof(Py_ssize_t) > sizeof(long) may be possible. In that case, and if a +dict is genuinely huge, then only the slots directly reachable via indexing +by a C long can be the first slot in a probe sequence. The probe sequence +will still eventually reach every slot in the table, but the collision rate +on initial probes may be much higher than this scheme was designed for. +Getting a hash code as fat as Py_ssize_t is the only real cure. But in +practice, this probably won't make a lick of difference for many years (at +which point everyone will have terabytes of RAM on 64-bit boxes). */ /* Object used as dummy key to fill deleted entries */ @@ -217,49 +227,43 @@ All arithmetic on hash should ignore overflow. contributions by Reimer Behrends, Jyrki Alakuijala, Vladimir Marangozov and Christian Tismer). -This function must never return NULL; failures are indicated by returning -a dictentry* for which the me_value field is NULL. Exceptions are never -reported by this function, and outstanding exceptions are maintained. +lookdict() is general-purpose, and may return NULL if (and only if) a +comparison raises an exception (this was new in Python 2.5). +lookdict_string() below is specialized to string keys, comparison of which can +never raise an exception; that function can never return NULL. For both, when +the key isn't found a dictentry* is returned for which the me_value field is +NULL; this is the slot in the dict at which the key would have been found, and +the caller can (if it wishes) add the pair to the returned +dictentry*. */ - static dictentry * lookdict(dictobject *mp, PyObject *key, register long hash) { - register Py_ssize_t i; + register size_t i; register size_t perturb; register dictentry *freeslot; - register unsigned int mask = mp->ma_mask; + register size_t mask = (size_t)mp->ma_mask; dictentry *ep0 = mp->ma_table; register dictentry *ep; - register int restore_error; - register int checked_error; register int cmp; - PyObject *err_type, *err_value, *err_tb; PyObject *startkey; - i = hash & mask; + i = (size_t)hash & mask; ep = &ep0[i]; if (ep->me_key == NULL || ep->me_key == key) return ep; - restore_error = checked_error = 0; if (ep->me_key == dummy) freeslot = ep; else { if (ep->me_hash == hash) { - /* error can't have been checked yet */ - checked_error = 1; - if (PyErr_Occurred()) { - restore_error = 1; - PyErr_Fetch(&err_type, &err_value, &err_tb); - } startkey = ep->me_key; cmp = PyObject_RichCompareBool(startkey, key, Py_EQ); if (cmp < 0) - PyErr_Clear(); + return NULL; if (ep0 == mp->ma_table && ep->me_key == startkey) { if (cmp > 0) - goto Done; + return ep; } else { /* The compare did major nasty stuff to the @@ -267,8 +271,7 @@ lookdict(dictobject *mp, PyObject *key, register long hash) * XXX A clever adversary could prevent this * XXX from terminating. */ - ep = lookdict(mp, key, hash); - goto Done; + return lookdict(mp, key, hash); } } freeslot = NULL; @@ -279,29 +282,18 @@ lookdict(dictobject *mp, PyObject *key, register long hash) for (perturb = hash; ; perturb >>= PERTURB_SHIFT) { i = (i << 2) + i + perturb + 1; ep = &ep0[i & mask]; - if (ep->me_key == NULL) { - if (freeslot != NULL) - ep = freeslot; - break; - } + if (ep->me_key == NULL) + return freeslot == NULL ? ep : freeslot; if (ep->me_key == key) - break; + return ep; if (ep->me_hash == hash && ep->me_key != dummy) { - if (!checked_error) { - checked_error = 1; - if (PyErr_Occurred()) { - restore_error = 1; - PyErr_Fetch(&err_type, &err_value, - &err_tb); - } - } startkey = ep->me_key; cmp = PyObject_RichCompareBool(startkey, key, Py_EQ); if (cmp < 0) - PyErr_Clear(); + return NULL; if (ep0 == mp->ma_table && ep->me_key == startkey) { if (cmp > 0) - break; + return ep; } else { /* The compare did major nasty stuff to the @@ -309,37 +301,30 @@ lookdict(dictobject *mp, PyObject *key, register long hash) * XXX A clever adversary could prevent this * XXX from terminating. */ - ep = lookdict(mp, key, hash); - break; + return lookdict(mp, key, hash); } } else if (ep->me_key == dummy && freeslot == NULL) freeslot = ep; } - -Done: - if (restore_error) - PyErr_Restore(err_type, err_value, err_tb); - return ep; } /* * Hacked up version of lookdict which can assume keys are always strings; - * this assumption allows testing for errors during PyObject_Compare() to - * be dropped; string-string comparisons never raise exceptions. This also - * means we don't need to go through PyObject_Compare(); we can always use - * _PyString_Eq directly. + * this assumption allows testing for errors during PyObject_RichCompareBool() + * to be dropped; string-string comparisons never raise exceptions. This also + * means we don't need to go through PyObject_RichCompareBool(); we can always + * use _PyString_Eq() directly. * - * This is valuable because the general-case error handling in lookdict() is - * expensive, and dicts with pure-string keys are very common. + * This is valuable because dicts with only string keys are very common. */ static dictentry * lookdict_string(dictobject *mp, PyObject *key, register long hash) { - register Py_ssize_t i; + register size_t i; register size_t perturb; register dictentry *freeslot; - register unsigned int mask = mp->ma_mask; + register size_t mask = (size_t)mp->ma_mask; dictentry *ep0 = mp->ma_table; register dictentry *ep; @@ -361,10 +346,8 @@ lookdict_string(dictobject *mp, PyObject *key, register long hash) if (ep->me_key == dummy) freeslot = ep; else { - if (ep->me_hash == hash - && _PyString_Eq(ep->me_key, key)) { + if (ep->me_hash == hash && _PyString_Eq(ep->me_key, key)) return ep; - } freeslot = NULL; } @@ -389,8 +372,9 @@ lookdict_string(dictobject *mp, PyObject *key, register long hash) Internal routine to insert a new item into the table. Used both by the internal resize routine and by the public insert routine. Eats a reference to key and one to value. +Returns -1 if an error occurred, or 0 on success. */ -static void +static int insertdict(register dictobject *mp, PyObject *key, long hash, PyObject *value) { PyObject *old_value; @@ -399,6 +383,11 @@ insertdict(register dictobject *mp, PyObject *key, long hash, PyObject *value) assert(mp->ma_lookup != NULL); ep = mp->ma_lookup(mp, key, hash); + if (ep == NULL) { + Py_DECREF(key); + Py_DECREF(value); + return -1; + } if (ep->me_value != NULL) { old_value = ep->me_value; ep->me_value = value; @@ -413,10 +402,43 @@ insertdict(register dictobject *mp, PyObject *key, long hash, PyObject *value) Py_DECREF(dummy); } ep->me_key = key; - ep->me_hash = hash; + ep->me_hash = (Py_ssize_t)hash; ep->me_value = value; mp->ma_used++; } + return 0; +} + +/* +Internal routine used by dictresize() to insert an item which is +known to be absent from the dict. This routine also assumes that +the dict contains no deleted entries. Besides the performance benefit, +using insertdict() in dictresize() is dangerous (SF bug #1456209). +Note that no refcounts are changed by this routine; if needed, the caller +is responsible for incref'ing `key` and `value`. +*/ +static void +insertdict_clean(register dictobject *mp, PyObject *key, long hash, + PyObject *value) +{ + register size_t i; + register size_t perturb; + register size_t mask = (size_t)mp->ma_mask; + dictentry *ep0 = mp->ma_table; + register dictentry *ep; + + i = hash & mask; + ep = &ep0[i]; + for (perturb = hash; ep->me_key != NULL; perturb >>= PERTURB_SHIFT) { + i = (i << 2) + i + perturb + 1; + ep = &ep0[i & mask]; + } + assert(ep->me_value == NULL); + mp->ma_fill++; + ep->me_key = key; + ep->me_hash = (Py_ssize_t)hash; + ep->me_value = value; + mp->ma_used++; } /* @@ -425,11 +447,11 @@ items again. When entries have been deleted, the new table may actually be smaller than the old one. */ static int -dictresize(dictobject *mp, int minused) +dictresize(dictobject *mp, Py_ssize_t minused) { - int newsize; + Py_ssize_t newsize; dictentry *oldtable, *newtable, *ep; - int i; + Py_ssize_t i; int is_oldtable_malloced; dictentry small_copy[PyDict_MINSIZE]; @@ -491,7 +513,8 @@ dictresize(dictobject *mp, int minused) for (ep = oldtable; i > 0; ep++) { if (ep->me_value != NULL) { /* active entry */ --i; - insertdict(mp, ep->me_key, ep->me_hash, ep->me_value); + insertdict_clean(mp, ep->me_key, (long)ep->me_hash, + ep->me_value); } else if (ep->me_key != NULL) { /* dummy entry */ --i; @@ -506,14 +529,25 @@ dictresize(dictobject *mp, int minused) return 0; } +/* Note that, for historical reasons, PyDict_GetItem() suppresses all errors + * that may occur (originally dicts supported only string keys, and exceptions + * weren't possible). So, while the original intent was that a NULL return + * meant the key wasn't present, it reality it can mean that, or that an error + * (suppressed) occurred while computing the key's hash, or that some error + * (suppressed) occurred when comparing keys in the dict's internal probe + * sequence. A nasty example of the latter is when a Python-coded comparison + * function hits a stack-depth error, which can cause this to return NULL + * even if the key is present. + */ PyObject * PyDict_GetItem(PyObject *op, PyObject *key) { long hash; dictobject *mp = (dictobject *)op; - if (!PyDict_Check(op)) { + dictentry *ep; + PyThreadState *tstate; + if (!PyDict_Check(op)) return NULL; - } if (!PyString_CheckExact(key) || (hash = ((PyStringObject *) key)->ob_shash) == -1) { @@ -523,7 +557,29 @@ PyDict_GetItem(PyObject *op, PyObject *key) return NULL; } } - return (mp->ma_lookup)(mp, key, hash)->me_value; + + /* We can arrive here with a NULL tstate during initialization: + try running "python -Wi" for an example related to string + interning. Let's just hope that no exception occurs then... */ + tstate = PyThreadState_GET(); + if (tstate != NULL && tstate->curexc_type != NULL) { + /* preserve the existing exception */ + PyObject *err_type, *err_value, *err_tb; + PyErr_Fetch(&err_type, &err_value, &err_tb); + ep = (mp->ma_lookup)(mp, key, hash); + /* ignore errors */ + PyErr_Restore(err_type, err_value, err_tb); + if (ep == NULL) + return NULL; + } + else { + ep = (mp->ma_lookup)(mp, key, hash); + if (ep == NULL) { + PyErr_Clear(); + return NULL; + } + } + return ep->me_value; } /* CAUTION: PyDict_SetItem() must guarantee that it won't resize the @@ -537,7 +593,7 @@ PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value) { register dictobject *mp; register long hash; - register int n_used; + register Py_ssize_t n_used; if (!PyDict_Check(op)) { PyErr_BadInternalCall(); @@ -558,7 +614,8 @@ PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value) n_used = mp->ma_used; Py_INCREF(value); Py_INCREF(key); - insertdict(mp, key, hash, value); + if (insertdict(mp, key, hash, value) != 0) + return -1; /* If we added a key, we can safely resize. Otherwise just return! * If fill >= 2/3 size, adjust size. Normally, this doubles or * quaduples the size, but it's also possible for the dict to shrink @@ -575,7 +632,7 @@ PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value) */ if (!(mp->ma_used > n_used && mp->ma_fill*3 >= (mp->ma_mask+1)*2)) return 0; - return dictresize(mp, (mp->ma_used>50000 ? mp->ma_used*2 : mp->ma_used*4)); + return dictresize(mp, (mp->ma_used > 50000 ? 2 : 4) * mp->ma_used); } int @@ -598,6 +655,8 @@ PyDict_DelItem(PyObject *op, PyObject *key) } mp = (dictobject *)op; ep = (mp->ma_lookup)(mp, key, hash); + if (ep == NULL) + return -1; if (ep->me_value == NULL) { PyErr_SetObject(PyExc_KeyError, key); return -1; @@ -619,10 +678,10 @@ PyDict_Clear(PyObject *op) dictobject *mp; dictentry *ep, *table; int table_is_malloced; - int fill; + Py_ssize_t fill; dictentry small_copy[PyDict_MINSIZE]; #ifdef Py_DEBUG - int i, n; + Py_ssize_t i, n; #endif if (!PyDict_Check(op)) @@ -685,7 +744,7 @@ PyDict_Clear(PyObject *op) /* * Iterate over a dict. Use like so: * - * int i; + * Py_ssize_t i; * PyObject *key, *value; * i = 0; # important! i should not otherwise be changed by you * while (PyDict_Next(yourdict, &i, &key, &value)) { @@ -701,7 +760,7 @@ int PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue) { register Py_ssize_t i; - register int mask; + register Py_ssize_t mask; register dictentry *ep; if (!PyDict_Check(op)) @@ -729,7 +788,7 @@ static void dict_dealloc(register dictobject *mp) { register dictentry *ep; - int fill = mp->ma_fill; + Py_ssize_t fill = mp->ma_fill; PyObject_GC_UnTrack(mp); Py_TRASHCAN_SAFE_BEGIN(mp) for (ep = mp->ma_table; fill > 0; ep++) { @@ -751,13 +810,14 @@ dict_dealloc(register dictobject *mp) static int dict_print(register dictobject *mp, register FILE *fp, register int flags) { - register int i; - register int any; + register Py_ssize_t i; + register Py_ssize_t any; + int status; - i = Py_ReprEnter((PyObject*)mp); - if (i != 0) { - if (i < 0) - return i; + status = Py_ReprEnter((PyObject*)mp); + if (status != 0) { + if (status < 0) + return status; fprintf(fp, "{...}"); return 0; } @@ -882,6 +942,7 @@ dict_subscript(dictobject *mp, register PyObject *key) { PyObject *v; long hash; + dictentry *ep; assert(mp->ma_table != NULL); if (!PyString_CheckExact(key) || (hash = ((PyStringObject *) key)->ob_shash) == -1) { @@ -889,14 +950,17 @@ dict_subscript(dictobject *mp, register PyObject *key) if (hash == -1) return NULL; } - v = (mp->ma_lookup)(mp, key, hash) -> me_value; + ep = (mp->ma_lookup)(mp, key, hash); + if (ep == NULL) + return NULL; + v = ep->me_value; if (v == NULL) { if (!PyDict_CheckExact(mp)) { /* Look up __missing__ method if we're a subclass. */ PyObject *missing; static PyObject *missing_str = NULL; if (missing_str == NULL) - missing_str = + missing_str = PyString_InternFromString("__missing__"); missing = _PyType_Lookup(mp->ob_type, missing_str); if (missing != NULL) @@ -930,9 +994,9 @@ static PyObject * dict_keys(register dictobject *mp) { register PyObject *v; - register int i, j; + register Py_ssize_t i, j; dictentry *ep; - int mask, n; + Py_ssize_t mask, n; again: n = mp->ma_used; @@ -964,9 +1028,9 @@ static PyObject * dict_values(register dictobject *mp) { register PyObject *v; - register int i, j; + register Py_ssize_t i, j; dictentry *ep; - int mask, n; + Py_ssize_t mask, n; again: n = mp->ma_used; @@ -998,8 +1062,8 @@ static PyObject * dict_items(register dictobject *mp) { register PyObject *v; - register int i, j, n; - int mask; + register Py_ssize_t i, j, n; + Py_ssize_t mask; PyObject *item, *key, *value; dictentry *ep; @@ -1132,7 +1196,7 @@ int PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override) { PyObject *it; /* iter(seq2) */ - int i; /* index into seq2 of current element */ + Py_ssize_t i; /* index into seq2 of current element */ PyObject *item; /* seq2[i] */ PyObject *fast; /* item as a 2-tuple or 2-list */ @@ -1162,14 +1226,14 @@ PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override) if (PyErr_ExceptionMatches(PyExc_TypeError)) PyErr_Format(PyExc_TypeError, "cannot convert dictionary update " - "sequence element #%d to a sequence", + "sequence element #%zd to a sequence", i); goto Fail; } n = PySequence_Fast_GET_SIZE(fast); if (n != 2) { PyErr_Format(PyExc_ValueError, - "dictionary update sequence element #%d " + "dictionary update sequence element #%zd " "has length %zd; 2 is required", i, n); goto Fail; @@ -1195,7 +1259,7 @@ Fail: i = -1; Return: Py_DECREF(it); - return i; + return Py_SAFE_DOWNCAST(i, Py_ssize_t, int); } int @@ -1208,7 +1272,7 @@ int PyDict_Merge(PyObject *a, PyObject *b, int override) { register PyDictObject *mp, *other; - register int i; + register Py_ssize_t i; dictentry *entry; /* We accept for the argument either a concrete dictionary object, @@ -1247,8 +1311,10 @@ PyDict_Merge(PyObject *a, PyObject *b, int override) PyDict_GetItem(a, entry->me_key) == NULL)) { Py_INCREF(entry->me_key); Py_INCREF(entry->me_value); - insertdict(mp, entry->me_key, entry->me_hash, - entry->me_value); + if (insertdict(mp, entry->me_key, + (long)entry->me_hash, + entry->me_value) != 0) + return -1; } } } @@ -1376,7 +1442,8 @@ characterize(dictobject *a, dictobject *b, PyObject **pval) { PyObject *akey = NULL; /* smallest key in a s.t. a[akey] != b[akey] */ PyObject *aval = NULL; /* a[akey] */ - int i, cmp; + Py_ssize_t i; + int cmp; for (i = 0; i <= a->ma_mask; i++) { PyObject *thiskey, *thisaval, *thisbval; @@ -1499,7 +1566,7 @@ Finished: static int dict_equal(dictobject *a, dictobject *b) { - int i; + Py_ssize_t i; if (a->ma_used != b->ma_used) /* can't be equal if # of entries differ */ @@ -1554,15 +1621,18 @@ static PyObject * dict_has_key(register dictobject *mp, PyObject *key) { long hash; - register long ok; + dictentry *ep; + if (!PyString_CheckExact(key) || (hash = ((PyStringObject *) key)->ob_shash) == -1) { hash = PyObject_Hash(key); if (hash == -1) return NULL; } - ok = (mp->ma_lookup)(mp, key, hash)->me_value != NULL; - return PyBool_FromLong(ok); + ep = (mp->ma_lookup)(mp, key, hash); + if (ep == NULL) + return NULL; + return PyBool_FromLong(ep->me_value != NULL); } static PyObject * @@ -1572,6 +1642,7 @@ dict_get(register dictobject *mp, PyObject *args) PyObject *failobj = Py_None; PyObject *val = NULL; long hash; + dictentry *ep; if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj)) return NULL; @@ -1582,8 +1653,10 @@ dict_get(register dictobject *mp, PyObject *args) if (hash == -1) return NULL; } - val = (mp->ma_lookup)(mp, key, hash)->me_value; - + ep = (mp->ma_lookup)(mp, key, hash); + if (ep == NULL) + return NULL; + val = ep->me_value; if (val == NULL) val = failobj; Py_INCREF(val); @@ -1598,6 +1671,7 @@ dict_setdefault(register dictobject *mp, PyObject *args) PyObject *failobj = Py_None; PyObject *val = NULL; long hash; + dictentry *ep; if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj)) return NULL; @@ -1608,7 +1682,10 @@ dict_setdefault(register dictobject *mp, PyObject *args) if (hash == -1) return NULL; } - val = (mp->ma_lookup)(mp, key, hash)->me_value; + ep = (mp->ma_lookup)(mp, key, hash); + if (ep == NULL) + return NULL; + val = ep->me_value; if (val == NULL) { val = failobj; if (PyDict_SetItem((PyObject*)mp, key, failobj)) @@ -1652,6 +1729,8 @@ dict_pop(dictobject *mp, PyObject *args) return NULL; } ep = (mp->ma_lookup)(mp, key, hash); + if (ep == NULL) + return NULL; if (ep->me_value == NULL) { if (deflt) { Py_INCREF(deflt); @@ -1673,7 +1752,7 @@ dict_pop(dictobject *mp, PyObject *args) static PyObject * dict_popitem(dictobject *mp) { - int i = 0; + Py_ssize_t i = 0; dictentry *ep; PyObject *res; @@ -1683,7 +1762,7 @@ dict_popitem(dictobject *mp) * happened, the result would be an infinite loop (searching for an * entry that no longer exists). Note that the usual popitem() * idiom is "while d: k, v = d.popitem()". so needing to throw the - * tuple away if the dict *is* empty isn't a significant + * tuple away if the dict *is* empty isn't a significant * inefficiency -- possible, but unlikely in practice. */ res = PyTuple_New(2); @@ -1703,7 +1782,7 @@ dict_popitem(dictobject *mp) */ ep = &mp->ma_table[0]; if (ep->me_value == NULL) { - i = (int)ep->me_hash; + i = ep->me_hash; /* The hash field may be a real hash value, or it may be a * legit search finger, or it may be a once-legit search * finger that's out of bounds now because it wrapped around @@ -1866,11 +1945,13 @@ static PyMethodDef mapp_methods[] = { {NULL, NULL} /* sentinel */ }; +/* Return 1 if `key` is in dict `op`, 0 if not, and -1 on error. */ int PyDict_Contains(PyObject *op, PyObject *key) { long hash; dictobject *mp = (dictobject *)op; + dictentry *ep; if (!PyString_CheckExact(key) || (hash = ((PyStringObject *) key)->ob_shash) == -1) { @@ -1878,7 +1959,8 @@ PyDict_Contains(PyObject *op, PyObject *key) if (hash == -1) return -1; } - return (mp->ma_lookup)(mp, key, hash)->me_value != NULL; + ep = (mp->ma_lookup)(mp, key, hash); + return ep == NULL ? -1 : (ep->me_value != NULL); } /* Hack to implement "key in dict" */ @@ -2035,10 +2117,10 @@ PyDict_DelItemString(PyObject *v, const char *key) typedef struct { PyObject_HEAD dictobject *di_dict; /* Set to NULL when iterator is exhausted */ - int di_used; - int di_pos; + Py_ssize_t di_used; + Py_ssize_t di_pos; PyObject* di_result; /* reusable result tuple for iteritems */ - long len; + Py_ssize_t len; } dictiterobject; static PyObject * @@ -2076,10 +2158,10 @@ dictiter_dealloc(dictiterobject *di) static PyObject * dictiter_len(dictiterobject *di) { - long len = 0; + Py_ssize_t len = 0; if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used) len = di->len; - return PyInt_FromLong(len); + return PyInt_FromSize_t(len); } PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); @@ -2092,7 +2174,7 @@ static PyMethodDef dictiter_methods[] = { static PyObject *dictiter_iternextkey(dictiterobject *di) { PyObject *key; - register int i, mask; + register Py_ssize_t i, mask; register dictentry *ep; dictobject *d = di->di_dict; @@ -2165,7 +2247,7 @@ PyTypeObject PyDictIterKey_Type = { static PyObject *dictiter_iternextvalue(dictiterobject *di) { PyObject *value; - register int i, mask; + register Py_ssize_t i, mask; register dictentry *ep; dictobject *d = di->di_dict; @@ -2238,7 +2320,7 @@ PyTypeObject PyDictIterValue_Type = { static PyObject *dictiter_iternextitem(dictiterobject *di) { PyObject *key, *value, *result = di->di_result; - register int i, mask; + register Py_ssize_t i, mask; register dictentry *ep; dictobject *d = di->di_dict; diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 6271372efb3..3b793074061 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1,3 +1,9 @@ +/* + * New exceptions.c written in Iceland by Richard Jones and Georg Brandl. + * + * Thanks go to Tim Peters and Michael Hudson for debugging. + */ + #define PY_SSIZE_T_CLEAN #include #include "structmember.h" @@ -36,7 +42,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } - self->message = PyString_FromString(""); + self->message = PyString_FromString(""); if (!self->message) { Py_DECREF(self); return NULL; @@ -48,19 +54,22 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static int BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) { + if (!_PyArg_NoKeywords(self->ob_type->tp_name, kwds)) + return -1; + Py_DECREF(self->args); self->args = args; Py_INCREF(self->args); if (PyTuple_GET_SIZE(self->args) == 1) { - Py_DECREF(self->message); + Py_CLEAR(self->message); self->message = PyTuple_GET_ITEM(self->args, 0); - Py_INCREF(self->message); + Py_INCREF(self->message); } return 0; } -int +static int BaseException_clear(PyBaseExceptionObject *self) { Py_CLEAR(self->dict); @@ -76,11 +85,10 @@ BaseException_dealloc(PyBaseExceptionObject *self) self->ob_type->tp_free((PyObject *)self); } -int +static int BaseException_traverse(PyBaseExceptionObject *self, visitproc visit, void *arg) { - if (self->dict) - Py_VISIT(self->dict); + Py_VISIT(self->dict); Py_VISIT(self->args); Py_VISIT(self->message); return 0; @@ -91,24 +99,13 @@ BaseException_str(PyBaseExceptionObject *self) { PyObject *out; - switch (PySequence_Length(self->args)) { + switch (PyTuple_GET_SIZE(self->args)) { case 0: out = PyString_FromString(""); break; case 1: - { - PyObject *tmp = PySequence_GetItem(self->args, 0); - if (tmp) { - out = PyObject_Str(tmp); - Py_DECREF(tmp); - } - else - out = NULL; + out = PyObject_Str(PyTuple_GET_ITEM(self->args, 0)); break; - } - case -1: - PyErr_Clear(); - /* Fall through */ default: out = PyObject_Str(self->args); break; @@ -120,28 +117,14 @@ BaseException_str(PyBaseExceptionObject *self) static PyObject * BaseException_repr(PyBaseExceptionObject *self) { - Py_ssize_t args_len; PyObject *repr_suffix; PyObject *repr; char *name; char *dot; - args_len = PySequence_Length(self->args); - if (args_len < 0) { + repr_suffix = PyObject_Repr(self->args); + if (!repr_suffix) return NULL; - } - - if (args_len == 0) { - repr_suffix = PyString_FromString("()"); - if (!repr_suffix) - return NULL; - } - else { - PyObject *args_repr = PyObject_Repr(self->args); - if (!args_repr) - return NULL; - repr_suffix = args_repr; - } name = (char *)self->ob_type->tp_name; dot = strrchr(name, '.'); @@ -161,9 +144,35 @@ BaseException_repr(PyBaseExceptionObject *self) static PyObject * BaseException_reduce(PyBaseExceptionObject *self) { - return PyTuple_Pack(3, self->ob_type, self->args, self->dict); + if (self->args && self->dict) + return PyTuple_Pack(3, self->ob_type, self->args, self->dict); + else + return PyTuple_Pack(2, self->ob_type, self->args); } +/* + * Needed for backward compatibility, since exceptions used to store + * all their attributes in the __dict__. Code is taken from cPickle's + * load_build function. + */ +static PyObject * +BaseException_setstate(PyObject *self, PyObject *state) +{ + PyObject *d_key, *d_value; + Py_ssize_t i = 0; + + if (state != Py_None) { + if (!PyDict_Check(state)) { + PyErr_SetString(PyExc_TypeError, "state is not a dictionary"); + return NULL; + } + while (PyDict_Next(state, &i, &d_key, &d_value)) { + if (PyObject_SetAttr(self, d_key, d_value) < 0) + return NULL; + } + } + Py_RETURN_NONE; +} #ifdef Py_USING_UNICODE /* while this method generates fairly uninspired output, it a least @@ -172,24 +181,17 @@ BaseException_reduce(PyBaseExceptionObject *self) static PyObject * BaseException_unicode(PyBaseExceptionObject *self) { - if (PySequence_Length(self->args) == 0) + if (PyTuple_GET_SIZE(self->args) == 0) return PyUnicode_FromUnicode(NULL, 0); - if (PySequence_Length(self->args) == 1) { - PyObject *temp = PySequence_GetItem(self->args, 0); - PyObject *unicode_obj; - if (!temp) { - return NULL; - } - unicode_obj = PyObject_Unicode(temp); - Py_DECREF(temp); - return unicode_obj; - } + if (PyTuple_GET_SIZE(self->args) == 1) + return PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0)); return PyObject_Unicode(self->args); } #endif /* Py_USING_UNICODE */ static PyMethodDef BaseException_methods[] = { {"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS }, + {"__setstate__", (PyCFunction)BaseException_setstate, METH_O }, #ifdef Py_USING_UNICODE {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS }, #endif @@ -274,6 +276,7 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val) } seq = PySequence_Tuple(val); if (!seq) return -1; + Py_CLEAR(self->args); self->args = seq; return 0; } @@ -356,13 +359,13 @@ static PyTypeObject _PyExc_ ## EXCNAME = { \ 0, \ EXC_MODULE_NAME # EXCNAME, \ sizeof(Py ## EXCSTORE ## Object), \ - 0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, \ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, \ - PyDoc_STR(EXCDOC), (traverseproc)BaseException_traverse, \ - (inquiry)BaseException_clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ + PyDoc_STR(EXCDOC), (traverseproc)EXCSTORE ## _traverse, \ + (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, 0, 0, 0, &_ ## EXCBASE, \ 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ - (initproc)EXCSTORE ## _init, 0, EXCSTORE ## _new,\ + (initproc)EXCSTORE ## _init, 0, BaseException_new,\ }; \ PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME @@ -379,7 +382,7 @@ static PyTypeObject _PyExc_ ## EXCNAME = { \ (inquiry)EXCSTORE ## _clear, 0, 0, 0, 0, EXCMETHODS, \ EXCMEMBERS, 0, &_ ## EXCBASE, \ 0, 0, 0, offsetof(Py ## EXCSTORE ## Object, dict), \ - (initproc)EXCSTORE ## _init, 0, EXCSTORE ## _new,\ + (initproc)EXCSTORE ## _init, 0, BaseException_new,\ }; \ PyObject *PyExc_ ## EXCNAME = (PyObject *)&_PyExc_ ## EXCNAME @@ -394,7 +397,7 @@ SimpleExtendsException(PyExc_BaseException, Exception, /* * StandardError extends Exception */ -SimpleExtendsException(PyExc_Exception, StandardError, +SimpleExtendsException(PyExc_Exception, StandardError, "Base class for all standard Python exceptions that do not represent\n" "interpreter exiting."); @@ -423,19 +426,6 @@ SimpleExtendsException(PyExc_Exception, GeneratorExit, /* * SystemExit extends BaseException */ -static PyObject * -SystemExit_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PySystemExitObject *self; - - self = (PySystemExitObject *)BaseException_new(type, args, kwds); - if (!self) - return NULL; - - MAKE_IT_NONE(self->code); - - return (PyObject *)self; -} static int SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) @@ -445,7 +435,9 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) return -1; - Py_DECREF(self->code); + if (size == 0) + return 0; + Py_CLEAR(self->code); if (size == 1) self->code = PyTuple_GET_ITEM(args, 0); else if (size > 1) @@ -454,7 +446,7 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) return 0; } -int +static int SystemExit_clear(PySystemExitObject *self) { Py_CLEAR(self->code); @@ -468,7 +460,7 @@ SystemExit_dealloc(PySystemExitObject *self) self->ob_type->tp_free((PyObject *)self); } -int +static int SystemExit_traverse(PySystemExitObject *self, visitproc visit, void *arg) { Py_VISIT(self->code); @@ -505,25 +497,6 @@ SimpleExtendsException(PyExc_StandardError, ImportError, * EnvironmentError extends StandardError */ -static PyObject * -EnvironmentError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyEnvironmentErrorObject *self = NULL; - - self = (PyEnvironmentErrorObject *)BaseException_new(type, args, kwds); - if (!self) - return NULL; - - self->myerrno = Py_None; - Py_INCREF(Py_None); - self->strerror = Py_None; - Py_INCREF(Py_None); - self->filename = Py_None; - Py_INCREF(Py_None); - - return (PyObject *)self; -} - /* Where a function has a single filename, such as open() or some * of the os module functions, PyErr_SetFromErrnoWithFilename() is * called, giving a third argument which is the filename. But, so @@ -548,22 +521,22 @@ EnvironmentError_init(PyEnvironmentErrorObject *self, PyObject *args, if (PyTuple_GET_SIZE(args) <= 1) { return 0; } - - if (!PyArg_UnpackTuple(args, "EnvironmentError", 2, 3, + + if (!PyArg_UnpackTuple(args, "EnvironmentError", 2, 3, &myerrno, &strerror, &filename)) { return -1; } - Py_DECREF(self->myerrno); /* replacing */ + Py_CLEAR(self->myerrno); /* replacing */ self->myerrno = myerrno; Py_INCREF(self->myerrno); - Py_DECREF(self->strerror); /* replacing */ + Py_CLEAR(self->strerror); /* replacing */ self->strerror = strerror; Py_INCREF(self->strerror); /* self->filename will remain Py_None otherwise */ if (filename != NULL) { - Py_DECREF(self->filename); /* replacing */ + Py_CLEAR(self->filename); /* replacing */ self->filename = filename; Py_INCREF(self->filename); @@ -577,7 +550,7 @@ EnvironmentError_init(PyEnvironmentErrorObject *self, PyObject *args, return 0; } -int +static int EnvironmentError_clear(PyEnvironmentErrorObject *self) { Py_CLEAR(self->myerrno); @@ -593,7 +566,7 @@ EnvironmentError_dealloc(PyEnvironmentErrorObject *self) self->ob_type->tp_free((PyObject *)self); } -int +static int EnvironmentError_traverse(PyEnvironmentErrorObject *self, visitproc visit, void *arg) { @@ -608,22 +581,44 @@ EnvironmentError_str(PyEnvironmentErrorObject *self) { PyObject *rtnval = NULL; - if (self->filename != Py_None) { - PyObject *fmt = PyString_FromString("[Errno %s] %s: %s"); - PyObject *repr = PyObject_Repr(self->filename); - PyObject *tuple = PyTuple_New(3); + if (self->filename) { + PyObject *fmt; + PyObject *repr; + PyObject *tuple; - if (!fmt || !repr || !tuple) { - Py_XDECREF(fmt); - Py_XDECREF(repr); - Py_XDECREF(tuple); + fmt = PyString_FromString("[Errno %s] %s: %s"); + if (!fmt) + return NULL; + + repr = PyObject_Repr(self->filename); + if (!repr) { + Py_DECREF(fmt); return NULL; } - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); - Py_INCREF(self->strerror); - PyTuple_SET_ITEM(tuple, 1, self->strerror); - Py_INCREF(repr); + tuple = PyTuple_New(3); + if (!tuple) { + Py_DECREF(repr); + Py_DECREF(fmt); + return NULL; + } + + if (self->myerrno) { + Py_INCREF(self->myerrno); + PyTuple_SET_ITEM(tuple, 0, self->myerrno); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 0, Py_None); + } + if (self->strerror) { + Py_INCREF(self->strerror); + PyTuple_SET_ITEM(tuple, 1, self->strerror); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 1, Py_None); + } + PyTuple_SET_ITEM(tuple, 2, repr); rtnval = PyString_Format(fmt, tuple); @@ -631,20 +626,36 @@ EnvironmentError_str(PyEnvironmentErrorObject *self) Py_DECREF(fmt); Py_DECREF(tuple); } - else if (PyObject_IsTrue(self->myerrno) && - PyObject_IsTrue(self->strerror)) { - PyObject *fmt = PyString_FromString("[Errno %s] %s"); - PyObject *tuple = PyTuple_New(2); + else if (self->myerrno && self->strerror) { + PyObject *fmt; + PyObject *tuple; - if (!fmt || !tuple) { - Py_XDECREF(fmt); - Py_XDECREF(tuple); + fmt = PyString_FromString("[Errno %s] %s"); + if (!fmt) + return NULL; + + tuple = PyTuple_New(2); + if (!tuple) { + Py_DECREF(fmt); return NULL; } - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); - Py_INCREF(self->strerror); - PyTuple_SET_ITEM(tuple, 1, self->strerror); + + if (self->myerrno) { + Py_INCREF(self->myerrno); + PyTuple_SET_ITEM(tuple, 0, self->myerrno); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 0, Py_None); + } + if (self->strerror) { + Py_INCREF(self->strerror); + PyTuple_SET_ITEM(tuple, 1, self->strerror); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 1, Py_None); + } rtnval = PyString_Format(fmt, tuple); @@ -675,32 +686,30 @@ EnvironmentError_reduce(PyEnvironmentErrorObject *self) { PyObject *args = self->args; PyObject *res = NULL, *tmp; + /* self->args is only the first two real arguments if there was a * file name given to EnvironmentError. */ - if (PyTuple_Check(args) && - PyTuple_GET_SIZE(args) == 2 && - self->filename != Py_None) { - + if (PyTuple_GET_SIZE(args) == 2 && self->filename) { args = PyTuple_New(3); if (!args) return NULL; - - tmp = PyTuple_GetItem(self->args, 0); - if (!tmp) goto finish; + + tmp = PyTuple_GET_ITEM(self->args, 0); Py_INCREF(tmp); PyTuple_SET_ITEM(args, 0, tmp); - - tmp = PyTuple_GetItem(self->args, 1); - if (!tmp) goto finish; + + tmp = PyTuple_GET_ITEM(self->args, 1); Py_INCREF(tmp); PyTuple_SET_ITEM(args, 1, tmp); Py_INCREF(self->filename); PyTuple_SET_ITEM(args, 2, self->filename); - } else { + } else Py_INCREF(args); - } - res = PyTuple_Pack(3, self->ob_type, args, self->dict); - finish: + + if (self->dict) + res = PyTuple_Pack(3, self->ob_type, args, self->dict); + else + res = PyTuple_Pack(2, self->ob_type, args); Py_DECREF(args); return res; } @@ -714,14 +723,14 @@ static PyMethodDef EnvironmentError_methods[] = { ComplexExtendsException(PyExc_StandardError, EnvironmentError, EnvironmentError, EnvironmentError_dealloc, EnvironmentError_methods, EnvironmentError_members, - EnvironmentError_str, + EnvironmentError_str, "Base class for I/O related errors."); /* * IOError extends EnvironmentError */ -MiddlingExtendsException(PyExc_EnvironmentError, IOError, +MiddlingExtendsException(PyExc_EnvironmentError, IOError, EnvironmentError, "I/O operation failed."); @@ -738,7 +747,7 @@ MiddlingExtendsException(PyExc_EnvironmentError, OSError, #ifdef MS_WINDOWS #include "errmap.h" -int +static int WindowsError_clear(PyWindowsErrorObject *self) { Py_CLEAR(self->myerrno); @@ -755,7 +764,7 @@ WindowsError_dealloc(PyWindowsErrorObject *self) self->ob_type->tp_free((PyObject *)self); } -int +static int WindowsError_traverse(PyWindowsErrorObject *self, visitproc visit, void *arg) { Py_VISIT(self->myerrno); @@ -765,50 +774,6 @@ WindowsError_traverse(PyWindowsErrorObject *self, visitproc visit, void *arg) return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg); } -static PyObject * -WindowsError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *o_errcode = NULL; - long errcode; - PyWindowsErrorObject *self; - long posix_errno; - - self = (PyWindowsErrorObject *)EnvironmentError_new(type, args, kwds); - if (!self) - return NULL; - - if (self->myerrno == Py_None) { - self->winerror = self->myerrno; - Py_INCREF(self->winerror); - return (PyObject *)self; - } - - /* Set errno to the POSIX errno, and winerror to the Win32 - error code. */ - errcode = PyInt_AsLong(self->myerrno); - if (errcode == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - /* give a clearer error message */ - PyErr_SetString(PyExc_TypeError, "errno has to be an integer"); - goto failed; - } - posix_errno = winerror_to_errno(errcode); - - self->winerror = self->myerrno; - - o_errcode = PyInt_FromLong(posix_errno); - if (!o_errcode) - goto failed; - - self->myerrno = o_errcode; - - return (PyObject *)self; -failed: - /* Could not set errno. */ - Py_DECREF(self); - return NULL; -} - static int WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds) { @@ -820,12 +785,8 @@ WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds) == -1) return -1; - if (self->myerrno == Py_None) { - Py_DECREF(self->winerror); - self->winerror = self->myerrno; - Py_INCREF(self->winerror); + if (self->myerrno == NULL) return 0; - } /* Set errno to the POSIX errno, and winerror to the Win32 error code. */ @@ -834,7 +795,7 @@ WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds) return -1; posix_errno = winerror_to_errno(errcode); - Py_DECREF(self->winerror); + Py_CLEAR(self->winerror); self->winerror = self->myerrno; o_errcode = PyInt_FromLong(posix_errno); @@ -850,44 +811,93 @@ WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds) static PyObject * WindowsError_str(PyWindowsErrorObject *self) { - PyObject *repr = NULL; - PyObject *fmt = NULL; - PyObject *tuple = NULL; PyObject *rtnval = NULL; - if (self->filename != Py_None) { - fmt = PyString_FromString("[Error %s] %s: %s"); - repr = PyObject_Repr(self->filename); - if (!fmt || !repr) - goto finally; + if (self->filename) { + PyObject *fmt; + PyObject *repr; + PyObject *tuple; - tuple = PyTuple_Pack(3, self->myerrno, self->strerror, repr); - if (!tuple) - goto finally; + fmt = PyString_FromString("[Error %s] %s: %s"); + if (!fmt) + return NULL; + + repr = PyObject_Repr(self->filename); + if (!repr) { + Py_DECREF(fmt); + return NULL; + } + tuple = PyTuple_New(3); + if (!tuple) { + Py_DECREF(repr); + Py_DECREF(fmt); + return NULL; + } + + if (self->myerrno) { + Py_INCREF(self->myerrno); + PyTuple_SET_ITEM(tuple, 0, self->myerrno); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 0, Py_None); + } + if (self->strerror) { + Py_INCREF(self->strerror); + PyTuple_SET_ITEM(tuple, 1, self->strerror); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 1, Py_None); + } + + Py_INCREF(repr); + PyTuple_SET_ITEM(tuple, 2, repr); rtnval = PyString_Format(fmt, tuple); + + Py_DECREF(fmt); Py_DECREF(tuple); } - else if (PyObject_IsTrue(self->myerrno) && - PyObject_IsTrue(self->strerror)) { + else if (self->myerrno && self->strerror) { + PyObject *fmt; + PyObject *tuple; + fmt = PyString_FromString("[Error %s] %s"); if (!fmt) - goto finally; + return NULL; - tuple = PyTuple_Pack(2, self->myerrno, self->strerror); - if (!tuple) - goto finally; + tuple = PyTuple_New(2); + if (!tuple) { + Py_DECREF(fmt); + return NULL; + } + + if (self->myerrno) { + Py_INCREF(self->myerrno); + PyTuple_SET_ITEM(tuple, 0, self->myerrno); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 0, Py_None); + } + if (self->strerror) { + Py_INCREF(self->strerror); + PyTuple_SET_ITEM(tuple, 1, self->strerror); + } + else { + Py_INCREF(Py_None); + PyTuple_SET_ITEM(tuple, 1, Py_None); + } rtnval = PyString_Format(fmt, tuple); + + Py_DECREF(fmt); Py_DECREF(tuple); } else - rtnval = EnvironmentError_str((PyEnvironmentErrorObject *)self); + rtnval = EnvironmentError_str((PyEnvironmentErrorObject *)self); - finally: - Py_XDECREF(repr); - Py_XDECREF(fmt); - Py_XDECREF(tuple); return rtnval; } @@ -963,27 +973,6 @@ SimpleExtendsException(PyExc_StandardError, AttributeError, /* * SyntaxError extends StandardError */ -static PyObject * -SyntaxError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PySyntaxErrorObject *self = NULL; - - self = (PySyntaxErrorObject *)BaseException_new(type, args, kwds); - if (!self) - return NULL; - - MAKE_IT_NONE(self->msg) - MAKE_IT_NONE(self->filename) - MAKE_IT_NONE(self->lineno) - MAKE_IT_NONE(self->offset) - MAKE_IT_NONE(self->text) - - /* this is always None - yes, I know it doesn't seem to be used - anywhere, but it was in the previous implementation */ - MAKE_IT_NONE(self->print_file_and_line) - - return (PyObject *)self; -} static int SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) @@ -995,7 +984,7 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) return -1; if (lenargs >= 1) { - Py_DECREF(self->msg); + Py_CLEAR(self->msg); self->msg = PyTuple_GET_ITEM(args, 0); Py_INCREF(self->msg); } @@ -1004,26 +993,35 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) info = PySequence_Tuple(info); if (!info) return -1; - Py_DECREF(self->filename); + if (PyTuple_GET_SIZE(info) != 4) { + /* not a very good error message, but it's what Python 2.4 gives */ + PyErr_SetString(PyExc_IndexError, "tuple index out of range"); + Py_DECREF(info); + return -1; + } + + Py_CLEAR(self->filename); self->filename = PyTuple_GET_ITEM(info, 0); Py_INCREF(self->filename); - Py_DECREF(self->lineno); + Py_CLEAR(self->lineno); self->lineno = PyTuple_GET_ITEM(info, 1); Py_INCREF(self->lineno); - Py_DECREF(self->offset); + Py_CLEAR(self->offset); self->offset = PyTuple_GET_ITEM(info, 2); Py_INCREF(self->offset); - Py_DECREF(self->text); + Py_CLEAR(self->text); self->text = PyTuple_GET_ITEM(info, 3); Py_INCREF(self->text); + + Py_DECREF(info); } return 0; } -int +static int SyntaxError_clear(PySyntaxErrorObject *self) { Py_CLEAR(self->msg); @@ -1042,7 +1040,7 @@ SyntaxError_dealloc(PySyntaxErrorObject *self) self->ob_type->tp_free((PyObject *)self); } -int +static int SyntaxError_traverse(PySyntaxErrorObject *self, visitproc visit, void *arg) { Py_VISIT(self->msg); @@ -1079,53 +1077,58 @@ SyntaxError_str(PySyntaxErrorObject *self) { PyObject *str; PyObject *result; + int have_filename = 0; + int have_lineno = 0; + char *buffer = NULL; + Py_ssize_t bufsize; - str = PyObject_Str(self->msg); - result = str; + if (self->msg) + str = PyObject_Str(self->msg); + else + str = PyObject_Str(Py_None); + if (!str) return NULL; + /* Don't fiddle with non-string return (shouldn't happen anyway) */ + if (!PyString_Check(str)) return str; /* XXX -- do all the additional formatting with filename and lineno here */ - if (str != NULL && PyString_Check(str)) { - int have_filename = 0; - int have_lineno = 0; - char *buffer = NULL; + have_filename = (self->filename != NULL) && + PyString_Check(self->filename); + have_lineno = (self->lineno != NULL) && PyInt_Check(self->lineno); - have_filename = (self->filename != NULL) && - PyString_Check(self->filename); - have_lineno = (self->lineno != NULL) && PyInt_Check(self->lineno); + if (!have_filename && !have_lineno) + return str; - if (have_filename || have_lineno) { - Py_ssize_t bufsize = PyString_GET_SIZE(str) + 64; - if (have_filename) - bufsize += PyString_GET_SIZE(self->filename); + bufsize = PyString_GET_SIZE(str) + 64; + if (have_filename) + bufsize += PyString_GET_SIZE(self->filename); - buffer = (char *)PyMem_MALLOC(bufsize); - if (buffer != NULL) { - if (have_filename && have_lineno) - PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)", - PyString_AS_STRING(str), - my_basename(PyString_AS_STRING(self->filename)), - PyInt_AsLong(self->lineno)); - else if (have_filename) - PyOS_snprintf(buffer, bufsize, "%s (%s)", - PyString_AS_STRING(str), - my_basename(PyString_AS_STRING(self->filename))); - else if (have_lineno) - PyOS_snprintf(buffer, bufsize, "%s (line %ld)", - PyString_AS_STRING(str), - PyInt_AsLong(self->lineno)); + buffer = PyMem_MALLOC(bufsize); + if (buffer == NULL) + return str; - result = PyString_FromString(buffer); - PyMem_FREE(buffer); + if (have_filename && have_lineno) + PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)", + PyString_AS_STRING(str), + my_basename(PyString_AS_STRING(self->filename)), + PyInt_AsLong(self->lineno)); + else if (have_filename) + PyOS_snprintf(buffer, bufsize, "%s (%s)", + PyString_AS_STRING(str), + my_basename(PyString_AS_STRING(self->filename))); + else /* only have_lineno */ + PyOS_snprintf(buffer, bufsize, "%s (line %ld)", + PyString_AS_STRING(str), + PyInt_AsLong(self->lineno)); - if (result == NULL) - result = str; - else - Py_DECREF(str); - } - } - } + result = PyString_FromString(buffer); + PyMem_FREE(buffer); + + if (result == NULL) + result = str; + else + Py_DECREF(str); return result; } @@ -1196,9 +1199,8 @@ KeyError_str(PyBaseExceptionObject *self) string, that string will be displayed in quotes. Too bad. If args is anything else, use the default BaseException__str__(). */ - if (PyTuple_Check(self->args) && PyTuple_GET_SIZE(self->args) == 1) { - PyObject *key = PyTuple_GET_ITEM(self->args, 0); - return PyObject_Repr(key); + if (PyTuple_GET_SIZE(self->args) == 1) { + return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0)); } return BaseException_str(self); } @@ -1248,7 +1250,7 @@ set_ssize_t(PyObject **attr, Py_ssize_t value) PyObject *obj = PyInt_FromSsize_t(value); if (!obj) return -1; - Py_XDECREF(*attr); + Py_CLEAR(*attr); *attr = obj; return 0; } @@ -1276,7 +1278,7 @@ set_string(PyObject **attr, const char *value) PyObject *obj = PyString_FromString(value); if (!obj) return -1; - Py_XDECREF(*attr); + Py_CLEAR(*attr); *attr = obj; return 0; } @@ -1342,6 +1344,7 @@ PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start) *start = 0; /*XXX check for values <0*/ if (*start>=size) *start = size-1; + Py_DECREF(obj); return 0; } return -1; @@ -1361,6 +1364,7 @@ PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start) *start = 0; if (*start>=size) *start = size-1; + Py_DECREF(obj); return 0; } return -1; @@ -1408,6 +1412,7 @@ PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end) *end = 1; if (*end>size) *end = size; + Py_DECREF(obj); return 0; } return -1; @@ -1427,6 +1432,7 @@ PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end) *end = 1; if (*end>size) *end = size; + Py_DECREF(obj); return 0; } return -1; @@ -1502,36 +1508,23 @@ PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason) } -static PyObject * -UnicodeError_new(PyTypeObject *type, PyObject *args, PyObject *kwds, - PyTypeObject *objecttype) -{ - PyUnicodeErrorObject *self; - - self = (PyUnicodeErrorObject *)BaseException_new(type, args, kwds); - if (!self) - return NULL; - - MAKE_IT_NONE(self->encoding); - MAKE_IT_NONE(self->object); - MAKE_IT_NONE(self->start); - MAKE_IT_NONE(self->end); - MAKE_IT_NONE(self->reason); - - return (PyObject *)self; -} - static int UnicodeError_init(PyUnicodeErrorObject *self, PyObject *args, PyObject *kwds, PyTypeObject *objecttype) { + Py_CLEAR(self->encoding); + Py_CLEAR(self->object); + Py_CLEAR(self->start); + Py_CLEAR(self->end); + Py_CLEAR(self->reason); + if (!PyArg_ParseTuple(args, "O!O!O!O!O!", &PyString_Type, &self->encoding, objecttype, &self->object, &PyInt_Type, &self->start, &PyInt_Type, &self->end, &PyString_Type, &self->reason)) { - self->encoding = self->object = self->start = self->end = + self->encoding = self->object = self->start = self->end = self->reason = NULL; return -1; } @@ -1545,7 +1538,7 @@ UnicodeError_init(PyUnicodeErrorObject *self, PyObject *args, PyObject *kwds, return 0; } -int +static int UnicodeError_clear(PyUnicodeErrorObject *self) { Py_CLEAR(self->encoding); @@ -1563,7 +1556,7 @@ UnicodeError_dealloc(PyUnicodeErrorObject *self) self->ob_type->tp_free((PyObject *)self); } -int +static int UnicodeError_traverse(PyUnicodeErrorObject *self, visitproc visit, void *arg) { Py_VISIT(self->encoding); @@ -1594,11 +1587,6 @@ static PyMemberDef UnicodeError_members[] = { /* * UnicodeEncodeError extends UnicodeError */ -static PyObject * -UnicodeEncodeError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - return UnicodeError_new(type, args, kwds, &PyUnicode_Type); -} static int UnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds) @@ -1616,27 +1604,27 @@ UnicodeEncodeError_str(PyObject *self) Py_ssize_t end; if (PyUnicodeEncodeError_GetStart(self, &start)) - return NULL; + return NULL; if (PyUnicodeEncodeError_GetEnd(self, &end)) - return NULL; + return NULL; if (end==start+1) { - int badchar = (int)PyUnicode_AS_UNICODE(((PyUnicodeErrorObject *)self)->object)[start]; - char badchar_str[20]; - if (badchar <= 0xff) - PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); - else if (badchar <= 0xffff) - PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); - else - PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); - return PyString_FromFormat( - "'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s", - PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding), - badchar_str, - start, - PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason) - ); + int badchar = (int)PyUnicode_AS_UNICODE(((PyUnicodeErrorObject *)self)->object)[start]; + char badchar_str[20]; + if (badchar <= 0xff) + PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); + else if (badchar <= 0xffff) + PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); + else + PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); + return PyString_FromFormat( + "'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s", + PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding), + badchar_str, + start, + PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason) + ); } return PyString_FromFormat( "'%.400s' codec can't encode characters in position %zd-%zd: %.400s", @@ -1655,10 +1643,10 @@ static PyTypeObject _PyExc_UnicodeEncodeError = { (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (reprfunc)UnicodeEncodeError_str, 0, 0, 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, - PyDoc_STR("Unicode encoding error."), (traverseproc)BaseException_traverse, - (inquiry)BaseException_clear, 0, 0, 0, 0, 0, UnicodeError_members, + PyDoc_STR("Unicode encoding error."), (traverseproc)UnicodeError_traverse, + (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), - (initproc)UnicodeEncodeError_init, 0, UnicodeEncodeError_new, + (initproc)UnicodeEncodeError_init, 0, BaseException_new, }; PyObject *PyExc_UnicodeEncodeError = (PyObject *)&_PyExc_UnicodeEncodeError; @@ -1668,18 +1656,13 @@ PyUnicodeEncodeError_Create( Py_ssize_t start, Py_ssize_t end, const char *reason) { return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns", - encoding, object, length, start, end, reason); + encoding, object, length, start, end, reason); } /* * UnicodeDecodeError extends UnicodeError */ -static PyObject * -UnicodeDecodeError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - return UnicodeError_new(type, args, kwds, &PyString_Type); -} static int UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) @@ -1693,8 +1676,8 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * UnicodeDecodeError_str(PyObject *self) { - Py_ssize_t start; - Py_ssize_t end; + Py_ssize_t start = 0; + Py_ssize_t end = 0; if (PyUnicodeDecodeError_GetStart(self, &start)) return NULL; @@ -1703,17 +1686,17 @@ UnicodeDecodeError_str(PyObject *self) return NULL; if (end==start+1) { - /* FromFormat does not support %02x, so format that separately */ - char byte[4]; - PyOS_snprintf(byte, sizeof(byte), "%02x", - ((int)PyString_AS_STRING(((PyUnicodeErrorObject *)self)->object)[start])&0xff); - return PyString_FromFormat( - "'%.400s' codec can't decode byte 0x%s in position %zd: %.400s", - PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding), - byte, - start, - PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason) - ); + /* FromFormat does not support %02x, so format that separately */ + char byte[4]; + PyOS_snprintf(byte, sizeof(byte), "%02x", + ((int)PyString_AS_STRING(((PyUnicodeErrorObject *)self)->object)[start])&0xff); + return PyString_FromFormat( + "'%.400s' codec can't decode byte 0x%s in position %zd: %.400s", + PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding), + byte, + start, + PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason) + ); } return PyString_FromFormat( "'%.400s' codec can't decode bytes in position %zd-%zd: %.400s", @@ -1732,10 +1715,10 @@ static PyTypeObject _PyExc_UnicodeDecodeError = { (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (reprfunc)UnicodeDecodeError_str, 0, 0, 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, - PyDoc_STR("Unicode decoding error."), (traverseproc)BaseException_traverse, - (inquiry)BaseException_clear, 0, 0, 0, 0, 0, UnicodeError_members, + PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse, + (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), - (initproc)UnicodeDecodeError_init, 0, UnicodeDecodeError_new, + (initproc)UnicodeDecodeError_init, 0, BaseException_new, }; PyObject *PyExc_UnicodeDecodeError = (PyObject *)&_PyExc_UnicodeDecodeError; @@ -1748,30 +1731,13 @@ PyUnicodeDecodeError_Create( assert(start < INT_MAX); assert(end < INT_MAX); return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#nns", - encoding, object, length, start, end, reason); + encoding, object, length, start, end, reason); } /* * UnicodeTranslateError extends UnicodeError */ -static PyObject * -UnicodeTranslateError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyUnicodeErrorObject *self = NULL; - - self = (PyUnicodeErrorObject *)BaseException_new(type, args, kwds); - if (!self) - return NULL; - - MAKE_IT_NONE(self->encoding); - MAKE_IT_NONE(self->object); - MAKE_IT_NONE(self->start); - MAKE_IT_NONE(self->end); - MAKE_IT_NONE(self->reason); - - return (PyObject *)self; -} static int UnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args, @@ -1793,7 +1759,7 @@ UnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args, self->object = self->start = self->end = self->reason = NULL; return -1; } - + Py_INCREF(self->object); Py_INCREF(self->start); Py_INCREF(self->end); @@ -1810,26 +1776,26 @@ UnicodeTranslateError_str(PyObject *self) Py_ssize_t end; if (PyUnicodeTranslateError_GetStart(self, &start)) - return NULL; + return NULL; if (PyUnicodeTranslateError_GetEnd(self, &end)) - return NULL; + return NULL; if (end==start+1) { - int badchar = (int)PyUnicode_AS_UNICODE(((PyUnicodeErrorObject *)self)->object)[start]; - char badchar_str[20]; - if (badchar <= 0xff) - PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); - else if (badchar <= 0xffff) - PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); - else - PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); - return PyString_FromFormat( + int badchar = (int)PyUnicode_AS_UNICODE(((PyUnicodeErrorObject *)self)->object)[start]; + char badchar_str[20]; + if (badchar <= 0xff) + PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar); + else if (badchar <= 0xffff) + PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar); + else + PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar); + return PyString_FromFormat( "can't translate character u'\\%s' in position %zd: %.400s", - badchar_str, - start, - PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason) - ); + badchar_str, + start, + PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason) + ); } return PyString_FromFormat( "can't translate characters in position %zd-%zd: %.400s", @@ -1850,7 +1816,7 @@ static PyTypeObject _PyExc_UnicodeTranslateError = { PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse, (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members, 0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict), - (initproc)UnicodeTranslateError_init, 0, UnicodeTranslateError_new, + (initproc)UnicodeTranslateError_init, 0, BaseException_new, }; PyObject *PyExc_UnicodeTranslateError = (PyObject *)&_PyExc_UnicodeTranslateError; @@ -1860,7 +1826,7 @@ PyUnicodeTranslateError_Create( Py_ssize_t start, Py_ssize_t end, const char *reason) { return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#nns", - object, length, start, end, reason); + object, length, start, end, reason); } #endif @@ -2003,7 +1969,7 @@ static PyMethodDef functions[] = { Py_FatalError("Module dictionary insertion problem."); PyMODINIT_FUNC -_PyExc_Init(void) +_PyExc_Init(void) { PyObject *m, *bltinmod, *bdict; diff --git a/Objects/genobject.c b/Objects/genobject.c index 15e53dd23bf..4d0c4f6ee84 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -216,7 +216,7 @@ gen_throw(PyGenObject *gen, PyObject *args) PyObject *tb = NULL; PyObject *val = NULL; - if (!PyArg_ParseTuple(args, "O|OO:throw", &typ, &val, &tb)) + if (!PyArg_UnpackTuple(args, "throw", 1, 3, &typ, &val, &tb)) return NULL; /* First, check the traceback argument, replacing None with diff --git a/Objects/longobject.c b/Objects/longobject.c index cd02eb3bb73..a1a4af00cee 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1509,6 +1509,57 @@ convmultmax_base[base], the result is "simply" (((c0*B + c1)*B + c2)*B + c3)*B + ... ))) + c_n-1 where B = convmultmax_base[base]. + +Error analysis: as above, the number of Python digits `n` needed is worst- +case + + n >= N * log(B)/log(BASE) + +where `N` is the number of input digits in base `B`. This is computed via + + size_z = (Py_ssize_t)((scan - str) * log_base_BASE[base]) + 1; + +below. Two numeric concerns are how much space this can waste, and whether +the computed result can be too small. To be concrete, assume BASE = 2**15, +which is the default (and it's unlikely anyone changes that). + +Waste isn't a problem: provided the first input digit isn't 0, the difference +between the worst-case input with N digits and the smallest input with N +digits is about a factor of B, but B is small compared to BASE so at most +one allocated Python digit can remain unused on that count. If +N*log(B)/log(BASE) is mathematically an exact integer, then truncating that +and adding 1 returns a result 1 larger than necessary. However, that can't +happen: whenever B is a power of 2, long_from_binary_base() is called +instead, and it's impossible for B**i to be an integer power of 2**15 when +B is not a power of 2 (i.e., it's impossible for N*log(B)/log(BASE) to be +an exact integer when B is not a power of 2, since B**i has a prime factor +other than 2 in that case, but (2**15)**j's only prime factor is 2). + +The computed result can be too small if the true value of N*log(B)/log(BASE) +is a little bit larger than an exact integer, but due to roundoff errors (in +computing log(B), log(BASE), their quotient, and/or multiplying that by N) +yields a numeric result a little less than that integer. Unfortunately, "how +close can a transcendental function get to an integer over some range?" +questions are generally theoretically intractable. Computer analysis via +continued fractions is practical: expand log(B)/log(BASE) via continued +fractions, giving a sequence i/j of "the best" rational approximations. Then +j*log(B)/log(BASE) is approximately equal to (the integer) i. This shows that +we can get very close to being in trouble, but very rarely. For example, +76573 is a denominator in one of the continued-fraction approximations to +log(10)/log(2**15), and indeed: + + >>> log(10)/log(2**15)*76573 + 16958.000000654003 + +is very close to an integer. If we were working with IEEE single-precision, +rounding errors could kill us. Finding worst cases in IEEE double-precision +requires better-than-double-precision log() functions, and Tim didn't bother. +Instead the code checks to see whether the allocated space is enough as each +new Python digit is added, and copies the whole thing to a larger long if not. +This should happen extremely rarely, and in fact I don't have a test case +that triggers it(!). Instead the code was tested by artificially allocating +just 1 digit at the start, so that the copying code was exercised for every +digit beyond the first. ***/ register twodigits c; /* current input character */ Py_ssize_t size_z; @@ -1551,6 +1602,8 @@ where B = convmultmax_base[base]. * being stored into. */ size_z = (Py_ssize_t)((scan - str) * log_base_BASE[base]) + 1; + /* Uncomment next line to test exceedingly rare copy code */ + /* size_z = 1; */ assert(size_z > 0); z = _PyLong_New(size_z); if (z == NULL) @@ -1594,9 +1647,27 @@ where B = convmultmax_base[base]. /* carry off the current end? */ if (c) { assert(c < BASE); - assert(z->ob_size < size_z); - *pz = (digit)c; - ++z->ob_size; + if (z->ob_size < size_z) { + *pz = (digit)c; + ++z->ob_size; + } + else { + PyLongObject *tmp; + /* Extremely rare. Get more space. */ + assert(z->ob_size == size_z); + tmp = _PyLong_New(size_z + 1); + if (tmp == NULL) { + Py_DECREF(z); + return NULL; + } + memcpy(tmp->ob_digit, + z->ob_digit, + sizeof(digit) * size_z); + Py_DECREF(z); + z = tmp; + z->ob_digit[size_z] = (digit)c; + ++size_z; + } } } } diff --git a/Objects/object.c b/Objects/object.c index 9a451d2d280..51699296589 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -112,7 +112,7 @@ get_counts(void) if (result == NULL) return NULL; for (tp = type_list; tp; tp = tp->tp_next) { - v = Py_BuildValue("(siii)", tp->tp_name, tp->tp_allocs, + v = Py_BuildValue("(snnn)", tp->tp_name, tp->tp_allocs, tp->tp_frees, tp->tp_maxalloc); if (v == NULL) { Py_DECREF(result); diff --git a/Objects/stringlib/count.h b/Objects/stringlib/count.h index 0bd02b59746..367a15c51a5 100644 --- a/Objects/stringlib/count.h +++ b/Objects/stringlib/count.h @@ -13,8 +13,11 @@ stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len, { Py_ssize_t count; - if (sub_len == 0) + if (sub_len == 0) { + if (str_len < 0) + return 0; /* start > len(str) */ return str_len + 1; + } count = fastsearch(str, str_len, sub, sub_len, FAST_COUNT); diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h index 4cea2db4b23..4cdbb096da3 100644 --- a/Objects/stringlib/find.h +++ b/Objects/stringlib/find.h @@ -14,8 +14,11 @@ stringlib_find(const STRINGLIB_CHAR* str, Py_ssize_t str_len, { Py_ssize_t pos; - if (sub_len == 0) + if (sub_len == 0) { + if (str_len < 0) + return -1; return offset; + } pos = fastsearch(str, str_len, sub, sub_len, FAST_SEARCH); @@ -30,22 +33,20 @@ stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len, const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, Py_ssize_t offset) { - Py_ssize_t pos; - /* XXX - create reversefastsearch helper! */ - if (sub_len == 0) - pos = str_len + offset; - else { - Py_ssize_t j; - pos = -1; + if (sub_len == 0) { + if (str_len < 0) + return -1; + return str_len + offset; + } else { + Py_ssize_t j, pos = -1; for (j = str_len - sub_len; j >= 0; --j) if (STRINGLIB_CMP(str+j, sub, sub_len) == 0) { pos = j + offset; break; } + return pos; } - - return pos; } Py_LOCAL_INLINE(Py_ssize_t) diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 110c38ee01e..430d112b789 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -23,7 +23,6 @@ static PyStringObject *nullstring; */ static PyObject *interned; - /* For both PyString_FromString() and PyString_FromStringAndSize(), the parameter `size' denotes number of characters to allocate, not counting any @@ -80,7 +79,7 @@ PyString_FromStringAndSize(const char *str, Py_ssize_t size) op->ob_shash = -1; op->ob_sstate = SSTATE_NOT_INTERNED; if (str != NULL) - memcpy(op->ob_sval, str, size); + Py_MEMCPY(op->ob_sval, str, size); op->ob_sval[size] = '\0'; /* share short strings */ if (size == 0) { @@ -134,7 +133,7 @@ PyString_FromString(const char *str) PyObject_INIT_VAR(op, &PyString_Type, size); op->ob_shash = -1; op->ob_sstate = SSTATE_NOT_INTERNED; - memcpy(op->ob_sval, str, size+1); + Py_MEMCPY(op->ob_sval, str, size+1); /* share short strings */ if (size == 0) { PyObject *t = (PyObject *)op; @@ -162,7 +161,7 @@ PyString_FromFormatV(const char *format, va_list vargs) PyObject* string; #ifdef VA_LIST_IS_ARRAY - memcpy(count, vargs, sizeof(va_list)); + Py_MEMCPY(count, vargs, sizeof(va_list)); #else #ifdef __va_copy __va_copy(count, vargs); @@ -304,7 +303,7 @@ PyString_FromFormatV(const char *format, va_list vargs) i = strlen(p); if (n > 0 && i > n) i = n; - memcpy(s, p, i); + Py_MEMCPY(s, p, i); s += i; break; case 'p': @@ -583,7 +582,7 @@ PyObject *PyString_DecodeEscape(const char *s, assert(PyString_Check(w)); r = PyString_AS_STRING(w); rn = PyString_GET_SIZE(w); - memcpy(p, r, rn); + Py_MEMCPY(p, r, rn); p += rn; Py_DECREF(w); s = t; @@ -967,8 +966,8 @@ string_concat(register PyStringObject *a, register PyObject *bb) PyObject_INIT_VAR(op, &PyString_Type, size); op->ob_shash = -1; op->ob_sstate = SSTATE_NOT_INTERNED; - memcpy(op->ob_sval, a->ob_sval, a->ob_size); - memcpy(op->ob_sval + a->ob_size, b->ob_sval, b->ob_size); + Py_MEMCPY(op->ob_sval, a->ob_sval, a->ob_size); + Py_MEMCPY(op->ob_sval + a->ob_size, b->ob_sval, b->ob_size); op->ob_sval[size] = '\0'; return (PyObject *) op; #undef b @@ -1017,12 +1016,12 @@ string_repeat(register PyStringObject *a, register Py_ssize_t n) } i = 0; if (i < size) { - memcpy(op->ob_sval, a->ob_sval, a->ob_size); + Py_MEMCPY(op->ob_sval, a->ob_sval, a->ob_size); i = a->ob_size; } while (i < size) { j = (i <= size-i) ? i : size-i; - memcpy(op->ob_sval+i, op->ob_sval, j); + Py_MEMCPY(op->ob_sval+i, op->ob_sval, j); i += j; } return (PyObject *) op; @@ -1364,7 +1363,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"}; count++; } /* Always force the list to the expected size. */ -#define FIX_PREALLOC_SIZE(list) ((PyListObject *)list)->ob_size = count; +#define FIX_PREALLOC_SIZE(list) ((PyListObject *)list)->ob_size = count #define SKIP_SPACE(s, i, len) { while (i 0) @@ -2131,7 +2131,7 @@ string_lower(PyStringObject *self) s = PyString_AS_STRING(newobj); - memcpy(s, PyString_AS_STRING(self), n); + Py_MEMCPY(s, PyString_AS_STRING(self), n); for (i = 0; i < n; i++) { int c = Py_CHARMASK(s[i]); @@ -2164,7 +2164,7 @@ string_upper(PyStringObject *self) s = PyString_AS_STRING(newobj); - memcpy(s, PyString_AS_STRING(self), n); + Py_MEMCPY(s, PyString_AS_STRING(self), n); for (i = 0; i < n; i++) { int c = Py_CHARMASK(s[i]); @@ -2615,18 +2615,18 @@ replace_interleave(PyStringObject *self, /* TODO: special case single character, which doesn't need memcpy */ /* Lay the first one down (guaranteed this will occur) */ - memcpy(result_s, to_s, to_len); + Py_MEMCPY(result_s, to_s, to_len); result_s += to_len; count -= 1; for (i=0; itp_alloc(type, n); if (pnew != NULL) { - memcpy(PyString_AS_STRING(pnew), PyString_AS_STRING(tmp), n+1); + Py_MEMCPY(PyString_AS_STRING(pnew), PyString_AS_STRING(tmp), n+1); ((PyStringObject *)pnew)->ob_shash = ((PyStringObject *)tmp)->ob_shash; ((PyStringObject *)pnew)->ob_sstate = SSTATE_NOT_INTERNED; @@ -4791,7 +4791,7 @@ PyString_Format(PyObject *format, PyObject *args) *res++ = *pbuf++; } } - memcpy(res, pbuf, len); + Py_MEMCPY(res, pbuf, len); res += len; rescnt -= len; while (--width >= len) { diff --git a/PC/VC6/pythoncore.dsp b/PC/VC6/pythoncore.dsp index cf3200c9cef..ec2ec3ea1dc 100644 --- a/PC/VC6/pythoncore.dsp +++ b/PC/VC6/pythoncore.dsp @@ -313,7 +313,7 @@ SOURCE=..\..\Objects\funcobject.c # End Source File # Begin Source File -SOURCE=..\..\Modules\functionalmodule.c +SOURCE=..\..\Modules\_functoolsmodule.c # End Source File # Begin Source File diff --git a/PC/_subprocess.c b/PC/_subprocess.c index 78ceb7d9e48..0e4ee5fe848 100644 --- a/PC/_subprocess.c +++ b/PC/_subprocess.c @@ -108,8 +108,8 @@ sp_handle_dealloc(sp_handle_object* self) } static PyMethodDef sp_handle_methods[] = { - {"Detach", (PyCFunction) sp_handle_detach, 1}, - {"Close", (PyCFunction) sp_handle_close, 1}, + {"Detach", (PyCFunction) sp_handle_detach, METH_VARARGS}, + {"Close", (PyCFunction) sp_handle_close, METH_VARARGS}, {NULL, NULL} }; diff --git a/PC/config.c b/PC/config.c index be11d3f8dcb..b832d7c64fe 100644 --- a/PC/config.c +++ b/PC/config.c @@ -54,7 +54,7 @@ extern void initparser(void); extern void init_winreg(void); extern void init_struct(void); extern void initdatetime(void); -extern void initfunctional(void); +extern void init_functools(void); extern void initzlib(void); extern void init_multibytecodec(void); @@ -132,7 +132,7 @@ struct _inittab _PyImport_Inittab[] = { {"_winreg", init_winreg}, {"_struct", init_struct}, {"datetime", initdatetime}, - {"functional", initfunctional}, + {"_functools", init_functools}, {"xxsubtype", initxxsubtype}, {"zipimport", initzipimport}, diff --git a/PC/example_nt/example.c b/PC/example_nt/example.c index 46cb429dae3..953fb824e7f 100644 --- a/PC/example_nt/example.c +++ b/PC/example_nt/example.c @@ -9,7 +9,7 @@ ex_foo(PyObject *self, PyObject *args) } static PyMethodDef example_methods[] = { - {"foo", ex_foo, 1, "foo() doc string"}, + {"foo", ex_foo, METH_VARARGS, "foo() doc string"}, {NULL, NULL} }; diff --git a/PC/icons/baselogo.svg b/PC/icons/baselogo.svg new file mode 100644 index 00000000000..fff6b170d7a --- /dev/null +++ b/PC/icons/baselogo.svg @@ -0,0 +1,609 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PC/icons/source.xar b/PC/icons/source.xar new file mode 100644 index 00000000000..84cbbc4d88e Binary files /dev/null and b/PC/icons/source.xar differ diff --git a/PCbuild/pythoncore.vcproj b/PCbuild/pythoncore.vcproj index c37e9b933d2..bb9f7af1b73 100644 --- a/PCbuild/pythoncore.vcproj +++ b/PCbuild/pythoncore.vcproj @@ -515,10 +515,7 @@ RelativePath="..\Objects\funcobject.c"> - - + RelativePath="..\Modules\_functoolsmodule.c"> diff --git a/PCbuild8/_bsddb.vcproj b/PCbuild8/_bsddb.vcproj index 003cef3c933..22e362afad0 100644 --- a/PCbuild8/_bsddb.vcproj +++ b/PCbuild8/_bsddb.vcproj @@ -1,385 +1,385 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_ctypes.vcproj b/PCbuild8/_ctypes.vcproj index de46f5faafb..b09f5c2b373 100644 --- a/PCbuild8/_ctypes.vcproj +++ b/PCbuild8/_ctypes.vcproj @@ -1,408 +1,408 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_ctypes_test.vcproj b/PCbuild8/_ctypes_test.vcproj index a20e3071bd0..e4503ea0be8 100644 --- a/PCbuild8/_ctypes_test.vcproj +++ b/PCbuild8/_ctypes_test.vcproj @@ -1,367 +1,367 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_elementtree.vcproj b/PCbuild8/_elementtree.vcproj index 9cfa28ffd3a..a496f7a1a27 100644 --- a/PCbuild8/_elementtree.vcproj +++ b/PCbuild8/_elementtree.vcproj @@ -1,390 +1,390 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_msi.vcproj b/PCbuild8/_msi.vcproj index 36df77d0e43..125db7d1900 100644 --- a/PCbuild8/_msi.vcproj +++ b/PCbuild8/_msi.vcproj @@ -1,375 +1,375 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_socket.vcproj b/PCbuild8/_socket.vcproj index 5e507c50d81..95c394103da 100644 --- a/PCbuild8/_socket.vcproj +++ b/PCbuild8/_socket.vcproj @@ -1,381 +1,381 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_sqlite3.vcproj b/PCbuild8/_sqlite3.vcproj index 1e01231625a..cd26b8b191a 100644 --- a/PCbuild8/_sqlite3.vcproj +++ b/PCbuild8/_sqlite3.vcproj @@ -1,414 +1,414 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_ssl.vcproj b/PCbuild8/_ssl.vcproj index 443657d827d..bd1299dc74d 100644 --- a/PCbuild8/_ssl.vcproj +++ b/PCbuild8/_ssl.vcproj @@ -1,121 +1,121 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_testcapi.vcproj b/PCbuild8/_testcapi.vcproj index bc681c66189..4b4524a7ca7 100644 --- a/PCbuild8/_testcapi.vcproj +++ b/PCbuild8/_testcapi.vcproj @@ -1,374 +1,374 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/_tkinter.vcproj b/PCbuild8/_tkinter.vcproj index e92c58abab4..72333753919 100644 --- a/PCbuild8/_tkinter.vcproj +++ b/PCbuild8/_tkinter.vcproj @@ -1,389 +1,389 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/build_ssl.py b/PCbuild8/build_ssl.py index 18488f176de..8f485a25809 100644 --- a/PCbuild8/build_ssl.py +++ b/PCbuild8/build_ssl.py @@ -1,163 +1,163 @@ -# Script for building the _ssl module for Windows. -# Uses Perl to setup the OpenSSL environment correctly -# and build OpenSSL, then invokes a simple nmake session -# for _ssl.pyd itself. - -# THEORETICALLY, you can: -# * Unpack the latest SSL release one level above your main Python source -# directory. It is likely you will already find the zlib library and -# any other external packages there. -# * Install ActivePerl and ensure it is somewhere on your path. -# * Run this script from the PCBuild directory. -# -# it should configure and build SSL, then build the ssl Python extension -# without intervention. - -import os, sys, re - -# Find all "foo.exe" files on the PATH. -def find_all_on_path(filename, extras = None): - entries = os.environ["PATH"].split(os.pathsep) - ret = [] - for p in entries: - fname = os.path.abspath(os.path.join(p, filename)) - if os.path.isfile(fname) and fname not in ret: - ret.append(fname) - if extras: - for p in extras: - fname = os.path.abspath(os.path.join(p, filename)) - if os.path.isfile(fname) and fname not in ret: - ret.append(fname) - return ret - -# Find a suitable Perl installation for OpenSSL. -# cygwin perl does *not* work. ActivePerl does. -# Being a Perl dummy, the simplest way I can check is if the "Win32" package -# is available. -def find_working_perl(perls): - for perl in perls: - fh = os.popen(perl + ' -e "use Win32;"') - fh.read() - rc = fh.close() - if rc: - continue - return perl - print "Can not find a suitable PERL:" - if perls: - print " the following perl interpreters were found:" - for p in perls: - print " ", p - print " None of these versions appear suitable for building OpenSSL" - else: - print " NO perl interpreters were found on this machine at all!" - print " Please install ActivePerl and ensure it appears on your path" - print "The Python SSL module was not built" - return None - -# Locate the best SSL directory given a few roots to look into. -def find_best_ssl_dir(sources): - candidates = [] - for s in sources: - try: - s = os.path.abspath(s) - fnames = os.listdir(s) - except os.error: - fnames = [] - for fname in fnames: - fqn = os.path.join(s, fname) - if os.path.isdir(fqn) and fname.startswith("openssl-"): - candidates.append(fqn) - # Now we have all the candidates, locate the best. - best_parts = [] - best_name = None - for c in candidates: - parts = re.split("[.-]", os.path.basename(c))[1:] - # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers - if len(parts) >= 4: - continue - if parts > best_parts: - best_parts = parts - best_name = c - if best_name is not None: - print "Found an SSL directory at '%s'" % (best_name,) - else: - print "Could not find an SSL directory in '%s'" % (sources,) - return best_name - -def main(): - debug = "-d" in sys.argv - build_all = "-a" in sys.argv - make_flags = "" - if build_all: - make_flags = "-a" - # perl should be on the path, but we also look in "\perl" and "c:\\perl" - # as "well known" locations - perls = find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"]) - perl = find_working_perl(perls) - if perl is None: - sys.exit(1) - - print "Found a working perl at '%s'" % (perl,) - # Look for SSL 2 levels up from pcbuild - ie, same place zlib etc all live. - ssl_dir = find_best_ssl_dir(("../..",)) - if ssl_dir is None: - sys.exit(1) - - old_cd = os.getcwd() - try: - os.chdir(ssl_dir) - # If the ssl makefiles do not exist, we invoke Perl to generate them. - if not os.path.isfile(os.path.join(ssl_dir, "32.mak")) or \ - not os.path.isfile(os.path.join(ssl_dir, "d32.mak")): - print "Creating the makefiles..." - # Put our working Perl at the front of our path - os.environ["PATH"] = os.path.split(perl)[0] + \ - os.pathsep + \ - os.environ["PATH"] - # ms\32all.bat will reconfigure OpenSSL and then try to build - # all outputs (debug/nondebug/dll/lib). So we filter the file - # to exclude any "nmake" commands and then execute. - tempname = "ms\\32all_py.bat" - - in_bat = open("ms\\32all.bat") - temp_bat = open(tempname,"w") - while 1: - cmd = in_bat.readline() - print 'cmd', repr(cmd) - if not cmd: break - if cmd.strip()[:5].lower() == "nmake": - continue - temp_bat.write(cmd) - in_bat.close() - temp_bat.close() - os.system(tempname) - try: - os.remove(tempname) - except: - pass - - # Now run make. - print "Executing nmake over the ssl makefiles..." - if debug: - rc = os.system("nmake /nologo -f d32.mak") - if rc: - print "Executing d32.mak failed" - print rc - sys.exit(rc) - else: - rc = os.system("nmake /nologo -f 32.mak") - if rc: - print "Executing 32.mak failed" - print rc - sys.exit(rc) - finally: - os.chdir(old_cd) - # And finally, we can build the _ssl module itself for Python. - defs = "SSL_DIR=%s" % (ssl_dir,) - if debug: - defs = defs + " " + "DEBUG=1" - rc = os.system('nmake /nologo -f _ssl.mak ' + defs + " " + make_flags) - sys.exit(rc) - -if __name__=='__main__': - main() +# Script for building the _ssl module for Windows. +# Uses Perl to setup the OpenSSL environment correctly +# and build OpenSSL, then invokes a simple nmake session +# for _ssl.pyd itself. + +# THEORETICALLY, you can: +# * Unpack the latest SSL release one level above your main Python source +# directory. It is likely you will already find the zlib library and +# any other external packages there. +# * Install ActivePerl and ensure it is somewhere on your path. +# * Run this script from the PCBuild directory. +# +# it should configure and build SSL, then build the ssl Python extension +# without intervention. + +import os, sys, re + +# Find all "foo.exe" files on the PATH. +def find_all_on_path(filename, extras = None): + entries = os.environ["PATH"].split(os.pathsep) + ret = [] + for p in entries: + fname = os.path.abspath(os.path.join(p, filename)) + if os.path.isfile(fname) and fname not in ret: + ret.append(fname) + if extras: + for p in extras: + fname = os.path.abspath(os.path.join(p, filename)) + if os.path.isfile(fname) and fname not in ret: + ret.append(fname) + return ret + +# Find a suitable Perl installation for OpenSSL. +# cygwin perl does *not* work. ActivePerl does. +# Being a Perl dummy, the simplest way I can check is if the "Win32" package +# is available. +def find_working_perl(perls): + for perl in perls: + fh = os.popen(perl + ' -e "use Win32;"') + fh.read() + rc = fh.close() + if rc: + continue + return perl + print "Can not find a suitable PERL:" + if perls: + print " the following perl interpreters were found:" + for p in perls: + print " ", p + print " None of these versions appear suitable for building OpenSSL" + else: + print " NO perl interpreters were found on this machine at all!" + print " Please install ActivePerl and ensure it appears on your path" + print "The Python SSL module was not built" + return None + +# Locate the best SSL directory given a few roots to look into. +def find_best_ssl_dir(sources): + candidates = [] + for s in sources: + try: + s = os.path.abspath(s) + fnames = os.listdir(s) + except os.error: + fnames = [] + for fname in fnames: + fqn = os.path.join(s, fname) + if os.path.isdir(fqn) and fname.startswith("openssl-"): + candidates.append(fqn) + # Now we have all the candidates, locate the best. + best_parts = [] + best_name = None + for c in candidates: + parts = re.split("[.-]", os.path.basename(c))[1:] + # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers + if len(parts) >= 4: + continue + if parts > best_parts: + best_parts = parts + best_name = c + if best_name is not None: + print "Found an SSL directory at '%s'" % (best_name,) + else: + print "Could not find an SSL directory in '%s'" % (sources,) + return best_name + +def main(): + debug = "-d" in sys.argv + build_all = "-a" in sys.argv + make_flags = "" + if build_all: + make_flags = "-a" + # perl should be on the path, but we also look in "\perl" and "c:\\perl" + # as "well known" locations + perls = find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"]) + perl = find_working_perl(perls) + if perl is None: + sys.exit(1) + + print "Found a working perl at '%s'" % (perl,) + # Look for SSL 2 levels up from pcbuild - ie, same place zlib etc all live. + ssl_dir = find_best_ssl_dir(("../..",)) + if ssl_dir is None: + sys.exit(1) + + old_cd = os.getcwd() + try: + os.chdir(ssl_dir) + # If the ssl makefiles do not exist, we invoke Perl to generate them. + if not os.path.isfile(os.path.join(ssl_dir, "32.mak")) or \ + not os.path.isfile(os.path.join(ssl_dir, "d32.mak")): + print "Creating the makefiles..." + # Put our working Perl at the front of our path + os.environ["PATH"] = os.path.split(perl)[0] + \ + os.pathsep + \ + os.environ["PATH"] + # ms\32all.bat will reconfigure OpenSSL and then try to build + # all outputs (debug/nondebug/dll/lib). So we filter the file + # to exclude any "nmake" commands and then execute. + tempname = "ms\\32all_py.bat" + + in_bat = open("ms\\32all.bat") + temp_bat = open(tempname,"w") + while 1: + cmd = in_bat.readline() + print 'cmd', repr(cmd) + if not cmd: break + if cmd.strip()[:5].lower() == "nmake": + continue + temp_bat.write(cmd) + in_bat.close() + temp_bat.close() + os.system(tempname) + try: + os.remove(tempname) + except: + pass + + # Now run make. + print "Executing nmake over the ssl makefiles..." + if debug: + rc = os.system("nmake /nologo -f d32.mak") + if rc: + print "Executing d32.mak failed" + print rc + sys.exit(rc) + else: + rc = os.system("nmake /nologo -f 32.mak") + if rc: + print "Executing 32.mak failed" + print rc + sys.exit(rc) + finally: + os.chdir(old_cd) + # And finally, we can build the _ssl module itself for Python. + defs = "SSL_DIR=%s" % (ssl_dir,) + if debug: + defs = defs + " " + "DEBUG=1" + rc = os.system('nmake /nologo -f _ssl.mak ' + defs + " " + make_flags) + sys.exit(rc) + +if __name__=='__main__': + main() diff --git a/PCbuild8/bz2.vcproj b/PCbuild8/bz2.vcproj index c5bf102a14e..48805dba5d8 100644 --- a/PCbuild8/bz2.vcproj +++ b/PCbuild8/bz2.vcproj @@ -1,390 +1,390 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/field3.py b/PCbuild8/field3.py index 8ed94e93c91..47f24ca3cb4 100644 --- a/PCbuild8/field3.py +++ b/PCbuild8/field3.py @@ -1,35 +1,35 @@ -# An absurd workaround for the lack of arithmetic in MS's resource compiler. -# After building Python, run this, then paste the output into the appropriate -# part of PC\python_nt.rc. -# Example output: -# -# * For 2.3a0, -# * PY_MICRO_VERSION = 0 -# * PY_RELEASE_LEVEL = 'alpha' = 0xA -# * PY_RELEASE_SERIAL = 1 -# * -# * and 0*1000 + 10*10 + 1 = 101. -# */ -# #define FIELD3 101 - -import sys - -major, minor, micro, level, serial = sys.version_info -levelnum = {'alpha': 0xA, - 'beta': 0xB, - 'candidate': 0xC, - 'final': 0xF, - }[level] -string = sys.version.split()[0] # like '2.3a0' - -print " * For %s," % string -print " * PY_MICRO_VERSION = %d" % micro -print " * PY_RELEASE_LEVEL = %r = %s" % (level, hex(levelnum)) -print " * PY_RELEASE_SERIAL = %d" % serial -print " *" - -field3 = micro * 1000 + levelnum * 10 + serial - -print " * and %d*1000 + %d*10 + %d = %d" % (micro, levelnum, serial, field3) -print " */" -print "#define FIELD3", field3 +# An absurd workaround for the lack of arithmetic in MS's resource compiler. +# After building Python, run this, then paste the output into the appropriate +# part of PC\python_nt.rc. +# Example output: +# +# * For 2.3a0, +# * PY_MICRO_VERSION = 0 +# * PY_RELEASE_LEVEL = 'alpha' = 0xA +# * PY_RELEASE_SERIAL = 1 +# * +# * and 0*1000 + 10*10 + 1 = 101. +# */ +# #define FIELD3 101 + +import sys + +major, minor, micro, level, serial = sys.version_info +levelnum = {'alpha': 0xA, + 'beta': 0xB, + 'candidate': 0xC, + 'final': 0xF, + }[level] +string = sys.version.split()[0] # like '2.3a0' + +print " * For %s," % string +print " * PY_MICRO_VERSION = %d" % micro +print " * PY_RELEASE_LEVEL = %r = %s" % (level, hex(levelnum)) +print " * PY_RELEASE_SERIAL = %d" % serial +print " *" + +field3 = micro * 1000 + levelnum * 10 + serial + +print " * and %d*1000 + %d*10 + %d = %d" % (micro, levelnum, serial, field3) +print " */" +print "#define FIELD3", field3 diff --git a/PCbuild8/make_buildinfo.c b/PCbuild8/make_buildinfo.c index 022e7afba96..4cebf45ccd8 100644 --- a/PCbuild8/make_buildinfo.c +++ b/PCbuild8/make_buildinfo.c @@ -1,92 +1,92 @@ -#include -#include -#include -#include - -/* This file creates the getbuildinfo.o object, by first - invoking subwcrev.exe (if found), and then invoking cl.exe. - As a side effect, it might generate PCBuild\getbuildinfo2.c - also. If this isn't a subversion checkout, or subwcrev isn't - found, it compiles ..\\Modules\\getbuildinfo.c instead. - - Currently, subwcrev.exe is found from the registry entries - of TortoiseSVN. - - No attempt is made to place getbuildinfo.o into the proper - binary directory. This isn't necessary, as this tool is - invoked as a pre-link step for pythoncore, so that overwrites - any previous getbuildinfo.o. - -*/ - -int make_buildinfo2() -{ - struct _stat st; - HKEY hTortoise; - char command[500]; - DWORD type, size; - if (_stat(".svn", &st) < 0) - return 0; - /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */ - if (_stat("no_subwcrev", &st) == 0) - return 0; - if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS && - RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS) - /* Tortoise not installed */ - return 0; - command[0] = '"'; /* quote the path to the executable */ - size = sizeof(command) - 1; - if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS || - type != REG_SZ) - /* Registry corrupted */ - return 0; - strcat(command, "bin\\subwcrev.exe"); - if (_stat(command+1, &st) < 0) - /* subwcrev.exe not part of the release */ - return 0; - strcat(command, "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c"); - puts(command); fflush(stdout); - if (system(command) < 0) - return 0; - return 1; -} - -int main(int argc, char*argv[]) -{ - char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL "; - int do_unlink, result; - if (argc != 2) { - fprintf(stderr, "make_buildinfo $(ConfigurationName)\n"); - return EXIT_FAILURE; - } - if (strcmp(argv[1], "Release") == 0) { - strcat(command, "-MD "); - } - else if (strcmp(argv[1], "Debug") == 0) { - strcat(command, "-D_DEBUG -MDd "); - } - else if (strcmp(argv[1], "ReleaseItanium") == 0) { - strcat(command, "-MD /USECL:MS_ITANIUM "); - } - else if (strcmp(argv[1], "ReleaseAMD64") == 0) { - strcat(command, "-MD "); - strcat(command, "-MD /USECL:MS_OPTERON "); - } - else { - fprintf(stderr, "unsupported configuration %s\n", argv[1]); - return EXIT_FAILURE; - } - - if ((do_unlink = make_buildinfo2())) - strcat(command, "getbuildinfo2.c -DSUBWCREV "); - else - strcat(command, "..\\Modules\\getbuildinfo.c"); - strcat(command, " -Fogetbuildinfo.o -I..\\Include -I..\\PC"); - puts(command); fflush(stdout); - result = system(command); - if (do_unlink) - unlink("getbuildinfo2.c"); - if (result < 0) - return EXIT_FAILURE; - return 0; +#include +#include +#include +#include + +/* This file creates the getbuildinfo.o object, by first + invoking subwcrev.exe (if found), and then invoking cl.exe. + As a side effect, it might generate PCBuild\getbuildinfo2.c + also. If this isn't a subversion checkout, or subwcrev isn't + found, it compiles ..\\Modules\\getbuildinfo.c instead. + + Currently, subwcrev.exe is found from the registry entries + of TortoiseSVN. + + No attempt is made to place getbuildinfo.o into the proper + binary directory. This isn't necessary, as this tool is + invoked as a pre-link step for pythoncore, so that overwrites + any previous getbuildinfo.o. + +*/ + +int make_buildinfo2() +{ + struct _stat st; + HKEY hTortoise; + char command[500]; + DWORD type, size; + if (_stat(".svn", &st) < 0) + return 0; + /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */ + if (_stat("no_subwcrev", &st) == 0) + return 0; + if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS && + RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS) + /* Tortoise not installed */ + return 0; + command[0] = '"'; /* quote the path to the executable */ + size = sizeof(command) - 1; + if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS || + type != REG_SZ) + /* Registry corrupted */ + return 0; + strcat(command, "bin\\subwcrev.exe"); + if (_stat(command+1, &st) < 0) + /* subwcrev.exe not part of the release */ + return 0; + strcat(command, "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c"); + puts(command); fflush(stdout); + if (system(command) < 0) + return 0; + return 1; +} + +int main(int argc, char*argv[]) +{ + char command[500] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL "; + int do_unlink, result; + if (argc != 2) { + fprintf(stderr, "make_buildinfo $(ConfigurationName)\n"); + return EXIT_FAILURE; + } + if (strcmp(argv[1], "Release") == 0) { + strcat(command, "-MD "); + } + else if (strcmp(argv[1], "Debug") == 0) { + strcat(command, "-D_DEBUG -MDd "); + } + else if (strcmp(argv[1], "ReleaseItanium") == 0) { + strcat(command, "-MD /USECL:MS_ITANIUM "); + } + else if (strcmp(argv[1], "ReleaseAMD64") == 0) { + strcat(command, "-MD "); + strcat(command, "-MD /USECL:MS_OPTERON "); + } + else { + fprintf(stderr, "unsupported configuration %s\n", argv[1]); + return EXIT_FAILURE; + } + + if ((do_unlink = make_buildinfo2())) + strcat(command, "getbuildinfo2.c -DSUBWCREV "); + else + strcat(command, "..\\Modules\\getbuildinfo.c"); + strcat(command, " -Fogetbuildinfo.o -I..\\Include -I..\\PC"); + puts(command); fflush(stdout); + result = system(command); + if (do_unlink) + unlink("getbuildinfo2.c"); + if (result < 0) + return EXIT_FAILURE; + return 0; } \ No newline at end of file diff --git a/PCbuild8/make_buildinfo.vcproj b/PCbuild8/make_buildinfo.vcproj index 45726634671..5dc6bca570a 100644 --- a/PCbuild8/make_buildinfo.vcproj +++ b/PCbuild8/make_buildinfo.vcproj @@ -1,188 +1,188 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/make_versioninfo.vcproj b/PCbuild8/make_versioninfo.vcproj index 852c437e5f2..e9efd53f04a 100644 --- a/PCbuild8/make_versioninfo.vcproj +++ b/PCbuild8/make_versioninfo.vcproj @@ -1,207 +1,204 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/pcbuild.sln b/PCbuild8/pcbuild.sln index 8a53fb2a61c..9f476268731 100644 --- a/PCbuild8/pcbuild.sln +++ b/PCbuild8/pcbuild.sln @@ -1,185 +1,199 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythoncore", "pythoncore.vcproj", "{CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}" - ProjectSection(ProjectDependencies) = postProject - {C73F0EC1-358B-4177-940F-0846AC8B04CD} = {C73F0EC1-358B-4177-940F-0846AC8B04CD} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythonw", "pythonw.vcproj", "{F4229CC3-873C-49AE-9729-DD308ED4CD4A}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "select", "select.vcproj", "{97239A56-DBC0-41D2-BC14-C87D9B97D63B}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unicodedata", "unicodedata.vcproj", "{FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcproj", "{51F35FAE-FB92-4B2C-9187-1542C065AD77}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_elementtree", "_elementtree.vcproj", "{1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_msi", "_msi.vcproj", "{2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes", "_ctypes.vcproj", "{F22F40F4-D318-40DC-96B3-88DC81CE0894}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes_test", "_ctypes_test.vcproj", "{8CF334D9-4F82-42EB-97AF-83592C5AFD2F}" - ProjectSection(ProjectDependencies) = postProject - {F22F40F4-D318-40DC-96B3-88DC81CE0894} = {F22F40F4-D318-40DC-96B3-88DC81CE0894} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_sqlite3", "_sqlite3.vcproj", "{2FF0A312-22F9-4C34-B070-842916DE27A9}" - ProjectSection(ProjectDependencies) = postProject - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8B172265-1F31-4880-A29C-11A4B7A80172}" - ProjectSection(SolutionItems) = preProject - ..\Modules\getbuildinfo.c = ..\Modules\getbuildinfo.c - readme.txt = readme.txt - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythoncore_pgo", "pythoncore_pgo.vcproj", "{8B59C1FF-2439-4BE9-9F24-84D4982D28D4}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "python", "python.vcproj", "{B11D750F-CD1F-4A96-85CE-E69A5C5259F9}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - ReleaseAMD64|Win32 = ReleaseAMD64|Win32 - ReleaseItanium|Win32 = ReleaseItanium|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|Win32.ActiveCfg = Debug|Win32 - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|Win32.Build.0 = Debug|Win32 - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|Win32.ActiveCfg = Release|Win32 - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|Win32.Build.0 = Release|Win32 - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|Win32.ActiveCfg = Debug|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|Win32.Build.0 = Debug|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|Win32.ActiveCfg = Release|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|Win32.Build.0 = Release|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Debug|Win32.ActiveCfg = Debug|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Debug|Win32.Build.0 = Debug|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Release|Win32.ActiveCfg = Release|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Release|Win32.Build.0 = Release|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Debug|Win32.ActiveCfg = Debug|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Debug|Win32.Build.0 = Debug|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Release|Win32.ActiveCfg = Release|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Release|Win32.Build.0 = Release|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|Win32.ActiveCfg = Debug|Win32 - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|Win32.Build.0 = Debug|Win32 - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|Win32.ActiveCfg = Release|Win32 - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|Win32.Build.0 = Release|Win32 - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.ReleaseAMD64|Win32.ActiveCfg = Release|Win32 - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.ReleaseItanium|Win32.ActiveCfg = Release|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Debug|Win32.ActiveCfg = Debug|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Debug|Win32.Build.0 = Debug|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Release|Win32.ActiveCfg = Release|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Release|Win32.Build.0 = Release|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Debug|Win32.ActiveCfg = Debug|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Debug|Win32.Build.0 = Debug|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Release|Win32.ActiveCfg = Release|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Release|Win32.Build.0 = Release|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|Win32.ActiveCfg = Debug|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|Win32.Build.0 = Debug|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|Win32.ActiveCfg = Release|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|Win32.Build.0 = Release|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseAMD64|Win32.ActiveCfg = Release|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseAMD64|Win32.Build.0 = Release|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseItanium|Win32.ActiveCfg = Release|Win32 - {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseItanium|Win32.Build.0 = Release|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Debug|Win32.ActiveCfg = Debug|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Debug|Win32.Build.0 = Debug|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Release|Win32.ActiveCfg = Release|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Release|Win32.Build.0 = Release|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Debug|Win32.ActiveCfg = Debug|Win32 - {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Debug|Win32.Build.0 = Debug|Win32 - {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release|Win32.ActiveCfg = Release|Win32 - {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release|Win32.Build.0 = Release|Win32 - {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug|Win32.ActiveCfg = Debug|Win32 - {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug|Win32.Build.0 = Debug|Win32 - {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release|Win32.ActiveCfg = Release|Win32 - {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release|Win32.Build.0 = Release|Win32 - {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug|Win32.ActiveCfg = Debug|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug|Win32.Build.0 = Debug|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.Release|Win32.ActiveCfg = Release|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.Release|Win32.Build.0 = Release|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Debug|Win32.ActiveCfg = Release|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Debug|Win32.Build.0 = Release|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Release|Win32.ActiveCfg = Release|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Release|Win32.Build.0 = Release|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseAMD64|Win32.ActiveCfg = Release|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseAMD64|Win32.Build.0 = Release|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseItanium|Win32.ActiveCfg = Release|Win32 - {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseItanium|Win32.Build.0 = Release|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|Win32.ActiveCfg = Debug|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|Win32.Build.0 = Debug|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|Win32.ActiveCfg = Release|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|Win32.Build.0 = Release|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 - {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythoncore", "pythoncore.vcproj", "{CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}" + ProjectSection(ProjectDependencies) = postProject + {C73F0EC1-358B-4177-940F-0846AC8B04CD} = {C73F0EC1-358B-4177-940F-0846AC8B04CD} + {F0E0541E-F17D-430B-97C4-93ADF0DD284E} = {F0E0541E-F17D-430B-97C4-93ADF0DD284E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythonw", "pythonw.vcproj", "{F4229CC3-873C-49AE-9729-DD308ED4CD4A}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "select", "select.vcproj", "{97239A56-DBC0-41D2-BC14-C87D9B97D63B}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unicodedata", "unicodedata.vcproj", "{FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcproj", "{51F35FAE-FB92-4B2C-9187-1542C065AD77}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_elementtree", "_elementtree.vcproj", "{1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_msi", "_msi.vcproj", "{2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes", "_ctypes.vcproj", "{F22F40F4-D318-40DC-96B3-88DC81CE0894}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_ctypes_test", "_ctypes_test.vcproj", "{8CF334D9-4F82-42EB-97AF-83592C5AFD2F}" + ProjectSection(ProjectDependencies) = postProject + {F22F40F4-D318-40DC-96B3-88DC81CE0894} = {F22F40F4-D318-40DC-96B3-88DC81CE0894} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_sqlite3", "_sqlite3.vcproj", "{2FF0A312-22F9-4C34-B070-842916DE27A9}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8B172265-1F31-4880-A29C-11A4B7A80172}" + ProjectSection(SolutionItems) = preProject + ..\Modules\getbuildinfo.c = ..\Modules\getbuildinfo.c + readme.txt = readme.txt + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythoncore_pgo", "pythoncore_pgo.vcproj", "{8B59C1FF-2439-4BE9-9F24-84D4982D28D4}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "python", "python.vcproj", "{B11D750F-CD1F-4A96-85CE-E69A5C5259F9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_versioninfo", "make_versioninfo.vcproj", "{F0E0541E-F17D-430B-97C4-93ADF0DD284E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + ReleaseAMD64|Win32 = ReleaseAMD64|Win32 + ReleaseItanium|Win32 = ReleaseItanium|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|Win32.ActiveCfg = Debug|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Debug|Win32.Build.0 = Debug|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|Win32.ActiveCfg = Release|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.Release|Win32.Build.0 = Release|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|Win32.ActiveCfg = Debug|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Debug|Win32.Build.0 = Debug|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|Win32.ActiveCfg = Release|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.Release|Win32.Build.0 = Release|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {F4229CC3-873C-49AE-9729-DD308ED4CD4A}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Debug|Win32.ActiveCfg = Debug|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Debug|Win32.Build.0 = Debug|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Release|Win32.ActiveCfg = Release|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.Release|Win32.Build.0 = Release|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {97239A56-DBC0-41D2-BC14-C87D9B97D63B}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Debug|Win32.ActiveCfg = Debug|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Debug|Win32.Build.0 = Debug|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Release|Win32.ActiveCfg = Release|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.Release|Win32.Build.0 = Release|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {FA5FC7EB-C72F-415F-AE42-91DD605ABDDA}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|Win32.ActiveCfg = Debug|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Debug|Win32.Build.0 = Debug|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|Win32.ActiveCfg = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.Release|Win32.Build.0 = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.ReleaseAMD64|Win32.ActiveCfg = Release|Win32 + {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}.ReleaseItanium|Win32.ActiveCfg = Release|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Debug|Win32.ActiveCfg = Debug|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Debug|Win32.Build.0 = Debug|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Release|Win32.ActiveCfg = Release|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.Release|Win32.Build.0 = Release|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {51F35FAE-FB92-4B2C-9187-1542C065AD77}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Debug|Win32.ActiveCfg = Debug|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Debug|Win32.Build.0 = Debug|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Release|Win32.ActiveCfg = Release|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.Release|Win32.Build.0 = Release|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {1966DDE2-4AB7-4E4E-ACC9-C121E4D37F8E}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|Win32.ActiveCfg = Debug|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Debug|Win32.Build.0 = Debug|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|Win32.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.Release|Win32.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseAMD64|Win32.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseAMD64|Win32.Build.0 = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseItanium|Win32.ActiveCfg = Release|Win32 + {C73F0EC1-358B-4177-940F-0846AC8B04CD}.ReleaseItanium|Win32.Build.0 = Release|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Debug|Win32.ActiveCfg = Debug|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Debug|Win32.Build.0 = Debug|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Release|Win32.ActiveCfg = Release|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.Release|Win32.Build.0 = Release|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {2C0BEFB9-70E2-4F80-AC5B-4AB8EE023574}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Debug|Win32.ActiveCfg = Debug|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Debug|Win32.Build.0 = Debug|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release|Win32.ActiveCfg = Release|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release|Win32.Build.0 = Release|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug|Win32.ActiveCfg = Debug|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug|Win32.Build.0 = Debug|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release|Win32.ActiveCfg = Release|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release|Win32.Build.0 = Release|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug|Win32.ActiveCfg = Debug|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug|Win32.Build.0 = Debug|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Release|Win32.ActiveCfg = Release|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.Release|Win32.Build.0 = Release|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {2FF0A312-22F9-4C34-B070-842916DE27A9}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Debug|Win32.ActiveCfg = Release|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Debug|Win32.Build.0 = Release|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Release|Win32.ActiveCfg = Release|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.Release|Win32.Build.0 = Release|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseAMD64|Win32.ActiveCfg = Release|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseAMD64|Win32.Build.0 = Release|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseItanium|Win32.ActiveCfg = Release|Win32 + {8B59C1FF-2439-4BE9-9F24-84D4982D28D4}.ReleaseItanium|Win32.Build.0 = Release|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|Win32.ActiveCfg = Debug|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Debug|Win32.Build.0 = Debug|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|Win32.ActiveCfg = Release|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.Release|Win32.Build.0 = Release|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseAMD64|Win32.ActiveCfg = ReleaseAMD64|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseAMD64|Win32.Build.0 = ReleaseAMD64|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseItanium|Win32.ActiveCfg = ReleaseItanium|Win32 + {B11D750F-CD1F-4A96-85CE-E69A5C5259F9}.ReleaseItanium|Win32.Build.0 = ReleaseItanium|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug|Win32.ActiveCfg = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Debug|Win32.Build.0 = Debug|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release|Win32.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.Release|Win32.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseAMD64|Win32.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseAMD64|Win32.Build.0 = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseItanium|Win32.ActiveCfg = Release|Win32 + {F0E0541E-F17D-430B-97C4-93ADF0DD284E}.ReleaseItanium|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/PCbuild8/pyexpat.vcproj b/PCbuild8/pyexpat.vcproj index 2ca207b9486..bc449cd2729 100644 --- a/PCbuild8/pyexpat.vcproj +++ b/PCbuild8/pyexpat.vcproj @@ -1,393 +1,393 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/python.vcproj b/PCbuild8/python.vcproj index 88bcc8f1b53..555df913059 100644 --- a/PCbuild8/python.vcproj +++ b/PCbuild8/python.vcproj @@ -1,400 +1,400 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/pythoncore.vcproj b/PCbuild8/pythoncore.vcproj index 156fabd7a6b..5fa154b1cfb 100644 --- a/PCbuild8/pythoncore.vcproj +++ b/PCbuild8/pythoncore.vcproj @@ -1,1103 +1,1099 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/pythoncore_link.txt b/PCbuild8/pythoncore_link.txt deleted file mode 100644 index 8dfdf71c3a0..00000000000 --- a/PCbuild8/pythoncore_link.txt +++ /dev/null @@ -1,311 +0,0 @@ -/OUT:"./python25.dll" /INCREMENTAL:NO /DLL /MANIFEST /MANIFESTFILE:".\x86-temp-release\pythoncore\python25.dll.intermediate.manifest" /NODEFAULTLIB:"libc" /DEBUG /PDB:".\./python25.pdb" /SUBSYSTEM:WINDOWS /LTCG:PGINSTRUMENT /PGD:"c:\pydev\PCbuild\python25.pgd" /BASE:"0x1e000000" /IMPLIB:".\./python25.lib" /MACHINE:X86 getbuildinfo.o kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib - -".\x86-temp-release\pythoncore\adler32.obj" - -".\x86-temp-release\pythoncore\compress.obj" - -".\x86-temp-release\pythoncore\crc32.obj" - -".\x86-temp-release\pythoncore\deflate.obj" - -".\x86-temp-release\pythoncore\gzio.obj" - -".\x86-temp-release\pythoncore\infback.obj" - -".\x86-temp-release\pythoncore\inffast.obj" - -".\x86-temp-release\pythoncore\inflate.obj" - -".\x86-temp-release\pythoncore\inftrees.obj" - -".\x86-temp-release\pythoncore\trees.obj" - -".\x86-temp-release\pythoncore\uncompr.obj" - -".\x86-temp-release\pythoncore\zlibmodule.obj" - -".\x86-temp-release\pythoncore\zutil.obj" - -".\x86-temp-release\pythoncore\_bisectmodule.obj" - -".\x86-temp-release\pythoncore\_codecs_cn.obj" - -".\x86-temp-release\pythoncore\_codecs_hk.obj" - -".\x86-temp-release\pythoncore\_codecs_iso2022.obj" - -".\x86-temp-release\pythoncore\_codecs_jp.obj" - -".\x86-temp-release\pythoncore\_codecs_kr.obj" - -".\x86-temp-release\pythoncore\_codecs_tw.obj" - -".\x86-temp-release\pythoncore\_codecsmodule.obj" - -".\x86-temp-release\pythoncore\_csv.obj" - -".\x86-temp-release\pythoncore\_heapqmodule.obj" - -".\x86-temp-release\pythoncore\_hotshot.obj" - -".\x86-temp-release\pythoncore\_localemodule.obj" - -".\x86-temp-release\pythoncore\_lsprof.obj" - -".\x86-temp-release\pythoncore\_randommodule.obj" - -".\x86-temp-release\pythoncore\_sre.obj" - -".\x86-temp-release\pythoncore\_subprocess.obj" - -".\x86-temp-release\pythoncore\_weakref.obj" - -".\x86-temp-release\pythoncore\_winreg.obj" - -".\x86-temp-release\pythoncore\abstract.obj" - -".\x86-temp-release\pythoncore\acceler.obj" - -".\x86-temp-release\pythoncore\arraymodule.obj" - -".\x86-temp-release\pythoncore\asdl.obj" - -".\x86-temp-release\pythoncore\ast.obj" - -".\x86-temp-release\pythoncore\audioop.obj" - -".\x86-temp-release\pythoncore\binascii.obj" - -".\x86-temp-release\pythoncore\bitset.obj" - -".\x86-temp-release\pythoncore\bltinmodule.obj" - -".\x86-temp-release\pythoncore\boolobject.obj" - -".\x86-temp-release\pythoncore\bufferobject.obj" - -".\x86-temp-release\pythoncore\cellobject.obj" - -".\x86-temp-release\pythoncore\ceval.obj" - -".\x86-temp-release\pythoncore\classobject.obj" - -".\x86-temp-release\pythoncore\cmathmodule.obj" - -".\x86-temp-release\pythoncore\cobject.obj" - -".\x86-temp-release\pythoncore\codecs.obj" - -".\x86-temp-release\pythoncore\codeobject.obj" - -".\x86-temp-release\pythoncore\collectionsmodule.obj" - -".\x86-temp-release\pythoncore\compile.obj" - -".\x86-temp-release\pythoncore\complexobject.obj" - -".\x86-temp-release\pythoncore\config.obj" - -".\x86-temp-release\pythoncore\cPickle.obj" - -".\x86-temp-release\pythoncore\cStringIO.obj" - -".\x86-temp-release\pythoncore\datetimemodule.obj" - -".\x86-temp-release\pythoncore\descrobject.obj" - -".\x86-temp-release\pythoncore\dictobject.obj" - -".\x86-temp-release\pythoncore\dl_nt.obj" - -".\x86-temp-release\pythoncore\dynload_win.obj" - -".\x86-temp-release\pythoncore\enumobject.obj" - -".\x86-temp-release\pythoncore\errnomodule.obj" - -".\x86-temp-release\pythoncore\errors.obj" - -".\x86-temp-release\pythoncore\exceptions.obj" - -".\x86-temp-release\pythoncore\fileobject.obj" - -".\x86-temp-release\pythoncore\firstsets.obj" - -".\x86-temp-release\pythoncore\floatobject.obj" - -".\x86-temp-release\pythoncore\frameobject.obj" - -".\x86-temp-release\pythoncore\frozen.obj" - -".\x86-temp-release\pythoncore\funcobject.obj" - -".\x86-temp-release\pythoncore\functionalmodule.obj" - -".\x86-temp-release\pythoncore\future.obj" - -".\x86-temp-release\pythoncore\gcmodule.obj" - -".\x86-temp-release\pythoncore\genobject.obj" - -".\x86-temp-release\pythoncore\getargs.obj" - -".\x86-temp-release\pythoncore\getcompiler.obj" - -".\x86-temp-release\pythoncore\getcopyright.obj" - -".\x86-temp-release\pythoncore\getmtime.obj" - -".\x86-temp-release\pythoncore\getopt.obj" - -".\x86-temp-release\pythoncore\getpathp.obj" - -".\x86-temp-release\pythoncore\getplatform.obj" - -".\x86-temp-release\pythoncore\getversion.obj" - -".\x86-temp-release\pythoncore\graminit.obj" - -".\x86-temp-release\pythoncore\grammar.obj" - -".\x86-temp-release\pythoncore\grammar1.obj" - -".\x86-temp-release\pythoncore\imageop.obj" - -".\x86-temp-release\pythoncore\import.obj" - -".\x86-temp-release\pythoncore\import_nt.obj" - -".\x86-temp-release\pythoncore\importdl.obj" - -".\x86-temp-release\pythoncore\intobject.obj" - -".\x86-temp-release\pythoncore\iterobject.obj" - -".\x86-temp-release\pythoncore\itertoolsmodule.obj" - -".\x86-temp-release\pythoncore\listnode.obj" - -".\x86-temp-release\pythoncore\listobject.obj" - -".\x86-temp-release\pythoncore\longobject.obj" - -".\x86-temp-release\pythoncore\main.obj" - -".\x86-temp-release\pythoncore\marshal.obj" - -".\x86-temp-release\pythoncore\mathmodule.obj" - -".\x86-temp-release\pythoncore\md5.obj" - -".\x86-temp-release\pythoncore\md5module.obj" - -".\x86-temp-release\pythoncore\metagrammar.obj" - -".\x86-temp-release\pythoncore\methodobject.obj" - -".\x86-temp-release\pythoncore\mmapmodule.obj" - -".\x86-temp-release\pythoncore\modsupport.obj" - -".\x86-temp-release\pythoncore\moduleobject.obj" - -".\x86-temp-release\pythoncore\msvcrtmodule.obj" - -".\x86-temp-release\pythoncore\multibytecodec.obj" - -".\x86-temp-release\pythoncore\myreadline.obj" - -".\x86-temp-release\pythoncore\mysnprintf.obj" - -".\x86-temp-release\pythoncore\mystrtoul.obj" - -".\x86-temp-release\pythoncore\node.obj" - -".\x86-temp-release\pythoncore\object.obj" - -".\x86-temp-release\pythoncore\obmalloc.obj" - -".\x86-temp-release\pythoncore\operator.obj" - -".\x86-temp-release\pythoncore\parser.obj" - -".\x86-temp-release\pythoncore\parsermodule.obj" - -".\x86-temp-release\pythoncore\parsetok.obj" - -".\x86-temp-release\pythoncore\posixmodule.obj" - -".\x86-temp-release\pythoncore\pyarena.obj" - -".\x86-temp-release\pythoncore\pyfpe.obj" - -".\x86-temp-release\pythoncore\pystate.obj" - -".\x86-temp-release\pythoncore\pystrtod.obj" - -".\x86-temp-release\pythoncore\Python-ast.obj" - -".\x86-temp-release\pythoncore\python_nt.res" - -".\x86-temp-release\pythoncore\pythonrun.obj" - -".\x86-temp-release\pythoncore\rangeobject.obj" - -".\x86-temp-release\pythoncore\rgbimgmodule.obj" - -".\x86-temp-release\pythoncore\rotatingtree.obj" - -".\x86-temp-release\pythoncore\setobject.obj" - -".\x86-temp-release\pythoncore\sha256module.obj" - -".\x86-temp-release\pythoncore\sha512module.obj" - -".\x86-temp-release\pythoncore\shamodule.obj" - -".\x86-temp-release\pythoncore\signalmodule.obj" - -".\x86-temp-release\pythoncore\sliceobject.obj" - -".\x86-temp-release\pythoncore\stringobject.obj" - -".\x86-temp-release\pythoncore\stropmodule.obj" - -".\x86-temp-release\pythoncore\structmember.obj" - -".\x86-temp-release\pythoncore\_struct.obj" - -".\x86-temp-release\pythoncore\structseq.obj" - -".\x86-temp-release\pythoncore\symtable.obj" - -".\x86-temp-release\pythoncore\symtablemodule.obj" - -".\x86-temp-release\pythoncore\sysmodule.obj" - -".\x86-temp-release\pythoncore\thread.obj" - -".\x86-temp-release\pythoncore\threadmodule.obj" - -".\x86-temp-release\pythoncore\timemodule.obj" - -".\x86-temp-release\pythoncore\tokenizer.obj" - -".\x86-temp-release\pythoncore\traceback.obj" - -".\x86-temp-release\pythoncore\tupleobject.obj" - -".\x86-temp-release\pythoncore\typeobject.obj" - -".\x86-temp-release\pythoncore\unicodectype.obj" - -".\x86-temp-release\pythoncore\unicodeobject.obj" - -".\x86-temp-release\pythoncore\weakrefobject.obj" - -".\x86-temp-release\pythoncore\xxsubtype.obj" - -".\x86-temp-release\pythoncore\yuvconvert.obj" - -".\x86-temp-release\pythoncore\zipimport.obj" \ No newline at end of file diff --git a/PCbuild8/pythoncore_pgo.vcproj b/PCbuild8/pythoncore_pgo.vcproj index 6353bb960c4..9a312ad0094 100644 --- a/PCbuild8/pythoncore_pgo.vcproj +++ b/PCbuild8/pythoncore_pgo.vcproj @@ -1,781 +1,781 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/pythoncore_pgo_link.txt b/PCbuild8/pythoncore_pgo_link.txt index 199d70b1312..cf43e6f9213 100644 --- a/PCbuild8/pythoncore_pgo_link.txt +++ b/PCbuild8/pythoncore_pgo_link.txt @@ -1,311 +1,311 @@ -/OUT:".\pythoncore_pgo/python25.dll" /INCREMENTAL:NO /DLL /MANIFEST /MANIFESTFILE:".\x86-temp-release\pythoncore_pgo\python25.dll.intermediate.manifest" /NODEFAULTLIB:"libc" /DEBUG /PDB:".\pythoncore_pgo/python25.pdb" /SUBSYSTEM:WINDOWS /LTCG:PGINSTRUMENT /PGD:"c:\pydev\PCbuild\pythoncore_pgo\python25.pgd" /BASE:"0x1e000000" /IMPLIB:"pythoncore_pgo/python25.lib" /MACHINE:X86 getbuildinfo.o kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib - -".\x86-temp-release\pythoncore_pgo\adler32.obj" - -".\x86-temp-release\pythoncore_pgo\compress.obj" - -".\x86-temp-release\pythoncore_pgo\crc32.obj" - -".\x86-temp-release\pythoncore_pgo\deflate.obj" - -".\x86-temp-release\pythoncore_pgo\gzio.obj" - -".\x86-temp-release\pythoncore_pgo\infback.obj" - -".\x86-temp-release\pythoncore_pgo\inffast.obj" - -".\x86-temp-release\pythoncore_pgo\inflate.obj" - -".\x86-temp-release\pythoncore_pgo\inftrees.obj" - -".\x86-temp-release\pythoncore_pgo\trees.obj" - -".\x86-temp-release\pythoncore_pgo\uncompr.obj" - -".\x86-temp-release\pythoncore_pgo\zlibmodule.obj" - -".\x86-temp-release\pythoncore_pgo\zutil.obj" - -".\x86-temp-release\pythoncore_pgo\_bisectmodule.obj" - -".\x86-temp-release\pythoncore_pgo\_codecs_cn.obj" - -".\x86-temp-release\pythoncore_pgo\_codecs_hk.obj" - -".\x86-temp-release\pythoncore_pgo\_codecs_iso2022.obj" - -".\x86-temp-release\pythoncore_pgo\_codecs_jp.obj" - -".\x86-temp-release\pythoncore_pgo\_codecs_kr.obj" - -".\x86-temp-release\pythoncore_pgo\_codecs_tw.obj" - -".\x86-temp-release\pythoncore_pgo\_codecsmodule.obj" - -".\x86-temp-release\pythoncore_pgo\_csv.obj" - -".\x86-temp-release\pythoncore_pgo\_heapqmodule.obj" - -".\x86-temp-release\pythoncore_pgo\_hotshot.obj" - -".\x86-temp-release\pythoncore_pgo\_localemodule.obj" - -".\x86-temp-release\pythoncore_pgo\_lsprof.obj" - -".\x86-temp-release\pythoncore_pgo\_randommodule.obj" - -".\x86-temp-release\pythoncore_pgo\_sre.obj" - -".\x86-temp-release\pythoncore_pgo\_struct.obj" - -".\x86-temp-release\pythoncore_pgo\_subprocess.obj" - -".\x86-temp-release\pythoncore_pgo\_weakref.obj" - -".\x86-temp-release\pythoncore_pgo\_winreg.obj" - -".\x86-temp-release\pythoncore_pgo\abstract.obj" - -".\x86-temp-release\pythoncore_pgo\acceler.obj" - -".\x86-temp-release\pythoncore_pgo\arraymodule.obj" - -".\x86-temp-release\pythoncore_pgo\asdl.obj" - -".\x86-temp-release\pythoncore_pgo\ast.obj" - -".\x86-temp-release\pythoncore_pgo\audioop.obj" - -".\x86-temp-release\pythoncore_pgo\binascii.obj" - -".\x86-temp-release\pythoncore_pgo\bitset.obj" - -".\x86-temp-release\pythoncore_pgo\bltinmodule.obj" - -".\x86-temp-release\pythoncore_pgo\boolobject.obj" - -".\x86-temp-release\pythoncore_pgo\bufferobject.obj" - -".\x86-temp-release\pythoncore_pgo\cellobject.obj" - -".\x86-temp-release\pythoncore_pgo\ceval.obj" - -".\x86-temp-release\pythoncore_pgo\classobject.obj" - -".\x86-temp-release\pythoncore_pgo\cmathmodule.obj" - -".\x86-temp-release\pythoncore_pgo\cobject.obj" - -".\x86-temp-release\pythoncore_pgo\codecs.obj" - -".\x86-temp-release\pythoncore_pgo\codeobject.obj" - -".\x86-temp-release\pythoncore_pgo\collectionsmodule.obj" - -".\x86-temp-release\pythoncore_pgo\compile.obj" - -".\x86-temp-release\pythoncore_pgo\complexobject.obj" - -".\x86-temp-release\pythoncore_pgo\config.obj" - -".\x86-temp-release\pythoncore_pgo\cPickle.obj" - -".\x86-temp-release\pythoncore_pgo\cStringIO.obj" - -".\x86-temp-release\pythoncore_pgo\datetimemodule.obj" - -".\x86-temp-release\pythoncore_pgo\descrobject.obj" - -".\x86-temp-release\pythoncore_pgo\dictobject.obj" - -".\x86-temp-release\pythoncore_pgo\dl_nt.obj" - -".\x86-temp-release\pythoncore_pgo\dynload_win.obj" - -".\x86-temp-release\pythoncore_pgo\enumobject.obj" - -".\x86-temp-release\pythoncore_pgo\errnomodule.obj" - -".\x86-temp-release\pythoncore_pgo\errors.obj" - -".\x86-temp-release\pythoncore_pgo\exceptions.obj" - -".\x86-temp-release\pythoncore_pgo\fileobject.obj" - -".\x86-temp-release\pythoncore_pgo\firstsets.obj" - -".\x86-temp-release\pythoncore_pgo\floatobject.obj" - -".\x86-temp-release\pythoncore_pgo\frameobject.obj" - -".\x86-temp-release\pythoncore_pgo\frozen.obj" - -".\x86-temp-release\pythoncore_pgo\funcobject.obj" - -".\x86-temp-release\pythoncore_pgo\functionalmodule.obj" - -".\x86-temp-release\pythoncore_pgo\future.obj" - -".\x86-temp-release\pythoncore_pgo\gcmodule.obj" - -".\x86-temp-release\pythoncore_pgo\genobject.obj" - -".\x86-temp-release\pythoncore_pgo\getargs.obj" - -".\x86-temp-release\pythoncore_pgo\getcompiler.obj" - -".\x86-temp-release\pythoncore_pgo\getcopyright.obj" - -".\x86-temp-release\pythoncore_pgo\getmtime.obj" - -".\x86-temp-release\pythoncore_pgo\getopt.obj" - -".\x86-temp-release\pythoncore_pgo\getpathp.obj" - -".\x86-temp-release\pythoncore_pgo\getplatform.obj" - -".\x86-temp-release\pythoncore_pgo\getversion.obj" - -".\x86-temp-release\pythoncore_pgo\graminit.obj" - -".\x86-temp-release\pythoncore_pgo\grammar.obj" - -".\x86-temp-release\pythoncore_pgo\grammar1.obj" - -".\x86-temp-release\pythoncore_pgo\imageop.obj" - -".\x86-temp-release\pythoncore_pgo\import.obj" - -".\x86-temp-release\pythoncore_pgo\import_nt.obj" - -".\x86-temp-release\pythoncore_pgo\importdl.obj" - -".\x86-temp-release\pythoncore_pgo\intobject.obj" - -".\x86-temp-release\pythoncore_pgo\iterobject.obj" - -".\x86-temp-release\pythoncore_pgo\itertoolsmodule.obj" - -".\x86-temp-release\pythoncore_pgo\listnode.obj" - -".\x86-temp-release\pythoncore_pgo\listobject.obj" - -".\x86-temp-release\pythoncore_pgo\longobject.obj" - -".\x86-temp-release\pythoncore_pgo\main.obj" - -".\x86-temp-release\pythoncore_pgo\marshal.obj" - -".\x86-temp-release\pythoncore_pgo\mathmodule.obj" - -".\x86-temp-release\pythoncore_pgo\md5.obj" - -".\x86-temp-release\pythoncore_pgo\md5module.obj" - -".\x86-temp-release\pythoncore_pgo\metagrammar.obj" - -".\x86-temp-release\pythoncore_pgo\methodobject.obj" - -".\x86-temp-release\pythoncore_pgo\mmapmodule.obj" - -".\x86-temp-release\pythoncore_pgo\modsupport.obj" - -".\x86-temp-release\pythoncore_pgo\moduleobject.obj" - -".\x86-temp-release\pythoncore_pgo\msvcrtmodule.obj" - -".\x86-temp-release\pythoncore_pgo\multibytecodec.obj" - -".\x86-temp-release\pythoncore_pgo\myreadline.obj" - -".\x86-temp-release\pythoncore_pgo\mysnprintf.obj" - -".\x86-temp-release\pythoncore_pgo\mystrtoul.obj" - -".\x86-temp-release\pythoncore_pgo\node.obj" - -".\x86-temp-release\pythoncore_pgo\object.obj" - -".\x86-temp-release\pythoncore_pgo\obmalloc.obj" - -".\x86-temp-release\pythoncore_pgo\operator.obj" - -".\x86-temp-release\pythoncore_pgo\parser.obj" - -".\x86-temp-release\pythoncore_pgo\parsermodule.obj" - -".\x86-temp-release\pythoncore_pgo\parsetok.obj" - -".\x86-temp-release\pythoncore_pgo\posixmodule.obj" - -".\x86-temp-release\pythoncore_pgo\pyarena.obj" - -".\x86-temp-release\pythoncore_pgo\pyfpe.obj" - -".\x86-temp-release\pythoncore_pgo\pystate.obj" - -".\x86-temp-release\pythoncore_pgo\pystrtod.obj" - -".\x86-temp-release\pythoncore_pgo\Python-ast.obj" - -".\x86-temp-release\pythoncore_pgo\python_nt.res" - -".\x86-temp-release\pythoncore_pgo\pythonrun.obj" - -".\x86-temp-release\pythoncore_pgo\rangeobject.obj" - -".\x86-temp-release\pythoncore_pgo\rgbimgmodule.obj" - -".\x86-temp-release\pythoncore_pgo\rotatingtree.obj" - -".\x86-temp-release\pythoncore_pgo\setobject.obj" - -".\x86-temp-release\pythoncore_pgo\sha256module.obj" - -".\x86-temp-release\pythoncore_pgo\sha512module.obj" - -".\x86-temp-release\pythoncore_pgo\shamodule.obj" - -".\x86-temp-release\pythoncore_pgo\signalmodule.obj" - -".\x86-temp-release\pythoncore_pgo\sliceobject.obj" - -".\x86-temp-release\pythoncore_pgo\stringobject.obj" - -".\x86-temp-release\pythoncore_pgo\stropmodule.obj" - -".\x86-temp-release\pythoncore_pgo\structmember.obj" - -".\x86-temp-release\pythoncore_pgo\structseq.obj" - -".\x86-temp-release\pythoncore_pgo\symtable.obj" - -".\x86-temp-release\pythoncore_pgo\symtablemodule.obj" - -".\x86-temp-release\pythoncore_pgo\sysmodule.obj" - -".\x86-temp-release\pythoncore_pgo\thread.obj" - -".\x86-temp-release\pythoncore_pgo\threadmodule.obj" - -".\x86-temp-release\pythoncore_pgo\timemodule.obj" - -".\x86-temp-release\pythoncore_pgo\tokenizer.obj" - -".\x86-temp-release\pythoncore_pgo\traceback.obj" - -".\x86-temp-release\pythoncore_pgo\tupleobject.obj" - -".\x86-temp-release\pythoncore_pgo\typeobject.obj" - -".\x86-temp-release\pythoncore_pgo\unicodectype.obj" - -".\x86-temp-release\pythoncore_pgo\unicodeobject.obj" - -".\x86-temp-release\pythoncore_pgo\weakrefobject.obj" - -".\x86-temp-release\pythoncore_pgo\xxsubtype.obj" - -".\x86-temp-release\pythoncore_pgo\yuvconvert.obj" - -".\x86-temp-release\pythoncore_pgo\zipimport.obj" +/OUT:".\pythoncore_pgo/python25.dll" /INCREMENTAL:NO /DLL /MANIFEST /MANIFESTFILE:".\x86-temp-release\pythoncore_pgo\python25.dll.intermediate.manifest" /NODEFAULTLIB:"libc" /DEBUG /PDB:".\pythoncore_pgo/python25.pdb" /SUBSYSTEM:WINDOWS /LTCG:PGINSTRUMENT /PGD:".\pythoncore_pgo\python25.pgd" /BASE:"0x1e000000" /IMPLIB:"pythoncore_pgo/python25.lib" /MACHINE:X86 getbuildinfo.o kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib + +".\x86-temp-release\pythoncore_pgo\adler32.obj" + +".\x86-temp-release\pythoncore_pgo\compress.obj" + +".\x86-temp-release\pythoncore_pgo\crc32.obj" + +".\x86-temp-release\pythoncore_pgo\deflate.obj" + +".\x86-temp-release\pythoncore_pgo\gzio.obj" + +".\x86-temp-release\pythoncore_pgo\infback.obj" + +".\x86-temp-release\pythoncore_pgo\inffast.obj" + +".\x86-temp-release\pythoncore_pgo\inflate.obj" + +".\x86-temp-release\pythoncore_pgo\inftrees.obj" + +".\x86-temp-release\pythoncore_pgo\trees.obj" + +".\x86-temp-release\pythoncore_pgo\uncompr.obj" + +".\x86-temp-release\pythoncore_pgo\zlibmodule.obj" + +".\x86-temp-release\pythoncore_pgo\zutil.obj" + +".\x86-temp-release\pythoncore_pgo\_bisectmodule.obj" + +".\x86-temp-release\pythoncore_pgo\_codecs_cn.obj" + +".\x86-temp-release\pythoncore_pgo\_codecs_hk.obj" + +".\x86-temp-release\pythoncore_pgo\_codecs_iso2022.obj" + +".\x86-temp-release\pythoncore_pgo\_codecs_jp.obj" + +".\x86-temp-release\pythoncore_pgo\_codecs_kr.obj" + +".\x86-temp-release\pythoncore_pgo\_codecs_tw.obj" + +".\x86-temp-release\pythoncore_pgo\_codecsmodule.obj" + +".\x86-temp-release\pythoncore_pgo\_csv.obj" + +".\x86-temp-release\pythoncore_pgo\_functoolsmodule.obj" + +".\x86-temp-release\pythoncore_pgo\_heapqmodule.obj" + +".\x86-temp-release\pythoncore_pgo\_hotshot.obj" + +".\x86-temp-release\pythoncore_pgo\_localemodule.obj" + +".\x86-temp-release\pythoncore_pgo\_lsprof.obj" + +".\x86-temp-release\pythoncore_pgo\_randommodule.obj" + +".\x86-temp-release\pythoncore_pgo\_sre.obj" + +".\x86-temp-release\pythoncore_pgo\_struct.obj" + +".\x86-temp-release\pythoncore_pgo\_subprocess.obj" + +".\x86-temp-release\pythoncore_pgo\_weakref.obj" + +".\x86-temp-release\pythoncore_pgo\_winreg.obj" + +".\x86-temp-release\pythoncore_pgo\abstract.obj" + +".\x86-temp-release\pythoncore_pgo\acceler.obj" + +".\x86-temp-release\pythoncore_pgo\arraymodule.obj" + +".\x86-temp-release\pythoncore_pgo\asdl.obj" + +".\x86-temp-release\pythoncore_pgo\ast.obj" + +".\x86-temp-release\pythoncore_pgo\audioop.obj" + +".\x86-temp-release\pythoncore_pgo\binascii.obj" + +".\x86-temp-release\pythoncore_pgo\bitset.obj" + +".\x86-temp-release\pythoncore_pgo\bltinmodule.obj" + +".\x86-temp-release\pythoncore_pgo\boolobject.obj" + +".\x86-temp-release\pythoncore_pgo\bufferobject.obj" + +".\x86-temp-release\pythoncore_pgo\cellobject.obj" + +".\x86-temp-release\pythoncore_pgo\ceval.obj" + +".\x86-temp-release\pythoncore_pgo\classobject.obj" + +".\x86-temp-release\pythoncore_pgo\cmathmodule.obj" + +".\x86-temp-release\pythoncore_pgo\cobject.obj" + +".\x86-temp-release\pythoncore_pgo\codecs.obj" + +".\x86-temp-release\pythoncore_pgo\codeobject.obj" + +".\x86-temp-release\pythoncore_pgo\collectionsmodule.obj" + +".\x86-temp-release\pythoncore_pgo\compile.obj" + +".\x86-temp-release\pythoncore_pgo\complexobject.obj" + +".\x86-temp-release\pythoncore_pgo\config.obj" + +".\x86-temp-release\pythoncore_pgo\cPickle.obj" + +".\x86-temp-release\pythoncore_pgo\cStringIO.obj" + +".\x86-temp-release\pythoncore_pgo\datetimemodule.obj" + +".\x86-temp-release\pythoncore_pgo\descrobject.obj" + +".\x86-temp-release\pythoncore_pgo\dictobject.obj" + +".\x86-temp-release\pythoncore_pgo\dl_nt.obj" + +".\x86-temp-release\pythoncore_pgo\dynload_win.obj" + +".\x86-temp-release\pythoncore_pgo\enumobject.obj" + +".\x86-temp-release\pythoncore_pgo\errnomodule.obj" + +".\x86-temp-release\pythoncore_pgo\errors.obj" + +".\x86-temp-release\pythoncore_pgo\exceptions.obj" + +".\x86-temp-release\pythoncore_pgo\fileobject.obj" + +".\x86-temp-release\pythoncore_pgo\firstsets.obj" + +".\x86-temp-release\pythoncore_pgo\floatobject.obj" + +".\x86-temp-release\pythoncore_pgo\frameobject.obj" + +".\x86-temp-release\pythoncore_pgo\frozen.obj" + +".\x86-temp-release\pythoncore_pgo\funcobject.obj" + +".\x86-temp-release\pythoncore_pgo\future.obj" + +".\x86-temp-release\pythoncore_pgo\gcmodule.obj" + +".\x86-temp-release\pythoncore_pgo\genobject.obj" + +".\x86-temp-release\pythoncore_pgo\getargs.obj" + +".\x86-temp-release\pythoncore_pgo\getcompiler.obj" + +".\x86-temp-release\pythoncore_pgo\getcopyright.obj" + +".\x86-temp-release\pythoncore_pgo\getmtime.obj" + +".\x86-temp-release\pythoncore_pgo\getopt.obj" + +".\x86-temp-release\pythoncore_pgo\getpathp.obj" + +".\x86-temp-release\pythoncore_pgo\getplatform.obj" + +".\x86-temp-release\pythoncore_pgo\getversion.obj" + +".\x86-temp-release\pythoncore_pgo\graminit.obj" + +".\x86-temp-release\pythoncore_pgo\grammar.obj" + +".\x86-temp-release\pythoncore_pgo\grammar1.obj" + +".\x86-temp-release\pythoncore_pgo\imageop.obj" + +".\x86-temp-release\pythoncore_pgo\import.obj" + +".\x86-temp-release\pythoncore_pgo\import_nt.obj" + +".\x86-temp-release\pythoncore_pgo\importdl.obj" + +".\x86-temp-release\pythoncore_pgo\intobject.obj" + +".\x86-temp-release\pythoncore_pgo\iterobject.obj" + +".\x86-temp-release\pythoncore_pgo\itertoolsmodule.obj" + +".\x86-temp-release\pythoncore_pgo\listnode.obj" + +".\x86-temp-release\pythoncore_pgo\listobject.obj" + +".\x86-temp-release\pythoncore_pgo\longobject.obj" + +".\x86-temp-release\pythoncore_pgo\main.obj" + +".\x86-temp-release\pythoncore_pgo\marshal.obj" + +".\x86-temp-release\pythoncore_pgo\mathmodule.obj" + +".\x86-temp-release\pythoncore_pgo\md5.obj" + +".\x86-temp-release\pythoncore_pgo\md5module.obj" + +".\x86-temp-release\pythoncore_pgo\metagrammar.obj" + +".\x86-temp-release\pythoncore_pgo\methodobject.obj" + +".\x86-temp-release\pythoncore_pgo\mmapmodule.obj" + +".\x86-temp-release\pythoncore_pgo\modsupport.obj" + +".\x86-temp-release\pythoncore_pgo\moduleobject.obj" + +".\x86-temp-release\pythoncore_pgo\msvcrtmodule.obj" + +".\x86-temp-release\pythoncore_pgo\multibytecodec.obj" + +".\x86-temp-release\pythoncore_pgo\myreadline.obj" + +".\x86-temp-release\pythoncore_pgo\mysnprintf.obj" + +".\x86-temp-release\pythoncore_pgo\mystrtoul.obj" + +".\x86-temp-release\pythoncore_pgo\node.obj" + +".\x86-temp-release\pythoncore_pgo\object.obj" + +".\x86-temp-release\pythoncore_pgo\obmalloc.obj" + +".\x86-temp-release\pythoncore_pgo\operator.obj" + +".\x86-temp-release\pythoncore_pgo\parser.obj" + +".\x86-temp-release\pythoncore_pgo\parsermodule.obj" + +".\x86-temp-release\pythoncore_pgo\parsetok.obj" + +".\x86-temp-release\pythoncore_pgo\posixmodule.obj" + +".\x86-temp-release\pythoncore_pgo\pyarena.obj" + +".\x86-temp-release\pythoncore_pgo\pyfpe.obj" + +".\x86-temp-release\pythoncore_pgo\pystate.obj" + +".\x86-temp-release\pythoncore_pgo\pystrtod.obj" + +".\x86-temp-release\pythoncore_pgo\Python-ast.obj" + +".\x86-temp-release\pythoncore_pgo\python_nt.res" + +".\x86-temp-release\pythoncore_pgo\pythonrun.obj" + +".\x86-temp-release\pythoncore_pgo\rangeobject.obj" + +".\x86-temp-release\pythoncore_pgo\rgbimgmodule.obj" + +".\x86-temp-release\pythoncore_pgo\rotatingtree.obj" + +".\x86-temp-release\pythoncore_pgo\setobject.obj" + +".\x86-temp-release\pythoncore_pgo\sha256module.obj" + +".\x86-temp-release\pythoncore_pgo\sha512module.obj" + +".\x86-temp-release\pythoncore_pgo\shamodule.obj" + +".\x86-temp-release\pythoncore_pgo\signalmodule.obj" + +".\x86-temp-release\pythoncore_pgo\sliceobject.obj" + +".\x86-temp-release\pythoncore_pgo\stringobject.obj" + +".\x86-temp-release\pythoncore_pgo\stropmodule.obj" + +".\x86-temp-release\pythoncore_pgo\structmember.obj" + +".\x86-temp-release\pythoncore_pgo\structseq.obj" + +".\x86-temp-release\pythoncore_pgo\symtable.obj" + +".\x86-temp-release\pythoncore_pgo\symtablemodule.obj" + +".\x86-temp-release\pythoncore_pgo\sysmodule.obj" + +".\x86-temp-release\pythoncore_pgo\thread.obj" + +".\x86-temp-release\pythoncore_pgo\threadmodule.obj" + +".\x86-temp-release\pythoncore_pgo\timemodule.obj" + +".\x86-temp-release\pythoncore_pgo\tokenizer.obj" + +".\x86-temp-release\pythoncore_pgo\traceback.obj" + +".\x86-temp-release\pythoncore_pgo\tupleobject.obj" + +".\x86-temp-release\pythoncore_pgo\typeobject.obj" + +".\x86-temp-release\pythoncore_pgo\unicodectype.obj" + +".\x86-temp-release\pythoncore_pgo\unicodeobject.obj" + +".\x86-temp-release\pythoncore_pgo\weakrefobject.obj" + +".\x86-temp-release\pythoncore_pgo\xxsubtype.obj" + +".\x86-temp-release\pythoncore_pgo\yuvconvert.obj" + +".\x86-temp-release\pythoncore_pgo\zipimport.obj" diff --git a/PCbuild8/pythonw.vcproj b/PCbuild8/pythonw.vcproj index 0a5e91c9e90..42716735c09 100644 --- a/PCbuild8/pythonw.vcproj +++ b/PCbuild8/pythonw.vcproj @@ -1,386 +1,386 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/readme.txt b/PCbuild8/readme.txt index 36e843bacbc..e521fee9e08 100644 --- a/PCbuild8/readme.txt +++ b/PCbuild8/readme.txt @@ -1,423 +1,423 @@ -Building Python using VC++ 8.0 -------------------------------------- -This directory is used to build Python for Win32 platforms, e.g. Windows -95, 98 and NT. It requires Microsoft Visual C++ 8.0 -(a.k.a. Visual Studio 2005). -(For other Windows platforms and compilers, see ../PC/readme.txt.) - -All you need to do is open the workspace "pcbuild.sln" in MSVC++, select -the Debug or Release setting (using "Solution Configuration" from -the "Standard" toolbar"), and build the projects. - -The proper order to build subprojects: - -1) pythoncore (this builds the main Python DLL and library files, - python25.{dll, lib} in Release mode) - NOTE: in previous releases, this subproject was - named after the release number, e.g. python20. - -2) python (this builds the main Python executable, - python.exe in Release mode) - -3) the other subprojects, as desired or needed (note: you probably don't - want to build most of the other subprojects, unless you're building an - entire Python distribution from scratch, or specifically making changes - to the subsystems they implement, or are running a Python core buildbot - test slave; see SUBPROJECTS below) - -When using the Debug setting, the output files have a _d added to -their name: python25_d.dll, python_d.exe, parser_d.pyd, and so on. - -SUBPROJECTS ------------ -These subprojects should build out of the box. Subprojects other than the -main ones (pythoncore, python, pythonw) generally build a DLL (renamed to -.pyd) from a specific module so that users don't have to load the code -supporting that module unless they import the module. - -pythoncore - .dll and .lib -pythoncore_pgo - .dll and .lib, a variant of pythoncore that is optimized through a - Profile Guided Optimization (PGO), employing pybench as the profile - case to optimize for. The results are produced as a python25.{dll,lib} - in the subfolder 'pythoncore_pgo'. To use this instead of the - standard Python dll place this dll with the python.exe. -python - .exe -pythonw - pythonw.exe, a variant of python.exe that doesn't pop up a DOS box -_socket - socketmodule.c -_testcapi - tests of the Python C API, run via Lib/test/test_capi.py, and - implemented by module Modules/_testcapimodule.c -pyexpat - Python wrapper for accelerated XML parsing, which incorporates stable - code from the Expat project: http://sourceforge.net/projects/expat/ -select - selectmodule.c -unicodedata - large tables of Unicode data -winsound - play sounds (typically .wav files) under Windows - -The following subprojects will generally NOT build out of the box. They -wrap code Python doesn't control, and you'll need to download the base -packages first and unpack them into siblings of PCbuilds's parent -directory; for example, if your PCbuild is .......\dist\src\PCbuild\, -unpack into new subdirectories of dist\. - -_tkinter - Python wrapper for the Tk windowing system. Requires building - Tcl/Tk first. Following are instructions for Tcl/Tk 8.4.12. - - Get source - ---------- - In the dist directory, run - svn export http://svn.python.org/projects/external/tcl8.4.12 - svn export http://svn.python.org/projects/external/tk8.4.12 - svn export http://svn.python.org/projects/external/tix-8.4.0 - - Build Tcl first (done here w/ MSVC 7.1 on Windows XP) - --------------- - Use "Start -> All Programs -> Microsoft Visual Studio .NET 2003 - -> Visual Studio .NET Tools -> Visual Studio .NET 2003 Command Prompt" - to get a shell window with the correct environment settings - cd dist\tcl8.4.12\win - nmake -f makefile.vc - nmake -f makefile.vc INSTALLDIR=..\..\tcltk install - - XXX Should we compile with OPTS=threads? - - Optional: run tests, via - nmake -f makefile.vc test - - On WinXP Pro, wholly up to date as of 30-Aug-2004: - all.tcl: Total 10678 Passed 9969 Skipped 709 Failed 0 - Sourced 129 Test Files. - - Build Tk - -------- - cd dist\tk8.4.12\win - nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 - nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 INSTALLDIR=..\..\tcltk install - - XXX Should we compile with OPTS=threads? - - XXX Our installer copies a lot of stuff out of the Tcl/Tk install - XXX directory. Is all of that really needed for Python use of Tcl/Tk? - - Optional: run tests, via - nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 test - - On WinXP Pro, wholly up to date as of 30-Aug-2004: - all.tcl: Total 8420 Passed 6826 Skipped 1581 Failed 13 - Sourced 91 Test Files. - Files with failing tests: canvImg.test scrollbar.test textWind.test winWm.test - - Built Tix - --------- - cd dist\tix-8.4.0\win - nmake -f python.mak - nmake -f python.mak install - -bz2 - Python wrapper for the libbz2 compression library. Homepage - http://sources.redhat.com/bzip2/ - Download the source from the python.org copy into the dist - directory: - - svn export http://svn.python.org/projects/external/bzip2-1.0.3 - - A custom pre-link step in the bz2 project settings should manage to - build bzip2-1.0.3\libbz2.lib by magic before bz2.pyd (or bz2_d.pyd) is - linked in PCbuild\. - However, the bz2 project is not smart enough to remove anything under - bzip2-1.0.3\ when you do a clean, so if you want to rebuild bzip2.lib - you need to clean up bzip2-1.0.3\ by hand. - - The build step shouldn't yield any warnings or errors, and should end - by displaying 6 blocks each terminated with - FC: no differences encountered - - All of this managed to build bzip2-1.0.3\libbz2.lib, which the Python - project links in. - - -_bsddb - To use the version of bsddb that Python is built with by default, invoke - (in the dist directory) - - svn export http://svn.python.org/projects/external/db-4.4.20 - - - Then open a VS.NET 2003 shell, and invoke: - - devenv db-4.4.20\build_win32\Berkeley_DB.sln /build Release /project db_static - - and do that a second time for a Debug build too: - - devenv db-4.4.20\build_win32\Berkeley_DB.sln /build Debug /project db_static - - Alternatively, if you want to start with the original sources, - go to Sleepycat's download page: - http://www.sleepycat.com/downloads/releasehistorybdb.html - - and download version 4.4.20. - - With or without strong cryptography? You can choose either with or - without strong cryptography, as per the instructions below. By - default, Python is built and distributed WITHOUT strong crypto. - - Unpack the sources; if you downloaded the non-crypto version, rename - the directory from db-4.4.20.NC to db-4.4.20. - - Now apply any patches that apply to your version. - - Open - dist\db-4.4.20\docs\index.html - - and follow the "Windows->Building Berkeley DB with Visual C++ .NET" - instructions for building the Sleepycat - software. Note that Berkeley_DB.dsw is in the build_win32 subdirectory. - Build the "db_static" project, for "Release" mode. - - To run extensive tests, pass "-u bsddb" to regrtest.py. test_bsddb3.py - is then enabled. Running in verbose mode may be helpful. - - XXX The test_bsddb3 tests don't always pass, on Windows (according to - XXX me) or on Linux (according to Barry). (I had much better luck - XXX on Win2K than on Win98SE.) The common failure mode across platforms - XXX is - XXX DBAgainError: (11, 'Resource temporarily unavailable -- unable - XXX to join the environment') - XXX - XXX and it appears timing-dependent. On Win2K I also saw this once: - XXX - XXX test02_SimpleLocks (bsddb.test.test_thread.HashSimpleThreaded) ... - XXX Exception in thread reader 1: - XXX Traceback (most recent call last): - XXX File "C:\Code\python\lib\threading.py", line 411, in __bootstrap - XXX self.run() - XXX File "C:\Code\python\lib\threading.py", line 399, in run - XXX apply(self.__target, self.__args, self.__kwargs) - XXX File "C:\Code\python\lib\bsddb\test\test_thread.py", line 268, in - XXX readerThread - XXX rec = c.next() - XXX DBLockDeadlockError: (-30996, 'DB_LOCK_DEADLOCK: Locker killed - XXX to resolve a deadlock') - XXX - XXX I'm told that DBLockDeadlockError is expected at times. It - XXX doesn't cause a test to fail when it happens (exceptions in - XXX threads are invisible to unittest). - - Building for Win64: - - open a VS.NET 2003 command prompt - - run the SDK setenv.cmd script, passing /RETAIL and the target - architecture (/SRV64 for Itanium, /X64 for AMD64) - - build BerkeleyDB with the solution configuration matching the - target ("Release IA64" for Itanium, "Release AMD64" for AMD64), e.g. - devenv db-4.4.20\build_win32\Berkeley_DB.sln /build "Release AMD64" /project db_static /useenv - -_sqlite3 - Python wrapper for SQLite library. - - Get the source code through - - svn export http://svn.python.org/projects/external/sqlite-source-3.3.4 - - To use the extension module in a Python build tree, copy sqlite3.dll into - the PCbuild folder. - -_ssl - Python wrapper for the secure sockets library. - - Get the source code through - - svn export http://svn.python.org/projects/external/openssl-0.9.8a - - Alternatively, get the latest version from http://www.openssl.org. - You can (theoretically) use any version of OpenSSL you like - the - build process will automatically select the latest version. - - You must also install ActivePerl from - http://www.activestate.com/Products/ActivePerl/ - as this is used by the OpenSSL build process. Complain to them . - - The MSVC project simply invokes PCBuild/build_ssl.py to perform - the build. This Python script locates and builds your OpenSSL - installation, then invokes a simple makefile to build the final .pyd. - - build_ssl.py attempts to catch the most common errors (such as not - being able to find OpenSSL sources, or not being able to find a Perl - that works with OpenSSL) and give a reasonable error message. - If you have a problem that doesn't seem to be handled correctly - (eg, you know you have ActivePerl but we can't find it), please take - a peek at build_ssl.py and suggest patches. Note that build_ssl.py - should be able to be run directly from the command-line. - - build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do - this by hand. - -Building for Itanium --------------------- - -The project files support a ReleaseItanium configuration which creates -Win64/Itanium binaries. For this to work, you need to install the Platform -SDK, in particular the 64-bit support. This includes an Itanium compiler -(future releases of the SDK likely include an AMD64 compiler as well). -In addition, you need the Visual Studio plugin for external C compilers, -from http://sf.net/projects/vsextcomp. The plugin will wrap cl.exe, to -locate the proper target compiler, and convert compiler options -accordingly. The project files require atleast version 0.8. - -Building for AMD64 ------------------- - -The build process for the ReleaseAMD64 configuration is very similar -to the Itanium configuration; make sure you use the latest version of -vsextcomp. - -Building Python Using the free MS Toolkit Compiler --------------------------------------------------- - -The build process for Visual C++ can be used almost unchanged with the free MS -Toolkit Compiler. This provides a way of building Python using freely -available software. - -Requirements - - To build Python, the following tools are required: - - * The Visual C++ Toolkit Compiler - from http://msdn.microsoft.com/visualc/vctoolkit2003/ - * A recent Platform SDK - from http://www.microsoft.com/downloads/details.aspx?FamilyID=484269e2-3b89-47e3-8eb7-1f2be6d7123a - * The .NET 1.1 SDK - from http://www.microsoft.com/downloads/details.aspx?FamilyID=9b3a2ca6-3647-4070-9f41-a333c6b9181d - - [Does anyone have better URLs for the last 2 of these?] - - The toolkit compiler is needed as it is an optimising compiler (the - compiler supplied with the .NET SDK is a non-optimising version). The - platform SDK is needed to provide the Windows header files and libraries - (the Windows 2003 Server SP1 edition, typical install, is known to work - - other configurations or versions are probably fine as well). The .NET 1.1 - SDK is needed because it contains a version of msvcrt.dll which links to - the msvcr71.dll CRT. Note that the .NET 2.0 SDK is NOT acceptable, as it - references msvcr80.dll. - - All of the above items should be installed as normal. - - If you intend to build the openssl (needed for the _ssl extension) you - will need the C runtime sources installed as part of the platform SDK. - - In addition, you will need Nant, available from - http://nant.sourceforge.net. The 0.85 release candidate 3 version is known - to work. This is the latest released version at the time of writing. Later - "nightly build" versions are known NOT to work - it is not clear at - present whether future released versions will work. - -Setting up the environment - - Start a platform SDK "build environment window" from the start menu. The - "Windows XP 32-bit retail" version is known to work. - - Add the following directories to your PATH: - * The toolkit compiler directory - * The SDK "Win64" binaries directory - * The Nant directory - Add to your INCLUDE environment variable: - * The toolkit compiler INCLUDE directory - Add to your LIB environment variable: - * The toolkit compiler LIB directory - * The .NET SDK Visual Studio 2003 VC7\lib directory - - The following commands should set things up as you need them: - - rem Set these values according to where you installed the software - set TOOLKIT=C:\Program Files\Microsoft Visual C++ Toolkit 2003 - set SDK=C:\Program Files\Microsoft Platform SDK - set NET=C:\Program Files\Microsoft Visual Studio .NET 2003 - set NANT=C:\Utils\Nant - - set PATH=%TOOLKIT%\bin;%PATH%;%SDK%\Bin\win64;%NANT%\bin - set INCLUDE=%TOOLKIT%\include;%INCLUDE% - set LIB=%TOOLKIT%\lib;%NET%\VC7\lib;%LIB% - - The "win64" directory from the SDK is added to supply executables such as - "cvtres" and "lib", which are not available elsewhere. The versions in the - "win64" directory are 32-bit programs, so they are fine to use here. - - That's it. To build Python (the core only, no binary extensions which - depend on external libraries) you just need to issue the command - - nant -buildfile:python.build all - - from within the PCBuild directory. - -Extension modules - - To build those extension modules which require external libraries - (_tkinter, bz2, _bsddb, _sqlite3, _ssl) you can follow the instructions - for the Visual Studio build above, with a few minor modifications. These - instructions have only been tested using the sources in the Python - subversion repository - building from original sources should work, but - has not been tested. - - For each extension module you wish to build, you should remove the - associated include line from the excludeprojects section of pc.build. - - The changes required are: - - _tkinter - The tix makefile (tix-8.4.0\win\makefile.vc) must be modified to - remove references to TOOLS32. The relevant lines should be changed to - read: - cc32 = cl.exe - link32 = link.exe - include32 = - The remainder of the build instructions will work as given. - - bz2 - No changes are needed - - _bsddb - The file db.build should be copied from the Python PCBuild directory - to the directory db-4.4.20\build_win32. - - The file db_static.vcproj in db-4.4.20\build_win32 should be edited to - remove the string "$(SolutionDir)" - this occurs in 2 places, only - relevant for 64-bit builds. (The edit is required as otherwise, nant - wants to read the solution file, which is not in a suitable form). - - The bsddb library can then be build with the command - nant -buildfile:db.build all - run from the db-4.4.20\build_win32 directory. - - _sqlite3 - No changes are needed. However, in order for the tests to succeed, a - copy of sqlite3.dll must be downloaded, and placed alongside - python.exe. - - _ssl - The documented build process works as written. However, it needs a - copy of the file setargv.obj, which is not supplied in the platform - SDK. However, the sources are available (in the crt source code). To - build setargv.obj, proceed as follows: - - Copy setargv.c, cruntime.h and internal.h from %SDK%\src\crt to a - temporary directory. - Compile using "cl /c /I. /MD /D_CRTBLD setargv.c" - Copy the resulting setargv.obj to somewhere on your LIB environment - (%SDK%\lib is a reasonable place). - - With setargv.obj in place, the standard build process should work - fine. - -YOUR OWN EXTENSION DLLs ------------------------ -If you want to create your own extension module DLL, there's an example -with easy-to-follow instructions in ../PC/example/; read the file -readme.txt there first. +Building Python using VC++ 8.0 +------------------------------------- +This directory is used to build Python for Win32 platforms, e.g. Windows +95, 98 and NT. It requires Microsoft Visual C++ 8.0 +(a.k.a. Visual Studio 2005). +(For other Windows platforms and compilers, see ../PC/readme.txt.) + +All you need to do is open the workspace "pcbuild.sln" in MSVC++, select +the Debug or Release setting (using "Solution Configuration" from +the "Standard" toolbar"), and build the projects. + +The proper order to build subprojects: + +1) pythoncore (this builds the main Python DLL and library files, + python25.{dll, lib} in Release mode) + NOTE: in previous releases, this subproject was + named after the release number, e.g. python20. + +2) python (this builds the main Python executable, + python.exe in Release mode) + +3) the other subprojects, as desired or needed (note: you probably don't + want to build most of the other subprojects, unless you're building an + entire Python distribution from scratch, or specifically making changes + to the subsystems they implement, or are running a Python core buildbot + test slave; see SUBPROJECTS below) + +When using the Debug setting, the output files have a _d added to +their name: python25_d.dll, python_d.exe, parser_d.pyd, and so on. + +SUBPROJECTS +----------- +These subprojects should build out of the box. Subprojects other than the +main ones (pythoncore, python, pythonw) generally build a DLL (renamed to +.pyd) from a specific module so that users don't have to load the code +supporting that module unless they import the module. + +pythoncore + .dll and .lib +pythoncore_pgo + .dll and .lib, a variant of pythoncore that is optimized through a + Profile Guided Optimization (PGO), employing pybench as the profile + case to optimize for. The results are produced as a python25.{dll,lib} + in the subfolder 'pythoncore_pgo'. To use this instead of the + standard Python dll place this dll with the python.exe. +python + .exe +pythonw + pythonw.exe, a variant of python.exe that doesn't pop up a DOS box +_socket + socketmodule.c +_testcapi + tests of the Python C API, run via Lib/test/test_capi.py, and + implemented by module Modules/_testcapimodule.c +pyexpat + Python wrapper for accelerated XML parsing, which incorporates stable + code from the Expat project: http://sourceforge.net/projects/expat/ +select + selectmodule.c +unicodedata + large tables of Unicode data +winsound + play sounds (typically .wav files) under Windows + +The following subprojects will generally NOT build out of the box. They +wrap code Python doesn't control, and you'll need to download the base +packages first and unpack them into siblings of PCbuilds's parent +directory; for example, if your PCbuild is .......\dist\src\PCbuild\, +unpack into new subdirectories of dist\. + +_tkinter + Python wrapper for the Tk windowing system. Requires building + Tcl/Tk first. Following are instructions for Tcl/Tk 8.4.12. + + Get source + ---------- + In the dist directory, run + svn export http://svn.python.org/projects/external/tcl8.4.12 + svn export http://svn.python.org/projects/external/tk8.4.12 + svn export http://svn.python.org/projects/external/tix-8.4.0 + + Build Tcl first (done here w/ MSVC 7.1 on Windows XP) + --------------- + Use "Start -> All Programs -> Microsoft Visual Studio .NET 2003 + -> Visual Studio .NET Tools -> Visual Studio .NET 2003 Command Prompt" + to get a shell window with the correct environment settings + cd dist\tcl8.4.12\win + nmake -f makefile.vc + nmake -f makefile.vc INSTALLDIR=..\..\tcltk install + + XXX Should we compile with OPTS=threads? + + Optional: run tests, via + nmake -f makefile.vc test + + On WinXP Pro, wholly up to date as of 30-Aug-2004: + all.tcl: Total 10678 Passed 9969 Skipped 709 Failed 0 + Sourced 129 Test Files. + + Build Tk + -------- + cd dist\tk8.4.12\win + nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 + nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 INSTALLDIR=..\..\tcltk install + + XXX Should we compile with OPTS=threads? + + XXX Our installer copies a lot of stuff out of the Tcl/Tk install + XXX directory. Is all of that really needed for Python use of Tcl/Tk? + + Optional: run tests, via + nmake -f makefile.vc TCLDIR=..\..\tcl8.4.12 test + + On WinXP Pro, wholly up to date as of 30-Aug-2004: + all.tcl: Total 8420 Passed 6826 Skipped 1581 Failed 13 + Sourced 91 Test Files. + Files with failing tests: canvImg.test scrollbar.test textWind.test winWm.test + + Built Tix + --------- + cd dist\tix-8.4.0\win + nmake -f python.mak + nmake -f python.mak install + +bz2 + Python wrapper for the libbz2 compression library. Homepage + http://sources.redhat.com/bzip2/ + Download the source from the python.org copy into the dist + directory: + + svn export http://svn.python.org/projects/external/bzip2-1.0.3 + + A custom pre-link step in the bz2 project settings should manage to + build bzip2-1.0.3\libbz2.lib by magic before bz2.pyd (or bz2_d.pyd) is + linked in PCbuild\. + However, the bz2 project is not smart enough to remove anything under + bzip2-1.0.3\ when you do a clean, so if you want to rebuild bzip2.lib + you need to clean up bzip2-1.0.3\ by hand. + + The build step shouldn't yield any warnings or errors, and should end + by displaying 6 blocks each terminated with + FC: no differences encountered + + All of this managed to build bzip2-1.0.3\libbz2.lib, which the Python + project links in. + + +_bsddb + To use the version of bsddb that Python is built with by default, invoke + (in the dist directory) + + svn export http://svn.python.org/projects/external/db-4.4.20 + + + Then open a VS.NET 2003 shell, and invoke: + + devenv db-4.4.20\build_win32\Berkeley_DB.sln /build Release /project db_static + + and do that a second time for a Debug build too: + + devenv db-4.4.20\build_win32\Berkeley_DB.sln /build Debug /project db_static + + Alternatively, if you want to start with the original sources, + go to Sleepycat's download page: + http://www.sleepycat.com/downloads/releasehistorybdb.html + + and download version 4.4.20. + + With or without strong cryptography? You can choose either with or + without strong cryptography, as per the instructions below. By + default, Python is built and distributed WITHOUT strong crypto. + + Unpack the sources; if you downloaded the non-crypto version, rename + the directory from db-4.4.20.NC to db-4.4.20. + + Now apply any patches that apply to your version. + + Open + dist\db-4.4.20\docs\index.html + + and follow the "Windows->Building Berkeley DB with Visual C++ .NET" + instructions for building the Sleepycat + software. Note that Berkeley_DB.dsw is in the build_win32 subdirectory. + Build the "db_static" project, for "Release" mode. + + To run extensive tests, pass "-u bsddb" to regrtest.py. test_bsddb3.py + is then enabled. Running in verbose mode may be helpful. + + XXX The test_bsddb3 tests don't always pass, on Windows (according to + XXX me) or on Linux (according to Barry). (I had much better luck + XXX on Win2K than on Win98SE.) The common failure mode across platforms + XXX is + XXX DBAgainError: (11, 'Resource temporarily unavailable -- unable + XXX to join the environment') + XXX + XXX and it appears timing-dependent. On Win2K I also saw this once: + XXX + XXX test02_SimpleLocks (bsddb.test.test_thread.HashSimpleThreaded) ... + XXX Exception in thread reader 1: + XXX Traceback (most recent call last): + XXX File "C:\Code\python\lib\threading.py", line 411, in __bootstrap + XXX self.run() + XXX File "C:\Code\python\lib\threading.py", line 399, in run + XXX apply(self.__target, self.__args, self.__kwargs) + XXX File "C:\Code\python\lib\bsddb\test\test_thread.py", line 268, in + XXX readerThread + XXX rec = c.next() + XXX DBLockDeadlockError: (-30996, 'DB_LOCK_DEADLOCK: Locker killed + XXX to resolve a deadlock') + XXX + XXX I'm told that DBLockDeadlockError is expected at times. It + XXX doesn't cause a test to fail when it happens (exceptions in + XXX threads are invisible to unittest). + + Building for Win64: + - open a VS.NET 2003 command prompt + - run the SDK setenv.cmd script, passing /RETAIL and the target + architecture (/SRV64 for Itanium, /X64 for AMD64) + - build BerkeleyDB with the solution configuration matching the + target ("Release IA64" for Itanium, "Release AMD64" for AMD64), e.g. + devenv db-4.4.20\build_win32\Berkeley_DB.sln /build "Release AMD64" /project db_static /useenv + +_sqlite3 + Python wrapper for SQLite library. + + Get the source code through + + svn export http://svn.python.org/projects/external/sqlite-source-3.3.4 + + To use the extension module in a Python build tree, copy sqlite3.dll into + the PCbuild folder. + +_ssl + Python wrapper for the secure sockets library. + + Get the source code through + + svn export http://svn.python.org/projects/external/openssl-0.9.8a + + Alternatively, get the latest version from http://www.openssl.org. + You can (theoretically) use any version of OpenSSL you like - the + build process will automatically select the latest version. + + You must also install ActivePerl from + http://www.activestate.com/Products/ActivePerl/ + as this is used by the OpenSSL build process. Complain to them . + + The MSVC project simply invokes PCBuild/build_ssl.py to perform + the build. This Python script locates and builds your OpenSSL + installation, then invokes a simple makefile to build the final .pyd. + + build_ssl.py attempts to catch the most common errors (such as not + being able to find OpenSSL sources, or not being able to find a Perl + that works with OpenSSL) and give a reasonable error message. + If you have a problem that doesn't seem to be handled correctly + (eg, you know you have ActivePerl but we can't find it), please take + a peek at build_ssl.py and suggest patches. Note that build_ssl.py + should be able to be run directly from the command-line. + + build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do + this by hand. + +Building for Itanium +-------------------- + +The project files support a ReleaseItanium configuration which creates +Win64/Itanium binaries. For this to work, you need to install the Platform +SDK, in particular the 64-bit support. This includes an Itanium compiler +(future releases of the SDK likely include an AMD64 compiler as well). +In addition, you need the Visual Studio plugin for external C compilers, +from http://sf.net/projects/vsextcomp. The plugin will wrap cl.exe, to +locate the proper target compiler, and convert compiler options +accordingly. The project files require atleast version 0.8. + +Building for AMD64 +------------------ + +The build process for the ReleaseAMD64 configuration is very similar +to the Itanium configuration; make sure you use the latest version of +vsextcomp. + +Building Python Using the free MS Toolkit Compiler +-------------------------------------------------- + +The build process for Visual C++ can be used almost unchanged with the free MS +Toolkit Compiler. This provides a way of building Python using freely +available software. + +Requirements + + To build Python, the following tools are required: + + * The Visual C++ Toolkit Compiler + from http://msdn.microsoft.com/visualc/vctoolkit2003/ + * A recent Platform SDK + from http://www.microsoft.com/downloads/details.aspx?FamilyID=484269e2-3b89-47e3-8eb7-1f2be6d7123a + * The .NET 1.1 SDK + from http://www.microsoft.com/downloads/details.aspx?FamilyID=9b3a2ca6-3647-4070-9f41-a333c6b9181d + + [Does anyone have better URLs for the last 2 of these?] + + The toolkit compiler is needed as it is an optimising compiler (the + compiler supplied with the .NET SDK is a non-optimising version). The + platform SDK is needed to provide the Windows header files and libraries + (the Windows 2003 Server SP1 edition, typical install, is known to work - + other configurations or versions are probably fine as well). The .NET 1.1 + SDK is needed because it contains a version of msvcrt.dll which links to + the msvcr71.dll CRT. Note that the .NET 2.0 SDK is NOT acceptable, as it + references msvcr80.dll. + + All of the above items should be installed as normal. + + If you intend to build the openssl (needed for the _ssl extension) you + will need the C runtime sources installed as part of the platform SDK. + + In addition, you will need Nant, available from + http://nant.sourceforge.net. The 0.85 release candidate 3 version is known + to work. This is the latest released version at the time of writing. Later + "nightly build" versions are known NOT to work - it is not clear at + present whether future released versions will work. + +Setting up the environment + + Start a platform SDK "build environment window" from the start menu. The + "Windows XP 32-bit retail" version is known to work. + + Add the following directories to your PATH: + * The toolkit compiler directory + * The SDK "Win64" binaries directory + * The Nant directory + Add to your INCLUDE environment variable: + * The toolkit compiler INCLUDE directory + Add to your LIB environment variable: + * The toolkit compiler LIB directory + * The .NET SDK Visual Studio 2003 VC7\lib directory + + The following commands should set things up as you need them: + + rem Set these values according to where you installed the software + set TOOLKIT=C:\Program Files\Microsoft Visual C++ Toolkit 2003 + set SDK=C:\Program Files\Microsoft Platform SDK + set NET=C:\Program Files\Microsoft Visual Studio .NET 2003 + set NANT=C:\Utils\Nant + + set PATH=%TOOLKIT%\bin;%PATH%;%SDK%\Bin\win64;%NANT%\bin + set INCLUDE=%TOOLKIT%\include;%INCLUDE% + set LIB=%TOOLKIT%\lib;%NET%\VC7\lib;%LIB% + + The "win64" directory from the SDK is added to supply executables such as + "cvtres" and "lib", which are not available elsewhere. The versions in the + "win64" directory are 32-bit programs, so they are fine to use here. + + That's it. To build Python (the core only, no binary extensions which + depend on external libraries) you just need to issue the command + + nant -buildfile:python.build all + + from within the PCBuild directory. + +Extension modules + + To build those extension modules which require external libraries + (_tkinter, bz2, _bsddb, _sqlite3, _ssl) you can follow the instructions + for the Visual Studio build above, with a few minor modifications. These + instructions have only been tested using the sources in the Python + subversion repository - building from original sources should work, but + has not been tested. + + For each extension module you wish to build, you should remove the + associated include line from the excludeprojects section of pc.build. + + The changes required are: + + _tkinter + The tix makefile (tix-8.4.0\win\makefile.vc) must be modified to + remove references to TOOLS32. The relevant lines should be changed to + read: + cc32 = cl.exe + link32 = link.exe + include32 = + The remainder of the build instructions will work as given. + + bz2 + No changes are needed + + _bsddb + The file db.build should be copied from the Python PCBuild directory + to the directory db-4.4.20\build_win32. + + The file db_static.vcproj in db-4.4.20\build_win32 should be edited to + remove the string "$(SolutionDir)" - this occurs in 2 places, only + relevant for 64-bit builds. (The edit is required as otherwise, nant + wants to read the solution file, which is not in a suitable form). + + The bsddb library can then be build with the command + nant -buildfile:db.build all + run from the db-4.4.20\build_win32 directory. + + _sqlite3 + No changes are needed. However, in order for the tests to succeed, a + copy of sqlite3.dll must be downloaded, and placed alongside + python.exe. + + _ssl + The documented build process works as written. However, it needs a + copy of the file setargv.obj, which is not supplied in the platform + SDK. However, the sources are available (in the crt source code). To + build setargv.obj, proceed as follows: + + Copy setargv.c, cruntime.h and internal.h from %SDK%\src\crt to a + temporary directory. + Compile using "cl /c /I. /MD /D_CRTBLD setargv.c" + Copy the resulting setargv.obj to somewhere on your LIB environment + (%SDK%\lib is a reasonable place). + + With setargv.obj in place, the standard build process should work + fine. + +YOUR OWN EXTENSION DLLs +----------------------- +If you want to create your own extension module DLL, there's an example +with easy-to-follow instructions in ../PC/example/; read the file +readme.txt there first. diff --git a/PCbuild8/rmpyc.py b/PCbuild8/rmpyc.py index 95de0f6b823..43c8576e798 100644 --- a/PCbuild8/rmpyc.py +++ b/PCbuild8/rmpyc.py @@ -1,25 +1,25 @@ -# Remove all the .pyc and .pyo files under ../Lib. - - -def deltree(root): - import os - from os.path import join - - npyc = npyo = 0 - for root, dirs, files in os.walk(root): - for name in files: - delete = False - if name.endswith('.pyc'): - delete = True - npyc += 1 - elif name.endswith('.pyo'): - delete = True - npyo += 1 - - if delete: - os.remove(join(root, name)) - - return npyc, npyo - -npyc, npyo = deltree("../Lib") -print npyc, ".pyc deleted,", npyo, ".pyo deleted" +# Remove all the .pyc and .pyo files under ../Lib. + + +def deltree(root): + import os + from os.path import join + + npyc = npyo = 0 + for root, dirs, files in os.walk(root): + for name in files: + delete = False + if name.endswith('.pyc'): + delete = True + npyc += 1 + elif name.endswith('.pyo'): + delete = True + npyo += 1 + + if delete: + os.remove(join(root, name)) + + return npyc, npyo + +npyc, npyo = deltree("../Lib") +print npyc, ".pyc deleted,", npyo, ".pyo deleted" diff --git a/PCbuild8/select.vcproj b/PCbuild8/select.vcproj index fb05c65f098..97a554b2ccb 100644 --- a/PCbuild8/select.vcproj +++ b/PCbuild8/select.vcproj @@ -1,382 +1,382 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/unicodedata.vcproj b/PCbuild8/unicodedata.vcproj index 05d41732b76..d6c375bcab1 100644 --- a/PCbuild8/unicodedata.vcproj +++ b/PCbuild8/unicodedata.vcproj @@ -1,371 +1,371 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/w9xpopen.vcproj b/PCbuild8/w9xpopen.vcproj index e326b9a414d..3539ecc49aa 100644 --- a/PCbuild8/w9xpopen.vcproj +++ b/PCbuild8/w9xpopen.vcproj @@ -1,185 +1,185 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCbuild8/winsound.vcproj b/PCbuild8/winsound.vcproj index 140e8406e9c..6a84ebbe1a8 100644 --- a/PCbuild8/winsound.vcproj +++ b/PCbuild8/winsound.vcproj @@ -1,375 +1,375 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index d9dcc412e19..885b91622ac 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -893,15 +893,17 @@ tok_nextc(register struct tok_state *tok) tok->inp = strchr(tok->inp, '\0'); done = tok->inp[-1] == '\n'; } - tok->cur = tok->buf + cur; - tok->line_start = tok->cur; - /* replace "\r\n" with "\n" */ - /* For Mac we leave the \r, giving a syntax error */ - pt = tok->inp - 2; - if (pt >= tok->buf && *pt == '\r') { - *pt++ = '\n'; - *pt = '\0'; - tok->inp = pt; + if (tok->buf != NULL) { + tok->cur = tok->buf + cur; + tok->line_start = tok->cur; + /* replace "\r\n" with "\n" */ + /* For Mac leave the \r, giving syntax error */ + pt = tok->inp - 2; + if (pt >= tok->buf && *pt == '\r') { + *pt++ = '\n'; + *pt = '\0'; + tok->inp = pt; + } } } if (tok->done != E_OK) { diff --git a/Python/ceval.c b/Python/ceval.c index 80adc30ed41..e35680005f9 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1829,15 +1829,26 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) long hash = ((PyStringObject *)w)->ob_shash; if (hash != -1) { PyDictObject *d; + PyDictEntry *e; d = (PyDictObject *)(f->f_globals); - x = d->ma_lookup(d, w, hash)->me_value; + e = d->ma_lookup(d, w, hash); + if (e == NULL) { + x = NULL; + break; + } + x = e->me_value; if (x != NULL) { Py_INCREF(x); PUSH(x); continue; } d = (PyDictObject *)(f->f_builtins); - x = d->ma_lookup(d, w, hash)->me_value; + e = d->ma_lookup(d, w, hash); + if (e == NULL) { + x = NULL; + break; + } + x = e->me_value; if (x != NULL) { Py_INCREF(x); PUSH(x); diff --git a/Python/errors.c b/Python/errors.c index c391d3389a4..d99f261e189 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -597,13 +597,16 @@ PyErr_WriteUnraisable(PyObject *obj) if (f != NULL) { PyFile_WriteString("Exception ", f); if (t) { - char* className = PyExceptionClass_Name(t); PyObject* moduleName; - char *dot = strrchr(className, '.'); - if (dot != NULL) - className = dot+1; - moduleName = PyObject_GetAttrString(t, "__module__"); + char* className = PyExceptionClass_Name(t); + if (className != NULL) { + char *dot = strrchr(className, '.'); + if (dot != NULL) + className = dot+1; + } + + moduleName = PyObject_GetAttrString(t, "__module__"); if (moduleName == NULL) PyFile_WriteString("", f); else { @@ -734,7 +737,8 @@ PyErr_SyntaxLocation(const char *filename, int lineno) tmp = PyErr_ProgramText(filename, lineno); if (tmp) { - PyObject_SetAttrString(v, "text", tmp); + if (PyObject_SetAttrString(v, "text", tmp)) + PyErr_Clear(); Py_DECREF(tmp); } } diff --git a/Python/import.c b/Python/import.c index 094e4fd00af..c14e8cd0f2b 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1252,9 +1252,11 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, } else if (importer == Py_None) { /* No importer was found, so it has to be a file. - * Check if the directory is valid. */ + * Check if the directory is valid. + * Note that the empty string is a valid path, but + * not stat'able, hence the check for len. */ #ifdef HAVE_STAT - if (stat(buf, &statbuf) != 0) { + if (len && stat(buf, &statbuf) != 0) { /* Directory does not exist. */ PyDict_SetItem(path_importer_cache, v, Py_False); @@ -2058,7 +2060,7 @@ PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, /* Return the package that an import is being performed in. If globals comes from the module foo.bar.bat (not itself a package), this returns the sys.modules entry for foo.bar. If globals is from a package's __init__.py, - the package's entry in sys.modules is returned. + the package's entry in sys.modules is returned, as a borrowed reference. The *name* of the returned package is returned in buf, with the length of the name in *p_buflen. diff --git a/Python/marshal.c b/Python/marshal.c index c5d5b72f7df..10a6c0c1d7a 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1073,12 +1073,10 @@ marshal_dump(PyObject *self, PyObject *args) } static PyObject * -marshal_load(PyObject *self, PyObject *args) +marshal_load(PyObject *self, PyObject *f) { RFILE rf; - PyObject *f, *result; - if (!PyArg_ParseTuple(args, "O:load", &f)) - return NULL; + PyObject *result; if (!PyFile_Check(f)) { PyErr_SetString(PyExc_TypeError, "marshal.load() arg must be file"); @@ -1121,7 +1119,7 @@ marshal_loads(PyObject *self, PyObject *args) static PyMethodDef marshal_methods[] = { {"dump", marshal_dump, METH_VARARGS}, - {"load", marshal_load, METH_VARARGS}, + {"load", marshal_load, METH_O}, {"dumps", marshal_dumps, METH_VARARGS}, {"loads", marshal_loads, METH_VARARGS}, {NULL, NULL} /* sentinel */ diff --git a/Python/pystrtod.c b/Python/pystrtod.c index 8a71c285a97..e1c84ea03e0 100644 --- a/Python/pystrtod.c +++ b/Python/pystrtod.c @@ -31,6 +31,7 @@ * is returned (according to the sign of the value), and %ERANGE is * stored in %errno. If the correct value would cause underflow, * zero is returned and %ERANGE is stored in %errno. + * If memory allocation fails, %ENOMEM is stored in %errno. * * This function resets %errno before calling strtod() so that * you can reliably detect overflow and underflow. @@ -102,6 +103,12 @@ PyOS_ascii_strtod(const char *nptr, char **endptr) /* We need to convert the '.' to the locale specific decimal point */ copy = (char *)PyMem_MALLOC(end - nptr + 1 + decimal_point_len); + if (copy == NULL) { + if (endptr) + *endptr = (char *)nptr; + errno = ENOMEM; + return val; + } c = copy; memcpy(c, nptr, decimal_point_pos - nptr); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 8283fc5c98a..2dbcf75ac97 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -659,7 +659,7 @@ initsite(void) /* Parse input from a file and execute it */ int -PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, +PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags) { if (filename == NULL) @@ -738,7 +738,7 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags ps2 = PyString_AsString(w); } arena = PyArena_New(); - mod = PyParser_ASTFromFile(fp, filename, + mod = PyParser_ASTFromFile(fp, filename, Py_single_input, ps1, ps2, flags, &errcode, arena); Py_XDECREF(v); @@ -1126,13 +1126,15 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) /* Don't do anything else */ } else if (PyExceptionClass_Check(exception)) { - char* className = PyExceptionClass_Name(exception); - char *dot = strrchr(className, '.'); PyObject* moduleName; - if (dot != NULL) - className = dot+1; - moduleName = PyObject_GetAttrString(exception, "__module__"); + char* className = PyExceptionClass_Name(exception); + if (className != NULL) { + char *dot = strrchr(className, '.'); + if (dot != NULL) + className = dot+1; + } + moduleName = PyObject_GetAttrString(exception, "__module__"); if (moduleName == NULL) err = PyFile_WriteString("", f); else { @@ -1178,7 +1180,7 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) } PyObject * -PyRun_StringFlags(const char *str, int start, PyObject *globals, +PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags) { PyObject *ret = NULL; @@ -1225,7 +1227,7 @@ run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, } static PyObject * -run_pyc_file(FILE *fp, const char *filename, PyObject *globals, +run_pyc_file(FILE *fp, const char *filename, PyObject *globals, PyObject *locals, PyCompilerFlags *flags) { PyCodeObject *co; @@ -1294,13 +1296,13 @@ Py_SymtableString(const char *str, const char *filename, int start) /* Preferred access to parser is through AST. */ mod_ty -PyParser_ASTFromString(const char *s, const char *filename, int start, +PyParser_ASTFromString(const char *s, const char *filename, int start, PyCompilerFlags *flags, PyArena *arena) { mod_ty mod; perrdetail err; node *n = PyParser_ParseStringFlagsFilename(s, filename, - &_PyParser_Grammar, start, &err, + &_PyParser_Grammar, start, &err, PARSER_FLAGS(flags)); if (n) { mod = PyAST_FromNode(n, flags, filename, arena); @@ -1314,7 +1316,7 @@ PyParser_ASTFromString(const char *s, const char *filename, int start, } mod_ty -PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, +PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, char *ps2, PyCompilerFlags *flags, int *errcode, PyArena *arena) { @@ -1345,7 +1347,7 @@ PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int fla start, NULL, NULL, &err, flags); if (n == NULL) err_input(&err); - + return n; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c6eb91fc6f5..4c92a90210e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -196,7 +196,7 @@ static PyObject * sys_exit(PyObject *self, PyObject *args) { PyObject *exit_code = 0; - if (!PyArg_ParseTuple(args, "|O:exit", &exit_code)) + if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code)) return NULL; /* Raise SystemExit so callers may catch it or clean up. */ PyErr_SetObject(PyExc_SystemExit, exit_code); @@ -668,7 +668,7 @@ static PyObject * sys_call_tracing(PyObject *self, PyObject *args) { PyObject *func, *funcargs; - if (!PyArg_ParseTuple(args, "OO:call_tracing", &func, &funcargs)) + if (!PyArg_UnpackTuple(args, "call_tracing", 2, 2, &func, &funcargs)) return NULL; return _PyEval_CallTracing(func, funcargs); } diff --git a/RISCOS/Modules/riscosmodule.c b/RISCOS/Modules/riscosmodule.c index 2ad449949e1..3dabb4d5894 100644 --- a/RISCOS/Modules/riscosmodule.c +++ b/RISCOS/Modules/riscosmodule.c @@ -31,39 +31,50 @@ static PyObject *riscos_oserror(void) /* RISCOS file commands */ -static PyObject *riscos_remove(PyObject *self,PyObject *args) -{ char *path1; - if (!PyArg_Parse(args, "s", &path1)) return NULL; +static PyObject * +riscos_remove(PyObject *self, PyObject *args) +{ + char *path1; + if (!PyArg_ParseTuple(args, "s:remove", &path1)) return NULL; if (remove(path1)) return PyErr_SetFromErrno(PyExc_OSError); Py_INCREF(Py_None); return Py_None; } -static PyObject *riscos_rename(PyObject *self,PyObject *args) -{ char *path1, *path2; - if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL; +static PyObject * +riscos_rename(PyObject *self, PyObject *args) +{ + char *path1, *path2; + if (!PyArg_ParseTuple(args, "ss:rename", &path1, &path2)) + return NULL; if (rename(path1,path2)) return PyErr_SetFromErrno(PyExc_OSError); Py_INCREF(Py_None); return Py_None; } -static PyObject *riscos_system(PyObject *self,PyObject *args) -{ char *command; - if (!PyArg_Parse(args, "s", &command)) return NULL; +static PyObject * +riscos_system(PyObject *self, PyObject *args) +{ + char *command; + if (!PyArg_ParseTuple(args, "s:system", &command)) return NULL; return PyInt_FromLong(system(command)); } -static PyObject *riscos_chdir(PyObject *self,PyObject *args) -{ char *path; - if (!PyArg_Parse(args, "s", &path)) return NULL; +static PyObject * +riscos_chdir(PyObject *self, PyObject *args) +{ + char *path; + if (!PyArg_ParseTuple(args, "s:chdir", &path)) return NULL; e=xosfscontrol_dir(path); if(e) return riscos_oserror(); Py_INCREF(Py_None); return Py_None; } -static PyObject *canon(char *path) -{ int len; +static PyObject * +canon(char *path) +{ + int len; PyObject *obj; char *buf; e=xosfscontrol_canonicalise_path(path,0,0,0,0,&len); @@ -78,32 +89,39 @@ static PyObject *canon(char *path) return riscos_oserror(); } -static PyObject *riscos_getcwd(PyObject *self,PyObject *args) -{ - return canon("@"); +static PyObject * +riscos_getcwd(PyObject *self, PyObject *unused) +{ + return canon("@"); } -static PyObject *riscos_expand(PyObject *self,PyObject *args) -{ char *path; - if (!PyArg_Parse(args, "s", &path)) return NULL; +static PyObject * +riscos_expand(PyObject *self, PyObject *args) +{ + char *path; + if (!PyArg_ParseTuple(args, "s:expand", &path)) return NULL; return canon(path); } -static PyObject *riscos_mkdir(PyObject *self,PyObject *args) -{ char *path; - int mode; - if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) return NULL; - e=xosfile_create_dir(path,0); - if(e) return riscos_oserror(); +static PyObject * +riscos_mkdir(PyObject *self, PyObject *args) +{ + char *path; + int mode; + if (!PyArg_ParseTuple(args, "s|i:mkdir", &path, &mode)) return NULL; + e=xosfile_create_dir(path,0); + if(e) return riscos_oserror(); Py_INCREF(Py_None); return Py_None; } -static PyObject *riscos_listdir(PyObject *self,PyObject *args) -{ char *path,buf[256]; - PyObject *d, *v; - int c=0,count; - if (!PyArg_Parse(args, "s", &path)) return NULL; +static PyObject * +riscos_listdir(PyObject *self, PyObject *args) +{ + char *path,buf[256]; + PyObject *d, *v; + int c=0,count; + if (!PyArg_ParseTuple(args, "s:listdir", &path)) return NULL; d=PyList_New(0); if(!d) return NULL; for(;;) @@ -158,14 +176,15 @@ static PyStructSequence_Desc stat_result_desc = { static PyTypeObject StatResultType; -static PyObject *riscos_stat(PyObject *self,PyObject *args) +static PyObject * +riscos_stat(PyObject *self, PyObject *args) { PyObject *v; char *path; int ob,len; bits t=0; bits ld,ex,at,ft,mode; - if (!PyArg_Parse(args, "s", &path)) return NULL; + if (!PyArg_ParseTuple(args, "s:stat", &path)) return NULL; e=xosfile_read_stamped_no_path(path,&ob,&ld,&ex,&len,&at,&ft); if(e) return riscos_oserror(); switch (ob) @@ -207,13 +226,15 @@ static PyObject *riscos_stat(PyObject *self,PyObject *args) return v; } -static PyObject *riscos_chmod(PyObject *self,PyObject *args) -{ char *path; - bits mode; - bits attr; - attr=(mode&0x700)>>8; - attr|=(mode&7)<<4; - if (!PyArg_Parse(args, "(si)", &path,(int*)&mode)) return NULL; +static PyObject * +riscos_chmod(PyObject *self,PyObject *args) +{ + char *path; + bits mode; + bits attr; + attr=(mode&0x700)>>8; + attr|=(mode&7)<<4; + if (!PyArg_ParseTuple(args, "si:chmod", &path,(int*)&mode)) return NULL; e=xosfile_write_attr(path,attr); if(e) return riscos_oserror(); Py_INCREF(Py_None); @@ -221,7 +242,8 @@ static PyObject *riscos_chmod(PyObject *self,PyObject *args) } -static PyObject *riscos_utime(PyObject *self,PyObject *args) +static PyObject * +riscos_utime(PyObject *self, PyObject *args) { char *path; long atime, mtime; @@ -274,35 +296,42 @@ static PyObject *riscos_utime(PyObject *self,PyObject *args) return Py_None; } -static PyObject *riscos_settype(PyObject *self,PyObject *args) -{ char *path,*name; - int type; - if (!PyArg_Parse(args, "(si)", &path,&type)) - { PyErr_Clear(); - if (!PyArg_Parse(args, "(ss)", &path,&name)) return NULL; +static PyObject * +riscos_settype(PyObject *self, PyObject *args) +{ + char *path,*name; + int type; + if (!PyArg_ParseTuple(args, "si:settype", &path,&type)) + { + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "ss:settype", &path,&name)) return NULL; e=xosfscontrol_file_type_from_string(name,(bits*)&type); if(e) return riscos_oserror(); } - e=xosfile_set_type(path,type); - if(e) return riscos_oserror(); + e=xosfile_set_type(path,type); + if(e) return riscos_oserror(); Py_INCREF(Py_None); return Py_None; } -static PyObject *riscos_getenv(PyObject *self,PyObject *args) -{ char *name,*value; - if(!PyArg_Parse(args,"s",&name)) return NULL; +static PyObject * +riscos_getenv(PyObject *self, PyObject *args) +{ + char *name,*value; + if(!PyArg_ParseTuple(args,"s:getenv",&name)) return NULL; value=getenv(name); if(value) return PyString_FromString(value); Py_INCREF(Py_None); return Py_None; } -static PyObject *riscos_putenv(PyObject *self,PyObject *args) -{ char *name,*value; +static PyObject * +riscos_putenv(PyObject *self, PyObject *args) +{ + char *name,*value; int len; os_var_type type=os_VARTYPE_LITERAL_STRING; - if(!PyArg_ParseTuple(args,"ss|i",&name,&value,&type)) return NULL; + if(!PyArg_ParseTuple(args,"ss|i:putenv",&name,&value,&type)) return NULL; if(type!=os_VARTYPE_STRING&&type!=os_VARTYPE_MACRO&&type!=os_VARTYPE_EXPANDED &&type!=os_VARTYPE_LITERAL_STRING) return riscos_error("Bad putenv type"); @@ -315,22 +344,26 @@ static PyObject *riscos_putenv(PyObject *self,PyObject *args) return Py_None; } -static PyObject *riscos_delenv(PyObject *self,PyObject *args) -{ char *name; - if(!PyArg_Parse(args,"s",&name)) return NULL; +static PyObject * +riscos_delenv(PyObject *self, PyObject *args) +{ + char *name; + if(!PyArg_ParseTuple(args,"s:delenv",&name)) return NULL; e=xos_set_var_val(name,NULL,-1,0,0,0,0); if(e) return riscos_oserror(); Py_INCREF(Py_None); return Py_None; } -static PyObject *riscos_getenvdict(PyObject *self,PyObject *args) -{ PyObject *dict; +static PyObject * +riscos_getenvdict(PyObject *self, PyObject *args) +{ + PyObject *dict; char value[257]; char *which="*"; int size; char *context=NULL; - if(!PyArg_ParseTuple(args,"|s",&which)) return NULL; + if(!PyArg_ParseTuple(args,"|s:getenvdict",&which)) return NULL; dict = PyDict_New(); if (!dict) return NULL; /* XXX This part ignores errors */ @@ -348,25 +381,25 @@ static PyObject *riscos_getenvdict(PyObject *self,PyObject *args) static PyMethodDef riscos_methods[] = { - {"unlink", riscos_remove}, - {"remove", riscos_remove}, - {"rename", riscos_rename}, - {"system", riscos_system}, - {"rmdir", riscos_remove}, - {"chdir", riscos_chdir}, + {"unlink", riscos_remove, METH_VARARGS}, + {"remove", riscos_remove, METH_VARARGS}, + {"rename", riscos_rename, METH_VARARGS}, + {"system", riscos_system, METH_VARARGS}, + {"rmdir", riscos_remove, METH_VARARGS}, + {"chdir", riscos_chdir, METH_VARARGS}, {"getcwd", riscos_getcwd, METH_NOARGS}, - {"expand", riscos_expand}, - {"mkdir", riscos_mkdir,1}, - {"listdir", riscos_listdir}, - {"stat", riscos_stat}, - {"lstat", riscos_stat}, - {"chmod", riscos_chmod}, - {"utime", riscos_utime}, - {"settype", riscos_settype}, - {"getenv", riscos_getenv}, - {"putenv", riscos_putenv}, - {"delenv", riscos_delenv}, - {"getenvdict", riscos_getenvdict,1}, + {"expand", riscos_expand, METH_VARARGS}, + {"mkdir", riscos_mkdir, METH_VARARGS}, + {"listdir", riscos_listdir, METH_VARARGS}, + {"stat", riscos_stat, METH_VARARGS}, + {"lstat", riscos_stat, METH_VARARGS}, + {"chmod", riscos_chmod, METH_VARARGS}, + {"utime", riscos_utime, METH_VARARGS}, + {"settype", riscos_settype, METH_VARARGS}, + {"getenv", riscos_getenv, METH_VARARGS}, + {"putenv", riscos_putenv, METH_VARARGS}, + {"delenv", riscos_delenv, METH_VARARGS}, + {"getenvdict", riscos_getenvdict, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; diff --git a/RISCOS/Modules/swimodule.c b/RISCOS/Modules/swimodule.c index b460b2fc6ae..b241276a18d 100644 --- a/RISCOS/Modules/swimodule.c +++ b/RISCOS/Modules/swimodule.c @@ -552,14 +552,14 @@ Read count bytes from given address."; static PyMethodDef SwiMethods[]= -{ { "swi", swi_swi,1}, - { "block", PyBlock_New,1}, - { "register", PyRegister,1}, - { "string", swi_string,METH_VARARGS, swi_string__doc__}, - { "integer", swi_integer,METH_VARARGS, swi_integer__doc__}, - { "integers", swi_integers,METH_VARARGS, swi_integers__doc__}, - { "tuples", swi_tuples,METH_VARARGS, swi_tuples__doc__}, - { "tuple", swi_tuple,METH_VARARGS, swi_tuple__doc__}, +{ { "swi", swi_swi, METH_VARARGS}, + { "block", PyBlock_New, METH_VARARGS}, + { "register", PyRegister, METH_VARARGS}, + { "string", swi_string, METH_VARARGS, swi_string__doc__}, + { "integer", swi_integer, METH_VARARGS, swi_integer__doc__}, + { "integers", swi_integers, METH_VARARGS, swi_integers__doc__}, + { "tuples", swi_tuples, METH_VARARGS, swi_tuples__doc__}, + { "tuple", swi_tuple, METH_VARARGS, swi_tuple__doc__}, { NULL,NULL,0,NULL} /* Sentinel */ }; diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py index 33d7bfa044d..2576380519e 100644 --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -455,10 +455,6 @@ def add_ui(db): exit_dialog.cancel("Cancel", "Back", active = 0) exit_dialog.text("Acknowledgements", 135, 95, 220, 120, 0x30003, "Special Windows thanks to:\n" - " LettError, Erik van Blokland, for the \n" - " Python for Windows graphic.\n" - " http://www.letterror.com/\n" - "\n" " Mark Hammond, without whose years of freely \n" " shared Windows expertise, Python for Windows \n" " would still be Python for DOS.") diff --git a/Tools/pybench/systimes.py b/Tools/pybench/systimes.py new file mode 100644 index 00000000000..79d249f8bb9 --- /dev/null +++ b/Tools/pybench/systimes.py @@ -0,0 +1,197 @@ +#!/usr/bin/env python + +""" systimes() user and system timer implementations for use by + pybench. + + This module implements various different strategies for measuring + performance timings. It tries to choose the best available method + based on the platforma and available tools. + + On Windows, it is recommended to have the Mark Hammond win32 + package installed. Alternatively, the Thomas Heller ctypes + packages can also be used. + + On Unix systems, the standard resource module provides the highest + resolution timings. Unfortunately, it is not available on all Unix + platforms. + + If no supported timing methods based on process time can be found, + the module reverts to the highest resolution wall-time timer + instead. The system time part will then always be 0.0. + + The module exports one public API: + + def systimes(): + + Return the current timer values for measuring user and system + time as tuple of seconds (user_time, system_time). + + Copyright (c) 2006, Marc-Andre Lemburg (mal@egenix.com). See the + documentation for further information on copyrights, or contact + the author. All Rights Reserved. + +""" +import time, sys, struct + +# +# Note: Please keep this module compatible to Python 1.5.2. +# +# TODOs: +# +# * Add ctypes wrapper for new clock_gettime() real-time POSIX APIs; +# these will then provide nano-second resolution where available. +# +# * Add a function that returns the resolution of systimes() +# values, ie. systimesres(). +# + +### Choose an implementation + +SYSTIMES_IMPLEMENTATION = None +USE_CTYPES_GETPROCESSTIMES = 'cytpes GetProcessTimes() wrapper' +USE_WIN32PROCESS_GETPROCESSTIMES = 'win32process.GetProcessTimes()' +USE_RESOURCE_GETRUSAGE = 'resource.getrusage()' +USE_PROCESS_TIME_CLOCK = 'time.clock() (process time)' +USE_WALL_TIME_CLOCK = 'time.clock() (wall-time)' +USE_WALL_TIME_TIME = 'time.time() (wall-time)' + +if sys.platform[:3] == 'win': + # Windows platform + try: + import win32process + except ImportError: + try: + import ctypes + except ImportError: + # Use the wall-time implementation time.clock(), since this + # is the highest resolution clock available on Windows + SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_CLOCK + else: + SYSTIMES_IMPLEMENTATION = USE_CTYPES_GETPROCESSTIMES + else: + SYSTIMES_IMPLEMENTATION = USE_WIN32PROCESS_GETPROCESSTIMES +else: + # All other platforms + try: + import resource + except ImportError: + pass + else: + SYSTIMES_IMPLEMENTATION = USE_RESOURCE_GETRUSAGE + +# Fall-back solution +if SYSTIMES_IMPLEMENTATION is None: + # Check whether we can use time.clock() as approximation + # for systimes() + start = time.clock() + time.sleep(0.1) + stop = time.clock() + if stop - start < 0.001: + # Looks like time.clock() is usable (and measures process + # time) + SYSTIMES_IMPLEMENTATION = USE_PROCESS_TIME_CLOCK + else: + # Use wall-time implementation time.time() since this provides + # the highest resolution clock on most systems + SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_TIME + +### Implementations + +def getrusage_systimes(): + return resource.getrusage(resource.RUSAGE_SELF)[:2] + +def process_time_clock_systimes(): + return (time.clock(), 0.0) + +def wall_time_clock_systimes(): + return (time.clock(), 0.0) + +def wall_time_time_systimes(): + return (time.time(), 0.0) + +# Number of clock ticks per second for the values returned +# by GetProcessTimes() on Windows. +# +# Note: Ticks returned by GetProcessTimes() are micro-seconds on +# Windows XP (though the docs say 100ns intervals) +WIN32_PROCESS_TIMES_TICKS_PER_SECOND = 10e6 + +def win32process_getprocesstimes_systimes(): + d = win32process.GetProcessTimes(win32process.GetCurrentProcess()) + # Note: I'm not sure whether KernelTime on Windows is the same as + # system time on Unix - I've yet to see a non-zero value for + # KernelTime on Windows. + return (d['UserTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND, + d['KernelTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND) + +def ctypes_getprocesstimes_systimes(): + creationtime = ctypes.c_ulonglong() + exittime = ctypes.c_ulonglong() + kerneltime = ctypes.c_ulonglong() + usertime = ctypes.c_ulonglong() + rc = ctypes.windll.kernel32.GetProcessTimes( + ctypes.windll.kernel32.GetCurrentProcess(), + ctypes.byref(creationtime), + ctypes.byref(exittime), + ctypes.byref(kerneltime), + ctypes.byref(usertime)) + if not rc: + raise TypeError('GetProcessTimes() returned an error') + return (usertime.value / WIN32_PROCESS_TIMES_TICKS_PER_SECOND, + kerneltime.value / WIN32_PROCESS_TIMES_TICKS_PER_SECOND) + +# Select the default for the systimes() function + +if SYSTIMES_IMPLEMENTATION is USE_RESOURCE_GETRUSAGE: + systimes = getrusage_systimes + +elif SYSTIMES_IMPLEMENTATION is USE_PROCESS_TIME_CLOCK: + systimes = process_time_clock_systimes + +elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_CLOCK: + systimes = wall_time_clock_systimes + +elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_TIME: + systimes = wall_time_time_systimes + +elif SYSTIMES_IMPLEMENTATION is USE_WIN32PROCESS_GETPROCESSTIMES: + systimes = win32process_getprocesstimes_systimes + +elif SYSTIMES_IMPLEMENTATION is USE_CTYPES_GETPROCESSTIMES: + systimes = ctypes_getprocesstimes_systimes + +else: + raise TypeError('no suitable systimes() implementation found') + +### Testing + +def some_workload(): + x = 0L + for i in xrange(10000000L): + x = x + 1L + +def test_workload(): + print 'Testing systimes() under load conditions' + t0 = systimes() + some_workload() + t1 = systimes() + print 'before:', t0 + print 'after:', t1 + print 'differences:', (t1[0] - t0[0], t1[1] - t0[1]) + print + +def test_idle(): + print 'Testing systimes() under idle conditions' + t0 = systimes() + time.sleep(1) + t1 = systimes() + print 'before:', t0 + print 'after:', t1 + print 'differences:', (t1[0] - t0[0], t1[1] - t0[1]) + print + +if __name__ == '__main__': + print 'Using %s as timer' % SYSTIMES_IMPLEMENTATION + print + test_workload() + test_idle() diff --git a/setup.py b/setup.py index 0abafd94d4e..9b2fac4b613 100644 --- a/setup.py +++ b/setup.py @@ -377,8 +377,8 @@ class PyBuildExt(build_ext): exts.append( Extension("_heapq", ["_heapqmodule.c"]) ) # operator.add() and similar goodies exts.append( Extension('operator', ['operator.c']) ) - # functional - exts.append( Extension("functional", ["functionalmodule.c"]) ) + # _functools + exts.append( Extension("_functools", ["_functoolsmodule.c"]) ) # Python C API test module exts.append( Extension('_testcapi', ['_testcapimodule.c']) ) # profilers (_lsprof is for cProfile.py)