comparison Python/sysmodule.c @ 13658:f79434ee41fa legacy-trunk

Mass ANSIfication of function definitions. Doesn't cover all 'extern' declarations yet, those come later.
author Thomas Wouters <thomas@python.org>
date Sat, 22 Jul 2000 18:47:25 +0000
parents a89f7f268de4
children b54f11ada91e
comparison
equal deleted inserted replaced
13657:6a5314a6c2c2 13658:f79434ee41fa
36 /* A string loaded from the DLL at startup: */ 36 /* A string loaded from the DLL at startup: */
37 extern const char *PyWin_DLLVersionString; 37 extern const char *PyWin_DLLVersionString;
38 #endif 38 #endif
39 39
40 PyObject * 40 PyObject *
41 PySys_GetObject(name) 41 PySys_GetObject(char *name)
42 char *name;
43 { 42 {
44 PyThreadState *tstate = PyThreadState_Get(); 43 PyThreadState *tstate = PyThreadState_Get();
45 PyObject *sd = tstate->interp->sysdict; 44 PyObject *sd = tstate->interp->sysdict;
46 if (sd == NULL) 45 if (sd == NULL)
47 return NULL; 46 return NULL;
48 return PyDict_GetItemString(sd, name); 47 return PyDict_GetItemString(sd, name);
49 } 48 }
50 49
51 FILE * 50 FILE *
52 PySys_GetFile(name, def) 51 PySys_GetFile(char *name, FILE *def)
53 char *name;
54 FILE *def;
55 { 52 {
56 FILE *fp = NULL; 53 FILE *fp = NULL;
57 PyObject *v = PySys_GetObject(name); 54 PyObject *v = PySys_GetObject(name);
58 if (v != NULL && PyFile_Check(v)) 55 if (v != NULL && PyFile_Check(v))
59 fp = PyFile_AsFile(v); 56 fp = PyFile_AsFile(v);
61 fp = def; 58 fp = def;
62 return fp; 59 return fp;
63 } 60 }
64 61
65 int 62 int
66 PySys_SetObject(name, v) 63 PySys_SetObject(char *name, PyObject *v)
67 char *name;
68 PyObject *v;
69 { 64 {
70 PyThreadState *tstate = PyThreadState_Get(); 65 PyThreadState *tstate = PyThreadState_Get();
71 PyObject *sd = tstate->interp->sysdict; 66 PyObject *sd = tstate->interp->sysdict;
72 if (v == NULL) { 67 if (v == NULL) {
73 if (PyDict_GetItemString(sd, name) == NULL) 68 if (PyDict_GetItemString(sd, name) == NULL)
78 else 73 else
79 return PyDict_SetItemString(sd, name, v); 74 return PyDict_SetItemString(sd, name, v);
80 } 75 }
81 76
82 static PyObject * 77 static PyObject *
83 sys_exc_info(self, args) 78 sys_exc_info(PyObject *self, PyObject *args)
84 PyObject *self;
85 PyObject *args;
86 { 79 {
87 PyThreadState *tstate; 80 PyThreadState *tstate;
88 if (!PyArg_ParseTuple(args, ":exc_info")) 81 if (!PyArg_ParseTuple(args, ":exc_info"))
89 return NULL; 82 return NULL;
90 tstate = PyThreadState_Get(); 83 tstate = PyThreadState_Get();
101 \n\ 94 \n\
102 Return information about the exception that is currently being handled.\n\ 95 Return information about the exception that is currently being handled.\n\
103 This should be called from inside an except clause only."; 96 This should be called from inside an except clause only.";
104 97
105 static PyObject * 98 static PyObject *
106 sys_exit(self, args) 99 sys_exit(PyObject *self, PyObject *args)
107 PyObject *self;
108 PyObject *args;
109 { 100 {
110 /* Raise SystemExit so callers may catch it or clean up. */ 101 /* Raise SystemExit so callers may catch it or clean up. */
111 PyErr_SetObject(PyExc_SystemExit, args); 102 PyErr_SetObject(PyExc_SystemExit, args);
112 return NULL; 103 return NULL;
113 } 104 }
120 If the status numeric, it will be used as the system exit status.\n\ 111 If the status numeric, it will be used as the system exit status.\n\
121 If it is another kind of object, it will be printed and the system\n\ 112 If it is another kind of object, it will be printed and the system\n\
122 exit status will be one (i.e., failure)."; 113 exit status will be one (i.e., failure).";
123 114
124 static PyObject * 115 static PyObject *
125 sys_getdefaultencoding(self, args) 116 sys_getdefaultencoding(PyObject *self, PyObject *args)
126 PyObject *self;
127 PyObject *args;
128 { 117 {
129 if (!PyArg_ParseTuple(args, ":getdefaultencoding")) 118 if (!PyArg_ParseTuple(args, ":getdefaultencoding"))
130 return NULL; 119 return NULL;
131 return PyString_FromString(PyUnicode_GetDefaultEncoding()); 120 return PyString_FromString(PyUnicode_GetDefaultEncoding());
132 } 121 }
136 \n\ 125 \n\
137 Return the current default string encoding used by the Unicode \n\ 126 Return the current default string encoding used by the Unicode \n\
138 implementation."; 127 implementation.";
139 128
140 static PyObject * 129 static PyObject *
141 sys_setdefaultencoding(self, args) 130 sys_setdefaultencoding(PyObject *self, PyObject *args)
142 PyObject *self;
143 PyObject *args;
144 { 131 {
145 char *encoding; 132 char *encoding;
146 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding)) 133 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
147 return NULL; 134 return NULL;
148 if (PyUnicode_SetDefaultEncoding(encoding)) 135 if (PyUnicode_SetDefaultEncoding(encoding))
155 "setdefaultencoding(encoding)\n\ 142 "setdefaultencoding(encoding)\n\
156 \n\ 143 \n\
157 Set the current default string encoding used by the Unicode implementation."; 144 Set the current default string encoding used by the Unicode implementation.";
158 145
159 static PyObject * 146 static PyObject *
160 sys_settrace(self, args) 147 sys_settrace(PyObject *self, PyObject *args)
161 PyObject *self;
162 PyObject *args;
163 { 148 {
164 PyThreadState *tstate = PyThreadState_Get(); 149 PyThreadState *tstate = PyThreadState_Get();
165 if (args == Py_None) 150 if (args == Py_None)
166 args = NULL; 151 args = NULL;
167 else 152 else
177 \n\ 162 \n\
178 Set the global debug tracing function. It will be called on each\n\ 163 Set the global debug tracing function. It will be called on each\n\
179 function call. See the debugger chapter in the library manual."; 164 function call. See the debugger chapter in the library manual.";
180 165
181 static PyObject * 166 static PyObject *
182 sys_setprofile(self, args) 167 sys_setprofile(PyObject *self, PyObject *args)
183 PyObject *self;
184 PyObject *args;
185 { 168 {
186 PyThreadState *tstate = PyThreadState_Get(); 169 PyThreadState *tstate = PyThreadState_Get();
187 if (args == Py_None) 170 if (args == Py_None)
188 args = NULL; 171 args = NULL;
189 else 172 else
199 \n\ 182 \n\
200 Set the profiling function. It will be called on each function call\n\ 183 Set the profiling function. It will be called on each function call\n\
201 and return. See the profiler chapter in the library manual."; 184 and return. See the profiler chapter in the library manual.";
202 185
203 static PyObject * 186 static PyObject *
204 sys_setcheckinterval(self, args) 187 sys_setcheckinterval(PyObject *self, PyObject *args)
205 PyObject *self;
206 PyObject *args;
207 { 188 {
208 PyThreadState *tstate = PyThreadState_Get(); 189 PyThreadState *tstate = PyThreadState_Get();
209 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &tstate->interp->checkinterval)) 190 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &tstate->interp->checkinterval))
210 return NULL; 191 return NULL;
211 Py_INCREF(Py_None); 192 Py_INCREF(Py_None);
221 #ifdef USE_MALLOPT 202 #ifdef USE_MALLOPT
222 /* Link with -lmalloc (or -lmpc) on an SGI */ 203 /* Link with -lmalloc (or -lmpc) on an SGI */
223 #include <malloc.h> 204 #include <malloc.h>
224 205
225 static PyObject * 206 static PyObject *
226 sys_mdebug(self, args) 207 sys_mdebug(PyObject *self, PyObject *args)
227 PyObject *self;
228 PyObject *args;
229 { 208 {
230 int flag; 209 int flag;
231 if (!PyArg_ParseTuple(args, "i:mdebug", &flag)) 210 if (!PyArg_ParseTuple(args, "i:mdebug", &flag))
232 return NULL; 211 return NULL;
233 mallopt(M_DEBUG, flag); 212 mallopt(M_DEBUG, flag);
235 return Py_None; 214 return Py_None;
236 } 215 }
237 #endif /* USE_MALLOPT */ 216 #endif /* USE_MALLOPT */
238 217
239 static PyObject * 218 static PyObject *
240 sys_getrefcount(self, args) 219 sys_getrefcount(PyObject *self, PyObject *args)
241 PyObject *self;
242 PyObject *args;
243 { 220 {
244 PyObject *arg; 221 PyObject *arg;
245 if (!PyArg_ParseTuple(args, "O:getrefcount", &arg)) 222 if (!PyArg_ParseTuple(args, "O:getrefcount", &arg))
246 return NULL; 223 return NULL;
247 return PyInt_FromLong(arg->ob_refcnt); 224 return PyInt_FromLong(arg->ob_refcnt);
265 Return the current reference count for the object. This includes the\n\ 242 Return the current reference count for the object. This includes the\n\
266 temporary reference in the argument list, so it is at least 2."; 243 temporary reference in the argument list, so it is at least 2.";
267 244
268 #ifdef COUNT_ALLOCS 245 #ifdef COUNT_ALLOCS
269 static PyObject * 246 static PyObject *
270 sys_getcounts(self, args) 247 sys_getcounts(PyObject *self, PyObject *args)
271 PyObject *self, *args;
272 { 248 {
273 extern PyObject *get_counts(void); 249 extern PyObject *get_counts(void);
274 250
275 if (!PyArg_ParseTuple(args, ":getcounts")) 251 if (!PyArg_ParseTuple(args, ":getcounts"))
276 return NULL; 252 return NULL;
313 {"settrace", sys_settrace, 0, settrace_doc}, 289 {"settrace", sys_settrace, 0, settrace_doc},
314 {NULL, NULL} /* sentinel */ 290 {NULL, NULL} /* sentinel */
315 }; 291 };
316 292
317 static PyObject * 293 static PyObject *
318 list_builtin_module_names() 294 list_builtin_module_names(void)
319 { 295 {
320 PyObject *list = PyList_New(0); 296 PyObject *list = PyList_New(0);
321 int i; 297 int i;
322 if (list == NULL) 298 if (list == NULL)
323 return NULL; 299 return NULL;
405 settrace() -- set the global debug tracing function\n\ 381 settrace() -- set the global debug tracing function\n\
406 "; 382 ";
407 #endif 383 #endif
408 384
409 PyObject * 385 PyObject *
410 _PySys_Init() 386 _PySys_Init(void)
411 { 387 {
412 extern int fclose(FILE *); 388 extern int fclose(FILE *);
413 PyObject *m, *v, *sysdict; 389 PyObject *m, *v, *sysdict;
414 PyObject *sysin, *sysout, *syserr; 390 PyObject *sysin, *sysout, *syserr;
415 char *s; 391 char *s;
493 return NULL; 469 return NULL;
494 return m; 470 return m;
495 } 471 }
496 472
497 static PyObject * 473 static PyObject *
498 makepathobject(path, delim) 474 makepathobject(char *path, int delim)
499 char *path;
500 int delim;
501 { 475 {
502 int i, n; 476 int i, n;
503 char *p; 477 char *p;
504 PyObject *v, *w; 478 PyObject *v, *w;
505 479
528 } 502 }
529 return v; 503 return v;
530 } 504 }
531 505
532 void 506 void
533 PySys_SetPath(path) 507 PySys_SetPath(char *path)
534 char *path;
535 { 508 {
536 PyObject *v; 509 PyObject *v;
537 if ((v = makepathobject(path, DELIM)) == NULL) 510 if ((v = makepathobject(path, DELIM)) == NULL)
538 Py_FatalError("can't create sys.path"); 511 Py_FatalError("can't create sys.path");
539 if (PySys_SetObject("path", v) != 0) 512 if (PySys_SetObject("path", v) != 0)
540 Py_FatalError("can't assign sys.path"); 513 Py_FatalError("can't assign sys.path");
541 Py_DECREF(v); 514 Py_DECREF(v);
542 } 515 }
543 516
544 static PyObject * 517 static PyObject *
545 makeargvobject(argc, argv) 518 makeargvobject(int argc, char **argv)
546 int argc;
547 char **argv;
548 { 519 {
549 PyObject *av; 520 PyObject *av;
550 if (argc <= 0 || argv == NULL) { 521 if (argc <= 0 || argv == NULL) {
551 /* Ensure at least one (empty) argument is seen */ 522 /* Ensure at least one (empty) argument is seen */
552 static char *empty_argv[1] = {""}; 523 static char *empty_argv[1] = {""};
568 } 539 }
569 return av; 540 return av;
570 } 541 }
571 542
572 void 543 void
573 PySys_SetArgv(argc, argv) 544 PySys_SetArgv(int argc, char **argv)
574 int argc;
575 char **argv;
576 { 545 {
577 PyObject *av = makeargvobject(argc, argv); 546 PyObject *av = makeargvobject(argc, argv);
578 PyObject *path = PySys_GetObject("path"); 547 PyObject *path = PySys_GetObject("path");
579 if (av == NULL) 548 if (av == NULL)
580 Py_FatalError("no mem for sys.argv"); 549 Py_FatalError("no mem for sys.argv");
672 which can print hundreds of digits for very large numbers. 641 which can print hundreds of digits for very large numbers.
673 642
674 */ 643 */
675 644
676 static void 645 static void
677 mywrite(name, fp, format, va) 646 mywrite(char *name, FILE *fp, const char *format, va_list va)
678 char *name;
679 FILE *fp;
680 const char *format;
681 va_list va;
682 { 647 {
683 PyObject *file; 648 PyObject *file;
684 PyObject *error_type, *error_value, *error_traceback; 649 PyObject *error_type, *error_value, *error_traceback;
685 650
686 PyErr_Fetch(&error_type, &error_value, &error_traceback); 651 PyErr_Fetch(&error_type, &error_value, &error_traceback);
698 } 663 }
699 PyErr_Restore(error_type, error_value, error_traceback); 664 PyErr_Restore(error_type, error_value, error_traceback);
700 } 665 }
701 666
702 void 667 void
703 #ifdef HAVE_STDARG_PROTOTYPES
704 PySys_WriteStdout(const char *format, ...) 668 PySys_WriteStdout(const char *format, ...)
705 #else
706 PySys_WriteStdout(va_alist)
707 va_dcl
708 #endif
709 { 669 {
710 va_list va; 670 va_list va;
711 671
712 #ifdef HAVE_STDARG_PROTOTYPES
713 va_start(va, format); 672 va_start(va, format);
714 #else
715 char *format;
716 va_start(va);
717 format = va_arg(va, char *);
718 #endif
719 mywrite("stdout", stdout, format, va); 673 mywrite("stdout", stdout, format, va);
720 va_end(va); 674 va_end(va);
721 } 675 }
722 676
723 void 677 void
724 #ifdef HAVE_STDARG_PROTOTYPES
725 PySys_WriteStderr(const char *format, ...) 678 PySys_WriteStderr(const char *format, ...)
726 #else
727 PySys_WriteStderr(va_alist)
728 va_dcl
729 #endif
730 { 679 {
731 va_list va; 680 va_list va;
732 681
733 #ifdef HAVE_STDARG_PROTOTYPES
734 va_start(va, format); 682 va_start(va, format);
735 #else
736 char *format;
737 va_start(va);
738 format = va_arg(va, char *);
739 #endif
740 mywrite("stderr", stderr, format, va); 683 mywrite("stderr", stderr, format, va);
741 va_end(va); 684 va_end(va);
742 } 685 }