Merging the py3k-pep3137 branch back into the py3k branch.

No detailed change log; just check out the change log for the py3k-pep3137
branch.  The most obvious changes:

  - str8 renamed to bytes (PyString at the C level);
  - bytes renamed to buffer (PyBytes at the C level);
  - PyString and PyUnicode are no longer compatible.

I.e. we now have an immutable bytes type and a mutable bytes type.

The behavior of PyString was modified quite a bit, to make it more
bytes-like.  Some changes are still on the to-do list.
This commit is contained in:
Guido van Rossum 2007-11-06 21:34:58 +00:00
parent a19f80c6df
commit 98297ee781
148 changed files with 2533 additions and 3517 deletions

View file

@ -75,6 +75,7 @@ int Py_VerboseFlag; /* Needed by import.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
int Py_NoSiteFlag; /* Suppress 'import site' */
int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */
int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
@ -234,6 +235,7 @@ Py_InitializeEx(int install_sigs)
if (pstderr == NULL)
Py_FatalError("Py_Initialize: can't set preliminary stderr");
PySys_SetObject("stderr", pstderr);
PySys_SetObject("__stderr__", pstderr);
_PyImport_Init();
@ -261,8 +263,28 @@ Py_InitializeEx(int install_sigs)
#endif /* WITH_THREAD */
warnings_module = PyImport_ImportModule("warnings");
if (!warnings_module)
if (!warnings_module) {
PyErr_Clear();
}
else {
PyObject *o;
char *action[8];
if (Py_BytesWarningFlag > 1)
*action = "error";
else if (Py_BytesWarningFlag)
*action = "default";
else
*action = "ignore";
o = PyObject_CallMethod(warnings_module,
"simplefilter", "sO",
*action, PyExc_BytesWarning);
if (o == NULL)
Py_FatalError("Py_Initialize: can't initialize"
"warning filter for BytesWarning.");
Py_DECREF(o);
}
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
/* On Unix, set the file system encoding according to the
@ -743,6 +765,7 @@ initstdio(void)
PySys_SetObject("stdout", std);
Py_DECREF(std);
#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
/* Set sys.stderr, replaces the preliminary stderr */
if (!(std = PyFile_FromFd(fileno(stderr), "<stderr>", "w", -1,
NULL, "\n", 0))) {
@ -751,6 +774,7 @@ initstdio(void)
PySys_SetObject("__stderr__", std);
PySys_SetObject("stderr", std);
Py_DECREF(std);
#endif
if (0) {
error:
@ -1339,7 +1363,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
PyArena *arena = PyArena_New();
if (arena == NULL)
return NULL;
mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
if (mod != NULL)
ret = run_mod(mod, "<string>", globals, locals, flags, arena);
@ -1356,7 +1380,7 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
PyArena *arena = PyArena_New();
if (arena == NULL)
return NULL;
mod = PyParser_ASTFromFile(fp, filename, NULL, start, 0, 0,
flags, NULL, arena);
if (closeit)
@ -1705,7 +1729,7 @@ void _Py_PyAtExit(void (*func)(void))
static void
call_py_exitfuncs(void)
{
if (pyexitfunc == NULL)
if (pyexitfunc == NULL)
return;
(*pyexitfunc)();