[Python-checkins] CVS: python/dist/src/Mac/Modules macmodule.c,1.43,1.44
Jack Jansen
jackjansen@users.sourceforge.net
2001年8月03日 06:07:21 -0700
Update of /cvsroot/python/python/dist/src/Mac/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv739/python/Mac/Modules
Modified Files:
macmodule.c
Log Message:
(Finally) converted to new-style args.
Added an optional (and ignored) 3d parameter to open() to make the signature compatible with posixmodule.
Added the various O_ constants (by stealing the code from posixmodule).
test_fileinput now passes.
Index: macmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/macmodule.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** macmodule.c 2001年05月12日 21:31:30 1.43
--- macmodule.c 2001年08月03日 13:07:19 1.44
***************
*** 133,137 ****
char *path1;
int res;
! if (!PyArg_Parse(args, "s", &path1))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 133,137 ----
char *path1;
int res;
! if (!PyArg_ParseTuple(args, "s", &path1))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 151,155 ****
char *path1, *path2;
int res;
! if (!PyArg_Parse(args, "(ss)", &path1, &path2))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 151,155 ----
char *path1, *path2;
int res;
! if (!PyArg_ParseTuple(args, "ss", &path1, &path2))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 170,174 ****
int i;
int res;
! if (!PyArg_Parse(args, "(si)", &path, &i))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 170,174 ----
int i;
int res;
! if (!PyArg_ParseTuple(args, "si", &path, &i))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 205,209 ****
{
int fd, res;
! if (!PyArg_Parse(args, "i", &fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 205,209 ----
{
int fd, res;
! if (!PyArg_ParseTuple(args, "i", &fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 227,231 ****
{
int fd;
! if (!PyArg_Parse(args, "i", &fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 227,231 ----
{
int fd;
! if (!PyArg_ParseTuple(args, "i", &fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 249,253 ****
char *mode;
FILE *fp;
! if (!PyArg_Parse(args, "(is)", &fd, &mode))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 249,253 ----
char *mode;
FILE *fp;
! if (!PyArg_ParseTuple(args, "is", &fd, &mode))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 267,271 ****
{
char *res;
! if (!PyArg_NoArgs(args))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 267,271 ----
{
char *res;
! if (!PyArg_ParseTuple(args, ""))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 285,289 ****
char path[MAXPATHLEN];
char *res;
! if (!PyArg_NoArgs(args))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 285,289 ----
char path[MAXPATHLEN];
char *res;
! if (!PyArg_ParseTuple(args, ""))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 310,314 ****
DIR *dirp;
struct dirent *ep;
! if (!PyArg_Parse(args, "s", &name))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 310,314 ----
DIR *dirp;
struct dirent *ep;
! if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 352,356 ****
int how;
long res;
! if (!PyArg_Parse(args, "(iii)", &fd, &where, &how))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 352,356 ----
int how;
long res;
! if (!PyArg_ParseTuple(args, "iii", &fd, &where, &how))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 392,397 ****
char *path;
int mode;
int fd;
! if (!PyArg_Parse(args, "(si)", &path, &mode))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 392,398 ----
char *path;
int mode;
+ int perm; /* Accepted but ignored */
int fd;
! if (!PyArg_ParseTuple(args, "si|i", &path, &mode, &perm))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 410,414 ****
int fd, size;
PyObject *buffer;
! if (!PyArg_Parse(args, "(ii)", &fd, &size))
return NULL;
buffer = PyString_FromStringAndSize((char *)NULL, size);
--- 411,415 ----
int fd, size;
PyObject *buffer;
! if (!PyArg_ParseTuple(args, "ii", &fd, &size))
return NULL;
buffer = PyString_FromStringAndSize((char *)NULL, size);
***************
*** 450,454 ****
char *path;
int res;
! if (!PyArg_Parse(args, "s", &path))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 451,455 ----
char *path;
int res;
! if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 479,483 ****
long fd;
int res;
! if (!PyArg_Parse(args, "l", &fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 480,484 ----
long fd;
int res;
! if (!PyArg_ParseTuple(args, "l", &fd))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 510,514 ****
char *path;
int res;
! if (!PyArg_Parse(args, "s", &path))
return NULL;
/*
--- 511,515 ----
char *path;
int res;
! if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
/*
***************
*** 550,554 ****
{
int res;
! if (!PyArg_NoArgs(args))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 551,555 ----
{
int res;
! if (!PyArg_ParseTuple(args, ""))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 576,580 ****
int fd, size;
char *buffer;
! if (!PyArg_Parse(args, "(is#)", &fd, &buffer, &size))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 577,581 ----
int fd, size;
char *buffer;
! if (!PyArg_ParseTuple(args, "is#", &fd, &buffer, &size))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 601,636 ****
static struct PyMethodDef mac_methods[] = {
! {"chdir", mac_chdir},
! {"close", mac_close},
#ifdef WEHAVE_DUP
! {"dup", mac_dup},
#endif
#ifdef WEHAVE_FDOPEN
! {"fdopen", mac_fdopen},
#endif
#ifdef WEHAVE_FSTAT
! {"fstat", mac_fstat},
#endif
#if TARGET_API_MAC_OS8
! {"getbootvol", mac_getbootvol}, /* non-standard */
#endif
! {"getcwd", mac_getcwd},
! {"listdir", mac_listdir, 0},
! {"lseek", mac_lseek},
{"mkdir", mac_mkdir, 1},
! {"open", mac_open},
! {"read", mac_read},
! {"rename", mac_rename},
! {"rmdir", mac_rmdir},
! {"stat", mac_stat},
#if TARGET_API_MAC_OS8
! {"xstat", mac_xstat},
#endif
! {"sync", mac_sync},
! {"remove", mac_unlink},
! {"unlink", mac_unlink},
! {"write", mac_write},
#ifdef USE_MALLOC_DEBUG
! {"mstats", mac_mstats},
#endif
--- 602,637 ----
static struct PyMethodDef mac_methods[] = {
! {"chdir", mac_chdir, 1},
! {"close", mac_close, 1},
#ifdef WEHAVE_DUP
! {"dup", mac_dup, 1},
#endif
#ifdef WEHAVE_FDOPEN
! {"fdopen", mac_fdopen, 1},
#endif
#ifdef WEHAVE_FSTAT
! {"fstat", mac_fstat, 1},
#endif
#if TARGET_API_MAC_OS8
! {"getbootvol", mac_getbootvol, 1}, /* non-standard */
#endif
! {"getcwd", mac_getcwd, 1},
! {"listdir", mac_listdir, 1},
! {"lseek", mac_lseek, 1},
{"mkdir", mac_mkdir, 1},
! {"open", mac_open, 1},
! {"read", mac_read, 1},
! {"rename", mac_rename, 1},
! {"rmdir", mac_rmdir, 1},
! {"stat", mac_stat, 1},
#if TARGET_API_MAC_OS8
! {"xstat", mac_xstat, 1},
#endif
! {"sync", mac_sync, 1},
! {"remove", mac_unlink, 1},
! {"unlink", mac_unlink, 1},
! {"write", mac_write, 1},
#ifdef USE_MALLOC_DEBUG
! {"mstats", mac_mstats, 1},
#endif
***************
*** 638,642 ****
--- 639,738 ----
};
+ static int
+ ins(PyObject *d, char *symbol, long value)
+ {
+ PyObject* v = PyInt_FromLong(value);
+ if (!v || PyDict_SetItemString(d, symbol, v) < 0)
+ return -1; /* triggers fatal error */
+
+ Py_DECREF(v);
+ return 0;
+ }
+ static int
+ all_ins(PyObject *d)
+ {
+ #ifdef F_OK
+ if (ins(d, "F_OK", (long)F_OK)) return -1;
+ #endif
+ #ifdef R_OK
+ if (ins(d, "R_OK", (long)R_OK)) return -1;
+ #endif
+ #ifdef W_OK
+ if (ins(d, "W_OK", (long)W_OK)) return -1;
+ #endif
+ #ifdef X_OK
+ if (ins(d, "X_OK", (long)X_OK)) return -1;
+ #endif
+ #ifdef NGROUPS_MAX
+ if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1;
+ #endif
+ #ifdef TMP_MAX
+ if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1;
+ #endif
+ #ifdef WNOHANG
+ if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
+ #endif
+ #ifdef O_RDONLY
+ if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1;
+ #endif
+ #ifdef O_WRONLY
+ if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1;
+ #endif
+ #ifdef O_RDWR
+ if (ins(d, "O_RDWR", (long)O_RDWR)) return -1;
+ #endif
+ #ifdef O_NDELAY
+ if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1;
+ #endif
+ #ifdef O_NONBLOCK
+ if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1;
+ #endif
+ #ifdef O_APPEND
+ if (ins(d, "O_APPEND", (long)O_APPEND)) return -1;
+ #endif
+ #ifdef O_DSYNC
+ if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1;
+ #endif
+ #ifdef O_RSYNC
+ if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1;
+ #endif
+ #ifdef O_SYNC
+ if (ins(d, "O_SYNC", (long)O_SYNC)) return -1;
+ #endif
+ #ifdef O_NOCTTY
+ if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1;
+ #endif
+ #ifdef O_CREAT
+ if (ins(d, "O_CREAT", (long)O_CREAT)) return -1;
+ #endif
+ #ifdef O_EXCL
+ if (ins(d, "O_EXCL", (long)O_EXCL)) return -1;
+ #endif
+ #ifdef O_TRUNC
+ if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1;
+ #endif
+ #ifdef O_BINARY
+ if (ins(d, "O_BINARY", (long)O_BINARY)) return -1;
+ #endif
+ #ifdef O_TEXT
+ if (ins(d, "O_TEXT", (long)O_TEXT)) return -1;
+ #endif
+
+ #ifdef HAVE_SPAWNV
+ if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1;
+ if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1;
+ if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1;
+ if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1;
+ if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1;
+ #endif
+
+ #if defined(PYOS_OS2)
+ if (insertvalues(d)) return -1;
+ #endif
+ return 0;
+ }
+
+
void
initmac()
***************
*** 647,650 ****
--- 743,749 ----
d = PyModule_GetDict(m);
+ if (all_ins(d))
+ return;
+
/* Initialize mac.error exception */
MacError = PyErr_NewException("mac.error", NULL, NULL);