[Python-checkins] r46126 - in python/branches/rjones-funccall: Doc/api/exceptions.tex Doc/whatsnew/whatsnew25.tex Include/unicodeobject.h Lib/distutils/command/build_ext.py Lib/distutils/sysconfig.py Lib/distutils/unixccompiler.py Lib/distutils/util.py Mac/OSX/BuildScript Mac/OSX/BuildScript/build-installer.py Mac/OSX/BuildScript/resources/background.jpg Mac/OSX/BuildScript/scripts/postflight.documentation Mac/OSX/BuildScript/scripts/postflight.framework Mac/OSX/BuildScript/scripts/postflight.patch-profile Mac/OSX/Makefile.in Misc/NEWS Objects/frameobject.c Objects/unicodeobject.c Python/errors.c
richard.jones
python-checkins at python.org
Tue May 23 20:19:17 CEST 2006
Author: richard.jones
Date: Tue May 23 20:19:15 2006
New Revision: 46126
Added:
python/branches/rjones-funccall/Mac/OSX/BuildScript/
- copied from r46113, python/trunk/Mac/OSX/BuildScript/
Modified:
python/branches/rjones-funccall/ (props changed)
python/branches/rjones-funccall/Doc/api/exceptions.tex
python/branches/rjones-funccall/Doc/whatsnew/whatsnew25.tex
python/branches/rjones-funccall/Include/unicodeobject.h
python/branches/rjones-funccall/Lib/distutils/command/build_ext.py
python/branches/rjones-funccall/Lib/distutils/sysconfig.py
python/branches/rjones-funccall/Lib/distutils/unixccompiler.py
python/branches/rjones-funccall/Lib/distutils/util.py
python/branches/rjones-funccall/Mac/OSX/BuildScript/build-installer.py (props changed)
python/branches/rjones-funccall/Mac/OSX/BuildScript/resources/background.jpg (props changed)
python/branches/rjones-funccall/Mac/OSX/BuildScript/scripts/postflight.documentation (props changed)
python/branches/rjones-funccall/Mac/OSX/BuildScript/scripts/postflight.framework (props changed)
python/branches/rjones-funccall/Mac/OSX/BuildScript/scripts/postflight.patch-profile (props changed)
python/branches/rjones-funccall/Mac/OSX/Makefile.in
python/branches/rjones-funccall/Misc/NEWS
python/branches/rjones-funccall/Objects/frameobject.c
python/branches/rjones-funccall/Objects/unicodeobject.c
python/branches/rjones-funccall/Python/errors.c
Log:
merge from trunk
Modified: python/branches/rjones-funccall/Doc/api/exceptions.tex
==============================================================================
--- python/branches/rjones-funccall/Doc/api/exceptions.tex (original)
+++ python/branches/rjones-funccall/Doc/api/exceptions.tex Tue May 23 20:19:15 2006
@@ -341,7 +341,8 @@
The \member{__module__} attribute of the new class is set to the
first part (up to the last dot) of the \var{name} argument, and the
class name is set to the last part (after the last dot). The
- \var{base} argument can be used to specify an alternate base class.
+ \var{base} argument can be used to specify alternate base classes;
+ it can either be only one class or a tuple of classes.
The \var{dict} argument can be used to specify a dictionary of class
variables and methods.
\end{cfuncdesc}
Modified: python/branches/rjones-funccall/Doc/whatsnew/whatsnew25.tex
==============================================================================
--- python/branches/rjones-funccall/Doc/whatsnew/whatsnew25.tex (original)
+++ python/branches/rjones-funccall/Doc/whatsnew/whatsnew25.tex Tue May 23 20:19:15 2006
@@ -1120,6 +1120,13 @@
%======================================================================
\subsection{Optimizations\label{opts}}
+Several of the optimizations were developed at the NeedForSpeed
+sprint, an event held in Reykjavik, Iceland, from May 21--28 2006.
+The sprint focused on speed enhancements to the CPython implementation
+and was funded by EWT LLC with local support from CCP Games. Those
+optimizations added at this sprint are specially marked in the
+following list.
+
\begin{itemize}
\item When they were introduced
@@ -1129,8 +1136,11 @@
and as a result sets will use a third less memory and are somewhat faster.
(Implemented by Raymond Hettinger.)
-\item The performance of some Unicode operations, such as
-character map decoding, has been improved.
+\item The speed of some Unicode operations, such as
+finding substrings and character map decoding, has been improved.
+(Substring search improvements were added by Fredrik Lundh and Andrew
+Dalke at the NeedForSpeed sprint. Character map decoding was improved
+by Walter D\"orwald.)
% Patch 1313939
\item The code generator's peephole optimizer now performs
@@ -1138,6 +1148,13 @@
\code{a = 2+3}, the code generator will do the arithmetic and produce
code corresponding to \code{a = 5}.
+\item Function calls are now faster because code objects now keep
+the most recently finished frame (a ``zombie frame'') in an internal
+field of the code object, reusing it the next time the code object is
+invoked. (Original patch by Michael Hudson, modified by Armin Rigo
+and Richard Jones; committed at the NeedForSpeed sprint.)
+% Patch 876206
+
\end{itemize}
The net result of the 2.5 optimizations is that Python 2.5 runs the
@@ -1411,7 +1428,7 @@
included in the \file{Tools/pybench} directory. The pybench suite is
an improvement on the commonly used \file{pystone.py} program because
pybench provides a more detailed measurement of the interpreter's
-performance. It times particular operations such as function calls,
+speed. It times particular operations such as function calls,
tuple slicing, method lookups, and numeric operations, instead of
performing many different operations and reducing the result to a
single number as \file{pystone.py} does.
@@ -1935,6 +1952,10 @@
\code{"trunk:45355:45356M, Apr 13 2006, 07:42:19"}.
(Contributed by Barry Warsaw.)
+\item \cfunction{PyErr_NewException(\var{name}, \var{base},
+\var{dict})} can now accept a tuple of base classes as its \var{base}
+argument. (Contributed by Georg Brandl.)
+
\item The CPython interpreter is still written in C, but
the code can now be compiled with a {\Cpp} compiler without errors.
(Implemented by Anthony Baxter, Martin von~L\"owis, Skip Montanaro.)
Modified: python/branches/rjones-funccall/Include/unicodeobject.h
==============================================================================
--- python/branches/rjones-funccall/Include/unicodeobject.h (original)
+++ python/branches/rjones-funccall/Include/unicodeobject.h Tue May 23 20:19:15 2006
@@ -367,10 +367,12 @@
for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\
} while (0)
-#define Py_UNICODE_MATCH(string, offset, substring)\
- ((*((string)->str + (offset)) == *((substring)->str)) &&\
- !memcmp((string)->str + (offset), (substring)->str,\
- (substring)->length*sizeof(Py_UNICODE)))
+/* check if substring matches at given offset. the offset must be
+ valid, and the substring must not be empty */
+#define Py_UNICODE_MATCH(string, offset, substring) \
+ ((*((string)->str + (offset)) == *((substring)->str)) && \
+ ((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \
+ !memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE)))
#ifdef __cplusplus
extern "C" {
Modified: python/branches/rjones-funccall/Lib/distutils/command/build_ext.py
==============================================================================
--- python/branches/rjones-funccall/Lib/distutils/command/build_ext.py (original)
+++ python/branches/rjones-funccall/Lib/distutils/command/build_ext.py Tue May 23 20:19:15 2006
@@ -689,6 +689,11 @@
# don't extend ext.libraries, it may be shared with other
# extensions, it is a reference to the original list
return ext.libraries + [pythonlib, "m"] + extra
+
+ elif sys.platform == 'darwin':
+ # Don't use the default code below
+ return ext.libraries
+
else:
from distutils import sysconfig
if sysconfig.get_config_var('Py_ENABLE_SHARED'):
Modified: python/branches/rjones-funccall/Lib/distutils/sysconfig.py
==============================================================================
--- python/branches/rjones-funccall/Lib/distutils/sysconfig.py (original)
+++ python/branches/rjones-funccall/Lib/distutils/sysconfig.py Tue May 23 20:19:15 2006
@@ -500,6 +500,21 @@
_config_vars['prefix'] = PREFIX
_config_vars['exec_prefix'] = EXEC_PREFIX
+ if sys.platform == 'darwin':
+ kernel_version = os.uname()[2] # Kernel version (8.4.3)
+ major_version = int(kernel_version.split('.')[0])
+
+ if major_version < 8:
+ # On Mac OS X before 10.4, check if -arch and -isysroot
+ # are in CFLAGS or LDFLAGS and remove them if they are.
+ # This is needed when building extensions on a 10.3 system
+ # using a universal build of python.
+ for key in ('LDFLAGS', 'BASECFLAGS'):
+ flags = _config_vars[key]
+ flags = re.sub('-arch\s+\w+\s', ' ', flags)
+ flags = re.sub('-isysroot [^ \t]* ', ' ', flags)
+ _config_vars[key] = flags
+
if args:
vals = []
for name in args:
Modified: python/branches/rjones-funccall/Lib/distutils/unixccompiler.py
==============================================================================
--- python/branches/rjones-funccall/Lib/distutils/unixccompiler.py (original)
+++ python/branches/rjones-funccall/Lib/distutils/unixccompiler.py Tue May 23 20:19:15 2006
@@ -42,6 +42,48 @@
# should just happily stuff them into the preprocessor/compiler/linker
# options and carry on.
+def _darwin_compiler_fixup(compiler_so, cc_args):
+ """
+ This function will strip '-isysroot PATH' and '-arch ARCH' from the
+ compile flags if the user has specified one them in extra_compile_flags.
+
+ This is needed because '-arch ARCH' adds another architecture to the
+ build, without a way to remove an architecture. Furthermore GCC will
+ barf if multiple '-isysroot' arguments are present.
+ """
+ stripArch = stripSysroot = 0
+
+ compiler_so = list(compiler_so)
+ kernel_version = os.uname()[2] # 8.4.3
+ major_version = int(kernel_version.split('.')[0])
+
+ if major_version < 8:
+ # OSX before 10.4.0, these don't support -arch and -isysroot at
+ # all.
+ stripArch = stripSysroot = True
+ else:
+ stripArch = '-arch' in cc_args
+ stripSysroot = '-isysroot' in cc_args
+
+ if stripArch:
+ while 1:
+ try:
+ index = compiler_so.index('-arch')
+ # Strip this argument and the next one:
+ del compiler_so[index:index+2]
+ except ValueError:
+ break
+
+ if stripSysroot:
+ try:
+ index = compiler_so.index('-isysroot')
+ # Strip this argument and the next one:
+ del compiler_so[index:index+1]
+ except ValueError:
+ pass
+
+ return compiler_so
+
class UnixCCompiler(CCompiler):
compiler_type = 'unix'
@@ -108,8 +150,11 @@
raise CompileError, msg
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
+ compiler_so = self.compiler_so
+ if sys.platform == 'darwin':
+ compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
try:
- self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
+ self.spawn(compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
except DistutilsExecError, msg:
raise CompileError, msg
@@ -172,7 +217,22 @@
else:
linker = self.linker_so[:]
if target_lang == "c++" and self.compiler_cxx:
- linker[0] = self.compiler_cxx[0]
+ # skip over environment variable settings if /usr/bin/env
+ # is used to set up the linker's environment.
+ # This is needed on OSX. Note: this assumes that the
+ # normal and C++ compiler have the same environment
+ # settings.
+ i = 0
+ if os.path.basename(linker[0]) == "env":
+ i = 1
+ while '=' in linker[i]:
+ i = i + 1
+
+ linker[i] = self.compiler_cxx[i]
+
+ if sys.platform == 'darwin':
+ linker = _darwin_compiler_fixup(linker, ld_args)
+
self.spawn(linker + ld_args)
except DistutilsExecError, msg:
raise LinkError, msg
Modified: python/branches/rjones-funccall/Lib/distutils/util.py
==============================================================================
--- python/branches/rjones-funccall/Lib/distutils/util.py (original)
+++ python/branches/rjones-funccall/Lib/distutils/util.py Tue May 23 20:19:15 2006
@@ -67,6 +67,54 @@
m = rel_re.match(release)
if m:
release = m.group()
+ elif osname[:6] == "darwin":
+ #
+ # For our purposes, we'll assume that the system version from
+ # distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
+ # to. This makes the compatibility story a bit more sane because the
+ # machine is going to compile and link as if it were
+ # MACOSX_DEPLOYMENT_TARGET.
+ from distutils.sysconfig import get_config_vars
+ cfgvars = get_config_vars()
+
+ macver = os.environ.get('MACOSX_DEPLOYMENT_TARGET')
+ if not macver:
+ macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
+
+ if not macver:
+ # Get the system version. Reading this plist is a documented
+ # way to get the system version (see the documentation for
+ # the Gestalt Manager)
+ try:
+ f = open('/System/Library/CoreServices/SystemVersion.plist')
+ except IOError:
+ # We're on a plain darwin box, fall back to the default
+ # behaviour.
+ pass
+ else:
+ m = re.search(
+ r'<key>ProductUserVisibleVersion</key>\s*' +
+ r'<string>(.*?)</string>', f.read())
+ f.close()
+ if m is not None:
+ macver = '.'.join(m.group(1).split('.')[:2])
+ # else: fall back to the default behaviour
+
+ if macver:
+ from distutils.sysconfig import get_config_vars
+ release = macver
+ osname = "macosx"
+
+
+ if (release + '.') < '10.4.' and \
+ get_config_vars().get('UNIVERSALSDK', '').strip():
+ # The universal build will build fat binaries, but not on
+ # systems before 10.4
+ machine = 'fat'
+
+ elif machine in ('PowerPC', 'Power_Macintosh'):
+ # Pick a sane name for the PPC architecture.
+ machine = 'ppc'
return "%s-%s-%s" % (osname, release, machine)
Modified: python/branches/rjones-funccall/Mac/OSX/Makefile.in
==============================================================================
--- python/branches/rjones-funccall/Mac/OSX/Makefile.in (original)
+++ python/branches/rjones-funccall/Mac/OSX/Makefile.in Tue May 23 20:19:15 2006
@@ -73,11 +73,16 @@
install_versionedtools:
for fn in idle pydoc python-config ;\
do \
+ if [ -h "$(DESTDIR)$(prefix)/bin/$${fn}" ]; then \
+ continue ;\
+ fi ;\
mv "$(DESTDIR)$(prefix)/bin/$${fn}" "$(DESTDIR)$(prefix)/bin/$${fn}$(VERSION)" ;\
ln -sf "$${fn}$(VERSION)" "$(DESTDIR)$(prefix)/bin/$${fn}" ;\
done
- mv "$(DESTDIR)$(prefix)/bin/smtpd.py" "$(DESTDIR)$(prefix)/bin/smtpd$(VERSION).py"
- ln -sf "smtpd$(VERSION).py" "$(DESTDIR)$(prefix)/bin/smtpd.py"
+ if [ ! -h "$(DESTDIR)$(prefix)/bin/smtpd.py" ]; then \
+ mv "$(DESTDIR)$(prefix)/bin/smtpd.py" "$(DESTDIR)$(prefix)/bin/smtpd$(VERSION).py" ;\
+ ln -sf "smtpd$(VERSION).py" "$(DESTDIR)$(prefix)/bin/smtpd.py" ;\
+ fi
pythonw: $(srcdir)/Tools/pythonw.c
Modified: python/branches/rjones-funccall/Misc/NEWS
==============================================================================
--- python/branches/rjones-funccall/Misc/NEWS (original)
+++ python/branches/rjones-funccall/Misc/NEWS Tue May 23 20:19:15 2006
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- PyErr_NewException now accepts a tuple of base classes as its
+ "base" parameter.
+
- Patch #876206: function call speedup by retaining allocated frame
objects.
Modified: python/branches/rjones-funccall/Objects/frameobject.c
==============================================================================
--- python/branches/rjones-funccall/Objects/frameobject.c (original)
+++ python/branches/rjones-funccall/Objects/frameobject.c Tue May 23 20:19:15 2006
@@ -555,7 +555,6 @@
PyFrameObject *f;
PyObject *builtins;
Py_ssize_t i;
- int frame_needs_init = 1;
#ifdef Py_DEBUG
if (code == NULL || globals == NULL || !PyDict_Check(globals) ||
@@ -595,7 +594,6 @@
Py_INCREF(builtins);
}
if (code->co_zombieframe != NULL) {
- frame_needs_init = 0;
f = code->co_zombieframe;
code->co_zombieframe = NULL;
_Py_NewReference((PyObject *)f);
@@ -605,9 +603,11 @@
Py_ssize_t extras, ncells, nfrees;
ncells = PyTuple_GET_SIZE(code->co_cellvars);
nfrees = PyTuple_GET_SIZE(code->co_freevars);
- extras = code->co_stacksize + code->co_nlocals + ncells + nfrees;
+ extras = code->co_stacksize + code->co_nlocals + ncells +
+ nfrees;
if (free_list == NULL) {
- f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras);
+ f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type,
+ extras);
if (f == NULL) {
Py_DECREF(builtins);
return NULL;
@@ -629,7 +629,11 @@
}
f->f_code = code;
- extras = f->f_code->co_nlocals + ncells + nfrees;
+ f->f_nlocals = code->co_nlocals;
+ f->f_stacksize = code->co_stacksize;
+ f->f_ncells = ncells;
+ f->f_nfreevars = nfrees;
+ extras = f->f_nlocals + ncells + nfrees;
f->f_valuestack = f->f_localsplus + extras;
for (i=0; i<extras; i++)
f->f_localsplus[i] = NULL;
Modified: python/branches/rjones-funccall/Objects/unicodeobject.c
==============================================================================
--- python/branches/rjones-funccall/Objects/unicodeobject.c (original)
+++ python/branches/rjones-funccall/Objects/unicodeobject.c Tue May 23 20:19:15 2006
@@ -4982,54 +4982,56 @@
int PyUnicode_Contains(PyObject *container,
PyObject *element)
{
- PyUnicodeObject *u = NULL, *v = NULL;
+ PyUnicodeObject *u, *v;
int result;
Py_ssize_t size;
- register const Py_UNICODE *lhs, *end, *rhs;
/* Coerce the two arguments */
- v = (PyUnicodeObject *)PyUnicode_FromObject(element);
- if (v == NULL) {
+ v = (PyUnicodeObject *) PyUnicode_FromObject(element);
+ if (!v) {
PyErr_SetString(PyExc_TypeError,
"'in <string>' requires string as left operand");
- goto onError;
+ return -1;
+ }
+
+ u = (PyUnicodeObject *) PyUnicode_FromObject(container);
+ if (!u) {
+ Py_DECREF(v);
+ return -1;
}
- u = (PyUnicodeObject *)PyUnicode_FromObject(container);
- if (u == NULL)
- goto onError;
size = PyUnicode_GET_SIZE(v);
- rhs = PyUnicode_AS_UNICODE(v);
- lhs = PyUnicode_AS_UNICODE(u);
+ if (!size) {
+ result = 1;
+ goto done;
+ }
result = 0;
+
if (size == 1) {
- end = lhs + PyUnicode_GET_SIZE(u);
- while (lhs < end) {
- if (*lhs++ == *rhs) {
- result = 1;
- break;
- }
- }
- }
- else {
- end = lhs + (PyUnicode_GET_SIZE(u) - size);
- while (lhs <= end) {
- if (memcmp(lhs++, rhs, size * sizeof(Py_UNICODE)) == 0) {
+ Py_UNICODE chr = PyUnicode_AS_UNICODE(v)[0];
+ Py_UNICODE* ptr = PyUnicode_AS_UNICODE(u);
+ Py_UNICODE* end = ptr + PyUnicode_GET_SIZE(u);
+ for (; ptr < end; ptr++) {
+ if (*ptr == chr) {
result = 1;
break;
}
}
+ } else {
+ int start = 0;
+ int end = PyUnicode_GET_SIZE(u) - size;
+ for (; start <= end; start++)
+ if (Py_UNICODE_MATCH(u, start, v)) {
+ result = 1;
+ break;
+ }
}
+done:
Py_DECREF(u);
Py_DECREF(v);
return result;
-
-onError:
- Py_XDECREF(u);
- Py_XDECREF(v);
- return -1;
}
/* Concat to string or Unicode object giving a new Unicode object. */
Modified: python/branches/rjones-funccall/Python/errors.c
==============================================================================
--- python/branches/rjones-funccall/Python/errors.c (original)
+++ python/branches/rjones-funccall/Python/errors.c Tue May 23 20:19:15 2006
@@ -527,6 +527,7 @@
}
+
PyObject *
PyErr_NewException(char *name, PyObject *base, PyObject *dict)
{
@@ -559,9 +560,15 @@
classname = PyString_FromString(dot+1);
if (classname == NULL)
goto failure;
- bases = PyTuple_Pack(1, base);
- if (bases == NULL)
- goto failure;
+ if (PyTuple_Check(base)) {
+ bases = base;
+ /* INCREF as we create a new ref in the else branch */
+ Py_INCREF(bases);
+ } else {
+ bases = PyTuple_Pack(1, base);
+ if (bases == NULL)
+ goto failure;
+ }
result = PyClass_New(bases, dict, classname);
failure:
Py_XDECREF(bases);
More information about the Python-checkins
mailing list