Changeset 3e7db4 in git for Singular/pyobject_setup.cc
- Timestamp:
- Dec 11, 2012, 7:33:39 PM (11 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
- Children:
- 14e634edb64741be0fbc04c9c89e8523cb0c1cc521dbb4186f3a2c56539d8f92abe1ee9e0fa0ae2c
- Parents:
- dcf88ff0bb046d73a7bde65e033fc58cbb5f4a97c9050082385152a64066f7540914cae34d990a43
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/pyobject_setup.cc
rc90500 r3e7db4 16 16 #include <kernel/mod2.h> 17 17 #include <kernel/febase.h> 18 #include <Singular/blackbox.h> 19 #include <Singular/ipshell.h> 18 20 19 21 /* whether pyobject module is linked statically or dynamically */ 22 23 #ifdef EMBED_PYTHON // Case: we include the pyobject interface in the binary 24 20 25 #ifdef HAVE_PYTHON 26 #include "pyobject.cc" 27 static BOOLEAN pyobject_load() 28 { 29 pyobject_init(iiAddCproc); 30 return FALSE; 31 } 21 32 22 #if defined(HAVE_STATIC) 23 #ifdef HAVE_STATIC_PYTHON 24 #define HAVE_STATIC_PYOBJECT 25 #endif 26 #else 27 #ifdef EMBED_PYTHON 28 #define HAVE_STATIC_PYOBJECT 29 #else 30 #define HAVE_DYNAMIC_PYOBJECT 31 #endif 32 #endif 33 #else // Forced embedding, but no (development version of) python available! 34 static BOOLEAN pyobject_load() { return TRUE; } 33 35 #endif 34 36 35 # ifdef HAVE_STATIC_PYOBJECT // Case: link pyobject interface statically 36 #include "pyobject.cc" 37 void pyobject_setup() { pyobject_init(); } 37 38 # else // Case: pyobject may be loaded from a dynamic module (prefered variant) 39 // Note: we do not need python at compile time. 40 static BOOLEAN pyobject_load() 41 { 42 return jjLOAD("pyobject.so", TRUE); 43 } 44 #endif 38 45 39 46 40 # elif defined(HAVE_DYNAMIC_PYOBJECT) // Case: pyobject is dynamic module (prefered variant)41 47 42 // forward declaration for Singular/iplib.cc 43 void* binary_module_function(const char* lib, const char* func); 44 void pyobject_setup() 48 /// blackbox support - initialization via autoloading 49 void* pyobject_autoload(blackbox* bbx) 45 50 { 46 void* fktn = binary_module_function("pyobject", "mod_init"); 47 if (fktn) (* reinterpret_cast<void (*)()>(fktn) )(); 48 else Werror("python related functions are not available"); 51 assume(bbx != NULL); 52 return (pyobject_load()? NULL: bbx->blackbox_Init(bbx)); 49 53 } 50 54 51 #else // Case: no python 52 void pyobject_setup() { } 55 void pyobject_default_destroy(blackbox *b, void *d) 56 { 57 Werror("Python-based functionality not available!"); 58 } 53 59 54 #endif // HAVE_PYTHON 60 // Setting up an empty blackbox type, which can be filled with pyobject 61 void pyobject_setup() 62 { 63 blackbox *bbx = (blackbox*)omAlloc0(sizeof(blackbox)); 64 bbx->blackbox_Init = pyobject_autoload; 65 bbx->blackbox_destroy = pyobject_default_destroy; 66 setBlackboxStuff(bbx, "pyobject"); 67 } 55 68 69 /// Explicitely load, if not loaded already 70 BOOLEAN pyobject_ensure() { 71 72 int tok = -1; 73 blackbox* bbx = (blackboxIsCmd("pyobject", tok) == ROOT_DECL? 74 getBlackboxStuff(tok): (blackbox*)NULL); 75 if (bbx == NULL) return TRUE; 76 return (bbx->blackbox_Init == pyobject_autoload? pyobject_load(): FALSE); 77 } 78 79 80
Note: See TracChangeset
for help on using the changeset viewer.