Changeset ec1006 in git


Ignore:
Timestamp:
Dec 7, 2012, 4:31:22 PM (10 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '00e2e9c41af3fde1273eb3633f4c0c7c3db2579d')
Children:
bf7dfc43347df3010846b62ff38fa0b4e8b30247
Parents:
6554ca42ebe1277c9afe7990970390905a6e1cf02ac2935796fc44d19ee67851bc57153313ee297b
Message:
Merge pull request #218 from alexanderdreyer/spielwiese-pyobject

Spielwiese pyobject
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r6554ca4 rec1006  
    3737
    3838bin_SCRIPTS = libsingular-config
     39
  • Singular/Makefile.am

    r6554ca4 rec1006  
    8888   links/ssiLink.cc\
    8989   subexpr.cc\
     90   pyobject_setup.cc\
    9091   walk.cc\
    9192   walk_ip.cc\
     
    390391MOD: ${top_builddir}/libpolys/polys/.libs
    391392        ln -snf ${top_builddir}/libpolys/polys/.libs/ ${builddir}/MOD
     393
     394if PYTHON_USE
     395   moduledir = $(bindir)/MOD
     396   module_LTLIBRARIES = pyobject.la
     397   pyobject_la_SOURCES = pyobject.cc
     398
     399   pyobject_la_CPPFLAGS   = ${AM_CPPFLAGS} ${NODEBUGDEFS}
     400   pyobject_g_la_CPPFLAGS = ${AM_CPPFLAGS}
     401
     402   pyobject_la_CXXFLAGS   = ${NODEBUGCXXFLAGS} @PYTHON_CSPEC@
     403   pyobject_g_la_CXXFLAGS = ${DEBUGCXXFLAGS} @PYTHON_CSPEC@
     404
     405   pyobject_la_LDFLAGS = -export-dynamic -shared -module -avoid-version \
     406     ${AMLDFLAGS} @PYTHON_LSPEC@
     407endif
  • Singular/blackbox.h

    r6554ca4 rec1006  
    5858
    5959/// default procedure blackboxDefaultOp3, to be called as "default:" branch
    60 BOOLEAN blackboxDefaultOp3(int op,leftv l, leftv r1,leftv r2, leftv r3);
     60BOOLEAN blackbox_default_Op3(int op,leftv l, leftv r1,leftv r2, leftv r3);
    6161
    6262/// default procedure blackboxDefaultOpM, to be called as "default:" branch
     
    7070/// return the name to the type given by t (r/o)
    7171const char *    getBlackboxName(const int t);
    72 /// used by scanner: returns ROOTDECL for known types (and the type number in t)
     72/// used by scanner: returns ROOT_DECL for known types
     73/// (and the type number in @c tok)
    7374int blackboxIsCmd(const char *n, int & tok);
    7475/// define a new type
  • Singular/iparith.cc

    r6554ca4 rec1006  
    52065206  }
    52075207  return TRUE;
     5208}
     5209
     5210BOOLEAN jjLOADLIB(const char* libname, BOOLEAN autoexport)
     5211{
     5212  leftv v =  (leftv)omAlloc0Bin(sleftv_bin);
     5213  v->data = (char*)libname;
     5214  v->rtyp = STRING_CMD;
     5215  BOOLEAN res = jjLOAD(NULL, v, autoexport);
     5216  omFreeBin(v, sleftv_bin);
     5217
     5218  return res;
    52085219}
    52095220
  • Singular/ipid.cc

    r6554ca4 rec1006  
    194194  IDLEV(h)  = level;
    195195  IDNEXT(h) = this;
     196  BOOLEAN at_start=(this==IDROOT);
    196197  h->id_i=iiS2I(s);
    197198  if (init)
     
    221222  }
    222223  // --------------------------------------------------------
     224  if (at_start)
     225    IDNEXT(h) = IDROOT;
    223226  return  h;
    224227}
  • Singular/pyobject.cc

    r6554ca4 rec1006  
    1515#include "config.h"
    1616#include <kernel/mod2.h>
     17  //#include <misc/auxiliary.h>
     18  //#include "newstruct.h"
     19
     20#include <Python.h>
     21
     22#include <Singular/ipid.h>
     23#include <Singular/blackbox.h>
     24#include <Singular/lists.h>
     25#include <Singular/ipid.h>
     26#include <Singular/ipshell.h>
     27#include <Singular/newstruct.h>
     28
     29
    1730#include <misc/auxiliary.h>
    18 #include "newstruct.h"
    1931
    2032#include <omalloc/omalloc.h>
    2133
    2234#include <kernel/febase.h>
    23 #include <kernel/intvec.h>
     35#include <misc/intvec.h>
    2436
    2537#include "subexpr.h"
     
    2739#include "ipid.h"
    2840#include "blackbox.h"
    29 
    30 #include <Python.h>
     41#include "ipshell.h"
     42
     43
     44
     45
     46  //#include <Python.h>
    3147// #include <iterator>             // std::distance
    3248// #include <stdio.h>
     
    4864  /// Initialize unique (singleton) python interpreter instance,
    4965  /// and set Singular type identifier
    50   static void init(id_type num ) { instance().m_id = num; }
     66  static void init(id_type num) { instance().m_id = num; }
    5167
    5268  /// Get Singular type identitfier
     
    587603    return FALSE;
    588604
    589   return blackboxDefaultOp3(op, res, arg1, arg2, arg3);
     605  return blackbox_default_Op3(op, res, arg1, arg2, arg3);
    590606}
    591607
     
    686702
    687703
    688 // forward declaration
    689 int iiAddCproc(char *libname, char *procname, BOOLEAN pstatic,
    690                BOOLEAN(*func)(leftv res, leftv v));
    691 
    692 #define ADD_C_PROC(name) iiAddCproc("", (char*)#name, FALSE, name);
    693 
    694 
    695 void pyobject_init()
    696 {
    697   blackbox *b = (blackbox*)omAlloc0(sizeof(blackbox));
    698   b->blackbox_destroy = pyobject_destroy;
    699   b->blackbox_String  = pyobject_String;
    700   b->blackbox_Init    = pyobject_Init;
    701   b->blackbox_Copy    = pyobject_Copy;
    702   b->blackbox_Assign  = pyobject_Assign;
    703   b->blackbox_Op1     = pyobject_Op1;
    704   b->blackbox_Op2     = pyobject_Op2;
    705   b->blackbox_Op3     = pyobject_Op3;
    706   b->blackbox_OpM     = pyobject_OpM;
    707   b->data             = omAlloc0(newstruct_desc_size());
    708 
    709   PythonInterpreter::init(setBlackboxStuff(b,"pyobject"));
    710 
    711   ADD_C_PROC(python_import);
    712   ADD_C_PROC(python_eval);
    713   ADD_C_PROC(python_run);
    714 }
    715 
    716 extern "C" { void mod_init() { pyobject_init(); } }
    717 
     704
     705blackbox* pyobject_blackbox(int& tok) {
     706  if(blackboxIsCmd("pyobject", tok) != ROOT_DECL)
     707  {
     708    tok = setBlackboxStuff((blackbox*)omAlloc0(sizeof(blackbox)),
     709                           "pyobject");
     710  }
     711  return getBlackboxStuff(tok);
     712}
     713
     714
     715
     716#define PYOBJECT_ADD_C_PROC(name) \
     717  add_C_proc(currPack->libname, (char*)#name, FALSE, name);
     718
     719typedef  BOOLEAN (*func_type)(leftv, leftv);
     720void pyobject_init(int (*add_C_proc)(const char*, const char*, BOOLEAN,
     721                                     func_type) )
     722{
     723  int tok = -1;
     724  blackbox* bbx = pyobject_blackbox(tok);
     725  if (bbx->blackbox_Init != pyobject_Init)
     726  {
     727    bbx->blackbox_destroy = pyobject_destroy;
     728    bbx->blackbox_String  = pyobject_String;
     729    bbx->blackbox_Init    = pyobject_Init;
     730    bbx->blackbox_Copy    = pyobject_Copy;
     731    bbx->blackbox_Assign  = pyobject_Assign;
     732    bbx->blackbox_Op1     = pyobject_Op1;
     733    bbx->blackbox_Op2     = pyobject_Op2;
     734    bbx->blackbox_Op3     = pyobject_Op3;
     735    bbx->blackbox_OpM     = pyobject_OpM;
     736    bbx->data             = omAlloc0(newstruct_desc_size());
     737   
     738    PythonInterpreter::init(tok);
     739
     740    PYOBJECT_ADD_C_PROC(python_import);
     741    PYOBJECT_ADD_C_PROC(python_eval);
     742    PYOBJECT_ADD_C_PROC(python_run);
     743  }
     744}
     745#undef PYOBJECT_ADD_C_PROC
     746
     747#ifndef EMBED_PYTHON
     748extern "C" {
     749  void mod_init(SModulFunctions* psModulFunctions)
     750  {
     751    pyobject_init(psModulFunctions->iiAddCproc);
     752  }
     753}
     754#endif
  • Singular/pyobject_setup.cc

    r6554ca4 rec1006  
    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  BOOLEAN jjLOADLIB(const char* libname, BOOLEAN autoexport);
     43  return jjLOADLIB("pyobject.so", TRUE);
     44}
     45#endif
    3846
    3947
    40 # elif defined(HAVE_DYNAMIC_PYOBJECT) // Case: pyobject is dynamic module (prefered variant)
    4148
    42 // forward declaration for Singular/iplib.cc
    43 void* binary_module_function(const char* lib, const char* func);
    44 void pyobject_setup()
     49/// blackbox support - initialization via autoloading
     50void* pyobject_autoload(blackbox* bbx)
    4551{
    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");
     52  if (pyobject_load()) return NULL;
     53  return bbx->blackbox_Init(bbx);
    4954}
    5055
    51 #else                // Case: no python
    52 void pyobject_setup() { }
     56void pyobject_default_destroy(blackbox  *b, void *d)
     57{
     58  Werror("Python-based functionality not available!");
     59}
    5360
    54 #endif  // HAVE_PYTHON
     61// Setting up an empty blackbox type, which can be filled with pyobject
     62void pyobject_setup()
     63{
     64  blackbox *bbx = (blackbox*)omAlloc0(sizeof(blackbox));
     65  bbx->blackbox_Init = pyobject_autoload;
     66  bbx->blackbox_destroy = pyobject_default_destroy;
     67  setBlackboxStuff(bbx, "pyobject");
     68}
    5569
  • Singular/tesths.cc

    r6554ca4 rec1006  
    4343#include "fegetopt.h"
    4444
    45 // #include "pyobject_setup.h"
     45#include "pyobject_setup.h"
    4646
    4747#include <unistd.h>
  • configure.ac

    r6554ca4 rec1006  
    6161LB_CHECK_NTL(5.0,,AC_MSG_WARN([Unable to find NTL (which is strongly recommended) on your machine: please use --with-ntl=PATH_TO_DIR_CONTAINING_LIB_AND_INCLUDE (see also ./configure --help if you do not understand what we are talking about)]))
    6262LB_CHECK_FLINT(2.3,,AC_MSG_WARN([Unable to find FLINT (which is strongly recommended) on your machine: please use --with-flint=PATH_TO_DIR_CONTAINING_LIB_AND_INCLUDE (see also ./configure --help if you do not understand what we are talking about)]))
     63
     64AX_PYTHON_ENABLE()
     65AX_PYTHON_WITH()
     66AX_PYTHON_VERSION_ENSURE( [2.4] )
     67AX_PYTHON_DEVEL([>= 2.4])
     68AX_PYTHON_LSPEC()
     69AX_PYTHON_CSPEC()
    6370
    6471AC_FUNC_ERROR_AT_LINE
Note: See TracChangeset for help on using the changeset viewer.