Loading...
Searching...
No Matches
PythonInterpreter Class Reference

This class initializes and finalized the python interpreter. More...

## Public Types

typedef int | id_type

## Public Member Functions

| ~PythonInterpreter ()

## Static Public Member Functions

static void | init (id_type num)
| Initialize unique (singleton) python interpreter instance, and set Singular type identifier.
static id_type | id ()
| Get Singular type identitfier.

## Private Member Functions

| PythonInterpreter ()
| Singleton: Only init() is allowed to construct an instance.
void | start_python ()
void | init_python ()
void | set_python_defaults ()

## Static Private Member Functions

static PythonInterpreter & | instance ()
| Static initialization - safely takes care of destruction on program termination.

## Private Attributes

id_type | m_id
bool | m_owns_python

## Detailed Description

This class initializes and finalized the python interpreter.

It also stores the Singular token number, which is assigned to this type on runtime.

Definition at line 45 of file pyobject.cc.

## Member Typedef Documentation

## id_type

typedef int PythonInterpreter::id_type

Definition at line 47 of file pyobject.cc.

## Constructor & Destructor Documentation

## ~PythonInterpreter()

PythonInterpreter::~PythonInterpreter | ( |  | ) |

inline

Definition at line 49 of file pyobject.cc.

{ if(m_owns_python) Py_Finalize(); }
PythonInterpreter::m_owns_python
bool m_owns_python
Definition pyobject.cc:98

## PythonInterpreter()

PythonInterpreter::PythonInterpreter | ( |  | ) |

inline private

Singleton: Only init() is allowed to construct an instance.

Definition at line 60 of file pyobject.cc.

:
m_id(0), m_owns_python(false) { start_python(); }
PythonInterpreter::m_id
id_type m_id
Definition pyobject.cc:97
PythonInterpreter::start_python
void start_python()
Definition pyobject.cc:71

## Member Function Documentation

## id()

id_type PythonInterpreter::id | ( |  | ) |

inline static

Get Singular type identitfier.

Definition at line 56 of file pyobject.cc.

{ return instance().m_id; }
PythonInterpreter::instance
static PythonInterpreter & instance()
Static initialization - safely takes care of destruction on program termination.
Definition pyobject.cc:65

## init()

void PythonInterpreter::init | ( | id_type | num | ) |

inline static

Initialize unique (singleton) python interpreter instance, and set Singular type identifier.

Definition at line 53 of file pyobject.cc.

{ instance().m_id = num; }
num
CanonicalForm num(const CanonicalForm &f)
Definition canonicalform.h:337

## init_python()

void PythonInterpreter::init_python | ( |  | ) |

inline private

Definition at line 77 of file pyobject.cc.

{
Py_Initialize();
m_owns_python = true;
}

## instance()

PythonInterpreter & PythonInterpreter::instance | ( |  | ) |

inline static private

Static initialization - safely takes care of destruction on program termination.

Definition at line 65 of file pyobject.cc.

{
STATIC_INST_VAR PythonInterpreter init_interpreter;
return init_interpreter;
}
PythonInterpreter::PythonInterpreter
PythonInterpreter()
Singleton: Only init() is allowed to construct an instance.
Definition pyobject.cc:60
STATIC_INST_VAR
#define STATIC_INST_VAR
Definition globaldefs.h:10

## set_python_defaults()

void PythonInterpreter::set_python_defaults | ( |  | ) |

inline private

Definition at line 83 of file pyobject.cc.

{
// Sone python modules needs argc, argv set for some reason
char* argv = (char*)"";
PySys_SetArgv(1, &argv);
PyRun_SimpleString("from sys import path, modules");
PyRun_SimpleString("_SINGULAR_IMPORTED = dict()");
char cmd[MAXPATHLEN + 20];
snprintf(cmd,MAXPATHLEN + 20, "path.insert(0, '%s')", feGetResource('b'));
PyRun_SimpleString(cmd);
PyRun_SimpleString("del path"); // cleanup
}
feGetResource
char * feGetResource(const char id, int warn)
Definition feResource.cc:145
MAXPATHLEN
#define MAXPATHLEN
Definition omRet2Info.c:22

## start_python()

void PythonInterpreter::start_python | ( |  | ) |

inline private

Definition at line 71 of file pyobject.cc.

{
if (!Py_IsInitialized()) init_python();
set_python_defaults();
}
PythonInterpreter::init_python
void init_python()
Definition pyobject.cc:77
PythonInterpreter::set_python_defaults
void set_python_defaults()
Definition pyobject.cc:83

## Field Documentation

## m_id

id_type PythonInterpreter::m_id

private

Definition at line 97 of file pyobject.cc.

## m_owns_python

bool PythonInterpreter::m_owns_python

private

Definition at line 98 of file pyobject.cc.

The documentation for this class was generated from the following file:

- Singular/dyn_modules/pyobject/pyobject.cc