Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
4350d7f2
Commit
4350d7f2
authored
Feb 17, 2011
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow embed option to take function name.
parent
4e6da5ac
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
37 deletions
+59
-37
Cython/Compiler/CmdLine.py
Cython/Compiler/CmdLine.py
+7
-3
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+49
-31
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+3
-3
No files found.
Cython/Compiler/CmdLine.py
View file @
4350d7f2
...
@@ -34,7 +34,7 @@ Options:
...
@@ -34,7 +34,7 @@ Options:
-a, --annotate Produce a colorized HTML version of the source.
-a, --annotate Produce a colorized HTML version of the source.
--line-directives Produce #line directives pointing to the .pyx source
--line-directives Produce #line directives pointing to the .pyx source
--cplus Output a C++ rather than C file.
--cplus Output a C++ rather than C file.
--embed
Generate a main() function that embeds the Python interpreter.
--embed
[=<method_name>]
Generate a main() function that embeds the Python interpreter.
-2 Compile based on Python-2 syntax and code semantics.
-2 Compile based on Python-2 syntax and code semantics.
-3 Compile based on Python-3 syntax and code semantics.
-3 Compile based on Python-3 syntax and code semantics.
--fast-fail Abort the compilation on the first error
--fast-fail Abort the compilation on the first error
...
@@ -84,8 +84,12 @@ def parse_command_line(args):
...
@@ -84,8 +84,12 @@ def parse_command_line(args):
options
.
use_listing_file
=
1
options
.
use_listing_file
=
1
elif
option
in
(
"-+"
,
"--cplus"
):
elif
option
in
(
"-+"
,
"--cplus"
):
options
.
cplus
=
1
options
.
cplus
=
1
elif
option
==
"--embed"
:
elif
option
.
startswith
(
"--embed"
):
Options
.
embed
=
True
ix
=
option
.
find
(
'='
)
if
ix
==
-
1
:
Options
.
embed
=
"main"
else
:
Options
.
embed
=
option
[
ix
+
1
:]
elif
option
.
startswith
(
"-I"
):
elif
option
.
startswith
(
"-I"
):
options
.
include_path
.
append
(
get_param
(
option
))
options
.
include_path
.
append
(
get_param
(
option
))
elif
option
==
"--include-dir"
:
elif
option
==
"--include-dir"
:
...
...
Cython/Compiler/ModuleNode.py
View file @
4350d7f2
...
@@ -1897,7 +1897,16 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1897,7 +1897,16 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def
generate_main_method
(
self
,
env
,
code
):
def
generate_main_method
(
self
,
env
,
code
):
module_is_main
=
"%s%s"
%
(
Naming
.
module_is_main
,
self
.
full_module_name
.
replace
(
'.'
,
'__'
))
module_is_main
=
"%s%s"
%
(
Naming
.
module_is_main
,
self
.
full_module_name
.
replace
(
'.'
,
'__'
))
code
.
globalstate
.
use_utility_code
(
main_method
.
specialize
(
module_name
=
env
.
module_name
,
module_is_main
=
module_is_main
))
if
Options
.
embed
==
"main"
:
wmain
=
"wmain"
else
:
wmain
=
Options
.
embed
code
.
globalstate
.
use_utility_code
(
main_method
.
specialize
(
module_name
=
env
.
module_name
,
module_is_main
=
module_is_main
,
main_method
=
Options
.
embed
,
wmain_method
=
wmain
))
def
generate_pymoduledef_struct
(
self
,
env
,
code
):
def
generate_pymoduledef_struct
(
self
,
env
,
code
):
if
env
.
doc
:
if
env
.
doc
:
...
@@ -2646,9 +2655,9 @@ impl = """
...
@@ -2646,9 +2655,9 @@ impl = """
#endif
#endif
#if PY_MAJOR_VERSION < 3
#if PY_MAJOR_VERSION < 3
int
main
(int argc, char** argv) {
int
%(main_method)s
(int argc, char** argv) {
#elif defined(WIN32) || defined(MS_WINDOWS)
#elif defined(WIN32) || defined(MS_WINDOWS)
int
wmain
(int argc, wchar_t **argv) {
int
%(wmain_method)s
(int argc, wchar_t **argv) {
#else
#else
static int __Pyx_main(int argc, wchar_t **argv) {
static int __Pyx_main(int argc, wchar_t **argv) {
#endif
#endif
...
@@ -2665,9 +2674,13 @@ static int __Pyx_main(int argc, wchar_t **argv) {
...
@@ -2665,9 +2674,13 @@ static int __Pyx_main(int argc, wchar_t **argv) {
m = fpgetmask();
m = fpgetmask();
fpsetmask(m & ~FP_X_OFL);
fpsetmask(m & ~FP_X_OFL);
#endif
#endif
if (argc) {
Py_SetProgramName(argv[0]);
Py_SetProgramName(argv[0]);
}
Py_Initialize();
Py_Initialize();
if (argc) {
PySys_SetArgv(argc, argv);
PySys_SetArgv(argc, argv);
}
%(module_is_main)s = 1;
%(module_is_main)s = 1;
#if PY_MAJOR_VERSION < 3
#if PY_MAJOR_VERSION < 3
init%(module_name)s();
init%(module_name)s();
...
@@ -2794,8 +2807,12 @@ oom:
...
@@ -2794,8 +2807,12 @@ oom:
}
}
int
int
main
(int argc, char **argv)
%(main_method)s
(int argc, char **argv)
{
{
if (!argc) {
return __Pyx_main(0, NULL);
}
else {
wchar_t **argv_copy = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
/* We need a second copies, as Python might modify the first one. */
/* We need a second copies, as Python might modify the first one. */
wchar_t **argv_copy2 = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy2 = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
...
@@ -2821,6 +2838,7 @@ main(int argc, char **argv)
...
@@ -2821,6 +2838,7 @@ main(int argc, char **argv)
free(argv_copy);
free(argv_copy);
free(argv_copy2);
free(argv_copy2);
return res;
return res;
}
}
}
#endif
#endif
"""
)
"""
)
...
...
Cython/Compiler/Options.py
View file @
4350d7f2
...
@@ -44,9 +44,9 @@ lookup_module_cpdef = 0
...
@@ -44,9 +44,9 @@ lookup_module_cpdef = 0
init_local_none
=
1
init_local_none
=
1
# Whether or not to embed the Python interpreter, for use in making a
# Whether or not to embed the Python interpreter, for use in making a
# standalone executable
. This will provide a main() method which simply
# standalone executable
or calling from external libraries.
# executes the body of this module.
#
This will provide a method which simply
executes the body of this module.
embed
=
Fals
e
embed
=
Non
e
# Disables function redefinition, allowing all functions to be declared at
# Disables function redefinition, allowing all functions to be declared at
# module creation time. For legacy code only.
# module creation time. For legacy code only.
...
...
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