Skip to content

Commit 57dcd6d

Browse files
using LIB("pyobject.so"); instead of system("pyobject");
1 parent 801d2b8 commit 57dcd6d

7 files changed

Lines changed: 55 additions & 43 deletions

File tree

Singular/extra.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,14 +2950,6 @@ static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h)
29502950
}
29512951
else
29522952

2953-
/*==== pyobject (or pyobject*, like pyobject.so) force loading python ===*/
2954-
if (strncmp(sys_cmd, "pyobject", 8) == 0)
2955-
{
2956-
res->rtyp = NONE;
2957-
return pyobject_ensure();
2958-
}
2959-
else
2960-
29612953
/*==================== DLL =================*/
29622954
#ifdef ix86_Win
29632955
#ifdef HAVE_DL

Singular/iparith.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5154,6 +5154,7 @@ BOOLEAN jjLOAD(char *s, BOOLEAN autoexport)
51545154
{
51555155
char libnamebuf[256];
51565156
lib_types LT = type_of_LIB(s, libnamebuf);
5157+
51575158
#ifdef HAVE_DYNAMIC_LOADING
51585159
extern BOOLEAN load_modules(char *newlib, char *fullpath, BOOLEAN autoexport);
51595160
#endif /* HAVE_DYNAMIC_LOADING */
@@ -5194,7 +5195,8 @@ BOOLEAN jjLOAD(char *s, BOOLEAN autoexport)
51945195
return bo;
51955196
}
51965197
case LT_BUILTIN:
5197-
return FALSE;
5198+
SModulFunc_t iiGetBuiltinModInit(char*);
5199+
return load_builtin(s,autoexport, iiGetBuiltinModInit(s));
51985200
case LT_MACH_O:
51995201
case LT_ELF:
52005202
case LT_HPUX:

Singular/iplib.cc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,25 @@ BOOLEAN iiEStart(char* example, procinfo *pi)
671671
return err;
672672
}
673673

674+
int huhu_mod_init(SModulFunctions*){ return 0; }
675+
676+
#define SI_GET_BUILTIN_MOD_INIT(name) \
677+
int name##_mod_init(SModulFunctions*); \
678+
if (strcmp(libname, #name ".so") == 0) { return name##_mod_init; }
679+
680+
681+
SModulFunc_t
682+
iiGetBuiltinModInit(char* libname)
683+
{
684+
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT)
685+
686+
return NULL;
687+
}
688+
689+
690+
#undef SI_GET_BUILTIN_MOD_INIT
691+
692+
674693
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
675694
BOOLEAN iiTryLoadLib(leftv v, const char *id)
676695
{
@@ -683,7 +702,6 @@ BOOLEAN iiTryLoadLib(leftv v, const char *id)
683702
package pack;
684703
idhdl packhdl;
685704
lib_types LT;
686-
687705
for(i=0; suffix[i] != NULL; i++)
688706
{
689707
sprintf(libname, "%s%s", id, suffix[i]);
@@ -701,7 +719,7 @@ BOOLEAN iiTryLoadLib(leftv v, const char *id)
701719
#endif
702720
else if (LT==LT_BUILTIN)
703721
{
704-
LoadResult=load_builtin(s,FALSE,(SModulFunc_t)NULL);
722+
LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s));
705723
}
706724
if(!LoadResult )
707725
{
@@ -1125,7 +1143,7 @@ BOOLEAN load_builtin(char *newlib, BOOLEAN autoexport, SModulFunc_t init)
11251143
else sModulFunctions.iiAddCproc = iiAddCproc;
11261144
(*init)(&sModulFunctions);
11271145
}
1128-
if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s \n", newlib);
1146+
if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
11291147
currPack->loaded=1;
11301148
currPack=s;
11311149

Singular/pyobject.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public PythonObject
412412
private:
413413
size_t size(leftv iter, size_t distance = 0) const
414414
{
415-
if (iter) { do { ++distance; } while(iter = iter->next); };
415+
if (iter) { do { ++distance; } while((iter = iter->next)); };
416416
return distance;
417417
}
418418

@@ -462,7 +462,7 @@ BOOLEAN python_run(leftv result, leftv arg)
462462
PyRun_SimpleString(reinterpret_cast<const char*>(arg->Data()));
463463
sync_contexts();
464464

465-
Py_XINCREF(Py_None);
465+
Py_INCREF(Py_None);
466466
return PythonCastStatic<>(Py_None).assign_to(result);
467467
}
468468

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

498-
Py_XINCREF(Py_None);
498+
Py_INCREF(Py_None);
499499
return PythonCastStatic<>(Py_None).assign_to(result);
500500
}
501501

502502
/// blackbox support - initialization
503503
void* pyobject_Init(blackbox*)
504504
{
505-
Py_XINCREF(Py_None);
505+
Py_INCREF(Py_None);
506506
return Py_None;
507507
}
508508

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

715715

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

719-
typedef BOOLEAN (*func_type)(leftv, leftv);
720-
void pyobject_init(int (*add_C_proc)(const char*, const char*, BOOLEAN,
721-
func_type) )
720+
int pyobject_mod_init(SModulFunctions* psModulFunctions)
722721
{
723722
int tok = -1;
724723
blackbox* bbx = pyobject_blackbox(tok);
@@ -733,22 +732,23 @@ void pyobject_init(int (*add_C_proc)(const char*, const char*, BOOLEAN,
733732
bbx->blackbox_Op2 = pyobject_Op2;
734733
bbx->blackbox_Op3 = pyobject_Op3;
735734
bbx->blackbox_OpM = pyobject_OpM;
736-
bbx->data = omAlloc0(newstruct_desc_size());
735+
bbx->data = (void*)omAlloc0(newstruct_desc_size());
737736

738737
PythonInterpreter::init(tok);
739738

740739
PYOBJECT_ADD_C_PROC(python_import);
741740
PYOBJECT_ADD_C_PROC(python_eval);
742741
PYOBJECT_ADD_C_PROC(python_run);
743742
}
743+
return 0;
744744
}
745745
#undef PYOBJECT_ADD_C_PROC
746746

747747
#ifndef EMBED_PYTHON
748748
extern "C" {
749-
void mod_init(SModulFunctions* psModulFunctions)
749+
int mod_init(SModulFunctions* psModulFunctions)
750750
{
751-
pyobject_init(psModulFunctions->iiAddCproc);
751+
return pyobject_mod_init(psModulFunctions);
752752
}
753753
}
754754
#endif

Singular/pyobject_setup.cc

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,14 @@
1818
#include <Singular/blackbox.h>
1919
#include <Singular/ipshell.h>
2020

21-
/* whether pyobject module is linked statically or dynamically */
22-
23-
#ifdef EMBED_PYTHON // Case: we include the pyobject interface in the binary
24-
25-
#ifdef HAVE_PYTHON
21+
#ifdef EMBED_PYTHON
2622
#include "pyobject.cc"
27-
static BOOLEAN pyobject_load()
28-
{
29-
pyobject_init(iiAddCproc);
30-
return FALSE;
31-
}
32-
33-
#else // Forced embedding, but no (development version of) python available!
34-
static BOOLEAN pyobject_load() { return TRUE; }
3523
#endif
3624

37-
38-
# else // Case: pyobject may be loaded from a dynamic module (prefered variant)
39-
// Note: we do not need python at compile time.
4025
static BOOLEAN pyobject_load()
4126
{
4227
return jjLOAD("pyobject.so", TRUE);
4328
}
44-
#endif
45-
46-
4729

4830
/// blackbox support - initialization via autoloading
4931
void* pyobject_autoload(blackbox* bbx)

libpolys/polys/mod_raw.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
3434
#define BYTES_TO_CHECK 7
3535

36-
char* si_bultin_libs[]={ "huhu.so", NULL };
36+
#define SI_BUILTIN_LIBSTR(name) (char*) #name ".so",
37+
38+
char* si_bultin_libs[]={ SI_FOREACH_BUILTIN(SI_BUILTIN_LIBSTR) NULL };
39+
40+
#undef SI_BUILTIN_LIBSTR
3741

3842
lib_types type_of_LIB(char *newlib, char *libnamebuf)
3943
{

libpolys/polys/mod_raw.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,18 @@ const char * dynl_error();
3838
#endif
3939

4040
#endif /* HAVE_DL */
41+
42+
43+
#ifdef EMBED_PYTHON
44+
#define SI_BUILTIN_PYOBJECT(add) add(pyobject)
45+
#else
46+
#define SI_BUILTIN_PYOBJECT(add)
47+
#endif
48+
49+
/// Use @c add(name) to add built-in library to macro
50+
#define SI_FOREACH_BUILTIN(add)\
51+
add(huhu)\
52+
SI_BUILTIN_PYOBJECT(add)
53+
54+
4155
#endif /* MOD_RAW_H */

0 commit comments

Comments
 (0)