Commit Graph

81 Commits

Author SHA1 Message Date
Mark Hammond 3d61a06aa2 Fix [ 616716 ] Bug in PyErr_SetExcFromWindows
Ensure that even if FormatMessage fails we (a) don't crash, and (b) provide something useful.

Bugfix candidate.
2002-10-04 00:13:02 +00:00
Mark Hammond da7efaa681 Fix errors to pep277 checkin identified by Neal Norwitz. 2002-10-04 00:09:38 +00:00
Mark Hammond c2e85bd4e2 Patch 594001: PEP 277 - Unicode file name support for Windows NT. 2002-10-03 05:10:39 +00:00
Thomas Heller 085358a3e2 New functions for extension writers on Windows:
PyErr_SetExcFromWindowsErr(), PyErr_SetExcFromWindowsErrWithFilename().

Similar to PyErr_SetFromWindowsErrWithFilename() and
PyErr_SetFromWindowsErr(), but they allow to specify
the exception type to raise. Available on Windows.

See SF patch #576458.
2002-07-29 14:27:41 +00:00
Martin v. Löwis 6238d2b024 Patch #569753: Remove support for WIN16.
Rename all occurrences of MS_WIN32 to MS_WINDOWS.
2002-06-30 15:26:10 +00:00
Jack Jansen 7b8c7546eb Mass checkin of universal newline support.
Highlights: import and friends will understand any of \r, \n and \r\n
as end of line. Python file input will do the same if you use mode 'U'.
Everything can be disabled by configuring with --without-universal-newlines.

See PEP278 for details.
2002-04-14 20:12:41 +00:00
Martin v. Löwis 3484a18af1 Patch #494045: patches errno and stat to cope on plan9. 2002-03-09 12:07:51 +00:00
Martin v. Löwis cfeb3b6ab8 Patch #50002: Display line information for bad \x escapes:
- recognize "SyntaxError"s by the print_file_and_line attribute.
- add the syntaxerror attributes to all exceptions in compile.c.
Fixes #221791
2002-03-03 21:30:27 +00:00
Tim Peters c15c4f1f39 SF bug [#467265] Compile errors on SuSe Linux on IBM/s390.
Unknown whether this fixes it.
- stringobject.c, PyString_FromFormatV:  don't assume that va_list is of
  a type that can be copied via an initializer.
- errors.c, PyErr_Format:  add a va_end() to balance the va_start().
2001-10-02 21:32:07 +00:00
Jeremy Hylton e2e2c9f41e PyErr_NormalizeException()
If a new exception occurs while an exception instance is being
created, try harder to make sure there is a traceback.  If the
original exception had a traceback associated with it and the new
exception does not, keep the old exception.

Of course, callers to PyErr_NormalizeException() must still be
prepared to have tb set to NULL.

XXX This isn't an ideal solution, but it's better than no traceback at
all.  It occurs if, for example, the exception occurs when the call to
the constructor fails before any Python code is executed.  Guido
suggests that it there is Python code that was about to be executed
-- but wasn't, say, because it was called with the wrong number of
arguments -- then we should point at the first line of the code object
anyway.
2001-09-26 19:58:38 +00:00
Barry Warsaw 876c8cb597 PyErr_Format(): Factor out most of this code into
PyString_FromFormat() since it's much more generally useful than
    just for exceptions.
2001-08-24 18:35:23 +00:00
Tim Peters 024da3545b PyErr_Occurred(): Use PyThreadState_GET(), which saves a tiny function call
in release builds.  Suggested by Martin v. Loewis.

I'm half tempted to macroize PyErr_Occurred too, as the whole thing could
collapse to just
     _PyThreadState_Current->curexc_type
2001-05-30 06:09:50 +00:00
Martin v. Löwis 2b6727bd8a Use Py_CHARMASK for ctype macros. Fixes bug #232787. 2001-03-06 12:12:02 +00:00
Guido van Rossum 2fd456508f Add PyErr_WarnExplicit(), which calls warnings.warn_explicit(), with
explicit filename, lineno etc. arguments.
2001-02-28 21:46:24 +00:00
Jeremy Hylton ad3d3f2f3f Improve SyntaxErrors for bad future statements. Set file and location
for errors raised in future.c.

Move some helper functions from compile.c to errors.c and make them
API functions: PyErr_SyntaxLocation() and PyErr_ProgramText().
2001-02-28 17:47:12 +00:00
Guido van Rossum cfd42b556b Add PyErr_Warn(). 2000-12-15 21:58:52 +00:00
Fred Drake 661ea26b3d Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity.

This (mostly) closes SourceForge patch #101839.
2000-10-24 19:57:45 +00:00
Fred Drake e693df94ed Avoid a couple of "value computed is not used" warnings from gcc -Wall;
these computations are required for their side effects in traversing the
variable arguments list.

Reported by Marc-Andre Lemburg <mal@lemburg.com>.
2000-10-10 21:10:35 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Jeremy Hylton b69a27e5b2 code part of patch #100895 by Fredrik Lundh
PyErr_Format computes size of buffer needed rather than relying on
static buffer.
2000-09-01 03:49:47 +00:00
Jeremy Hylton b709df3810 refactor __del__ exception handler into PyErr_WriteUnraisable
add sanity check to gc: if an exception occurs during GC, call
PyErr_WriteUnraisable and then call Py_FatalEror.
2000-09-01 02:47:25 +00:00
Fred Drake 6d63adfbb7 Improve the exceptions raised by PyErr_BadInternalCall(); adding the
filename and line number of the call site to allow esier debugging.

This closes SourceForge patch #101214.
2000-08-24 22:38:39 +00:00
Vladimir Marangozov 0888ff17bd Do not set a MemoryError exception over another MemoryError exception,
thus preserving the first one that has been raised.
2000-08-18 18:01:06 +00:00
Guido van Rossum ed473a46fc Avoid dumping core when PyErr_NormalizeException() is called without
an exception set.  This shouldn't happen, but we see it at times...
2000-08-07 19:18:27 +00:00
Thomas Wouters f70ef4f860 Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
2000-07-22 18:47:25 +00:00
Skip Montanaro 6980dff3db delete obsolete SYMANTEC__CFM68K__ #ifdefs 2000-07-12 17:21:42 +00:00
Tim Peters dbd9ba6a6c Nuke all remaining occurrences of Py_PROTO and Py_FPROTO. 2000-07-09 03:09:57 +00:00
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Barry Warsaw fa5c315afa PyErr_GivenExceptionMatches(): Check for err==NULL and exc==NULL and
return 0 (exceptions don't match).  This means that if an ImportError
is raised because exceptions.py can't be imported, the interpreter
will exit "cleanly" with an error message instead of just core
dumping.

PyErr_SetFromErrnoWithFilename(), PyErr_SetFromWindowsErrWithFilename():
Don't test on Py_UseClassExceptionsFlag.
2000-05-02 19:27:51 +00:00
Guido van Rossum 0b55670968 Mark discovered a bug in his patch: he didn't *use* PyExc_WindowsError
in PyErr_SetFromWindowsErrWithFilename() like he intended to... :-)
2000-03-02 13:55:01 +00:00
Guido van Rossum 584b16a1f3 Mark pointed out a buglet in his patch: i < _sys_nerr isn't strong
enough, it could be negative.  Add i > 0 test.  (Not i >= 0; zero isn't
a valid error number.)
2000-02-21 16:50:31 +00:00
Guido van Rossum 795e189d28 Patch by Mark Hammond:
* Changes to a recent patch by Chris Tismer to errors.c.  Chris' patch
always used FormatMessage() to get the error message passing the error code
from errno - but errno and FormatMessage use a different numbering scheme.
The main reason the patch looked OK was that ENOFILE==ERROR_FILE_NOT_FOUND -
but that is about the only shared error code :-).  The MS CRT docs tell you
to use _sys_errlist()/_sys_nerr.  My patch does also this, and adds a very
similar function specifically for win32 error codes.
2000-02-17 15:19:15 +00:00
Guido van Rossum 743007d2fe Patch by Christian Tismer for Win32, to use FormatMessage() instead of
strerror().  This improves the quality of the error messages.
1999-04-21 15:27:31 +00:00
Guido van Rossum 885553e8d3 Use PyThreadState_GET() macro. 1998-12-21 18:33:30 +00:00
Guido van Rossum e0e59829e0 When errno is zero, avoid calling strerror() and use "Error" for the
message.
1998-10-14 20:38:13 +00:00
Barry Warsaw 97d951533e PyErr_SetFromErrnoWithFilename(): New function which supports setting
an exception from errno, with a supplied filename (primarily used by
IOError and OSError).  If class exceptions are used then the exception
is instantiated with a 3-tuple: (errno, strerror, filename).  For
backwards compatibility reasons, if string exceptions are used,
filename is ignored.

PyErr_SetFromErrno(): Implement in terms of
PyErr_SetFromErrnoWithFilename().
1998-07-23 16:05:56 +00:00
Guido van Rossum 19b55f2d17 Fix subtle bug in cleanup code in PyErr_NormalizeException(), detected
by Marc Lemburg.  There's a path through the code where *val is NULL,
but value isn't, and value should be DECREF'ed.
1997-12-09 14:11:39 +00:00
Guido van Rossum 2ac650f385 New version of PyErr_NewException() that is compatible with -X option. 1997-10-03 19:50:55 +00:00
Barry Warsaw 3a74993118 PyErr_NormalizeException(): If the exception's type is a class and the
instance's class is a subclass of this, then use the instance's class
as the exception type.
1997-09-30 15:00:18 +00:00
Guido van Rossum 7617e05a9b New API PyErr_NewException(name, base, dict) to create simple new exceptions. 1997-09-16 18:43:50 +00:00
Barry Warsaw 2d8adff10a PyErr_NoMemory(): If the pre-instantiated memory exception is non-null
(PyExc_MemoryErrorInst) raise this instead of PyExc_MemoryError.  This
only happens when exception classes are enabled (e.g. when Python is
started with -X).
1997-08-29 21:54:35 +00:00
Barry Warsaw c0dc92af7d Three new C API functions:
- int PyErr_GivenExceptionMatches(obj1, obj2)

  Returns 1 if obj1 and obj2 are the same object, or if obj1 is an
  instance of type obj2, or of a class derived from obj2

- int PyErr_ExceptionMatches(obj)

  Higher level wrapper around PyErr_GivenExceptionMatches() which uses
  PyErr_Occurred() as obj1.  This will be the more commonly called
  function.

- void PyErr_NormalizeException(typeptr, valptr, tbptr)

  Normalizes exceptions, and places the normalized values in the
  arguments.  If type is not a class, this does nothing.  If type is a
  class, then it makes sure that value is an instance of the class by:

  1. if instance is of the type, or a class derived from type, it does
     nothing.

  2. otherwise it instantiates the class, using the value as an
     argument.  If value is None, it uses an empty arg tuple, and if
     the value is a tuple, it uses just that.
1997-08-22 21:22:58 +00:00
Guido van Rossum e5b4026881 Use strerror on the mac if using MSL (Jack). 1997-08-12 14:51:52 +00:00
Guido van Rossum a027efa5bf Massive changes for separate thread state management.
All per-thread globals are moved into a struct which is manipulated
separately.
1997-05-05 20:56:21 +00:00
Guido van Rossum 373c869a6a Quickly renamed. Also removed the long comment explaining why this is
better than the old error API.
1997-04-29 18:22:47 +00:00
Guido van Rossum 7844e38a98 Keep Microsoft VC happy. 1997-04-11 20:44:04 +00:00
Guido van Rossum 6976a52099 (Jack:) On the Mac, use standard strerror() if using MSL C-library. 1997-04-11 19:18:23 +00:00
Guido van Rossum 2dc466169e Oops, remove an unused variable from PyErr_Format(). 1997-02-14 20:57:31 +00:00
Guido van Rossum 1548bacb14 Added convenience function PyErr_Format(exception, formatstring, ...) -> NULL. 1997-02-14 17:09:47 +00:00