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