[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 | |
---|
[16f511] | 15 | #ifdef HAVE_CONFIG_H |
---|
[ba5e9e] | 16 | #include "singularconfig.h" |
---|
[16f511] | 17 | #endif /* HAVE_CONFIG_H */ |
---|
[83192d] | 18 | |
---|
[f5b40a] | 19 | #include <kernel/mod2.h> |
---|
[a015f4] | 20 | #include <kernel/febase.h> |
---|
[35a0c12] | 21 | #include <Singular/blackbox.h> |
---|
| 22 | #include <Singular/ipshell.h> |
---|
[1cb879] | 23 | |
---|
[83192d] | 24 | //#ifdef EMBED_PYTHON |
---|
| 25 | //#include "pyobject.cc" |
---|
| 26 | //#endif |
---|
[1cb879] | 27 | |
---|
[51f563] | 28 | static BOOLEAN pyobject_load() |
---|
| 29 | { |
---|
[6babcbc] | 30 | return jjLOAD("pyobject.so", TRUE); |
---|
[51f563] | 31 | } |
---|
[35a0c12] | 32 | |
---|
| 33 | /// blackbox support - initialization via autoloading |
---|
| 34 | void* pyobject_autoload(blackbox* bbx) |
---|
[1cb879] | 35 | { |
---|
[e87d40] | 36 | assume(bbx != NULL); |
---|
[a9c298] | 37 | return (pyobject_load() || (bbx->blackbox_Init == pyobject_autoload)? |
---|
[6b39bc] | 38 | NULL: bbx->blackbox_Init(bbx)); |
---|
[1cb879] | 39 | } |
---|
| 40 | |
---|
[2e4ec14] | 41 | void pyobject_default_destroy(blackbox */*b*/, void */*d*/) |
---|
[35a0c12] | 42 | { |
---|
| 43 | Werror("Python-based functionality not available!"); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | // Setting up an empty blackbox type, which can be filled with pyobject |
---|
[a9c298] | 47 | void pyobject_setup() |
---|
[35a0c12] | 48 | { |
---|
| 49 | blackbox *bbx = (blackbox*)omAlloc0(sizeof(blackbox)); |
---|
| 50 | bbx->blackbox_Init = pyobject_autoload; |
---|
| 51 | bbx->blackbox_destroy = pyobject_default_destroy; |
---|
| 52 | setBlackboxStuff(bbx, "pyobject"); |
---|
| 53 | } |
---|
[1cb879] | 54 | |
---|
[e87d40] | 55 | /// Explicitely load, if not loaded already |
---|
| 56 | BOOLEAN pyobject_ensure() { |
---|
| 57 | |
---|
| 58 | int tok = -1; |
---|
| 59 | blackbox* bbx = (blackboxIsCmd("pyobject", tok) == ROOT_DECL? |
---|
| 60 | getBlackboxStuff(tok): (blackbox*)NULL); |
---|
| 61 | if (bbx == NULL) return TRUE; |
---|
[a9c298] | 62 | return (bbx->blackbox_Init == pyobject_autoload? pyobject_load(): FALSE); |
---|
[e87d40] | 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|