Changeset 3e7db4 in git for Singular/pyobject_setup.cc


Ignore:
Timestamp:
Dec 11, 2012, 7:33:39 PM (11 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
14e634edb64741be0fbc04c9c89e8523cb0c1cc521dbb4186f3a2c56539d8f92abe1ee9e0fa0ae2c
Parents:
dcf88ff0bb046d73a7bde65e033fc58cbb5f4a97c9050082385152a64066f7540914cae34d990a43
Message:
Merge pull request #207 from kovzol/spielwiese

Adding new command line option --no-shell to prevent running escape shel...

NOTE: according to Hans we have to fix some more things in order to make this right
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/pyobject_setup.cc

    rc90500 r3e7db4  
    1616#include <kernel/mod2.h>
    1717#include <kernel/febase.h>
     18#include <Singular/blackbox.h>
     19#include <Singular/ipshell.h>
    1820
    1921/* whether pyobject module is linked statically or dynamically */
     22
     23#ifdef EMBED_PYTHON // Case: we include the pyobject interface in the binary
     24
    2025#ifdef HAVE_PYTHON
     26#include "pyobject.cc"
     27static BOOLEAN pyobject_load()
     28{
     29   pyobject_init(iiAddCproc);
     30   return FALSE;
     31}
    2132
    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!
     34static BOOLEAN pyobject_load() { return TRUE; }
    3335#endif
    3436
    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.
     40static BOOLEAN pyobject_load()
     41{
     42  return jjLOAD("pyobject.so", TRUE);
     43}
     44#endif
    3845
    3946
    40 # elif defined(HAVE_DYNAMIC_PYOBJECT) // Case: pyobject is dynamic module (prefered variant)
    4147
    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
     49void* pyobject_autoload(blackbox* bbx)
    4550{
    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));
    4953}
    5054
    51 #else                // Case: no python
    52 void pyobject_setup() { }
     55void pyobject_default_destroy(blackbox  *b, void *d)
     56{
     57  Werror("Python-based functionality not available!");
     58}
    5359
    54 #endif  // HAVE_PYTHON
     60// Setting up an empty blackbox type, which can be filled with pyobject
     61void 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}
    5568
     69/// Explicitely load, if not loaded already
     70BOOLEAN 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.