Loading...
Searching...
No Matches
p_Procs_Dynamic.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/***************************************************************
* File: p_Procs_Dynamic.cc
* Purpose: source for dynamically loaded version of p_Procs
* Author: obachman (Olaf Bachmann)
* Created: 12/00
*******************************************************************/
#include "misc/auxiliary.h"
#include "factory/factory.h"
#include "reporter/reporter.h"
#include "polys/monomials/ring.h"
#include "polys/monomials/p_polys.h"
#include "polys/kbuckets.h"
#include "polys/templates/p_Numbers.h"
#include "polys/templates/p_Procs.h"
#include "polys/templates/p_MemCmp.h"
#include "polys/templates/p_MemAdd.h"
#include "polys/templates/p_MemCopy.h"
#ifdef HAVE_DL
const BOOLEAN p_procs_dynamic = TRUE;
#define WARN_MSG "Singular will work properly, but much slower."
// need external linkage, so that dynl_sym works
#undef LINKAGE
#define LINKAGE extern "C"
#define p_Procs_Kernel
#include "templates/p_Procs.inc"
#include "templates/p_Procs_Dynamic.h"
// include general p_Proc stuff
#include "templates/p_Procs_Impl.h"
#include "mod_raw.h"
// define to bound for length of p_Proc name
#define MAX_PROCNAME_LEN 200
void* p_procs_handle_FieldIndep = NULL;
void* p_procs_handle_FieldZp = NULL;
void* p_procs_handle_FieldQ = NULL;
void* p_procs_handle_FieldGeneral = NULL;
static void* p_ProcInitHandle(void** handle, const char* module)
{
if (*handle == NULL)
{
char name[25];
snprintf(name,25, "p_Procs_%s", module);
*handle = dynl_open_binary_warn(name, WARN_MSG);
}
return *handle;
}
static inline void* p_ProcGetHandle(p_Proc proc, p_Field field)
{
const char* module = p_ProcField_2_Module(proc, field);
if (strcmp(module, "FieldIndep") == 0)
return p_ProcInitHandle(&p_procs_handle_FieldIndep, module);
else if (strcmp(module, "FieldZp") == 0)
return p_ProcInitHandle(&p_procs_handle_FieldZp, module);
else if (strcmp(module, "FieldQ") == 0)
return p_ProcInitHandle(&p_procs_handle_FieldQ, module);
else if (strcmp(module, "FieldGeneral") == 0)
return p_ProcInitHandle(&p_procs_handle_FieldGeneral, module);
else
{
assume(0);
return NULL;
}
}
static void* GetGeneralProc(p_Proc proc)
{
switch(proc)
{
case p_Copy_Proc:
return cast_A_to_vptr(p_Copy__FieldGeneral_LengthGeneral_OrdGeneral);
case p_Delete_Proc:
return cast_A_to_vptr(p_Delete__FieldGeneral_LengthGeneral_OrdGeneral);
case p_ShallowCopyDelete_Proc:
return cast_A_to_vptr(p_ShallowCopyDelete__FieldGeneral_LengthGeneral_OrdGeneral);
case p_Add_q_Proc:
return cast_A_to_vptr(p_Add_q__FieldGeneral_LengthGeneral_OrdGeneral);
case p_Neg_Proc:
return cast_A_to_vptr(p_Neg__FieldGeneral_LengthGeneral_OrdGeneral);
case p_Merge_q_Proc:
return cast_A_to_vptr(p_Merge_q__FieldGeneral_LengthGeneral_OrdGeneral);
case p_kBucketSetLm_Proc:
return cast_A_to_vptr(p_kBucketSetLm__FieldGeneral_LengthGeneral_OrdGeneral);
#ifdef HAVE_RINGS
case p_Mult_nn_Proc:
return cast_A_to_vptr(p_Mult_nn__RingGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_nn_Proc:
return cast_A_to_vptr(pp_Mult_nn__RingGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_mm_Proc:
return cast_A_to_vptr(pp_Mult_mm__RingGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_mm_Noether_Proc:
return cast_A_to_vptr(pp_Mult_mm_Noether__RingGeneral_LengthGeneral_OrdGeneral);
case p_Mult_mm_Proc:
return cast_A_to_vptr(p_Mult_mm__RingGeneral_LengthGeneral_OrdGeneral);
case p_Minus_mm_Mult_qq_Proc:
return cast_A_to_vptr(p_Minus_mm_Mult_qq__RingGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_Coeff_mm_DivSelect_Proc:
return cast_A_to_vptr(pp_Mult_Coeff_mm_DivSelect__RingGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_Coeff_mm_DivSelectMult_Proc:
return cast_A_to_vptr(pp_Mult_Coeff_mm_DivSelectMult__RingGeneral_LengthGeneral_OrdGeneral);
#else
case p_Mult_nn_Proc:
return cast_A_to_vptr(p_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_nn_Proc:
return cast_A_to_vptr(pp_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_mm_Proc:
return cast_A_to_vptr(pp_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_mm_Noether_Proc:
return cast_A_to_vptr(pp_Mult_mm_Noether__FieldGeneral_LengthGeneral_OrdGeneral);
case p_Mult_mm_Proc:
return cast_A_to_vptr(p_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral);
case p_Minus_mm_Mult_qq_Proc:
return cast_A_to_vptr(p_Minus_mm_Mult_qq__FieldGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_Coeff_mm_DivSelect_Proc:
return cast_A_to_vptr(pp_Mult_Coeff_mm_DivSelect__FieldGeneral_LengthGeneral_OrdGeneral);
case pp_Mult_Coeff_mm_DivSelectMult_Proc:
return cast_A_to_vptr(pp_Mult_Coeff_mm_DivSelectMult__FieldGeneral_LengthGeneral_OrdGeneral);
#endif
case p_Unknown_Proc:
break;
}
dReportBug("p_Unknown_Proc");
return NULL;
}
#ifdef RDEBUG
static const char* GetGeneralProcName(p_Proc proc)
{
switch(proc)
{
case p_Copy_Proc:
return "p_Copy__FieldGeneral_LengthGeneral_OrdGeneral";
case p_Delete_Proc:
return "p_Delete__FieldGeneral_LengthGeneral_OrdGeneral";
case p_ShallowCopyDelete_Proc:
return "p_ShallowCopyDelete__FieldGeneral_LengthGeneral_OrdGeneral";
case p_Add_q_Proc:
return "p_Add_q__FieldGeneral_LengthGeneral_OrdGeneral";
case p_Neg_Proc:
return "p_Neg__FieldGeneral_LengthGeneral_OrdGeneral";
case p_Merge_q_Proc:
return "p_Merge_q__FieldGeneral_LengthGeneral_OrdGeneral";
case p_kBucketSetLm_Proc:
return "p_kBucketSetLm__FieldGeneral_LengthGeneral_OrdGeneral";
case p_Unknown_Proc:
break;
#ifdef HAVE_RINGS
case p_Mult_nn_Proc:
return "p_Mult_nn__RingGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_nn_Proc:
return "pp_Mult_nn__RingGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_mm_Proc:
return "pp_Mult_mm__RingGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_mm_Noether_Proc:
return "pp_Mult_mm_Noether__RingGeneral_LengthGeneral_OrdGeneral";
case p_Mult_mm_Proc:
return "p_Mult_mm__RingGeneral_LengthGeneral_OrdGeneral";
case p_Minus_mm_Mult_qq_Proc:
return "p_Minus_mm_Mult_qq__RingGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_Coeff_mm_DivSelect_Proc:
return "pp_Mult_Coeff_mm_DivSelect__RingGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_Coeff_mm_DivSelectMult_Proc:
return "pp_Mult_Coeff_mm_DivSelectMult__RingGeneral_LengthGeneral_OrdGeneral";
#else
case p_Mult_nn_Proc:
return "p_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_nn_Proc:
return "pp_Mult_nn__FieldGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_mm_Proc:
return "pp_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_mm_Noether_Proc:
return "pp_Mult_mm_Noether__FieldGeneral_LengthGeneral_OrdGeneral";
case p_Mult_mm_Proc:
return "p_Mult_mm__FieldGeneral_LengthGeneral_OrdGeneral";
case p_Minus_mm_Mult_qq_Proc:
return "p_Minus_mm_Mult_qq__FieldGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_Coeff_mm_DivSelect_Proc:
return "pp_Mult_Coeff_mm_DivSelect__FieldGeneral_LengthGeneral_OrdGeneral";
case pp_Mult_Coeff_mm_DivSelectMult_Proc:
return "pp_Mult_Coeff_mm_DivSelectMult__FieldGeneral_LengthGeneral_OrdGeneral";
#endif
}
return "p_Unknown_Proc";
}
#endif
static void* GetDynamicProc(const char* proc_s, p_Proc proc,
p_Field field, p_Length length, p_Ord ord
#ifdef RDEBUG
, int get_name = 0
#endif
)
{
void* proc_ptr = NULL;
char proc_name[MAX_PROCNAME_LEN];
snprintf(proc_name,MAX_PROCNAME_LEN, "%s__%s_%s_%s", proc_s,
p_FieldEnum_2_String(field),
p_LengthEnum_2_String(length),
p_OrdEnum_2_String(ord));
// printf("set %s\n",proc_name);
// first, try to get the proc from the kernel
proc_ptr = dynl_sym(DYNL_KERNEL_HANDLE, proc_name);
if (proc_ptr == NULL)
{
proc_ptr = dynl_sym_warn(p_ProcGetHandle(proc, field), proc_name, WARN_MSG);
// last but not least use general proc
if (proc_ptr == NULL)
{
proc_ptr = GetGeneralProc(proc);
#ifdef RDEBUG
snprintf(proc_name,MAX_PROCNAME_LEN,"%s", GetGeneralProcName(proc));
#endif
}
}
#ifdef RDEBUG
if (get_name)
{
char* name = omStrDup(proc_name);
#if (!defined(SING_NDEBUG)) && (!defined(OM_NDEBUG))
omMarkAsStaticAddr(name);
#endif
return (void*) name;
}
#endif
return proc_ptr;
}
#define DoReallySetProc(what, field, length, ord) \
_p_procs->what = cast_vptr_to_A<what##_Proc_Ptr>( \
GetDynamicProc(#what, what##_Proc, field, length, ord))
#ifdef RDEBUG
#define DoSetProc(what, field, length, ord) \
do \
{ \
if (set_names) \
_p_procs->what = cast_vptr_to_A<what##_Proc_Ptr>( \
GetDynamicProc(#what, what##_Proc, field, length, ord, 1)); \
else \
DoReallySetProc(what, field, length, ord); \
} \
while(0)
#else
#define DoSetProc DoReallySetProc
#endif
#include "templates/p_Procs_Set.h"
#endif
auxiliary.h
All the auxiliary stuff.
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
cast_A_to_vptr
void * cast_A_to_vptr(A a)
Definition auxiliary.h:386
proc
unsigned char * proc[NUM_PROC]
Definition checklibs.c:16
factory.h
factory.h' is the user interface to Factory.
name
char name(const Variable &v)
Definition factory.h:189
length
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
kbuckets.h
assume
#define assume(x)
Definition mod2.h:389
RDEBUG
#define RDEBUG
Definition mod2.h:309
dynl_open_binary_warn
void * dynl_open_binary_warn(const char *binary_name, const char *msg)
Definition mod_raw.cc:45
dynl_sym_warn
void * dynl_sym_warn(void *handle, const char *proc, const char *msg)
Definition mod_raw.cc:89
dynl_sym
void * dynl_sym(void *handle, const char *symbol)
Definition mod_raw.cc:159
mod_raw.h
DYNL_KERNEL_HANDLE
#define DYNL_KERNEL_HANDLE
Definition mod_raw.h:32
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
NULL
#define NULL
Definition omList.c:12
p_MemAdd.h
p_MemCmp.h
p_MemCopy.h
p_Numbers.h
p_Procs.h
p_procs_dynamic
const BOOLEAN p_procs_dynamic
Definition p_Procs_Dynamic.cc:30
GetGeneralProcName
static const char * GetGeneralProcName(p_Proc proc)
Definition p_Procs_Dynamic.cc:147
GetGeneralProc
static void * GetGeneralProc(p_Proc proc)
Definition p_Procs_Dynamic.cc:86
p_ProcGetHandle
static void * p_ProcGetHandle(p_Proc proc, p_Field field)
Definition p_Procs_Dynamic.cc:66
p_procs_handle_FieldZp
void * p_procs_handle_FieldZp
Definition p_Procs_Dynamic.cc:51
p_procs_handle_FieldQ
void * p_procs_handle_FieldQ
Definition p_Procs_Dynamic.cc:52
p_ProcInitHandle
static void * p_ProcInitHandle(void **handle, const char *module)
Definition p_Procs_Dynamic.cc:55
WARN_MSG
#define WARN_MSG
Definition p_Procs_Dynamic.cc:32
p_procs_handle_FieldGeneral
void * p_procs_handle_FieldGeneral
Definition p_Procs_Dynamic.cc:53
MAX_PROCNAME_LEN
#define MAX_PROCNAME_LEN
Definition p_Procs_Dynamic.cc:48
p_procs_handle_FieldIndep
void * p_procs_handle_FieldIndep
Definition p_Procs_Dynamic.cc:50
GetDynamicProc
static void * GetDynamicProc(const char *proc_s, p_Proc proc, p_Field field, p_Length length, p_Ord ord, int get_name=0)
Definition p_Procs_Dynamic.cc:208
p_Procs_Dynamic.h
p_Procs_Impl.h
p_Length
p_Length
Definition p_Procs_Impl.h:123
p_ProcField_2_Module
static const char * p_ProcField_2_Module(p_Proc proc, p_Field field)
Definition p_Procs_Impl.h:331
p_Field
p_Field
Definition p_Procs_Impl.h:107
p_Proc
p_Proc
Definition p_Procs_Impl.h:179
p_ShallowCopyDelete_Proc
@ p_ShallowCopyDelete_Proc
Definition p_Procs_Impl.h:182
p_Delete_Proc
@ p_Delete_Proc
Definition p_Procs_Impl.h:181
p_kBucketSetLm_Proc
@ p_kBucketSetLm_Proc
Definition p_Procs_Impl.h:194
p_Neg_Proc
@ p_Neg_Proc
Definition p_Procs_Impl.h:190
p_Mult_nn_Proc
@ p_Mult_nn_Proc
Definition p_Procs_Impl.h:183
p_Mult_mm_Proc
@ p_Mult_mm_Proc
Definition p_Procs_Impl.h:187
pp_Mult_nn_Proc
@ pp_Mult_nn_Proc
Definition p_Procs_Impl.h:184
pp_Mult_Coeff_mm_DivSelect_Proc
@ pp_Mult_Coeff_mm_DivSelect_Proc
Definition p_Procs_Impl.h:191
p_Merge_q_Proc
@ p_Merge_q_Proc
Definition p_Procs_Impl.h:193
p_Copy_Proc
@ p_Copy_Proc
Definition p_Procs_Impl.h:180
p_Add_q_Proc
@ p_Add_q_Proc
Definition p_Procs_Impl.h:188
pp_Mult_mm_Proc
@ pp_Mult_mm_Proc
Definition p_Procs_Impl.h:185
pp_Mult_Coeff_mm_DivSelectMult_Proc
@ pp_Mult_Coeff_mm_DivSelectMult_Proc
Definition p_Procs_Impl.h:192
p_Minus_mm_Mult_qq_Proc
@ p_Minus_mm_Mult_qq_Proc
Definition p_Procs_Impl.h:189
pp_Mult_mm_Noether_Proc
@ pp_Mult_mm_Noether_Proc
Definition p_Procs_Impl.h:186
p_Unknown_Proc
@ p_Unknown_Proc
Definition p_Procs_Impl.h:195
p_FieldEnum_2_String
static const char * p_FieldEnum_2_String(p_Field field)
Definition p_Procs_Impl.h:198
p_Ord
p_Ord
Definition p_Procs_Impl.h:136
p_OrdEnum_2_String
static const char * p_OrdEnum_2_String(p_Ord ord)
Definition p_Procs_Impl.h:237
p_LengthEnum_2_String
static const char * p_LengthEnum_2_String(p_Length length)
Definition p_Procs_Impl.h:219
p_Procs_Set.h
p_polys.h
reporter.h
dReportBug
#define dReportBug(s)
Definition reporter.h:113
ring.h
omMarkAsStaticAddr
#define omMarkAsStaticAddr(A)
Definition xalloc.h:245