[Python-3000-checkins] r55919 - in python/branches/py3k-struni: Objects/fileobject.c Python/ast.c Tools/freeze/bkfile.py Tools/freeze/freeze.py Tools/freeze/makefreeze.py Tools/freeze/makemakefile.py Tools/freeze/parsesetup.py runtests.sh
Guido van Rossum
guido at python.org
Tue Jun 12 02:34:15 CEST 2007
This submitted two things I meant to submit separately; here are the comments:
fileobject.c: make PyFile_FromFile() work (more or less) by calling
io.open() and closing the input file.
ast.c: When the input is known to be UTF-8, ignore an encoding
declaration. (This was a hack to make the freeze tool "work" --
unclear what else to do about this.)
On 6/11/07, guido.van.rossum <python-3000-checkins at python.org> wrote:
> Author: guido.van.rossum
> Date: Tue Jun 12 02:28:30 2007
> New Revision: 55919
>
> Modified:
> python/branches/py3k-struni/Objects/fileobject.c
> python/branches/py3k-struni/Python/ast.c
> python/branches/py3k-struni/Tools/freeze/bkfile.py
> python/branches/py3k-struni/Tools/freeze/freeze.py
> python/branches/py3k-struni/Tools/freeze/makefreeze.py
> python/branches/py3k-struni/Tools/freeze/makemakefile.py
> python/branches/py3k-struni/Tools/freeze/parsesetup.py
> python/branches/py3k-struni/runtests.sh
> Log:
> Minimal changes to make the "freeze" tool work again.
> There are other issues left, but these were basics (e.g. keys().sort()).
>
>
> Modified: python/branches/py3k-struni/Objects/fileobject.c
> ==============================================================================
> --- python/branches/py3k-struni/Objects/fileobject.c (original)
> +++ python/branches/py3k-struni/Objects/fileobject.c Tue Jun 12 02:28:30 2007
> @@ -265,24 +265,19 @@
> PyObject *
> PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
> {
> - PyErr_SetString(PyExc_SystemError,
> - "attempt to create old file from FILE *");
> - return NULL;
> -#if 0
> - PyFileObject *f = (PyFileObject *)PyFile_Type.tp_new(&PyFile_Type,
> - NULL, NULL);
> - if (f != NULL) {
> - PyObject *o_name = PyString_FromString(name);
> - if (o_name == NULL)
> - return NULL;
> - if (fill_file_fields(f, fp, o_name, mode, close) == NULL) {
> - Py_DECREF(f);
> - f = NULL;
> - }
> - Py_DECREF(o_name);
> + PyObject *io = NULL, *stream = NULL;
> +
> + io = PyImport_ImportModule("io");
> + if (io == NULL)
> + return NULL;
> + stream = PyObject_CallMethod(io, "open", "ss", name, mode);
> + if (stream == NULL) {
> + Py_XDECREF(io);
> + return NULL;
> }
> - return (PyObject *) f;
> -#endif
> + if (close != NULL)
> + close(fp);
> + return stream;
> }
>
> PyObject *
>
> Modified: python/branches/py3k-struni/Python/ast.c
> ==============================================================================
> --- python/branches/py3k-struni/Python/ast.c (original)
> +++ python/branches/py3k-struni/Python/ast.c Tue Jun 12 02:28:30 2007
> @@ -193,8 +193,11 @@
> if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) {
> c.c_encoding = "utf-8";
> if (TYPE(n) == encoding_decl) {
> +#if 0
> ast_error(n, "encoding declaration in Unicode string");
> goto error;
> +#endif
> + n = CHILD(n, 0);
> }
> } else if (TYPE(n) == encoding_decl) {
> c.c_encoding = STR(n);
>
> Modified: python/branches/py3k-struni/Tools/freeze/bkfile.py
> ==============================================================================
> --- python/branches/py3k-struni/Tools/freeze/bkfile.py (original)
> +++ python/branches/py3k-struni/Tools/freeze/bkfile.py Tue Jun 12 02:28:30 2007
> @@ -21,7 +21,10 @@
> self.mode = self.__file.mode
> self.name = self.__file.name
> self.read = self.__file.read
> - self.readinto = self.__file.readinto
> + try:
> + self.readinto = self.__file.readinto
> + except AttributeError:
> + pass
> self.readline = self.__file.readline
> self.readlines = self.__file.readlines
> self.seek = self.__file.seek
>
> Modified: python/branches/py3k-struni/Tools/freeze/freeze.py
> ==============================================================================
> --- python/branches/py3k-struni/Tools/freeze/freeze.py (original)
> +++ python/branches/py3k-struni/Tools/freeze/freeze.py Tue Jun 12 02:28:30 2007
> @@ -386,8 +386,7 @@
> # look for unfrozen modules (builtin and of unknown origin)
> builtins = []
> unknown = []
> - mods = dict.keys()
> - mods.sort()
> + mods = sorted(dict.keys())
> for mod in mods:
> if dict[mod].__code__:
> continue
>
> Modified: python/branches/py3k-struni/Tools/freeze/makefreeze.py
> ==============================================================================
> --- python/branches/py3k-struni/Tools/freeze/makefreeze.py (original)
> +++ python/branches/py3k-struni/Tools/freeze/makefreeze.py Tue Jun 12 02:28:30 2007
> @@ -33,8 +33,7 @@
> if entry_point is None: entry_point = default_entry_point
> done = []
> files = []
> - mods = dict.keys()
> - mods.sort()
> + mods = sorted(dict.keys())
> for mod in mods:
> m = dict[mod]
> mangled = "__".join(mod.split("."))
> @@ -81,8 +80,8 @@
> outfp.write('unsigned char M_%s[] = {' % mod)
> for i in range(0, len(str), 16):
> outfp.write('\n\t')
> - for c in str[i:i+16]:
> - outfp.write('%d,' % ord(c))
> + for c in bytes(str[i:i+16]):
> + outfp.write('%d,' % c)
> outfp.write('\n};\n')
>
> ## def writecode(outfp, mod, str):
>
> Modified: python/branches/py3k-struni/Tools/freeze/makemakefile.py
> ==============================================================================
> --- python/branches/py3k-struni/Tools/freeze/makemakefile.py (original)
> +++ python/branches/py3k-struni/Tools/freeze/makemakefile.py Tue Jun 12 02:28:30 2007
> @@ -5,8 +5,7 @@
> def makemakefile(outfp, makevars, files, target):
> outfp.write("# Makefile generated by freeze.py script\n\n")
>
> - keys = makevars.keys()
> - keys.sort()
> + keys = sorted(makevars.keys())
> for key in keys:
> outfp.write("%s=%s\n" % (key, makevars[key]))
> outfp.write("\nall: %s\n\n" % target)
>
> Modified: python/branches/py3k-struni/Tools/freeze/parsesetup.py
> ==============================================================================
> --- python/branches/py3k-struni/Tools/freeze/parsesetup.py (original)
> +++ python/branches/py3k-struni/Tools/freeze/parsesetup.py Tue Jun 12 02:28:30 2007
> @@ -102,8 +102,7 @@
> print('(name must begin with "Makefile" or "Setup")')
>
> def prdict(d):
> - keys = d.keys()
> - keys.sort()
> + keys = sorted(d.keys())
> for key in keys:
> value = d[key]
> print("%-15s" % key, str(value))
>
> Modified: python/branches/py3k-struni/runtests.sh
> ==============================================================================
> --- python/branches/py3k-struni/runtests.sh (original)
> +++ python/branches/py3k-struni/runtests.sh Tue Jun 12 02:28:30 2007
> @@ -24,6 +24,9 @@
> >BAD
> >SKIPPED
>
> +# The -uall flag (edit this file to change).
> +UALL="-uall"
> +
> # Compute the list of tests to run.
> case $# in
> 0)
> @@ -38,7 +41,7 @@
> for T in $TESTS
> do
> echo -n $T
> - if $PYTHON Lib/test/regrtest.py -uall $T >OUT/$T.out 2>&1
> + if $PYTHON Lib/test/regrtest.py $UALL $T >OUT/$T.out 2>&1
> then
> if grep -q "1 test skipped:" OUT/$T.out
> then
> @@ -51,5 +54,7 @@
> else
> echo " BAD"
> echo $T >>BAD
> + echo "---------- Re-running test in verbose mode ----------" >>OUT/$T
> + $PYTHON Lib/test/regrtest.py -v $UALL $T >>OUT/$T.out 2>&1
> fi
> done
> _______________________________________________
> Python-3000-checkins mailing list
> Python-3000-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-3000-checkins
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000-checkins
mailing list