diff options
Diffstat (limited to 'Modules/fcntlmodule.c')
-rw-r--r-- | Modules/fcntlmodule.c | 172 |
1 files changed, 78 insertions, 94 deletions
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 6b7e3fc..38ef55f 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -325,11 +325,6 @@ fcntl_lockf(PyObject *self, PyObject *args) &lenobj, &startobj, &whence)) return NULL; -#if defined(PYOS_OS2) && defined(PYCC_GCC) - PyErr_SetString(PyExc_NotImplementedError, - "lockf not supported on OS/2 (EMX)"); - return NULL; -#else #ifndef LOCK_SH #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ @@ -383,7 +378,6 @@ fcntl_lockf(PyObject *self, PyObject *args) } Py_INCREF(Py_None); return Py_None; -#endif /* defined(PYOS_OS2) && defined(PYCC_GCC) */ } PyDoc_STRVAR(lockf_doc, @@ -430,188 +424,179 @@ a file or socket object."); /* Module initialisation */ -static int -ins(PyObject* d, char* symbol, long value) -{ - PyObject* v = PyLong_FromLong(value); - if (!v || PyDict_SetItemString(d, symbol, v) < 0) - return -1; - - Py_DECREF(v); - return 0; -} - -#define INS(x) if (ins(d, #x, (long)x)) return -1 static int -all_ins(PyObject* d) +all_ins(PyObject* m) { - if (ins(d, "LOCK_SH", (long)LOCK_SH)) return -1; - if (ins(d, "LOCK_EX", (long)LOCK_EX)) return -1; - if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1; - if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1; + if (PyModule_AddIntMacro(m, LOCK_SH)) return -1; + if (PyModule_AddIntMacro(m, LOCK_EX)) return -1; + if (PyModule_AddIntMacro(m, LOCK_NB)) return -1; + if (PyModule_AddIntMacro(m, LOCK_UN)) return -1; /* GNU extensions, as of glibc 2.2.4 */ #ifdef LOCK_MAND - if (ins(d, "LOCK_MAND", (long)LOCK_MAND)) return -1; + if (PyModule_AddIntMacro(m, LOCK_MAND)) return -1; #endif #ifdef LOCK_READ - if (ins(d, "LOCK_READ", (long)LOCK_READ)) return -1; + if (PyModule_AddIntMacro(m, LOCK_READ)) return -1; #endif #ifdef LOCK_WRITE - if (ins(d, "LOCK_WRITE", (long)LOCK_WRITE)) return -1; + if (PyModule_AddIntMacro(m, LOCK_WRITE)) return -1; #endif #ifdef LOCK_RW - if (ins(d, "LOCK_RW", (long)LOCK_RW)) return -1; + if (PyModule_AddIntMacro(m, LOCK_RW)) return -1; #endif #ifdef F_DUPFD - if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1; + if (PyModule_AddIntMacro(m, F_DUPFD)) return -1; +#endif +#ifdef F_DUPFD_CLOEXEC + if (PyModule_AddIntMacro(m, F_DUPFD_CLOEXEC)) return -1; #endif #ifdef F_GETFD - if (ins(d, "F_GETFD", (long)F_GETFD)) return -1; + if (PyModule_AddIntMacro(m, F_GETFD)) return -1; #endif #ifdef F_SETFD - if (ins(d, "F_SETFD", (long)F_SETFD)) return -1; + if (PyModule_AddIntMacro(m, F_SETFD)) return -1; #endif #ifdef F_GETFL - if (ins(d, "F_GETFL", (long)F_GETFL)) return -1; + if (PyModule_AddIntMacro(m, F_GETFL)) return -1; #endif #ifdef F_SETFL - if (ins(d, "F_SETFL", (long)F_SETFL)) return -1; + if (PyModule_AddIntMacro(m, F_SETFL)) return -1; #endif #ifdef F_GETLK - if (ins(d, "F_GETLK", (long)F_GETLK)) return -1; + if (PyModule_AddIntMacro(m, F_GETLK)) return -1; #endif #ifdef F_SETLK - if (ins(d, "F_SETLK", (long)F_SETLK)) return -1; + if (PyModule_AddIntMacro(m, F_SETLK)) return -1; #endif #ifdef F_SETLKW - if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1; + if (PyModule_AddIntMacro(m, F_SETLKW)) return -1; #endif #ifdef F_GETOWN - if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1; + if (PyModule_AddIntMacro(m, F_GETOWN)) return -1; #endif #ifdef F_SETOWN - if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1; + if (PyModule_AddIntMacro(m, F_SETOWN)) return -1; #endif #ifdef F_GETSIG - if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1; + if (PyModule_AddIntMacro(m, F_GETSIG)) return -1; #endif #ifdef F_SETSIG - if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1; + if (PyModule_AddIntMacro(m, F_SETSIG)) return -1; #endif #ifdef F_RDLCK - if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1; + if (PyModule_AddIntMacro(m, F_RDLCK)) return -1; #endif #ifdef F_WRLCK - if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1; + if (PyModule_AddIntMacro(m, F_WRLCK)) return -1; #endif #ifdef F_UNLCK - if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1; + if (PyModule_AddIntMacro(m, F_UNLCK)) return -1; #endif /* LFS constants */ #ifdef F_GETLK64 - if (ins(d, "F_GETLK64", (long)F_GETLK64)) return -1; + if (PyModule_AddIntMacro(m, F_GETLK64)) return -1; #endif #ifdef F_SETLK64 - if (ins(d, "F_SETLK64", (long)F_SETLK64)) return -1; + if (PyModule_AddIntMacro(m, F_SETLK64)) return -1; #endif #ifdef F_SETLKW64 - if (ins(d, "F_SETLKW64", (long)F_SETLKW64)) return -1; + if (PyModule_AddIntMacro(m, F_SETLKW64)) return -1; #endif /* GNU extensions, as of glibc 2.2.4. */ #ifdef FASYNC - if (ins(d, "FASYNC", (long)FASYNC)) return -1; + if (PyModule_AddIntMacro(m, FASYNC)) return -1; #endif #ifdef F_SETLEASE - if (ins(d, "F_SETLEASE", (long)F_SETLEASE)) return -1; + if (PyModule_AddIntMacro(m, F_SETLEASE)) return -1; #endif #ifdef F_GETLEASE - if (ins(d, "F_GETLEASE", (long)F_GETLEASE)) return -1; + if (PyModule_AddIntMacro(m, F_GETLEASE)) return -1; #endif #ifdef F_NOTIFY - if (ins(d, "F_NOTIFY", (long)F_NOTIFY)) return -1; + if (PyModule_AddIntMacro(m, F_NOTIFY)) return -1; #endif /* Old BSD flock(). */ #ifdef F_EXLCK - if (ins(d, "F_EXLCK", (long)F_EXLCK)) return -1; + if (PyModule_AddIntMacro(m, F_EXLCK)) return -1; #endif #ifdef F_SHLCK - if (ins(d, "F_SHLCK", (long)F_SHLCK)) return -1; + if (PyModule_AddIntMacro(m, F_SHLCK)) return -1; #endif /* OS X specifics */ #ifdef F_FULLFSYNC - if (ins(d, "F_FULLFSYNC", (long)F_FULLFSYNC)) return -1; + if (PyModule_AddIntMacro(m, F_FULLFSYNC)) return -1; #endif #ifdef F_NOCACHE - if (ins(d, "F_NOCACHE", (long)F_NOCACHE)) return -1; + if (PyModule_AddIntMacro(m, F_NOCACHE)) return -1; #endif /* For F_{GET|SET}FL */ #ifdef FD_CLOEXEC - if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) return -1; + if (PyModule_AddIntMacro(m, FD_CLOEXEC)) return -1; #endif /* For F_NOTIFY */ #ifdef DN_ACCESS - if (ins(d, "DN_ACCESS", (long)DN_ACCESS)) return -1; + if (PyModule_AddIntMacro(m, DN_ACCESS)) return -1; #endif #ifdef DN_MODIFY - if (ins(d, "DN_MODIFY", (long)DN_MODIFY)) return -1; + if (PyModule_AddIntMacro(m, DN_MODIFY)) return -1; #endif #ifdef DN_CREATE - if (ins(d, "DN_CREATE", (long)DN_CREATE)) return -1; + if (PyModule_AddIntMacro(m, DN_CREATE)) return -1; #endif #ifdef DN_DELETE - if (ins(d, "DN_DELETE", (long)DN_DELETE)) return -1; + if (PyModule_AddIntMacro(m, DN_DELETE)) return -1; #endif #ifdef DN_RENAME - if (ins(d, "DN_RENAME", (long)DN_RENAME)) return -1; + if (PyModule_AddIntMacro(m, DN_RENAME)) return -1; #endif #ifdef DN_ATTRIB - if (ins(d, "DN_ATTRIB", (long)DN_ATTRIB)) return -1; + if (PyModule_AddIntMacro(m, DN_ATTRIB)) return -1; #endif #ifdef DN_MULTISHOT - if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1; + if (PyModule_AddIntMacro(m, DN_MULTISHOT)) return -1; #endif #ifdef HAVE_STROPTS_H /* Unix 98 guarantees that these are in stropts.h. */ - INS(I_PUSH); - INS(I_POP); - INS(I_LOOK); - INS(I_FLUSH); - INS(I_FLUSHBAND); - INS(I_SETSIG); - INS(I_GETSIG); - INS(I_FIND); - INS(I_PEEK); - INS(I_SRDOPT); - INS(I_GRDOPT); - INS(I_NREAD); - INS(I_FDINSERT); - INS(I_STR); - INS(I_SWROPT); + if (PyModule_AddIntMacro(m, I_PUSH)) return -1; + if (PyModule_AddIntMacro(m, I_POP)) return -1; + if (PyModule_AddIntMacro(m, I_LOOK)) return -1; + if (PyModule_AddIntMacro(m, I_FLUSH)) return -1; + if (PyModule_AddIntMacro(m, I_FLUSHBAND)) return -1; + if (PyModule_AddIntMacro(m, I_SETSIG)) return -1; + if (PyModule_AddIntMacro(m, I_GETSIG)) return -1; + if (PyModule_AddIntMacro(m, I_FIND)) return -1; + if (PyModule_AddIntMacro(m, I_PEEK)) return -1; + if (PyModule_AddIntMacro(m, I_SRDOPT)) return -1; + if (PyModule_AddIntMacro(m, I_GRDOPT)) return -1; + if (PyModule_AddIntMacro(m, I_NREAD)) return -1; + if (PyModule_AddIntMacro(m, I_FDINSERT)) return -1; + if (PyModule_AddIntMacro(m, I_STR)) return -1; + if (PyModule_AddIntMacro(m, I_SWROPT)) return -1; #ifdef I_GWROPT /* despite the comment above, old-ish glibcs miss a couple... */ - INS(I_GWROPT); -#endif - INS(I_SENDFD); - INS(I_RECVFD); - INS(I_LIST); - INS(I_ATMARK); - INS(I_CKBAND); - INS(I_GETBAND); - INS(I_CANPUT); - INS(I_SETCLTIME); + if (PyModule_AddIntMacro(m, I_GWROPT)) return -1; +#endif + if (PyModule_AddIntMacro(m, I_SENDFD)) return -1; + if (PyModule_AddIntMacro(m, I_RECVFD)) return -1; + if (PyModule_AddIntMacro(m, I_LIST)) return -1; + if (PyModule_AddIntMacro(m, I_ATMARK)) return -1; + if (PyModule_AddIntMacro(m, I_CKBAND)) return -1; + if (PyModule_AddIntMacro(m, I_GETBAND)) return -1; + if (PyModule_AddIntMacro(m, I_CANPUT)) return -1; + if (PyModule_AddIntMacro(m, I_SETCLTIME)) return -1; #ifdef I_GETCLTIME - INS(I_GETCLTIME); + if (PyModule_AddIntMacro(m, I_GETCLTIME)) return -1; #endif - INS(I_LINK); - INS(I_UNLINK); - INS(I_PLINK); - INS(I_PUNLINK); + if (PyModule_AddIntMacro(m, I_LINK)) return -1; + if (PyModule_AddIntMacro(m, I_UNLINK)) return -1; + if (PyModule_AddIntMacro(m, I_PLINK)) return -1; + if (PyModule_AddIntMacro(m, I_PUNLINK)) return -1; #endif return 0; @@ -633,7 +618,7 @@ static struct PyModuleDef fcntlmodule = { PyMODINIT_FUNC PyInit_fcntl(void) { - PyObject *m, *d; + PyObject *m; /* Create the module and add the functions and documentation */ m = PyModule_Create(&fcntlmodule); @@ -641,7 +626,6 @@ PyInit_fcntl(void) return NULL; /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - all_ins(d); + all_ins(m); return m; } |