Le jeudi 06 mai 2010 02:59:26, Eric Smith a écrit :
> I grant you that it's a largely a mechanized change (except for the "a
> posteriori manual intervention" part), but still.
Attached patches are the "manual interventation" parts. 99% of the whole patch
only changes the indentation. There is just *two* changes not related directly
to indentation:
- I moved rc and buffer variable (specific to OS/2) at the beginning of the
function to avoid { and }.
- I added a newline in "static PyObject * os2_error(int code)"
The manual editions is mostly to "fix" the indentation.
Diff on Python trunk (diff -uw):
---------------------------
--- Modules/posixmodule.c.r80843 2010-05-06 10:18:47.000000000 +0200
+++ Modules/posixmodule.c 2010-05-06 10:18:51.000000000 +0200
@@ -470,6 +470,10 @@
{
PyObject *d;
char **e;
+#if defined(PYOS_OS2)
+ APIRET rc;
+ char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
+#endif
d = PyDict_New();
if (d == NULL)
return NULL;
@@ -505,10 +509,6 @@
Py_DECREF(v);
}
#if defined(PYOS_OS2)
- {
- APIRET rc;
- char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars
*/
-
rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH')
*/
PyObject *v = PyString_FromString(buffer);
@@ -521,7 +521,6 @@
PyDict_SetItemString(d, "ENDLIBPATH", v);
Py_DECREF(v);
}
- }
#endif
return d;
}
@@ -662,7 +661,8 @@
errors are not in a global variable e.g. 'errno' nor are
they congruent with posix error numbers. */
-static PyObject * os2_error(int code)
+static PyObject *
+os2_error(int code)
{
char text[1024];
PyObject *v;
---------------------------
Diff on Python py3k (diff -uw):
---------------------------
--- Modules/posixmodule.c.r80845 2010-05-06 10:36:27.000000000 +0200
+++ Modules/posixmodule.c 2010-05-06 10:36:32.000000000 +0200
@@ -445,6 +445,11 @@
#else
char **e;
#endif
+#if defined(PYOS_OS2)
+ APIRET rc;
+ char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
+#endif
+
d = PyDict_New();
if (d == NULL)
return NULL;
@@ -515,10 +520,6 @@
}
#endif
#if defined(PYOS_OS2)
- {
- APIRET rc;
- char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars
*/
-
rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */
PyObject *v = PyBytes_FromString(buffer);
@@ -531,7 +532,6 @@
PyDict_SetItemString(d, "ENDLIBPATH", v);
Py_DECREF(v);
}
- }
#endif
return d;
}
@@ -672,7 +672,8 @@
errors are not in a global variable e.g. 'errno' nor are
they congruent with posix error numbers. */
-static PyObject * os2_error(int code)
+static PyObject *
+os2_error(int code)
{
char text[1024];
PyObject *v;
---------------------------
--
Victor Stinner
http://www.haypocalc.com/
--- Modules/posixmodule.c 2010-05-06 02:16:46.000000000 +0200
+++ Modules/posixmodule.c 2010-05-06 02:16:15.000000000 +0200
@@ -470,6 +470,10 @@
{
PyObject *d;
char **e;
+#if defined(PYOS_OS2)
+ APIRET rc;
+ char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
+#endif
d = PyDict_New();
if (d == NULL)
return NULL;
@@ -505,10 +509,6 @@
Py_DECREF(v);
}
#if defined(PYOS_OS2)
- {
- APIRET rc;
- char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
-
rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */
PyObject *v = PyString_FromString(buffer);
@@ -521,7 +521,6 @@
PyDict_SetItemString(d, "ENDLIBPATH", v);
Py_DECREF(v);
}
- }
#endif
return d;
}
@@ -607,22 +606,22 @@
/**********************************************************************
* Helper Function to Trim and Format OS/2 Messages
**********************************************************************/
- static void
+static void
os2_formatmsg(char *msgbuf, int msglen, char *reason)
{
msgbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */
if (strlen(msgbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
- char *lastc = &msgbuf[ strlen(msgbuf)-1 ];
+ char *lastc = &msgbuf[ strlen(msgbuf)-1 ];
- while (lastc > msgbuf && isspace(Py_CHARMASK(*lastc)))
- *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
+ while (lastc > msgbuf && isspace(Py_CHARMASK(*lastc)))
+ *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
}
/* Add Optional Reason Text */
if (reason) {
- strcat(msgbuf, " : ");
- strcat(msgbuf, reason);
+ strcat(msgbuf, " : ");
+ strcat(msgbuf, reason);
}
}
@@ -637,7 +636,7 @@
* the file OSO001.MSG in the \OS2 directory hierarchy.
*
**********************************************************************/
- static char *
+static char *
os2_strerror(char *msgbuf, int msgbuflen, int errorcode, char *reason)
{
APIRET rc;
@@ -650,10 +649,10 @@
Py_END_ALLOW_THREADS
if (rc == NO_ERROR)
- os2_formatmsg(msgbuf, msglen, reason);
+ os2_formatmsg(msgbuf, msglen, reason);
else
- PyOS_snprintf(msgbuf, msgbuflen,
- "unknown OS error #%d", errorcode);
+ PyOS_snprintf(msgbuf, msgbuflen,
+ "unknown OS error #%d", errorcode);
return msgbuf;
}
@@ -662,7 +661,8 @@
errors are not in a global variable e.g. 'errno' nor are
they congruent with posix error numbers. */
-static PyObject * os2_error(int code)
+static PyObject *
+os2_error(int code)
{
char text[1024];
PyObject *v;
@@ -671,8 +671,8 @@
v = Py_BuildValue("(is)", code, text);
if (v != NULL) {
- PyErr_SetObject(PyExc_OSError, v);
- Py_DECREF(v);
+ PyErr_SetObject(PyExc_OSError, v);
+ Py_DECREF(v);
}
return NULL; /* Signal to Python that an Exception is Pending */
}
@@ -991,7 +991,7 @@
stricmp(dot, ".cmd") == 0 ||
stricmp(dot, ".exe") == 0 ||
stricmp(dot, ".com") == 0)
- result->st_mode |= 0111;
+ result->st_mode |= 0111;
}
return code;
}
@@ -1336,19 +1336,19 @@
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
- PyInt_FromLong((long)st->st_blksize));
+ PyInt_FromLong((long)st->st_blksize));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
- PyInt_FromLong((long)st->st_blocks));
+ PyInt_FromLong((long)st->st_blocks));
#endif
#ifdef HAVE_STRUCT_STAT_ST_RDEV
PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
- PyInt_FromLong((long)st->st_rdev));
+ PyInt_FromLong((long)st->st_rdev));
#endif
#ifdef HAVE_STRUCT_STAT_ST_GEN
PyStructSequence_SET_ITEM(v, ST_GEN_IDX,
- PyInt_FromLong((long)st->st_gen));
+ PyInt_FromLong((long)st->st_gen));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
{
@@ -1371,7 +1371,7 @@
#endif
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
- PyInt_FromLong((long)st->st_flags));
+ PyInt_FromLong((long)st->st_flags));
#endif
if (PyErr_Occurred()) {
@@ -1688,7 +1688,7 @@
Py_END_ALLOW_THREADS
if (!res)
return win32_error_unicode("chmod",
- PyUnicode_AS_UNICODE(po));
+ PyUnicode_AS_UNICODE(po));
Py_INCREF(Py_None);
return Py_None;
}
@@ -2239,59 +2239,59 @@
APIRET rc;
if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len))
- return NULL;
+ return NULL;
if (len >= MAX_PATH) {
- PyErr_SetString(PyExc_ValueError, "path too long");
- return NULL;
+ PyErr_SetString(PyExc_ValueError, "path too long");
+ return NULL;
}
strcpy(namebuf, name);
for (pt = namebuf; *pt; pt++)
- if (*pt == ALTSEP)
- *pt = SEP;
+ if (*pt == ALTSEP)
+ *pt = SEP;
if (namebuf[len-1] != SEP)
- namebuf[len++] = SEP;
+ namebuf[len++] = SEP;
strcpy(namebuf + len, "*.*");
if ((d = PyList_New(0)) == NULL)
- return NULL;
+ return NULL;
rc = DosFindFirst(namebuf, /* Wildcard Pattern to Match */
- &hdir, /* Handle to Use While Search Directory */
- FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
- &ep, sizeof(ep), /* Structure to Receive Directory Entry */
- &srchcnt, /* Max and Actual Count of Entries Per Iteration */
- FIL_STANDARD); /* Format of Entry (EAs or Not) */
+ &hdir, /* Handle to Use While Search Directory */
+ FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
+ &ep, sizeof(ep), /* Structure to Receive Directory Entry */
+ &srchcnt, /* Max and Actual Count of Entries Per Iteration */
+ FIL_STANDARD); /* Format of Entry (EAs or Not) */
if (rc != NO_ERROR) {
- errno = ENOENT;
- return posix_error_with_filename(name);
+ errno = ENOENT;
+ return posix_error_with_filename(name);
}
if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */
- do {
- if (ep.achName[0] == '.'
- && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2] == '\0')))
- continue; /* Skip Over "." and ".." Names */
+ do {
+ if (ep.achName[0] == '.'
+ && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2] == '\0')))
+ continue; /* Skip Over "." and ".." Names */
- strcpy(namebuf, ep.achName);
+ strcpy(namebuf, ep.achName);
- /* Leave Case of Name Alone -- In Native Form */
- /* (Removed Forced Lowercasing Code) */
+ /* Leave Case of Name Alone -- In Native Form */
+ /* (Removed Forced Lowercasing Code) */
- v = PyString_FromString(namebuf);
- if (v == NULL) {
- Py_DECREF(d);
- d = NULL;
- break;
- }
- if (PyList_Append(d, v) != 0) {
- Py_DECREF(v);
- Py_DECREF(d);
- d = NULL;
- break;
- }
- Py_DECREF(v);
- } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
+ v = PyString_FromString(namebuf);
+ if (v == NULL) {
+ Py_DECREF(d);
+ d = NULL;
+ break;
+ }
+ if (PyList_Append(d, v) != 0) {
+ Py_DECREF(v);
+ Py_DECREF(d);
+ d = NULL;
+ break;
+ }
+ Py_DECREF(v);
+ } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
}
return d;
@@ -2347,8 +2347,8 @@
PyObject *w;
w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "strict");
+ Py_FileSystemDefaultEncoding,
+ "strict");
if (w != NULL) {
Py_DECREF(v);
v = w;
@@ -2396,8 +2396,8 @@
DWORD result;
PyObject *v;
result = GetFullPathNameW(wpath,
- sizeof(woutbuf)/sizeof(woutbuf[0]),
- woutbuf, &wtemp);
+ sizeof(woutbuf)/sizeof(woutbuf[0]),
+ woutbuf, &wtemp);
if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) {
woutbufp = malloc(result * sizeof(Py_UNICODE));
if (!woutbufp)
@@ -2425,7 +2425,7 @@
return win32_error("GetFullPathName", inbuf);
if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {
return PyUnicode_Decode(outbuf, strlen(outbuf),
- Py_FileSystemDefaultEncoding, NULL);
+ Py_FileSystemDefaultEncoding, NULL);
}
return PyString_FromString(outbuf);
} /* end of posix__getfullpathname */
@@ -2758,7 +2758,7 @@
if (!wpath) {
if (!PyArg_ParseTuple(args, "etO:utime",
- Py_FileSystemDefaultEncoding, &apath, &arg))
+ Py_FileSystemDefaultEncoding, &apath, &arg))
return NULL;
Py_BEGIN_ALLOW_THREADS
hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0,
@@ -2835,7 +2835,7 @@
if (!PyArg_ParseTuple(args, "etO:utime",
- Py_FileSystemDefaultEncoding, &path, &arg))
+ Py_FileSystemDefaultEncoding, &path, &arg))
return NULL;
if (arg == Py_None) {
/* optional time values not given */
@@ -3067,7 +3067,7 @@
goto fail_2;
if (!PyList_Check(keys) || !PyList_Check(vals)) {
PyErr_SetString(PyExc_TypeError,
- "execve(): env.keys() or env.values() is not a list");
+ "execve(): env.keys() or env.values() is not a list");
goto fail_2;
}
@@ -3093,8 +3093,8 @@
}
#if defined(PYOS_OS2)
- /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
- if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
+ /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
+ if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
#endif
len = PyString_Size(key) + PyString_Size(val) + 2;
p = PyMem_NEW(char, len);
@@ -3105,7 +3105,7 @@
PyOS_snprintf(p, len, "%s=%s", k, v);
envlist[envc++] = p;
#if defined(PYOS_OS2)
- }
+ }
#endif
}
envlist[envc] = 0;
@@ -3302,7 +3302,7 @@
goto fail_2;
if (!PyList_Check(keys) || !PyList_Check(vals)) {
PyErr_SetString(PyExc_TypeError,
- "spawnve(): env.keys() or env.values() is not a list");
+ "spawnve(): env.keys() or env.values() is not a list");
goto fail_2;
}
@@ -3535,7 +3535,7 @@
goto fail_2;
if (!PyList_Check(keys) || !PyList_Check(vals)) {
PyErr_SetString(PyExc_TypeError,
- "spawnvpe(): env.keys() or env.values() is not a list");
+ "spawnvpe(): env.keys() or env.values() is not a list");
goto fail_2;
}
@@ -4032,17 +4032,17 @@
return NULL;
#if defined(PYOS_OS2) && !defined(PYCC_GCC)
if (sig == XCPT_SIGNAL_INTR || sig == XCPT_SIGNAL_BREAK) {
- APIRET rc;
- if ((rc = DosSendSignalException(pid, sig)) != NO_ERROR)
- return os2_error(rc);
+ APIRET rc;
+ if ((rc = DosSendSignalException(pid, sig)) != NO_ERROR)
+ return os2_error(rc);
} else if (sig == XCPT_SIGNAL_KILLPROC) {
- APIRET rc;
- if ((rc = DosKillProcess(DKP_PROCESS, pid)) != NO_ERROR)
- return os2_error(rc);
+ APIRET rc;
+ if ((rc = DosKillProcess(DKP_PROCESS, pid)) != NO_ERROR)
+ return os2_error(rc);
} else
- return NULL; /* Unrecognized Signal Requested */
+ return NULL; /* Unrecognized Signal Requested */
#else
if (kill(pid, sig) == -1)
return posix_error();
@@ -4692,17 +4692,17 @@
if (!ins_rc[0] && fileObj[0])
{
PyDict_DelItem(_PyPopenProcs,
- fileObj[0]);
+ fileObj[0]);
}
if (!ins_rc[1] && fileObj[1])
{
PyDict_DelItem(_PyPopenProcs,
- fileObj[1]);
+ fileObj[1]);
}
if (!ins_rc[2] && fileObj[2])
{
PyDict_DelItem(_PyPopenProcs,
- fileObj[2]);
+ fileObj[2]);
}
}
}
@@ -5071,23 +5071,23 @@
modulepath[x] = '\0';
/* Create the full-name to w9xpopen, so we can test it exists */
strncat(modulepath,
- szConsoleSpawn,
- (sizeof(modulepath)/sizeof(modulepath[0]))
- -strlen(modulepath));
+ szConsoleSpawn,
+ (sizeof(modulepath)/sizeof(modulepath[0]))
+ -strlen(modulepath));
if (stat(modulepath, &statinfo) != 0) {
size_t mplen = sizeof(modulepath)/sizeof(modulepath[0]);
/* Eeek - file-not-found - possibly an embedding
situation - see if we can locate it in sys.prefix
*/
strncpy(modulepath,
- Py_GetExecPrefix(),
- mplen);
+ Py_GetExecPrefix(),
+ mplen);
modulepath[mplen-1] = '\0';
if (modulepath[strlen(modulepath)-1] != '\\')
strcat(modulepath, "\\");
strncat(modulepath,
- szConsoleSpawn,
- mplen-strlen(modulepath));
+ szConsoleSpawn,
+ mplen-strlen(modulepath));
/* No where else to look - raise an easily identifiable
error, rather than leaving Windows to report
"file not found" - as the user is probably blissfully
@@ -5096,10 +5096,10 @@
*/
if (stat(modulepath, &statinfo) != 0) {
PyErr_Format(PyExc_RuntimeError,
- "Can not locate '%s' which is needed "
- "for popen to work with your shell "
- "or platform.",
- szConsoleSpawn);
+ "Can not locate '%s' which is needed "
+ "for popen to work with your shell "
+ "or platform.",
+ szConsoleSpawn);
return FALSE;
}
}
@@ -5139,8 +5139,8 @@
Now we'll just error out.. */
else {
PyErr_SetString(PyExc_RuntimeError,
- "Cannot locate a COMSPEC environment variable to "
- "use as the shell");
+ "Cannot locate a COMSPEC environment variable to "
+ "use as the shell");
return FALSE;
}
@@ -5880,9 +5880,9 @@
#endif
PyStructSequence_SET_ITEM(result, 0,
- PyFloat_FromDouble(doubletime(ru->ru_utime)));
+ PyFloat_FromDouble(doubletime(ru->ru_utime)));
PyStructSequence_SET_ITEM(result, 1,
- PyFloat_FromDouble(doubletime(ru->ru_stime)));
+ PyFloat_FromDouble(doubletime(ru->ru_stime)));
#define SET_INT(result, index, value)\
PyStructSequence_SET_ITEM(result, index, PyInt_FromLong(value))
SET_INT(result, 2, ru->ru_maxrss);
@@ -6069,7 +6069,7 @@
#endif
if (!PyArg_ParseTuple(args, "et:readlink",
- Py_FileSystemDefaultEncoding, &path))
+ Py_FileSystemDefaultEncoding, &path))
return NULL;
#ifdef Py_USING_UNICODE
v = PySequence_GetItem(args, 0);
@@ -6097,8 +6097,8 @@
PyObject *w;
w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "strict");
+ Py_FileSystemDefaultEncoding,
+ "strict");
if (w != NULL) {
Py_DECREF(v);
v = w;
@@ -6667,7 +6667,7 @@
rc = DosCreatePipe( &read, &write, 4096);
Py_END_ALLOW_THREADS
if (rc != NO_ERROR)
- return os2_error(rc);
+ return os2_error(rc);
return Py_BuildValue("(ii)", read, write);
#else
@@ -6851,18 +6851,18 @@
#if defined(PYOS_OS2)
if (stricmp(s1, "BEGINLIBPATH") == 0) {
- APIRET rc;
+ APIRET rc;
- rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH);
- if (rc != NO_ERROR)
- return os2_error(rc);
+ rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH);
+ if (rc != NO_ERROR)
+ return os2_error(rc);
} else if (stricmp(s1, "ENDLIBPATH") == 0) {
- APIRET rc;
+ APIRET rc;
- rc = DosSetExtLIBPATH(s2, END_LIBPATH);
- if (rc != NO_ERROR)
- return os2_error(rc);
+ rc = DosSetExtLIBPATH(s2, END_LIBPATH);
+ if (rc != NO_ERROR)
+ return os2_error(rc);
} else {
#endif
@@ -6922,7 +6922,7 @@
* old value was still accessible until then.
*/
if (PyDict_DelItem(posix_putenv_garbage,
- PyTuple_GET_ITEM(args, 0))) {
+ PyTuple_GET_ITEM(args, 0))) {
/* really not much we can do; just leak */
PyErr_Clear();
}
@@ -7135,17 +7135,17 @@
PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));
PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));
PyStructSequence_SET_ITEM(v, 2,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));
PyStructSequence_SET_ITEM(v, 3,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_bfree));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_bfree));
PyStructSequence_SET_ITEM(v, 4,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_bavail));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_bavail));
PyStructSequence_SET_ITEM(v, 5,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_files));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_files));
PyStructSequence_SET_ITEM(v, 6,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));
PyStructSequence_SET_ITEM(v, 7,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));
PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));
PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));
#endif
@@ -7221,7 +7221,7 @@
return NULL;
if (PyErr_Warn(PyExc_RuntimeWarning,
- "tempnam is a potential security risk to your program") < 0)
+ "tempnam is a potential security risk to your program") < 0)
return NULL;
#ifdef MS_WINDOWS
@@ -7268,7 +7268,7 @@
char *name;
if (PyErr_Warn(PyExc_RuntimeWarning,
- "tmpnam is a potential security risk to your program") < 0)
+ "tmpnam is a potential security risk to your program") < 0)
return NULL;
#ifdef USE_TMPNAM_R
@@ -8181,14 +8181,14 @@
int name;
if (PyArg_ParseTuple(args, "O&:sysconf", conv_sysconf_confname, &name)) {
- int value;
+ int value;
- errno = 0;
- value = sysconf(name);
- if (value == -1 && errno != 0)
- posix_error();
- else
- result = PyInt_FromLong(value);
+ errno = 0;
+ value = sysconf(name);
+ if (value == -1 && errno != 0)
+ posix_error();
+ else
+ result = PyInt_FromLong(value);
}
return result;
}
@@ -8336,7 +8336,7 @@
Py_XDECREF(woperation);
if (rc <= (HINSTANCE)32) {
PyObject *errval = win32_error_unicode("startfile",
- PyUnicode_AS_UNICODE(unipath));
+ PyUnicode_AS_UNICODE(unipath));
return errval;
}
Py_INCREF(Py_None);
@@ -8920,8 +8920,8 @@
Py_END_ALLOW_THREADS
if (rc != NO_ERROR) {
- os2_error(rc);
- return -1;
+ os2_error(rc);
+ return -1;
}
if (ins(module, "meminstalled", values[QSV_TOTPHYSMEM])) return -1;
@@ -8940,15 +8940,15 @@
case 40: ver = "4.00"; break;
case 50: ver = "5.00"; break;
default:
- PyOS_snprintf(tmp, sizeof(tmp),
- "%d-%d", values[QSV_VERSION_MAJOR],
- values[QSV_VERSION_MINOR]);
- ver = &tmp[0];
+ PyOS_snprintf(tmp, sizeof(tmp),
+ "%d-%d", values[QSV_VERSION_MAJOR],
+ values[QSV_VERSION_MINOR]);
+ ver = &tmp[0];
}
/* Add Indicator of the Version of the Operating System */
if (PyModule_AddStringConstant(module, "version", tmp) < 0)
- return -1;
+ return -1;
/* Add Indicator of Which Drive was Used to Boot the System */
tmp[0] = 'A' + values[QSV_BOOT_DRIVE] - 1;
--- Modules/posixmodule.c 2010-05-06 02:00:07.000000000 +0200
+++ Modules/posixmodule.c.final 2010-05-06 01:59:49.000000000 +0200
@@ -445,6 +445,11 @@
#else
char **e;
#endif
+#if defined(PYOS_OS2)
+ APIRET rc;
+ char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
+#endif
+
d = PyDict_New();
if (d == NULL)
return NULL;
@@ -515,10 +520,6 @@
}
#endif
#if defined(PYOS_OS2)
- {
- APIRET rc;
- char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
-
rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */
PyObject *v = PyBytes_FromString(buffer);
@@ -531,7 +532,6 @@
PyDict_SetItemString(d, "ENDLIBPATH", v);
Py_DECREF(v);
}
- }
#endif
return d;
}
@@ -617,22 +617,22 @@
/**********************************************************************
* Helper Function to Trim and Format OS/2 Messages
**********************************************************************/
- static void
+static void
os2_formatmsg(char *msgbuf, int msglen, char *reason)
{
msgbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */
if (strlen(msgbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
- char *lastc = &msgbuf[ strlen(msgbuf)-1 ];
+ char *lastc = &msgbuf[ strlen(msgbuf)-1 ];
- while (lastc > msgbuf && isspace(Py_CHARMASK(*lastc)))
- *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
+ while (lastc > msgbuf && isspace(Py_CHARMASK(*lastc)))
+ *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
}
/* Add Optional Reason Text */
if (reason) {
- strcat(msgbuf, " : ");
- strcat(msgbuf, reason);
+ strcat(msgbuf, " : ");
+ strcat(msgbuf, reason);
}
}
@@ -647,7 +647,7 @@
* the file OSO001.MSG in the \OS2 directory hierarchy.
*
**********************************************************************/
- static char *
+static char *
os2_strerror(char *msgbuf, int msgbuflen, int errorcode, char *reason)
{
APIRET rc;
@@ -660,10 +660,10 @@
Py_END_ALLOW_THREADS
if (rc == NO_ERROR)
- os2_formatmsg(msgbuf, msglen, reason);
+ os2_formatmsg(msgbuf, msglen, reason);
else
- PyOS_snprintf(msgbuf, msgbuflen,
- "unknown OS error #%d", errorcode);
+ PyOS_snprintf(msgbuf, msgbuflen,
+ "unknown OS error #%d", errorcode);
return msgbuf;
}
@@ -672,7 +672,8 @@
errors are not in a global variable e.g. 'errno' nor are
they congruent with posix error numbers. */
-static PyObject * os2_error(int code)
+static PyObject *
+os2_error(int code)
{
char text[1024];
PyObject *v;
@@ -681,8 +682,8 @@
v = Py_BuildValue("(is)", code, text);
if (v != NULL) {
- PyErr_SetObject(PyExc_OSError, v);
- Py_DECREF(v);
+ PyErr_SetObject(PyExc_OSError, v);
+ Py_DECREF(v);
}
return NULL; /* Signal to Python that an Exception is Pending */
}
@@ -1007,7 +1008,7 @@
stricmp(dot, ".cmd") == 0 ||
stricmp(dot, ".exe") == 0 ||
stricmp(dot, ".com") == 0)
- result->st_mode |= 0111;
+ result->st_mode |= 0111;
}
return code;
}
@@ -1352,19 +1353,19 @@
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
- PyLong_FromLong((long)st->st_blksize));
+ PyLong_FromLong((long)st->st_blksize));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
- PyLong_FromLong((long)st->st_blocks));
+ PyLong_FromLong((long)st->st_blocks));
#endif
#ifdef HAVE_STRUCT_STAT_ST_RDEV
PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
- PyLong_FromLong((long)st->st_rdev));
+ PyLong_FromLong((long)st->st_rdev));
#endif
#ifdef HAVE_STRUCT_STAT_ST_GEN
PyStructSequence_SET_ITEM(v, ST_GEN_IDX,
- PyLong_FromLong((long)st->st_gen));
+ PyLong_FromLong((long)st->st_gen));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
{
@@ -1387,7 +1388,7 @@
#endif
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
- PyLong_FromLong((long)st->st_flags));
+ PyLong_FromLong((long)st->st_flags));
#endif
if (PyErr_Occurred()) {
@@ -1707,7 +1708,7 @@
Py_END_ALLOW_THREADS
if (!res)
return win32_error_unicode("chmod",
- PyUnicode_AS_UNICODE(po));
+ PyUnicode_AS_UNICODE(po));
Py_INCREF(Py_None);
return Py_None;
}
@@ -2257,64 +2258,64 @@
if (!PyArg_ParseTuple(args, "O&:listdir",
PyUnicode_FSConverter, &oname))
- return NULL;
+ return NULL;
name = PyBytes_AsString(oname);
len = PyBytes_GET_SIZE(oname);
if (len >= MAX_PATH) {
- Py_DECREF(oname);
- PyErr_SetString(PyExc_ValueError, "path too long");
- return NULL;
+ Py_DECREF(oname);
+ PyErr_SetString(PyExc_ValueError, "path too long");
+ return NULL;
}
strcpy(namebuf, name);
for (pt = namebuf; *pt; pt++)
- if (*pt == ALTSEP)
- *pt = SEP;
+ if (*pt == ALTSEP)
+ *pt = SEP;
if (namebuf[len-1] != SEP)
- namebuf[len++] = SEP;
+ namebuf[len++] = SEP;
strcpy(namebuf + len, "*.*");
if ((d = PyList_New(0)) == NULL) {
- Py_DECREF(oname);
- return NULL;
+ Py_DECREF(oname);
+ return NULL;
}
rc = DosFindFirst(namebuf, /* Wildcard Pattern to Match */
- &hdir, /* Handle to Use While Search Directory */
- FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
- &ep, sizeof(ep), /* Structure to Receive Directory Entry */
- &srchcnt, /* Max and Actual Count of Entries Per Iteration */
- FIL_STANDARD); /* Format of Entry (EAs or Not) */
+ &hdir, /* Handle to Use While Search Directory */
+ FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
+ &ep, sizeof(ep), /* Structure to Receive Directory Entry */
+ &srchcnt, /* Max and Actual Count of Entries Per Iteration */
+ FIL_STANDARD); /* Format of Entry (EAs or Not) */
if (rc != NO_ERROR) {
- errno = ENOENT;
- return posix_error_with_allocated_filename(oname);
+ errno = ENOENT;
+ return posix_error_with_allocated_filename(oname);
}
if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */
- do {
- if (ep.achName[0] == '.'
- && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2] == '\0')))
- continue; /* Skip Over "." and ".." Names */
+ do {
+ if (ep.achName[0] == '.'
+ && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2] == '\0')))
+ continue; /* Skip Over "." and ".." Names */
- strcpy(namebuf, ep.achName);
+ strcpy(namebuf, ep.achName);
- /* Leave Case of Name Alone -- In Native Form */
- /* (Removed Forced Lowercasing Code) */
+ /* Leave Case of Name Alone -- In Native Form */
+ /* (Removed Forced Lowercasing Code) */
- v = PyBytes_FromString(namebuf);
- if (v == NULL) {
- Py_DECREF(d);
- d = NULL;
- break;
- }
- if (PyList_Append(d, v) != 0) {
- Py_DECREF(v);
- Py_DECREF(d);
- d = NULL;
- break;
- }
- Py_DECREF(v);
- } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
+ v = PyBytes_FromString(namebuf);
+ if (v == NULL) {
+ Py_DECREF(d);
+ d = NULL;
+ break;
+ }
+ if (PyList_Append(d, v) != 0) {
+ Py_DECREF(v);
+ Py_DECREF(d);
+ d = NULL;
+ break;
+ }
+ Py_DECREF(v);
+ } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
}
Py_DECREF(oname);
@@ -2371,8 +2372,8 @@
PyObject *w;
w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "surrogateescape");
+ Py_FileSystemDefaultEncoding,
+ "surrogateescape");
Py_DECREF(v);
if (w != NULL)
v = w;
@@ -2418,8 +2419,8 @@
DWORD result;
PyObject *v;
result = GetFullPathNameW(wpath,
- sizeof(woutbuf)/sizeof(woutbuf[0]),
- woutbuf, &wtemp);
+ sizeof(woutbuf)/sizeof(woutbuf[0]),
+ woutbuf, &wtemp);
if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) {
woutbufp = malloc(result * sizeof(Py_UNICODE));
if (!woutbufp)
@@ -2452,7 +2453,7 @@
Py_DECREF(opath);
if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {
return PyUnicode_Decode(outbuf, strlen(outbuf),
- Py_FileSystemDefaultEncoding, NULL);
+ Py_FileSystemDefaultEncoding, NULL);
}
return PyBytes_FromString(outbuf);
} /* end of posix__getfullpathname */
@@ -2883,7 +2884,7 @@
if (!PyArg_ParseTuple(args, "O&O:utime",
- PyUnicode_FSConverter, &opath, &arg))
+ PyUnicode_FSConverter, &opath, &arg))
return NULL;
path = PyBytes_AsString(opath);
if (arg == Py_None) {
@@ -3077,7 +3078,7 @@
goto error;
if (!PyList_Check(keys) || !PyList_Check(vals)) {
PyErr_Format(PyExc_TypeError,
- "env.keys() or env.values() is not a list");
+ "env.keys() or env.values() is not a list");
goto error;
}
@@ -4024,17 +4025,17 @@
return NULL;
#if defined(PYOS_OS2) && !defined(PYCC_GCC)
if (sig == XCPT_SIGNAL_INTR || sig == XCPT_SIGNAL_BREAK) {
- APIRET rc;
- if ((rc = DosSendSignalException(pid, sig)) != NO_ERROR)
- return os2_error(rc);
+ APIRET rc;
+ if ((rc = DosSendSignalException(pid, sig)) != NO_ERROR)
+ return os2_error(rc);
} else if (sig == XCPT_SIGNAL_KILLPROC) {
- APIRET rc;
- if ((rc = DosKillProcess(DKP_PROCESS, pid)) != NO_ERROR)
- return os2_error(rc);
+ APIRET rc;
+ if ((rc = DosKillProcess(DKP_PROCESS, pid)) != NO_ERROR)
+ return os2_error(rc);
} else
- return NULL; /* Unrecognized Signal Requested */
+ return NULL; /* Unrecognized Signal Requested */
#else
if (kill(pid, sig) == -1)
return posix_error();
@@ -4393,9 +4394,9 @@
#endif
PyStructSequence_SET_ITEM(result, 0,
- PyFloat_FromDouble(doubletime(ru->ru_utime)));
+ PyFloat_FromDouble(doubletime(ru->ru_utime)));
PyStructSequence_SET_ITEM(result, 1,
- PyFloat_FromDouble(doubletime(ru->ru_stime)));
+ PyFloat_FromDouble(doubletime(ru->ru_stime)));
#define SET_INT(result, index, value)\
PyStructSequence_SET_ITEM(result, index, PyLong_FromLong(value))
SET_INT(result, 2, ru->ru_maxrss);
@@ -4581,7 +4582,7 @@
int arg_is_unicode = 0;
if (!PyArg_ParseTuple(args, "O&:readlink",
- PyUnicode_FSConverter, &opath))
+ PyUnicode_FSConverter, &opath))
return NULL;
path = PyBytes_AsString(opath);
v = PySequence_GetItem(args, 0);
@@ -4607,8 +4608,8 @@
PyObject *w;
w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "surrogateescape");
+ Py_FileSystemDefaultEncoding,
+ "surrogateescape");
if (w != NULL) {
Py_DECREF(v);
v = w;
@@ -5118,7 +5119,7 @@
rc = DosCreatePipe( &read, &write, 4096);
Py_END_ALLOW_THREADS
if (rc != NO_ERROR)
- return os2_error(rc);
+ return os2_error(rc);
return Py_BuildValue("(ii)", read, write);
#else
@@ -5320,18 +5321,18 @@
#if defined(PYOS_OS2)
if (stricmp(s1, "BEGINLIBPATH") == 0) {
- APIRET rc;
+ APIRET rc;
- rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH);
- if (rc != NO_ERROR)
- return os2_error(rc);
+ rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH);
+ if (rc != NO_ERROR)
+ return os2_error(rc);
} else if (stricmp(s1, "ENDLIBPATH") == 0) {
- APIRET rc;
+ APIRET rc;
- rc = DosSetExtLIBPATH(s2, END_LIBPATH);
- if (rc != NO_ERROR)
- return os2_error(rc);
+ rc = DosSetExtLIBPATH(s2, END_LIBPATH);
+ if (rc != NO_ERROR)
+ return os2_error(rc);
} else {
#endif
/* XXX This can leak memory -- not easy to fix :-( */
@@ -5411,7 +5412,7 @@
* old value was still accessible until then.
*/
if (PyDict_DelItem(posix_putenv_garbage,
- PyTuple_GET_ITEM(args, 0))) {
+ PyTuple_GET_ITEM(args, 0))) {
/* really not much we can do; just leak */
PyErr_Clear();
}
@@ -5624,17 +5625,17 @@
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
PyStructSequence_SET_ITEM(v, 2,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));
PyStructSequence_SET_ITEM(v, 3,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_bfree));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_bfree));
PyStructSequence_SET_ITEM(v, 4,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_bavail));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_bavail));
PyStructSequence_SET_ITEM(v, 5,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_files));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_files));
PyStructSequence_SET_ITEM(v, 6,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));
PyStructSequence_SET_ITEM(v, 7,
- PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));
+ PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));
PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
#endif
@@ -6046,28 +6047,28 @@
char buffer[256];
if (PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) {
- int len;
+ int len;
- errno = 0;
- len = confstr(name, buffer, sizeof(buffer));
- if (len == 0) {
- if (errno) {
- posix_error();
+ errno = 0;
+ len = confstr(name, buffer, sizeof(buffer));
+ if (len == 0) {
+ if (errno) {
+ posix_error();
+ }
+ else {
+ result = Py_None;
+ Py_INCREF(Py_None);
+ }
}
else {
- result = Py_None;
- Py_INCREF(Py_None);
- }
- }
- else {
- if ((unsigned int)len >= sizeof(buffer)) {
- result = PyUnicode_FromStringAndSize(NULL, len-1);
- if (result != NULL)
- confstr(name, _PyUnicode_AsString(result), len);
+ if ((unsigned int)len >= sizeof(buffer)) {
+ result = PyUnicode_FromStringAndSize(NULL, len-1);
+ if (result != NULL)
+ confstr(name, _PyUnicode_AsString(result), len);
+ }
+ else
+ result = PyUnicode_FromStringAndSize(buffer, len-1);
}
- else
- result = PyUnicode_FromStringAndSize(buffer, len-1);
- }
}
return result;
}
@@ -6589,14 +6590,14 @@
int name;
if (PyArg_ParseTuple(args, "O&:sysconf", conv_sysconf_confname, &name)) {
- int value;
+ int value;
- errno = 0;
- value = sysconf(name);
- if (value == -1 && errno != 0)
- posix_error();
- else
- result = PyLong_FromLong(value);
+ errno = 0;
+ value = sysconf(name);
+ if (value == -1 && errno != 0)
+ posix_error();
+ else
+ result = PyLong_FromLong(value);
}
return result;
}
@@ -6745,7 +6746,7 @@
Py_XDECREF(woperation);
if (rc <= (HINSTANCE)32) {
PyObject *errval = win32_error_unicode("startfile",
- PyUnicode_AS_UNICODE(unipath));
+ PyUnicode_AS_UNICODE(unipath));
return errval;
}
Py_INCREF(Py_None);
@@ -7346,8 +7347,8 @@
Py_END_ALLOW_THREADS
if (rc != NO_ERROR) {
- os2_error(rc);
- return -1;
+ os2_error(rc);
+ return -1;
}
if (ins(module, "meminstalled", values[QSV_TOTPHYSMEM])) return -1;
@@ -7366,15 +7367,15 @@
case 40: ver = "4.00"; break;
case 50: ver = "5.00"; break;
default:
- PyOS_snprintf(tmp, sizeof(tmp),
- "%d-%d", values[QSV_VERSION_MAJOR],
- values[QSV_VERSION_MINOR]);
- ver = &tmp[0];
+ PyOS_snprintf(tmp, sizeof(tmp),
+ "%d-%d", values[QSV_VERSION_MAJOR],
+ values[QSV_VERSION_MINOR]);
+ ver = &tmp[0];
}
/* Add Indicator of the Version of the Operating System */
if (PyModule_AddStringConstant(module, "version", tmp) < 0)
- return -1;
+ return -1;
/* Add Indicator of Which Drive was Used to Boot the System */
tmp[0] = 'A' + values[QSV_BOOT_DRIVE] - 1;
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com