File: test_python.cc

package info (click to toggle)
gnucap-python 0.0.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,672 kB
  • sloc: python: 7,873; sh: 4,384; cpp: 1,786; makefile: 252
file content (49 lines) | stat: -rw-r--r-- 987 bytes parent folder | download
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
#include <Python.h>
#include <string>

#if PY_MAJOR_VERSION >= 3
#define IS_PY3K
#endif

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
int main( int argc, char**argv)
{
  std::string file_name("comp.py");
//  char *argv[] = {};
  FILE *fp;
  
  fp = fopen(file_name.c_str(), "r");
  
  if(fp == NULL) {
  }else{
  }
  

//  huh?! why not link?
  //  dlopen(PYTHON_SO, RTLD_NOW|RTLD_GLOBAL);
    Py_Initialize();
#ifdef IS_PY3K
	 wchar_t **argv_w;
	 argv_w = (wchar_t**) malloc((argc)* sizeof(wchar_t**));

	for (int i = 0; i < argc; ++i) {
	 argv_w[i] = Py_DecodeLocale(argv[i], NULL);
	}

    PySys_SetArgv(0, argv_w);

	for (int i = 0; i < argc; ++i) {
	  PyMem_RawFree(argv_w[i]);
	}
#else
    PySys_SetArgv(0, argv);
#endif
    
    // Call init function of SWIG _gnucap module
 //   init_gnucap();

//    python_loaded = 1;

  PyRun_SimpleFile(fp, file_name.c_str());
}