[1cb879] | 1 | // -*- c++ -*- |
---|
| 2 | //***************************************************************************** |
---|
| 3 | /** @file pyobject_setup.cc |
---|
| 4 | * |
---|
| 5 | * @author Alexander Dreyer |
---|
| 6 | * @date 2010-12-15 |
---|
| 7 | * |
---|
| 8 | * This header file defines the @c blackbox setup operations for the pyobject |
---|
| 9 | * |
---|
| 10 | * @par Copyright: |
---|
| 11 | * (c) 2010 by The Singular Team, see LICENSE file |
---|
| 12 | **/ |
---|
| 13 | //***************************************************************************** |
---|
| 14 | |
---|
[762407] | 15 | #include "config.h" |
---|
[f5b40a] | 16 | #include <kernel/mod2.h> |
---|
[a015f4] | 17 | #include <kernel/febase.h> |
---|
[35a0c12] | 18 | #include <Singular/blackbox.h> |
---|
| 19 | #include <Singular/ipshell.h> |
---|
[1cb879] | 20 | |
---|
[57dcd6] | 21 | #ifdef EMBED_PYTHON |
---|
[51f563] | 22 | #include "pyobject.cc" |
---|
[1cb879] | 23 | #endif |
---|
| 24 | |
---|
[51f563] | 25 | static BOOLEAN pyobject_load() |
---|
| 26 | { |
---|
[6babcbc] | 27 | return jjLOAD("pyobject.so", TRUE); |
---|
[51f563] | 28 | } |
---|
[35a0c12] | 29 | |
---|
| 30 | /// blackbox support - initialization via autoloading |
---|
| 31 | void* pyobject_autoload(blackbox* bbx) |
---|
[1cb879] | 32 | { |
---|
[e87d40] | 33 | assume(bbx != NULL); |
---|
[6b39bc] | 34 | return (pyobject_load() || (bbx->blackbox_Init == pyobject_autoload)? |
---|
| 35 | NULL: bbx->blackbox_Init(bbx)); |
---|
[1cb879] | 36 | } |
---|
| 37 | |
---|
[2e4ec14] | 38 | void pyobject_default_destroy(blackbox */*b*/, void */*d*/) |
---|
[35a0c12] | 39 | { |
---|
| 40 | Werror("Python-based functionality not available!"); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | // Setting up an empty blackbox type, which can be filled with pyobject |
---|
| 44 | void pyobject_setup() |
---|
| 45 | { |
---|
| 46 | blackbox *bbx = (blackbox*)omAlloc0(sizeof(blackbox)); |
---|
| 47 | bbx->blackbox_Init = pyobject_autoload; |
---|
| 48 | bbx->blackbox_destroy = pyobject_default_destroy; |
---|
| 49 | setBlackboxStuff(bbx, "pyobject"); |
---|
| 50 | } |
---|
[1cb879] | 51 | |
---|
[e87d40] | 52 | /// Explicitely load, if not loaded already |
---|
| 53 | BOOLEAN pyobject_ensure() { |
---|
| 54 | |
---|
| 55 | int tok = -1; |
---|
| 56 | blackbox* bbx = (blackboxIsCmd("pyobject", tok) == ROOT_DECL? |
---|
| 57 | getBlackboxStuff(tok): (blackbox*)NULL); |
---|
| 58 | if (bbx == NULL) return TRUE; |
---|
| 59 | return (bbx->blackbox_Init == pyobject_autoload? pyobject_load(): FALSE); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|