Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1abcf670
Commit
1abcf670
authored
May 23, 2017
by
Eric Snow
Committed by
GitHub
May 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-22257: Private C-API for core runtime initialization (PEP 432). (#1772)
(patch by Nick Coghlan)
parent
c842efc6
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
224 additions
and
62 deletions
+224
-62
Include/pylifecycle.h
Include/pylifecycle.h
+9
-1
Include/pystate.h
Include/pystate.h
+11
-0
Modules/main.c
Modules/main.c
+19
-16
Python/bootstrap_hash.c
Python/bootstrap_hash.c
+5
-3
Python/pylifecycle.c
Python/pylifecycle.c
+180
-42
No files found.
Include/pylifecycle.h
View file @
1abcf670
...
...
@@ -19,8 +19,14 @@ PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
*/
PyAPI_FUNC
(
int
)
Py_SetStandardStreamEncoding
(
const
char
*
encoding
,
const
char
*
errors
);
/* PEP 432 Multi-phase initialization API (Private while provisional!) */
PyAPI_FUNC
(
void
)
_Py_InitializeCore
(
const
_PyCoreConfig
*
);
PyAPI_FUNC
(
int
)
_Py_IsCoreInitialized
(
void
);
PyAPI_FUNC
(
int
)
_Py_InitializeMainInterpreter
(
int
install_sigs
);
#endif
/* Initialization and finalization */
PyAPI_FUNC
(
void
)
Py_Initialize
(
void
);
PyAPI_FUNC
(
void
)
Py_InitializeEx
(
int
);
#ifndef Py_LIMITED_API
...
...
@@ -29,6 +35,8 @@ PyAPI_FUNC(void) _Py_InitializeEx_Private(int, int);
PyAPI_FUNC
(
void
)
Py_Finalize
(
void
);
PyAPI_FUNC
(
int
)
Py_FinalizeEx
(
void
);
PyAPI_FUNC
(
int
)
Py_IsInitialized
(
void
);
/* Subinterpreter support */
PyAPI_FUNC
(
PyThreadState
*
)
Py_NewInterpreter
(
void
);
PyAPI_FUNC
(
void
)
Py_EndInterpreter
(
PyThreadState
*
);
...
...
@@ -85,7 +93,7 @@ PyAPI_FUNC(void) _PyImportHooks_Init(void);
PyAPI_FUNC
(
int
)
_PyFrame_Init
(
void
);
PyAPI_FUNC
(
int
)
_PyFloat_Init
(
void
);
PyAPI_FUNC
(
int
)
PyByteArray_Init
(
void
);
PyAPI_FUNC
(
void
)
_Py_HashRandomization_Init
(
void
);
PyAPI_FUNC
(
void
)
_Py_HashRandomization_Init
(
_PyCoreConfig
*
core_config
);
#endif
/* Various internal finalizers */
...
...
Include/pystate.h
View file @
1abcf670
...
...
@@ -23,6 +23,16 @@ typedef struct _is PyInterpreterState;
#else
typedef
PyObject
*
(
*
_PyFrameEvalFunction
)(
struct
_frame
*
,
int
);
typedef
struct
{
int
ignore_environment
;
int
use_hash_seed
;
unsigned
long
hash_seed
;
int
_disable_importlib
;
/* Needed by freeze_importlib */
}
_PyCoreConfig
;
#define _PyCoreConfig_INIT {0, -1, 0, 0}
typedef
struct
_is
{
struct
_is
*
next
;
...
...
@@ -42,6 +52,7 @@ typedef struct _is {
int
codecs_initialized
;
int
fscodec_initialized
;
_PyCoreConfig
core_config
;
#ifdef HAVE_DLOPEN
int
dlopenflags
;
#endif
...
...
Modules/main.c
View file @
1abcf670
...
...
@@ -380,19 +380,6 @@ read_command_line(int argc, wchar_t **argv, _Py_CommandLineDetails *cmdline)
wchar_t
*
command
=
NULL
;
wchar_t
*
module
=
NULL
;
int
c
;
char
*
opt
;
opt
=
Py_GETENV
(
"PYTHONMALLOC"
);
if
(
_PyMem_SetupAllocators
(
opt
)
<
0
)
{
fprintf
(
stderr
,
"Error in PYTHONMALLOC: unknown allocator
\"
%s
\"
!
\n
"
,
opt
);
exit
(
1
);
}
// TODO: Move these to core runtime init.
Py_HashRandomizationFlag
=
1
;
_Py_HashRandomization_Init
();
PySys_ResetWarnOptions
();
_PyOS_ResetGetOpt
();
...
...
@@ -584,6 +571,7 @@ Py_Main(int argc, wchar_t **argv)
#endif
int
stdin_is_interactive
=
0
;
_Py_CommandLineDetails
cmdline
=
_Py_CommandLineDetails_INIT
;
_PyCoreConfig
core_config
=
_PyCoreConfig_INIT
;
PyCompilerFlags
cf
;
PyObject
*
main_importer_path
=
NULL
;
...
...
@@ -602,11 +590,23 @@ Py_Main(int argc, wchar_t **argv)
break
;
}
if
(
c
==
'E'
||
c
==
'I'
)
{
Py_IgnoreEnvironmentFlag
++
;
core_config
.
ignore_environment
++
;
break
;
}
}
char
*
pymalloc
=
Py_GETENV
(
"PYTHONMALLOC"
);
if
(
_PyMem_SetupAllocators
(
pymalloc
)
<
0
)
{
fprintf
(
stderr
,
"Error in PYTHONMALLOC: unknown allocator
\"
%s
\"
!
\n
"
,
pymalloc
);
exit
(
1
);
}
/* Initialize the core language runtime */
Py_IgnoreEnvironmentFlag
=
core_config
.
ignore_environment
;
core_config
.
_disable_importlib
=
0
;
_Py_InitializeCore
(
&
core_config
);
/* Reprocess the command line with the language runtime available */
if
(
read_command_line
(
argc
,
argv
,
&
cmdline
))
{
return
usage
(
2
,
argv
[
0
]);
...
...
@@ -680,6 +680,7 @@ Py_Main(int argc, wchar_t **argv)
for
(
i
=
0
;
i
<
PyList_GET_SIZE
(
cmdline
.
warning_options
);
i
++
)
{
PySys_AddWarnOptionUnicode
(
PyList_GET_ITEM
(
cmdline
.
warning_options
,
i
));
}
Py_DECREF
(
cmdline
.
warning_options
);
}
stdin_is_interactive
=
Py_FdIsInteractive
(
stdin
,
(
char
*
)
0
);
...
...
@@ -767,9 +768,10 @@ Py_Main(int argc, wchar_t **argv)
#else
Py_SetProgramName
(
argv
[
0
]);
#endif
Py_Initialize
();
Py_XDECREF
(
cmdline
.
warning_options
);
if
(
_Py_InitializeMainInterpreter
(
1
))
Py_FatalError
(
"Py_Main: Py_InitializeMainInterpreter failed"
);
/* TODO: Move this to _PyRun_PrepareMain */
if
(
!
Py_QuietFlag
&&
(
Py_VerboseFlag
||
(
cmdline
.
command
==
NULL
&&
cmdline
.
filename
==
NULL
&&
cmdline
.
module
==
NULL
&&
stdin_is_interactive
)))
{
...
...
@@ -779,6 +781,7 @@ Py_Main(int argc, wchar_t **argv)
fprintf
(
stderr
,
"%s
\n
"
,
COPYRIGHT
);
}
/* TODO: Move this to _Py_InitializeMainInterpreter */
if
(
cmdline
.
command
!=
NULL
)
{
/* Backup _PyOS_optind and force sys.argv[0] = '-c' */
_PyOS_optind
--
;
...
...
Python/bootstrap_hash.c
View file @
1abcf670
...
...
@@ -599,11 +599,11 @@ init_hash_secret(int use_hash_seed,
}
void
_Py_HashRandomization_Init
(
void
)
_Py_HashRandomization_Init
(
_PyCoreConfig
*
core_config
)
{
char
*
seed_text
;
int
use_hash_seed
=
-
1
;
unsigned
long
hash_seed
;
int
use_hash_seed
=
core_config
->
use_hash_seed
;
unsigned
long
hash_seed
=
core_config
->
hash_seed
;
if
(
use_hash_seed
<
0
)
{
seed_text
=
Py_GETENV
(
"PYTHONHASHSEED"
);
...
...
@@ -611,6 +611,8 @@ _Py_HashRandomization_Init(void)
Py_FatalError
(
"PYTHONHASHSEED must be
\"
random
\"
or an integer "
"in range [0; 4294967295]"
);
}
core_config
->
use_hash_seed
=
use_hash_seed
;
core_config
->
hash_seed
=
hash_seed
;
}
init_hash_secret
(
use_hash_seed
,
hash_seed
);
}
...
...
Python/pylifecycle.c
View file @
1abcf670
This diff is collapsed.
Click to expand it.
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