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
65bf9f26
Kaydet (Commit)
65bf9f26
authored
Nis 29, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Quickly renamed.
üst
04e30c18
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
204 additions
and
200 deletions
+204
-200
sysmodule.c
Python/sysmodule.c
+147
-143
traceback.c
Python/traceback.c
+57
-57
No files found.
Python/sysmodule.c
Dosyayı görüntüle @
65bf9f26
...
...
@@ -44,140 +44,137 @@ Data members:
- ps1, ps2: optional primary and secondary prompts (strings)
*/
#include "
allobjects
.h"
#include "
Python
.h"
#include "sysmodule.h"
#include "import.h"
#include "modsupport.h"
#include "osdefs.h"
object
*
sys_trace
,
*
sys_profile
;
int
sys_checki
nterval
=
10
;
PyObject
*
_PySys_TraceFunc
,
*
_PySys_ProfileFunc
;
int
_PySys_CheckI
nterval
=
10
;
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
static
o
bject
*
sysdict
;
static
PyO
bject
*
sysdict
;
#ifdef MS_COREDLL
extern
void
*
PyWin_DLLhModule
;
#endif
o
bject
*
sysge
t
(
name
)
PyO
bject
*
PySys_GetObjec
t
(
name
)
char
*
name
;
{
return
dictlookup
(
sysdict
,
name
);
return
PyDict_GetItemString
(
sysdict
,
name
);
}
FILE
*
sysgetf
ile
(
name
,
def
)
PySys_GetF
ile
(
name
,
def
)
char
*
name
;
FILE
*
def
;
{
FILE
*
fp
=
NULL
;
object
*
v
=
sysge
t
(
name
);
if
(
v
!=
NULL
&&
is_fileobject
(
v
))
fp
=
getfilef
ile
(
v
);
PyObject
*
v
=
PySys_GetObjec
t
(
name
);
if
(
v
!=
NULL
&&
PyFile_Check
(
v
))
fp
=
PyFile_AsF
ile
(
v
);
if
(
fp
==
NULL
)
fp
=
def
;
return
fp
;
}
int
sysse
t
(
name
,
v
)
PySys_SetObjec
t
(
name
,
v
)
char
*
name
;
o
bject
*
v
;
PyO
bject
*
v
;
{
if
(
v
==
NULL
)
{
if
(
dictlookup
(
sysdict
,
name
)
==
NULL
)
if
(
PyDict_GetItemString
(
sysdict
,
name
)
==
NULL
)
return
0
;
else
return
dictremove
(
sysdict
,
name
);
return
PyDict_DelItemString
(
sysdict
,
name
);
}
else
return
dictinsert
(
sysdict
,
name
,
v
);
return
PyDict_SetItemString
(
sysdict
,
name
,
v
);
}
static
o
bject
*
static
PyO
bject
*
sys_exit
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
/* Raise SystemExit so callers may catch it or clean up. */
err_setval
(
SystemExit
,
args
);
PyErr_SetObject
(
PyExc_
SystemExit
,
args
);
return
NULL
;
}
static
o
bject
*
static
PyO
bject
*
sys_settrace
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
if
(
args
==
None
)
if
(
args
==
Py_
None
)
args
=
NULL
;
else
XINCREF
(
args
);
XDECREF
(
sys_trace
);
sys_trace
=
args
;
INCREF
(
None
);
return
None
;
Py_
XINCREF
(
args
);
Py_XDECREF
(
_PySys_TraceFunc
);
_PySys_TraceFunc
=
args
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
sys_setprofile
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
if
(
args
==
None
)
if
(
args
==
Py_
None
)
args
=
NULL
;
else
XINCREF
(
args
);
XDECREF
(
sys_profile
);
sys_profile
=
args
;
INCREF
(
None
);
return
None
;
Py_
XINCREF
(
args
);
Py_XDECREF
(
_PySys_ProfileFunc
);
_PySys_ProfileFunc
=
args
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
sys_setcheckinterval
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
if
(
!
newgetargs
(
args
,
"i"
,
&
sys_checki
nterval
))
if
(
!
PyArg_ParseTuple
(
args
,
"i"
,
&
_PySys_CheckI
nterval
))
return
NULL
;
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
#ifdef USE_MALLOPT
/* Link with -lmalloc (or -lmpc) on an SGI */
#include <malloc.h>
static
o
bject
*
static
PyO
bject
*
sys_mdebug
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
flag
;
if
(
!
getargs
(
args
,
"i"
,
&
flag
))
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
flag
))
return
NULL
;
mallopt
(
M_DEBUG
,
flag
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
#endif
/* USE_MALLOPT */
static
o
bject
*
static
PyO
bject
*
sys_getrefcount
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
o
bject
*
arg
;
if
(
!
getargs
(
args
,
"O"
,
&
arg
))
PyO
bject
*
arg
;
if
(
!
PyArg_Parse
(
args
,
"O"
,
&
arg
))
return
NULL
;
return
newintobject
((
long
)
arg
->
ob_refcnt
);
return
PyInt_FromLong
((
long
)
arg
->
ob_refcnt
);
}
#ifdef COUNT_ALLOCS
...
...
@@ -203,7 +200,7 @@ extern PyObject *_Py_GetObjects Py_PROTO((PyObject *, PyObject *));
extern
PyObject
*
_Py_GetDXProfile
Py_PROTO
((
PyObject
*
,
PyObject
*
));
#endif
static
struct
methodlist
sys_methods
[]
=
{
static
PyMethodDef
sys_methods
[]
=
{
/* Might as well keep this in alphabetic order */
{
"exit"
,
sys_exit
,
0
},
#ifdef COUNT_ALLOCS
...
...
@@ -225,93 +222,100 @@ static struct methodlist sys_methods[] = {
{
NULL
,
NULL
}
/* sentinel */
};
static
o
bject
*
sysin
,
*
sysout
,
*
syserr
;
static
PyO
bject
*
sysin
,
*
sysout
,
*
syserr
;
static
o
bject
*
static
PyO
bject
*
list_builtin_module_names
()
{
object
*
list
=
newlistobject
(
0
);
PyObject
*
list
=
PyList_New
(
0
);
int
i
;
if
(
list
==
NULL
)
return
NULL
;
for
(
i
=
0
;
inittab
[
i
].
name
!=
NULL
;
i
++
)
{
object
*
name
=
newstringobject
(
inittab
[
i
].
name
);
PyObject
*
name
=
PyString_FromString
(
inittab
[
i
].
name
);
if
(
name
==
NULL
)
break
;
addlistitem
(
list
,
name
);
DECREF
(
name
);
PyList_Append
(
list
,
name
);
Py_
DECREF
(
name
);
}
if
(
sortlis
t
(
list
)
!=
0
)
{
DECREF
(
list
);
if
(
PyList_Sor
t
(
list
)
!=
0
)
{
Py_
DECREF
(
list
);
list
=
NULL
;
}
if
(
list
)
{
object
*
v
=
listt
uple
(
list
);
DECREF
(
list
);
PyObject
*
v
=
PyList_AsT
uple
(
list
);
Py_
DECREF
(
list
);
list
=
v
;
}
return
list
;
}
void
initsys
()
PySys_Init
()
{
extern
long
getmaxint
PROTO
((
void
));
extern
char
*
getversion
PROTO
((
void
));
extern
char
*
getcopyright
PROTO
((
void
));
extern
char
*
getplatform
PROTO
((
void
));
extern
char
*
Py_GetPrefix
PROTO
((
void
));
extern
char
*
Py_GetExecPrefix
PROTO
((
void
));
extern
int
fclose
PROTO
((
FILE
*
));
object
*
m
=
initm
odule
(
"sys"
,
sys_methods
);
o
bject
*
v
;
sysdict
=
getmoduled
ict
(
m
);
INCREF
(
sysdict
);
extern
long
PyInt_GetMax
Py_
PROTO
((
void
));
extern
char
*
Py_GetVersion
Py_
PROTO
((
void
));
extern
char
*
Py_GetCopyright
Py_
PROTO
((
void
));
extern
char
*
Py_GetPlatform
Py_
PROTO
((
void
));
extern
char
*
Py_GetPrefix
P
y_P
ROTO
((
void
));
extern
char
*
Py_GetExecPrefix
P
y_P
ROTO
((
void
));
extern
int
fclose
P
y_P
ROTO
((
FILE
*
));
PyObject
*
m
=
Py_InitM
odule
(
"sys"
,
sys_methods
);
PyO
bject
*
v
;
sysdict
=
PyModule_GetD
ict
(
m
);
Py_
INCREF
(
sysdict
);
/* NB keep an extra ref to the std files to avoid closing them
when the user deletes them */
sysin
=
newopenfileobject
(
stdin
,
"<stdin>"
,
"r"
,
fclose
);
sysout
=
newopenfileobject
(
stdout
,
"<stdout>"
,
"w"
,
fclose
);
syserr
=
newopenfileobject
(
stderr
,
"<stderr>"
,
"w"
,
fclose
);
if
(
err_occurred
())
fatal
(
"can't initialize sys.std{in,out,err}"
);
dictinsert
(
sysdict
,
"stdin"
,
sysin
);
dictinsert
(
sysdict
,
"stdout"
,
sysout
);
dictinsert
(
sysdict
,
"stderr"
,
syserr
);
dictinsert
(
sysdict
,
"version"
,
v
=
newstringobject
(
getversion
()));
XDECREF
(
v
);
dictinsert
(
sysdict
,
"copyright"
,
v
=
newstringobject
(
getcopyright
()));
XDECREF
(
v
);
dictinsert
(
sysdict
,
"platform"
,
v
=
newstringobject
(
getplatform
()));
XDECREF
(
v
);
dictinsert
(
sysdict
,
"prefix"
,
v
=
newstringobject
(
Py_GetPrefix
()));
XDECREF
(
v
);
dictinsert
(
sysdict
,
"exec_prefix"
,
v
=
newstringobject
(
Py_GetExecPrefix
()));
XDECREF
(
v
);
dictinsert
(
sysdict
,
"maxint"
,
v
=
newintobject
(
getmaxint
()));
XDECREF
(
v
);
dictinsert
(
sysdict
,
"modules"
,
get_modules
());
dictinsert
(
sysdict
,
"builtin_module_names"
,
sysin
=
PyFile_FromFile
(
stdin
,
"<stdin>"
,
"r"
,
fclose
);
sysout
=
PyFile_FromFile
(
stdout
,
"<stdout>"
,
"w"
,
fclose
);
syserr
=
PyFile_FromFile
(
stderr
,
"<stderr>"
,
"w"
,
fclose
);
if
(
PyErr_Occurred
())
Py_FatalError
(
"can't initialize sys.std{in,out,err}"
);
PyDict_SetItemString
(
sysdict
,
"stdin"
,
sysin
);
PyDict_SetItemString
(
sysdict
,
"stdout"
,
sysout
);
PyDict_SetItemString
(
sysdict
,
"stderr"
,
syserr
);
PyDict_SetItemString
(
sysdict
,
"version"
,
v
=
PyString_FromString
(
Py_GetVersion
()));
Py_XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"copyright"
,
v
=
PyString_FromString
(
Py_GetCopyright
()));
Py_XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"platform"
,
v
=
PyString_FromString
(
Py_GetPlatform
()));
Py_XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"prefix"
,
v
=
PyString_FromString
(
Py_GetPrefix
()));
Py_XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"exec_prefix"
,
v
=
PyString_FromString
(
Py_GetExecPrefix
()));
Py_XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"maxint"
,
v
=
PyInt_FromLong
(
PyInt_GetMax
()));
Py_XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"modules"
,
PyImport_GetModuleDict
());
PyDict_SetItemString
(
sysdict
,
"builtin_module_names"
,
v
=
list_builtin_module_names
());
XDECREF
(
v
);
Py_
XDECREF
(
v
);
#ifdef MS_COREDLL
dictinsert
(
sysdict
,
"dllhandle"
,
v
=
newintobject
((
int
)
PyWin_DLLhModule
));
XDECREF
(
v
);
dictinsert
(
sysdict
,
"winver"
,
v
=
newstringobject
(
MS_DLL_ID
));
XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"dllhandle"
,
v
=
PyInt_FromLong
((
int
)
PyWin_DLLhModule
));
Py_XDECREF
(
v
);
PyDict_SetItemString
(
sysdict
,
"winver"
,
v
=
PyString_FromString
(
MS_DLL_ID
));
Py_XDECREF
(
v
);
#endif
if
(
err_o
ccurred
())
fatal
(
"can't insert sys.* objects in sys dict"
);
if
(
PyErr_O
ccurred
())
Py_FatalError
(
"can't insert sys.* objects in sys dict"
);
}
static
o
bject
*
static
PyO
bject
*
makepathobject
(
path
,
delim
)
char
*
path
;
int
delim
;
{
int
i
,
n
;
char
*
p
;
o
bject
*
v
,
*
w
;
PyO
bject
*
v
,
*
w
;
n
=
1
;
p
=
path
;
...
...
@@ -319,19 +323,19 @@ makepathobject(path, delim)
n
++
;
p
++
;
}
v
=
newlistobject
(
n
);
v
=
PyList_New
(
n
);
if
(
v
==
NULL
)
return
NULL
;
for
(
i
=
0
;
;
i
++
)
{
p
=
strchr
(
path
,
delim
);
if
(
p
==
NULL
)
p
=
strchr
(
path
,
'\0'
);
/* End of string */
w
=
newsizedstringobject
(
path
,
(
int
)
(
p
-
path
));
w
=
PyString_FromStringAndSize
(
path
,
(
int
)
(
p
-
path
));
if
(
w
==
NULL
)
{
DECREF
(
v
);
Py_
DECREF
(
v
);
return
NULL
;
}
setlisti
tem
(
v
,
i
,
w
);
PyList_SetI
tem
(
v
,
i
,
w
);
if
(
*
p
==
'\0'
)
break
;
path
=
p
+
1
;
...
...
@@ -340,61 +344,61 @@ makepathobject(path, delim)
}
void
setpythonp
ath
(
path
)
PySys_SetP
ath
(
path
)
char
*
path
;
{
o
bject
*
v
;
PyO
bject
*
v
;
if
((
v
=
makepathobject
(
path
,
DELIM
))
==
NULL
)
fatal
(
"can't create sys.path"
);
if
(
sysse
t
(
"path"
,
v
)
!=
0
)
fatal
(
"can't assign sys.path"
);
DECREF
(
v
);
Py_FatalError
(
"can't create sys.path"
);
if
(
PySys_SetObjec
t
(
"path"
,
v
)
!=
0
)
Py_FatalError
(
"can't assign sys.path"
);
Py_
DECREF
(
v
);
}
static
o
bject
*
static
PyO
bject
*
makeargvobject
(
argc
,
argv
)
int
argc
;
char
**
argv
;
{
o
bject
*
av
;
PyO
bject
*
av
;
if
(
argc
<=
0
||
argv
==
NULL
)
{
/* Ensure at least one (empty) argument is seen */
static
char
*
empty_argv
[
1
]
=
{
""
};
argv
=
empty_argv
;
argc
=
1
;
}
av
=
newlistobject
(
argc
);
av
=
PyList_New
(
argc
);
if
(
av
!=
NULL
)
{
int
i
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
object
*
v
=
newstringobject
(
argv
[
i
]);
PyObject
*
v
=
PyString_FromString
(
argv
[
i
]);
if
(
v
==
NULL
)
{
DECREF
(
av
);
Py_
DECREF
(
av
);
av
=
NULL
;
break
;
}
setlisti
tem
(
av
,
i
,
v
);
PyList_SetI
tem
(
av
,
i
,
v
);
}
}
return
av
;
}
void
setpythona
rgv
(
argc
,
argv
)
PySys_SetA
rgv
(
argc
,
argv
)
int
argc
;
char
**
argv
;
{
o
bject
*
av
=
makeargvobject
(
argc
,
argv
);
object
*
path
=
sysge
t
(
"path"
);
PyO
bject
*
av
=
makeargvobject
(
argc
,
argv
);
PyObject
*
path
=
PySys_GetObjec
t
(
"path"
);
if
(
av
==
NULL
)
fatal
(
"no mem for sys.argv"
);
if
(
sysse
t
(
"argv"
,
av
)
!=
0
)
fatal
(
"can't assign sys.argv"
);
Py_FatalError
(
"no mem for sys.argv"
);
if
(
PySys_SetObjec
t
(
"argv"
,
av
)
!=
0
)
Py_FatalError
(
"can't assign sys.argv"
);
if
(
path
!=
NULL
)
{
char
*
argv0
=
argv
[
0
];
char
*
p
=
NULL
;
int
n
=
0
;
o
bject
*
a
;
PyO
bject
*
a
;
#ifdef HAVE_READLINK
char
link
[
MAXPATHLEN
+
1
];
char
argv0copy
[
2
*
MAXPATHLEN
+
1
];
...
...
@@ -448,12 +452,12 @@ setpythonargv(argc, argv)
#endif
/* Unix */
}
#endif
/* All others */
a
=
newsizedstringobject
(
argv0
,
n
);
a
=
PyString_FromStringAndSize
(
argv0
,
n
);
if
(
a
==
NULL
)
fatal
(
"no mem for sys.path insertion"
);
if
(
inslistitem
(
path
,
0
,
a
)
<
0
)
fatal
(
"sys.path.insert(0) failed"
);
DECREF
(
a
);
Py_FatalError
(
"no mem for sys.path insertion"
);
if
(
PyList_Insert
(
path
,
0
,
a
)
<
0
)
Py_FatalError
(
"sys.path.insert(0) failed"
);
Py_
DECREF
(
a
);
}
DECREF
(
av
);
Py_
DECREF
(
av
);
}
Python/traceback.c
Dosyayı görüntüle @
65bf9f26
...
...
@@ -31,19 +31,17 @@ PERFORMANCE OF THIS SOFTWARE.
/* Traceback implementation */
#include "
allobjects
.h"
#include "
Python
.h"
#include "sysmodule.h"
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
#include "structmember.h"
#include "osdefs.h"
typedef
struct
_tracebackobject
{
OB
_HEAD
PyObject
_HEAD
struct
_tracebackobject
*
tb_next
;
frameo
bject
*
tb_frame
;
PyFrameO
bject
*
tb_frame
;
int
tb_lasti
;
int
tb_lineno
;
}
tracebackobject
;
...
...
@@ -58,28 +56,28 @@ static struct memberlist tb_memberlist[] = {
{
NULL
}
/* Sentinel */
};
static
o
bject
*
static
PyO
bject
*
tb_getattr
(
tb
,
name
)
tracebackobject
*
tb
;
char
*
name
;
{
return
getmember
((
char
*
)
tb
,
tb_memberlist
,
name
);
return
PyMember_Get
((
char
*
)
tb
,
tb_memberlist
,
name
);
}
static
void
tb_dealloc
(
tb
)
tracebackobject
*
tb
;
{
XDECREF
(
tb
->
tb_next
);
XDECREF
(
tb
->
tb_frame
);
DEL
(
tb
);
Py_
XDECREF
(
tb
->
tb_next
);
Py_
XDECREF
(
tb
->
tb_frame
);
PyMem_
DEL
(
tb
);
}
#define Tracebacktype PyTraceBack_Type
#define is_tracebackobject PyTraceBack_Check
typeo
bject
Tracebacktype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
PyTypeO
bject
Tracebacktype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
"traceback"
,
sizeof
(
tracebackobject
),
...
...
@@ -98,20 +96,20 @@ typeobject Tracebacktype = {
static
tracebackobject
*
newtracebackobject
(
next
,
frame
,
lasti
,
lineno
)
tracebackobject
*
next
;
frameo
bject
*
frame
;
PyFrameO
bject
*
frame
;
int
lasti
,
lineno
;
{
tracebackobject
*
tb
;
if
((
next
!=
NULL
&&
!
is_tracebackobject
(
next
))
||
frame
==
NULL
||
!
is_frameobject
(
frame
))
{
err_badc
all
();
frame
==
NULL
||
!
PyFrame_Check
(
frame
))
{
PyErr_BadInternalC
all
();
return
NULL
;
}
tb
=
NEWOBJ
(
tracebackobject
,
&
Tracebacktype
);
tb
=
PyObject_NEW
(
tracebackobject
,
&
Tracebacktype
);
if
(
tb
!=
NULL
)
{
XINCREF
(
next
);
Py_
XINCREF
(
next
);
tb
->
tb_next
=
next
;
XINCREF
(
frame
);
Py_
XINCREF
(
frame
);
tb
->
tb_frame
=
frame
;
tb
->
tb_lasti
=
lasti
;
tb
->
tb_lineno
=
lineno
;
...
...
@@ -122,44 +120,45 @@ newtracebackobject(next, frame, lasti, lineno)
static
tracebackobject
*
tb_current
=
NULL
;
int
tb_h
ere
(
frame
)
frameo
bject
*
frame
;
PyTraceBack_H
ere
(
frame
)
PyFrameO
bject
*
frame
;
{
tracebackobject
*
tb
;
tb
=
newtracebackobject
(
tb_current
,
frame
,
frame
->
f_lasti
,
frame
->
f_lineno
);
tb
=
newtracebackobject
(
tb_current
,
frame
,
frame
->
f_lasti
,
frame
->
f_lineno
);
if
(
tb
==
NULL
)
return
-
1
;
XDECREF
(
tb_current
);
Py_
XDECREF
(
tb_current
);
tb_current
=
tb
;
return
0
;
}
o
bject
*
tb_f
etch
()
PyO
bject
*
PyTraceBack_F
etch
()
{
o
bject
*
v
;
v
=
(
o
bject
*
)
tb_current
;
PyO
bject
*
v
;
v
=
(
PyO
bject
*
)
tb_current
;
tb_current
=
NULL
;
return
v
;
}
int
tb_s
tore
(
v
)
o
bject
*
v
;
PyTraceBack_S
tore
(
v
)
PyO
bject
*
v
;
{
if
(
v
!=
NULL
&&
!
is_tracebackobject
(
v
))
{
err_badc
all
();
PyErr_BadInternalC
all
();
return
-
1
;
}
XDECREF
(
tb_current
);
XINCREF
(
v
);
Py_
XDECREF
(
tb_current
);
Py_
XINCREF
(
v
);
tb_current
=
(
tracebackobject
*
)
v
;
return
0
;
}
static
void
tb_displayline
(
f
,
filename
,
lineno
,
name
)
o
bject
*
f
;
PyO
bject
*
f
;
char
*
filename
;
int
lineno
;
char
*
name
;
...
...
@@ -177,25 +176,25 @@ tb_displayline(f, filename, lineno, name)
xfp
=
fopen
(
filename
,
"r"
);
if
(
xfp
==
NULL
)
{
/* Search tail of filename in sys.path before giving up */
o
bject
*
path
;
PyO
bject
*
path
;
char
*
tail
=
strrchr
(
filename
,
SEP
);
if
(
tail
==
NULL
)
tail
=
filename
;
else
tail
++
;
path
=
sysge
t
(
"path"
);
if
(
path
!=
NULL
&&
is_listobject
(
path
))
{
int
npath
=
getlists
ize
(
path
);
path
=
PySys_GetObjec
t
(
"path"
);
if
(
path
!=
NULL
&&
PyList_Check
(
path
))
{
int
npath
=
PyList_S
ize
(
path
);
int
taillen
=
strlen
(
tail
);
char
namebuf
[
MAXPATHLEN
+
1
];
for
(
i
=
0
;
i
<
npath
;
i
++
)
{
object
*
v
=
getlisti
tem
(
path
,
i
);
if
(
is_stringobject
(
v
))
{
PyObject
*
v
=
PyList_GetI
tem
(
path
,
i
);
if
(
PyString_Check
(
v
))
{
int
len
;
len
=
getstrings
ize
(
v
);
len
=
PyString_S
ize
(
v
);
if
(
len
+
1
+
taillen
>=
MAXPATHLEN
)
continue
;
/* Too long */
strcpy
(
namebuf
,
getstringvalue
(
v
));
strcpy
(
namebuf
,
PyString_AsString
(
v
));
if
((
int
)
strlen
(
namebuf
)
!=
len
)
continue
;
/* v contains '\0' */
if
(
len
>
0
&&
namebuf
[
len
-
1
]
!=
SEP
)
...
...
@@ -211,7 +210,7 @@ tb_displayline(f, filename, lineno, name)
}
}
sprintf
(
linebuf
,
FMT
,
filename
,
lineno
,
name
);
writes
tring
(
linebuf
,
f
);
PyFile_WriteS
tring
(
linebuf
,
f
);
if
(
xfp
==
NULL
)
return
;
for
(
i
=
0
;
i
<
lineno
;
i
++
)
{
...
...
@@ -222,10 +221,10 @@ tb_displayline(f, filename, lineno, name)
char
*
p
=
linebuf
;
while
(
*
p
==
' '
||
*
p
==
'\t'
||
*
p
==
'\014'
)
p
++
;
writes
tring
(
" "
,
f
);
writes
tring
(
p
,
f
);
PyFile_WriteS
tring
(
" "
,
f
);
PyFile_WriteS
tring
(
p
,
f
);
if
(
strchr
(
p
,
'\n'
)
==
NULL
)
writes
tring
(
"
\n
"
,
f
);
PyFile_WriteS
tring
(
"
\n
"
,
f
);
}
fclose
(
xfp
);
}
...
...
@@ -233,7 +232,7 @@ tb_displayline(f, filename, lineno, name)
static
void
tb_printinternal
(
tb
,
f
,
limit
)
tracebackobject
*
tb
;
o
bject
*
f
;
PyO
bject
*
f
;
int
limit
;
{
int
depth
=
0
;
...
...
@@ -242,14 +241,15 @@ tb_printinternal(tb, f, limit)
depth
++
;
tb1
=
tb1
->
tb_next
;
}
while
(
tb
!=
NULL
&&
!
intrcheck
())
{
while
(
tb
!=
NULL
&&
!
PyOS_InterruptOccurred
())
{
if
(
depth
<=
limit
)
{
tb
->
tb_lineno
=
PyCode_Addr2Line
(
tb
->
tb_frame
->
f_code
,
tb
->
tb_lasti
);
tb_displayline
(
f
,
getstringvalue
(
tb
->
tb_frame
->
f_code
->
co_filename
),
PyString_AsString
(
tb
->
tb_frame
->
f_code
->
co_filename
),
tb
->
tb_lineno
,
getstringvalue
(
tb
->
tb_frame
->
f_code
->
co_name
));
PyString_AsString
(
tb
->
tb_frame
->
f_code
->
co_name
));
}
depth
--
;
tb
=
tb
->
tb_next
;
...
...
@@ -257,25 +257,25 @@ tb_printinternal(tb, f, limit)
}
int
tb_p
rint
(
v
,
f
)
o
bject
*
v
;
o
bject
*
f
;
PyTraceBack_P
rint
(
v
,
f
)
PyO
bject
*
v
;
PyO
bject
*
f
;
{
o
bject
*
limitv
;
PyO
bject
*
limitv
;
int
limit
=
1000
;
if
(
v
==
NULL
)
return
0
;
if
(
!
is_tracebackobject
(
v
))
{
err_badc
all
();
PyErr_BadInternalC
all
();
return
-
1
;
}
limitv
=
sysge
t
(
"tracebacklimit"
);
if
(
limitv
&&
is_intobject
(
limitv
))
{
limit
=
getintvalue
(
limitv
);
limitv
=
PySys_GetObjec
t
(
"tracebacklimit"
);
if
(
limitv
&&
PyInt_Check
(
limitv
))
{
limit
=
PyInt_AsLong
(
limitv
);
if
(
limit
<=
0
)
return
0
;
}
writes
tring
(
"Traceback (innermost last):
\n
"
,
f
);
PyFile_WriteS
tring
(
"Traceback (innermost last):
\n
"
,
f
);
tb_printinternal
((
tracebackobject
*
)
v
,
f
,
limit
);
return
0
;
}
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