Skip to content

Commit

Permalink
using LIB("pyobject.so"); instead of system("pyobject");
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderdreyer committed Dec 14, 2012
1 parent 801d2b8 commit 57dcd6d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 43 deletions.
8 changes: 0 additions & 8 deletions Singular/extra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2950,14 +2950,6 @@ static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h)
}
else

/*==== pyobject (or pyobject*, like pyobject.so) force loading python ===*/
if (strncmp(sys_cmd, "pyobject", 8) == 0)
{
res->rtyp = NONE;
return pyobject_ensure();
}
else

/*==================== DLL =================*/
#ifdef ix86_Win
#ifdef HAVE_DL
Expand Down
4 changes: 3 additions & 1 deletion Singular/iparith.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5154,6 +5154,7 @@ BOOLEAN jjLOAD(char *s, BOOLEAN autoexport)
{
char libnamebuf[256];
lib_types LT = type_of_LIB(s, libnamebuf);

#ifdef HAVE_DYNAMIC_LOADING
extern BOOLEAN load_modules(char *newlib, char *fullpath, BOOLEAN autoexport);
#endif /* HAVE_DYNAMIC_LOADING */
Expand Down Expand Up @@ -5194,7 +5195,8 @@ BOOLEAN jjLOAD(char *s, BOOLEAN autoexport)
return bo;
}
case LT_BUILTIN:
return FALSE;
SModulFunc_t iiGetBuiltinModInit(char*);
return load_builtin(s,autoexport, iiGetBuiltinModInit(s));
case LT_MACH_O:
case LT_ELF:
case LT_HPUX:
Expand Down
24 changes: 21 additions & 3 deletions Singular/iplib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,25 @@ BOOLEAN iiEStart(char* example, procinfo *pi)
return err;
}

int huhu_mod_init(SModulFunctions*){ return 0; }

#define SI_GET_BUILTIN_MOD_INIT(name) \
int name##_mod_init(SModulFunctions*); \
if (strcmp(libname, #name ".so") == 0) { return name##_mod_init; }


SModulFunc_t
iiGetBuiltinModInit(char* libname)
{
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT)

return NULL;
}


#undef SI_GET_BUILTIN_MOD_INIT


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
BOOLEAN iiTryLoadLib(leftv v, const char *id)
{
Expand All @@ -683,7 +702,6 @@ BOOLEAN iiTryLoadLib(leftv v, const char *id)
package pack;
idhdl packhdl;
lib_types LT;

for(i=0; suffix[i] != NULL; i++)
{
sprintf(libname, "%s%s", id, suffix[i]);
Expand All @@ -701,7 +719,7 @@ BOOLEAN iiTryLoadLib(leftv v, const char *id)
#endif
else if (LT==LT_BUILTIN)
{
LoadResult=load_builtin(s,FALSE,(SModulFunc_t)NULL);
LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s));
}
if(!LoadResult )
{
Expand Down Expand Up @@ -1125,7 +1143,7 @@ BOOLEAN load_builtin(char *newlib, BOOLEAN autoexport, SModulFunc_t init)
else sModulFunctions.iiAddCproc = iiAddCproc;
(*init)(&sModulFunctions);
}
if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s \n", newlib);
if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
currPack->loaded=1;
currPack=s;

Expand Down
22 changes: 11 additions & 11 deletions Singular/pyobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public PythonObject
private:
size_t size(leftv iter, size_t distance = 0) const
{
if (iter) { do { ++distance; } while(iter = iter->next); };
if (iter) { do { ++distance; } while((iter = iter->next)); };
return distance;
}

Expand Down Expand Up @@ -462,7 +462,7 @@ BOOLEAN python_run(leftv result, leftv arg)
PyRun_SimpleString(reinterpret_cast<const char*>(arg->Data()));
sync_contexts();

Py_XINCREF(Py_None);
Py_INCREF(Py_None);
return PythonCastStatic<>(Py_None).assign_to(result);
}

Expand Down Expand Up @@ -495,14 +495,14 @@ BOOLEAN python_import(leftv result, leftv value) {
from_module_import_all(reinterpret_cast<const char*>(value->Data()));
sync_contexts();

Py_XINCREF(Py_None);
Py_INCREF(Py_None);
return PythonCastStatic<>(Py_None).assign_to(result);
}

/// blackbox support - initialization
void* pyobject_Init(blackbox*)
{
Py_XINCREF(Py_None);
Py_INCREF(Py_None);
return Py_None;
}

Expand Down Expand Up @@ -714,11 +714,10 @@ blackbox* pyobject_blackbox(int& tok) {


#define PYOBJECT_ADD_C_PROC(name) \
add_C_proc((currPack->libname? currPack->libname: ""), (char*)#name, FALSE, name);
psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""),\
(char*)#name, FALSE, name);

typedef BOOLEAN (*func_type)(leftv, leftv);
void pyobject_init(int (*add_C_proc)(const char*, const char*, BOOLEAN,
func_type) )
int pyobject_mod_init(SModulFunctions* psModulFunctions)
{
int tok = -1;
blackbox* bbx = pyobject_blackbox(tok);
Expand All @@ -733,22 +732,23 @@ void pyobject_init(int (*add_C_proc)(const char*, const char*, BOOLEAN,
bbx->blackbox_Op2 = pyobject_Op2;
bbx->blackbox_Op3 = pyobject_Op3;
bbx->blackbox_OpM = pyobject_OpM;
bbx->data = omAlloc0(newstruct_desc_size());
bbx->data = (void*)omAlloc0(newstruct_desc_size());

PythonInterpreter::init(tok);

PYOBJECT_ADD_C_PROC(python_import);
PYOBJECT_ADD_C_PROC(python_eval);
PYOBJECT_ADD_C_PROC(python_run);
}
return 0;
}
#undef PYOBJECT_ADD_C_PROC

#ifndef EMBED_PYTHON
extern "C" {
void mod_init(SModulFunctions* psModulFunctions)
int mod_init(SModulFunctions* psModulFunctions)
{
pyobject_init(psModulFunctions->iiAddCproc);
return pyobject_mod_init(psModulFunctions);
}
}
#endif
20 changes: 1 addition & 19 deletions Singular/pyobject_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,14 @@
#include <Singular/blackbox.h>
#include <Singular/ipshell.h>

/* whether pyobject module is linked statically or dynamically */

#ifdef EMBED_PYTHON // Case: we include the pyobject interface in the binary

#ifdef HAVE_PYTHON
#ifdef EMBED_PYTHON
#include "pyobject.cc"
static BOOLEAN pyobject_load()
{
pyobject_init(iiAddCproc);
return FALSE;
}

#else // Forced embedding, but no (development version of) python available!
static BOOLEAN pyobject_load() { return TRUE; }
#endif


# else // Case: pyobject may be loaded from a dynamic module (prefered variant)
// Note: we do not need python at compile time.
static BOOLEAN pyobject_load()
{
return jjLOAD("pyobject.so", TRUE);
}
#endif



/// blackbox support - initialization via autoloading
void* pyobject_autoload(blackbox* bbx)
Expand Down
6 changes: 5 additions & 1 deletion libpolys/polys/mod_raw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#define BYTES_TO_CHECK 7

char* si_bultin_libs[]={ "huhu.so", NULL };
#define SI_BUILTIN_LIBSTR(name) (char*) #name ".so",

char* si_bultin_libs[]={ SI_FOREACH_BUILTIN(SI_BUILTIN_LIBSTR) NULL };

#undef SI_BUILTIN_LIBSTR

lib_types type_of_LIB(char *newlib, char *libnamebuf)
{
Expand Down
14 changes: 14 additions & 0 deletions libpolys/polys/mod_raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ const char * dynl_error();
#endif

#endif /* HAVE_DL */


#ifdef EMBED_PYTHON
#define SI_BUILTIN_PYOBJECT(add) add(pyobject)
#else
#define SI_BUILTIN_PYOBJECT(add)
#endif

/// Use @c add(name) to add built-in library to macro
#define SI_FOREACH_BUILTIN(add)\
add(huhu)\
SI_BUILTIN_PYOBJECT(add)


#endif /* MOD_RAW_H */

0 comments on commit 57dcd6d

Please sign in to comment.