[Python-checkins] r64506 - in python/branches/tlee-ast-optimize: Doc/library/cmath.rst Doc/library/subprocess.rst Doc/whatsnew/2.6.rst Include/stringobject.h Lib/_abcoll.py Lib/test/test_collections.py Lib/test/test_cpickle.py Lib/test/test_posix.py Lib/test/test_types.py Misc/NEWS Modules/_sqlite/module.c Modules/cPickle.c Modules/posixmodule.c Objects/stringlib/formatter.h Objects/stringlib/localeutil.h PCbuild/_ctypes.vcproj Python/pystrtod.c
thomas.lee
python-checkins at python.org
Tue Jun 24 16:30:36 CEST 2008
Author: thomas.lee
Date: Tue Jun 24 16:30:35 2008
New Revision: 64506
Log:
Merged revisions 64452-64502 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64452 | facundo.batista | 2008-06-22 23:36:20 +1000 (Sun, 22 Jun 2008) | 5 lines
Issue #2722. Now the char buffer to support the path string has
not fixed length, it mallocs memory if needed. As a result, we
don't have a maximum for the getcwd() method.
........
r64453 | andrew.kuchling | 2008-06-22 23:39:11 +1000 (Sun, 22 Jun 2008) | 1 line
Wording fix
........
r64455 | facundo.batista | 2008-06-23 01:27:10 +1000 (Mon, 23 Jun 2008) | 4 lines
Issue 3164. Small fix to don't repeat a comparation
without necessity.
........
r64456 | facundo.batista | 2008-06-23 02:11:34 +1000 (Mon, 23 Jun 2008) | 4 lines
Trying to see if the @ in a path is causing the issue in the
shutil.rmtree() in the trunk.loewis-sun buildbot.
........
r64461 | georg.brandl | 2008-06-23 04:11:52 +1000 (Mon, 23 Jun 2008) | 2 lines
#3085: Fix syntax error.
........
r64462 | facundo.batista | 2008-06-23 04:23:55 +1000 (Mon, 23 Jun 2008) | 4 lines
Trying to see if the problem in Martin's buildot is at
directory creation time...
........
r64464 | georg.brandl | 2008-06-23 04:31:54 +1000 (Mon, 23 Jun 2008) | 2 lines
Expand docstrings of sqlite3 functions.
........
r64466 | georg.brandl | 2008-06-23 05:07:59 +1000 (Mon, 23 Jun 2008) | 2 lines
Write out "phi" consistently.
........
r64468 | facundo.batista | 2008-06-23 05:35:24 +1000 (Mon, 23 Jun 2008) | 4 lines
Just returning nothing instead of rising TestSkipped, because
it makes the test fail in the trunk.loewis-sun buildbot.
........
r64471 | facundo.batista | 2008-06-23 09:19:14 +1000 (Mon, 23 Jun 2008) | 5 lines
Fixing the problem stated in issue 2702 with the patch submitted
in the issue 3165. Now cPickle does not fails with uncontrolled
behaviour when pickling into a very deep nested structure.
........
r64475 | raymond.hettinger | 2008-06-23 13:29:28 +1000 (Mon, 23 Jun 2008) | 1 line
Issue 3161: Missing import and test.
........
r64489 | thomas.heller | 2008-06-24 00:49:56 +1000 (Tue, 24 Jun 2008) | 2 lines
Fix compilation on Windows.
........
r64490 | thomas.heller | 2008-06-24 05:51:41 +1000 (Tue, 24 Jun 2008) | 1 line
Include debug info when assembling win64.asm in a debug build.
........
r64491 | eric.smith | 2008-06-24 10:42:10 +1000 (Tue, 24 Jun 2008) | 1 line
Modified interface to _Py_[String|Unicode]InsertThousandsGrouping, in anticipation of fixing issue 3140.
........
r64495 | benjamin.peterson | 2008-06-24 12:41:08 +1000 (Tue, 24 Jun 2008) | 1 line
minor fix
........
r64496 | eric.smith | 2008-06-24 16:05:30 +1000 (Tue, 24 Jun 2008) | 1 line
Typo in comment.
........
r64498 | mark.dickinson | 2008-06-24 21:08:58 +1000 (Tue, 24 Jun 2008) | 4 lines
Change description of float('nan') feature; NaNs don't care much about
signs, and float('nan'), float('+nan') and float('-nan') actually all
generate the exact same NaN value.
........
r64499 | eric.smith | 2008-06-24 21:11:59 +1000 (Tue, 24 Jun 2008) | 1 line
Fixed formatting with thousands separator and padding. Resolves issue 3140.
........
Modified:
python/branches/tlee-ast-optimize/ (props changed)
python/branches/tlee-ast-optimize/Doc/library/cmath.rst
python/branches/tlee-ast-optimize/Doc/library/subprocess.rst
python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
python/branches/tlee-ast-optimize/Include/stringobject.h
python/branches/tlee-ast-optimize/Lib/_abcoll.py
python/branches/tlee-ast-optimize/Lib/test/test_collections.py
python/branches/tlee-ast-optimize/Lib/test/test_cpickle.py
python/branches/tlee-ast-optimize/Lib/test/test_posix.py
python/branches/tlee-ast-optimize/Lib/test/test_types.py
python/branches/tlee-ast-optimize/Misc/NEWS
python/branches/tlee-ast-optimize/Modules/_sqlite/module.c
python/branches/tlee-ast-optimize/Modules/cPickle.c
python/branches/tlee-ast-optimize/Modules/posixmodule.c
python/branches/tlee-ast-optimize/Objects/stringlib/formatter.h
python/branches/tlee-ast-optimize/Objects/stringlib/localeutil.h
python/branches/tlee-ast-optimize/PCbuild/_ctypes.vcproj
python/branches/tlee-ast-optimize/Python/pystrtod.c
Modified: python/branches/tlee-ast-optimize/Doc/library/cmath.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/cmath.rst (original)
+++ python/branches/tlee-ast-optimize/Doc/library/cmath.rst Tue Jun 24 16:30:35 2008
@@ -40,9 +40,9 @@
In engineering the polar coordinate system is popular for complex numbers. In
polar coordinates a complex number is defined by the radius *r* and the phase
-angle *φ*. The radius *r* is the absolute value of the complex, which can be
+angle *phi*. The radius *r* is the absolute value of the complex, which can be
viewed as distance from (0, 0). The radius *r* is always 0 or a positive float.
-The phase angle *φ* is the counter clockwise angle from the positive x axis,
+The phase angle *phi* is the counter clockwise angle from the positive x axis,
e.g. *1* has the angle *0*, *1j* has the angle *π/2* and *-1* the angle *-π*.
.. note::
@@ -53,12 +53,12 @@
Definition::
- z = r * exp(1j * φ)
- z = r * cis(φ)
+ z = r * exp(1j * phi)
+ z = r * cis(phi)
r := abs(z) := sqrt(real(z)**2 + imag(z)**2)
phi := phase(z) := atan2(imag(z), real(z))
- cis(φ) := cos(φ) + 1j * sin(φ)
+ cis(phi) := cos(phi) + 1j * sin(phi)
.. function:: phase(x)
Modified: python/branches/tlee-ast-optimize/Doc/library/subprocess.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/subprocess.rst (original)
+++ python/branches/tlee-ast-optimize/Doc/library/subprocess.rst Tue Jun 24 16:30:35 2008
@@ -372,13 +372,13 @@
::
- pipe = os.popen(cmd, mode='r', bufsize)
+ pipe = os.popen(cmd, 'r', bufsize)
==>
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout
::
- pipe = os.popen(cmd, mode='w', bufsize)
+ pipe = os.popen(cmd, 'w', bufsize)
==>
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin
Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst (original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst Tue Jun 24 16:30:35 2008
@@ -530,7 +530,7 @@
.. seealso::
- :pep:`371` - Per-user ``site-packages`` Directory
+ :pep:`371` - Addition of the multiprocessing package
PEP written by Jesse Noller and Richard Oudkerk;
implemented by Richard Oudkerk and Jesse Noller.
@@ -1374,8 +1374,8 @@
of the zero. (Fixed by Mark T. Dickinson; :issue:`1507`)
* More floating-point features were also added. The :func:`float` function
- will now turn the strings ``+nan`` and ``-nan`` into the corresponding
- IEEE 754 Not A Number values, and ``+inf`` and ``-inf`` into
+ will now turn the string ``nan`` into an
+ IEEE 754 Not A Number value, and ``+inf`` and ``-inf`` into
positive or negative infinity. This works on any platform with
IEEE 754 semantics. (Contributed by Christian Heimes; :issue:`1635`.)
Modified: python/branches/tlee-ast-optimize/Include/stringobject.h
==============================================================================
--- python/branches/tlee-ast-optimize/Include/stringobject.h (original)
+++ python/branches/tlee-ast-optimize/Include/stringobject.h Tue Jun 24 16:30:35 2008
@@ -182,8 +182,8 @@
see Objects/stringlib/localeutil.h */
PyAPI_FUNC(int) _PyString_InsertThousandsGrouping(char *buffer,
- Py_ssize_t len,
- char *plast,
+ Py_ssize_t n_buffer,
+ Py_ssize_t n_digits,
Py_ssize_t buf_size,
Py_ssize_t *count,
int append_zero_char);
Modified: python/branches/tlee-ast-optimize/Lib/_abcoll.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/_abcoll.py (original)
+++ python/branches/tlee-ast-optimize/Lib/_abcoll.py Tue Jun 24 16:30:35 2008
@@ -9,6 +9,7 @@
"""
from abc import ABCMeta, abstractmethod
+import sys
__all__ = ["Hashable", "Iterable", "Iterator",
"Sized", "Container", "Callable",
Modified: python/branches/tlee-ast-optimize/Lib/test/test_collections.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_collections.py (original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_collections.py Tue Jun 24 16:30:35 2008
@@ -294,6 +294,21 @@
self.failUnless(isinstance(sample(), Set))
self.failUnless(issubclass(sample, Set))
+ def test_hash_Set(self):
+ class OneTwoThreeSet(Set):
+ def __init__(self):
+ self.contents = [1, 2, 3]
+ def __contains__(self, x):
+ return x in self.contents
+ def __len__(self):
+ return len(self.contents)
+ def __iter__(self):
+ return iter(self.contents)
+ def __hash__(self):
+ return self._hash()
+ a, b = OneTwoThreeSet(), OneTwoThreeSet()
+ self.failUnless(hash(a) == hash(b))
+
def test_MutableSet(self):
self.failUnless(isinstance(set(), MutableSet))
self.failUnless(issubclass(set, MutableSet))
Modified: python/branches/tlee-ast-optimize/Lib/test/test_cpickle.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_cpickle.py (original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_cpickle.py Tue Jun 24 16:30:35 2008
@@ -1,4 +1,4 @@
-import cPickle
+import cPickle, unittest
from cStringIO import StringIO
from test.pickletester import AbstractPickleTests, AbstractPickleModuleTests
from test import test_support
@@ -90,12 +90,28 @@
b = self.loads(self.dumps(a))
self.assertEqual(a, b)
+class Node(object):
+ pass
+
+class cPickleDeepRecursive(unittest.TestCase):
+ '''Issue 2702. This should raise a RecursionLimit but in some
+ platforms (FreeBSD, win32) sometimes raises KeyError instead,
+ or just silently terminates the interpreter (=crashes).
+ '''
+ def test_deep_recursive(self):
+ nodes = [Node() for i in range(500)]
+ for n in nodes:
+ n.connections = list(nodes)
+ n.connections.remove(n)
+ self.assertRaises(RuntimeError, cPickle.dumps, n)
+
def test_main():
test_support.run_unittest(
cPickleTests,
cPicklePicklerTests,
cPickleListPicklerTests,
- cPickleFastPicklerTests
+ cPickleFastPicklerTests,
+ cPickleDeepRecursive,
)
if __name__ == "__main__":
Modified: python/branches/tlee-ast-optimize/Lib/test/test_posix.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_posix.py (original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_posix.py Tue Jun 24 16:30:35 2008
@@ -10,6 +10,7 @@
import time
import os
import pwd
+import shutil
import unittest
import warnings
warnings.filterwarnings('ignore', '.* potential security risk .*',
@@ -231,6 +232,45 @@
if hasattr(st, 'st_flags'):
posix.lchflags(test_support.TESTFN, st.st_flags)
+ def test_getcwd_long_pathnames(self):
+ if hasattr(posix, 'getcwd'):
+ dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
+ curdir = os.getcwd()
+ base_path = os.path.abspath(test_support.TESTFN) + '.getcwd'
+
+ try:
+ os.mkdir(base_path)
+ os.chdir(base_path)
+ except:
+# Just returning nothing instead of the TestSkipped exception,
+# because the test results in Error in that case.
+# Is that ok?
+# raise test_support.TestSkipped, "cannot create directory for testing"
+ return
+
+ try:
+ def _create_and_do_getcwd(dirname, current_path_length = 0):
+ try:
+ os.mkdir(dirname)
+ except:
+ raise test_support.TestSkipped, "mkdir cannot create directory sufficiently deep for getcwd test"
+
+ os.chdir(dirname)
+ try:
+ os.getcwd()
+ if current_path_length < 1027:
+ _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
+ finally:
+ os.chdir('..')
+ os.rmdir(dirname)
+
+ _create_and_do_getcwd(dirname)
+
+ finally:
+ shutil.rmtree(base_path)
+ os.chdir(curdir)
+
+
def test_main():
test_support.run_unittest(PosixTester)
Modified: python/branches/tlee-ast-optimize/Lib/test/test_types.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_types.py (original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_types.py Tue Jun 24 16:30:35 2008
@@ -497,6 +497,14 @@
# move to the next integer to test
x = x // 10
+ rfmt = ">20n"
+ lfmt = "<20n"
+ cfmt = "^20n"
+ for x in (1234, 12345, 123456, 1234567, 12345678, 123456789, 1234567890, 12345678900):
+ self.assertEqual(len(format(0, rfmt)), len(format(x, rfmt)))
+ self.assertEqual(len(format(0, lfmt)), len(format(x, lfmt)))
+ self.assertEqual(len(format(0, cfmt)), len(format(x, cfmt)))
+
def test_float__format__(self):
# these should be rewritten to use both format(x, spec) and
# x.__format__(spec)
Modified: python/branches/tlee-ast-optimize/Misc/NEWS
==============================================================================
--- python/branches/tlee-ast-optimize/Misc/NEWS (original)
+++ python/branches/tlee-ast-optimize/Misc/NEWS Tue Jun 24 16:30:35 2008
@@ -74,7 +74,7 @@
- Issue #3116: marshal.dumps() had quadratic behavior for strings > 32Mb.
-- Issue #2138: Add factorial() the math module.
+- Issue #2138: Add factorial() to the math module.
- The heapq module does comparisons using LT instead of LE. This
makes its implementation match that used by list.sort().
@@ -108,6 +108,8 @@
Library
-------
+- Issue #2722: Now the os.getcwd() supports very long path names.
+
- Issue #2888: Fixed the behaviour of pprint when working with nested
structures, to match the behaviour of 2.5 and 3.0 (now follows the common
sense).
Modified: python/branches/tlee-ast-optimize/Modules/_sqlite/module.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_sqlite/module.c (original)
+++ python/branches/tlee-ast-optimize/Modules/_sqlite/module.c Tue Jun 24 16:30:35 2008
@@ -76,6 +76,13 @@
return result;
}
+PyDoc_STRVAR(module_connect_doc,
+"connect(database[, timeout, isolation_level, detect_types, factory])\n\
+\n\
+Opens a connection to the SQLite database file *database*. You can use\n\
+\":memory:\" to open a database connection to a database that resides in\n\
+RAM instead of on disk.");
+
static PyObject* module_complete(PyObject* self, PyObject* args, PyObject*
kwargs)
{
@@ -100,6 +107,11 @@
return result;
}
+PyDoc_STRVAR(module_complete_doc,
+"complete_statement(sql)\n\
+\n\
+Checks if a string contains a complete SQL statement. Non-standard.");
+
#ifdef HAVE_SHARED_CACHE
static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyObject*
kwargs)
@@ -123,9 +135,15 @@
return Py_None;
}
}
+
+PyDoc_STRVAR(module_enable_shared_cache_doc,
+"enable_shared_cache(do_enable)\n\
+\n\
+Enable or disable shared cache mode for the calling thread.\n\
+Experimental/Non-standard.");
#endif /* HAVE_SHARED_CACHE */
-static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObject* kwargs)
+static PyObject* module_register_adapter(PyObject* self, PyObject* args)
{
PyTypeObject* type;
PyObject* caster;
@@ -147,7 +165,12 @@
return Py_None;
}
-static PyObject* module_register_converter(PyObject* self, PyObject* args, PyObject* kwargs)
+PyDoc_STRVAR(module_register_adapter_doc,
+"register_adapter(type, callable)\n\
+\n\
+Registers an adapter with pysqlite's adapter registry. Non-standard.");
+
+static PyObject* module_register_converter(PyObject* self, PyObject* args)
{
PyObject* orig_name;
PyObject* name = NULL;
@@ -175,7 +198,12 @@
return retval;
}
-static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args, PyObject* kwargs)
+PyDoc_STRVAR(module_register_converter_doc,
+"register_converter(typename, callable)\n\
+\n\
+Registers a converter with pysqlite. Non-standard.");
+
+static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, "i", &_enable_callback_tracebacks)) {
return NULL;
@@ -185,6 +213,11 @@
return Py_None;
}
+PyDoc_STRVAR(enable_callback_tracebacks_doc,
+"enable_callback_tracebacks(flag)\n\
+\n\
+Enable or disable callback functions throwing errors to stderr.");
+
static void converters_init(PyObject* dict)
{
converters = PyDict_New();
@@ -196,15 +229,22 @@
}
static PyMethodDef module_methods[] = {
- {"connect", (PyCFunction)module_connect, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Creates a connection.")},
- {"complete_statement", (PyCFunction)module_complete, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Checks if a string contains a complete SQL statement. Non-standard.")},
+ {"connect", (PyCFunction)module_connect,
+ METH_VARARGS | METH_KEYWORDS, module_connect_doc},
+ {"complete_statement", (PyCFunction)module_complete,
+ METH_VARARGS | METH_KEYWORDS, module_complete_doc},
#ifdef HAVE_SHARED_CACHE
- {"enable_shared_cache", (PyCFunction)module_enable_shared_cache, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("Enable or disable shared cache mode for the calling thread. Experimental/Non-standard.")},
+ {"enable_shared_cache", (PyCFunction)module_enable_shared_cache,
+ METH_VARARGS | METH_KEYWORDS, module_enable_shared_cache_doc},
#endif
- {"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with pysqlite's adapter registry. Non-standard.")},
- {"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with pysqlite. Non-standard.")},
- {"adapt", (PyCFunction)psyco_microprotocols_adapt, METH_VARARGS, psyco_microprotocols_adapt_doc},
- {"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks, METH_VARARGS, PyDoc_STR("Enable or disable callback functions throwing errors to stderr.")},
+ {"register_adapter", (PyCFunction)module_register_adapter,
+ METH_VARARGS, module_register_adapter_doc},
+ {"register_converter", (PyCFunction)module_register_converter,
+ METH_VARARGS, module_register_converter_doc},
+ {"adapt", (PyCFunction)psyco_microprotocols_adapt, METH_VARARGS,
+ psyco_microprotocols_adapt_doc},
+ {"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks,
+ METH_VARARGS, enable_callback_tracebacks_doc},
{NULL, NULL}
};
@@ -389,12 +429,12 @@
pysqlite_BaseTypeAdapted = 0;
- /* Original comment form _bsddb.c in the Python core. This is also still
+ /* Original comment from _bsddb.c in the Python core. This is also still
* needed nowadays for Python 2.3/2.4.
*
* PyEval_InitThreads is called here due to a quirk in python 1.5
* - 2.2.1 (at least) according to Russell Williamson <merel at wt.net>:
- * The global interepreter lock is not initialized until the first
+ * The global interpreter lock is not initialized until the first
* thread is created using thread.start_new_thread() or fork() is
* called. that would cause the ALLOW_THREADS here to segfault due
* to a null pointer reference if no threads or child processes
Modified: python/branches/tlee-ast-optimize/Modules/cPickle.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/cPickle.c (original)
+++ python/branches/tlee-ast-optimize/Modules/cPickle.c Tue Jun 24 16:30:35 2008
@@ -1523,6 +1523,8 @@
static char append = APPEND;
static char appends = APPENDS;
+ self->nesting++;
+
assert(iter != NULL);
if (self->proto == 0) {
@@ -1662,6 +1664,8 @@
static char setitem = SETITEM;
static char setitems = SETITEMS;
+ self->nesting++;
+
assert(iter != NULL);
if (self->proto == 0) {
@@ -2366,6 +2370,7 @@
res = save_string(self, args, 0);
goto finally;
}
+ break;
#ifdef Py_USING_UNICODE
case 'u':
@@ -2373,6 +2378,7 @@
res = save_unicode(self, args, 0);
goto finally;
}
+ break;
#endif
}
Modified: python/branches/tlee-ast-optimize/Modules/posixmodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/posixmodule.c (original)
+++ python/branches/tlee-ast-optimize/Modules/posixmodule.c Tue Jun 24 16:30:35 2008
@@ -1956,19 +1956,38 @@
static PyObject *
posix_getcwd(PyObject *self, PyObject *noargs)
{
- char buf[1026];
- char *res;
+ int bufsize_incr = 1024;
+ int bufsize = 0;
+ char *tmpbuf = NULL;
+ char *res = NULL;
+ PyObject *dynamic_return;
Py_BEGIN_ALLOW_THREADS
+ do {
+ bufsize = bufsize + bufsize_incr;
+ tmpbuf = malloc(bufsize);
+ if (tmpbuf == NULL) {
+ break;
+ }
#if defined(PYOS_OS2) && defined(PYCC_GCC)
- res = _getcwd2(buf, sizeof buf);
+ res = _getcwd2(tmpbuf, bufsize);
#else
- res = getcwd(buf, sizeof buf);
+ res = getcwd(tmpbuf, bufsize);
#endif
+
+ if (res == NULL) {
+ free(tmpbuf);
+ }
+ } while ((res == NULL) && (errno == ERANGE));
Py_END_ALLOW_THREADS
+
if (res == NULL)
return posix_error();
- return PyString_FromString(buf);
+
+ dynamic_return = PyString_FromString(tmpbuf);
+ free(tmpbuf);
+
+ return dynamic_return;
}
#ifdef Py_USING_UNICODE
Modified: python/branches/tlee-ast-optimize/Objects/stringlib/formatter.h
==============================================================================
--- python/branches/tlee-ast-optimize/Objects/stringlib/formatter.h (original)
+++ python/branches/tlee-ast-optimize/Objects/stringlib/formatter.h Tue Jun 24 16:30:35 2008
@@ -313,8 +313,8 @@
as determined in _calc_integer_widths(). returns the pointer to
where the digits go. */
static STRINGLIB_CHAR *
-fill_number(STRINGLIB_CHAR *p_buf, const NumberFieldWidths *spec,
- Py_ssize_t n_digits, STRINGLIB_CHAR fill_char)
+fill_non_digits(STRINGLIB_CHAR *p_buf, const NumberFieldWidths *spec,
+ Py_ssize_t n_digits, STRINGLIB_CHAR fill_char)
{
STRINGLIB_CHAR* p_digits;
@@ -557,18 +557,17 @@
pnumeric_chars += leading_chars_to_skip;
}
- /* Calculate the widths of the various leading and trailing parts */
- calc_number_widths(&spec, sign, n_digits, format);
-
if (format->type == 'n')
/* Compute how many additional chars we need to allocate
to hold the thousands grouping. */
- STRINGLIB_GROUPING(pnumeric_chars, n_digits,
- pnumeric_chars+n_digits,
+ STRINGLIB_GROUPING(NULL, n_digits, n_digits,
0, &n_grouping_chars, 0);
+ /* Calculate the widths of the various leading and trailing parts */
+ calc_number_widths(&spec, sign, n_digits + n_grouping_chars, format);
+
/* Allocate a new string to hold the result */
- result = STRINGLIB_NEW(NULL, spec.n_total + n_grouping_chars);
+ result = STRINGLIB_NEW(NULL, spec.n_total);
if (!result)
goto done;
p = STRINGLIB_STR(result);
@@ -587,21 +586,20 @@
}
/* Insert the grouping, if any, after the uppercasing of 'X', so we can
- ensure that grouping chars won't be affeted. */
- if (n_grouping_chars && format->type == 'n') {
+ ensure that grouping chars won't be affected. */
+ if (n_grouping_chars) {
/* We know this can't fail, since we've already
reserved enough space. */
STRINGLIB_CHAR *pstart = p + n_leading_chars;
- int r = STRINGLIB_GROUPING(pstart, n_digits,
- pstart + n_digits,
+ int r = STRINGLIB_GROUPING(pstart, n_digits, n_digits,
spec.n_total+n_grouping_chars-n_leading_chars,
NULL, 0);
assert(r);
}
- /* Fill in the non-digit parts */
- fill_number(p, &spec, n_digits,
- format->fill_char == '\0' ? ' ' : format->fill_char);
+ /* Fill in the non-digit parts (padding, sign, etc.) */
+ fill_non_digits(p, &spec, n_digits + n_grouping_chars,
+ format->fill_char == '\0' ? ' ' : format->fill_char);
done:
Py_XDECREF(tmp);
@@ -739,9 +737,9 @@
if (result == NULL)
goto done;
- /* fill in the non-digit parts */
- fill_number(STRINGLIB_STR(result), &spec, n_digits,
- format->fill_char == '\0' ? ' ' : format->fill_char);
+ /* Fill in the non-digit parts (padding, sign, etc.) */
+ fill_non_digits(STRINGLIB_STR(result), &spec, n_digits,
+ format->fill_char == '\0' ? ' ' : format->fill_char);
/* fill in the digit parts */
memmove(STRINGLIB_STR(result) +
Modified: python/branches/tlee-ast-optimize/Objects/stringlib/localeutil.h
==============================================================================
--- python/branches/tlee-ast-optimize/Objects/stringlib/localeutil.h (original)
+++ python/branches/tlee-ast-optimize/Objects/stringlib/localeutil.h Tue Jun 24 16:30:35 2008
@@ -8,10 +8,9 @@
/**
* _Py_InsertThousandsGrouping:
* @buffer: A pointer to the start of a string.
- * @len: The length of the string.
- * @plast: A pointer to the end of of the digits in the string. This
- * may be before the end of the string (if the string contains
- * decimals, for example).
+ * @n_buffer: The length of the string.
+ * @n_digits: The number of digits in the string, in which we want
+ * to put the grouping chars.
* @buf_size: The maximum size of the buffer pointed to by buffer.
* @count: If non-NULL, points to a variable that will receive the
* number of characters we need to insert (and no formatting
@@ -21,10 +20,11 @@
* string.
*
* Inserts thousand grouping characters (as defined in the current
- * locale) into the string between buffer and plast. If count is
- * non-NULL, don't do any formatting, just count the number of
- * characters to insert. This is used by the caller to appropriately
- * resize the buffer, if needed.
+ * locale) into the string between buffer and buffer+n_digits. If
+ * count is non-NULL, don't do any formatting, just count the number
+ * of characters to insert. This is used by the caller to
+ * appropriately resize the buffer, if needed. If count is non-NULL,
+ * buffer can be NULL (it is not dereferenced at all in that case).
*
* Return value: 0 on error, else 1. Note that no error can occur if
* count is non-NULL.
@@ -34,8 +34,8 @@
**/
int
_Py_InsertThousandsGrouping(STRINGLIB_CHAR *buffer,
- Py_ssize_t len,
- STRINGLIB_CHAR *plast,
+ Py_ssize_t n_buffer,
+ Py_ssize_t n_digits,
Py_ssize_t buf_size,
Py_ssize_t *count,
int append_zero_char)
@@ -44,15 +44,22 @@
const char *grouping = locale_data->grouping;
const char *thousands_sep = locale_data->thousands_sep;
Py_ssize_t thousands_sep_len = strlen(thousands_sep);
- STRINGLIB_CHAR *pend = buffer + len; /* current end of buffer */
- STRINGLIB_CHAR *pmax = buffer + buf_size; /* max of buffer */
+ STRINGLIB_CHAR *pend = NULL; /* current end of buffer */
+ STRINGLIB_CHAR *pmax = NULL; /* max of buffer */
char current_grouping;
+ Py_ssize_t remaining = n_digits; /* Number of chars remaining to
+ be looked at */
/* Initialize the character count, if we're just counting. */
if (count)
*count = 0;
+ else {
+ /* We're not just counting, we're modifying buffer */
+ pend = buffer + n_buffer;
+ pmax = buffer + buf_size;
+ }
- /* Starting at plast and working right-to-left, keep track of
+ /* Starting at the end and working right-to-left, keep track of
what grouping needs to be added and insert that. */
current_grouping = *grouping++;
@@ -60,11 +67,11 @@
if (current_grouping == 0)
return 1;
- while (plast - buffer > current_grouping) {
+ while (remaining > current_grouping) {
/* Always leave buffer and pend valid at the end of this
loop, since we might leave with a return statement. */
- plast -= current_grouping;
+ remaining -= current_grouping;
if (count) {
/* We're only counting, not touching the memory. */
*count += thousands_sep_len;
@@ -72,6 +79,8 @@
else {
/* Do the formatting. */
+ STRINGLIB_CHAR *plast = buffer + remaining;
+
/* Is there room to insert thousands_sep_len chars? */
if (pmax - pend < thousands_sep_len)
/* No room. */
@@ -111,7 +120,7 @@
if (append_zero_char) {
/* Append a zero character to mark the end of the string,
if there's room. */
- if (pend - plast < 1)
+ if (pend - (buffer + remaining) < 1)
/* No room, error. */
return 0;
*pend = 0;
Modified: python/branches/tlee-ast-optimize/PCbuild/_ctypes.vcproj
==============================================================================
--- python/branches/tlee-ast-optimize/PCbuild/_ctypes.vcproj (original)
+++ python/branches/tlee-ast-optimize/PCbuild/_ctypes.vcproj Tue Jun 24 16:30:35 2008
@@ -642,7 +642,7 @@
>
<Tool
Name="VCCustomBuildTool"
- CommandLine="ml64 /nologo /c /Fo "$(IntDir)\win64.obj" "$(InputPath)"
"
+ CommandLine="ml64 /nologo /c /Zi /Fo "$(IntDir)\win64.obj" "$(InputPath)"
"
Outputs="$(IntDir)\win64.obj"
/>
</FileConfiguration>
Modified: python/branches/tlee-ast-optimize/Python/pystrtod.c
==============================================================================
--- python/branches/tlee-ast-optimize/Python/pystrtod.c (original)
+++ python/branches/tlee-ast-optimize/Python/pystrtod.c Tue Jun 24 16:30:35 2008
@@ -364,7 +364,7 @@
/* At this point, p points just past the right-most character we
want to format. We need to add the grouping string for the
characters between buffer and p. */
- return _PyString_InsertThousandsGrouping(buffer, len, p,
+ return _PyString_InsertThousandsGrouping(buffer, len, p-buffer,
buf_size, NULL, 1);
}
More information about the Python-checkins
mailing list