@@ -132,7 +132,7 @@ mac_1str(args, func)
132132{
133133 char * path1 ;
134134 int res ;
135- if (!PyArg_Parse (args , "s" , & path1 ))
135+ if (!PyArg_ParseTuple (args , "s" , & path1 ))
136136 return NULL ;
137137 Py_BEGIN_ALLOW_THREADS
138138 res = (* func )(path1 );
@@ -150,7 +150,7 @@ mac_2str(args, func)
150150{
151151 char * path1 , * path2 ;
152152 int res ;
153- if (!PyArg_Parse (args , "(ss) " , & path1 , & path2 ))
153+ if (!PyArg_ParseTuple (args , "ss " , & path1 , & path2 ))
154154 return NULL ;
155155 Py_BEGIN_ALLOW_THREADS
156156 res = (* func )(path1 , path2 );
@@ -169,7 +169,7 @@ mac_strint(args, func)
169169 char * path ;
170170 int i ;
171171 int res ;
172- if (!PyArg_Parse (args , "(si) " , & path , & i ))
172+ if (!PyArg_ParseTuple (args , "si " , & path , & i ))
173173 return NULL ;
174174 Py_BEGIN_ALLOW_THREADS
175175 res = (* func )(path , i );
@@ -204,7 +204,7 @@ mac_close(self, args)
204204 PyObject * args ;
205205{
206206 int fd , res ;
207- if (!PyArg_Parse (args , "i" , & fd ))
207+ if (!PyArg_ParseTuple (args , "i" , & fd ))
208208 return NULL ;
209209 Py_BEGIN_ALLOW_THREADS
210210 res = close (fd );
@@ -226,7 +226,7 @@ mac_dup(self, args)
226226 PyObject * args ;
227227{
228228 int fd ;
229- if (!PyArg_Parse (args , "i" , & fd ))
229+ if (!PyArg_ParseTuple (args , "i" , & fd ))
230230 return NULL ;
231231 Py_BEGIN_ALLOW_THREADS
232232 fd = dup (fd );
@@ -248,7 +248,7 @@ mac_fdopen(self, args)
248248 int fd ;
249249 char * mode ;
250250 FILE * fp ;
251- if (!PyArg_Parse (args , "(is) " , & fd , & mode ))
251+ if (!PyArg_ParseTuple (args , "is " , & fd , & mode ))
252252 return NULL ;
253253 Py_BEGIN_ALLOW_THREADS
254254 fp = fdopen (fd , mode );
@@ -266,7 +266,7 @@ mac_getbootvol(self, args)
266266 PyObject * args ;
267267{
268268 char * res ;
269- if (!PyArg_NoArgs (args ))
269+ if (!PyArg_ParseTuple (args , "" ))
270270 return NULL ;
271271 Py_BEGIN_ALLOW_THREADS
272272 res = getbootvol ();
@@ -284,7 +284,7 @@ mac_getcwd(self, args)
284284{
285285 char path [MAXPATHLEN ];
286286 char * res ;
287- if (!PyArg_NoArgs (args ))
287+ if (!PyArg_ParseTuple (args , "" ))
288288 return NULL ;
289289 Py_BEGIN_ALLOW_THREADS
290290#ifdef USE_GUSI
@@ -309,7 +309,7 @@ mac_listdir(self, args)
309309 PyObject * d , * v ;
310310 DIR * dirp ;
311311 struct dirent * ep ;
312- if (!PyArg_Parse (args , "s" , & name ))
312+ if (!PyArg_ParseTuple (args , "s" , & name ))
313313 return NULL ;
314314 Py_BEGIN_ALLOW_THREADS
315315 if ((dirp = opendir (name )) == NULL) {
@@ -351,7 +351,7 @@ mac_lseek(self, args)
351351 int where ;
352352 int how ;
353353 long res ;
354- if (!PyArg_Parse (args , "( iii) " , & fd , & where , & how ))
354+ if (!PyArg_ParseTuple (args , "iii" , & fd , & where , & how ))
355355 return NULL ;
356356 Py_BEGIN_ALLOW_THREADS
357357 res = lseek (fd , (long )where , how );
@@ -391,8 +391,9 @@ mac_open(self, args)
391391{
392392 char * path ;
393393 int mode ;
394+ int perm ; /* Accepted but ignored */
394395 int fd ;
395- if (!PyArg_Parse (args , "(si) " , & path , & mode ))
396+ if (!PyArg_ParseTuple (args , "si|i " , & path , & mode , & perm ))
396397 return NULL ;
397398 Py_BEGIN_ALLOW_THREADS
398399 fd = open (path , mode );
@@ -409,7 +410,7 @@ mac_read(self, args)
409410{
410411 int fd , size ;
411412 PyObject * buffer ;
412- if (!PyArg_Parse (args , "(ii) " , & fd , & size ))
413+ if (!PyArg_ParseTuple (args , "ii " , & fd , & size ))
413414 return NULL ;
414415 buffer = PyString_FromStringAndSize ((char * )NULL , size );
415416 if (buffer == NULL )
@@ -449,7 +450,7 @@ mac_stat(self, args)
449450 struct stat st ;
450451 char * path ;
451452 int res ;
452- if (!PyArg_Parse (args , "s" , & path ))
453+ if (!PyArg_ParseTuple (args , "s" , & path ))
453454 return NULL ;
454455 Py_BEGIN_ALLOW_THREADS
455456 res = stat (path , & st );
@@ -478,7 +479,7 @@ mac_fstat(self, args)
478479 struct stat st ;
479480 long fd ;
480481 int res ;
481- if (!PyArg_Parse (args , "l" , & fd ))
482+ if (!PyArg_ParseTuple (args , "l" , & fd ))
482483 return NULL ;
483484 Py_BEGIN_ALLOW_THREADS
484485 res = fstat ((int )fd , & st );
@@ -509,7 +510,7 @@ mac_xstat(self, args)
509510 struct stat st ;
510511 char * path ;
511512 int res ;
512- if (!PyArg_Parse (args , "s" , & path ))
513+ if (!PyArg_ParseTuple (args , "s" , & path ))
513514 return NULL ;
514515 /*
515516 ** Convoluted: we want stat() and xstat() to agree, so we call both
@@ -549,7 +550,7 @@ mac_sync(self, args)
549550 PyObject * args ;
550551{
551552 int res ;
552- if (!PyArg_NoArgs (args ))
553+ if (!PyArg_ParseTuple (args , "" ))
553554 return NULL ;
554555 Py_BEGIN_ALLOW_THREADS
555556 res = sync ();
@@ -575,7 +576,7 @@ mac_write(self, args)
575576{
576577 int fd , size ;
577578 char * buffer ;
578- if (!PyArg_Parse (args , "( is#) " , & fd , & buffer , & size ))
579+ if (!PyArg_ParseTuple (args , "is#" , & fd , & buffer , & size ))
579580 return NULL ;
580581 Py_BEGIN_ALLOW_THREADS
581582 size = write (fd , buffer , size );
@@ -600,43 +601,138 @@ mac_mstats(self, args)
600601#endif /* USE_MALLOC_DEBUG */
601602
602603static struct PyMethodDef mac_methods [] = {
603- {"chdir" , mac_chdir },
604- {"close" , mac_close },
604+ {"chdir" , mac_chdir , 1 },
605+ {"close" , mac_close , 1 },
605606#ifdef WEHAVE_DUP
606- {"dup" , mac_dup },
607+ {"dup" , mac_dup , 1 },
607608#endif
608609#ifdef WEHAVE_FDOPEN
609- {"fdopen" , mac_fdopen },
610+ {"fdopen" , mac_fdopen , 1 },
610611#endif
611612#ifdef WEHAVE_FSTAT
612- {"fstat" , mac_fstat },
613+ {"fstat" , mac_fstat , 1 },
613614#endif
614615#if TARGET_API_MAC_OS8
615- {"getbootvol" , mac_getbootvol }, /* non-standard */
616+ {"getbootvol" , mac_getbootvol , 1 }, /* non-standard */
616617#endif
617- {"getcwd" , mac_getcwd },
618- {"listdir" , mac_listdir , 0 },
619- {"lseek" , mac_lseek },
618+ {"getcwd" , mac_getcwd , 1 },
619+ {"listdir" , mac_listdir , 1 },
620+ {"lseek" , mac_lseek , 1 },
620621 {"mkdir" , mac_mkdir , 1 },
621- {"open" , mac_open },
622- {"read" , mac_read },
623- {"rename" , mac_rename },
624- {"rmdir" , mac_rmdir },
625- {"stat" , mac_stat },
622+ {"open" , mac_open , 1 },
623+ {"read" , mac_read , 1 },
624+ {"rename" , mac_rename , 1 },
625+ {"rmdir" , mac_rmdir , 1 },
626+ {"stat" , mac_stat , 1 },
626627#if TARGET_API_MAC_OS8
627- {"xstat" , mac_xstat },
628+ {"xstat" , mac_xstat , 1 },
628629#endif
629- {"sync" , mac_sync },
630- {"remove" , mac_unlink },
631- {"unlink" , mac_unlink },
632- {"write" , mac_write },
630+ {"sync" , mac_sync , 1 },
631+ {"remove" , mac_unlink , 1 },
632+ {"unlink" , mac_unlink , 1 },
633+ {"write" , mac_write , 1 },
633634#ifdef USE_MALLOC_DEBUG
634- {"mstats" , mac_mstats },
635+ {"mstats" , mac_mstats , 1 },
635636#endif
636637
637638 {NULL , NULL } /* Sentinel */
638639};
639640
641+ static int
642+ ins (PyObject * d , char * symbol , long value )
643+ {
644+ PyObject * v = PyInt_FromLong (value );
645+ if (!v || PyDict_SetItemString (d , symbol , v ) < 0 )
646+ return -1 ; /* triggers fatal error */
647+
648+ Py_DECREF (v );
649+ return 0 ;
650+ }
651+
652+ static int
653+ all_ins (PyObject * d )
654+ {
655+ #ifdef F_OK
656+ if (ins (d , "F_OK" , (long )F_OK )) return -1 ;
657+ #endif
658+ #ifdef R_OK
659+ if (ins (d , "R_OK" , (long )R_OK )) return -1 ;
660+ #endif
661+ #ifdef W_OK
662+ if (ins (d , "W_OK" , (long )W_OK )) return -1 ;
663+ #endif
664+ #ifdef X_OK
665+ if (ins (d , "X_OK" , (long )X_OK )) return -1 ;
666+ #endif
667+ #ifdef NGROUPS_MAX
668+ if (ins (d , "NGROUPS_MAX" , (long )NGROUPS_MAX )) return -1 ;
669+ #endif
670+ #ifdef TMP_MAX
671+ if (ins (d , "TMP_MAX" , (long )TMP_MAX )) return -1 ;
672+ #endif
673+ #ifdef WNOHANG
674+ if (ins (d , "WNOHANG" , (long )WNOHANG )) return -1 ;
675+ #endif
676+ #ifdef O_RDONLY
677+ if (ins (d , "O_RDONLY" , (long )O_RDONLY )) return -1 ;
678+ #endif
679+ #ifdef O_WRONLY
680+ if (ins (d , "O_WRONLY" , (long )O_WRONLY )) return -1 ;
681+ #endif
682+ #ifdef O_RDWR
683+ if (ins (d , "O_RDWR" , (long )O_RDWR )) return -1 ;
684+ #endif
685+ #ifdef O_NDELAY
686+ if (ins (d , "O_NDELAY" , (long )O_NDELAY )) return -1 ;
687+ #endif
688+ #ifdef O_NONBLOCK
689+ if (ins (d , "O_NONBLOCK" , (long )O_NONBLOCK )) return -1 ;
690+ #endif
691+ #ifdef O_APPEND
692+ if (ins (d , "O_APPEND" , (long )O_APPEND )) return -1 ;
693+ #endif
694+ #ifdef O_DSYNC
695+ if (ins (d , "O_DSYNC" , (long )O_DSYNC )) return -1 ;
696+ #endif
697+ #ifdef O_RSYNC
698+ if (ins (d , "O_RSYNC" , (long )O_RSYNC )) return -1 ;
699+ #endif
700+ #ifdef O_SYNC
701+ if (ins (d , "O_SYNC" , (long )O_SYNC )) return -1 ;
702+ #endif
703+ #ifdef O_NOCTTY
704+ if (ins (d , "O_NOCTTY" , (long )O_NOCTTY )) return -1 ;
705+ #endif
706+ #ifdef O_CREAT
707+ if (ins (d , "O_CREAT" , (long )O_CREAT )) return -1 ;
708+ #endif
709+ #ifdef O_EXCL
710+ if (ins (d , "O_EXCL" , (long )O_EXCL )) return -1 ;
711+ #endif
712+ #ifdef O_TRUNC
713+ if (ins (d , "O_TRUNC" , (long )O_TRUNC )) return -1 ;
714+ #endif
715+ #ifdef O_BINARY
716+ if (ins (d , "O_BINARY" , (long )O_BINARY )) return -1 ;
717+ #endif
718+ #ifdef O_TEXT
719+ if (ins (d , "O_TEXT" , (long )O_TEXT )) return -1 ;
720+ #endif
721+
722+ #ifdef HAVE_SPAWNV
723+ if (ins (d , "P_WAIT" , (long )_P_WAIT )) return -1 ;
724+ if (ins (d , "P_NOWAIT" , (long )_P_NOWAIT )) return -1 ;
725+ if (ins (d , "P_OVERLAY" , (long )_OLD_P_OVERLAY )) return -1 ;
726+ if (ins (d , "P_NOWAITO" , (long )_P_NOWAITO )) return -1 ;
727+ if (ins (d , "P_DETACH" , (long )_P_DETACH )) return -1 ;
728+ #endif
729+
730+ #if defined(PYOS_OS2 )
731+ if (insertvalues (d )) return -1 ;
732+ #endif
733+ return 0 ;
734+ }
735+
640736
641737void
642738initmac ()
@@ -646,6 +742,9 @@ initmac()
646742 m = Py_InitModule ("mac" , mac_methods );
647743 d = PyModule_GetDict (m );
648744
745+ if (all_ins (d ))
746+ return ;
747+
649748 /* Initialize mac.error exception */
650749 MacError = PyErr_NewException ("mac.error" , NULL , NULL );
651750 PyDict_SetItemString (d , "error" , MacError );
0 commit comments