source: git/Singular/dyn_modules/python/python_module.cc @ a3f0fea

spielwiese
Last change on this file since a3f0fea was a3f0fea, checked in by Reimer Behrends <behrends@…>, 5 years ago
Modify variable declarions for pSingular.
  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "kernel/mod2.h"
2#ifdef HAVE_PYTHON_MOD
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <ctype.h>
7
8#include <unistd.h>
9#include <sys/stat.h>
10#include <boost/python.hpp>
11#include <Python.h>
12#include "Singular/tok.h"
13#include "kernel/structs.h"
14#include "Singular/mod_lib.h"
15#include "Singular/ipid.h"
16
17#include "Singular/locals.h"
18
19#include "omalloc/omalloc.h"
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <time.h>
25#include <Python.h>
26#include "wrapper.h"
27
28static BOOLEAN mod_python(leftv __res, leftv __h)
29{
30  leftv __v = __h, __v_save;
31  int __tok = NONE, __index = 0;
32  sleftv __sa; leftv __za = &__sa;
33  char * a;
34  if(__v==NULL) goto mod_python_error;
35  __tok = __v->Typ();
36  if((__index=iiTestConvert(__tok, STRING_CMD))==0)
37     goto mod_python_error;
38  __v_save = __v->next;
39  __v->next = NULL;
40  if(iiConvert(__tok, STRING_CMD, __index, __v, __za))
41     goto mod_python_error;
42  __v = __v_save;
43  a = (char *)__za->Data();
44  if(__v!=NULL) { __tok = __v->Typ(); goto mod_python_error; }
45
46  PyRun_SimpleString(a);
47  __res->data = NULL;
48  __res->rtyp = END_RING;
49  return FALSE;
50
51  mod_python_error:
52    Werror("python(`%s`) is not supported", Tok2Cmdname(__tok));
53    Werror("expected python('string')");
54    return TRUE;
55}
56//int mod_init(
57//  int (*iiAddCproc)(char *libname, char *procname, BOOLEAN pstatic,
58//              BOOLEAN(*func)(leftv res, leftv v))
59//  )
60extern "C" int SI_MOD_INIT(python_module)(SModulFunctions* psModulFunctions)
61{
62  VAR char *py=getenv("PYTHONPATH");
63  VAR char buf[1024];
64  if (py!=NULL)
65  {
66    strcpy(buf,py);
67    strcat(buf,":");
68    strcat(buf,feResource('s',FALSE));
69  }
70  else
71    strcpy(buf,feResource('s',FALSE));
72  Print("setting PYTHONAPTH to %s\n",buf);
73  setenv("PYTHONPATH",buf,1);
74
75  Py_Initialize();
76  PyRun_SimpleString("from sys import path\n\
77path.insert(0,'.')\n");
78  initSingular();
79  init_Singular();
80
81  psModulFunctions->iiAddCproc(currPack->libname,"python",FALSE, mod_python);
82  VAR return MAX_TOK;
83}
84#endif
Note: See TracBrowser for help on using the repository browser.