--- _warnings.c 2009-07-17 08:33:04.000000000 +0200 +++ _warnings.c 2010-05-25 17:29:40.000000000 +0200 @@ -531,6 +531,16 @@ setup_context(Py_ssize_t stack_level, Py Py_INCREF(*filename); } else { + PyCodeObject *f_code = (PyCodeObject*)f->f_code; + if(f_code!=NULL) { + PyObject *co_filename = f_code->co_filename; + if(co_filename!=NULL) { + *filename = PyObject_Str(co_filename); + //*filename already INCREF'ed + return 1; + } + } + const char *module_str = PyString_AsString(*module); if (module_str && strcmp(module_str, "__main__") == 0) { PyObject *argv = PySys_GetObject("argv");