[Patches] Discuss: Unicode patch for open() builtin.
M.-A. Lemburg
lem-mal@gogetter.de
Wed, 29 Mar 2000 11:49:02 +0200
Mark Hammond wrote:
>
> Not a patch yet, but Im working towards one :)
>
> Im thinking about how to change open() WRT unicode.
>
> First thought was that the change would be to a PyArg_ParseTuple()
> call, but inspection shows a PyFile_FromString(char *name, ...).
>
> So it makes sense to create a new API - PyFile_FromWCHAR()?
Why not a PyFile_FromUnicode(Py_UNICODE *fname,... ) API ? The
open() builtin could use the new "es" parser markers to have
the input converted to Unicode first and then pass it along
to this new API.
On Windows, PyFile_FromUnicode() would then have to convert
the Py_UNICODE value to wchar_t using the PyUnicode_AsWideChar()
API and then proceed with fopenW()...
> On Windows, Im thinking that rather than performing a conversion to
> MBCS, this could perform a runtime check for WCHAR CRTL support -
> ie, basically "am I running NT", and call fopenW(). This could be a
> global static, so the first check would be "expensive", but after
> that we have a single "if" test.
>
> The bltinmodule call to this function can simply check the type of
> the arg and make the appropriate call (fopen() or fopenW()). (Note
> that on Windows 95/98 the W calls exist, they just dont work! This
> is by design, and designed for exactly this case)
>
> Something like:
>
> #ifdef HAVE_WCHAR_H
>
> PyObject PyFile_FromWCHAR(WCHAR *fname, ...)
> {
> ...
> #ifdef MS_WIN32
> static int have_wchar_crt = -1;
> if (have_wchar_crt==-1)
> have_wchar_crt = AmIRunningNT() ? 1 : 0;
> if (have_wchar_crt)
> fp = fopenW(fname, ...);
> else {
> /* encode as MBCS */
> fp = fopen(mbcs_name, ...);
> }
> ...
> #endif
>
> }
> #endif
>
> Sound reasonable?
>
> Mark.
>
> _______________________________________________
> Patches mailing list
> Patches@python.org
> http://www.python.org/mailman/listinfo/patches
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/