Index: Python/errors.c =================================================================== --- Python/errors.c (revision 58381) +++ Python/errors.c (working copy) @@ -639,84 +639,6 @@ Py_XDECREF(tb); } -extern PyObject *PyModule_GetWarningsModule(void); - -/* Function to issue a warning message; may raise an exception. */ -int -PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level) -{ - PyObject *dict, *func = NULL; - PyObject *warnings_module = PyModule_GetWarningsModule(); - - if (warnings_module != NULL) { - dict = PyModule_GetDict(warnings_module); - if (dict != NULL) - func = PyDict_GetItemString(dict, "warn"); - } - if (func == NULL) { - PySys_WriteStderr("warning: %s\n", message); - return 0; - } - else { - PyObject *res; - - if (category == NULL) - category = PyExc_RuntimeWarning; - res = PyObject_CallFunction(func, "sOn", - message, category, stack_level); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; - } -} - -/* PyErr_Warn is only for backwards compatability and will be removed. - Use PyErr_WarnEx instead. */ - -#undef PyErr_Warn - -PyAPI_FUNC(int) -PyErr_Warn(PyObject *category, char *message) -{ - return PyErr_WarnEx(category, message, 1); -} - -/* Warning with explicit origin */ -int -PyErr_WarnExplicit(PyObject *category, const char *message, - const char *filename, int lineno, - const char *module, PyObject *registry) -{ - PyObject *mod, *dict, *func = NULL; - - mod = PyImport_ImportModule("warnings"); - if (mod != NULL) { - dict = PyModule_GetDict(mod); - func = PyDict_GetItemString(dict, "warn_explicit"); - Py_DECREF(mod); - } - if (func == NULL) { - PySys_WriteStderr("warning: %s\n", message); - return 0; - } - else { - PyObject *res; - - if (category == NULL) - category = PyExc_RuntimeWarning; - if (registry == NULL) - registry = Py_None; - res = PyObject_CallFunction(func, "sOsizO", message, category, - filename, lineno, module, registry); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; - } -} - - /* Set file and line information for the current exception. If the exception is not a SyntaxError, also sets additional attributes to make printing of exceptions believe it is a syntax error. */ Index: Python/traceback.c =================================================================== --- Python/traceback.c (revision 58381) +++ Python/traceback.c (working copy) @@ -122,8 +122,8 @@ return 0; } -static int -tb_displayline(PyObject *f, char *filename, int lineno, char *name) +int +Py_DisplayLine(PyObject *f, const char *filename, int lineno, const char *name) { int err = 0; FILE *xfp; @@ -137,7 +137,7 @@ if (xfp == NULL) { /* Search tail of filename in sys.path before giving up */ PyObject *path; - char *tail = strrchr(filename, SEP); + const char *tail = strrchr(filename, SEP); if (tail == NULL) tail = filename; else @@ -211,10 +211,10 @@ } static int -tb_printinternal(PyTracebackObject *tb, PyObject *f, int limit) +tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit) { int err = 0; - int depth = 0; + long depth = 0; PyTracebackObject *tb1 = tb; while (tb1 != NULL) { depth++; @@ -222,7 +222,7 @@ } while (tb != NULL && err == 0) { if (depth <= limit) { - err = tb_displayline(f, + err = Py_DisplayLine(f, PyString_AsString( tb->tb_frame->f_code->co_filename), tb->tb_lineno, @@ -241,7 +241,7 @@ { int err; PyObject *limitv; - int limit = 1000; + long limit = 1000; if (v == NULL) return 0; if (!PyTraceBack_Check(v)) { Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 58381) +++ Python/pythonrun.c (working copy) @@ -81,38 +81,12 @@ true divisions (which they will be in 2.3). */ int _Py_QnewFlag = 0; -/* Reference to 'warnings' module, to avoid importing it - on the fly when the import lock may be held. See 683658/771097 -*/ -static PyObject *warnings_module = NULL; - -/* Returns a borrowed reference to the 'warnings' module, or NULL. - If the module is returned, it is guaranteed to have been obtained - without acquiring the import lock -*/ -PyObject *PyModule_GetWarningsModule(void) +/* PyModule_GetWarningsModule is no longer necessary as of 2.6 +since _warnings is builtin. This API should not be used. */ +PyObject * +PyModule_GetWarningsModule(void) { - PyObject *typ, *val, *tb; - PyObject *all_modules; - /* If we managed to get the module at init time, just use it */ - if (warnings_module) - return warnings_module; - /* If it wasn't available at init time, it may be available - now in sys.modules (common scenario is frozen apps: import - at init time fails, but the frozen init code sets up sys.path - correctly, then does an implicit import of warnings for us - */ - /* Save and restore any exceptions */ - PyErr_Fetch(&typ, &val, &tb); - - all_modules = PySys_GetObject("modules"); - if (all_modules) { - warnings_module = PyDict_GetItemString(all_modules, "warnings"); - /* We keep a ref in the global */ - Py_XINCREF(warnings_module); - } - PyErr_Restore(typ, val, tb); - return warnings_module; + return NULL; } static int initialized = 0; @@ -247,10 +221,6 @@ _PyGILState_Init(interp, tstate); #endif /* WITH_THREAD */ - warnings_module = PyImport_ImportModule("warnings"); - if (!warnings_module) - PyErr_Clear(); - #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET) /* On Unix, set the file system encoding according to the user's preference, if the CODESET names a well-known @@ -370,10 +340,6 @@ /* Disable signal handling */ PyOS_FiniInterrupts(); - /* drop module references we saved */ - Py_XDECREF(warnings_module); - warnings_module = NULL; - /* Collect garbage. This may call finalizers; it's nice to call these * before all modules are destroyed. * XXX If a __del__ or weakref callback is triggered here, and tries to Index: PCbuild/pythoncore.vcproj =================================================================== --- PCbuild/pythoncore.vcproj (revision 58381) +++ PCbuild/pythoncore.vcproj (working copy) @@ -398,6 +398,9 @@ RelativePath="..\Modules\_typesmodule.c"> + + " - if module[-3:].lower() == ".py": - module = module[:-3] # XXX What about leading pathname? - if registry is None: - registry = {} - if isinstance(message, Warning): - text = str(message) - category = message.__class__ - else: - text = message - message = category(message) - key = (text, category, lineno) - # Quick test for common case - if registry.get(key): - return - # Search the filters - for item in filters: - action, msg, cat, mod, ln = item - if ((msg is None or msg.match(text)) and - issubclass(category, cat) and - (mod is None or mod.match(module)) and - (ln == 0 or lineno == ln)): - break - else: - action = defaultaction - # Early exit actions - if action == "ignore": - registry[key] = 1 - return - - # Prime the linecache for formatting, in case the - # "file" is actually in a zipfile or something. - linecache.getlines(filename, module_globals) - - if action == "error": - raise message - # Other actions - if action == "once": - registry[key] = 1 - oncekey = (text, category) - if onceregistry.get(oncekey): - return - onceregistry[oncekey] = 1 - elif action == "always": - pass - elif action == "module": - registry[key] = 1 - altkey = (text, category, 0) - if registry.get(altkey): - return - registry[altkey] = 1 - elif action == "default": - registry[key] = 1 - else: - # Unrecognized actions are errors - raise RuntimeError( - "Unrecognized action (%r) in warnings.filters:\n %s" % - (action, item)) - # Print message and context - showwarning(message, category, filename, lineno) - def showwarning(message, category, filename, lineno, file=None): """Hook to write a warning to a file; replace if you like.""" if file is None: @@ -139,7 +35,7 @@ s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message) line = linecache.getline(filename, lineno).strip() if line: - s = s + " " + line + "\n" + s += " %s\n" % line return s def filterwarnings(action, message="", category=Warning, module="", lineno=0, @@ -260,5 +156,3 @@ # Module initialization _processoptions(sys.warnoptions) -simplefilter("ignore", category=PendingDeprecationWarning, append=1) -simplefilter("ignore", category=ImportWarning, append=1) Index: Makefile.pre.in =================================================================== --- Makefile.pre.in (revision 58381) +++ Makefile.pre.in (working copy) @@ -254,6 +254,7 @@ Python/getcompiler.o \ Python/getcopyright.o \ Python/getmtime.o \ + Python/getopt.o \ Python/getplatform.o \ Python/getversion.o \ Python/graminit.o \ @@ -267,13 +268,13 @@ Python/pyarena.o \ Python/pyfpe.o \ Python/pystate.o \ + Python/pystrtod.o \ Python/pythonrun.o \ Python/structmember.o \ Python/symtable.o \ Python/sysmodule.o \ Python/traceback.o \ - Python/getopt.o \ - Python/pystrtod.o \ + Python/_warnings.o \ Python/$(DYNLOADFILE) \ $(MACHDEP_OBJS) \ $(THREADOBJ) Index: Modules/config.c.in =================================================================== --- Modules/config.c.in (revision 58381) +++ Modules/config.c.in (working copy) @@ -29,6 +29,7 @@ extern void initgc(void); extern void init_ast(void); extern void init_types(void); +extern void init_warnings(void); struct _inittab _PyImport_Inittab[] = { @@ -55,6 +56,9 @@ /* This lives in gcmodule.c */ {"gc", initgc}, + /* This lives in _warnings.c */ + {"_warnings", init_warnings}, + /* Sentinel */ {0, 0} };