[Python-checkins] python/dist/src/Modules posixmodule.c, 2.308,
2.309
mhammond at users.sourceforge.net
mhammond at users.sourceforge.net
Tue Dec 2 20:22:40 EST 2003
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv13267
Modified Files:
posixmodule.c
Log Message:
Fix [ 846133 ] os.chmod/os.utime/shutil do not work with unicode filenames
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.308
retrieving revision 2.309
diff -C2 -d -r2.308 -r2.309
*** posixmodule.c 10 Nov 2003 06:35:36 -0000 2.308
--- posixmodule.c 3 Dec 2003 01:22:38 -0000 2.309
***************
*** 1163,1167 ****
int i;
int res;
! if (!PyArg_ParseTuple(args, "eti", Py_FileSystemDefaultEncoding,
&path, &i))
return NULL;
--- 1163,1185 ----
int i;
int res;
! #ifdef Py_WIN_WIDE_FILENAMES
! if (unicode_file_names()) {
! PyUnicodeObject *po;
! if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) {
! Py_BEGIN_ALLOW_THREADS
! res = _wchmod(PyUnicode_AS_UNICODE(po), i);
! Py_END_ALLOW_THREADS
! if (res < 0)
! return posix_error_with_unicode_filename(
! PyUnicode_AS_UNICODE(po));
! Py_INCREF(Py_None);
! return Py_None;
! }
! /* Drop the argument parsing error as narrow strings
! are also valid. */
! PyErr_Clear();
! }
! #endif /* Py_WIN_WIDE_FILENAMES */
! if (!PyArg_ParseTuple(args, "eti:chmod", Py_FileSystemDefaultEncoding,
&path, &i))
return NULL;
***************
*** 1935,1943 ****
#endif /* HAVE_UTIMES */
! if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg))
return NULL;
if (arg == Py_None) {
/* optional time values not given */
Py_BEGIN_ALLOW_THREADS
res = utime(path, NULL);
Py_END_ALLOW_THREADS
--- 1953,1982 ----
#endif /* HAVE_UTIMES */
! int have_unicode_filename = 0;
! #ifdef Py_WIN_WIDE_FILENAMES
! PyUnicodeObject *obwpath;
! wchar_t *wpath;
! if (unicode_file_names()) {
! if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) {
! wpath = PyUnicode_AS_UNICODE(obwpath);
! have_unicode_filename = 1;
! } else
! /* Drop the argument parsing error as narrow strings
! are also valid. */
! PyErr_Clear();
! }
! #endif /* Py_WIN_WIDE_FILENAMES */
!
! if (!have_unicode_filename && \
! !PyArg_ParseTuple(args, "sO:utime", &path, &arg))
return NULL;
if (arg == Py_None) {
/* optional time values not given */
Py_BEGIN_ALLOW_THREADS
+ #ifdef Py_WIN_WIDE_FILENAMES
+ if (have_unicode_filename)
+ res = _wutime(wpath, NULL);
+ else
+ #endif /* Py_WIN_WIDE_FILENAMES */
res = utime(path, NULL);
Py_END_ALLOW_THREADS
***************
*** 1965,1971 ****
#else
Py_BEGIN_ALLOW_THREADS
res = utime(path, UTIME_ARG);
Py_END_ALLOW_THREADS
! #endif
}
if (res < 0)
--- 2004,2018 ----
#else
Py_BEGIN_ALLOW_THREADS
+ #ifdef Py_WIN_WIDE_FILENAMES
+ if (have_unicode_filename)
+ /* utime is OK with utimbuf, but _wutime insists
+ on _utimbuf (the msvc headers assert the
+ underscore version is ansi) */
+ res = _wutime(wpath, (struct _utimbuf *)UTIME_ARG);
+ else
+ #endif /* Py_WIN_WIDE_FILENAMES */
res = utime(path, UTIME_ARG);
Py_END_ALLOW_THREADS
! #endif /* HAVE_UTIMES */
}
if (res < 0)
More information about the Python-checkins
mailing list