My Project
Loading...
Searching...
No Matches
Functions
python_module.cc File Reference
#include "kernel/mod2.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include "Singular/tok.h"
#include "kernel/structs.h"
#include "Singular/mod_lib.h"
#include "Singular/ipid.h"
#include "Singular/locals.h"
#include "omalloc/omalloc.h"
#include <time.h>
#include <boost/python.hpp>
#include <Python.h>
#include "wrapper.h"

Go to the source code of this file.

Functions

static BOOLEAN mod_python (leftv __res, leftv __h)
 
int SI_MOD_INIT() python_module (SModulFunctions *psModulFunctions)
 

Function Documentation

◆ mod_python()

static BOOLEAN mod_python ( leftv  __res,
leftv  __h 
)
static

Definition at line 25 of file python_module.cc.

26{
27 leftv __v = __h, __v_save;
28 int __tok = NONE, __index = 0;
29 sleftv __sa; leftv __za = &__sa;
30 char * a;
31 if(__v==NULL) goto mod_python_error;
32 __tok = __v->Typ();
33 if((__index=iiTestConvert(__tok, STRING_CMD))==0)
34 goto mod_python_error;
35 __v_save = __v->next;
36 __v->next = NULL;
37 if(iiConvert(__tok, STRING_CMD, __index, __v, __za))
38 goto mod_python_error;
39 __v = __v_save;
40 a = (char *)__za->Data();
41 if(__v!=NULL) { __tok = __v->Typ(); goto mod_python_error; }
42
43 PyRun_SimpleString(a);
44 __res->data = NULL;
45 __res->rtyp = END_RING;
46 return FALSE;
47
48 mod_python_error:
49 Werror("python(`%s`) is not supported", Tok2Cmdname(__tok));
50 Werror("expected python('string')");
51 return TRUE;
52}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int Typ()
Definition: subexpr.cc:1019
int rtyp
Definition: subexpr.h:91
void * Data()
Definition: subexpr.cc:1162
leftv next
Definition: subexpr.h:86
void * data
Definition: subexpr.h:88
int iiTestConvert(int inputType, int outputType)
Definition: gentable.cc:301
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
@ END_RING
Definition: grammar.cc:310
BOOLEAN iiConvert(int inputType, int outputType, int index, leftv input, leftv output, const struct sConvertTypes *dConvertTypes)
Definition: ipconv.cc:435
#define NULL
Definition: omList.c:12
void Werror(const char *fmt,...)
Definition: reporter.cc:189
@ STRING_CMD
Definition: tok.h:185
#define NONE
Definition: tok.h:221

◆ python_module()

int SI_MOD_INIT() python_module ( SModulFunctions psModulFunctions)

Definition at line 57 of file python_module.cc.

58{
59 VAR char *py=getenv("PYTHONPATH");
60 VAR char buf[1024];
61 if (py!=NULL)
62 {
63 strcpy(buf,py);
64 strcat(buf,":");
65 strcat(buf,feResource('s',FALSE));
66 }
67 else
68 strcpy(buf,feResource('s',FALSE));
69 Print("setting PYTHONAPTH to %s\n",buf);
70 setenv("PYTHONPATH",buf,1);
71
72 Py_Initialize();
73 PyRun_SimpleString("from sys import path\n\
74path.insert(0,'.')\n");
75 initSingular();
76 init_Singular();
77
78 psModulFunctions->iiAddCproc(currPack->libname,"python",FALSE, mod_python);
79 return MAX_TOK;
80}
#define Print
Definition: emacs.cc:80
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:236
char * getenv()
#define VAR
Definition: globaldefs.h:5
VAR package currPack
Definition: ipid.cc:57
static BOOLEAN mod_python(leftv __res, leftv __h)
int status int void * buf
Definition: si_signals.h:59
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:70
@ MAX_TOK
Definition: tok.h:218