diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2019-05-04 15:09:31 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2019-05-07 14:37:24 (GMT) |
commit | 30b873c05d6281b865ba08524bb1b90e0afd1ece (patch) | |
tree | 235ff9a85d3a4e83de7f2b7ad94037d1edcb07eb /Tests/FindPython/display_time.c | |
parent | 37bf503db268c41d5a337265300357c76bda34ea (diff) | |
download | CMake-30b873c05d6281b865ba08524bb1b90e0afd1ece.zip CMake-30b873c05d6281b865ba08524bb1b90e0afd1ece.tar.gz CMake-30b873c05d6281b865ba08524bb1b90e0afd1ece.tar.bz2 |
FindPython*: Manage weak link for Python modules
Add new target Python::Module which take care of platform requirements
for Python module development.
Fixes: #18100
Diffstat (limited to 'Tests/FindPython/display_time.c')
-rw-r--r-- | Tests/FindPython/display_time.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Tests/FindPython/display_time.c b/Tests/FindPython/display_time.c new file mode 100644 index 0000000..0e78434 --- /dev/null +++ b/Tests/FindPython/display_time.c @@ -0,0 +1,36 @@ + +#include <stdio.h> + +#define PY_SSIZE_T_CLEAN +#include <Python.h> + +#include "display_time.h" + +void display_time() +{ +#if defined(PYTHON3) + wchar_t* program = Py_DecodeLocale("display_time", NULL); + if (program == NULL) { + fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); + exit(1); + } + char* cmd = "from time import time,ctime\n" + "print('Today is', ctime(time()))\n"; +#else + char* program = "display_time"; + char* cmd = "from time import time,ctime\n" + "print 'Today is', ctime(time())\n"; +#endif + + Py_SetProgramName(program); /* optional but recommended */ + Py_Initialize(); + PyRun_SimpleString(cmd); +#if defined(PYTHON3) + if (Py_FinalizeEx() < 0) { + exit(120); + } + PyMem_RawFree(program); +#else + Py_Finalize(); +#endif +} |