-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy patheval.c
More file actions
24 lines (22 loc) · 661 Bytes
/
eval.c
File metadata and controls
24 lines (22 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* Adapted from: https://docs.python.org/3.7/extending/embedding.html#very-high-level-embedding
*
* Simply `eval` a Python string in C, don't communicate any values between the two. Not very exciting.
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
int main(int argc, char *argv[]) {
(void)argc;
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program);
Py_Initialize();
PyRun_SimpleString(argv[1]);
if (Py_FinalizeEx() < 0) {
exit(120);
}
PyMem_RawFree(program);
return 0;
}