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
82598051
Kaydet (Commit)
82598051
authored
Mar 05, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Greatly renamed. Not a very thorough job -- I'm going to restructure
it anyway.
üst
159b77fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
211 additions
and
210 deletions
+211
-210
pythonrun.c
Python/pythonrun.c
+211
-210
No files found.
Python/pythonrun.c
Dosyayı görüntüle @
82598051
...
@@ -31,7 +31,7 @@ PERFORMANCE OF THIS SOFTWARE.
...
@@ -31,7 +31,7 @@ PERFORMANCE OF THIS SOFTWARE.
/* Python interpreter top-level routines, including init/exit */
/* Python interpreter top-level routines, including init/exit */
#include "
allobjects
.h"
#include "
Python
.h"
#include "grammar.h"
#include "grammar.h"
#include "node.h"
#include "node.h"
...
@@ -39,12 +39,8 @@ PERFORMANCE OF THIS SOFTWARE.
...
@@ -39,12 +39,8 @@ PERFORMANCE OF THIS SOFTWARE.
#include "graminit.h"
#include "graminit.h"
#undef argument
/* Avoid conflict on Mac */
#undef argument
/* Avoid conflict on Mac */
#include "errcode.h"
#include "errcode.h"
#include "sysmodule.h"
#include "bltinmodule.h"
#include "compile.h"
#include "compile.h"
#include "eval.h"
#include "eval.h"
#include "ceval.h"
#include "import.h"
#include "marshal.h"
#include "marshal.h"
#ifdef HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
...
@@ -61,30 +57,30 @@ PERFORMANCE OF THIS SOFTWARE.
...
@@ -61,30 +57,30 @@ PERFORMANCE OF THIS SOFTWARE.
#include "windows.h"
#include "windows.h"
#endif
#endif
extern
char
*
getpythonp
ath
();
extern
char
*
Py_GetP
ath
();
extern
grammar
gram
;
/* From graminit.c */
extern
grammar
_PyParser_Grammar
;
/* From graminit.c */
/* Forward */
/* Forward */
static
void
initmain
PROTO
((
void
));
static
void
initmain
P
y_P
ROTO
((
void
));
static
object
*
run_err_node
PROTO
((
node
*
n
,
char
*
filename
,
static
PyObject
*
run_err_node
Py_
PROTO
((
node
*
n
,
char
*
filename
,
object
*
globals
,
o
bject
*
locals
));
PyObject
*
globals
,
PyO
bject
*
locals
));
static
object
*
run_node
PROTO
((
node
*
n
,
char
*
filename
,
static
PyObject
*
run_node
Py_
PROTO
((
node
*
n
,
char
*
filename
,
object
*
globals
,
o
bject
*
locals
));
PyObject
*
globals
,
PyO
bject
*
locals
));
static
object
*
run_pyc_file
PROTO
((
FILE
*
fp
,
char
*
filename
,
static
PyObject
*
run_pyc_file
Py_
PROTO
((
FILE
*
fp
,
char
*
filename
,
object
*
globals
,
o
bject
*
locals
));
PyObject
*
globals
,
PyO
bject
*
locals
));
static
void
err_input
PROTO
((
perrdetail
*
));
static
void
err_input
P
y_P
ROTO
((
perrdetail
*
));
static
void
initsigs
PROTO
((
void
));
static
void
initsigs
P
y_P
ROTO
((
void
));
int
debuggin
g
;
/* Needed by parser.c */
int
Py_DebugFla
g
;
/* Needed by parser.c */
int
verbose
;
/* Needed by import.c */
int
Py_VerboseFlag
;
/* Needed by import.c */
int
suppress_print
;
/* Needed by ceval.c */
int
Py_SuppressPrintingFlag
;
/* Needed by ceval.c */
int
Py_InteractiveFlag
;
/* Needed by Py_FdIsInteractive() below */
int
Py_InteractiveFlag
;
/* Needed by Py_FdIsInteractive() below */
/* Initialize all */
/* Initialize all */
void
void
initall
()
Py_Initialize
()
{
{
static
int
inited
;
static
int
inited
;
...
@@ -92,17 +88,17 @@ initall()
...
@@ -92,17 +88,17 @@ initall()
return
;
return
;
inited
=
1
;
inited
=
1
;
initimpor
t
();
PyImport_Ini
t
();
/* Modules '__builtin__' and 'sys' are initialized here,
/* Modules '__builtin__' and 'sys' are initialized here,
they are needed by random bits of the interpreter.
they are needed by random bits of the interpreter.
All other modules are optional and are initialized
All other modules are optional and are initialized
when they are first imported. */
when they are first imported. */
initbuiltin
();
/* Also initializes builtin exceptions */
PyBuiltin_Init
();
/* Also initializes builtin exceptions */
initsys
();
PySys_Init
();
setpythonpath
(
getpythonp
ath
());
PySys_SetPath
(
Py_GetP
ath
());
initsigs
();
/* Signal handling stuff, including initintr() */
initsigs
();
/* Signal handling stuff, including initintr() */
...
@@ -114,51 +110,52 @@ initall()
...
@@ -114,51 +110,52 @@ initall()
static
void
static
void
initmain
()
initmain
()
{
{
o
bject
*
m
,
*
d
;
PyO
bject
*
m
,
*
d
;
m
=
add_m
odule
(
"__main__"
);
m
=
PyImport_AddM
odule
(
"__main__"
);
if
(
m
==
NULL
)
if
(
m
==
NULL
)
fatal
(
"can't create __main__ module"
);
Py_FatalError
(
"can't create __main__ module"
);
d
=
getmoduledict
(
m
);
d
=
PyModule_GetDict
(
m
);
if
(
dictlookup
(
d
,
"__builtins__"
)
==
NULL
)
{
if
(
PyDict_GetItemString
(
d
,
"__builtins__"
)
==
NULL
)
{
if
(
dictinsert
(
d
,
"__builtins__"
,
getbuiltins
()))
if
(
PyDict_SetItemString
(
d
,
"__builtins__"
,
fatal
(
"can't add __builtins__ to __main__"
);
PyEval_GetBuiltins
()))
Py_FatalError
(
"can't add __builtins__ to __main__"
);
}
}
}
}
/* Parse input from a file and execute it */
/* Parse input from a file and execute it */
int
int
run
(
fp
,
filename
)
PyRun_AnyFile
(
fp
,
filename
)
FILE
*
fp
;
FILE
*
fp
;
char
*
filename
;
char
*
filename
;
{
{
if
(
filename
==
NULL
)
if
(
filename
==
NULL
)
filename
=
"???"
;
filename
=
"???"
;
if
(
Py_FdIsInteractive
(
fp
,
filename
))
if
(
Py_FdIsInteractive
(
fp
,
filename
))
return
run_tty_l
oop
(
fp
,
filename
);
return
PyRun_InteractiveL
oop
(
fp
,
filename
);
else
else
return
run_script
(
fp
,
filename
);
return
PyRun_SimpleFile
(
fp
,
filename
);
}
}
int
int
run_tty_l
oop
(
fp
,
filename
)
PyRun_InteractiveL
oop
(
fp
,
filename
)
FILE
*
fp
;
FILE
*
fp
;
char
*
filename
;
char
*
filename
;
{
{
o
bject
*
v
;
PyO
bject
*
v
;
int
ret
;
int
ret
;
v
=
sysge
t
(
"ps1"
);
v
=
PySys_GetObjec
t
(
"ps1"
);
if
(
v
==
NULL
)
{
if
(
v
==
NULL
)
{
sysset
(
"ps1"
,
v
=
newstringobject
(
">>> "
));
PySys_SetObject
(
"ps1"
,
v
=
PyString_FromString
(
">>> "
));
XDECREF
(
v
);
Py_
XDECREF
(
v
);
}
}
v
=
sysge
t
(
"ps2"
);
v
=
PySys_GetObjec
t
(
"ps2"
);
if
(
v
==
NULL
)
{
if
(
v
==
NULL
)
{
sysset
(
"ps2"
,
v
=
newstringobject
(
"... "
));
PySys_SetObject
(
"ps2"
,
v
=
PyString_FromString
(
"... "
));
XDECREF
(
v
);
Py_
XDECREF
(
v
);
}
}
for
(;;)
{
for
(;;)
{
ret
=
run_tty_1
(
fp
,
filename
);
ret
=
PyRun_InteractiveOne
(
fp
,
filename
);
#ifdef Py_REF_DEBUG
#ifdef Py_REF_DEBUG
fprintf
(
stderr
,
"[%ld refs]
\n
"
,
_Py_RefTotal
);
fprintf
(
stderr
,
"[%ld refs]
\n
"
,
_Py_RefTotal
);
#endif
#endif
...
@@ -172,37 +169,38 @@ run_tty_loop(fp, filename)
...
@@ -172,37 +169,38 @@ run_tty_loop(fp, filename)
}
}
int
int
run_tty_1
(
fp
,
filename
)
PyRun_InteractiveOne
(
fp
,
filename
)
FILE
*
fp
;
FILE
*
fp
;
char
*
filename
;
char
*
filename
;
{
{
o
bject
*
m
,
*
d
,
*
v
,
*
w
;
PyO
bject
*
m
,
*
d
,
*
v
,
*
w
;
node
*
n
;
node
*
n
;
perrdetail
err
;
perrdetail
err
;
char
*
ps1
,
*
ps2
;
char
*
ps1
,
*
ps2
;
v
=
sysge
t
(
"ps1"
);
v
=
PySys_GetObjec
t
(
"ps1"
);
w
=
sysge
t
(
"ps2"
);
w
=
PySys_GetObjec
t
(
"ps2"
);
if
(
v
!=
NULL
&&
is_stringobject
(
v
))
{
if
(
v
!=
NULL
&&
PyString_Check
(
v
))
{
INCREF
(
v
);
Py_
INCREF
(
v
);
ps1
=
getstringvalue
(
v
);
ps1
=
PyString_AsString
(
v
);
}
}
else
{
else
{
v
=
NULL
;
v
=
NULL
;
ps1
=
""
;
ps1
=
""
;
}
}
if
(
w
!=
NULL
&&
is_stringobject
(
w
))
{
if
(
w
!=
NULL
&&
PyString_Check
(
w
))
{
INCREF
(
w
);
Py_
INCREF
(
w
);
ps2
=
getstringvalue
(
w
);
ps2
=
PyString_AsString
(
w
);
}
}
else
{
else
{
w
=
NULL
;
w
=
NULL
;
ps2
=
""
;
ps2
=
""
;
}
}
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
n
=
parsefile
(
fp
,
filename
,
&
gram
,
single_input
,
ps1
,
ps2
,
&
err
);
n
=
PyParser_ParseFile
(
fp
,
filename
,
&
_PyParser_Grammar
,
END_SAVE
single_input
,
ps1
,
ps2
,
&
err
);
XDECREF
(
v
);
Py_END_ALLOW_THREADS
XDECREF
(
w
);
Py_XDECREF
(
v
);
Py_XDECREF
(
w
);
if
(
n
==
NULL
)
{
if
(
n
==
NULL
)
{
if
(
err
.
error
==
E_EOF
)
{
if
(
err
.
error
==
E_EOF
)
{
if
(
err
.
text
)
if
(
err
.
text
)
...
@@ -210,35 +208,35 @@ run_tty_1(fp, filename)
...
@@ -210,35 +208,35 @@ run_tty_1(fp, filename)
return
E_EOF
;
return
E_EOF
;
}
}
err_input
(
&
err
);
err_input
(
&
err
);
print_error
();
PyErr_Print
();
return
err
.
error
;
return
err
.
error
;
}
}
m
=
add_m
odule
(
"__main__"
);
m
=
PyImport_AddM
odule
(
"__main__"
);
if
(
m
==
NULL
)
if
(
m
==
NULL
)
return
-
1
;
return
-
1
;
d
=
getmoduled
ict
(
m
);
d
=
PyModule_GetD
ict
(
m
);
v
=
run_node
(
n
,
filename
,
d
,
d
);
v
=
run_node
(
n
,
filename
,
d
,
d
);
if
(
v
==
NULL
)
{
if
(
v
==
NULL
)
{
print_error
();
PyErr_Print
();
return
-
1
;
return
-
1
;
}
}
DECREF
(
v
);
Py_
DECREF
(
v
);
flushl
ine
();
Py_FlushL
ine
();
return
0
;
return
0
;
}
}
int
int
run_script
(
fp
,
filename
)
PyRun_SimpleFile
(
fp
,
filename
)
FILE
*
fp
;
FILE
*
fp
;
char
*
filename
;
char
*
filename
;
{
{
o
bject
*
m
,
*
d
,
*
v
;
PyO
bject
*
m
,
*
d
,
*
v
;
char
*
ext
;
char
*
ext
;
m
=
add_m
odule
(
"__main__"
);
m
=
PyImport_AddM
odule
(
"__main__"
);
if
(
m
==
NULL
)
if
(
m
==
NULL
)
return
-
1
;
return
-
1
;
d
=
getmoduled
ict
(
m
);
d
=
PyModule_GetD
ict
(
m
);
ext
=
filename
+
strlen
(
filename
)
-
4
;
ext
=
filename
+
strlen
(
filename
)
-
4
;
#ifdef macintosh
#ifdef macintosh
/* On a mac, we also assume a pyc file for types 'PYC ' and 'APPL' */
/* On a mac, we also assume a pyc file for types 'PYC ' and 'APPL' */
...
@@ -255,83 +253,83 @@ run_script(fp, filename)
...
@@ -255,83 +253,83 @@ run_script(fp, filename)
}
}
v
=
run_pyc_file
(
fp
,
filename
,
d
,
d
);
v
=
run_pyc_file
(
fp
,
filename
,
d
,
d
);
}
else
{
}
else
{
v
=
run_f
ile
(
fp
,
filename
,
file_input
,
d
,
d
);
v
=
PyRun_F
ile
(
fp
,
filename
,
file_input
,
d
,
d
);
}
}
if
(
v
==
NULL
)
{
if
(
v
==
NULL
)
{
print_error
();
PyErr_Print
();
return
-
1
;
return
-
1
;
}
}
DECREF
(
v
);
Py_
DECREF
(
v
);
flushl
ine
();
Py_FlushL
ine
();
return
0
;
return
0
;
}
}
int
int
run_command
(
command
)
PyRun_SimpleString
(
command
)
char
*
command
;
char
*
command
;
{
{
o
bject
*
m
,
*
d
,
*
v
;
PyO
bject
*
m
,
*
d
,
*
v
;
m
=
add_m
odule
(
"__main__"
);
m
=
PyImport_AddM
odule
(
"__main__"
);
if
(
m
==
NULL
)
if
(
m
==
NULL
)
return
-
1
;
return
-
1
;
d
=
getmoduled
ict
(
m
);
d
=
PyModule_GetD
ict
(
m
);
v
=
run_s
tring
(
command
,
file_input
,
d
,
d
);
v
=
PyRun_S
tring
(
command
,
file_input
,
d
,
d
);
if
(
v
==
NULL
)
{
if
(
v
==
NULL
)
{
print_error
();
PyErr_Print
();
return
-
1
;
return
-
1
;
}
}
DECREF
(
v
);
Py_
DECREF
(
v
);
flushl
ine
();
Py_FlushL
ine
();
return
0
;
return
0
;
}
}
void
void
print_error
()
PyErr_Print
()
{
{
o
bject
*
exception
,
*
v
,
*
tb
,
*
f
;
PyO
bject
*
exception
,
*
v
,
*
tb
,
*
f
;
err_f
etch
(
&
exception
,
&
v
,
&
tb
);
PyErr_F
etch
(
&
exception
,
&
v
,
&
tb
);
flushl
ine
();
Py_FlushL
ine
();
fflush
(
stdout
);
fflush
(
stdout
);
if
(
exception
==
NULL
)
if
(
exception
==
NULL
)
fatal
(
"print_error called but no exception"
);
Py_FatalError
(
"print_error called but no exception"
);
if
(
exception
==
SystemExit
)
{
if
(
exception
==
PyExc_
SystemExit
)
{
if
(
v
==
NULL
||
v
==
None
)
if
(
v
==
NULL
||
v
==
Py_
None
)
goaway
(
0
);
Py_Exit
(
0
);
if
(
is_intobject
(
v
))
if
(
PyInt_Check
(
v
))
goaway
((
int
)
getintvalue
(
v
));
Py_Exit
((
int
)
PyInt_AsLong
(
v
));
else
{
else
{
/* OK to use real stderr here */
/* OK to use real stderr here */
printobject
(
v
,
stderr
,
PRINT_RAW
);
PyObject_Print
(
v
,
stderr
,
Py_
PRINT_RAW
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
goaway
(
1
);
Py_Exit
(
1
);
}
}
}
}
sysse
t
(
"last_type"
,
exception
);
PySys_SetObjec
t
(
"last_type"
,
exception
);
sysse
t
(
"last_value"
,
v
);
PySys_SetObjec
t
(
"last_value"
,
v
);
sysse
t
(
"last_traceback"
,
tb
);
PySys_SetObjec
t
(
"last_traceback"
,
tb
);
f
=
sysge
t
(
"stderr"
);
f
=
PySys_GetObjec
t
(
"stderr"
);
if
(
f
==
NULL
)
if
(
f
==
NULL
)
fprintf
(
stderr
,
"lost sys.stderr
\n
"
);
fprintf
(
stderr
,
"lost sys.stderr
\n
"
);
else
{
else
{
tb_p
rint
(
tb
,
f
);
PyTraceBack_P
rint
(
tb
,
f
);
if
(
exception
==
SyntaxError
)
{
if
(
exception
==
PyExc_
SyntaxError
)
{
o
bject
*
message
;
PyO
bject
*
message
;
char
*
filename
,
*
text
;
char
*
filename
,
*
text
;
int
lineno
,
offset
;
int
lineno
,
offset
;
if
(
!
getargs
(
v
,
"(O(ziiz))"
,
&
message
,
if
(
!
PyArg_Parse
(
v
,
"(O(ziiz))"
,
&
message
,
&
filename
,
&
lineno
,
&
offset
,
&
text
))
&
filename
,
&
lineno
,
&
offset
,
&
text
))
err_c
lear
();
PyErr_C
lear
();
else
{
else
{
char
buf
[
10
];
char
buf
[
10
];
writes
tring
(
" File
\"
"
,
f
);
PyFile_WriteS
tring
(
" File
\"
"
,
f
);
if
(
filename
==
NULL
)
if
(
filename
==
NULL
)
writes
tring
(
"<string>"
,
f
);
PyFile_WriteS
tring
(
"<string>"
,
f
);
else
else
writes
tring
(
filename
,
f
);
PyFile_WriteS
tring
(
filename
,
f
);
writes
tring
(
"
\"
, line "
,
f
);
PyFile_WriteS
tring
(
"
\"
, line "
,
f
);
sprintf
(
buf
,
"%d"
,
lineno
);
sprintf
(
buf
,
"%d"
,
lineno
);
writes
tring
(
buf
,
f
);
PyFile_WriteS
tring
(
buf
,
f
);
writes
tring
(
"
\n
"
,
f
);
PyFile_WriteS
tring
(
"
\n
"
,
f
);
if
(
text
!=
NULL
)
{
if
(
text
!=
NULL
)
{
char
*
nl
;
char
*
nl
;
if
(
offset
>
0
&&
if
(
offset
>
0
&&
...
@@ -349,159 +347,162 @@ print_error()
...
@@ -349,159 +347,162 @@ print_error()
text
++
;
text
++
;
offset
--
;
offset
--
;
}
}
writes
tring
(
" "
,
f
);
PyFile_WriteS
tring
(
" "
,
f
);
writes
tring
(
text
,
f
);
PyFile_WriteS
tring
(
text
,
f
);
if
(
*
text
==
'\0'
||
if
(
*
text
==
'\0'
||
text
[
strlen
(
text
)
-
1
]
!=
'\n'
)
text
[
strlen
(
text
)
-
1
]
!=
'\n'
)
writes
tring
(
"
\n
"
,
f
);
PyFile_WriteS
tring
(
"
\n
"
,
f
);
writes
tring
(
" "
,
f
);
PyFile_WriteS
tring
(
" "
,
f
);
offset
--
;
offset
--
;
while
(
offset
>
0
)
{
while
(
offset
>
0
)
{
writes
tring
(
" "
,
f
);
PyFile_WriteS
tring
(
" "
,
f
);
offset
--
;
offset
--
;
}
}
writes
tring
(
"^
\n
"
,
f
);
PyFile_WriteS
tring
(
"^
\n
"
,
f
);
}
}
INCREF
(
message
);
Py_
INCREF
(
message
);
DECREF
(
v
);
Py_
DECREF
(
v
);
v
=
message
;
v
=
message
;
}
}
}
}
if
(
is_classobject
(
exception
))
{
if
(
PyClass_Check
(
exception
))
{
object
*
className
=
((
classobject
*
)
exception
)
->
cl_name
;
PyObject
*
className
=
((
PyClassObject
*
)
exception
)
->
cl_name
;
if
(
className
==
NULL
)
if
(
className
==
NULL
)
writes
tring
(
"<unknown>"
,
f
);
PyFile_WriteS
tring
(
"<unknown>"
,
f
);
else
{
else
{
if
(
writeobject
(
className
,
f
,
PRINT_RAW
)
!=
0
)
if
(
PyFile_WriteObject
(
className
,
f
,
err_clear
();
Py_PRINT_RAW
)
!=
0
)
PyErr_Clear
();
}
}
}
else
{
}
else
{
if
(
writeobject
(
exception
,
f
,
PRINT_RAW
)
!=
0
)
if
(
PyFile_WriteObject
(
exception
,
f
,
err_clear
();
Py_PRINT_RAW
)
!=
0
)
PyErr_Clear
();
}
}
if
(
v
!=
NULL
&&
v
!=
None
)
{
if
(
v
!=
NULL
&&
v
!=
Py_
None
)
{
writes
tring
(
": "
,
f
);
PyFile_WriteS
tring
(
": "
,
f
);
if
(
writeobject
(
v
,
f
,
PRINT_RAW
)
!=
0
)
if
(
PyFile_WriteObject
(
v
,
f
,
Py_
PRINT_RAW
)
!=
0
)
err_c
lear
();
PyErr_C
lear
();
}
}
writes
tring
(
"
\n
"
,
f
);
PyFile_WriteS
tring
(
"
\n
"
,
f
);
}
}
XDECREF
(
exception
);
Py_
XDECREF
(
exception
);
XDECREF
(
v
);
Py_
XDECREF
(
v
);
XDECREF
(
tb
);
Py_
XDECREF
(
tb
);
}
}
o
bject
*
PyO
bject
*
run_s
tring
(
str
,
start
,
globals
,
locals
)
PyRun_S
tring
(
str
,
start
,
globals
,
locals
)
char
*
str
;
char
*
str
;
int
start
;
int
start
;
o
bject
*
globals
,
*
locals
;
PyO
bject
*
globals
,
*
locals
;
{
{
return
run_err_node
(
parse_s
tring
(
str
,
start
),
return
run_err_node
(
PyParser_SimpleParseS
tring
(
str
,
start
),
"<string>"
,
globals
,
locals
);
"<string>"
,
globals
,
locals
);
}
}
o
bject
*
PyO
bject
*
run_f
ile
(
fp
,
filename
,
start
,
globals
,
locals
)
PyRun_F
ile
(
fp
,
filename
,
start
,
globals
,
locals
)
FILE
*
fp
;
FILE
*
fp
;
char
*
filename
;
char
*
filename
;
int
start
;
int
start
;
o
bject
*
globals
,
*
locals
;
PyO
bject
*
globals
,
*
locals
;
{
{
return
run_err_node
(
parse_f
ile
(
fp
,
filename
,
start
),
return
run_err_node
(
PyParser_SimpleParseF
ile
(
fp
,
filename
,
start
),
filename
,
globals
,
locals
);
filename
,
globals
,
locals
);
}
}
static
o
bject
*
static
PyO
bject
*
run_err_node
(
n
,
filename
,
globals
,
locals
)
run_err_node
(
n
,
filename
,
globals
,
locals
)
node
*
n
;
node
*
n
;
char
*
filename
;
char
*
filename
;
o
bject
*
globals
,
*
locals
;
PyO
bject
*
globals
,
*
locals
;
{
{
if
(
n
==
NULL
)
if
(
n
==
NULL
)
return
NULL
;
return
NULL
;
return
run_node
(
n
,
filename
,
globals
,
locals
);
return
run_node
(
n
,
filename
,
globals
,
locals
);
}
}
static
o
bject
*
static
PyO
bject
*
run_node
(
n
,
filename
,
globals
,
locals
)
run_node
(
n
,
filename
,
globals
,
locals
)
node
*
n
;
node
*
n
;
char
*
filename
;
char
*
filename
;
o
bject
*
globals
,
*
locals
;
PyO
bject
*
globals
,
*
locals
;
{
{
codeo
bject
*
co
;
PyCodeO
bject
*
co
;
o
bject
*
v
;
PyO
bject
*
v
;
co
=
c
ompile
(
n
,
filename
);
co
=
PyNode_C
ompile
(
n
,
filename
);
freet
ree
(
n
);
PyNode_F
ree
(
n
);
if
(
co
==
NULL
)
if
(
co
==
NULL
)
return
NULL
;
return
NULL
;
v
=
eval_c
ode
(
co
,
globals
,
locals
);
v
=
PyEval_EvalC
ode
(
co
,
globals
,
locals
);
DECREF
(
co
);
Py_
DECREF
(
co
);
return
v
;
return
v
;
}
}
static
o
bject
*
static
PyO
bject
*
run_pyc_file
(
fp
,
filename
,
globals
,
locals
)
run_pyc_file
(
fp
,
filename
,
globals
,
locals
)
FILE
*
fp
;
FILE
*
fp
;
char
*
filename
;
char
*
filename
;
o
bject
*
globals
,
*
locals
;
PyO
bject
*
globals
,
*
locals
;
{
{
codeo
bject
*
co
;
PyCodeO
bject
*
co
;
o
bject
*
v
;
PyO
bject
*
v
;
long
magic
;
long
magic
;
long
get_pyc_magic
();
long
PyImport_GetMagicNumber
();
magic
=
rd_long
(
fp
);
magic
=
PyMarshal_ReadLongFromFile
(
fp
);
if
(
magic
!=
get_pyc_magic
())
{
if
(
magic
!=
PyImport_GetMagicNumber
())
{
err_setstr
(
RuntimeError
,
PyErr_SetString
(
PyExc_
RuntimeError
,
"Bad magic number in .pyc file"
);
"Bad magic number in .pyc file"
);
return
NULL
;
return
NULL
;
}
}
(
void
)
rd_long
(
fp
);
(
void
)
PyMarshal_ReadLongFromFile
(
fp
);
v
=
rd_object
(
fp
);
v
=
PyMarshal_ReadObjectFromFile
(
fp
);
fclose
(
fp
);
fclose
(
fp
);
if
(
v
==
NULL
||
!
is_codeobject
(
v
))
{
if
(
v
==
NULL
||
!
PyCode_Check
(
v
))
{
XDECREF
(
v
);
Py_
XDECREF
(
v
);
err_setstr
(
RuntimeError
,
PyErr_SetString
(
PyExc_
RuntimeError
,
"Bad code object in .pyc file"
);
"Bad code object in .pyc file"
);
return
NULL
;
return
NULL
;
}
}
co
=
(
codeo
bject
*
)
v
;
co
=
(
PyCodeO
bject
*
)
v
;
v
=
eval_c
ode
(
co
,
globals
,
locals
);
v
=
PyEval_EvalC
ode
(
co
,
globals
,
locals
);
DECREF
(
co
);
Py_
DECREF
(
co
);
return
v
;
return
v
;
}
}
o
bject
*
PyO
bject
*
compile_s
tring
(
str
,
filename
,
start
)
Py_CompileS
tring
(
str
,
filename
,
start
)
char
*
str
;
char
*
str
;
char
*
filename
;
char
*
filename
;
int
start
;
int
start
;
{
{
node
*
n
;
node
*
n
;
codeo
bject
*
co
;
PyCodeO
bject
*
co
;
n
=
parse_s
tring
(
str
,
start
);
n
=
PyParser_SimpleParseS
tring
(
str
,
start
);
if
(
n
==
NULL
)
if
(
n
==
NULL
)
return
NULL
;
return
NULL
;
co
=
c
ompile
(
n
,
filename
);
co
=
PyNode_C
ompile
(
n
,
filename
);
freet
ree
(
n
);
PyNode_F
ree
(
n
);
return
(
o
bject
*
)
co
;
return
(
PyO
bject
*
)
co
;
}
}
/* Simplified interface to parsefile -- return node or set exception */
/* Simplified interface to parsefile -- return node or set exception */
node
*
node
*
parse_f
ile
(
fp
,
filename
,
start
)
PyParser_SimpleParseF
ile
(
fp
,
filename
,
start
)
FILE
*
fp
;
FILE
*
fp
;
char
*
filename
;
char
*
filename
;
int
start
;
int
start
;
{
{
node
*
n
;
node
*
n
;
perrdetail
err
;
perrdetail
err
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
n
=
parsefile
(
fp
,
filename
,
&
gram
,
start
,
n
=
PyParser_ParseFile
(
fp
,
filename
,
&
_PyParser_Grammar
,
start
,
(
char
*
)
0
,
(
char
*
)
0
,
&
err
);
(
char
*
)
0
,
(
char
*
)
0
,
&
err
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
n
==
NULL
)
if
(
n
==
NULL
)
err_input
(
&
err
);
err_input
(
&
err
);
return
n
;
return
n
;
...
@@ -510,13 +511,13 @@ parse_file(fp, filename, start)
...
@@ -510,13 +511,13 @@ parse_file(fp, filename, start)
/* Simplified interface to parsestring -- return node or set exception */
/* Simplified interface to parsestring -- return node or set exception */
node
*
node
*
parse_s
tring
(
str
,
start
)
PyParser_SimpleParseS
tring
(
str
,
start
)
char
*
str
;
char
*
str
;
int
start
;
int
start
;
{
{
node
*
n
;
node
*
n
;
perrdetail
err
;
perrdetail
err
;
n
=
parsestring
(
str
,
&
gram
,
start
,
&
err
);
n
=
PyParser_ParseString
(
str
,
&
_PyParser_Grammar
,
start
,
&
err
);
if
(
n
==
NULL
)
if
(
n
==
NULL
)
err_input
(
&
err
);
err_input
(
&
err
);
return
n
;
return
n
;
...
@@ -528,9 +529,9 @@ static void
...
@@ -528,9 +529,9 @@ static void
err_input
(
err
)
err_input
(
err
)
perrdetail
*
err
;
perrdetail
*
err
;
{
{
o
bject
*
v
,
*
w
;
PyO
bject
*
v
,
*
w
;
char
*
msg
=
NULL
;
char
*
msg
=
NULL
;
v
=
mkv
alue
(
"(ziiz)"
,
err
->
filename
,
v
=
Py_BuildV
alue
(
"(ziiz)"
,
err
->
filename
,
err
->
lineno
,
err
->
offset
,
err
->
text
);
err
->
lineno
,
err
->
offset
,
err
->
text
);
if
(
err
->
text
!=
NULL
)
{
if
(
err
->
text
!=
NULL
)
{
free
(
err
->
text
);
free
(
err
->
text
);
...
@@ -545,10 +546,10 @@ err_input(err)
...
@@ -545,10 +546,10 @@ err_input(err)
break
;
break
;
case
E_INTR
:
case
E_INTR
:
err_set
(
KeyboardInterrupt
);
PyErr_SetNone
(
PyExc_
KeyboardInterrupt
);
return
;
return
;
case
E_NOMEM
:
case
E_NOMEM
:
err_nomem
();
PyErr_NoMemory
();
return
;
return
;
case
E_EOF
:
case
E_EOF
:
msg
=
"unexpected EOF while parsing"
;
msg
=
"unexpected EOF while parsing"
;
...
@@ -558,16 +559,16 @@ err_input(err)
...
@@ -558,16 +559,16 @@ err_input(err)
msg
=
"unknown parsing error"
;
msg
=
"unknown parsing error"
;
break
;
break
;
}
}
w
=
mkv
alue
(
"(sO)"
,
msg
,
v
);
w
=
Py_BuildV
alue
(
"(sO)"
,
msg
,
v
);
XDECREF
(
v
);
Py_
XDECREF
(
v
);
err_setval
(
SyntaxError
,
w
);
PyErr_SetObject
(
PyExc_
SyntaxError
,
w
);
XDECREF
(
w
);
Py_
XDECREF
(
w
);
}
}
/* Print fatal error message and abort */
/* Print fatal error message and abort */
void
void
fatal
(
msg
)
Py_FatalError
(
msg
)
char
*
msg
;
char
*
msg
;
{
{
fprintf
(
stderr
,
"Fatal Python error: %s
\n
"
,
msg
);
fprintf
(
stderr
,
"Fatal Python error: %s
\n
"
,
msg
);
...
@@ -586,7 +587,7 @@ fatal(msg)
...
@@ -586,7 +587,7 @@ fatal(msg)
#ifdef WITH_THREAD
#ifdef WITH_THREAD
#include "thread.h"
#include "thread.h"
int
threads_s
tarted
=
0
;
/* Set by threadmodule.c and maybe others */
int
_PyThread_S
tarted
=
0
;
/* Set by threadmodule.c and maybe others */
#endif
#endif
#define NEXITFUNCS 32
#define NEXITFUNCS 32
...
@@ -594,7 +595,7 @@ static void (*exitfuncs[NEXITFUNCS])();
...
@@ -594,7 +595,7 @@ static void (*exitfuncs[NEXITFUNCS])();
static
int
nexitfuncs
=
0
;
static
int
nexitfuncs
=
0
;
int
Py_AtExit
(
func
)
int
Py_AtExit
(
func
)
void
(
*
func
)
PROTO
((
void
));
void
(
*
func
)
P
y_P
ROTO
((
void
));
{
{
if
(
nexitfuncs
>=
NEXITFUNCS
)
if
(
nexitfuncs
>=
NEXITFUNCS
)
return
-
1
;
return
-
1
;
...
@@ -603,37 +604,37 @@ int Py_AtExit(func)
...
@@ -603,37 +604,37 @@ int Py_AtExit(func)
}
}
void
void
c
leanup
()
Py_C
leanup
()
{
{
object
*
exitfunc
=
sysge
t
(
"exitfunc"
);
PyObject
*
exitfunc
=
PySys_GetObjec
t
(
"exitfunc"
);
if
(
exitfunc
)
{
if
(
exitfunc
)
{
o
bject
*
res
;
PyO
bject
*
res
;
INCREF
(
exitfunc
);
Py_
INCREF
(
exitfunc
);
sysset
(
"exitfunc"
,
(
o
bject
*
)
NULL
);
PySys_SetObject
(
"exitfunc"
,
(
PyO
bject
*
)
NULL
);
res
=
call_object
(
exitfunc
,
(
o
bject
*
)
NULL
);
res
=
PyEval_CallObject
(
exitfunc
,
(
PyO
bject
*
)
NULL
);
if
(
res
==
NULL
)
{
if
(
res
==
NULL
)
{
fprintf
(
stderr
,
"Error in sys.exitfunc:
\n
"
);
fprintf
(
stderr
,
"Error in sys.exitfunc:
\n
"
);
print_error
();
PyErr_Print
();
}
}
DECREF
(
exitfunc
);
Py_
DECREF
(
exitfunc
);
}
}
flushl
ine
();
Py_FlushL
ine
();
while
(
nexitfuncs
>
0
)
while
(
nexitfuncs
>
0
)
(
*
exitfuncs
[
--
nexitfuncs
])();
(
*
exitfuncs
[
--
nexitfuncs
])();
}
}
#ifdef COUNT_ALLOCS
#ifdef COUNT_ALLOCS
extern
void
dump_counts
PROTO
((
void
));
extern
void
dump_counts
P
y_P
ROTO
((
void
));
#endif
#endif
void
void
goaway
(
sts
)
Py_Exit
(
sts
)
int
sts
;
int
sts
;
{
{
c
leanup
();
Py_C
leanup
();
#ifdef COUNT_ALLOCS
#ifdef COUNT_ALLOCS
dump_counts
();
dump_counts
();
...
@@ -645,14 +646,14 @@ goaway(sts)
...
@@ -645,14 +646,14 @@ goaway(sts)
cleanup actions usually done (these are mostly for
cleanup actions usually done (these are mostly for
debugging anyway). */
debugging anyway). */
(
void
)
save_t
hread
();
(
void
)
PyEval_SaveT
hread
();
#ifndef NO_EXIT_PROG
#ifndef NO_EXIT_PROG
if
(
threads_s
tarted
)
if
(
_PyThread_S
tarted
)
_exit_prog
(
sts
);
_exit_prog
(
sts
);
else
else
exit_prog
(
sts
);
exit_prog
(
sts
);
#else
/* !NO_EXIT_PROG */
#else
/* !NO_EXIT_PROG */
if
(
threads_s
tarted
)
if
(
_PyThread_S
tarted
)
_exit
(
sts
);
_exit
(
sts
);
else
else
exit
(
sts
);
exit
(
sts
);
...
@@ -660,16 +661,16 @@ goaway(sts)
...
@@ -660,16 +661,16 @@ goaway(sts)
#else
/* WITH_THREAD */
#else
/* WITH_THREAD */
doneimport
();
PyImport_Cleanup
();
err_c
lear
();
PyErr_C
lear
();
#ifdef Py_REF_DEBUG
#ifdef Py_REF_DEBUG
fprintf
(
stderr
,
"[%ld refs]
\n
"
,
_Py_RefTotal
);
fprintf
(
stderr
,
"[%ld refs]
\n
"
,
_Py_RefTotal
);
#endif
#endif
#ifdef Py_TRACE_REFS
#ifdef Py_TRACE_REFS
if
(
askyesn
o
(
"Print left references?"
))
{
if
(
_Py_AskYesN
o
(
"Print left references?"
))
{
_Py_PrintReferences
(
stderr
);
_Py_PrintReferences
(
stderr
);
}
}
#endif
/* Py_TRACE_REFS */
#endif
/* Py_TRACE_REFS */
...
@@ -689,7 +690,7 @@ sighandler(sig)
...
@@ -689,7 +690,7 @@ sighandler(sig)
int
sig
;
int
sig
;
{
{
signal
(
sig
,
SIG_DFL
);
/* Don't catch recursive signals */
signal
(
sig
,
SIG_DFL
);
/* Don't catch recursive signals */
c
leanup
();
/* Do essential clean-up */
Py_C
leanup
();
/* Do essential clean-up */
#ifdef HAVE_GETPID
#ifdef HAVE_GETPID
kill
(
getpid
(),
sig
);
/* Pretend the signal killed us */
kill
(
getpid
(),
sig
);
/* Pretend the signal killed us */
#else
#else
...
@@ -722,14 +723,14 @@ initsigs()
...
@@ -722,14 +723,14 @@ initsigs()
signal
(
SIGTERM
,
t
);
signal
(
SIGTERM
,
t
);
#endif
#endif
#endif
/* HAVE_SIGNAL_H */
#endif
/* HAVE_SIGNAL_H */
initintr
();
/* May imply initsignal() */
PyOS_InitInterrupts
();
/* May imply initsignal() */
}
}
#ifdef Py_TRACE_REFS
#ifdef Py_TRACE_REFS
/* Ask a yes/no question */
/* Ask a yes/no question */
int
int
askyesn
o
(
prompt
)
_Py_AskYesN
o
(
prompt
)
char
*
prompt
;
char
*
prompt
;
{
{
char
buf
[
256
];
char
buf
[
256
];
...
...
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