[SCM] an open source computer algebra system branch, cleanedupstream, updated. 6125e540ca6d66c307958938a9d53b245507c323
Bernhard R. Link
brlink at debian.org
Tue Apr 24 15:54:08 UTC 2012
The following commit has been merged in the cleanedupstream branch:
commit bd90c457894ada499c67efa64a446298b3506875
Author: Hans Schoenemann <hannes at mathematik.uni-kl.de>
Date: Tue Mar 13 14:58:47 2012 +0100
add: help for modules, "static" modules - part 1
diff --git a/Singular/iparith.cc b/Singular/iparith.cc
index a464029..03d7a56 100644
--- a/Singular/iparith.cc
+++ b/Singular/iparith.cc
@@ -4975,6 +4975,8 @@ static BOOLEAN jjLOAD(leftv res, leftv v, BOOLEAN autoexport)
IDPACKAGE(pl)->loaded=(!bo);
return bo;
}
+ case LT_BUILTIN:
+ return FALSE;
case LT_MACH_O:
case LT_ELF:
case LT_HPUX:
diff --git a/Singular/ipid.h b/Singular/ipid.h
index 576fd6e..027e763 100644
--- a/Singular/ipid.h
+++ b/Singular/ipid.h
@@ -76,6 +76,15 @@ typedef struct
} SModulFunctions;
+/* ================================================================== */
+/* module support */
+typedef int (*SModulFunc_t)(SModulFunctions*);
+BOOLEAN load_builtin(char *newlib, BOOLEAN autoexport, SModulFunc_t init);
+void module_help_main(char *newlib,const char *help);
+void module_help_proc(char *newlib,const char *p, const char *help);
+
+/* ================================================================== */
+
/*extern idhdl currRingHdl; in ring.h */
/*extern ring currRing; in ring.h */
/*extern ideal currQuotient; in structs.h */
diff --git a/Singular/iplib.cc b/Singular/iplib.cc
index f646f7a..ac63631 100644
--- a/Singular/iplib.cc
+++ b/Singular/iplib.cc
@@ -762,6 +762,10 @@ BOOLEAN iiTryLoadLib(leftv v, const char *id)
else if ((LT==LT_ELF) || (LT==LT_HPUX))
LoadResult = load_modules(s,libnamebuf,FALSE);
#endif
+ else if (LT==LT_BUILTIN)
+ {
+ LoadResult=load_builtin(s,FALSE,(SModulFunc_t)NULL);
+ }
if(!LoadResult )
{
v->name = iiConvName(libname);
@@ -1054,8 +1058,7 @@ BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport)
typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
BOOLEAN pstatic,
BOOLEAN(*func)(leftv res, leftv v)));
- typedef int (*fktn2_t)(SModulFunctions*);
- fktn2_t fktn;
+ SModulFunc_t fktn;
idhdl pl;
char *plib = iiConvName(newlib);
BOOLEAN RET=TRUE;
@@ -1102,7 +1105,7 @@ BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport)
package s=currPack;
currPack=IDPACKAGE(pl);
- fktn = (fktn2_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
+ fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
if( fktn!= NULL)
{
sModulFunctions.iiArithAddCmd = iiArithAddCmd;
@@ -1121,6 +1124,82 @@ BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport)
return RET;
#endif /*STATIC */
}
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+BOOLEAN load_builtin(char *newlib, BOOLEAN autoexport, SModulFunc_t init)
+{
+ int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
+ BOOLEAN(*func)(leftv res, leftv v));
+ typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
+ BOOLEAN pstatic,
+ BOOLEAN(*func)(leftv res, leftv v)));
+ SModulFunc_t fktn;
+ idhdl pl;
+ char *plib = iiConvName(newlib);
+ BOOLEAN RET=TRUE;
+ int token;
+
+ pl = IDROOT->get(plib,0);
+ if (pl==NULL)
+ {
+ pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
+ TRUE );
+ IDPACKAGE(pl)->language = LANG_C;
+ IDPACKAGE(pl)->libname=omStrDup(newlib);
+ }
+ IDPACKAGE(pl)->handle=(void *)NULL;
+ SModulFunctions sModulFunctions;
+
+ package s=currPack;
+ currPack=IDPACKAGE(pl);
+ if( init!= NULL)
+ {
+ sModulFunctions.iiArithAddCmd = iiArithAddCmd;
+ if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
+ else sModulFunctions.iiAddCproc = iiAddCproc;
+ (*init)(&sModulFunctions);
+ }
+ if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s \n", newlib);
+ currPack->loaded=1;
+ currPack=s;
+
+ return FALSE;
+}
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+void module_help_main(char *newlib,const char *help)
+{
+ char *plib = iiConvName(newlib);
+ idhdl pl = IDROOT->get(plib,0);
+ if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
+ Werror(">>%s<< is not a package",plib);
+ else
+ {
+ package s=currPack;
+ currPack=IDPACKAGE(pl);
+ idhdl h=enterid(omStrDup("info"),0,STRING_CMD,&IDROOT,FALSE);
+ IDSTRING(h)=omStrDup(help);
+ currPack=s;
+ }
+}
+void module_help_proc(char *newlib,const char *p, const char *help)
+{
+ char *plib = iiConvName(newlib);
+ idhdl pl = IDROOT->get(plib,0);
+ if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
+ Werror(">>%s<< is not a package",plib);
+ else
+ {
+ package s=currPack;
+ currPack=IDPACKAGE(pl);
+ char buff[256];
+ buff[255]='\0';
+ strncpy(buff,p,255);
+ strncat(buff,"_help",255-strlen(p));
+ idhdl h=enterid(omStrDup(buff),0,STRING_CMD,&IDROOT,FALSE);
+ IDSTRING(h)=omStrDup(help);
+ currPack=s;
+ }
+}
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
// loads a dynamic module from the binary path and returns a named function
// returns NULL, if something fails
diff --git a/Singular/tesths.cc b/Singular/tesths.cc
index 3f7b411..ad7fd38 100644
--- a/Singular/tesths.cc
+++ b/Singular/tesths.cc
@@ -171,6 +171,10 @@ int main( /* main entry to Singular */
#endif /* HAVE_FANS */
errorreported = 0;
+ // -- example for "static" modules ------
+ //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
+ //module_help_main("huhu.so","Help for huhu\nhaha\n");
+ //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
setjmp(si_start_jmpbuf);
// Now, put things on the stack of stuff to do
diff --git a/kernel/mod_raw.cc b/kernel/mod_raw.cc
index 72cc55d..048898a 100644
--- a/kernel/mod_raw.cc
+++ b/kernel/mod_raw.cc
@@ -1,7 +1,6 @@
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
-/* $Id$ */
/*
* ABSTRACT: machine depend code for dynamic modules
*
@@ -29,10 +28,22 @@
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#define BYTES_TO_CHECK 7
+char* si_bultin_libs[]={ "huhu.so", NULL };
+
lib_types type_of_LIB(char *newlib, char *libnamebuf)
{
const char mach_o[]={0xfe,0xed,0xfa,0xce,0};
const char mach_o_module[]={0xce,0xfa,0xed,0xfe,0};
+ int i=0;
+ while(si_bultin_libs[i]!=NULL)
+ {
+ if (strcmp(newlib,si_bultin_libs[i])==0)
+ {
+ if(libnamebuf!=NULL) strcpy(libnamebuf,newlib);
+ return LT_BUILTIN;
+ }
+ i++;
+ }
char buf[BYTES_TO_CHECK+1]; /* one extra for terminating '\0' */
struct stat sb;
int nbytes = 0;
@@ -85,7 +96,7 @@ lib_types type_of_LIB(char *newlib, char *libnamebuf)
goto lib_type_end;
}
-
+
if( (strncmp(buf, "\02\020\01\016\05\022@", 7)==0))
{
LT = LT_HPUX;
@@ -202,7 +213,7 @@ void *dynl_open(
else
Werror("module %s already loaded",filename);
return NULL;
-// alternative
+// alternative
// return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
}
diff --git a/kernel/mod_raw.h b/kernel/mod_raw.h
index a617150..4b25495 100644
--- a/kernel/mod_raw.h
+++ b/kernel/mod_raw.h
@@ -3,7 +3,6 @@
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
-/* $Id$ */
/*
* ABSTRACT: machine depend code for dynamic modules
*
@@ -13,7 +12,7 @@
* dunl_close()
*/
-typedef enum { LT_NONE, LT_NOTFOUND, LT_SINGULAR, LT_ELF, LT_HPUX, LT_MACH_O} lib_types;
+typedef enum { LT_NONE, LT_NOTFOUND, LT_SINGULAR, LT_ELF, LT_HPUX, LT_MACH_O, LT_BUILTIN} lib_types;
lib_types type_of_LIB(char *newlib, char *fullname);
--
an open source computer algebra system
More information about the debian-science-commits
mailing list