-
Notifications
You must be signed in to change notification settings - Fork 56
Add a new --mode=python by using the standard Python interpreter entry point #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Py_BytesMain is the stable API to enter the standard interpreter from an embedding executable: https://docs.python.org/3.10/c-api/veryhigh.html#c.Py_BytesMain Create the new class ProcessInfo and the member datum CommandLineInfo. CommandLineInfo provides the flags processed from the command line arguments to provide information for the execution mode.
|
|
||
| if (clinfo.python_main()) | ||
| { | ||
| ret = Py_BytesMain(clinfo.python_main_argc(), clinfo.python_main_argv_ptr()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Py_BytesMain() finalizes the interpreter when returning.
| modmesh::python::Interpreter::instance().setup_process(argc, argv); | ||
| modmesh::python::Interpreter::instance().finalize(); | ||
| return 0; | ||
| return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return the error code.
| #include <stdexcept> | ||
| #include <array> | ||
| #include <vector> | ||
| #include <algorithm> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For std::copy_n.
| Interpreter & setup_process(int argc, char ** argv); | ||
| Interpreter & setup_process(); | ||
|
|
||
| int enter_main(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the "main" an inverse wrapper to call the Python entry function from C++.
| for (int i = 0; i < argc; ++i) | ||
| { | ||
| std::string const & arg = m_populated_argv[i]; | ||
| if ("--mode=python" == arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove --mode=python from the command-line argument for Py_BytesMain.
|
Take command: Interactive mode: Run module: |
|
This PR makes #103 more complete. |
|
The new |
Use
Py_BytesMainfor the "python" mode of viewer.Py_BytesMainis the stable API to enter the standard interpreter from an embedding executable: https://docs.python.org/3.10/c-api/veryhigh.html#c.Py_BytesMainCreate the new class ProcessInfo and the member datum CommandLineInfo. CommandLineInfo provides the flags processed from the command line arguments to provide information for the execution mode.