Skip to content

Commit 5af8a4b

Browse files
author
christian.heimes
committed
Backport of several functions from Python 3.0 to 2.6 including PyUnicode_FromString, PyUnicode_Format and PyLong_From/AsSsize_t. The functions are partly required for the backport of the bytearray type and _fileio module. They should also make it easier to port C to 3.0.
First chapter of the Python 3.0 io framework back port: _fileio The next step depends on a working bytearray type which itself depends on a backport of the nwe buffer API. git-svn-id: http://svn.python.org/projects/python/trunk@60283 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent c956b46 commit 5af8a4b

8 files changed

Lines changed: 1599 additions & 173 deletions

File tree

Include/longintrepr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ typedef unsigned int wdigit; /* digit widened to parameter size */
2424
typedef unsigned BASE_TWODIGITS_TYPE twodigits;
2525
typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
2626

27-
#define SHIFT 15
28-
#define BASE ((digit)1 << SHIFT)
29-
#define MASK ((int)(BASE - 1))
27+
#define PyLong_SHIFT 15
28+
#define PyLong_BASE ((digit)1 << PyLong_SHIFT)
29+
#define PyLong_MASK ((int)(PyLong_BASE - 1))
3030

31-
#if SHIFT % 5 != 0
31+
#if PyLong_SHIFT % 5 != 0
3232
#error "longobject.c requires that SHIFT be divisible by 5"
3333
#endif
3434

Include/longobject.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ PyAPI_DATA(PyTypeObject) PyLong_Type;
1818
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
1919
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
2020
PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
21+
PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);
22+
PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
2123
PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
2224
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
2325
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
26+
PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
2427

2528
/* For use by intobject.c only */
26-
PyAPI_FUNC(Py_ssize_t) _PyLong_AsSsize_t(PyObject *);
27-
PyAPI_FUNC(PyObject *) _PyLong_FromSize_t(size_t);
28-
PyAPI_FUNC(PyObject *) _PyLong_FromSsize_t(Py_ssize_t);
29+
#define _PyLong_AsSsize_t PyLong_AsSsize_t
30+
#define _PyLong_FromSize_t PyLong_FromSize_t
31+
#define _PyLong_FromSsize_t PyLong_FromSsize_t
2932
PyAPI_DATA(int) _PyLong_DigitValue[256];
3033

3134
/* _PyLong_AsScaledDouble returns a double x and an exponent e such that

Include/unicodeobject.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
183183
# define PyUnicode_FromObject PyUnicodeUCS2_FromObject
184184
# define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal
185185
# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode
186+
# define PyUnicode_FromString PyUnicodeUCS2_FromString
187+
# define PyUnicode_FromStringAndSize PyUnicodeUCS2_FromStringAndSize
188+
# define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV
189+
# define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat
186190
# define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar
187191
# define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding
188192
# define PyUnicode_GetMax PyUnicodeUCS2_GetMax
@@ -265,6 +269,10 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
265269
# define PyUnicode_FromObject PyUnicodeUCS4_FromObject
266270
# define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal
267271
# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode
272+
# define PyUnicode_FromString PyUnicodeUCS4_FromString
273+
# define PyUnicode_FromStringAndSize PyUnicodeUCS4_FromStringAndSize
274+
# define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV
275+
# define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat
268276
# define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar
269277
# define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding
270278
# define PyUnicode_GetMax PyUnicodeUCS4_GetMax
@@ -442,6 +450,18 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
442450
Py_ssize_t size /* size of buffer */
443451
);
444452

453+
/* Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */
454+
PyAPI_FUNC(PyObject*) PyUnicode_FromStringAndSize(
455+
const char *u, /* char buffer */
456+
Py_ssize_t size /* size of buffer */
457+
);
458+
459+
/* Similar to PyUnicode_FromUnicode(), but u points to null-terminated
460+
Latin-1 encoded bytes */
461+
PyAPI_FUNC(PyObject*) PyUnicode_FromString(
462+
const char *u /* string */
463+
);
464+
445465
/* Return a read-only pointer to the Unicode object's internal
446466
Py_UNICODE buffer. */
447467

@@ -517,6 +537,9 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromObject(
517537
register PyObject *obj /* Object */
518538
);
519539

540+
PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(const char*, va_list);
541+
PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(const char*, ...);
542+
520543
/* --- wchar_t support for platforms which support it --------------------- */
521544

522545
#ifdef HAVE_WCHAR_H

Misc/NEWS

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
+++++++++++
1+
+++++++++++
22
Python News
33
+++++++++++
44

@@ -12,6 +12,10 @@ What's New in Python 2.6 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- Backport of PyUnicode_FromString(), _FromStringAndSize(), _Format and
16+
_FormatV from Python 3.0. Made PyLong_AsSsize_t and PyLong_FromSsize_t
17+
public functions.
18+
1519
- Issue #1920: "while 0" statements were completely removed by the compiler,
1620
even in the presence of an "else" clause, which is supposed to be run when
1721
the condition is false. Now the compiler correctly emits bytecode for the
@@ -1102,6 +1106,8 @@ Library
11021106
Extension Modules
11031107
-----------------
11041108

1109+
- Backport of _fileio module from Python 3.0.
1110+
11051111
- #1087741: mmap.mmap is now a class, not a factory function. It is also
11061112
subclassable now.
11071113

0 commit comments

Comments
 (0)