Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
373c869a
Kaydet (Commit)
373c869a
authored
Nis 29, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Quickly renamed. Also removed the long comment explaining why this is
better than the old error API.
üst
58d8e3dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
90 deletions
+56
-90
errors.c
Python/errors.c
+56
-90
No files found.
Python/errors.c
Dosyayı görüntüle @
373c869a
...
...
@@ -29,43 +29,9 @@ PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Error handling -- see also run.c */
/* New error handling interface.
The following problem exists (existed): methods of built-in modules
are called with 'self' and 'args' arguments, but without a context
argument, so they have no way to raise a specific exception.
The same is true for the object implementations: no context argument.
The old convention was to set 'errno' and to return NULL.
The caller (usually call_function() in eval.c) detects the NULL
return value and then calls puterrno(ctx) to turn the errno value
into a true exception. Problems with this approach are:
- it used standard errno values to indicate Python-specific errors,
but this means that when such an error code is reported by a system
call (e.g., in module posix), the user gets a confusing message
- errno is a global variable, which makes extensions to a multi-
threading environment difficult; e.g., in IRIX, multi-threaded
programs must use the function oserror() instead of looking in errno
- there is no portable way to add new error numbers for specic
situations -- the value space for errno is reserved to the OS, yet
the way to turn module-specific errors into a module-specific
exception requires module-specific values for errno
- there is no way to add a more situation-specific message to an
error.
The new interface solves all these problems. To return an error, a
built-in function calls err_set(exception), err_setval(exception,
value) or err_setstr(exception, string), and returns NULL. These
functions save the value for later use by puterrno(). To adapt this
scheme to a multi-threaded environment, only the implementation of
err_setval() has to be changed.
*/
#include "allobjects.h"
#include "traceback.h"
/* Error handling */
#include
<errno.h>
#include
"Python.h"
#ifdef SYMANTEC__CFM68K__
#pragma lib_export on
...
...
@@ -77,7 +43,7 @@ PERFORMANCE OF THIS SOFTWARE.
XXX PROBLEM: some positive errors have a meaning for MacOS,
but some library routines set Unix error numbers...
*/
extern
char
*
PyMac_StrError
PROTO
((
int
));
extern
char
*
PyMac_StrError
P
y_P
ROTO
((
int
));
#undef strerror
#define strerror PyMac_StrError
#endif
...
...
@@ -85,127 +51,127 @@ extern char *PyMac_StrError PROTO((int));
#ifndef __STDC__
#ifndef MS_WINDOWS
extern
char
*
strerror
PROTO
((
int
));
extern
char
*
strerror
P
y_P
ROTO
((
int
));
#endif
#endif
/* Last exception stored
by err_setval()
*/
/* Last exception stored */
static
o
bject
*
last_exception
;
static
o
bject
*
last_exc_val
;
static
PyO
bject
*
last_exception
;
static
PyO
bject
*
last_exc_val
;
void
err_r
estore
(
exception
,
value
,
traceback
)
o
bject
*
exception
;
o
bject
*
value
;
o
bject
*
traceback
;
PyErr_R
estore
(
exception
,
value
,
traceback
)
PyO
bject
*
exception
;
PyO
bject
*
value
;
PyO
bject
*
traceback
;
{
err_c
lear
();
PyErr_C
lear
();
last_exception
=
exception
;
last_exc_val
=
value
;
(
void
)
tb_s
tore
(
traceback
);
XDECREF
(
traceback
);
(
void
)
PyTraceBack_S
tore
(
traceback
);
Py_
XDECREF
(
traceback
);
}
void
err_setval
(
exception
,
value
)
o
bject
*
exception
;
o
bject
*
value
;
PyErr_SetObject
(
exception
,
value
)
PyO
bject
*
exception
;
PyO
bject
*
value
;
{
XINCREF
(
exception
);
XINCREF
(
value
);
err_restore
(
exception
,
value
,
(
o
bject
*
)
NULL
);
Py_
XINCREF
(
exception
);
Py_
XINCREF
(
value
);
PyErr_Restore
(
exception
,
value
,
(
PyO
bject
*
)
NULL
);
}
void
err_set
(
exception
)
o
bject
*
exception
;
PyErr_SetNone
(
exception
)
PyO
bject
*
exception
;
{
err_setval
(
exception
,
(
o
bject
*
)
NULL
);
PyErr_SetObject
(
exception
,
(
PyO
bject
*
)
NULL
);
}
void
err_setstr
(
exception
,
string
)
o
bject
*
exception
;
PyErr_SetString
(
exception
,
string
)
PyO
bject
*
exception
;
const
char
*
string
;
{
object
*
value
=
newstringobject
(
string
);
err_setval
(
exception
,
value
);
XDECREF
(
value
);
PyObject
*
value
=
PyString_FromString
(
string
);
PyErr_SetObject
(
exception
,
value
);
Py_
XDECREF
(
value
);
}
o
bject
*
err_o
ccurred
()
PyO
bject
*
PyErr_O
ccurred
()
{
return
last_exception
;
}
void
err_f
etch
(
p_exc
,
p_val
,
p_tb
)
o
bject
**
p_exc
;
o
bject
**
p_val
;
o
bject
**
p_tb
;
PyErr_F
etch
(
p_exc
,
p_val
,
p_tb
)
PyO
bject
**
p_exc
;
PyO
bject
**
p_val
;
PyO
bject
**
p_tb
;
{
*
p_exc
=
last_exception
;
last_exception
=
NULL
;
*
p_val
=
last_exc_val
;
last_exc_val
=
NULL
;
*
p_tb
=
tb_f
etch
();
*
p_tb
=
PyTraceBack_F
etch
();
}
void
err_c
lear
()
PyErr_C
lear
()
{
o
bject
*
tb
;
XDECREF
(
last_exception
);
PyO
bject
*
tb
;
Py_
XDECREF
(
last_exception
);
last_exception
=
NULL
;
XDECREF
(
last_exc_val
);
Py_
XDECREF
(
last_exc_val
);
last_exc_val
=
NULL
;
/* Also clear interpreter stack trace */
tb
=
tb_f
etch
();
XDECREF
(
tb
);
tb
=
PyTraceBack_F
etch
();
Py_
XDECREF
(
tb
);
}
/* Convenience functions to set a type error exception and return 0 */
int
err_badarg
()
PyErr_BadArgument
()
{
err_setstr
(
TypeError
,
"illegal argument type for built-in operation"
);
PyErr_SetString
(
PyExc_
TypeError
,
"illegal argument type for built-in operation"
);
return
0
;
}
o
bject
*
err_nomem
()
PyO
bject
*
PyErr_NoMemory
()
{
err_set
(
MemoryError
);
PyErr_SetNone
(
PyExc_
MemoryError
);
return
NULL
;
}
o
bject
*
err_e
rrno
(
exc
)
o
bject
*
exc
;
PyO
bject
*
PyErr_SetFromE
rrno
(
exc
)
PyO
bject
*
exc
;
{
o
bject
*
v
;
PyO
bject
*
v
;
int
i
=
errno
;
#ifdef EINTR
if
(
i
==
EINTR
&&
sigcheck
())
if
(
i
==
EINTR
&&
PyErr_CheckSignals
())
return
NULL
;
#endif
v
=
mkv
alue
(
"(is)"
,
i
,
strerror
(
i
));
v
=
Py_BuildV
alue
(
"(is)"
,
i
,
strerror
(
i
));
if
(
v
!=
NULL
)
{
err_setval
(
exc
,
v
);
DECREF
(
v
);
PyErr_SetObject
(
exc
,
v
);
Py_
DECREF
(
v
);
}
return
NULL
;
}
void
err_badc
all
()
PyErr_BadInternalC
all
()
{
err_setstr
(
SystemError
,
"bad argument to internal function"
);
PyErr_SetString
(
PyExc_
SystemError
,
"bad argument to internal function"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment