-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpywrap.cc
executable file
·53 lines (48 loc) · 1.17 KB
/
pywrap.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#if defined (_WIN32)
#include <windows.h>
#include <math.h>
#endif
#include <string>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <Python.h>
int main(int argc, char* argv[]){
#if PY_MAJOR_VERSION > 2
#if PY_MINOR_VERSION > 7
PyStatus status;
PyPreConfig preconfig;
PyPreConfig_InitPythonConfig(&preconfig);
preconfig.utf8_mode = 1;
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
#endif
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); /* optional but recommended */
wchar_t **wargs = new wchar_t*[argc];
for(int i=0;i<argc;i++){
wargs[i] = Py_DecodeLocale(argv[i], NULL);
}
Py_Initialize();
int err = Py_Main(argc,wargs);
if (Py_FinalizeEx() < 0) {
exit(120);
}
PyMem_RawFree(program);
for(int i=0;i<argc;i++){
PyMem_RawFree(wargs[i]);
}
return err;
#else
Py_Initialize();
int err = Py_Main(argc,argv);
Py_Finalize();
return err;
#endif
}