1
0
Fork 0
mirror of git://git.psyced.org/git/psyclpc synced 2024-08-15 03:20:16 +00:00

merge with ldmud distribution

This commit is contained in:
psyc://psyced.org/~lynX 2009-05-22 00:41:07 +02:00
parent 480babdac9
commit c0325c31e6
134 changed files with 16545 additions and 3006 deletions

View file

@ -1,3 +1,9 @@
2009-05-22 (lynX) (4.0.12)
+ adopted changes in LDMUD 3.3.718:
- many many many fixes
+ support for iksemel xml parser library
+ state of the art random generator
2008-07-27 (lynX) (4.0.10)
+ added ERR_TLS_NOT_DETECTED code to sys/tls.h
+ added suitable message to tls_error()

View file

@ -25,6 +25,7 @@
#define DIT_ERROR 1 /* Return the last error call chain as an array */
#define DIT_UNCAUGHT_ERROR 2 /* Return the last uncaught error call chain */
#define DIT_STR_CURRENT 3 /* Return the current call chain as a string */
#define DIT_CURRENT_DEPTH 4 /* Return the current control stack depth */
/* Indices into the array resulting from debug_info(DINFO_DATA, DID_STATUS)
*/
@ -226,8 +227,13 @@
#define TRACE_PROGRAM 2
#define TRACE_OBJECT 3
#define TRACE_LOC 4
#ifdef __EVAL_COST_TRACE__
#define TRACE_EVALCOST 5
#define TRACE_MAX 6
#else
#define TRACE_MAX 5
#endif
/* Values for entry TRACE_TYPE */

View file

@ -73,6 +73,14 @@ OPTIMIZE= $(@val_optimize@_OPTIMIZE)
# recompile.
#DEBUG = -DDEBUG # -DDEBUG_TELNET
DEBUG=
# Flags for compiling the SFMT random number generator.
SFMT_FLAGS = -fno-strict-aliasing
# for machines with sse2 support you may use:
#SFMT_FLAGS = -msse2 -fno-strict-aliasing -DHAVE_SSE2=1
# for machines with altivec support you may use:
#SFMT_FLAGS = -faltivec -fno-strict-aliasing -DHAVE_ALTIVEC=1
#
MPATH=-DMUD_LIB='"$(MUD_LIB)"' -DBINDIR='"$(BINDIR)"' -DERQ_DIR='"$(ERQ_DIR)"'
#
@ -93,7 +101,7 @@ SRC = access_check.c actions.c array.c backend.c bitstrings.c call_out.c \
interpret.c \
lex.c main.c mapping.c md5.c mempools.c mregex.c mstrings.c object.c \
otable.c\
parser.c parse.c pkg-alists.c pkg-idna.c \
parser.c parse.c pkg-alists.c pgk-iksemel.c pkg-idna.c pkg-expat.c \
pkg-mccp.c pkg-mysql.c pkg-pcre.c \
pkg-pgsql.c pkg-sqlite.c pkg-tls.c \
ptmalloc.c port.c ptrtable.c \
@ -105,13 +113,12 @@ OBJ = access_check.o actions.o array.o backend.o bitstrings.o call_out.o \
interpret.o \
lex.o main.o mapping.o md5.o mempools.o mregex.o mstrings.o object.o \
otable.o \
parser.o parse.o pkg-alists.o pkg-idna.o \
parser.o parse.o pkg-alists.o pkg-iksemel.o pkg-idna.o pkg-expat.o \
pkg-mccp.o pkg-mysql.o pkg-pcre.o \
pkg-pgsql.o pkg-sqlite.o pkg-tls.o \
ptmalloc.o port.o ptrtable.o \
random.o regexp.o sha1.o simulate.o simul_efun.o stdstrings.o \
strfuns.o structs.o sprintf.o swap.o wiz_list.o xalloc.o @ALLOCA@ \
pkg-expat.o
strfuns.o structs.o sprintf.o swap.o wiz_list.o xalloc.o @ALLOCA@
all: make-patchlevel @PROGNAME@@EXEEXT@
@ -123,7 +130,7 @@ it: @PROGNAME@@EXEEXT@
docs: @PROGNAME@@EXEEXT@
-help2man --name=@PROGNAME@ -N --help-option=--longhelp --include=../HELP --output=../@PROGNAME@.1 ./@PROGNAME@@EXEEXT@
install-all: install-driver install-headers install-utils
install: install-driver
@ -213,6 +220,9 @@ lang.c lang.h: lang.y
pcre/chartables.c : dftables@EXEEXT@
./dftables@EXEEXT@ pcre/chartables.c
random.o : random.c config.h driver.h
$(CC) $(CFLAGS) $(SFMT_FLAGS) -c random.c -o random.o
#--------------------------------------------------------
# The dependency generation uses the program 'mkdepend' and assumes GNUmake.
@ -228,11 +238,11 @@ pcre/chartables.c : dftables@EXEEXT@
depend: $(SRC) $(GENSRC)
@$(SHELL) -ec "if type mkdepend > /dev/null 2>&1; then \
echo Updating dependencies.; \
mkdepend $(SKELETON) -I. $(EXCEPT) -m -p .c:%n.o -fMakefile; \
mkdepend $(SKELETON) -I. $(EXCEPT) $(SELECT) -m -p .c:%n.o -fMakefile; \
mkdepend $(SKELETON) -I. -Ipcre -Iptmalloc $(EXCEPT) -m -p .c:%n.o -fMakefile; \
mkdepend $(SKELETON) -I. -Ipcre -Iptmalloc $(EXCEPT) $(SELECT) -m -p .c:%n.o -fMakefile; \
echo Updating dependencies in Makefile.in.; \
mkdepend $(SKELETON) -I. $(EXCEPT) -m -p .c:%n.o -fMakefile.in; \
mkdepend $(SKELETON) -I. $(EXCEPT) $(SELECT) -m -p .c:%n.o -fMakefile.in; \
mkdepend $(SKELETON) -I. -Ipcre -Iptmalloc $(EXCEPT) -m -p .c:%n.o -fMakefile.in; \
mkdepend $(SKELETON) -I. -Ipcre -Iptmalloc $(EXCEPT) $(SELECT) -m -p .c:%n.o -fMakefile.in; \
else\
echo mkdepend utility not available.; \
fi"
@ -242,8 +252,8 @@ depend: $(SRC) $(GENSRC)
depend-generic: $(SRC) $(GENSRC)
@$(SHELL) -ec "if type mkdepend > /dev/null 2>&1; then \
echo Updating dependencies in hosts/be/Makefile.; \
mkdepend $(SKELETON) -I. $(EXCEPT) -m -p .c:$$\(OBJ\)/%n.o -fhosts/be/Makefile; \
mkdepend $(SKELETON) -I. $(EXCEPT) $(SELECT) -m -p .c:$$\(OBJ\)/%n.o -fhosts/be/Makefile; \
mkdepend $(SKELETON) -I. -Ipcre -Iptmalloc $(EXCEPT) -m -p .c:$$\(OBJ\)/%n.o -fhosts/be/Makefile; \
mkdepend $(SKELETON) -I. -Ipcre -Iptmalloc $(EXCEPT) $(SELECT) -m -p .c:$$\(OBJ\)/%n.o -fhosts/be/Makefile; \
else\
echo mkdepend utility not available.; \
fi"
@ -271,20 +281,20 @@ array.o : i-svalue_cmp.h xalloc.h wiz_list.h swap.h svalue.h simulate.h \
hosts/be/be.h machine.h
backend.o : ../mudlib/sys/debug_message.h ../mudlib/sys/driver_hook.h \
xalloc.h wiz_list.h swap.h svalue.h stdstrings.h simulate.h random.h \
otable.h object.h mstrings.h mregex.h mapping.h main.h lex.h \
interpret.h heartbeat.h gcollect.h filestat.h exec.h ed.h comm.h \
closure.h call_out.h array.h actions.h backend.h my-alloca.h typedefs.h \
driver.h strfuns.h sent.h bytecode.h hash.h pkg-tls.h port.h config.h \
hosts/unix.h hosts/be/be.h machine.h
i-eval_cost.h xalloc.h wiz_list.h swap.h svalue.h stdstrings.h \
simulate.h random.h otable.h object.h mstrings.h mregex.h mapping.h \
main.h lex.h interpret.h heartbeat.h gcollect.h filestat.h exec.h ed.h \
comm.h closure.h call_out.h array.h actions.h backend.h my-alloca.h \
typedefs.h driver.h strfuns.h sent.h bytecode.h hash.h pkg-tls.h port.h \
config.h hosts/unix.h hosts/be/be.h machine.h
bitstrings.o : xalloc.h svalue.h simulate.h mstrings.h interpret.h \
bitstrings.h typedefs.h driver.h strfuns.h sent.h bytecode.h hash.h \
backend.h port.h config.h main.h hosts/unix.h hosts/be/be.h machine.h
call_out.o : ../mudlib/sys/debug_info.h xalloc.h wiz_list.h swap.h svalue.h \
strfuns.h stdstrings.h simulate.h object.h mstrings.h main.h \
interpret.h gcollect.h exec.h comm.h closure.h backend.h array.h \
call_out.o : ../mudlib/sys/debug_info.h i-eval_cost.h xalloc.h wiz_list.h \
swap.h svalue.h strfuns.h stdstrings.h simulate.h object.h mstrings.h \
main.h interpret.h gcollect.h exec.h comm.h closure.h backend.h array.h \
actions.h call_out.h typedefs.h driver.h sent.h bytecode.h hash.h \
pkg-tls.h port.h config.h hosts/unix.h hosts/be/be.h machine.h
@ -295,13 +305,13 @@ closure.o : i-svalue_cmp.h xalloc.h switch.h swap.h svalue.h structs.h \
bytecode.h port.h config.h hosts/unix.h hosts/be/be.h machine.h
comm.o : util/erq/erq.h ../mudlib/sys/input_to.h \
../mudlib/sys/driver_hook.h ../mudlib/sys/comm.h xalloc.h wiz_list.h \
swap.h svalue.h stdstrings.h simulate.h sent.h pkg-tls.h pkg-pgsql.h \
pkg-mccp.h object.h mstrings.h main.h interpret.h gcollect.h filestat.h \
exec.h ed.h closure.h array.h actions.h access_check.h comm.h \
../mudlib/sys/telnet.h my-alloca.h typedefs.h driver.h strfuns.h \
bytecode.h hash.h backend.h config.h port.h hosts/unix.h hosts/be/be.h \
machine.h
../mudlib/sys/driver_hook.h ../mudlib/sys/comm.h i-eval_cost.h xalloc.h \
wiz_list.h swap.h svalue.h stdstrings.h simulate.h sent.h pkg-tls.h \
pkg-pgsql.h pkg-mccp.h object.h mstrings.h main.h interpret.h \
gcollect.h filestat.h exec.h ed.h closure.h array.h actions.h \
access_check.h comm.h ../mudlib/sys/telnet.h my-alloca.h typedefs.h \
driver.h strfuns.h bytecode.h hash.h backend.h config.h port.h \
hosts/unix.h hosts/be/be.h machine.h
dumpstat.o : xalloc.h svalue.h structs.h stdstrings.h simulate.h ptrtable.h \
object.h mstrings.h mapping.h instrs.h filestat.h exec.h closure.h \
@ -316,14 +326,14 @@ ed.o : ../mudlib/sys/regexp.h xalloc.h svalue.h stdstrings.h simulate.h \
efuns.o : ../mudlib/sys/time.h ../mudlib/sys/strings.h \
../mudlib/sys/regexp.h ../mudlib/sys/objectinfo.h \
../mudlib/sys/driver_hook.h ../mudlib/sys/debug_info.h xalloc.h \
wiz_list.h svalue.h swap.h structs.h strfuns.h simulate.h stdstrings.h \
sha1.h random.h ptrtable.h otable.h object.h mstrings.h mregex.h md5.h \
mempools.h mapping.h main.h lex.h interpret.h heartbeat.h exec.h \
dumpstat.h comm.h closure.h call_out.h backend.h array.h actions.h \
efuns.h my-rusage.h my-alloca.h typedefs.h driver.h hash.h sent.h \
bytecode.h my-stdint.h pkg-tls.h port.h config.h hosts/unix.h \
hosts/be/be.h machine.h
../mudlib/sys/driver_hook.h ../mudlib/sys/debug_info.h i-eval_cost.h \
xalloc.h wiz_list.h svalue.h swap.h structs.h strfuns.h simulate.h \
stdstrings.h sha1.h random.h ptrtable.h otable.h object.h mstrings.h \
mregex.h md5.h mempools.h mapping.h main.h lex.h interpret.h \
heartbeat.h exec.h dumpstat.h comm.h closure.h call_out.h backend.h \
array.h actions.h efuns.h my-rusage.h my-alloca.h typedefs.h driver.h \
hash.h sent.h bytecode.h my-stdint.h pkg-tls.h port.h config.h \
hosts/unix.h hosts/be/be.h machine.h
files.o : ../mudlib/sys/files.h xalloc.h svalue.h stdstrings.h simulate.h \
mstrings.h mempools.h main.h lex.h interpret.h filestat.h comm.h \
@ -331,8 +341,8 @@ files.o : ../mudlib/sys/files.h xalloc.h svalue.h stdstrings.h simulate.h \
bytecode.h hash.h backend.h pkg-tls.h port.h config.h hosts/unix.h \
hosts/be/be.h machine.h
gcollect.o : ../mudlib/sys/driver_hook.h xalloc.h wiz_list.h swap.h \
structs.h stdstrings.h simul_efun.h simulate.h sent.h random.h \
gcollect.o : ../mudlib/sys/driver_hook.h i-eval_cost.h xalloc.h wiz_list.h \
swap.h structs.h stdstrings.h simul_efun.h simulate.h sent.h random.h \
ptrtable.h prolang.h pkg-pgsql.h parse.h otable.h object.h mstrings.h \
mregex.h mempools.h mapping.h main.h lex.h instrs.h interpret.h \
heartbeat.h filestat.h ed.h comm.h closure.h call_out.h backend.h \
@ -342,35 +352,36 @@ gcollect.o : ../mudlib/sys/driver_hook.h xalloc.h wiz_list.h swap.h \
hash.o : hash.h
heartbeat.o : ../mudlib/sys/debug_info.h xalloc.h wiz_list.h svalue.h \
strfuns.h simulate.h sent.h object.h mstrings.h interpret.h gcollect.h \
exec.h comm.h backend.h array.h actions.h heartbeat.h typedefs.h \
driver.h bytecode.h hash.h pkg-tls.h main.h port.h config.h \
heartbeat.o : ../mudlib/sys/debug_info.h i-eval_cost.h xalloc.h wiz_list.h \
svalue.h strfuns.h simulate.h sent.h object.h mstrings.h interpret.h \
gcollect.h exec.h comm.h backend.h array.h actions.h heartbeat.h \
typedefs.h driver.h bytecode.h hash.h pkg-tls.h main.h port.h config.h \
hosts/unix.h hosts/be/be.h machine.h
interpret.o : ../mudlib/sys/trace.h ../mudlib/sys/debug_info.h \
../mudlib/sys/driver_hook.h xalloc.h wiz_list.h switch.h swap.h \
svalue.h structs.h stdstrings.h simul_efun.h simulate.h prolang.h \
parse.h otable.h object.h mstrings.h mapping.h lex.h instrs.h \
heartbeat.h gcollect.h filestat.h exec.h efuns.h ed.h comm.h closure.h \
call_out.h backend.h array.h actions.h interpret.h my-alloca.h \
typedefs.h driver.h strfuns.h hash.h ptrtable.h sent.h bytecode.h \
pkg-tls.h main.h port.h config.h hosts/unix.h hosts/be/be.h machine.h
interpret.o : ../mudlib/sys/debug_info.h ../mudlib/sys/driver_hook.h \
i-eval_cost.h xalloc.h wiz_list.h switch.h swap.h svalue.h structs.h \
stdstrings.h simul_efun.h simulate.h prolang.h parse.h otable.h \
object.h mstrings.h mapping.h lex.h instrs.h heartbeat.h gcollect.h \
filestat.h exec.h efuns.h ed.h comm.h closure.h call_out.h backend.h \
array.h actions.h interpret.h my-alloca.h typedefs.h driver.h strfuns.h \
hash.h ptrtable.h sent.h bytecode.h pkg-tls.h main.h port.h config.h \
hosts/unix.h hosts/be/be.h machine.h
lex.o : efun_defs.c ../mudlib/sys/driver_hook.h xalloc.h wiz_list.h \
svalue.h strfuns.h stdstrings.h simul_efun.h simulate.h prolang.h \
patchlevel.h object.h mstrings.h mempools.h main.h lang.h interpret.h \
instrs.h hash.h gcollect.h filestat.h exec.h comm.h closure.h backend.h \
array.h lex.h my-alloca.h typedefs.h driver.h ptrtable.h sent.h \
bytecode.h pkg-tls.h port.h config.h hosts/unix.h hosts/be/be.h \
machine.h
lex.o : efun_defs.c ../mudlib/sys/driver_hook.h i-eval_cost.h xalloc.h \
wiz_list.h svalue.h strfuns.h stdstrings.h simul_efun.h simulate.h \
prolang.h patchlevel.h object.h mstrings.h mempools.h main.h lang.h \
interpret.h instrs.h hash.h gcollect.h filestat.h exec.h comm.h \
closure.h backend.h array.h lex.h my-alloca.h typedefs.h driver.h \
ptrtable.h sent.h bytecode.h pkg-tls.h port.h config.h hosts/unix.h \
hosts/be/be.h machine.h
main.o : ../mudlib/sys/regexp.h pkg-mysql.h xalloc.h wiz_list.h swap.h \
svalue.h stdstrings.h simul_efun.h simulate.h random.h pkg-tls.h \
patchlevel.h otable.h object.h mstrings.h mregex.h mempools.h mapping.h \
lex.h interpret.h gcollect.h filestat.h comm.h array.h backend.h main.h \
my-alloca.h typedefs.h driver.h strfuns.h ptrtable.h exec.h sent.h \
bytecode.h hash.h port.h config.h hosts/unix.h hosts/be/be.h machine.h
main.o : ../mudlib/sys/regexp.h i-eval_cost.h pkg-mysql.h xalloc.h \
wiz_list.h swap.h svalue.h stdstrings.h simul_efun.h simulate.h \
random.h pkg-tls.h patchlevel.h otable.h object.h mstrings.h mregex.h \
mempools.h mapping.h lex.h interpret.h gcollect.h filestat.h comm.h \
array.h backend.h main.h my-alloca.h typedefs.h driver.h strfuns.h \
ptrtable.h exec.h sent.h bytecode.h hash.h port.h config.h hosts/unix.h \
hosts/be/be.h machine.h
mapping.o : i-svalue_cmp.h xalloc.h wiz_list.h svalue.h structs.h \
simulate.h object.h mstrings.h main.h interpret.h gcollect.h closure.h \
@ -421,12 +432,12 @@ parse.o : xalloc.h wiz_list.h svalue.h stdstrings.h simulate.h object.h \
parse.h typedefs.h driver.h strfuns.h sent.h bytecode.h hash.h \
backend.h port.h config.h hosts/unix.h hosts/be/be.h machine.h
parser.o : lang.c ../mudlib/sys/driver_hook.h xalloc.h wiz_list.h switch.h \
swap.h svalue.h structs.h stdstrings.h simul_efun.h simulate.h object.h \
mstrings.h mapping.h main.h lex.h instrs.h interpret.h gcollect.h \
exec.h closure.h backend.h array.h prolang.h my-alloca.h typedefs.h \
driver.h strfuns.h hash.h ptrtable.h sent.h bytecode.h port.h config.h \
hosts/unix.h hosts/be/be.h machine.h
parser.o : lang.c ../mudlib/sys/driver_hook.h i-eval_cost.h xalloc.h \
wiz_list.h switch.h swap.h svalue.h structs.h stdstrings.h simul_efun.h \
simulate.h object.h mstrings.h mapping.h main.h lex.h instrs.h \
interpret.h gcollect.h exec.h closure.h backend.h array.h prolang.h \
my-alloca.h typedefs.h driver.h strfuns.h hash.h ptrtable.h sent.h \
bytecode.h port.h config.h hosts/unix.h hosts/be/be.h machine.h
dftables.o : pcre/maketables.c pcre/internal.h pcre/pcre.h pcre/config.h
@ -487,9 +498,10 @@ ptrtable.o : simulate.h mempools.h ptrtable.h driver.h svalue.h strfuns.h \
random.o : random.h driver.h port.h config.h hosts/unix.h hosts/be/be.h \
machine.h
regexp.o : main.h xalloc.h simulate.h interpret.h regexp.h driver.h \
typedefs.h svalue.h strfuns.h sent.h bytecode.h backend.h pkg-pcre.h \
port.h config.h pcre/pcre.h hosts/unix.h hosts/be/be.h machine.h
regexp.o : i-eval_cost.h main.h xalloc.h simulate.h regexp.h driver.h \
interpret.h typedefs.h svalue.h strfuns.h sent.h bytecode.h pkg-pcre.h \
port.h config.h backend.h pcre/pcre.h hosts/unix.h hosts/be/be.h \
machine.h
sha1.o : sha1.h my-stdint.h driver.h port.h config.h hosts/unix.h \
hosts/be/be.h machine.h
@ -502,12 +514,12 @@ simul_efun.o : xalloc.h swap.h svalue.h stdstrings.h simulate.h prolang.h \
simulate.o : ../mudlib/sys/rtlimits.h ../mudlib/sys/regexp.h \
../mudlib/sys/files.h ../mudlib/sys/driver_hook.h \
../mudlib/sys/debug_info.h xalloc.h wiz_list.h svalue.h swap.h \
structs.h strfuns.h stdstrings.h simul_efun.h sent.h prolang.h \
../mudlib/sys/debug_info.h i-eval_cost.h xalloc.h wiz_list.h svalue.h \
swap.h structs.h strfuns.h stdstrings.h simul_efun.h sent.h prolang.h \
pkg-sqlite.h pkg-tls.h otable.h object.h mstrings.h mregex.h mempools.h \
mapping.h main.h lex.h interpret.h heartbeat.h gcollect.h filestat.h \
ed.h comm.h closure.h call_out.h backend.h array.h actions.h simulate.h \
my-alloca.h typedefs.h driver.h hash.h exec.h ptrtable.h bytecode.h \
mapping.h main.h lex.h heartbeat.h gcollect.h filestat.h ed.h comm.h \
closure.h call_out.h backend.h array.h actions.h simulate.h my-alloca.h \
typedefs.h driver.h interpret.h hash.h exec.h ptrtable.h bytecode.h \
port.h config.h hosts/unix.h hosts/be/be.h machine.h
sprintf.o : xalloc.h swap.h svalue.h structs.h stdstrings.h simul_efun.h \

View file

@ -496,12 +496,20 @@ remove_shadow_actions (object_t *shadow, object_t *target)
*/
{
#ifdef USE_INVENTORIES
# ifdef USE_INVENTORIES
object_t *item;
#endif
# endif
object_t *shadowing;
/* Get the real underlying object, just as add_action does. */
while ((target->flags & O_SHADOW)
&& NULL != (shadowing = O_GET_SHADOW(target)->shadowing))
{
target = shadowing;
}
remove_shadow_action_sent(shadow, target);
#ifdef USE_INVENTORIES
# ifdef USE_INVENTORIES
for (item = target->contains; item; item = item->next_inv)
{
if (shadow != item)
@ -517,7 +525,7 @@ remove_shadow_actions (object_t *shadow, object_t *target)
remove_shadow_action_sent(shadow, item);
}
}
#endif
# endif
} /* remove_shadow_actions() */
#endif
@ -1248,7 +1256,7 @@ execute_command (char *str, object_t *ob)
/* Save the current context */
save_command_context(&context);
context.rt.last = rt_context;
rt_context = (rt_context_t *)&context;
rt_context = (rt_context_t *)&context.rt;
/* Default settings */
command_giver = ob;
@ -1423,8 +1431,8 @@ e_add_action (svalue_t *func, svalue_t *cmd, p_int flag)
if ((size_t)(-flag) >= mstrsize(p->verb))
{
free_action_sent(p);
errorf("Bad arg 3 to add_action(): value %ld larger than verb '%s'.\n"
, (long)flag, get_txt(p->verb));
errorf("Bad arg 3 to add_action(): value %"PRIdPINT" larger than verb '%s'.\n"
, flag, get_txt(p->verb));
/* NOTREACHED */
return MY_TRUE;
}
@ -1437,8 +1445,8 @@ e_add_action (svalue_t *func, svalue_t *cmd, p_int flag)
else
{
free_action_sent(p);
errorf("Bad arg 3 to add_action(): value %ld too big.\n"
, (long)flag);
errorf("Bad arg 3 to add_action(): value %"PRIdPINT" too big.\n"
, flag);
/* NOTREACHED */
return MY_TRUE;
}
@ -1613,7 +1621,8 @@ f_execute_command (svalue_t *sp)
len = mstrsize(argp->u.str);
if (len >= sizeof(buf) - 1)
errorf("Command too long: '%.200s...'\n", get_txt(argp->u.str));
errorf("Command too long (size: %zu): '%.200s...'\n",
len, get_txt(argp->u.str));
strncpy(buf, get_txt(argp->u.str), len);
buf[len+1] = '\0';
@ -1940,7 +1949,7 @@ f_remove_action (svalue_t *sp)
*/
{
object_t *ob;
object_t *ob, *shadow_ob;
string_t *verb;
sentence_t **sentp;
action_t *s;
@ -1969,14 +1978,33 @@ f_remove_action (svalue_t *sp)
efun_gen_arg_error(1, sp[-1].type, sp);
/* NOTREACHED */
}
/* Now search and remove the sentence */
rc = 0;
sentp = &ob->sent;
ob = current_object;
shadow_ob = NULL;
/* Look for the underlying object, just as add_action does. */
if (ob->flags & O_SHADOW && O_GET_SHADOW(ob)->shadowing)
{
object_t *shadowing;
shadow_ob = ob;
while ((ob->flags & O_SHADOW)
&& NULL != (shadowing = O_GET_SHADOW(ob)->shadowing))
{
ob = shadowing;
}
}
/* Now search and remove the sentence */
while ( NULL != (s = (action_t *)*sentp) )
{
if (!SENT_IS_INTERNAL((*sentp)->type) && s->ob == ob && (!verb || s->verb == verb))
if (!SENT_IS_INTERNAL((*sentp)->type) && s->ob == ob
&& (!verb || s->verb == verb)
&& (!shadow_ob || s->shadow_ob == shadow_ob))
{
#ifdef CHECK_OBJECT_REF
if (sentp == &ob->sent)
@ -2281,7 +2309,7 @@ f_disable_commands (svalue_t *sp)
return sp;
if (d_flag > 1) {
debug_message("%s Disable commands %s (ref %ld)\n"
debug_message("%s Disable commands %s (ref %"PRIdPINT")\n"
, time_stamp(), get_txt(current_object->name)
, current_object->ref);
}
@ -2311,7 +2339,7 @@ f_enable_commands (svalue_t *sp)
return sp;
if (d_flag > 1) {
debug_message("%s Enable commands %s (ref %ld)\n"
debug_message("%s Enable commands %s (ref %"PRIdPINT")\n"
, time_stamp(), get_txt(current_object->name)
, current_object->ref);
}
@ -2545,8 +2573,8 @@ f_set_modify_command (svalue_t *sp)
else
{
if (sp->u.number != -1)
errorf("Bad num arg 1 to set_modify_command(): got %ld, "
"expected 0 or -1\n", sp->u.number);
errorf("Bad num arg 1 to set_modify_command(): got %"PRIdPINT
", expected 0 or -1\n", sp->u.number);
if (old) ref_object(old, "set_modify_command");
}
}

View file

@ -63,7 +63,7 @@
#include "array.h"
#include "backend.h"
#include "closure.h" /* closure_cmp(), closure_eq() */
#include "interpret.h" /* for the efuns */
#include "interpret.h"
#include "main.h"
#include "mapping.h"
#include "mempools.h"
@ -133,7 +133,7 @@ _allocate_array(mp_int n MTRACE_DECL)
svalue_t *svp;
if (n < 0 || (max_array_size && (size_t)n > max_array_size))
errorf("Illegal array size: %ld.\n", n);
errorf("Illegal array size: %"PRIdMPINT".\n", n);
if (n == 0) {
p = ref_array(&null_vector);
@ -145,10 +145,11 @@ _allocate_array(mp_int n MTRACE_DECL)
p = ALLOC_VECTOR(n);
if (!p) {
#ifndef MALLOC_TRACE
(*allocate_array_error_handler)("Out of memory: array[%ld]\n", n);
(*allocate_array_error_handler)
("Out of memory: array[%"PRIdMPINT"]\n", n);
#else
(*allocate_array_error_handler)
("(%s:%d) Out of memory: array[%ld]\n"
("(%s:%d) Out of memory: array[%"PRIdMPINT"]\n"
MTRACE_PASS, n);
#endif
return 0;
@ -191,7 +192,7 @@ _allocate_array_unlimited(mp_int n MTRACE_DECL)
svalue_t *svp;
if (n < 0)
errorf("Illegal array size: %ld.\n", n);
errorf("Illegal array size: %"PRIdMPINT".\n", n);
if (n == 0) {
p = ref_array(&null_vector);
@ -204,10 +205,10 @@ _allocate_array_unlimited(mp_int n MTRACE_DECL)
if (!p) {
#ifndef MALLOC_TRACE
(*allocate_array_error_handler)
("Out of memory: unlimited array[%ld]\n", n);
("Out of memory: unlimited array[%"PRIdMPINT"]\n", n);
#else
(*allocate_array_error_handler)
("(%s:%d) Out of memory: unlimited array[%ld]\n"
("(%s:%d) Out of memory: unlimited array[%"PRIdMPINT"]\n"
MTRACE_PASS, n);
#endif
return 0;
@ -247,7 +248,7 @@ _allocate_uninit_array (mp_int n MTRACE_DECL)
vector_t *p;
if (n < 0 || (max_array_size && (size_t)n > max_array_size))
errorf("Illegal array size: %ld.\n", n);
errorf("Illegal array size: %"PRIdMPINT".\n", n);
if (n == 0) {
p = ref_array(&null_vector);
@ -260,10 +261,10 @@ _allocate_uninit_array (mp_int n MTRACE_DECL)
if (!p) {
#ifndef MALLOC_TRACE
(*allocate_array_error_handler)
("Out of memory: uninited array[%ld]\n", n);
("Out of memory: uninited array[%"PRIdMPINT"]\n", n);
#else
(*allocate_array_error_handler)
("(%s:%d) Out of memory: uninited array[%ld]\n"
("(%s:%d) Out of memory: uninited array[%"PRIdMPINT"]\n"
MTRACE_PASS, n);
#endif
return 0;
@ -293,7 +294,8 @@ _free_vector (vector_t *p)
#ifdef DEBUG
if (p->ref > 0)
fatal("Vector with %ld refs passed to _free_vector()\n", p->ref);
fatal("Vector with %"PRIdPINT" refs passed to _free_vector()\n",
p->ref);
if (p == &null_vector)
fatal("Tried to free the zero-size shared vector.\n");
#endif
@ -1860,7 +1862,7 @@ v_allocate (svalue_t *sp, int num_arg)
size = svp->u.number;
if (size < 0 || (max_array_size && (size_t)size > max_array_size))
errorf("Illegal array size: %ld\n", (long)size);
errorf("Illegal array size: %"PRIdPINT"\n", size);
if (size == 0 && dim < num_dim-1)
errorf("Only the last dimension can have empty arrays.\n");
@ -2186,7 +2188,8 @@ x_map_array (svalue_t *sp, int num_arg)
res = allocate_array(cnt);
if (!res)
errorf("(map_array) Out of memory: array[%ld] for result\n", cnt);
errorf("(map_array) Out of memory: array[%"PRIdMPINT
"] for result\n", cnt);
push_array(inter_sp, res); /* In case of errors */
for (w = arr->item, x = res->item; --cnt >= 0; w++, x++)
@ -2224,7 +2227,8 @@ x_map_array (svalue_t *sp, int num_arg)
res = allocate_array(cnt);
if (!res)
errorf("(map_array) Out of memory: array[%ld] for result\n", cnt);
errorf("(map_array) Out of memory: array[%"PRIdMPINT
"] for result\n", cnt);
push_array(inter_sp, res); /* In case of errors */
/* Loop through arr and res, mapping the values from arr */

View file

@ -7,49 +7,6 @@
#include "typedefs.h"
#include "svalue.h"
/* --- Macros --- */
/* vector_t *ref_array(vector_t *a)
* Add another ref to array <a> and return the vector <a>.
*/
#define ref_array(a) ((a)->ref++, (a))
/* void free_array(vector_t *a)
* Subtract one ref from array <a>, and free the array fully if
* the refcount reaches zero.
*/
#define free_array(a) MACRO( if (--((a)->ref) <= 0) _free_vector(a); )
/* p_int deref_array(vector_t *a)
* Subtract one ref from array <a>, but don't check if it needs to
* be freed. Result is the number of refs left.
*/
#define deref_array(a) (--(a)->ref)
/* See array.c for a description of what the following macros do. */
/* Helper for LOCAL_VECn() */
#ifdef DEBUG
# define VEC_DEBUGREF(ref) ref,
#else
# define VEC_DEBUGREF(ref)
#endif
#include "svalue.h"
#define VEC_HEAD(size) size, 1, VEC_DEBUGREF(1) NULL
#define VEC_SIZE(v) ((v)->size)
#define LOCAL_VEC1(name, type1) \
struct { vector_t v; } name \
= { { VEC_HEAD(1), { { type1, { 0 } } } } }
#define LOCAL_VEC2(name, type1, type2) \
struct { vector_t v; svalue_t item[1]; } name \
= { { VEC_HEAD(2), { { type1, { 0 } } } }, { { type2, { 0 } } } }
/* --- Types --- */
@ -70,6 +27,30 @@ struct vector_s {
};
/* --- Macros --- */
/* See array.c for a description of what the following macros do. */
/* Helper for LOCAL_VECn() */
#ifdef DEBUG
# define VEC_DEBUGREF(ref) ref,
#else
# define VEC_DEBUGREF(ref)
#endif
#define VEC_HEAD(size) size, 1, VEC_DEBUGREF(1) NULL
#define VEC_SIZE(v) ((v)->size)
#define LOCAL_VEC1(name, type1) \
struct { vector_t v; } name \
= { { VEC_HEAD(1), { { type1, { 0 } } } } }
#define LOCAL_VEC2(name, type1, type2) \
struct { vector_t v; svalue_t item[1]; } name \
= { { VEC_HEAD(2), { { type1, { 0 } } } }, { { type2, { 0 } } } }
/* --- Variables --- */
extern vector_t null_vector;
@ -77,6 +58,7 @@ extern vector_t null_vector;
extern int num_arrays;
extern void (*allocate_array_error_handler) (const char *, ...);
/* --- Prototypes --- */
#if defined(MALLOC_TRACE)
@ -134,4 +116,33 @@ extern void clear_array_size (void);
extern void count_array_size (vector_t *vec);
#endif
/* --- static helper functions --- */
/* vector_t *ref_array(vector_t *a)
* Add another ref to array <a> and return the vector <a>.
*/
static INLINE vector_t* ref_array(vector_t *a) {
++a->ref;
return a;
}
/* void free_array(vector_t *a)
* Subtract one ref from array <a>, and free the array fully if
* the refcount reaches zero.
*/
static INLINE void free_array(vector_t *a) {
if (--(a->ref) <= 0)
_free_vector(a);
}
/* p_int deref_array(vector_t *a)
* Subtract one ref from array <a>, but don't check if it needs to
* be freed. Result is the number of refs left.
*/
static INLINE p_int deref_array(vector_t *a) {
return --a->ref;
}
#endif /* ARRAY_H__ */

View file

@ -74,6 +74,8 @@
#include "wiz_list.h"
#include "xalloc.h"
#include "i-eval_cost.h"
#include "../mudlib/sys/driver_hook.h"
#include "../mudlib/sys/debug_message.h"
@ -122,9 +124,9 @@ uint num_last_data_cleaned = 0;
/* Number of object data-cleaned in last process_objects().
*/
statistic_t stat_last_processed = { 0 };
statistic_t stat_last_data_cleaned = { 0 };
statistic_t stat_in_list = { 0 };
statistic_t stat_last_processed = { 0, 0, 0.0 };
statistic_t stat_last_data_cleaned = { 0, 0, 0.0 };
statistic_t stat_in_list = { 0, 0, 0.0 };
/* Decaying average number of objects processed and objects in the list.
*/
@ -151,12 +153,12 @@ Bool mud_is_up = MY_FALSE;
*/
#endif
statistic_t stat_load = { 0 };
statistic_t stat_load = { 0, 0, 0.0 };
/* The load average (player commands/second), weighted over the
* last period of time.
*/
statistic_t stat_compile = { 0 };
statistic_t stat_compile = { 0, 0, 0.0 };
/* The average of compiled lines/second, weighted over the last period
* of time.
*/
@ -337,7 +339,7 @@ handle_usr1 (int sig UNUSED)
#ifndef RETSIGTYPE_VOID
return 0;
#endif
} /* handle_usr1() */
} /* handle_usr2() */
/*-------------------------------------------------------------------------*/
static RETSIGTYPE
@ -614,7 +616,7 @@ backend (void)
/* puts("Handling outgoing connections."); */
check_for_out_connections();
} else
extra_jobs_to_do = MY_FALSE;
extra_jobs_to_do = MY_FALSE;
} /* if (extra_jobs_to_do */
@ -841,8 +843,9 @@ void check_alarm (void)
}
else if (curtime - last_alarm_time > 15)
{
debug_message("%s Last alarm was %ld seconds ago - restarting it.\n"
, time_stamp(), curtime - last_alarm_time);
debug_message("%s Last alarm was %"PRIdMPINT" seconds ago "
"- restarting it.\n",
time_stamp(), curtime - last_alarm_time);
alarm(0); /* stop alarm in case it is still alive, but just slow */
comm_time_to_call_heart_beat = MY_TRUE;
@ -931,7 +934,7 @@ static Bool did_swap;
error_recovery_info.rt.last = rt_context;
error_recovery_info.rt.type = ERROR_RECOVERY_BACKEND;
rt_context = (rt_context_t *)&error_recovery_info;
rt_context = (rt_context_t *)&error_recovery_info.rt;
if (setjmp(error_recovery_info.con.text))
{

View file

@ -64,10 +64,10 @@ last_bit (string_t *str)
*/
{
mp_int pos;
long len;
char * cstr;
int c;
mp_int pos;
long len;
const char * cstr;
int c;
pos = -1;
@ -624,7 +624,7 @@ f_count_bits (svalue_t *sp)
} /* f_count_bits() */
/*-------------------------------------------------------------------------*/
static INLINE void
static void
copy_bits ( string_t * dest, p_int deststart
, string_t * src, p_int srcstart
, p_int len

View file

@ -232,7 +232,7 @@ typedef bytecode_t * bytecode_p;
RSTORE_2BYTE(p,_us);)
#else
# error "Unsupported size of short."
#endif
#endif /* SIZEOF_SHORT */
#if SIZEOF_LONG == 4
# define GET_LONG(d,p) GET_4BYTE(d,p)
@ -256,7 +256,7 @@ typedef bytecode_t * bytecode_p;
RSTORE_4BYTE(p,_ui);)
#else
# error "Unsupported size of long."
#endif
#endif /* SIZEOF_LONG */
#define LOAD_INT16(d,p) LOAD_2BYTE(d,p)
@ -280,7 +280,7 @@ typedef bytecode_t * bytecode_p;
# define LOAD_INT32(d,p) LOAD_2BYTE(d,p)
#endif
#endif
#endif /* CHAR_BIT */
#ifndef GET_CODE
# error "No bytecode type defined."

View file

@ -46,6 +46,8 @@
#include "wiz_list.h"
#include "xalloc.h"
#include "i-eval_cost.h"
#include "../mudlib/sys/debug_info.h"
/*-------------------------------------------------------------------------*/
@ -262,7 +264,7 @@ call_out (void)
error_recovery_info.rt.last = rt_context;
error_recovery_info.rt.type = ERROR_RECOVERY_BACKEND;
rt_context = (rt_context_t *)&error_recovery_info;
rt_context = (rt_context_t *)&error_recovery_info.rt;
if (setjmp(error_recovery_info.con.text))
{

View file

@ -344,6 +344,9 @@ static work_area_t current
/* Forward declarations */
static void lambda_error VARPROT((const char *error_str, ...), printf, 1, 2) NORETURN;
static void lambda_cerror(const char *s) FORMATDEBUG(printf,1,0) NORETURN;
static void lambda_cerrorl(const char *s1, const char *s2 UNUSED, int line1 UNUSED,
int line2 UNUSED) NORETURN FORMATDEBUG(printf,1,0);
static void free_symbols(void);
static Bool is_lvalue (svalue_t *argp, int index_lvalue);
static void compile_lvalue(svalue_t *, int);
@ -939,7 +942,7 @@ replace_program_lambda_adjust (replace_ob_t *r_ob)
error_recovery_info.rt.last = rt_context;
error_recovery_info.rt.type = ERROR_RECOVERY_BACKEND;
rt_context = (rt_context_t *)&error_recovery_info;
rt_context = (rt_context_t *)&error_recovery_info.rt;
if (setjmp(error_recovery_info.con.text))
{
bytecode_p p;
@ -1347,8 +1350,9 @@ realloc_values (void)
new_values = xalloc(new_max * sizeof(*new_values));
if (!new_values)
lambda_error("Out of memory (%lu bytes) for %ld new values\n"
, new_max, new_max * sizeof(*new_values));
lambda_error("Out of memory (%"PRIdMPINT
" bytes) for %"PRIdMPINT" new values\n",
new_max, new_max * sizeof(*new_values));
current.values_left += current.value_max;
memcpy( (current.valuep = new_values + current.value_max)
@ -1380,7 +1384,8 @@ realloc_code (void)
new_max = current.code_max * 2;
new_code = rexalloc(current.code, (size_t)new_max);
if (!new_code)
lambda_error("Out of memory (%ld bytes) for new code\n", new_max);
lambda_error("Out of memory (%"PRIdMPINT" bytes) for new code\n",
new_max);
current.code_left += current.code_max;
current.code_max = new_max;
@ -1595,7 +1600,7 @@ make_symbol (string_t *name)
if (!symp) {
current.symbol_max /= 2;
xfree(sym);
lambda_error("Out of memory (%ld bytes) for symbol table\n"
lambda_error("Out of memory (%"PRIdMPINT" bytes) for symbol table\n"
, current.symbol_max);
}
current.symbol_mask = i = current.symbol_max - (long)sizeof sym;
@ -5200,8 +5205,8 @@ lambda (vector_t *args, svalue_t *block, object_t *origin)
current.code_left = CODE_BUFFER_START_SIZE-3;
current.levels_left = MAX_LAMBDA_LEVELS;
if ( !(current.code = current.codep = xalloc((size_t)current.code_max)) )
lambda_error("Out of memory (%ld bytes) for initial codebuffer\n"
, current.code_max);
lambda_error("Out of memory (%"PRIdMPINT
" bytes) for initial codebuffer\n", current.code_max);
/* Store the lambda code header */
STORE_UINT8(current.codep, 0); /* dummy for num values */
@ -5212,8 +5217,9 @@ lambda (vector_t *args, svalue_t *block, object_t *origin)
if ( !(current.values =
xalloc(current.value_max * sizeof current.values[0])) )
{
lambda_error("Out of memory (%lu bytes) for initial value buffer\n"
, current.value_max * sizeof current.values[0]);
lambda_error("Out of memory (%"PRIdMPINT
" bytes) for initial value buffer\n",
current.value_max * sizeof current.values[0]);
}
current.valuep = current.values + current.value_max;

View file

@ -9,6 +9,10 @@
#include "svalue.h"
#endif /* USE_NEW_INLINES */
/* In case offsetof() is not a compiler builtin include stddef.h which
* supplies a define as fallback. Needed for LAMBDA_VALUE_OFFSET */
#include <stddef.h>
/* --- Types --- */
/* --- struct lambda_s: ---

File diff suppressed because it is too large Load diff

View file

@ -156,6 +156,10 @@ struct input_to_s {
*
* When changing struct members, take care that you don't introduce
* unnecessary padding.
*
* If the CBool members should ever be changed to C99's _Bool, take care of
* checking who is relying on a specific size (e.g. some printf())
*
*/
struct interactive_s {
@ -416,7 +420,7 @@ extern void add_message VARPROT((const char *, ...), printf, 1, 2);
extern void flush_all_player_mess(void);
extern Bool get_message(char *buff, size_t *len);
extern void remove_interactive(object_t *ob, Bool force);
extern void set_noecho(interactive_t *i, char noecho, Bool local_change);
extern void set_noecho(interactive_t *i, char noecho, Bool local_change, Bool external);
extern int find_no_bang (interactive_t *ip);
extern Bool call_function_interactive(interactive_t *i, char *str, size_t len);
extern void remove_all_players(void);

View file

@ -14,6 +14,9 @@
#include "config.h"
/* Include the portability headers */
#include "port.h"
/* TODO: Some TODO defines */
/* NO_NEGATIVE_RANGES: If defined, assignments to negative ranges
@ -46,17 +49,26 @@
# define GC_SUPPORT 1
#endif
/* Do some of the selected packages require special treatment? */
/* SQLite in the threadsafe mode needs a normal malloc() */
#if defined(SBRK_OK) && defined(USE_SQLITE)
# undef SBRK_OK
#endif
/* ptmalloc only works correctly with SBRK_OK right now. */
#ifdef MALLOC_ptmalloc
# ifndef SBRK_OK
# define SBRK_OK
# endif
#else // no ptmalloc
/* SQLite in the threadsafe mode needs a normal malloc() if the allocator is
* not ptmalloc*/
# if defined(SBRK_OK) && defined(USE_SQLITE) && defined(SQLITE3_USES_PTHREADS)
# undef SBRK_OK
# endif
/* PTHREADS need a normal malloc() if the allocator is not ptmalloc */
# if defined(SBRK_OK) && defined(USE_PTHREADS)
# undef SBRK_OK
# endif
#endif // MALLOC_ptmalloc
/* PTHREADS need a normal malloc() */
#if defined(SBRK_OK) && (defined(USE_PTHREADS) || defined(SQLITE3_USES_PTHREADS))
# undef SBRK_OK
#endif
/* When we have allocation tracing, the allocator annotates every
* allocation with the source filename and line where the allocation
@ -131,9 +143,6 @@
# define __IPV6__
#endif
/* Include the portability headers */
#include "port.h"
/* TODO: this ctype-stuff might go into lex.h (impl in efun_defs.c) */
#define _MCTe 0x01 /* escaped character in save/restore object. */
#define _MCTd 0x02 /* numeric digit */
@ -166,4 +175,10 @@ extern unsigned char _my_ctype[];
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif /* MIN */
/* For the use of mudlib/sys/debug_info.h.
*/
#ifdef EVAL_COST_TRACE
#define __EVAL_COST_TRACE__
#endif
#endif /* DRIVER_H__ */

View file

@ -346,7 +346,7 @@ dumpstat (string_t *fname)
overhead += sizeof (object_t);
fprintf(f, "%-20s %5ld (%5ld) ref %2ld %s "
fprintf(f, "%-20s %5"PRIdMPINT" (%5"PRIdMPINT") ref %2"PRIdPINT" %s "
, get_txt(ob->name)
, compsize + overhead, totalsize + overhead
, ob->ref
@ -360,14 +360,15 @@ dumpstat (string_t *fname)
fprintf(f, "-- ");
if (ob->gigaticks)
fprintf(f, " (%lu%09lu)", ob->gigaticks, ob->ticks);
fprintf(f, " (%"PRIuMPINT"%09"PRIuMPINT")",
(mp_uint)ob->gigaticks, (mp_uint)ob->ticks);
else
fprintf(f, " (%lu)", ob->ticks);
fprintf(f, " (%"PRIuMPINT")", (mp_uint)ob->ticks);
fprintf(f, " %s",
swapstrings[(O_PROG_SWAPPED(ob)?1:0) | (O_VAR_SWAPPED(ob)?2:0)]
);
tm = localtime((time_t *)&ob->load_time);
strftime(timest, sizeof(timest)-1, "%Y.%m.%d-%H:%M:%S", tm);
strftime(timest, sizeof(timest), "%Y.%m.%d-%H:%M:%S", tm);
fprintf(f, " %s\n", timest);
}
fclose(f);
@ -406,7 +407,7 @@ dumpstat_dest(string_t *fname)
if (!(ob->flags & O_DESTRUCTED)) /* TODO: Can't happen */
continue;
#endif
fprintf(f, "%-20s ref %2ld NEW\n"
fprintf(f, "%-20s ref %2"PRIdPINT" NEW\n"
, get_txt(ob->name)
, ob->ref
);
@ -418,7 +419,7 @@ dumpstat_dest(string_t *fname)
if (!(ob->flags & O_DESTRUCTED)) /* TODO: Can't happen */
continue;
#endif
fprintf(f, "%-20s ref %2ld\n"
fprintf(f, "%-20s ref %2"PRIdPINT"\n"
, get_txt(ob->name)
, ob->ref
);

View file

@ -362,7 +362,7 @@ static void count_blanks(int line);
static void _count_blanks(char *str, int blanks);
static LINE *getptr(int num);
static void putcntl(char c);
static void prntln(char *str, int vflg, int lin);
static void prntln(char *str, Bool vflg, int lin);
static regexp_t *optpat(void);
/*-------------------------------------------------------------------------*/
@ -2917,6 +2917,7 @@ docmd (Bool glob)
free_mstring(fptr);
return err;
}
free_mstring(fptr);
P_FCHANGED = TRUE;
break;
@ -3257,8 +3258,12 @@ clear_ed_buffer_refs (ed_buffer_t *b)
{
object_t *ob;
if (b->fname)
clear_string_ref(b->fname);
if (b->exit_fn)
{
clear_string_ref(b->exit_fn);
if ( NULL != (ob = b->exit_ob) )
{
if (ob->flags & O_DESTRUCTED)

File diff suppressed because it is too large Load diff

View file

@ -76,21 +76,26 @@ extern svalue_t *f_localtime (svalue_t *sp);
extern svalue_t *f_blueprint (svalue_t *sp);
extern svalue_t *v_clones (svalue_t *sp, int num_args);
extern svalue_t *v_object_info (svalue_t *sp, int num_args);
extern svalue_t *f_present_clone (svalue_t *sp);
extern svalue_t *v_present_clone (svalue_t *sp, int num_arg);
extern svalue_t *f_to_object(svalue_t *sp);
extern svalue_t *f_set_is_wizard(svalue_t *sp); /* optional */
extern svalue_t *tell_room(svalue_t *sp);
extern svalue_t *f_ctime(svalue_t *);
extern svalue_t *v_strftime(svalue_t *, int num_arg);
extern svalue_t *v_debug_info(svalue_t *sp, int num_arg);
extern svalue_t *f_rusage(svalue_t *sp);
extern svalue_t *f_random(svalue_t *);
extern svalue_t *f_shutdown(svalue_t *sp);
extern svalue_t *f_time(svalue_t *);
extern svalue_t *f_utime(svalue_t *);
extern svalue_t *f_mktime(svalue_t *);
extern svalue_t *f_strftime(svalue_t *);
extern svalue_t *f_strptime(svalue_t *);
extern svalue_t *f_mktime(svalue_t *);
extern svalue_t *f_utime(svalue_t *);
#ifdef GC_SUPPORT
extern void clear_ref_from_efuns(void);
extern void count_ref_from_efuns(void);
#endif /* GC_SUPPORT */
#endif /* EFUNS_H__ */

View file

@ -46,7 +46,7 @@ extern int lstat(const char *, struct stat *);
#ifdef SunOS4
# if !defined (__GNUC__) || __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
extern int lstat(CONST char *, struct stat *);
extern int lstat (CONST char *, struct stat *);
# endif
extern int fchmod(int, int);
#endif
@ -74,10 +74,6 @@ extern int fchmod(int, int);
#include "../mudlib/sys/files.h"
/* TODO: The move/copy code is a derivate of the GNU fileutils. Rewrite
* TODO:: it, replace it by the BSD code, or put the driver under the GPL.
*/
/*-------------------------------------------------------------------------*/
static Bool
isdir (const char *path)
@ -115,95 +111,81 @@ copy_file (const char *from, const char *to, int mode)
*/
{
int ifd;
int ofd;
char buf[1024 * 8];
int len; /* Number of bytes read into `buf'. */
if (unlink(to) && errno != ENOENT)
int fromfd, tofd;
ssize_t count;
char buf[4096];
fromfd = ixopen(from, O_RDONLY);
if (fromfd < 0)
{
debug_message("copy_file(): cannot remove `%s'\n", to);
debug_message("copy_file(): can't open '%s': %s\n", from, strerror(errno));
return 1;
}
/* We have to unlink 'to', because it may be a symlink.
O_CREAT won't remove that. */
if (unlink(to) < 0 && errno != ENOENT)
{
debug_message("copy_file(): can't unlink '%s': %s\n", to, strerror(errno));
close(fromfd);
return 1;
}
tofd = ixopen3(to, O_WRONLY|O_CREAT|O_TRUNC, mode);
if (tofd < 0)
{
debug_message("copy_file(): can't open '%s': %s\n", to, strerror(errno));
close(fromfd);
return 1;
}
ifd = ixopen3(from, O_RDONLY | O_BINARY, 0);
if (ifd < 0)
#ifdef HAVE_FCHMOD
/* We have given the file mode to ixopen3, this is just to counter umask.
So don't worry if this fchmod fails. */
fchmod(tofd, mode);
#endif
do
{
debug_message("copy_file(): %s: open failed\n", from);
return errno;
}
ofd = ixopen3(to, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600);
if (ofd < 0)
{
debug_message("copy_file(): %s: open failed\n", to);
close(ifd);
return 1;
}
#ifdef HAVE_FCHMOD
if (fchmod(ofd, mode))
{
debug_message("copy_file(): %s: fchmod failed\n", to);
close(ifd);
close(ofd);
unlink(to);
return 1;
}
#endif
ssize_t written;
count = read(fromfd, buf, sizeof(buf));
if (count < 0)
{
debug_message("copy_file(): can't read from '%s': %s\n", from, strerror(errno));
close(fromfd);
close(tofd);
unlink(to);
return 1;
}
written = 0;
while (written < count)
{
ssize_t len;
len = write(tofd, buf + written, count - written);
if (len <= 0)
{
debug_message("copy_file(): can't write to '%s': %s\n", to, strerror(errno));
close(fromfd);
close(tofd);
unlink(to);
return 1;
}
written += len;
}
} while (count > 0);
FCOUNT_READ(from);
FCOUNT_WRITE(to);
while ((len = read(ifd, buf, sizeof (buf))) > 0)
{
int wrote = 0;
char *bp = buf;
do
{
wrote = write(ofd, bp, len);
if (wrote < 0)
{
debug_message("copy_file(): %s: write failed\n", to);
close(ifd);
close(ofd);
unlink(to);
return 1;
}
bp += wrote;
len -= wrote;
} while (len > 0);
}
if (len < 0)
{
debug_message("copy_file(): %s: read failed\n", from);
close(ifd);
close(ofd);
unlink(to);
return 1;
}
if (close (ifd) < 0)
{
debug_message("copy_file(): %s: close failed\n", from);
close(ofd);
return 1;
}
if (close (ofd) < 0)
{
debug_message("copy_file(): %s: close failed\n", to);
return 1;
}
close(fromfd);
close(tofd);
#ifndef HAVE_FCHMOD
if (chmod (to, mode))
{
debug_message("copy_file(): %s: chmod failed\n", to);
return 1;
}
chmod(to, mode);
#endif
return 0;
@ -218,80 +200,55 @@ move_file (const char *from, const char *to)
*/
{
struct stat to_stats, from_stats;
if (lstat(from, &from_stats) != 0)
struct stat fromstat, tostat;
if (lstat(from, &fromstat) < 0)
{
debug_message("move_file(): %s: lstat failed\n", from);
debug_message("move_file(): can't lstat '%s': %s\n", from, strerror(errno));
return 1;
}
if (lstat (to, &to_stats) == 0)
if (!lstat(to, &tostat))
{
if (from_stats.st_dev == to_stats.st_dev
&& from_stats.st_ino == to_stats.st_ino)
if (fromstat.st_dev == tostat.st_dev
&& fromstat.st_ino == tostat.st_ino)
{
debug_message("move_file(): '%s' and '%s' are the same file\n", from, to);
/* Same file. */
debug_message("move_file(): '%s' and '%s' are the same.\n", from, to);
return 1;
}
if (S_ISDIR (to_stats.st_mode))
if (S_ISDIR(tostat.st_mode))
{
debug_message("move_file(): %s: cannot overwrite directory\n", to);
debug_message("move_file(): destination '%s' is a directory.\n", to);
return 1;
}
}
if (rename(from, to))
{
if (errno == EXDEV)
{
if (!S_ISREG(fromstat.st_mode))
{
debug_message("move_file(): can't move '%s' across filesystems: Not a regular file.\n", to);
return 1;
}
if (copy_file(from, to, fromstat.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)))
return 1;
unlink(from);
}
else
{
debug_message("move_file(): can't rename '%s' to '%s': %s\n", to, from, strerror(errno));
return 1;
}
}
else if (errno != ENOENT)
{
perror("do_move");
debug_message("move_file(): %s: unknown error\n", to);
return 1;
}
#ifndef RENAME_HANDLES_DIRECTORIES
/* old SYSV */
if (isdir(from))
{
char cmd_buf[3*MAXPATHLEN+1];
if (strchr(from, '\'') || strchr(to, '\''))
return 0;
sprintf(cmd_buf, "/usr/lib/mv_dir '%s' '%s'", from, to);
return system(cmd_buf);
}
else
#endif /* RENAME_HANDLES_DIRECTORIES */
if (rename (from, to) == 0)
{
FCOUNT_DEL(from);
return 0;
}
if (errno != EXDEV)
{
debug_message("move_file(): cannot move '%s' to '%s'\n", from, to);
return 1;
}
/* rename failed on cross-filesystem link. Copy the file instead. */
if (!S_ISREG(from_stats.st_mode))
{
debug_message("move_file(): cannot move '%s' across filesystems: "
"Not a regular file\n", from);
return 1;
}
if (copy_file(from, to, from_stats.st_mode & 0777))
return 1;
if (unlink(from))
{
debug_message("move_file(): cannot remove '%s'\n", from);
return 1;
}
FCOUNT_DEL(from);
return 0;
} /* move_file() */
@ -1750,7 +1707,7 @@ f_write_file (svalue_t *sp)
break;
if (sp->u.number & 1)
if (remove(get_txt(file)))
if (remove(get_txt(file)) && errno != ENOENT)
{
perror("write_file (remove)");
errorf("Could not remove %s: errno %d.\n", get_txt(file), errno);

View file

@ -657,7 +657,7 @@ object first_inventory(object|string default: F_THIS_OBJECT);
object next_inventory(object default: F_THIS_OBJECT);
void move_object(object|string, object|string);
object present(object|string, void|int|object, void|object);
object present_clone(object|string, object default: F_THIS_OBJECT); /* PRELIMINARY */
object present_clone(object|string, object|int|void, int|void);
#ifdef USE_STRUCTS
void say(string|mixed *|object|mapping|struct, void|object|object *);
#else

View file

@ -94,6 +94,7 @@
#include "closure.h"
#include "comm.h"
#include "ed.h"
#include "efuns.h"
#include "filestat.h"
#include "heartbeat.h"
#include "interpret.h"
@ -124,6 +125,8 @@
#include "wiz_list.h"
#include "xalloc.h"
#include "i-eval_cost.h"
#include "../mudlib/sys/driver_hook.h"
/*-------------------------------------------------------------------------*/
@ -2094,6 +2097,7 @@ garbage_collection(void)
mstring_clear_refs();
clear_ref_from_wiz_list();
clear_ref_from_call_outs();
clear_ref_from_efuns();
#if defined(USE_PARSE_COMMAND)
clear_parse_refs();
#endif
@ -2313,6 +2317,7 @@ garbage_collection(void)
count_ref_from_wiz_list();
count_ref_from_call_outs();
count_ref_from_efuns();
if (master_ob)
master_ob->ref++;

View file

@ -57,6 +57,8 @@
#include "wiz_list.h"
#include "xalloc.h"
#include "i-eval_cost.h"
#include "../mudlib/sys/debug_info.h"
/*-------------------------------------------------------------------------*/
@ -165,7 +167,7 @@ call_heart_beat (void)
error_recovery_info.rt.last = rt_context;
error_recovery_info.rt.type = ERROR_RECOVERY_BACKEND;
rt_context = (rt_context_t *)&error_recovery_info;
rt_context = (rt_context_t *)&error_recovery_info.rt;
if (setjmp(error_recovery_info.con.text))
{

82
src/i-eval_cost.h Normal file
View file

@ -0,0 +1,82 @@
/*---------------------------------------------------------------------------
* Eval Cost functions.
*
*---------------------------------------------------------------------------
*/
#ifndef I_EVAL_COST__
#define I_EVAL_COST__
#include "driver.h"
#include "interpret.h"
/*-------------------------------------------------------------------------*/
static INLINE Bool
add_eval_cost_n (int32 added_cost, uint repetitions)
/* Increase the evaluation cost by <added_cost>*<repetitions>. Return TRUE if
* this would exceed max_eval_cost, return FALSE if not.
*
* Passing <repetitions> explicitely guards against situations where
* <added_cost>*<repetitions> itself would overflow.
*
* To safeguard the driver against ridiculous executions, the actual eval_cost
* is capped at max_eval_cost+1.
*/
{
if (repetitions == 0)
return MY_FALSE;
if (max_eval_cost)
{
/* Test the evaluation cost against the limit.
* eval_cost < 0 signify a wrap-around - unlikely, but with these crazy
* wizards everything is possible.
*/
if (eval_cost >= max_eval_cost || eval_cost < 0)
return MY_TRUE;
if (max_eval_cost - eval_cost < added_cost
|| (int32)((max_eval_cost - eval_cost) / repetitions) < added_cost
)
{
total_evalcost += max_eval_cost - eval_cost + 1;
eval_cost = max_eval_cost+1;
return MY_TRUE;
}
}
eval_cost += added_cost * repetitions;
total_evalcost += added_cost * repetitions;
return MY_FALSE;
} /* add_eval_cost_n() */
/*-------------------------------------------------------------------------*/
/* --- Macros --- */
/* Increase the eval cost for a non-repetitive action.
*/
#define add_eval_cost(cost) add_eval_cost_n(cost, 1)
/* Reset the evaluation cost/time counter.
*/
#define CLEAR_EVAL_COST (assigned_eval_cost = eval_cost = 0)
/* Check if the current evaluation took too long
*/
#define EVALUATION_TOO_LONG() \
(max_eval_cost && (eval_cost >= max_eval_cost || eval_cost < 0))
/* Return the amount of remaining evaluation costs, or MAX_INT if there
* is no real maximum.
*/
#define GET_REMAINING_EVAL_COST() \
( max_eval_cost ? ((eval_cost >= max_eval_cost || eval_cost < 0) ? 0 : (max_eval_cost - eval_cost)) : INT32_MAX)
/***************************************************************************/
#endif /* I_EVAL_COST__ */

View file

@ -37,7 +37,7 @@ svalue_cmp (svalue_t *left, svalue_t *right)
*/
{
register int d;
register p_int d;
if ( 0 != (d = left->type - right->type) ) return d;

File diff suppressed because it is too large Load diff

View file

@ -78,23 +78,28 @@ struct control_stack {
* TODO: This should be mirrored in the current_object global variable,
* TODO:: to avoid accesses to wrong functions/variables.
*/
#ifdef EVAL_COST_TRACE
int32 eval_cost;
/* The eval cost at that moment. */
#endif
};
/* --- Macros --- */
/* a general error handler structure. head is assigned as payload to an
* T_LVALUE svalue of type T_ERROR_HANDLER and pushed onto the value stack.
* If the stack is unrolled during runtime errors the error_handler function
* is called and frees buff. */
typedef struct errorhandler_s {
svalue_t head; /* The T_ERROR_HANDLER structure */
char * buff; /* The allocated buffer to free. */
} errorhandler_t;
#define MAX_SHIFT ((sizeof(p_int) << 3) - 1)
/* --- Constants --- */
static const short MAX_SHIFT = (sizeof(p_int) << 3) - 1;
/* The maximally useful shift (left or right) of a number in LPC.
*/
/* Reset the evaluation cost/time counter.
*/
#define CLEAR_EVAL_COST (assigned_eval_cost = eval_cost = 0)
/* Check if the current evaluation took too long
*/
#define EVALUATION_TOO_LONG() \
(max_eval_cost && (eval_cost >= max_eval_cost || eval_cost < 0))
/* --- Variables --- */
extern program_t *current_prog;
@ -108,12 +113,11 @@ extern svalue_t *current_variables;
extern int32 eval_cost;
extern int32 assigned_eval_cost;
extern svalue_t apply_return_value;
extern svalue_t catch_value;
extern svalue_t last_indexing_protector;
#ifdef APPLY_CACHE_STAT
extern p_int apply_cache_hit;
extern p_int apply_cache_miss;
extern p_uint apply_cache_hit;
extern p_uint apply_cache_miss;
#endif
extern unsigned long total_evalcost;
@ -138,7 +142,8 @@ extern void push_control_stack(svalue_t *sp, bytecode_p pc, svalue_t *fp);
extern void pop_control_stack(void);
extern struct longjump_s *push_error_context(svalue_t *sp, int catch_flags);
extern void pop_error_context (void);
extern svalue_t *pull_error_context (svalue_t *sp);
extern svalue_t *pull_error_context (svalue_t *sp, svalue_t *msg);
extern void transfer_error_message (svalue_t *v, rt_context_t *rt);
extern Bool destructed_object_ref (svalue_t *svp);
extern void free_object_svalue(svalue_t *v);
extern void zero_object_svalue(svalue_t *v);
@ -156,6 +161,11 @@ extern void push_svalue(svalue_t *v);
extern void push_svalue_block(int num, svalue_t *v);
extern svalue_t *pop_n_elems (int n, svalue_t *sp);
extern void pop_stack(void);
extern void push_apply_value(void);
extern void pop_apply_value (void);
extern void push_referenced_mapping(mapping_t *m);
extern svalue_t *push_error_handler(void (*errorhandler)(svalue_t *), svalue_t *arg);
extern void *xalloc_with_error_handler(size_t size);
extern void init_interpret(void);
extern const char *typename(int type);
@ -170,8 +180,7 @@ extern void vefun_exp_arg_error (int arg, long expected, int got, svalue_t *sp)
extern Bool privilege_violation(string_t *what, svalue_t *arg, svalue_t *sp);
extern Bool privilege_violation2(string_t *what, svalue_t *arg, svalue_t *arg2, svalue_t *sp);
extern Bool privilege_violation4(string_t *what, object_t *whom, string_t *how_str, int how_num, svalue_t *sp);
extern void push_apply_value(void);
extern void pop_apply_value (void);
extern svalue_t *sapply_int(string_t *fun, object_t *ob, int num_arg, Bool b_ign_prot, Bool b_use_default);
#define sapply(f,o,n) sapply_int(f,o,n, MY_FALSE, MY_TRUE)
#define sapply_ign_prot(f,o,n) sapply_int(f,o,n, MY_TRUE, MY_TRUE)
@ -182,7 +191,11 @@ extern string_t *collect_trace(strbuf_t * sbuf, vector_t ** rvec);
extern string_t *dump_trace(Bool how, vector_t **rvec);
extern int get_line_number_if_any(string_t **name);
extern void reset_machine(Bool first);
extern svalue_t *secure_apply(string_t *fun, object_t *ob, int num_arg);
extern void secure_apply_error(svalue_t *save_sp, struct control_stack *save_csp, Bool clear_costs);
extern svalue_t *secure_apply_ob(string_t *fun, object_t *ob, int num_arg, Bool external);
#define secure_apply(fun, ob, num_arg) secure_apply_ob(fun, ob, num_arg, MY_FALSE)
#define secure_callback(fun, ob, num_arg) secure_apply_ob(fun, ob, num_arg, MY_TRUE)
extern svalue_t *apply_master_ob(string_t *fun, int num_arg, Bool external);
#define apply_master(fun, num_arg) apply_master_ob(fun, num_arg, MY_FALSE)
#define callback_master(fun, num_arg) apply_master_ob(fun, num_arg, MY_TRUE)
@ -198,12 +211,9 @@ extern void int_call_lambda(svalue_t *lsvp, int num_arg, Bool allowRefs);
extern inherit_t *adjust_variable_offsets(const inherit_t *inheritp, const program_t *prog, const object_t *obj);
extern void free_interpreter_temporaries(void);
extern void invalidate_apply_low_cache(void);
extern void push_referenced_mapping(mapping_t *m);
extern void push_error_handler(void (*errorhandler)(svalue_t *), svalue_t *arg);
extern void m_indices_filter (svalue_t *key, svalue_t *data, void *extra);
extern void m_values_filter (svalue_t *key, svalue_t *data, void *extra);
extern void m_unmake_filter ( svalue_t *key, svalue_t *data, void *extra);
extern int last_instructions(int length, Bool verbose, svalue_t **svpp);
extern svalue_t *v_apply (svalue_t *sp, int num_arg);
extern svalue_t *v_funcall (svalue_t *sp, int num_arg);
extern svalue_t *v_call_direct_resolved (svalue_t *sp, int num_arg);
@ -212,7 +222,6 @@ extern svalue_t *f_caller_stack_depth (svalue_t *sp);
extern svalue_t *f_caller_stack (svalue_t *sp);
extern svalue_t *f_get_eval_cost (svalue_t *sp);
extern svalue_t *f_previous_object (svalue_t *sp);
extern svalue_t *f_last_instructions(svalue_t *sp);
extern svalue_t *f_set_this_object (svalue_t *sp);
extern svalue_t *f_trace(svalue_t *sp);
extern svalue_t *f_traceprefix(svalue_t *sp);
@ -222,7 +231,8 @@ extern Bool opcdump(string_t *fname);
#endif
#ifdef TRACE_CODE
extern int last_instructions(int length, int verbose, svalue_t **svpp);
extern svalue_t *f_last_instructions(svalue_t *sp);
extern int last_instructions(int length, Bool verbose, svalue_t **svpp);
#endif
#ifdef DEBUG
@ -240,5 +250,6 @@ extern void clear_interpreter_refs(void);
extern void count_interpreter_refs(void);
#endif
extern int control_stack_depth(void);
#endif /* INTERPRET_H__ */

View file

@ -62,6 +62,8 @@
#include "wiz_list.h" /* wizlist_name[] */
#include "xalloc.h"
#include "i-eval_cost.h"
#include "../mudlib/sys/driver_hook.h"
/* TODO: Implement the # and ## operators. With this, #define X(a) (a + "a")
@ -795,24 +797,27 @@ init_lexer(void)
sprintf(mtext, "%d", ERQ_MAX_REPLY);
add_permanent_define("__ERQ_MAX_REPLY__", -1, string_copy(mtext), MY_FALSE);
#endif
sprintf(mtext, "%ld", (long)max_malloced);
sprintf(mtext, "%"PRIdMPINT, max_malloced);
add_permanent_define("__MAX_MALLOC__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", (long)def_eval_cost);
sprintf(mtext, "%"PRId32, def_eval_cost);
add_permanent_define("__MAX_EVAL_COST__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", (long)CATCH_RESERVED_COST);
add_permanent_define("__CATCH_EVAL_COST__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", (long)MASTER_RESERVED_COST);
add_permanent_define("__MASTER_EVAL_COST__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", (long)time_to_reset);
sprintf(mtext, "%ld", time_to_reset);
add_permanent_define("__RESET_TIME__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", (long)time_to_cleanup);
sprintf(mtext, "%ld", time_to_cleanup);
add_permanent_define("__CLEANUP_TIME__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", (long)alarm_time);
sprintf(mtext, "%ld", alarm_time);
add_permanent_define("__ALARM_TIME__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", (long)heart_beat_interval);
sprintf(mtext, "%ld", heart_beat_interval);
add_permanent_define("__HEART_BEAT_INTERVAL__", -1, string_copy(mtext), MY_FALSE);
if (synch_heart_beats)
add_permanent_define("__SYNCHRONOUS_HEART_BEAT__", -1, string_copy("1"), MY_FALSE);
#ifdef EVAL_COST_TRACE
add_permanent_define("__EVAL_COST_TRACE__", -1, string_copy("1"), MY_FALSE);
#endif
#ifdef MSDOS_FS
add_permanent_define("__MSDOS_FS__", -1, string_copy("1"), MY_FALSE);
#endif
@ -834,6 +839,9 @@ init_lexer(void)
#ifdef USE_SQLITE
add_permanent_define("__SQLITE__", -1, string_copy("1"), MY_FALSE);
#endif
#ifdef USE_IKSEMEL
add_permanent_define("__XML_DOM__", -1, string_copy("1"), MY_FALSE);
#endif
#ifdef USE_EXPAT
add_permanent_define("__EXPAT__", -1, string_copy("1"), MY_FALSE);
#endif
@ -892,15 +900,15 @@ init_lexer(void)
add_permanent_define("__WIZLIST__", -1, string_copy(mtext), MY_FALSE);
}
sprintf(mtext, "(%ld)", PINT_MAX);
sprintf(mtext, "(%"PRIdPINT")", PINT_MAX);
add_permanent_define("__INT_MAX__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "(%ld)", PINT_MIN);
sprintf(mtext, "(%"PRIdPINT")", PINT_MIN);
add_permanent_define("__INT_MIN__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "(%g)", DBL_MAX);
add_permanent_define("__FLOAT_MAX__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "(%g)", DBL_MIN);
add_permanent_define("__FLOAT_MIN__", -1, string_copy(mtext), MY_FALSE);
sprintf(mtext, "%ld", get_current_time());
sprintf(mtext, "%"PRIdMPINT, get_current_time());
add_permanent_define("__BOOT_TIME__", -1, string_copy(mtext), MY_FALSE);
/* Add the permanent macro definitions given on the commandline */
@ -1925,8 +1933,8 @@ make_global_identifier (char *s, int n)
{
ip = xalloc(sizeof(ident_t));
if (!ip) {
yyerrorf("Out of memory: identifier (%lu bytes)"
, (unsigned long) sizeof(ident_t));
yyerrorf("Out of memory: identifier (%zu bytes)",
sizeof(ident_t));
return NULL;
}
ip->name = ref_mstring(q->name);
@ -2079,8 +2087,8 @@ realloc_defbuf (void)
defbuf_len <<= 1;
}
if (comp_flag)
fprintf(stderr, "%s (reallocating defbuf from %ld (%ld left) to %ld) "
, time_stamp(), (long)old_defbuf_len, (long)(old_outp-defbuf)
fprintf(stderr, "%s (reallocating defbuf from %zu (%td left) to %lu) "
, time_stamp(), old_defbuf_len, (ptrdiff_t)(old_outp-defbuf)
, defbuf_len);
defbuf = xalloc(defbuf_len);
memcpy(defbuf+defbuf_len-old_defbuf_len, old_defbuf, old_defbuf_len);
@ -2604,10 +2612,12 @@ add_auto_include (const char * obj_file, const char *cur_file, Bool sys_include)
if (auto_include_string != NULL)
{
/* The auto include string is handled like a normal include */
current_loc.line++; /* Make sure to restore to line 1 */
if (cur_file != NULL) /* Otherwise we already are at line 1 */
current_loc.line++; /* Make sure to restore to line 1 */
(void)start_new_include(-1, auto_include_string
, current_loc.file->name, "auto include", ')');
current_loc.line++; /* Make sure to start at line 1 */
if (cur_file == NULL) /* Otherwise #include will increment it */
current_loc.line++; /* Make sure to start at line 1 */
}
} /* add_auto_include() */
@ -3664,6 +3674,8 @@ parse_numeric_escape (char * cp, unsigned char * p_char)
/* strtol() gets the sign bit wrong,
* strtoul() isn't portable enough.
* TODO: strtoul should be portable enough today... Re-check if we
* TODO::require C99.
*/
num_digits = 2;
l = 0;
@ -3680,7 +3692,10 @@ parse_numeric_escape (char * cp, unsigned char * p_char)
/* Parse a normal number from here */
l = c - '0';
if (l < 0 || l > base)
/* l is unsigned. So any c smaller than '0' will be wrapped into
* positive values and be larger then base as well. Therefore an
* additional comparison of l < 0 is not explicitly needed here. */
if (l > base)
{
yywarn("Character constant used with no valid digits");
return NULL;
@ -3933,8 +3948,8 @@ add_lex_string (char *str, size_t slen)
new = mstr_add_txt(last_lex_string, str, slen);
if (!new)
{
lexerrorf("Out of memory for string concatenation (%lu bytes)"
, (unsigned long)len1+slen);
lexerrorf("Out of memory for string concatenation (%zu bytes)",
len1+slen);
}
free_mstring(last_lex_string);
last_lex_string = make_tabled(new);
@ -3961,8 +3976,8 @@ string (char *str, size_t slen)
last_lex_string = new_n_tabled(str, slen);
if (!last_lex_string)
{
lexerrorf("Out of memory for string literal (%lu bytes)"
, (unsigned long)slen);
lexerrorf("Out of memory for string literal (%zu bytes)",
slen);
}
}
return L_STRING;
@ -4233,7 +4248,7 @@ closure (char *in_yyp)
} /* closure() */
/*-------------------------------------------------------------------------*/
static INLINE char *
static char *
handle_preprocessor_statement (char * in_yyp)
/* The lexer has found a preprocessor statement (<newline>#), an <in_yyp>
@ -4647,18 +4662,6 @@ yylex1 (void)
current_loc = p->loc;
if (!was_string_source)
current_loc.line++;
else
{
/* 'string' includes are supposed to be inline
* so correct the line number information to take out
* the assumed newlines.
* This has to be done after store_include_end()
* since that function may remove all line number
* information since the start of the include.
*/
current_loc.line -= 1;
store_line_number_backward(1);
}
yyin = p->yyin;
saved_char = p->saved_char;
@ -7774,7 +7777,7 @@ show_lexer_status (strbuf_t * sbuf, Bool verbose UNUSED)
sum += 2 * DEFMAX; /* for the buffers in _expand_define() */
if (sbuf)
strbuf_addf(sbuf, "Lexer structures\t\t\t %9lu\n", sum);
strbuf_addf(sbuf, "Lexer structures\t\t\t %9zu\n", sum);
return sum;
} /* show_lexer_status() */
@ -7814,7 +7817,7 @@ count_lex_refs (void)
count_ident_refs(id);
for (id2 = id->inferior; id2 != NULL; id2 = id2->next)
{
count_ident_refs(id);
count_ident_refs(id2);
}
}
}

View file

@ -240,7 +240,7 @@ struct inline_fun
extern struct lpc_predef_s * lpc_predefs;
extern int total_lines;
extern source_loc_t current_loc;
extern int pragma_strict_types;
extern Bool pragma_strict_types;
extern Bool pragma_use_local_scopes;
extern Bool pragma_save_types;
extern Bool pragma_combine_strings;

View file

@ -76,6 +76,12 @@
#include "pkg-mysql.h"
#endif
#ifdef USE_IKSEMEL
#include "pkg-iksemel.h"
#endif
#include "i-eval_cost.h"
#include "../mudlib/sys/regexp.h"
/*-------------------------------------------------------------------------*/
@ -110,8 +116,6 @@ Bool share_variables = MY_FALSE; /* Clones are initialized from their
Bool allow_filename_spaces = MY_FALSE; /* Allow spaces in filenames */
static uint32 random_seed = 0; /* The seed for the pseudo-random generator. */
static char * hostname = NULL;
static char * hostaddr = NULL;
/* Hostname and -addr given on the commandline. They are passed as
@ -269,6 +273,7 @@ main (int argc, char **argv)
boot_time = (mp_int)time(NULL);
setlocale(LC_CTYPE, ""); /* Use the locale defined in the LANG env var */
setlocale(LC_TIME, "");
get_stack_direction();
mb_init();
init_interpret();
@ -278,9 +283,15 @@ main (int argc, char **argv)
put_number(&const1, 1);
current_time = get_current_time();
random_seed = (uint32)current_time;
seed_random(random_seed);
// Set prng_device_name to the default //
prng_device_name = strdup(PRNG_DEFAULT_DEVICE);
// init PRG by the default device (/dev/urandom)
// if --random-seed or --randomdevice is given on the command-line it
// will re-seeded later.
seed_random(prng_device_name);
do {
dummy_current_object_for_loads = NULL_object;
#ifdef DEBUG
@ -437,15 +448,6 @@ main (int argc, char **argv)
for (i = 0; i < (int)(sizeof avg_consts / sizeof avg_consts[0]); i++)
avg_consts[i] = exp(- i / 900.0);
#ifdef USE_LDMUD_COMPATIBILITY
# ifdef VERBOSE
printf("%s Random seed: 0x%lx\n"
, time_stamp(), (unsigned long)random_seed);
# endif
debug_message("%s Random seed: 0x%lx\n"
, time_stamp(), (unsigned long)random_seed);
#endif
#ifdef USE_MYSQL
if (!pkg_mysql_init())
{
@ -454,6 +456,10 @@ main (int argc, char **argv)
}
#endif
#ifdef USE_IKSEMEL
pkg_iksemel_init();
#endif
/* If the master_name hasn't been set, select a sensible default */
if ('\0' == master_name[0])
{
@ -1064,6 +1070,7 @@ typedef enum OptNumber {
, cNoHeart /* --no-heart */
, cNoPreload /* --no-preload */
, cPidFile /* --pidfile */
, cRandomdevice /* --randomdevice */
, cRandomSeed /* --random-seed */
, cRegexp /* --regexp */
, cResetTime /* --reset-time */
@ -1506,6 +1513,16 @@ static Option aOptions[]
, " Use <pathname> as the directory where your certificate revocation lists reside.\n"
" If relative, <pathname> is interpreted relative to <mudlib>.\n"
}
, { 0, "tls-crlfile", cTLScrlfile, MY_TRUE
, " --tls-crlfile <pathname>\n"
, " Use <pathname> as the filename holding your certificate revocation lists.\n"
" If relative, <pathname> is interpreted relative to <mudlib>.\n"
}
, { 0, "tls-crldirectory", cTLScrldir, MY_TRUE
, " --tls-crldirectory <pathname>\n"
, " Use <pathname> as the directory where your certificate revocation lists reside.\n"
" If relative, <pathname> is interpreted relative to <mudlib>.\n"
}
#endif /* USE_TLS */
, { 0, "wizlist-file", cWizlistFile, MY_TRUE
@ -1527,6 +1544,13 @@ static Option aOptions[]
" Write the pid of the driver process into <filename>.\n"
}
, { 0, "randomdevice", cRandomdevice, MY_TRUE
, " --randomdevice <filename>\n"
, " --randomdevice <filename>\n"
" Determines the source of the seed for the random number generator.\n"
" (tries /dev/urandom by default and uses system clock as fallback)\n"
}
, { 0, "random-seed", cRandomSeed, MY_TRUE
, " --random-seed <num>\n"
, " --random-seed <num>\n"
@ -1820,6 +1844,9 @@ options (void)
#ifdef HAS_IDN
, "idna supported\n"
#endif
#ifdef USE_IKSEMEL
, "iksemel supported\n"
#endif
#ifdef USE_IPV6
, "IPv6 supported\n"
#endif
@ -2556,33 +2583,38 @@ eval_arg (int eOption, const char * pValue)
}
new_mudlib = 1;
#ifndef USE_LDMUD_COMPATIBILITY
debug_message("%s Sandboxing myself into %s\n",
debug_message("%s Entering my %s sandbox\n",
time_stamp(), pValue);
#endif
break;
#if 1 /* def USE_DEBUG_LOG */
case cDebugFile:
#ifdef USE_DEBUG_LOG
if (debug_file != NULL)
free(debug_file);
debug_file = strdup(pValue);
#else
debug_message("%s Ignoring --debug-file option\n"
/* " This function has been disabled at compile time.\n"
" Please remove it from your scripts.\n" */
, time_stamp());
debug_message("%s Ignoring --debug-file option\n", time_stamp());
#endif
break;
#endif
case cRandomdevice:
// sets prng_device_name to some file/device and re-seeds the PRNG
// from it.
if (prng_device_name != NULL)
free(prng_device_name);
prng_device_name = strdup(pValue);
seed_random(prng_device_name);
break;
case cRandomSeed:
// seeds PRG with given value
#ifdef HAVE_STRTOUL
random_seed = strtoul(pValue, (char **)0, 0);
seed_random_from_int(strtoul(pValue, (char **)0, 0));
#else
random_seed = (uint32)strtol(pValue, (char **)0, 0);
seed_random_from_int((uint32)strtol(pValue, (char **)0, 0));
#endif
seed_random(random_seed);
break;
case cReserved:
@ -2687,6 +2719,16 @@ eval_arg (int eOption, const char * pValue)
}
gcollect_outfd = default_gcollect_outfd;
break;
case cTLScrlfile:
if (tls_crlfile != NULL)
free(tls_crlfile);
tls_crlfile = strdup(pValue);
break;
case cTLScrldir:
if (tls_crldirectory != NULL)
free(tls_crldirectory);
tls_crldirectory = strdup(pValue);
break;
#endif
case cOptions:

View file

@ -61,7 +61,7 @@ extern int exit_code;
extern int main(int argc, char **argv);
extern void initialize_master_uid(void);
extern void debug_message(const char *, ...) FORMATDEBUG(printf, 1, 2);
extern void vdebug_message(const char *, va_list);
extern void vdebug_message(const char *, va_list) FORMATDEBUG(printf, 1, 0);
extern void write_X (int d, unsigned char i);
extern void write_x(int d, p_uint i);

View file

@ -485,7 +485,7 @@ static int curr_lpc_type_size = 0;
/* Forward declarations */
static void yyerror(const char *);
static void yyerror(const char *) NORETURN;
static int yylex(void);
int yyparse(void);
int ungetc(int c, FILE *f);
@ -496,7 +496,7 @@ static const char *ctype(int);
#ifndef toupper
int toupper(int);
#endif
static int fatal(const char *str);
static void fatal(const char *str) NORETURN;
static int cond_get_exp(int);
/*-------------------------------------------------------------------------*/
@ -517,7 +517,7 @@ mystrdup (const char *str)
}
/*-------------------------------------------------------------------------*/
static int
static void
fatal (const char *str)
/* Print <str> on stderr, flush stdout and exit the program with
@ -528,8 +528,6 @@ fatal (const char *str)
fprintf(stderr, "%s", str);
fflush(stdout);
exit(1);
/* NOTREACHED */
return 0;
}
/*-------------------------------------------------------------------------*/

View file

@ -15,6 +15,11 @@
* TODO:: The pool is not absolutely required, but would reduce overhead if
* TODO:: MALLOC_TRACE is in effect.
*
* TODO: Check if the use of mp_int is reasonable for values for num_values
* TODO::and num_entries (which are in the struct p_int). And check as
* TODO::the wild mixture of mp_int, p_int, size_t (and maybe still int?)
* TODO::used for iterating over mapping structures.
*
* Mappings, or 'associative arrays', are similar to normal arrays, with
* the principal difference that they can use every value to index their
* stored data, whereas arrays only index with integer values. On the
@ -370,7 +375,8 @@ get_new_hash ( mapping_t *m, mp_int hash_size)
*
* Return the new structure, or NULL when out of memory.
*/
/* TODO: hash_size of mp_int seems unnecessarily large to me, because
* TODO::mappings can only have p_int values? */
{
mapping_hash_t *hm;
map_chain_t **mcp;
@ -439,7 +445,8 @@ get_new_mapping ( wiz_list_t * user, mp_int num_values
*
* Return the new mapping, or NULL when out of memory.
*/
/* TODO: hash_size of mp_int seems unnecessarily large to me, because
* TODO::mappings can only have p_int values? */
{
mapping_cond_t *cm;
mapping_hash_t *hm;
@ -588,7 +595,8 @@ _free_mapping (mapping_t *m, Bool no_data)
fatal("No wizlist pointer for mapping");
if (!no_data && m->ref > 0)
fatal("Mapping with %ld refs passed to _free_mapping().\n", m->ref);
fatal("Mapping with %"PRIdPINT" refs passed to _free_mapping().\n",
m->ref);
#endif
num_mappings--;
@ -624,11 +632,11 @@ _free_mapping (mapping_t *m, Bool no_data)
if ( NULL != (hm = m->hash) )
{
map_chain_t **mcp, *mc, *next;
int i;
p_int i;
#ifdef DEBUG
if (hm->ref)
fatal("Ref count in freed hash mapping: %ld\n", hm->ref);
fatal("Ref count in freed hash mapping: %"PRIdPINT"\n", hm->ref);
#endif
LOG_SUB("free_mapping hash", SIZEOF_MH(hm));
m->user->mapping_total -= SIZEOF_MH(hm);
@ -694,8 +702,9 @@ free_protector_mapping (mapping_t *m)
}
#endif
dump_trace(MY_FALSE, NULL);
printf("%s free_protector_mapping() : no hash %s\n"
/* printf("%s free_protector_mapping() : no hash %s\n"
, time_stamp(), m->hash ? "reference" : "part");
*/
free_mapping(m);
}
#endif /* DEBUG */
@ -980,13 +989,14 @@ static svalue_t local_const0;
}
if (max_mapping_size && msize > (mp_int)max_mapping_size)
{
errorf("Illegal mapping size: %ld elements (%ld x %ld)\n"
, msize, (long)MAP_SIZE(m)+1, (long)m->num_values);
errorf("Illegal mapping size: %"PRIdMPINT" elements (%"
PRIdPINT" x %"PRIdPINT")\n"
, msize, MAP_SIZE(m)+1, m->num_values);
return NULL;
}
if (max_mapping_keys && MAP_SIZE(m) > (mp_int)max_mapping_keys)
{
errorf("Illegal mapping size: %ld entries\n", msize+1);
errorf("Illegal mapping size: %"PRIdMPINT" entries\n", msize+1);
return NULL;
}
}
@ -1188,7 +1198,7 @@ check_map_for_destr (mapping_t *m)
*/
{
int num_values;
p_int num_values;
mapping_cond_t *cm;
mapping_hash_t *hm;
@ -1210,7 +1220,7 @@ check_map_for_destr (mapping_t *m)
if (destructed_object_ref(entry))
{
int i;
p_int i;
svalue_t * data = COND_DATA(cm, ix, num_values);
/* Destructed key: remove the whole entry */
@ -1450,6 +1460,7 @@ resize_mapping (mapping_t *m, mp_int new_width)
mapping_hash_t * hm, *hm2 = NULL;
mapping_cond_t * cm, *cm2 = NULL;
mp_int common_width; /* == min(num_values, new_width) */
p_int num_entries;
/* Set the width variables */
if (m->num_values >= new_width)
@ -1469,12 +1480,14 @@ resize_mapping (mapping_t *m, mp_int new_width)
&& (SSIZE_MAX - sizeof(map_chain_t)) / new_width < sizeof(svalue_t))
)
{
errorf("Mapping width too big (%ld)\n", new_width);
errorf("Mapping width too big (%"PRIdMPINT")\n", new_width);
/* NOTREACHED */
return NULL;
}
}
num_entries = m->num_entries;
/* Get the target mapping without a hash, but with a condensed block
* big enough to hold all entries.
@ -1490,7 +1503,7 @@ resize_mapping (mapping_t *m, mp_int new_width)
m2 = get_new_mapping(current_object->user, new_width, 0, cm_size);
if (!m2)
{
outofmem(sizeof *m2 + sizeof(svalue_t) * m->num_entries * new_width
outofmem(sizeof *m2 + (mp_int)sizeof(svalue_t) * m->num_entries * new_width
, "result mapping base structure");
/* NOTREACHED */
return NULL;
@ -1531,39 +1544,42 @@ resize_mapping (mapping_t *m, mp_int new_width)
map_chain_t *last = NULL, *mc, *mc2;
for (mc = *mcp++; mc; mc = mc->next)
{
svalue_t *src, *dest;
p_int i;
mc2 = new_map_chain(m2);
if (!mc2)
if(destructed_object_ref(&(mc->data[0])))
num_entries--;
else
{
xfree(hm2);
outofmem(SIZEOF_MCH(mc, new_width), "hash link");
/* NOTREACHED */
return NULL;
svalue_t *src, *dest;
p_int i;
mc2 = new_map_chain(m2);
if (!mc2)
{
xfree(hm2);
outofmem(SIZEOF_MCH(mc, new_width), "hash link");
/* NOTREACHED */
return NULL;
}
/* Copy the key and the common values */
for (src = &(mc->data[0]), dest = &(mc2->data[0]), i = common_width
; i >= 0
; --i, src++, dest++)
{
assign_svalue_no_free(dest, src);
}
/* Zero out any extraneous values */
for (dest = &(mc2->data[common_width+1]), i = new_width - common_width
; i > 0
; --i, dest++)
{
put_number(dest, 0);
}
mc2->next = last;
last = mc2;
}
/* Copy the key and the common values */
for (src = &(mc->data[0]), dest = &(mc2->data[0]), i = common_width
; i >= 0
; --i, src++, dest++)
{
assign_svalue_no_free(dest, src);
}
/* Zero out any extraneous values */
for (dest = &(mc2->data[common_width+1]), i = new_width - common_width
; i > 0
; --i, dest++)
{
put_number(dest, 0);
}
mc2->next = last;
last = mc2;
}
*mcp2++ = last;
} while (--size);
@ -1595,7 +1611,24 @@ resize_mapping (mapping_t *m, mp_int new_width)
; src_ix < cm->size
; src_ix++, src_key++)
{
if (src_key->type != T_INVALID)
if (src_key->type == T_INVALID)
; /* Do nothing */
else if (destructed_object_ref(src_key))
{
/* We have to fill the space.
* (Alternatively we could decrease m->cond->size.)
*/
p_int i;
num_entries--;
dest_key->type = T_INVALID;
dest_key++;
for (i = new_width; i > 0; i--, dest_data++)
put_number(dest_data, 0);
}
else
{
p_int i;
@ -1616,7 +1649,7 @@ resize_mapping (mapping_t *m, mp_int new_width)
/* --- Finalize the basis structure ---
*/
m2->num_entries = m->num_entries;
m2->num_entries = num_entries;
/* That's it. */
return m2;
@ -1671,8 +1704,9 @@ add_mapping (mapping_t *m1, mapping_t *m2)
return copy_mapping(m1);
}
errorf("Mappings to be added are of different width: %ld vs. %ld\n"
, (long)num_values, (long)m2->num_values);
errorf("Mappings to be added are of different width: %"PRIdMPINT
" vs. %"PRIdPINT"\n",
num_values, m2->num_values);
}
@ -1730,7 +1764,8 @@ add_mapping (mapping_t *m1, mapping_t *m2)
; cm1_ix < cm1size && cm2_ix < cm2size
; NOOP )
{
int cmp, i;
int cmp;
p_int i;
if (src1_key->type == T_INVALID
|| destructed_object_ref(src1_key)
@ -1793,7 +1828,7 @@ add_mapping (mapping_t *m1, mapping_t *m2)
for ( ; cm1_ix < cm1size; cm1_ix++, src1_key++)
{
svalue_t *data = COND_DATA(cm1, cm1_ix, num_values);
int i;
p_int i;
if (src1_key->type != T_INVALID
&& !destructed_object_ref(src1_key))
@ -1811,7 +1846,7 @@ add_mapping (mapping_t *m1, mapping_t *m2)
for ( ; cm2_ix < cm2size; cm2_ix++, src2_key++)
{
svalue_t *data = COND_DATA(cm2, cm2_ix, num_values);
int i;
p_int i;
if (src2_key->type != T_INVALID
&& !destructed_object_ref(src2_key))
@ -1834,7 +1869,7 @@ add_mapping (mapping_t *m1, mapping_t *m2)
for ( ; (p_int)num_entries < cm3size; num_entries++)
{
int i;
p_int i;
dest_key->type = T_INVALID; dest_key++;
@ -1864,7 +1899,7 @@ add_mapping (mapping_t *m1, mapping_t *m2)
for (mc = *mcp++; mc; mc = mc->next)
{
svalue_t * src, * dest;
int i;
p_int i;
src = &(mc->data[0]);
dest = get_map_lvalue_unchecked(m3, src);
@ -1894,7 +1929,7 @@ add_mapping (mapping_t *m1, mapping_t *m2)
for (mc = *mcp++; mc; mc = mc->next)
{
svalue_t * src, * dest;
int i;
p_int i;
src = &(mc->data[0]);
dest = get_map_lvalue_unchecked(m3, src);
@ -2060,7 +2095,8 @@ compact_mapping (mapping_t *m, Bool force)
cm = m->cond;
if (hm && hm->ref) {
fatal("compact_mapping(): remaining protector ref count %ld!\n", hm->ref);
fatal("compact_mapping(): remaining protector ref count %"
PRIdPINT"!\n", hm->ref);
}
/* Test if the mapping is dirty at all.
@ -2184,7 +2220,7 @@ compact_mapping (mapping_t *m, Bool force)
if (last_hash)
{
p_int d = svalue_cmp(&(mcp->data[0]), &(last_hash->data[0]));
int d = svalue_cmp(&(mcp->data[0]), &(last_hash->data[0]));
if (d < 0) {
last_hash->next = hook1;
@ -2260,7 +2296,7 @@ compact_mapping (mapping_t *m, Bool force)
{
/* Sort the next runlength elements onto out1 */
while (1) {
p_int d = svalue_cmp(&(hook1->data[0]), &(hook2->data[0]));
int d = svalue_cmp(&(hook1->data[0]), &(hook2->data[0]));
if (d > 0)
{
@ -2352,7 +2388,7 @@ compact_mapping (mapping_t *m, Bool force)
map_chain_t *temp;
svalue_t *src;
int i;
p_int i;
*dest_key++ = hook1->data[0];
@ -2367,7 +2403,7 @@ compact_mapping (mapping_t *m, Bool force)
{
/* Take entry from the old condensed part */
int i;
p_int i;
*dest_key++ = *src_key++;
@ -2389,7 +2425,7 @@ compact_mapping (mapping_t *m, Bool force)
{
if (src_key->type != T_INVALID)
{
int i;
p_int i;
*dest_key++ = *src_key++;
@ -2412,7 +2448,7 @@ compact_mapping (mapping_t *m, Bool force)
{
map_chain_t *temp;
svalue_t *src;
int i;
p_int i;
*dest_key++ = hook1->data[0];
@ -2553,7 +2589,7 @@ mapping_overhead (mapping_t *m)
*/
struct set_mapping_user_locals
{
int num_values; /* Number of values per key */
p_int num_values; /* Number of values per key */
object_t *owner; /* Owner to set */
svalue_t **hairy;
/* Next free entry in the array of keys which need manual tweaking */
@ -2575,7 +2611,7 @@ set_mapping_user_filter (svalue_t *key, svalue_t *data, void *extra)
*/
{
int i;
p_int i;
struct set_mapping_user_locals *locals;
object_t *owner;
@ -2608,7 +2644,7 @@ set_mapping_user (mapping_t *m, object_t *owner)
*/
{
int num_values;
p_int num_values;
mp_int total;
wiz_list_t *user;
struct set_mapping_user_locals locals;
@ -2958,12 +2994,12 @@ clean_stale_mappings (void)
{
#ifdef VERBOSE
fprintf(stderr, "%s Unable to compact stale mapping: Out of memory "
"for new condensed block (%ld bytes).\n"
, time_stamp(), (long)size);
"for new condensed block (%zu bytes).\n"
, time_stamp(), size);
#endif
debug_message("%s Unable to compact stale mapping: Out of memory "
"for new condensed block (%ld bytes).\n"
, time_stamp(), (long)size);
"for new condensed block (%zu bytes).\n"
, time_stamp(), size);
/* No use in even trying to compact the much bigger data
* block either.
@ -3085,19 +3121,20 @@ f_m_allocate (svalue_t *sp)
p_int width = sp[0].u.number;
if (size < 0)
errorf("Illegal mapping size: %ld\n", size);
errorf("Illegal mapping size: %"PRIdPINT"\n", size);
if (width < 0)
errorf("Illegal mapping width: %ld\n", width);
errorf("Illegal mapping width: %"PRIdPINT"\n", width);
if (max_mapping_size
&& size * (1 + width) > (p_int)max_mapping_size)
errorf("Illegal mapping size: %ld elements (%ld x %ld).\n"
, size * (1+width)
, size, width);
errorf("Illegal mapping size: %"PRIdMPINT
" elements (%"PRIdPINT" x %"PRIdPINT").\n",
(mp_int)size * (1+width),
size, width);
if (max_mapping_keys
&& size > (p_int)max_mapping_keys)
errorf("Illegal mapping size: %ld entries.\n", size);
errorf("Illegal mapping size: %"PRIdPINT" entries.\n", size);
sp--;
@ -3107,7 +3144,8 @@ f_m_allocate (svalue_t *sp)
/* sp points to a number-typed svalue, so freeing won't
* be a problem.
*/
errorf("Out of memory for mapping[%ld,%ld].\n", size, width);
errorf("Out of memory for mapping[%"PRIdPINT",%"PRIdPINT"].\n",
size, width);
/* NOTREACHED */
}
sp->type = T_MAPPING;
@ -3135,7 +3173,7 @@ v_m_add (svalue_t *sp, int num_arg)
mapping_t *m;
svalue_t *argp;
svalue_t *entry;
int num_values;
p_int num_values;
argp = sp - num_arg + 1;
m = argp->u.map;
@ -3214,7 +3252,7 @@ m_indices (mapping_t *m)
mp_int size;
check_map_for_destr(m);
size = (mp_int)MAP_SIZE(m);
size = MAP_SIZE(m);
v = allocate_array(size); /* might cause error */
svp = v->item;
walk_mapping(m, m_indices_filter, &svp);
@ -3267,8 +3305,8 @@ f_m_values (svalue_t *sp)
mapping_t *m;
vector_t *v;
struct mvf_info vip;
mp_int size;
int num;
p_int size;
p_int num;
/* Get and check the arguments */
num = sp->u.number;
@ -3277,12 +3315,12 @@ f_m_values (svalue_t *sp)
m = sp->u.map;
if (num < 0 || num >= m->num_values)
errorf("Illegal index %d to m_values(): should be in 0..%ld.\n"
, num, (long)m->num_values-1);
errorf("Illegal index %"PRIdPINT" to m_values(): should be in 0..%"
PRIdPINT".\n", num, m->num_values-1);
/* Get the size of the mapping */
check_map_for_destr(m);
size = (mp_int)MAP_SIZE(m);
size = MAP_SIZE(m);
if (size > 0 && m->num_values < 1)
errorf("m_values() applied on mapping with no values.\n");
@ -3311,7 +3349,7 @@ add_to_mapping_filter (svalue_t *key, svalue_t *data, void *extra)
{
svalue_t *data2;
int i;
p_int i;
data2 = get_map_lvalue_unchecked((mapping_t *)extra, key);
if (!data2)
@ -3378,8 +3416,9 @@ add_to_mapping (mapping_t *m1, mapping_t *m2)
}
else
{
errorf("Mappings to be added are of different width: %ld vs. %ld\n"
, (long)m1->num_values, (long)m2->num_values);
errorf("Mappings to be added are of different width: %"PRIdPINT
" vs. %"PRIdPINT"\n",
m1->num_values, m2->num_values);
return;
}
}
@ -3452,9 +3491,9 @@ map_intersect_filter (svalue_t *key, svalue_t *data UNUSED, void *extra)
src = get_map_value(m, key);
if (src != &const0)
{
int num_values = m->num_values;
p_int num_values = m->num_values;
svalue_t * dest;
int j;
p_int j;
dest = get_map_lvalue(rc, key);
if (!dest)
@ -3488,9 +3527,9 @@ map_intersect (mapping_t *m, svalue_t * val)
if (val->type == T_POINTER)
{
vector_t * vec = val->u.vec;
size_t vecsize = VEC_SIZE(vec);
int num_values = m->num_values;
size_t i;
p_int vecsize = VEC_SIZE(vec);
p_int num_values = m->num_values;
p_int i;
rc = allocate_mapping(vecsize, num_values);
if (!rc)
@ -3507,7 +3546,7 @@ map_intersect (mapping_t *m, svalue_t * val)
if (src != &const0)
{
svalue_t * dest;
int j;
p_int j;
dest = get_map_lvalue(rc, &vec->item[i]);
if (!dest)
@ -3525,7 +3564,7 @@ map_intersect (mapping_t *m, svalue_t * val)
else if (val->type == T_MAPPING)
{
mapping_t * map = val->u.map;
int num_values = m->num_values;
p_int num_values = m->num_values;
struct map_intersect_s data;
rc = allocate_mapping(MAP_SIZE(map), num_values);
@ -3566,12 +3605,12 @@ map_intersect_array (vector_t *vec, mapping_t *map)
{
Bool *flags; /* The result from match_arrays() */
size_t result_size; /* Size of the result array */
p_int result_size; /* Size of the result array */
vector_t *result; /* Result array */
svalue_t *dest; /* Pointer for storing the result elements */
size_t i;
p_int i;
size_t vec_size = VEC_SIZE(vec);
p_int vec_size = VEC_SIZE(vec);
/* Handle empty arrays */
@ -3615,7 +3654,7 @@ map_intersect_array (vector_t *vec, mapping_t *map)
xfree(flags);
free_mapping(map);
free_array(vec);
errorf("Illegal array size: %lu.\n", (unsigned long)result_size);
errorf("Illegal array size: %"PRIdPINT".\n", result_size);
}
result = allocate_array(result_size);
@ -3810,7 +3849,7 @@ v_walk_mapping (svalue_t *sp, int num_arg)
callback_t cb;
int error_index;
mapping_t *m; /* Mapping to walk */
int num_values; /* Number of values per entry */
p_int num_values; /* Number of values per entry */
svalue_t *read_pointer; /* Prepared mapping values */
mp_int i;
@ -3848,7 +3887,7 @@ v_walk_mapping (svalue_t *sp, int num_arg)
*/
while (--i >= 0)
{
int j;
p_int j;
svalue_t *sp2, *data;
if (!callback_object(&cb))
@ -3916,12 +3955,12 @@ x_filter_mapping (svalue_t *sp, int num_arg, Bool bFull)
mapping_t *m; /* Mapping to filter */
int error_index;
callback_t cb;
int num_values; /* Width of the mapping */
p_int num_values; /* Width of the mapping */
vector_t *dvec; /* Values of one key */
svalue_t *dvec_sp; /* Stackentry of dvec */
svalue_t *read_pointer; /* Prepared mapping values */
svalue_t *v;
int i, j;
p_int i, j;
/* Locate the arguments on the stack and extract them */
arg = sp - num_arg + 1;
@ -4144,11 +4183,11 @@ x_map_mapping (svalue_t *sp, int num_arg, Bool bFull)
svalue_t *arg; /* Begin of arguments on the stack */
mapping_t *arg_m; /* Mapping to map */
mapping_t *m; /* Result mapping */
int num_values; /* Width of the mapping */
p_int num_values; /* Width of the mapping */
vector_t *vec; /* Indices of m */
svalue_t *dvec_sp; /* Stackentry of dvec */
vector_t *dvec; /* Values of one key */
long i;
p_int i;
svalue_t *key;
callback_t cb;
int error_index;
@ -4204,7 +4243,7 @@ x_map_mapping (svalue_t *sp, int num_arg, Bool bFull)
dvec_sp = sp;
}
m = allocate_mapping((i = (long)VEC_SIZE(vec)), 1);
m = allocate_mapping((i = VEC_SIZE(vec)), 1);
if (!m)
{
inter_sp = sp;
@ -4255,7 +4294,7 @@ x_map_mapping (svalue_t *sp, int num_arg, Bool bFull)
}
else
{
int j;
p_int j;
svalue_t *svp;
v = get_map_value(arg_m, key);
@ -4334,7 +4373,7 @@ v_m_contains (svalue_t *sp, int num_arg)
* int m_contains(mixed &data1, ..., &dataN, map, key)
*
* If the mapping contains the key map, the corresponding values
* are assigned to the data arguments, which massed be passed by
* are assigned to the data arguments, which must be passed by
* reference, and 1 is returned. If key is not in map, 0 is
* returned and the data args are left unchanged.
* It is possible to use this function for a 0-value mapping, in
@ -4352,8 +4391,8 @@ v_m_contains (svalue_t *sp, int num_arg)
if (sp[-1].type != T_MAPPING)
vefun_arg_error(num_arg-1, T_MAPPING, sp[-1].type, sp);
if (sp[-1].u.map->num_values != num_arg - 2)
errorf("Not enough lvalues: given %ld, required %ld.\n"
, (long)num_arg-2, (long)sp[-1].u.map->num_values);
errorf("Not enough lvalues: given %d, required %"PRIdPINT".\n",
num_arg-2, sp[-1].u.map->num_values);
item = get_map_value(sp[-1].u.map, sp);
if (item == &const0)
@ -4411,8 +4450,8 @@ f_m_entry (svalue_t *sp)
data = get_map_value(sp[-1].u.map, sp);
if (&const0 != data)
{
int num_values = sp[-1].u.map->num_values;
int i;
p_int num_values = sp[-1].u.map->num_values;
p_int i;
rc = allocate_array(num_values);
@ -4450,7 +4489,7 @@ f_m_reallocate (svalue_t *sp)
*/
{
int new_width; /* Requested width of the target mapping */
p_int new_width; /* Requested width of the target mapping */
mapping_t *m; /* Argument mapping */
mapping_t *new_m; /* New mapping */
@ -4458,7 +4497,7 @@ f_m_reallocate (svalue_t *sp)
new_width = sp->u.number;
if (new_width < 0)
{
errorf("Illegal width to m_reallocate(): %ld\n", (long)new_width);
errorf("Illegal width to m_reallocate(): %"PRIdPINT"\n", new_width);
/* NOTREACHED */
return sp;
}
@ -4549,26 +4588,28 @@ v_mkmapping (svalue_t *sp, int num_arg)
if (sp[-num_arg+1].type == T_POINTER)
{
long i, length, num_values;
int i, num_values; /* contains num_arg, which is int */
p_int length; /* VEC_SIZE, array sizes */
svalue_t *key;
/* Check the arguments and set length to the size of
* the shortest array.
*/
length = LONG_MAX;
length = PINT_MAX;
for (i = -num_arg; ++i <= 0; )
{
if ( sp[i].type != T_POINTER )
vefun_arg_error(i+num_arg, T_POINTER, sp[i].type, sp);
if (length > (long)VEC_SIZE(sp[i].u.vec))
length = (long)VEC_SIZE(sp[i].u.vec);
if (length > VEC_SIZE(sp[i].u.vec))
length = VEC_SIZE(sp[i].u.vec);
}
if (max_mapping_size && length * num_arg > (p_int)max_mapping_size)
errorf("Illegal mapping size: %ld elements (%ld x %ld)\n"
, length * num_arg, length, (long)num_arg);
if (max_mapping_size && (mp_int)length * num_arg > (mp_int)max_mapping_size)
errorf("Illegal mapping size: %"PRIdMPINT
" elements (%"PRIdPINT" x %d)\n"
, (mp_int)length * num_arg, length, num_arg);
if (max_mapping_keys && length > (p_int)max_mapping_keys)
errorf("Illegal mapping size: %ld entries\n", length);
errorf("Illegal mapping size: %"PRIdPINT" entries\n", length);
/* Allocate the mapping */
num_values = num_arg - 1;
@ -4635,14 +4676,14 @@ f_unmkmapping (svalue_t *sp)
vector_t *v;
struct mvf_info vip;
mp_int size;
int i;
p_int i;
/* Get the arguments */
m = sp->u.map;
/* Determine the size of the mapping and allocate the result vector */
check_map_for_destr(m);
size = (mp_int)MAP_SIZE(m);
size = MAP_SIZE(m);
v = allocate_array(m->num_values+1);
/* Allocate the sub vectors */
@ -4680,7 +4721,7 @@ f_widthof (svalue_t *sp)
*/
{
int width;
p_int width;
if (sp->type == T_NUMBER && sp->u.number == 0)
return sp;

View file

@ -266,12 +266,12 @@ mb_status (strbuf_t * sbuf, Bool verbose)
{
strbuf_add(sbuf, "\nMemory Buffers:\n");
strbuf_add(sbuf, "---------------\n");
strbuf_addf(sbuf, "File data: %8lu\n", membuffers[mbFile].size);
strbuf_addf(sbuf, "Swap buffer: %8lu\n", membuffers[mbSwap].size);
strbuf_addf(sbuf, "File data: %8zu\n", membuffers[mbFile].size);
strbuf_addf(sbuf, "Swap buffer: %8zu\n", membuffers[mbSwap].size);
}
else
{
strbuf_addf(sbuf, "Memory buffers:\t\t\t\t %9lu\n", res);
strbuf_addf(sbuf, "Memory buffers:\t\t\t\t %9zu\n", res);
}
return res;

View file

@ -421,6 +421,22 @@ rx_compile_pcre (string_t * expr, int opt, Bool from_ed, regdata_t * rdata)
errorf("pcre: %s\n", pErrmsg);
return 0;
}
/* We have to ensure to have an initialized pHints structure for
setting the recursion limit later on */
if (pHints == NULL)
{
pcre_malloc_err = "allocating memory for pHints section in regexp";
pHints = (pcre_extra *)pcre_xalloc(sizeof(pcre_extra));
if (pHints == NULL)
{
if (from_ed)
add_message("pcre: Could not allocate memory for pHints\n");
else
errorf("pcre: Could not allocate memory for pHints\n");
return 0;
}
pHints->flags = 0;
}
{
int rc;
@ -685,18 +701,28 @@ rx_exec (regexp_t *pRegexp, string_t * string, size_t start)
if (prog->opt & RE_NOTEMPTY) pcre_opt |= PCRE_NOTEMPTY;
pHints = prog->pHints;
if (pHints && max_eval_cost)
{
pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
if (max_eval_cost > eval_cost + 1)
pHints->match_limit = max_eval_cost - eval_cost - 1;
else
pHints->match_limit = 1;
}
else if (pHints)
{
pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
}
/* If LD_PCRE_RECURSION_LIMIT is defined we set a limit for match. If
* PCRE_EXTRA_MATCH_LIMIT_RECURSION is defined, we have a new libpcre,
* which supports limiting the recursions. Otherwise we have to limit
* the no of calls to match().
* TODO: Instead of the conditional compilation we should update the
* TODO::built-in pcre package.
*/
#ifdef LD_PCRE_RECURSION_LIMIT
#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
pHints->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
pHints->match_limit_recursion = LD_PCRE_RECURSION_LIMIT;
#else
pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
pHints->match_limit = LD_PCRE_RECURSION_LIMIT;
#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
#else /* LD_PCRE_RECURSION_LIMIT */
#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION
#else
pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
#endif /* LD_PCRE_RECURSION_LIMIT */
rc = pcre_exec( prog->pProg, pHints
, get_txt(string), mstrsize(string), start, pcre_opt
@ -748,18 +774,28 @@ rx_exec_str (regexp_t *pRegexp, char * string, char * start)
if (prog->opt & RE_NOTEMPTY) pcre_opt |= PCRE_NOTEMPTY;
pHints = prog->pHints;
if (pHints && max_eval_cost)
{
pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
if (max_eval_cost > eval_cost + 1)
pHints->match_limit = max_eval_cost - eval_cost - 1;
else
pHints->match_limit = 1;
}
else if (pHints)
{
pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
}
/* If LD_PCRE_RECURSION_LIMIT is defined we set a limit for match. If
* PCRE_EXTRA_MATCH_LIMIT_RECURSION is defined, we have a new libpcre,
* which supports limiting the recursions. Otherwise we have to limit
* the no of calls to match().
* TODO: Instead of the conditional compilation we should update the
* TODO::built-in pcre package.
*/
#ifdef LD_PCRE_RECURSION_LIMIT
#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
pHints->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
pHints->match_limit_recursion = LD_PCRE_RECURSION_LIMIT;
#else
pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
pHints->match_limit = LD_PCRE_RECURSION_LIMIT;
#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
#else /* LD_PCRE_RECURSION_LIMIT */
#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION
#else
pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
#endif /* LD_PCRE_RECURSION_LIMIT */
rc = pcre_exec( prog->pProg, pHints
, start, strlen(start), string - start, pcre_opt
@ -1172,12 +1208,13 @@ rxcache_status (strbuf_t *sbuf, Bool verbose)
{
strbuf_add(sbuf, "\nRegexp cache status:\n");
strbuf_add(sbuf, "--------------------\n");
strbuf_addf(sbuf, "Expressions in cache: %lu (%.1f%%)\n"
strbuf_addf(sbuf, "Expressions in cache: %"PRIu32" (%.1f%%)\n"
, iNumXEntries, 100.0 * (float)iNumXEntries / RXCACHE_TABLE);
strbuf_addf(sbuf, "Memory allocated: %lu\n", iXSizeAlloc);
strbuf_addf(sbuf, "Memory allocated: %"PRIu32"\n", iXSizeAlloc);
iNumXReq = iNumXRequests ? iNumXRequests : 1;
strbuf_addf(sbuf
, "Requests: %lu - Found: %lu (%.1f%%) - Coll: %lu (%.1f%% req/%.1f%% entries)\n"
, "Requests: %"PRIu32" - Found: %"PRIu32" (%.1f%%) - "
"Coll: %"PRIu32" (%.1f%% req/%.1f%% entries)\n"
, iNumXRequests, iNumXFound, 100.0 * (float)iNumXFound/(float)iNumXReq
, iNumXCollisions, 100.0 * (float)iNumXCollisions/(float)iNumXReq
, 100.0 * (float)iNumXCollisions/(iNumXEntries ? iNumXEntries : 1)
@ -1185,7 +1222,8 @@ rxcache_status (strbuf_t *sbuf, Bool verbose)
}
else
{
strbuf_addf(sbuf, "Regexp cache:\t\t\t%8ld %9lu\n", iNumXEntries, iXSizeAlloc);
strbuf_addf(sbuf, "Regexp cache:\t\t\t%8"PRId32" %9"PRIu32"\n",
iNumXEntries, iXSizeAlloc);
}
return iXSizeAlloc;

View file

@ -111,7 +111,7 @@ static string_t ** stringtable = NULL;
* This does include the memory by the string management structures.
*/
static mp_uint mstr_tabled = 0;
static mp_uint mstr_tabled_count = 0;
/* Number of distinct strings in the string table.
*/
@ -128,14 +128,14 @@ static mp_uint mstr_added = 0;
*/
static mp_uint mstr_deleted = 0;
/* Number of distinct strings delete from the string table.
/* Number of distinct strings deleted from the string table.
*/
static mp_uint mstr_collisions = 0;
/* Number of collisions when adding a new distinct string.
*/
static mp_uint mstr_untabled = 0;
static mp_uint mstr_untabled_count = 0;
/* Number of distinct untabled strings.
*/
@ -180,7 +180,7 @@ unsigned long stNumTabledCheckedSearch = 0;
/*-------------------------------------------------------------------------*/
static INLINE whash_t
hash_string (const char * const s, size_t size)
hash_string_inl (const char * const s, size_t size)
/* Compute the hash for string <s> of length <size> and return it.
* The result will always be non-zero.
@ -193,7 +193,13 @@ hash_string (const char * const s, size_t size)
if (!hash)
hash = 1 << (sizeof (hash) * CHAR_BIT - 1);
return hash;
} /* hash_string() */
} /* hash_string_inl() */
whash_t
hash_string (const char * const s, size_t size)
{
return hash_string_inl(s, size);
}
/*-------------------------------------------------------------------------*/
static INLINE whash_t
@ -204,7 +210,7 @@ get_hash (string_t * pStr)
{
if (!pStr->hash)
pStr->hash = hash_string(pStr->txt, pStr->size);
pStr->hash = hash_string_inl(pStr->txt, pStr->size);
return pStr->hash;
} /* get_hash() */
@ -363,7 +369,7 @@ make_new_tabled (const char * const pTxt, size_t size, whash_t hash MTRACE_DECL)
msize = mstr_mem_size(string);
mstr_used++;
mstr_used_size += msize;
mstr_tabled++;
mstr_tabled_count++;
mstr_tabled_size += msize;
}
@ -409,7 +415,7 @@ mstring_alloc_string (size_t iSize MTRACE_DECL)
msize = mstr_mem_size(string);
mstr_used++;
mstr_used_size += msize;
mstr_untabled++;
mstr_untabled_count++;
mstr_untabled_size += msize;
}
@ -486,7 +492,7 @@ mstring_new_tabled (const char * const pTxt MTRACE_DECL)
string_t * string;
size = strlen(pTxt);
hash = hash_string(pTxt, size);
hash = hash_string_inl(pTxt, size);
/* Check if the string has already been tabled */
string = find_and_move(pTxt, size, hash);
@ -516,7 +522,7 @@ mstring_new_n_tabled (const char * const pTxt, size_t size MTRACE_DECL)
whash_t hash;
string_t * string;
hash = hash_string(pTxt, size);
hash = hash_string_inl(pTxt, size);
/* Check if the string has already been tabled */
string = find_and_move(pTxt, size, hash);
@ -581,10 +587,10 @@ table_string (string_t * pStr MTRACE_DECL)
pStr->next = stringtable[idx];
stringtable[idx] = pStr;
mstr_tabled++;
mstr_tabled_count++;
mstr_tabled_size += msize;
mstr_untabled--;
mstr_untabled_count--;
mstr_untabled_size -= msize;
string = pStr;
@ -792,7 +798,7 @@ mstring_find_tabled_str (const char * const pTxt, size_t size)
{
whash_t hash;
hash = hash_string(pTxt, size);
hash = hash_string_inl(pTxt, size);
return find_and_move(pTxt, size, hash);
} /* mstring_find_tabled_str() */
@ -831,7 +837,7 @@ mstring_free (string_t *s)
int idx;
mstr_tabled--;
mstr_tabled_count--;
mstr_tabled_size -= msize;
idx = HashToIndex(get_hash(s));
@ -853,7 +859,7 @@ mstring_free (string_t *s)
{
/* An untabled string */
mstr_untabled--;
mstr_untabled_count--;
mstr_untabled_size -= msize;
}
@ -861,36 +867,6 @@ mstring_free (string_t *s)
xfree(s);
} /* mstring_free() */
/*-------------------------------------------------------------------------*/
string_t *
mstring_ref ( string_t * str)
/* Aliased to: ref_mstring_safe(s)
*
* Increment the refcount for string <str> and return the ref'ed string.
* In contrast to macro ref_mstring(), this function can handle arguments
* with sideeffects.
*/
{
return ref_mstring(str);
} /* mstring_ref() */
/*-------------------------------------------------------------------------*/
unsigned long
mstring_deref ( string_t * str)
/* Aliased to: deref_mstring_safe(s)
*
* Decrement the refcount for string <str> and return the new refcount.
* In contrast to macro deref_mstring(), this function can handle arguments
* with sideeffects.
*/
{
return deref_mstring(str);
} /* mstring_deref() */
/*-------------------------------------------------------------------------*/
Bool
mstring_equal(string_t * const pStr1, string_t * const pStr2)
@ -1048,12 +1024,13 @@ mstring_mstr_n_str ( const string_t * const pStr, size_t start
size_t left;
char first;
if (start >= mstrsize(pStr))
if (start > mstrsize(pStr))
return NULL;
/* Initialize 'characters remaining' and 'current position' */
left = mstrsize(pStr) - start;
cp = get_txt(pStr)+start;
/* remove the const qualifier temporarily when calling get_txt(). */
cp = get_txt((string_t *const)pStr)+start;
/* Special case: strstr("text", "") */
if (len == 0)
@ -1099,12 +1076,12 @@ mstring_mstr_rn_str ( const string_t * const pStr, size_t start
size_t left;
char first;
if (start >= mstrsize(pStr))
if (start > mstrsize(pStr))
return NULL;
/* Initialize 'characters remaining' and 'current position' */
left = mstrsize(pStr) - start;
cp = get_txt(pStr)+start;
cp = get_txt((string_t *const)pStr)+start;
/* Special case: strrstr("text", "") */
if (len == 0)
@ -1119,7 +1096,7 @@ mstring_mstr_rn_str ( const string_t * const pStr, size_t start
&& 0 == memcmp(cp, pTxt, len)
)
return cp;
} while (cp != get_txt(pStr));
} while (cp != get_txt((string_t *const)pStr));
return NULL;
} /* mstring_mstr_n_str() */
@ -1146,7 +1123,7 @@ mstring_add_slash (const string_t *str MTRACE_DECL)
{
txt = get_txt(tmp);
*txt = '/';
memcpy(txt+1, get_txt(str), mstrsize(str));
memcpy(txt+1, get_txt((string_t *const)str), mstrsize(str));
}
return tmp;
} /* mstring_add_slash() */
@ -1234,7 +1211,7 @@ mstring_cvt_progname (const string_t *str MTRACE_DECL)
const char * txt, *p;
char *txt2;
txt = get_txt(str);
txt = get_txt((string_t *const)str);
len = mstrsize(str);
p = strrchr(txt, '.');
@ -1287,8 +1264,8 @@ mstring_add (const string_t *left, const string_t *right MTRACE_DECL)
char * txt;
txt = get_txt(tmp);
memcpy(txt, get_txt(left), lleft);
memcpy(txt+lleft, get_txt(right), lright);
memcpy(txt, get_txt((string_t *const)left), lleft);
memcpy(txt+lleft, get_txt((string_t *const)right), lright);
}
return tmp;
} /* mstring_add() */
@ -1317,7 +1294,7 @@ mstring_add_txt (const string_t *left, const char *right, size_t len MTRACE_DECL
if (tmp)
{
txt = get_txt(tmp);
memcpy(txt, get_txt(left), lleft);
memcpy(txt, get_txt((string_t *const)left), lleft);
memcpy(txt+lleft, right, len);
}
return tmp;
@ -1348,7 +1325,7 @@ mstring_add_to_txt (const char *left, size_t len, const string_t *right MTRACE_D
{
txt = get_txt(tmp);
memcpy(txt, left, len);
memcpy(txt+len, get_txt(right), lright);
memcpy(txt+len, get_txt((string_t *const)right), lright);
}
return tmp;
} /* mstring_add_to_txt() */
@ -1432,7 +1409,7 @@ mstring_repeat (const string_t *base, size_t num MTRACE_DECL)
char * txt = get_txt(result);
/* Seed result[] with one copy of the string */
memcpy(txt, get_txt(base), len);
memcpy(txt, get_txt((string_t *const)base), len);
/* Repeatedly double the string in result */
curlen = len;
@ -1506,7 +1483,7 @@ mstring_extract (const string_t *str, size_t start, long end MTRACE_DECL)
result = mstring_alloc_string(reslen MTRACE_PASS);
if (result && reslen)
{
memcpy(get_txt(result), get_txt(str)+start, reslen);
memcpy(get_txt(result), get_txt((string_t *const)str)+start, reslen);
}
return result;
} /* mstring_extract() */
@ -1524,8 +1501,8 @@ mstring_prefixed (const string_t *p, const string_t *s)
const char *pp, *ps;
size_t lp, ls;
lp = mstrsize(p); pp = get_txt(p);
ls = mstrsize(s); ps = get_txt(s);
lp = mstrsize(p); pp = get_txt((string_t *const)p);
ls = mstrsize(s); ps = get_txt((string_t *const)s);
for (; lp > 0 && ls > 0; lp--, ls--)
{
@ -1549,9 +1526,9 @@ mstring_chr (const string_t *p, char c)
{
char *pp;
pp = memchr(get_txt(p), c, mstrsize(p));
pp = memchr(get_txt((string_t *const)p), c, mstrsize(p));
if (pp != NULL)
return pp - get_txt(p);
return pp - get_txt((string_t *const)p);
return -1;
} /* mstring_chr() */
@ -1676,9 +1653,9 @@ mstring_gc_table (void)
next = this->next;
}
mstr_untabled++;
mstr_untabled_count++;
mstr_untabled_size += mstr_mem_size(this);
mstr_tabled--;
mstr_tabled_count--;
mstr_tabled_size += mstr_mem_size(this);
mstr_deleted++;
@ -1715,10 +1692,10 @@ add_string_status (strbuf_t *sbuf, Bool verbose)
mp_uint distinct_overhead;
stringtable_size = HTABLE_SIZE * sizeof(string_t *);
distinct_strings = mstr_tabled + mstr_untabled;
distinct_strings = mstr_tabled_count + mstr_untabled_count;
distinct_size = mstr_tabled_size + mstr_untabled_size;
distinct_overhead = mstr_tabled * STR_OVERHEAD
+ mstr_untabled * STR_OVERHEAD;
distinct_overhead = mstr_tabled_count * STR_OVERHEAD
+ mstr_untabled_count * STR_OVERHEAD;
if (!verbose)
{
@ -1748,20 +1725,20 @@ add_string_status (strbuf_t *sbuf, Bool verbose)
, distinct_overhead + stringtable_size
);
strbuf_addf(sbuf, " - tabled\t%9lu %9lu (%9lu+%9lu)\n"
, mstr_tabled
, mstr_tabled_count
, mstr_tabled_size + stringtable_size
, mstr_tabled_size
? mstr_tabled_size - mstr_tabled * STR_OVERHEAD
? mstr_tabled_size - mstr_tabled_count * STR_OVERHEAD
: 0
, mstr_tabled * STR_OVERHEAD + stringtable_size
, mstr_tabled_count * STR_OVERHEAD + stringtable_size
);
strbuf_addf(sbuf, " - untabled\t%9lu %9lu (%9lu+%9lu)\n"
, mstr_untabled
, mstr_untabled_count
, mstr_untabled_size
, mstr_untabled_size
? mstr_untabled_size - mstr_untabled * STR_OVERHEAD
? mstr_untabled_size - mstr_untabled_count * STR_OVERHEAD
: 0
, mstr_untabled * STR_OVERHEAD
, mstr_untabled_count * STR_OVERHEAD
);
strbuf_addf(sbuf, "\nSpace required vs. 'regular C' string implementation: "
"%lu%% with, %lu%% without overhead.\n"
@ -1782,7 +1759,7 @@ add_string_status (strbuf_t *sbuf, Bool verbose)
, (float)mstr_searchlen_byvalue / (float)mstr_searches_byvalue
);
strbuf_addf(sbuf, "Hash chains used: %lu of %lu (%.1f%%)\n"
, mstr_chains, HTABLE_SIZE
, mstr_chains, (unsigned long)HTABLE_SIZE
, 100.0 * (float)mstr_chains / (float)HTABLE_SIZE
);
strbuf_addf(sbuf, "Distinct strings added: %lu "
@ -1847,9 +1824,9 @@ string_dinfo_status (svalue_t *svp, int value)
ST_NUMBER(DID_ST_STR_DELETED, mstr_deleted);
ST_NUMBER(DID_ST_STR_COLLISIONS, mstr_collisions);
ST_NUMBER(DID_ST_UNTABLED, mstr_untabled);
ST_NUMBER(DID_ST_UNTABLED, mstr_untabled_count);
ST_NUMBER(DID_ST_UNTABLED_SIZE, mstr_untabled_size);
ST_NUMBER(DID_ST_TABLED, mstr_tabled);
ST_NUMBER(DID_ST_TABLED, mstr_tabled_count);
ST_NUMBER(DID_ST_TABLED_SIZE, mstr_tabled_size);
ST_NUMBER(DID_ST_STR_SEARCHES, mstr_searches);

View file

@ -65,6 +65,7 @@ extern mp_uint mstr_used_size;
/* --- Prototypes --- */
extern void mstring_init (void);
extern whash_t hash_string (const char * const s, size_t size);
extern whash_t mstring_get_hash (string_t * pStr);
extern string_t * mstring_alloc_string (size_t iSize MTRACE_DECL);
extern string_t * mstring_new_string (const char * const pTxt MTRACE_DECL);
@ -84,8 +85,6 @@ extern int mstring_compare( string_t * const pStr1
extern Bool mstring_equal( string_t * const pStr1
, string_t * const pStr2);
extern void mstring_free (string_t *s);
extern string_t * mstring_ref ( string_t * str);
extern unsigned long mstring_deref ( string_t * str);
extern const char * mstring_mstr_n_str(const string_t * const pStr, size_t start, const char * const pTxt, size_t len);
extern const char * mstring_mstr_rn_str(const string_t * const pStr, size_t start, const char * const pTxt, size_t len);
extern string_t * mstring_add_slash (const string_t *str MTRACE_DECL);
@ -116,110 +115,140 @@ extern void string_dinfo_status(svalue_t *svp, int value);
/* --- Inline functions and macros --- */
#define mstr_mem_size(s) \
(sizeof(string_t) + (s)->size)
/* size_t mstr_mem_size(string_t * s)
* The amount of memory used to hold all this strings' data.
static INLINE size_t mstr_mem_size(const string_t * const s)
__attribute__((nonnull(1)))
__attribute__((pure));
static INLINE size_t mstr_mem_size(const string_t * const s)
/* The amount of memory used to hold all this strings' data.
* Used only to keep the statistics up to date.
*/
{
return sizeof(string_t) + s->size;
}
#define mstr_hash(s) \
( (s)->hash )
/* whash_t mstr_hash(string_t * s)
* Return the hash value of string <s>, which is 0 if the
static INLINE whash_t mstr_hash(const string_t * const s)
__attribute__((nonnull(1)))
__attribute__((pure));
static INLINE whash_t mstr_hash(const string_t * const s)
/* Return the hash value of string <s>, which is 0 if the
* hash hasn't been computed yet.
*/
{
return s->hash;
}
#define mstr_singular(s) \
(! ((s)->info.tabled || (s)->info.ref != 1) )
/* Bool mstr_singular(string_t *s)
* Return FALSE if string<s> has multiple users, ie. is tabled
* or has more than one reference.
static INLINE Bool mstr_singular(const string_t * const s)
__attribute__((nonnull(1)))
__attribute__((pure));
static INLINE Bool mstr_singular(const string_t * const s)
/* Return FALSE if string<s> has multiple users, ie. is tabled
* or has more than one reference.
*/
{
return ! (s->info.tabled || s->info.ref != 1);
}
#define mstr_untabled(s) \
(!(s)->info.tabled)
/* Bool mstr_untabled (string_t *s)
* Return TRUE if string <s> is not tabled.
* The argument must not have sideeffects!
static INLINE Bool mstr_untabled(const string_t * const s)
__attribute__((nonnull(1)))
__attribute__((pure));
static INLINE Bool mstr_untabled(const string_t * const s)
/* Return TRUE if string <s> is not tabled.
*/
{
return !(s->info.tabled);
}
#define mstr_tabled(s) \
((s)->info.tabled)
/* Bool mstr_tabled (string_t *s)
* Return TRUE if string <s> is tabled - directly or indirectly.
* The argument must not have sideeffects!
static INLINE Bool mstr_tabled(const string_t * const s)
__attribute__((nonnull(1)))
__attribute__((pure));
static INLINE Bool mstr_tabled(const string_t * const s)
/* Return TRUE if string <s> is tabled - directly or indirectly.
*/
{
return s->info.tabled;
}
#define mstrsize(s) \
((s)->size)
/* size_t mstrsize(string_t *s)
* Return the size (length) of the string <s>.
static INLINE size_t mstrsize(const string_t * const s)
__attribute__((nonnull(1)))
__attribute__((pure));
static INLINE size_t mstrsize(const string_t * const s)
/* Return the size (length) of the string <s>.
*/
{
return s->size;
}
#define ref_mstring(s) \
(mstr_used++, mstr_used_size += mstr_mem_size(s), (s)->info.ref ? ++((s)->info.ref) : 0, (s))
#define ref_mstring_safe(s) mstring_ref(s)
/* string_t * ref_mstring (string_t *s)
* string_t * ref_mstring_safe (string_t *s)
* Increment the refcount for string <s> and return the ref'ed string.
* The argument <s> to ref_mstring() must not have sideeffects!
static INLINE string_t *ref_mstring(string_t *const s) __attribute__((nonnull(1)));
static INLINE string_t *ref_mstring(string_t *const s)
/* Increment the refcount for string <s> and return the ref'ed string.
*/
{
mstr_used++;
mstr_used_size += mstr_mem_size(s);
if (s->info.ref)
++(s->info.ref);
return s;
}
#define deref_mstring(s) \
(mstr_used--, mstr_used_size -= mstr_mem_size(s), (s)->info.ref ? --((s)->info.ref) : (s)->info.ref)
#define deref_mstring_safe(s) mstring_deref(s)
/* int deref_mstring (string_t *s)
* int deref_mstring_safe (string_t *s)
* Decrement the refcount for string <s> and return the new count.
* The argument <s> to deref_mstring() must not have sideeffects!
static INLINE unsigned int deref_mstring(string_t *const s) __attribute__((nonnull(1)));
static INLINE unsigned int deref_mstring(string_t *const s)
/* Decrement the refcount for string <s> and return the new count.
*/
{
mstr_used--;
mstr_used_size -= mstr_mem_size(s);
if (s->info.ref)
--(s->info.ref);
return s->info.ref;
}
#define free_mstring(s) \
MACRO(string_t * fmsttmp = s; if (fmsttmp != NULL) { if (fmsttmp->info.ref == 1) { mstring_free(fmsttmp); } else deref_mstring(fmsttmp); } )
/* void free_mstring(s)
*
* Decrement the refcount for string <s>, and if it reaches 0,
* deallocate <s> altogether.
static INLINE void free_mstring(string_t *const s) __attribute__((nonnull(1)));
static INLINE void free_mstring(string_t *const s)
/* Decrement the refcount for string <s>, and if it reaches 0,
* deallocate <s> altogether.
* TODO: check if s can really be NULL or should be allowed to be.
*/
{
if (s != NULL)
{
if (s->info.ref == 1)
{
mstring_free(s);
}
else
deref_mstring(s);
}
}
#define get_txt(s) \
((s)->txt)
/* char * get_txt (string_t *s)
*
* Return a pointer to the actual string text of string <s>.
* There is at least one '\0' terminating the string text.
static INLINE char *get_txt(string_t *const s)
__attribute__((nonnull(1)))
__attribute__((pure));
static INLINE char *get_txt(string_t *const s)
/* Return a pointer to the actual string text of string <s>.
* There is at least one '\0' terminating the string text.
* BTW: It is a pity that it can't be const char *get_txt().
*/
{
return s->txt;
}
#define extract_cstr(d,s,l) \
MACRO(strncpy((d), get_txt(s), (l)-1); \
if ((l) > mstrsize(s)) \
d[mstrsize(s)] = '\0'; \
else \
d[(l)-1] = '\0'; \
)
/* void extract_cstr (char * d, string_t *s, size_t l)
*
* Extract the C string from <s> (that is: all characters up to the
* first '\0' resp the end of the string) and copy it into buffer <d>
* of size <l>. The macro makes sure that the string is terminated
* with a '\0'
static INLINE void extract_cstr(char *d, const string_t *const s, size_t l)
__attribute__((nonnull(1,2)));
static INLINE void extract_cstr(char *d, const string_t *const s, size_t l)
/* Extract the C string from <s> (that is: all characters up to the
* first '\0' resp the end of the string) and copy it into buffer <d>
* of size <l>. The macro makes sure that the string is terminated
* with a '\0'
*/
{
strncpy(d, get_txt((string_t*)s), l-1);
if (l > mstrsize(s))
d[mstrsize(s)] = '\0';
else
d[l-1] = '\0';
}
/* A handful of shorthands for commonly used functions */

View file

@ -39,7 +39,7 @@
extern int getpagesize();
# endif
# if defined(sun) || defined(ultrix)
extern int getrusage(int, struct rusage *);
extern int getrusage (int, struct rusage *);
# endif
#else /* !HAVE_GETRUSAGE */

File diff suppressed because it is too large Load diff

View file

@ -189,7 +189,7 @@ struct replace_ob_s
# define ref_object(o,from) (\
(o)->ref++,\
d_flag > 1 ? printf("Add ref to object %s: %ld (%s) %s %d\n" \
d_flag > 1 ? printf("Add ref to object %s: %"PRIdPINT" (%s) %s %d\n" \
, get_txt((o)->name), (o)->ref, from, __FILE__, __LINE__) : 0, \
(o))
@ -233,7 +233,7 @@ struct replace_ob_s
object_t * tmp_ = o; \
if (tmp_->ref == 2) dest_last_ref_gone = MY_TRUE; \
tmp_->ref--;\
if (d_flag > 1) printf("Sub ref from object %s: %ld (%s) %s %d\n"\
if (d_flag > 1) printf("Sub ref from object %s: %"PRIdPINT" (%s) %s %d\n"\
, get_txt(tmp_->name), tmp_->ref, from, __FILE__, __LINE__);\
if (tmp_->ref <= 0) dealloc_object(tmp_); \
)
@ -242,7 +242,7 @@ struct replace_ob_s
object_t * tmp_ = o; \
if (tmp_->ref == 2) dest_last_ref_gone = MY_TRUE; \
tmp_->ref--;\
if (d_flag > 1) printf("Sub ref from object %s: %ld (%s) %s %d\n"\
if (d_flag > 1) printf("Sub ref from object %s: %"PRIdPINT" (%s) %s %d\n"\
, get_txt(tmp_->name), tmp_->ref, from, __FILE__, __LINE__);\
if (tmp_->ref <= 0) dealloc_object(tmp_, __FILE__, __LINE__); \
)
@ -262,7 +262,7 @@ struct replace_ob_s
#else
# define deref_object(o,from) (--(o)->ref, \
d_flag > 1 ? printf("Sub ref from object %s: %ld (%s)\n" \
d_flag > 1 ? printf("Sub ref from object %s: %"PRIdPINT" (%s)\n" \
, get_txt((o)->name), (o)->ref, from) : 0)
#endif
@ -321,7 +321,7 @@ extern void dealloc_object(object_t *);
extern void dealloc_object(object_t *, const char * file, int line);
#endif
extern object_t *get_empty_object(int num_var);
extern void init_object_variables (object_t *ob);
extern void init_object_variables (object_t *ob, object_t *templ);
extern svalue_t *v_function_exists(svalue_t *sp, int num_arg);
extern svalue_t *f_functionlist(svalue_t *sp);

View file

@ -51,10 +51,10 @@
#if !( (OTABLE_SIZE) & (OTABLE_SIZE)-1 )
# define ObjHash(s) (mstr_get_hash(s) & ((OTABLE_SIZE)-1) )
# define ObjHashStr(s,len) (whashmem(s, len, MSTRING_HASH_LENGTH) & ((OTABLE_SIZE)-1) )
# define ObjHashStr(s,len) (hash_string(s, len) & ((OTABLE_SIZE)-1) )
#else
# define ObjHash(s) (mstr_get_hash(s) % OTABLE_SIZE)
# define ObjHashStr(s,len) (whashmem(s, len, MSTRING_HASH_LENGTH) % OTABLE_SIZE)
# define ObjHashStr(s,len) (hash_string(s, len) % OTABLE_SIZE)
#endif
/* Hash the string <s> and compute the appropriate table index
*/

View file

@ -216,7 +216,7 @@ f_idna_stringprep (svalue_t *sp)
{
errorf("stringprep(): Error %s", stringprep_strerror(ret));
/* NOTREACHED */
}
}
else
{
// free the string argument

560
src/pkg-iksemel.c Normal file
View file

@ -0,0 +1,560 @@
/*------------------------------------------------------------------
* iksemel Efuns
*
*------------------------------------------------------------------
* This file holds the efuns interfacing with iksemel and provides
* functions for handling xml files and converting them between
* mappings and xml data strings.
*
* efun: xml_
*------------------------------------------------------------------
*/
#include "driver.h"
#ifdef USE_IKSEMEL
#include <iksemel.h>
#include "array.h"
#include "xalloc.h"
#include "mapping.h"
#include "mstrings.h"
#include "simulate.h"
#include "interpret.h"
#include "pkg-iksemel.h"
#include "typedefs.h"
#include "../mudlib/sys/xml.h"
typedef struct attribute_walk_extra_s attribute_walk_extra_t;
/* This structure is used to walk all attributes as well as for error handling.
* In case an error happens, this structure is called too.
*/
struct attribute_walk_extra_s
{
iks *node;
int size;
char *tag_name;
};
/* This structure is used for error handling. In case of an error our handler
* called with a pointer ot this structure.
*/
struct xml_cleanup_s
{
svalue_t head; /* push_error_handler saves the link to our handler here. */
iks *node;
iksparser *parser;
};
void *
iksemel_alloc(size_t size)
{
return xalloc(size);
}
void
iksemel_free(void *ptr)
{
xfree(ptr);
}
void
add_string_to_mapping(mapping_t *map, char *skey, char *svalue)
/*
* Adds a string value under the given key to the given mapping. In case the
* value already exists, it is overriden.
*/
{
svalue_t key;
svalue_t *value;
/* change the c string into an string_t */
put_c_string(&key, skey);
/* get or insert key */
value = get_map_lvalue(map, &key);
/* free the string_t again */
free_svalue(&key);
/* free maybe existing value (should not happen, i hope) */
free_svalue(value);
/* change the value of the key to the given value */
put_c_string(value, svalue);
}
void
parse_node(svalue_t *result, iks *node)
/*
* Parses the xml DOM starting at node and returns the information on the
* stack.
*/
{
int i = 0;
int num_attributes = 0;
int num_children = 0;
iks *attribute;
iks *child;
vector_t *root = NULL;
vector_t *children = NULL;
mapping_t *attributes = NULL;
/* lets figure out if the node is cdata or another tag */
switch (iks_type(node))
{
case IKS_NONE:
case IKS_ATTRIBUTE:
/* we ignore those, as they will not occure for us */
return;
case IKS_CDATA:
/* Add the string as result, and return */
put_c_n_string(result, iks_cdata(node), iks_cdata_size(node));
return;
case IKS_TAG:
break;
}
/* We have a tag here, so allocate a tag array with three elements
* (name, contents and attributes)
*/
memsafe(root = allocate_array(XML_TAG_SIZE), sizeof(*root), "new tag array");
/* Put the array as result */
put_array(result, root);
/* add name to array */
put_c_string(&root->item[XML_TAG_NAME], iks_name(node));
/* check if the node has any children */
child = iks_child(node);
if (child != NULL)
{
do
{
++num_children;
}
while ((child = iks_next(child)));
}
if (0 < num_children)
{
/* children need to stay in the right order, so we create another
* for them
*/
memsafe(children = allocate_array(num_children), sizeof(*children)
, "new tag contents array");
/* Add the array of all children to the node */
put_array(&root->item[XML_TAG_CONTENTS], children);
/* get the first child */
child = iks_child(node);
do
{
/* recurse here cause the child can be a string or another node */
parse_node(&children->item[i++], child);
}
while ((child = iks_next(child)));
}
/* Finally, lets handle the attributes, we need to find out how many
* attributes the node has, to allocate enough memory for them. If
* no attributes exist, the part in the array will be empty */
attribute = iks_attrib(node);
if (attribute != NULL)
{
do
{
++num_attributes;
}
while ((attribute = iks_next(attribute)));
}
if (0 < num_attributes)
{
/* allocate new mapping */
memsafe(attributes = allocate_mapping(num_attributes, 1), sizeof(*attributes)
, "new attributes mapping");
/* add the attributes to the array */
put_mapping(&root->item[XML_TAG_ATTRIBUTES], attributes);
/* get the first one */
attribute = iks_attrib(node);
do
{
add_string_to_mapping(attributes, iks_name(attribute), iks_cdata(attribute));
}
while ((attribute = iks_next(attribute)));
}
}
void
walk_attribute_mapping(svalue_t *key, svalue_t *val, void *pextra)
/*
* Callback for walk_mapping() used in generate_xml_node to add iks
* attribute nodes to the node given in the pextra.
*/
{
char *ckey;
attribute_walk_extra_t *extra = pextra;
if (key->type == T_STRING)
{
ckey = get_txt(key->u.str);
}
else
{
errorf("Bad argument 1 to xml_generate(): expected string for attribute key of tag '%s'.\n"
, extra->tag_name);
/* NOTREACHED */
return;
}
if (val->type == T_STRING)
{
memsafe(iks_insert_attrib(extra->node, ckey, get_txt(val->u.str))
, sizeof(*ckey), "new iksemel attribute");
}
else
{
errorf("Bad argument 1 to xml_generate(): expected string for value of attribute '%s' of tag '%s'.\n"
, ckey, extra->tag_name);
}
}
static void
xml_cleanup(svalue_t * arg)
/*
* Takes care, that the node without parent (root node) is correctly freed in
* case of an error and at the end of the f_generate_xml().
*/
{
struct xml_cleanup_s * data;
data = (struct xml_cleanup_s *)arg;
if (data->node)
{
iks_delete(data->node);
}
if (data->parser)
{
iks_parser_delete(data->parser);
}
xfree(data);
} /* xml_cleanup() */
iks *
generate_xml_node(vector_t *vnode, iks *parent)
/*
* Generates a new iks node from the given array structure with the three
* elements (name, contents, attributes) and adds the node to the parent,
* or in case this is empty, simply returns it. The contents element may
* contain other tags, so recursion may occur.
*/
{
iks *node;
svalue_t *element;
char *name;
struct xml_cleanup_s * rec_data;
if ((mp_int) VEC_SIZE(vnode) != 3)
{
errorf("Bad arg 1 to xml_generate(): tag is not an array with 3 "
"elements.\n");
/* NOTREACHED */
return NULL;
}
/* get the name, as this is essential */
element = &vnode->item[XML_TAG_NAME];
if (element->type != T_STRING)
{
errorf("Bad arg 1 to xml_generate(): first element of tag array not a "
"string.\n");
/* NOTREACHED */
return NULL;
}
/* get the name */
name = get_txt(element->u.str);
/* depending whether there is a parent or not, we start the structure
* or add the node to the given one */
if (parent == NULL)
{
memsafe(node = iks_new(name), 30, "new iksemel node");
rec_data = xalloc(sizeof(*rec_data));
if (rec_data == NULL)
{
iks_delete(node);
errorf("generate_xml() Out of memory: (%lu bytes) for cleanup structure\n"
, (unsigned long) sizeof(*rec_data));
/* NOTREACHED */
return NULL;
}
rec_data->node = node;
rec_data->parser = NULL;
push_error_handler(xml_cleanup, &(rec_data->head));
}
else
{
memsafe(node = iks_insert(parent, name), 30, "insert new iksemel node");
}
/* now handle the attributes of this one */
element = &vnode->item[XML_TAG_ATTRIBUTES];
/* this might be absent */
if (element->type == T_MAPPING)
{
attribute_walk_extra_t extra;
extra.node = node;
extra.size = element->u.map->num_values;
extra.tag_name = name;
/* walk the mapping and add all attributes */
walk_mapping(element->u.map, &walk_attribute_mapping, &extra);
}
else if (element->type != T_NUMBER || element->u.number != 0)
{
errorf("Bad arg 1 to xml_generate(): second element of tag array not "
"NULL/mapping.\n");
/* NOTREACHED */
return NULL;
}
/* now check, if the node has a contents */
element = &vnode->item[XML_TAG_CONTENTS];
/* this might even be absent */
if (element->type == T_POINTER)
{
int size;
int i;
vector_t *contents;
/* get the vector */
contents = element->u.vec;
/* get its size */
size = (mp_int)VEC_SIZE(contents);
for (i = 0; i < size; i++)
{
element = &contents->item[i];
if (element->type == T_STRING)
{
/* found a cdata */
memsafe(iks_insert_cdata(node, get_txt(element->u.str), mstrsize(element->u.str))
, mstrsize(element->u.str)
, "new iksemel node cdata");
}
else if (element->type == T_POINTER)
{
/* found a sub tag, as iks_insert will handle the insert we do
* not have anything to do with the result
*/
generate_xml_node(element->u.vec, node);
}
}
}
else if (element->type != T_NUMBER || element->u.number != 0)
{
errorf("Bad arg 1 to xml_generate(): third element of tag array not "
"NULL/array.\n");
/* NOTREACHED */
return NULL;
}
return node;
}
void
pkg_iksemel_init()
{
iks_set_mem_funcs(iksemel_alloc, iksemel_free);
}
/*=========================================================================*/
/* EFUNS */
/*-------------------------------------------------------------------------*/
svalue_t *
f_xml_generate(svalue_t *sp)
/* EFUN xml_generate()
*
* string xml_generate(mixed *xml)
*
* Converts the given <xml> array into an XML conform string, if
* possible. The <xml> argument array must have the same structure
* as xml_parse returns.
*
* In case the parameter does not follow these rules, errors are raised.
* The method returns a valid XML string otherwise.
*/
{
char *xml_string;
iks *node;
vector_t *root;
/* get the root of the structure to be used */
root = sp->u.vec;
/* start generating the tree */
node = generate_xml_node(root, NULL);
/* At this point generate_xml_node() had
put an error handler on the stack.
*/
/* Clean up and return result */
free_svalue(sp);
/* get the xml string out of the stack */
memsafe(xml_string = iks_string(iks_stack(node), node)
, sizeof(*xml_string), "new xml string from node");
/* send the xml string back onto the stack */
put_c_string(sp, xml_string);
/* clean up, this will free the root node too, as it calls our error handler */
pop_stack();
return sp;
}
svalue_t *
f_xml_parse(svalue_t * sp)
/* EFUN xml_parse()
*
* mixed * xml_parse(string xml_text)
*
* Parses the given string <xml> as a XML conform string. The string must
* have only one root tag, subsequent root tags are ignored.
*
* If the xml string is correct, an array is of three elements is
* returned, where as the following indices are defined:
*
* string XML_TAG_NAME
* The name of the XML tag.
*
* mixed * XML_TAG_CONTENTS
* The contents of this xml tag as array. This array may
* contain either strings, or arrags of sub-tags again with
* three elements (see example)
*
* If the xml tag does not contain anything, the element is
* set 0.
*
* mapping XML_TAG_ATTRIBUTES
* All attributes given to the XML tag as mapping where the key
* is the attribute name and the value is its string value.
*
* If the xml tag does not contain any attributes, this element
* is set 0.
*
* If the XML string is not well formed, or there is not enough memory to
* parse the whole XML structure into the array an error is raised. In case
* the XML string can't be parsed, cause it is not valid XML, 0 is returned.
*/
{
struct xml_cleanup_s * rec_data;
int err;
memsafe(rec_data = xalloc(sizeof(*rec_data)), sizeof(*rec_data), "xml cleanup structure");
rec_data->node = NULL;
rec_data->parser = NULL;
push_error_handler(xml_cleanup, &(rec_data->head));
/* TODO: This can be implemented more efficient using the SAX interface. */
memsafe(rec_data->parser = iks_dom_new(&(rec_data->node)), 50, "new iksemel parser");
err = iks_parse(rec_data->parser, get_txt(sp->u.str), mstrsize(sp->u.str), 1);
switch (err)
{
case IKS_OK:
break;
case IKS_NOMEM:
errorf("Out of memory.\n");
/* NOTREACHED */
return sp;
case IKS_BADXML:
errorf("Bad arg 1 to xml_parse(): XML document not well formed (error "
"in line %ld, byte %ld).\n", iks_nr_lines(rec_data->parser)
, iks_nr_bytes(rec_data->parser));
/* NOTREACHED */
return sp;
case IKS_HOOK:
/* actually only used for a sax parser? */
break;
}
/* we no longer need the string */
free_svalue(sp);
/* set 0 to always have a valid return */
put_number(sp, 0);
if (rec_data->node != NULL)
{
/* tree contains the tree now, this will put the resulting a */
parse_node(sp, rec_data->node);
}
else
{
/* There was no XML tag or the tag was not closed properly. */
errorf("Bad arg 1 to xml_parse(): XML document not well formed (premature end "
"at line %ld, byte %ld).\n", iks_nr_lines(rec_data->parser)
, iks_nr_bytes(rec_data->parser));
}
/* At the end, be nice and remove the rest
using our error handler. */
pop_stack();
return sp;
}
#endif /* USE_IKSEMEL */

19
src/pkg-iksemel.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef PKG_IKSEMEL_H__
#define PKG_IKSEMEL_H__ 1
#include "driver.h"
#ifdef USE_IKSEMEL
#ifndef HAS_IKSEMEL
#error "pkg-iksemel configured even though the machine doesn't support iksemel."
#endif
/* --- Prototypes --- */
void pkg_iksemel_init();
#endif /* USE_IKSEMEL */
#endif /* PKG_IKSEMEL_H__ */

View file

@ -381,15 +381,17 @@ f_db_conv_string (svalue_t *sp)
char *buff;
s = sp->u.str;
buff = alloca(mstrsize(s)*2 +1);
buff = xalloc(mstrsize(s)*2 +1);
if ( !buff )
{
errorf("Out of memory.\n");
errorf("Out of memory (%zu bytes) in db_conv_string().\n",
mstrsize(s)*2 + 1);
/* NOTREACHED */
return sp;
}
mysql_escape_string(buff, get_txt(s), strlen(get_txt(s)) );
xfree(buff);
free_string_svalue(sp);
put_c_string(sp, buff);
return sp;

View file

@ -22,6 +22,10 @@
/* Error code to be returned if too many backtracks are detected.
*/
#ifdef PCRE_ERROR_RECURSIONLIMIT
#define RE_ERROR_BACKTRACK PCRE_ERROR_RECURSIONLIMIT
#else
#define RE_ERROR_BACKTRACK PCRE_ERROR_MATCHLIMIT
#endif
#endif /* PKG_PCRE_H_ */

View file

@ -74,7 +74,7 @@ struct sqlite_dbs_s
/* The list of database connections.
*/
static sqlite_dbs_t *head = NULL;
/*-------------------------------------------------------------------------*/
static sqlite_dbs_t *
find_db (object_t * obj)
@ -150,29 +150,83 @@ remove_db(sqlite_dbs_t *db)
/*-------------------------------------------------------------------------*/
static int
my_sqlite3_authorizer(void * data, int what, const char* arg1, const char* arg2,
my_sqlite3_authorizer (void * data, int what, const char* arg1, const char* arg2,
const char* dbname, const char* view)
/* Callback function for SQLite to handle authorizations.
*/
{
/* TODO: Check them via privilege_violation resp. valid_write.
(Don't know, whether sqlite can handle longjmps out of
its code in case of an error...)
*/
struct error_recovery_info error_recovery_info;
svalue_t *save_sp, sarg1, sarg2;
struct control_stack *save_csp;
int val;
switch(what)
{
case SQLITE_PRAGMA:
if(!strcasecmp(arg1, "synchronous"))
return SQLITE_OK;
return SQLITE_DENY;
/* PRAGMA name [ = value ]
* PRAGMA function(arg)
*
* arg1: name/function
* arg2: value/arg
* dbname/view: NULL
*/
error_recovery_info.rt.last = rt_context;
error_recovery_info.rt.type = ERROR_RECOVERY_APPLY;
rt_context = (rt_context_t *)&error_recovery_info;
save_sp = inter_sp;
save_csp = csp;
sarg1.type = T_INVALID;
sarg2.type = T_INVALID;
if (setjmp(error_recovery_info.con.text))
{
secure_apply_error(save_sp, save_csp, MY_FALSE);
val = SQLITE_DENY;
}
else
{
if(arg1)
put_c_string(&sarg1, arg1);
else
put_number(&sarg1, 0);
if(arg2)
put_c_string(&sarg2, arg2);
else
put_number(&sarg2, 0);
if(privilege_violation2(STR_SQLITE_PRAGMA, &sarg1, &sarg2, inter_sp))
val = SQLITE_OK;
else
val = SQLITE_DENY;
}
free_svalue(&sarg1);
sarg1.type = T_INVALID;
free_svalue(&sarg2);
sarg2.type = T_INVALID;
rt_context = error_recovery_info.rt.last;
return val;
case SQLITE_ATTACH:
case SQLITE_DETACH:
/* ATTACH "filename" AS "dbname"
*
* arg1: filename
* arg2, dbname, view: NULL
*/
/* SQLite3 doesn't allow the filename to be changed,
* but at least we must convert an absolute pathname
* to a relative one. So we have to deactivate it...
*/
return SQLITE_DENY;
default:
return SQLITE_OK;
}
@ -323,13 +377,13 @@ v_sl_exec (svalue_t * sp, int num_arg)
db = find_db (current_object);
if (!db)
errorf("The current object doesn't have a database open.\n");
/* To increase the efficiency of SQLite by avoid re-parsing of statements,
* these prepared (precompiled) statement objects should be cached and
* re-used whenever the command string is the same. The placeholder syntax
* of SQLite is defined at http://www.sqlite.org/c3ref/bind_blob.html
* See also http://about.psyc.eu/SQL -lynX 2008
*/
/* To increase the efficiency of SQLite by avoid re-parsing of statements,
* these prepared (precompiled) statement objects should be cached and
* re-used whenever the command string is the same. The placeholder syntax
* of SQLite is defined at http://www.sqlite.org/c3ref/bind_blob.html
* See also http://about.psyc.eu/SQL -lynX 2008
*/
err = sqlite3_prepare(db->db, get_txt(argp->u.str), mstrsize(argp->u.str),
&stmt, &tail);
if(err)
@ -380,8 +434,7 @@ v_sl_exec (svalue_t * sp, int num_arg)
rec_data->rows = NULL;
rec_data->stmt = stmt;
push_error_handler(sl_exec_cleanup, &(rec_data->head));
sp = inter_sp;
sp = push_error_handler(sl_exec_cleanup, &(rec_data->head));
while((err = sqlite3_step(stmt)) == SQLITE_ROW)
{

View file

@ -19,6 +19,7 @@
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <locale.h>
#include <time.h>
#include "backend.h"
@ -86,24 +87,30 @@ get_current_time (void)
/*-------------------------------------------------------------------------*/
char *
time_string (mp_int t)
/* Return a textual representation of the time <t>. */
time_fstring (mp_int t, const char* str, Bool localized)
/* Return a textual representation of the time <t> according to the format
* string <str>. Doesn't cache because it would be necessary to
* save the format string and compare.
* If localized is true, this function sets the locale according to the
* environment variable before calling strftime and resets it afterwards.
* TODO: It would be nicer to allocate the result buffer dynamically
* TODO::for using longer format strings. */
{
static char result[80];
struct tm *tm;
mp_int last_time = -1;
if (t != last_time)
{
time_t ti = (time_t)t;
last_time = t;
tm = localtime(&ti);
strftime(result, sizeof(result)-1, "%a %b %d %H:%M:%S %Y", tm);
static char result[512];
struct tm *tm; // broken-down time struct
time_t ti = (time_t)t;
tm = localtime(&ti);
if (!localized) {
setlocale(LC_TIME, "C");
strftime(result, sizeof(result)-1, str, tm);
setlocale(LC_TIME, "");
}
else
strftime(result, sizeof(result)-1, str, tm);
return result;
} /* time_string() */
} /* time_fstring() */
/*-------------------------------------------------------------------------*/
char *
@ -115,18 +122,13 @@ utime_string (mp_int t, mp_int ut)
static char result[80];
struct tm *tm;
size_t len;
mp_int last_t = -1, last_ut = -1;
if (t != last_t || ut != last_ut)
{
time_t ti = (time_t)t;
last_t= t;
last_ut= ut;
tm = localtime(&ti);
len = strftime(result, sizeof(result)-1, "%a %b %d %H:%M:%S:", tm);
sprintf(result+len, "%06ld", ut);
strftime(result+len+6, sizeof(result)-7-len, " %Y", tm);
}
time_t ti = (time_t)t;
tm = localtime(&ti);
len = strftime(result, sizeof(result)-1, "%a %b %d %H:%M:%S:", tm);
sprintf(result+len, "%06"PRIdMPINT, ut);
strftime(result+len+6, sizeof(result)-7-len, " %Y", tm);
return result;
} /* utime_string() */
@ -154,8 +156,8 @@ time_stamp (void)
time_t ti = (time_t)t;
last_time = t;
tm = localtime(&ti);
strftime( current_time_stamp, sizeof(current_time_stamp)-1
, "%Y.%m.%d %H:%M:%S", tm);
strftime( current_time_stamp, sizeof(current_time_stamp),
"%Y.%m.%d %H:%M:%S", tm);
}
return current_time_stamp;
} /* time_stamp() */

View file

@ -87,12 +87,7 @@ extern int errno;
#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
# include <memory.h>
#endif
#if 0
/* TODO: Obsoleted by limits.h+floats.h - remove this and the config check */
#ifdef HAVE_VALUES_H
# include <values.h>
#endif
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
@ -121,35 +116,6 @@ extern int errno;
# include <sys/param.h>
#endif
/*------------------------------------------------------------------
* Limits for less-standard integral types:
*
* LONGLONG_MIN, LONGLONG_MAX, ULONGLONG_MAX
* TODO: Add SIZEOF_SIZET to configure, and SIZET_limits here.
* TODO:: Then use SIZET_limits in smalloc::smalloc().
*/
#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
# if defined(LONG_LONG_MAX)
# define LONGLONG_MIN LONG_LONG_MIN
# define LONGLONG_MAX LONG_LONG_MAX
# define ULONGLONG_MAX ULONG_LONG_MAX
# elif SIZEOF_LONG_LONG == 8
# define LONGLONG_MIN (-9223372036854775807LL - 1)
# define LONGLONG_MAX (9223372036854775807LL)
# define ULONGLONG_MAX (0xffffffffffffffffULL)
# elif SIZEOF_LONG_LONG == SIZEOF_LONG
# define LONGLONG_MIN LONG_MIN
# define LONGLONG_MAX LONG_MAX
# define ULONGLONG_MAX ULONG_MAX
# elif SIZEOF_LONG_LONG == SIZEOF_INT
# define LONGLONG_MIN INT_MIN
# define LONGLONG_MAX INT_MAX
# define ULONGLONG_MAX UINT_MAX
# endif
#endif
/*------------------------------------------------------------------
* Define some macros:
* CHAR_BIT number of bits in a char, if not defined already.
@ -184,31 +150,35 @@ extern int errno;
# endif
#endif
#if defined(__GNUC__) && __GNUC__ >= 2 && (__GNUC_MINOR__ > 6 || __GNUC__ > 2)
# define NORETURN __attribute__ ((noreturn))
# define UNUSED __attribute__ ((unused))
/* some handy gcc attributes, but define everything to nothing if any other
* compiler ist used. Additional attributes maybe used in the driver are:
always_inline, const, deprecated, format_arg, nonnull, pure, returns_twice,
unused, warn_unused_result.
*/
#if defined(__GNUC__)
# define MALLOC __attribute__((malloc))
# define NORETURN __attribute__((noreturn))
# define UNUSED __attribute__((unused))
# define FORMATDEBUG(f,a,b) __attribute__((format (f,a,b)))
#elif defined(__MWERKS__)
# define __attribute__(x) /*NOTHING*/
# define NORETURN
# define UNUSED
#else
# define NORETURN
# define UNUSED
#endif
#if defined(__GNUC__) && __GNUC__ >= 3
# define MALLOC __attribute__ ((malloc))
#else
# define MALLOC
#endif
#ifdef __GNUC__
# define FORMATDEBUG(f,a,b) __attribute__ ((format (f,a,b)))
# define FORMATDEBUG(f,a,b)
#else
# define __attribute__(x) /*NOTHING*/
# define NORETURN
# define UNUSED
# define MALLOC
# define FORMATDEBUG(f,a,b)
#endif
#define VARPROT(proto,like,form,var) proto FORMATDEBUG(like,form,var)
// TODO: autoconf defines inline to some suitable keyword if the compiler does
// not understand inline itself. Just use inline in code?
#if defined(HAS_INLINE) && !defined(NO_INLINES)
# define INLINE inline
/* configure made sure that 'inline' expands to the proper attribute */
@ -234,102 +204,284 @@ extern int errno;
#define MSDOS_FS
#endif
/*------------------------------------------------------------------
* Test for C99-compatible data types
* TODO: check if we can remove these checks once (if?) we require a C99
* compliant build environment.
*/
#if defined(HAVE_INTTYPES_H)
/* C99 compliant inttypes.h. */
# include <inttypes.h>
#endif
#if defined(HAVE_STDINT_H)
/* C99 compliant stdint.h available
* Usually it gets included also in inttypes.h, but it doesn't hurt to
* include it specifically. */
# include <stdint.h>
#endif
/* If stdint.h or inttypes.h don't have int8_t, int16_t, int32_t, int64_t,
* uint8_t, uint16_t, uint32_t, uint64_t, intmax_t, uintmax_t, intptr_t,
* or uintmax_t, autoconf will have them defined to a suitable type now.
* If Autoconf did not find suitable types, there is probably no sense in
* searching them ourself.
*/
#if !defined(HAVE_INTPTR_T) && !defined(intptr_t)
/* If there is no intptr_t in stdint.h and autoconf did not find a
* suitable type, we're out of luck (because in this case we are unlikely
* to find one). */
# error Autoconf did not find an integer type with same size as a pointer
Thats it.
#endif
#if !defined(INT32_MAX) && !defined(int32_t)
# error Autoconf did not find an integer type with exactly 32 bits.
Thats it.
#endif
/* If mode_t, off_t, pid_t, size_t or ssize_t are not defined by the standard
* headers on this system, autoconf will have them defined as well.
*/
/*------------------------------------------------------------------
* Limits for less-standard integral types:
*
* LONGLONG_MIN, LONGLONG_MAX, ULONGLONG_MAX
* TODO: Add SIZEOF_SIZET to configure, and SIZET_limits here.
* TODO:: Then use SIZET_limits in smalloc::smalloc().
*/
#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
# if defined(LONG_LONG_MAX)
# define LONGLONG_MIN LONG_LONG_MIN
# define LONGLONG_MAX LONG_LONG_MAX
# define ULONGLONG_MAX ULONG_LONG_MAX
# elif SIZEOF_LONG_LONG == 8
# define LONGLONG_MIN (-9223372036854775807LL - 1)
# define LONGLONG_MAX (9223372036854775807LL)
# define ULONGLONG_MAX (0xffffffffffffffffULL)
# elif SIZEOF_LONG_LONG == SIZEOF_LONG
# define LONGLONG_MIN LONG_MIN
# define LONGLONG_MAX LONG_MAX
# define ULONGLONG_MAX ULONG_MAX
# elif SIZEOF_LONG_LONG == SIZEOF_INT
# define LONGLONG_MIN INT_MIN
# define LONGLONG_MAX INT_MAX
# define ULONGLONG_MAX UINT_MAX
# endif
#endif
/*------------------------------------------------------------------
* Integral types:
* Bool, SBool, CBool: boolean type, sized as int/short/char.
* Bool, SBool, CBool: boolean type, sized as _Bool or int, short, char.
* p_int : an integer that has the same size as a pointer
* ph_int : an integer that has half the size of a pointer
* mp_int : an integer that has at least the size of a pointer
* int32 : an integer with 32 bits
* PTRTYPE: a type to use with constant pointer arithmetic.
* The unsigned versions use 'uint' instead of 'int'.
* Additionally to the type themselves we define format specifiers for
* printing our types with sprintf() (PRN*) and scanning them with sscanf()
* (SCN*).
* Changes here must be reflected in my-limits.h .
* TODO: Add a type 'u/schar', '(u/s)int8' and '(u/s)int16'., unless not already
* TODO:: defined by STDC.
* TODO: inttypes.h, stdint.h, limits.h have many interesting types...
* Additional integral types from stdint.h/inttypes.h are available (s. above)
* TODO: check, if it is feasible to use the C99 data types instead of our own
* TODO::names in the future.
*/
/* p_int : an integer that has the same size as a pointer */
#define SIZEOF_PINT SIZEOF_CHAR_P
#if SIZEOF_LONG == SIZEOF_CHAR_P
typedef long p_int;
typedef unsigned long p_uint;
# define PINT_MIN LONG_MIN
# define PINT_MAX LONG_MAX
# define PUINT_MAX ULONG_MAX
#elif SIZEOF_INT == SIZEOF_CHAR_P
typedef int p_int;
typedef unsigned int p_uint;
# define PINT_MIN INT_MIN
# define PINT_MAX INT_MAX
# define PUINT_MAX UINT_MAX
#elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == SIZEOF_CHAR_P
typedef long long p_int;
typedef unsigned long long p_uint;
# define PINT_MIN LONGLONG_MIN
# define PINT_MAX LONGLONG_MAX
# define PUINT_MAX ULONGLONG_MAX
#if defined(HAVE_INTPTR_T) && SIZEOF_INT != SIZEOF_CHAR_P
/* just use intptr_t
* BUT! glibc on ILP32 platforms unfortunately defines intptr_t as int,
* not as long. While this doesn't change things in principle, because they
* have equal size, gcc will output a bunch of warnings on
* sprintf("%ld",p_int) because %ld is the wrong format specifier for int.
* Therefore this little hack, which uses intptr_t for the time being
* only if sizeof(int) != sizeof(char*) (because then intptr_t cannot be
* an int). As it is not guaranteed that p_int will always be a long or
* have the size of a long, this %ld for outputting p_int are anyway a
* problem.
* TODO: As soon, as all the %ld for p_int are replaced, this hack should
* TODO::be removed!
*/
typedef intptr_t p_int;
typedef uintptr_t p_uint;
# define PINT_MIN INTPTR_MIN
# define PINT_MAX INTPTR_MAX
# define PUINT_MAX UINTPTR_MAX
# define SIZEOF_PINT SIZEOF_INTPTR_T
# define PRIdPINT PRIdPTR
# define PRIuPINT PRIuPTR
# define PRIxPINT PRIxPTR
# define SCNdPINT SCNdPTR
# define SCNuPINT SCNuPTR
# define SCNxPINT SCNxPTR
# ifdef __PRIPTR_PREFIX
# define PRI_PINT_PREFIX __PRIPTR_PREFIX
# else
/* ugly - it is a pity that the format specifiers are standardized but not
* the length modifier. But we need one for sprintf.c. *sigh* */
# if SIZEOF_INTPTR_T == SIZEOF_LONG
# define PRI_PINT_PREFIX "l"
# elif SIZEOF_INTPTR_T == SIZEOF_INT
# define PRI_PINT_PREFIX
# elif HAVE_LONG_LONG && SIZEOF_INTPTR_T == SIZEOF_LONG_LONG
# define PRI_PINT_PREFIX "ll"
# else
# error Could not find a length modifier for intptr_t.
Thats it.
# endif
# endif
#else
#error cannot find an integer type with same size as a pointer
Thats it.
#endif
/* autoconf will have some type defined to intptr_t, but it won't define the
* limits and we won't have SIZEOF_INTPTR_T available. Therefore we have to
* search ourselves the old way.
* TODO: remove once C99 support is required */
# define SIZEOF_PINT SIZEOF_CHAR_P
# if SIZEOF_LONG == SIZEOF_CHAR_P
typedef long p_int;
typedef unsigned long p_uint;
# define PINT_MIN LONG_MIN
# define PINT_MAX LONG_MAX
# define PUINT_MAX ULONG_MAX
# define PRI_PINT_PREFIX "l"
# elif SIZEOF_INT == SIZEOF_CHAR_P
typedef int p_int;
typedef unsigned int p_uint;
# define PINT_MIN INT_MIN
# define PINT_MAX INT_MAX
# define PUINT_MAX UINT_MAX
# define PRI_PINT_PREFIX
# elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == SIZEOF_CHAR_P
typedef long long p_int;
typedef unsigned long long p_uint;
# define PINT_MIN LONGLONG_MIN
# define PINT_MAX LONGLONG_MAX
# define PUINT_MAX ULONGLONG_MAX
# define PRI_PINT_PREFIX "ll"
# else
/* nearly impossible (s. intptr_t check above, but better safe than
* sorry. */
# error cannot find an integer type with same size as a pointer
Thats it.
# endif
# define PRIdPINT PRI_PINT_PREFIX "d"
# define PRIuPINT PRI_PINT_PREFIX "u"
# define PRIxPINT PRI_PINT_PREFIX "x"
# define SCNdPINT PRI_PINT_PREFIX "d"
# define SCNuPINT PRI_PINT_PREFIX "u"
# define SCNxPINT PRI_PINT_PREFIX "x"
#endif // HAVE_INTPTR_T
/* ph_int : an integer that has half the size of a pointer */
/* ph_int : an integer that has half the size of a pointer.
* Unfortuntately C99 has nothing like this and therefore we have to find our
* own.
*/
#if SIZEOF_CHAR_P == SIZEOF_INT * 2
typedef int ph_int;
typedef unsigned int ph_uint;
# define PHINT_MIN INT_MIN
# define PHINT_MAX INT_MAX
# define PHUINT_MAX UINT_MAX
# define PRI_PHINT_PREFIX
#elif SIZEOF_CHAR_P == SIZEOF_SHORT * 2
typedef short ph_int;
typedef unsigned short ph_uint;
# define PHINT_MIN SHRT_MIN
# define PHINT_MAX SHRT_MAX
# define PHUINT_MAX USHRT_MAX
# define PRI_PHINT_PREFIX "h"
#elif SIZEOF_CHAR_P == SIZEOF_LONG * 2
typedef long ph_int;
typedef unsigned long ph_uint;
# define PHINT_MIN LONG_MIN
# define PHINT_MAX LONG_MAX
# define PHUINT_MAX ULONG_MAX
# define PRI_PHINT_PREFIX "l"
#else
# if SIZEOF_CHAR_P == 4
/* short is assumed to be always 2 bytes. */
/* TODO: This is a dangerous assumption. */
typedef short ph_int;
typedef unsigned short ph_uint;
# define PHINT_MIN SHORT_MIN
# define PHINT_MAX SHORT_MAX
# define PHUINT_MAX USHORT_MAX
# endif
# error Cannot find an integer of half the size of a pointer.
Thats it.
#endif
#define PRIdPHINT PRI_PHINT_PREFIX "d"
#define PRIuPHINT PRI_PHINT_PREFIX "u"
#define PRIxPHINT PRI_PHINT_PREFIX "x"
#define SCNdPHINT PRI_PHINT_PREFIX "d"
#define SCNuPHINT PRI_PHINT_PREFIX "u"
#define SCNxPHINT PRI_PHINT_PREFIX "x"
/* mp_int : an integer that has at least the size of a pointer */
/* mp_int : an integer that has at least the size of a pointer
* TODO: use intmax_t intstead once the driver does not assume mp_ints to be
* TODO::longs? */
typedef p_int mp_int;
typedef p_uint mp_uint;
typedef p_uint mp_uint;
#define MPINT_MIN PINT_MIN
#define MPINT_MAX PINT_MAX
#define MPUINT_MAX PUINT_MAX
#define PRIdMPINT PRIdPINT
#define PRIuMPINT PRIuPINT
#define PRIxMPINT PRIxPINT
#define SCNdMPINT PRIdPINT
#define SCNuMPINT PRIuPINT
#define SCNxMPINT PRIxPINT
#ifndef __BEOS__
/* int32 : an integer with 32 bits. */
/* TODO: Add a configuration check for 'int32' typedef */
# if SIZEOF_LONG == 4
# if !defined(_AIX)
typedef long int32;
# endif
typedef unsigned long uint32;
# else
# if SIZEOF_INT == 4
typedef int int32;
typedef unsigned int uint32;
# endif
/* int32 : an integer with 32 bits.
TODO: just use (u)int32_t instead of (u)int32. */
typedef int32_t int32;
typedef uint32_t uint32;
# ifndef PRId32
/* unfortunately there seems to be no PRId32 from inttypes.h or alike.
TODO: Once we require C99, we can get rid of the this stuff */
# if !defined(CHAR_BIT) || CHAR_BIT != 8
# error CHAR_BIT does not exist or is != 8 which is currently not supported!
Thats it.
# endif
/* now sizeof(int32) has to be sizeof(char) * 4 == 4. */
# if SIZEOF_INT == 4
# define __PRId32PREFIX
# elif SIZEOF_LONG == 4
# define __PRId32PREFIX "l"
# elif SIZEOF_SHORT == 4
# define __PRIx32PREFIX "h"
# else
# error Could not find length modifier for (u)int32
Thats it.
# endif
# define PRId32 __PRId32PREFIX "d"
# define PRIu32 __PRId32PREFIX "u"
# define PRIx32 __PRId32PREFIX "x"
# endif /* PRId32 */
#endif /* __BEOS__ */
/* Boolean datatype and values */
typedef int Bool; /* naming it 'bool' clashes on some machines... */
/* type to use with constant pointer arithmetic. */
#define PTRTYPE char *
/* Boolean datatype and values */
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# ifndef HAVE__BOOL
/* _Bool is not available - typedef our own with int.
* naming it 'bool' clashes on some machines... */
typedef int _Bool;
# endif
/* define true and false as stdbool.h does. */
# define false 0
# define true 1
# define __bool_true_false_are_defined 1
#endif // HAVE_STDBOOL_H
/* _Bool looks strange and we anyway used Bool until now. */
typedef _Bool Bool;
/* TODO: check if these two can be merged with Bool */
typedef short SBool;
typedef char CBool;
#define MY_TRUE (1)
#define MY_FALSE (0)
#define MY_TRUE (true)
#define MY_FALSE (false)
/* TODO: This should go into my-malloc.h? */
#ifdef FREE_RETURNS_VOID
@ -340,17 +492,11 @@ typedef char CBool;
# define FREE_RETURN return 1;
#endif
#define PTRTYPE char *
/*------------------------------------------------------------------
* Provide functions, types and defines missing from the system headers.
*/
#ifndef HAVE_SSIZE_T
typedef signed long ssize_t;
#endif
#ifndef HAVE_MEMCPY
/* The following 'implementation' is suitable for throwing away a value,
but not to using it; the cast to return int is likely to show a warning
@ -427,7 +573,8 @@ typedef signed long ssize_t;
extern char current_time_stamp[];
extern mp_int get_current_time(void);
extern char * time_string(mp_int);
extern char * time_fstring(mp_int t, const char* str, Bool localized)
FORMATDEBUG(strftime,2,0);
extern char * utime_string(mp_int, mp_int);
extern char * time_stamp(void);
extern char *xmemmem(const char *, size_t, const char *, size_t);

File diff suppressed because it is too large Load diff

View file

@ -127,7 +127,7 @@ find_add_pointer (struct pointer_table *ptable, void *pointer, Bool bAdd)
*/
{
mp_int key; /* The <pointer> as a normal int */
p_uint key; /* The <pointer> as a normal int */
int hash; /* hash computed from <key> aka <pointer> */
int mask; /* mask for <hash> in to <usage_p> */
char *usage_p; /* First usage vector byte for entry <hash> */
@ -135,7 +135,7 @@ find_add_pointer (struct pointer_table *ptable, void *pointer, Bool bAdd)
struct pointer_record *new; /* New record to add */
struct pointer_record **insert; /* Pointer to hashed table entry */
key = (mp_int)pointer;
key = (p_uint)pointer;
/* Compute the hash value, and the index and mask for
* the usage vector
@ -214,8 +214,8 @@ find_add_pointer (struct pointer_table *ptable, void *pointer, Bool bAdd)
table = mempool_alloc(ptable->pool, sizeof *table);
if (!table)
errorf("(pointertable) Out of memory (%lu bytes pooled) "
"for subtable.\n", (unsigned long) sizeof *table);
errorf("(pointertable) Out of memory (%zu bytes pooled) "
"for subtable.\n", sizeof *table);
*insert = (struct pointer_record *)table;
memset(table->used, 0, sizeof table->used);
@ -247,8 +247,8 @@ find_add_pointer (struct pointer_table *ptable, void *pointer, Bool bAdd)
usage_p[0] |= mask;
new = mempool_alloc(ptable->pool, sizeof *new);
if (!new)
errorf("(pointertable) Out of memory (%lu bytes pooled) for "
"new entry.\n", (unsigned long) sizeof *new);
errorf("(pointertable) Out of memory (%zu bytes pooled) for "
"new entry.\n", sizeof *new);
*insert = new;
new->key = key;
new->next = old;

View file

@ -1,274 +1,120 @@
/*---------------------------------------------------------------------------
* Gamedriver: Random Generator 'Mersenne Twister'
/*------------------------------------------------------------------
* Wrapper for the 'SIMD oriented Fast Mersenne Twister.
*
* A C-program for MT19937, with initialization improved 2002/2/10.
* Coded by Takuji Nishimura and Makoto Matsumoto.
* This is a faster version by taking Shawn Cokus's optimization,
* Matthe Bellew's simplification, Isaku Wada's real version.
*
* Before using, initialize the state by using init_genrand(seed)
* or init_by_array(init_key, key_length).
*
* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Any feedback is very welcome.
* http://www.math.keio.ac.jp/matumoto/emt.html
* email: matumoto@math.keio.ac.jp
*---------------------------------------------------------------------------
* SFMT was developed by Mutsuo Saito and Makoto Matsumoto,
* Hiroshima University,
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html)
* SFMT was integrated to LDMud by Zesstra@MorgenGrauen (http://mg.mud.de)
*------------------------------------------------------------------
*/
#include "driver.h"
#include "random.h"
#include "backend.h"
/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UMASK 0x80000000UL /* most significant w-r bits */
#define LMASK 0x7fffffffUL /* least significant r bits */
#define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) )
#define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
/* This is included on purpose so that the compiler may inline some functions.
* They are anyway never used anywhere else, all other parts of the driver use
* only the wrapper functions in this file.
*/
#include "random/SFMT.c"
static unsigned long state[N]; /* the array for the state vector */
static int left = 1;
static int initf = 0;
static unsigned long *next;
const unsigned int INIT_ARRAY_SIZE = 156U; // 4*156 == 624 bytes
/* initializes state[N] with a seed */
void init_genrand(unsigned long s)
{
int j;
state[0]= s & 0xffffffffUL;
for (j=1; j<N; j++) {
state[j] = (1812433253UL * (state[j-1] ^ (state[j-1] >> 30)) + j);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array state[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
state[j] &= 0xffffffffUL; /* for >32 bit machines */
}
left = 1; initf = 1;
}
/* initialize by an array with array-length */
/* init_key is the array for initializing keys */
/* key_length is its length */
/* slight change for C++, 2004/2/26 */
void init_by_array(unsigned long init_key[], int key_length)
{
int i, j, k;
init_genrand(19650218UL);
i=1; j=0;
k = (N>key_length ? N : key_length);
for (; k; k--) {
state[i] = (state[i] ^ ((state[i-1] ^ (state[i-1] >> 30)) * 1664525UL))
+ init_key[j] + j; /* non linear */
state[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
i++; j++;
if (i>=N) { state[0] = state[N-1]; i=1; }
if (j>=key_length) j=0;
}
for (k=N-1; k; k--) {
state[i] = (state[i] ^ ((state[i-1] ^ (state[i-1] >> 30)) * 1566083941UL))
- i; /* non linear */
state[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
i++;
if (i>=N) { state[0] = state[N-1]; i=1; }
}
state[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
left = 1; initf = 1;
}
static void next_state(void)
{
unsigned long *p=state;
int j;
/* if init_genrand() has not been called, */
/* a default initial seed is used */
if (initf==0) init_genrand(5489UL);
left = N;
next = state;
for (j=N-M+1; --j; p++)
*p = p[M] ^ TWIST(p[0], p[1]);
for (j=M; --j; p++)
*p = p[M-N] ^ TWIST(p[0], p[1]);
*p = p[M-N] ^ TWIST(p[0], state[0]);
}
/* generates a random number on [0,0xffffffff]-interval */
unsigned long genrand_int32(void)
{
unsigned long y;
if (--left == 0) next_state();
y = *next++;
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return y;
}
#if 0
/** LDMud doesn't use the following functions - yet. **/
/* generates a random number on [0,0x7fffffff]-interval */
long genrand_int31(void)
{
unsigned long y;
if (--left == 0) next_state();
y = *next++;
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return (long)(y>>1);
}
/* generates a random number on [0,1]-real-interval */
double genrand_real1(void)
{
unsigned long y;
if (--left == 0) next_state();
y = *next++;
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return (double)y * (1.0/4294967295.0);
/* divided by 2^32-1 */
}
/* generates a random number on [0,1)-real-interval */
double genrand_real2(void)
{
unsigned long y;
if (--left == 0) next_state();
y = *next++;
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return (double)y * (1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on (0,1)-real-interval */
double genrand_real3(void)
{
unsigned long y;
if (--left == 0) next_state();
y = *next++;
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return ((double)y + 0.5) * (1.0/4294967296.0);
/* divided by 2^32 */
}
/* generates a random number on [0,1) with 53-bit resolution*/
double genrand_res53(void)
{
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
return(a*67108864.0+b)*(1.0/9007199254740992.0);
}
/* These real versions are due to Isaku Wada, 2002/01/09 added */
#endif
// Name of the device/file to seed the PRNG from
char * prng_device_name = NULL;
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* Driver interface functions */
/*-------------------------------------------------------------------------*/
void
seed_random (uint32 seed)
/* Initialize the generator */
{
unsigned long init[4];
init[0] = seed & 0xFFF;
init[1] = (seed >>= 8) & 0xFFF;
init[2] = (seed >>= 8) & 0xFFF;
init[3] = (seed >>= 8) & 0xFFF;
init_by_array(init, 4);
} /* seed_random() */
/*-------------------------------------------------------------------------*/
uint32
random_number (uint32 n)
/* random_number() is in random.h to be inlined. */
/* Return a random number in the range 0..n-1.
*
* The MT FAQ suggests:
* If the application is not sensitive to the rounding off error, then please
* multiply N to [0,1)-real uniform random numbers and take the integer part
* (this is sufficient for most applications).
*
* I use the appropriate functions from the SFMT to generate random numbers on
* the [0,1) interval and multiply with N.
*/
#if SIZEOF_LONG == SIZEOF_CHAR_P
uint64_t random_number(uint64_t n) {
return genrand_res53() * n;
}
#elif SIZEOF_INT == SIZEOF_CHAR_P
uint32_t random_number(uint32 n) {
return genrand_real2() * n;
}
#else
#error We currently do not yet support a 128 bit integer type used as \
svalue number type.
#endif
void seed_random_from_int (uint32_t seed)
/* Initialize the generator */
{
return genrand_int32() * (1.0/4294967296.0) * n;
/*
* Since most compilers compute the constant when it is compiled, so this
* code runs with the same speed with the standard C codes, and portability
* and readability are better.
*/
} /* random_number() */
#ifdef USE_LDMUD_COMPATIBILITY
# ifdef VERBOSE
printf("%s Seeding PRNG with: 0x%lx\n"
, time_stamp(), (unsigned long)seed);
# endif
debug_message("%s Seeding PRNG with: 0x%lx\n"
, time_stamp(), (unsigned long)seed);
#endif
init_gen_rand(seed);
} /* seed_random_from_int() */
/*-------------------------------------------------------------------------*/
void
seed_random(const char *filename)
/* Opens the file given by filename and reads 156 uint32_t (624
* bytes) from it (most often the file is probably /dev/urandom or
* /dev/random). If successful the random number generator will be seeded
* by an array of 624 bytes. Otherwise the driver clock will be used as
* fallback.
*/
{
FILE *seedsrc = NULL; // Filepointer
// If we got a NULL pointer or an empty string, don't try to open some
// device/file.
if (filename != NULL && strlen(filename))
seedsrc = fopen(filename,"rb");
// if we have a file descriptor try to get a suitable amount of 32-bit
// values from a file (right now 156 uint32_t / 624 bytes)
if (seedsrc) {
uint32_t seeddata[INIT_ARRAY_SIZE];
size_t count = fread( seeddata, sizeof(uint32), INIT_ARRAY_SIZE,
seedsrc );
fclose(seedsrc);
if( count == INIT_ARRAY_SIZE ) {
init_by_array(seeddata, INIT_ARRAY_SIZE ); // seed PRNG
#ifdef USE_LDMUD_COMPATIBILITY
# ifdef VERBOSE
printf("%s Seeding PRNG from %s.\n", time_stamp(),
filename);
# endif
debug_message("%s Seeding PRNG from %s.\n", time_stamp(),
filename);
#endif
return;
} // if (count == INIT_ARRAY_SIZE)
} // if (seedsrc)
// Fall-back: driver clock
#ifdef USE_LDMUD_COMPATIBILITY
# ifdef VERBOSE
printf("%s Seeding PRNG with current driver time\n"
, time_stamp());
# endif
debug_message("%s Seeding PRNG with current driver time\n"
, time_stamp());
#endif
seed_random_from_int((uint32_t)current_time);
} /* seed_random() */
/***************************************************************************/

View file

@ -2,8 +2,28 @@
#define RANDOM_H__ 1
#include "driver.h"
// SFTM expects MEXP to contain the desired period length
#ifdef RANDOM_PERIOD_LENGTH
#define MEXP RANDOM_PERIOD_LENGTH
#endif
extern uint32 random_number(uint32 n);
extern void seed_random(uint32 seed);
#include "random/SFMT.h"
#define PRNG_DEFAULT_DEVICE "/dev/urandom"
// device/file to read seed for the PRNG from
extern char * prng_device_name;
/* --- Prototypes --- */
extern void seed_random_from_int(uint32_t seed);
extern void seed_random(const char *filename);
#if SIZEOF_LONG == SIZEOF_CHAR_P
uint64_t random_number(uint64_t n);
#elif SIZEOF_INT == SIZEOF_CHAR_P
uint32_t random_number(uint32_t n);
#else
#error We currently do not yes support a 128 bit integer type used as \
svalue number type.
#endif
#endif /* RANDOM_H__ */

55
src/random/CHANGE-LOG.txt Normal file
View file

@ -0,0 +1,55 @@
ver 1.3.3
-------
change condition compile of do_recursion in SFMT.c
ver 1.3.2
-------
bug fix to_res53_mix and genrand_res53_mix.
ver 1.3.1
-------
gcc compile option changed form -O9 to -O3.
add functions genrand_res53_mix and to_res53_mix.
bug fix about definition of ALWAYS_INLINE.
add new definition PRE_ALWAYS for MSC.
ver 1.3
-------
bug fixed: -DONLY64 without -DBIG_ENIAN64 had been generating
wrong sequence.
bug fixed: There is no documentation about BIG_ENDIAN64.
add automatic endian check by __BIG_ENDIAN__ predefined macro.
bug fixed: change == in check.sh to =
add SFMT-params216091.h
add AltiVec parameter format for systems which are not osx.
change Makefile for systems which are not osx and support AltiVec.
change sample2 of howto-compile for Free BSD.
change source files for BORLANDC and Visual Studio.
change period certification code more smart.
add params directory.
ver 1.2.1
-------
Fix typo in SFMT-alti.c SFMT-sse2.c
marge SFMT-alti.c and SFMT-alti.h into SFMT-alti.h
marge SFMT-sse2.c and SFMT-sse2.h into SFMT-sse2.h
This version is not released.
ver 1.2
-------
Support many periods: 2^{607}, 2^{1279}, 2^{2281}, 2^{4253}, 2^{11213},
2^{19937}, 2^{44497}, 2^{86243}, 2^{132049}
Fix typo in LICENSE.txt.
Add cast to vec_perm for SFMT-alti.c, SFMT-alti64.c.
combine source codes.
ver 1.1
-------
The period certification method is changed from constant to function.
The convert functions from 32-bit and 64-bit integer to double are added.
The documentation is changed.
Sample programs are added.
ver 1.0
-------
The first version.

21
src/random/FILES.txt Normal file
View file

@ -0,0 +1,21 @@
This archive contails following directories and files.
TOP DIRECTORY
FILES.txt: This file.
LICENSE.txt: License file.
CHANGE-LOG.txt: Change log file.
SFMT.h: Header file.
SFMT-params.h: parameter file which controls various Mersenne expornent
params607.h: parameters for period of 2^{607}-1
params1279.h: parameters for period of 2^{1279}-1
params2281.h: parameters for period of 2^{2281}-1
params4253.h: parameters for period of 2^{4253}-1
params11213.h: parameters for period of 2^{11213}-1
params19937.h: parameters for period of 2^{19937}-1
params44497.h: parameters for period of 2^{44497}-1
params86243.h: parameters for period of 2^{86243}-1
params132049.h: parameters for period of 2^{132049}-1
params216091.h: parameters for period of 2^{216091}-1
SFMT.c: C code for standard C (c99) and unix like systems.
SFMT-alti.h: C code optimized for PowerPC AltiVec.
SFMT-sse2.h: C code optimized for intel SSE2.

32
src/random/LICENSE.txt Normal file
View file

@ -0,0 +1,32 @@
This License covers the the files in this subdirectory of the LDMud
source (src/random/).
Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
University. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the Hiroshima University nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

10
src/random/README.LDMUD Normal file
View file

@ -0,0 +1,10 @@
This is SFMT-1.3.3, stripped down to what is required by the LDMud gamedriver.
Additionally the 'public' function were made static as well because they are
probably not used without the wrapper. Therefore, their declarations have been
commented out.
The small inline functions from SFMT.h were moved to SFMT.c for the same
reason.
The files README.txt and LICENSE.txt tell you where to get the complete package.

22
src/random/README.txt Normal file
View file

@ -0,0 +1,22 @@
=================================================================
SFMT ver. 1.3.3
SIMD oriented Fast Mersenne Twister(SFMT)
Mutsuo Saito (Hiroshima University) and
Makoto Matsumoto (Hiroshima University)
Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
University. All rights reserved.
The (modified) BSD License is applied to this software, see LICENSE.txt
=================================================================
To see documents, see html/index.html.
To make test program, see html/howto-compile.html
If you want to redistribute and/or change source files, see LICENSE.txt.
When you change these files and redistribute them, PLEASE write your
e-mail address in redistribution and write to contact YOU first if
users of your changed source encounter troubles.

156
src/random/SFMT-alti.h Normal file
View file

@ -0,0 +1,156 @@
/**
* @file SFMT-alti.h
*
* @brief SIMD oriented Fast Mersenne Twister(SFMT)
* pseudorandom number generator
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (Hiroshima University)
*
* Copyright (C) 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* The new BSD License is applied to this software.
* see LICENSE.txt
*/
#ifndef SFMT_ALTI_H
#define SFMT_ALTI_H
inline static vector unsigned int vec_recursion(vector unsigned int a,
vector unsigned int b,
vector unsigned int c,
vector unsigned int d)
ALWAYSINLINE;
/**
* This function represents the recursion formula in AltiVec and BIG ENDIAN.
* @param a a 128-bit part of the interal state array
* @param b a 128-bit part of the interal state array
* @param c a 128-bit part of the interal state array
* @param d a 128-bit part of the interal state array
* @return output
*/
inline static vector unsigned int vec_recursion(vector unsigned int a,
vector unsigned int b,
vector unsigned int c,
vector unsigned int d) {
const vector unsigned int sl1 = ALTI_SL1;
const vector unsigned int sr1 = ALTI_SR1;
#ifdef ONLY64
const vector unsigned int mask = ALTI_MSK64;
const vector unsigned char perm_sl = ALTI_SL2_PERM64;
const vector unsigned char perm_sr = ALTI_SR2_PERM64;
#else
const vector unsigned int mask = ALTI_MSK;
const vector unsigned char perm_sl = ALTI_SL2_PERM;
const vector unsigned char perm_sr = ALTI_SR2_PERM;
#endif
vector unsigned int v, w, x, y, z;
x = vec_perm(a, (vector unsigned int)perm_sl, perm_sl);
v = a;
y = vec_sr(b, sr1);
z = vec_perm(c, (vector unsigned int)perm_sr, perm_sr);
w = vec_sl(d, sl1);
z = vec_xor(z, w);
y = vec_and(y, mask);
v = vec_xor(v, x);
z = vec_xor(z, y);
z = vec_xor(z, v);
return z;
}
/**
* This function fills the internal state array with pseudorandom
* integers.
*/
inline static void gen_rand_all(void) {
int i;
vector unsigned int r, r1, r2;
r1 = sfmt[N - 2].s;
r2 = sfmt[N - 1].s;
for (i = 0; i < N - POS1; i++) {
r = vec_recursion(sfmt[i].s, sfmt[i + POS1].s, r1, r2);
sfmt[i].s = r;
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = vec_recursion(sfmt[i].s, sfmt[i + POS1 - N].s, r1, r2);
sfmt[i].s = r;
r1 = r2;
r2 = r;
}
}
/**
* This function fills the user-specified array with pseudorandom
* integers.
*
* @param array an 128-bit array to be filled by pseudorandom numbers.
* @param size number of 128-bit pesudorandom numbers to be generated.
*/
inline static void gen_rand_array(w128_t *array, int size) {
int i, j;
vector unsigned int r, r1, r2;
r1 = sfmt[N - 2].s;
r2 = sfmt[N - 1].s;
for (i = 0; i < N - POS1; i++) {
r = vec_recursion(sfmt[i].s, sfmt[i + POS1].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = vec_recursion(sfmt[i].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
/* main loop */
for (; i < size - N; i++) {
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
r1 = r2;
r2 = r;
}
for (j = 0; j < 2 * N - size; j++) {
sfmt[j].s = array[j + size - N].s;
}
for (; i < size; i++) {
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
array[i].s = r;
sfmt[j++].s = r;
r1 = r2;
r2 = r;
}
}
#ifndef ONLY64
#if defined(__APPLE__)
#define ALTI_SWAP (vector unsigned char) \
(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)
#else
#define ALTI_SWAP {4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}
#endif
/**
* This function swaps high and low 32-bit of 64-bit integers in user
* specified array.
*
* @param array an 128-bit array to be swaped.
* @param size size of 128-bit array.
*/
inline static void swap(w128_t *array, int size) {
int i;
const vector unsigned char perm = ALTI_SWAP;
for (i = 0; i < size; i++) {
array[i].s = vec_perm(array[i].s, (vector unsigned int)perm, perm);
}
}
#endif
#endif

97
src/random/SFMT-params.h Normal file
View file

@ -0,0 +1,97 @@
#ifndef SFMT_PARAMS_H
#define SFMT_PARAMS_H
#if !defined(MEXP)
#ifdef __GNUC__
#warning "MEXP is not defined. I assume MEXP is 19937."
#endif
#define MEXP 19937
#endif
/*-----------------
BASIC DEFINITIONS
-----------------*/
/** Mersenne Exponent. The period of the sequence
* is a multiple of 2^MEXP-1.
* #define MEXP 19937 */
/** SFMT generator has an internal state array of 128-bit integers,
* and N is its size. */
#define N (MEXP / 128 + 1)
/** N32 is the size of internal state array when regarded as an array
* of 32-bit integers.*/
#define N32 (N * 4)
/** N64 is the size of internal state array when regarded as an array
* of 64-bit integers.*/
#define N64 (N * 2)
/*----------------------
the parameters of SFMT
following definitions are in paramsXXXX.h file.
----------------------*/
/** the pick up position of the array.
#define POS1 122
*/
/** the parameter of shift left as four 32-bit registers.
#define SL1 18
*/
/** the parameter of shift left as one 128-bit register.
* The 128-bit integer is shifted by (SL2 * 8) bits.
#define SL2 1
*/
/** the parameter of shift right as four 32-bit registers.
#define SR1 11
*/
/** the parameter of shift right as one 128-bit register.
* The 128-bit integer is shifted by (SL2 * 8) bits.
#define SR2 1
*/
/** A bitmask, used in the recursion. These parameters are introduced
* to break symmetry of SIMD.
#define MSK1 0xdfffffefU
#define MSK2 0xddfecb7fU
#define MSK3 0xbffaffffU
#define MSK4 0xbffffff6U
*/
/** These definitions are part of a 128-bit period certification vector.
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0xc98e126aU
*/
#if MEXP == 607
#include "SFMT-params607.h"
#elif MEXP == 1279
#include "SFMT-params1279.h"
#elif MEXP == 2281
#include "SFMT-params2281.h"
#elif MEXP == 4253
#include "SFMT-params4253.h"
#elif MEXP == 11213
#include "SFMT-params11213.h"
#elif MEXP == 19937
#include "SFMT-params19937.h"
#elif MEXP == 44497
#include "SFMT-params44497.h"
#elif MEXP == 86243
#include "SFMT-params86243.h"
#elif MEXP == 132049
#include "SFMT-params132049.h"
#elif MEXP == 216091
#include "SFMT-params216091.h"
#else
#ifdef __GNUC__
#error "MEXP is not valid."
#undef MEXP
#else
#undef MEXP
#endif
#endif
#endif /* SFMT_PARAMS_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS11213_H
#define SFMT_PARAMS11213_H
#define POS1 68
#define SL1 14
#define SL2 3
#define SR1 7
#define SR2 3
#define MSK1 0xeffff7fbU
#define MSK2 0xffffffefU
#define MSK3 0xdfdfbfffU
#define MSK4 0x7fffdbfdU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0xe8148000U
#define PARITY4 0xd0c7afa3U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
#define ALTI_SR2_PERM \
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
#endif /* For OSX */
#define IDSTR "SFMT-11213:68-14-3-7-3:effff7fb-ffffffef-dfdfbfff-7fffdbfd"
#endif /* SFMT_PARAMS11213_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS1279_H
#define SFMT_PARAMS1279_H
#define POS1 7
#define SL1 14
#define SL2 3
#define SR1 5
#define SR2 1
#define MSK1 0xf7fefffdU
#define MSK2 0x7fefcfffU
#define MSK3 0xaff3ef3fU
#define MSK4 0xb5ffff7fU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0x20000000U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif /* For OSX */
#define IDSTR "SFMT-1279:7-14-3-5-1:f7fefffd-7fefcfff-aff3ef3f-b5ffff7f"
#endif /* SFMT_PARAMS1279_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS132049_H
#define SFMT_PARAMS132049_H
#define POS1 110
#define SL1 19
#define SL2 1
#define SR1 21
#define SR2 1
#define MSK1 0xffffbb5fU
#define MSK2 0xfb6ebf95U
#define MSK3 0xfffefffaU
#define MSK4 0xcff77fffU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0xcb520000U
#define PARITY4 0xc7e91c7dU
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif /* For OSX */
#define IDSTR "SFMT-132049:110-19-1-21-1:ffffbb5f-fb6ebf95-fffefffa-cff77fff"
#endif /* SFMT_PARAMS132049_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS19937_H
#define SFMT_PARAMS19937_H
#define POS1 122
#define SL1 18
#define SL2 1
#define SR1 11
#define SR2 1
#define MSK1 0xdfffffefU
#define MSK2 0xddfecb7fU
#define MSK3 0xbffaffffU
#define MSK4 0xbffffff6U
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0x13c9e684U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif /* For OSX */
#define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
#endif /* SFMT_PARAMS19937_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS216091_H
#define SFMT_PARAMS216091_H
#define POS1 627
#define SL1 11
#define SL2 3
#define SR1 10
#define SR2 1
#define MSK1 0xbff7bff7U
#define MSK2 0xbfffffffU
#define MSK3 0xbffffa7fU
#define MSK4 0xffddfbfbU
#define PARITY1 0xf8000001U
#define PARITY2 0x89e80709U
#define PARITY3 0x3bd2b64bU
#define PARITY4 0x0c64b1e4U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif /* For OSX */
#define IDSTR "SFMT-216091:627-11-3-10-1:bff7bff7-bfffffff-bffffa7f-ffddfbfb"
#endif /* SFMT_PARAMS216091_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS2281_H
#define SFMT_PARAMS2281_H
#define POS1 12
#define SL1 19
#define SL2 1
#define SR1 5
#define SR2 1
#define MSK1 0xbff7ffbfU
#define MSK2 0xfdfffffeU
#define MSK3 0xf7ffef7fU
#define MSK4 0xf2f7cbbfU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0x41dfa600U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif /* For OSX */
#define IDSTR "SFMT-2281:12-19-1-5-1:bff7ffbf-fdfffffe-f7ffef7f-f2f7cbbf"
#endif /* SFMT_PARAMS2281_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS4253_H
#define SFMT_PARAMS4253_H
#define POS1 17
#define SL1 20
#define SL2 1
#define SR1 7
#define SR2 1
#define MSK1 0x9f7bffffU
#define MSK2 0x9fffff5fU
#define MSK3 0x3efffffbU
#define MSK4 0xfffff7bbU
#define PARITY1 0xa8000001U
#define PARITY2 0xaf5390a3U
#define PARITY3 0xb740b3f8U
#define PARITY4 0x6c11486dU
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif /* For OSX */
#define IDSTR "SFMT-4253:17-20-1-7-1:9f7bffff-9fffff5f-3efffffb-fffff7bb"
#endif /* SFMT_PARAMS4253_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS44497_H
#define SFMT_PARAMS44497_H
#define POS1 330
#define SL1 5
#define SL2 3
#define SR1 9
#define SR2 3
#define MSK1 0xeffffffbU
#define MSK2 0xdfbebfffU
#define MSK3 0xbfbf7befU
#define MSK4 0x9ffd7bffU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0xa3ac4000U
#define PARITY4 0xecc1327aU
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
#define ALTI_SR2_PERM \
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
#endif /* For OSX */
#define IDSTR "SFMT-44497:330-5-3-9-3:effffffb-dfbebfff-bfbf7bef-9ffd7bff"
#endif /* SFMT_PARAMS44497_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS607_H
#define SFMT_PARAMS607_H
#define POS1 2
#define SL1 15
#define SL2 3
#define SR1 13
#define SR2 3
#define MSK1 0xfdff37ffU
#define MSK2 0xef7f3f7dU
#define MSK3 0xff777b7dU
#define MSK4 0x7ff7fb2fU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0x5986f054U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
#define ALTI_SR2_PERM \
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
#endif /* For OSX */
#define IDSTR "SFMT-607:2-15-3-13-3:fdff37ff-ef7f3f7d-ff777b7d-7ff7fb2f"
#endif /* SFMT_PARAMS607_H */

View file

@ -0,0 +1,46 @@
#ifndef SFMT_PARAMS86243_H
#define SFMT_PARAMS86243_H
#define POS1 366
#define SL1 6
#define SL2 7
#define SR1 19
#define SR2 1
#define MSK1 0xfdbffbffU
#define MSK2 0xbff7ff3fU
#define MSK3 0xfd77efffU
#define MSK4 0xbf9ff3ffU
#define PARITY1 0x00000001U
#define PARITY2 0x00000000U
#define PARITY3 0x00000000U
#define PARITY4 0xe9528d85U
/* PARAMETERS FOR ALTIVEC */
#if defined(__APPLE__) /* For OSX */
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
#define ALTI_MSK64 \
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
#define ALTI_SL2_PERM \
(vector unsigned char)(25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6)
#define ALTI_SL2_PERM64 \
(vector unsigned char)(7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6)
#define ALTI_SR2_PERM \
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
#define ALTI_SR2_PERM64 \
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
#else /* For OTHER OSs(Linux?) */
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
#define ALTI_SL2_PERM {25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6}
#define ALTI_SL2_PERM64 {7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6}
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
#endif /* For OSX */
#define IDSTR "SFMT-86243:366-6-7-19-1:fdbffbff-bff7ff3f-fd77efff-bf9ff3ff"
#endif /* SFMT_PARAMS86243_H */

121
src/random/SFMT-sse2.h Normal file
View file

@ -0,0 +1,121 @@
/**
* @file SFMT-sse2.h
* @brief SIMD oriented Fast Mersenne Twister(SFMT) for Intel SSE2
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (Hiroshima University)
*
* @note We assume LITTLE ENDIAN in this file
*
* Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* The new BSD License is applied to this software, see LICENSE.txt
*/
#ifndef SFMT_SSE2_H
#define SFMT_SSE2_H
PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c,
__m128i d, __m128i mask) ALWAYSINLINE;
/**
* This function represents the recursion formula.
* @param a a 128-bit part of the interal state array
* @param b a 128-bit part of the interal state array
* @param c a 128-bit part of the interal state array
* @param d a 128-bit part of the interal state array
* @param mask 128-bit mask
* @return output
*/
PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b,
__m128i c, __m128i d, __m128i mask) {
__m128i v, x, y, z;
x = _mm_load_si128(a);
y = _mm_srli_epi32(*b, SR1);
z = _mm_srli_si128(c, SR2);
v = _mm_slli_epi32(d, SL1);
z = _mm_xor_si128(z, x);
z = _mm_xor_si128(z, v);
x = _mm_slli_si128(x, SL2);
y = _mm_and_si128(y, mask);
z = _mm_xor_si128(z, x);
z = _mm_xor_si128(z, y);
return z;
}
/**
* This function fills the internal state array with pseudorandom
* integers.
*/
inline static void gen_rand_all(void) {
int i;
__m128i r, r1, r2, mask;
mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
r1 = _mm_load_si128(&sfmt[N - 2].si);
r2 = _mm_load_si128(&sfmt[N - 1].si);
for (i = 0; i < N - POS1; i++) {
r = mm_recursion(&sfmt[i].si, &sfmt[i + POS1].si, r1, r2, mask);
_mm_store_si128(&sfmt[i].si, r);
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = mm_recursion(&sfmt[i].si, &sfmt[i + POS1 - N].si, r1, r2, mask);
_mm_store_si128(&sfmt[i].si, r);
r1 = r2;
r2 = r;
}
}
/**
* This function fills the user-specified array with pseudorandom
* integers.
*
* @param array an 128-bit array to be filled by pseudorandom numbers.
* @param size number of 128-bit pesudorandom numbers to be generated.
*/
inline static void gen_rand_array(w128_t *array, int size) {
int i, j;
__m128i r, r1, r2, mask;
mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
r1 = _mm_load_si128(&sfmt[N - 2].si);
r2 = _mm_load_si128(&sfmt[N - 1].si);
for (i = 0; i < N - POS1; i++) {
r = mm_recursion(&sfmt[i].si, &sfmt[i + POS1].si, r1, r2, mask);
_mm_store_si128(&array[i].si, r);
r1 = r2;
r2 = r;
}
for (; i < N; i++) {
r = mm_recursion(&sfmt[i].si, &array[i + POS1 - N].si, r1, r2, mask);
_mm_store_si128(&array[i].si, r);
r1 = r2;
r2 = r;
}
/* main loop */
for (; i < size - N; i++) {
r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2,
mask);
_mm_store_si128(&array[i].si, r);
r1 = r2;
r2 = r;
}
for (j = 0; j < 2 * N - size; j++) {
r = _mm_load_si128(&array[j + size - N].si);
_mm_store_si128(&sfmt[j].si, r);
}
for (; i < size; i++) {
r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2,
mask);
_mm_store_si128(&array[i].si, r);
_mm_store_si128(&sfmt[j++].si, r);
r1 = r2;
r2 = r;
}
}
#endif

694
src/random/SFMT.c Normal file
View file

@ -0,0 +1,694 @@
/**
* @file SFMT.c
* @brief SIMD oriented Fast Mersenne Twister(SFMT)
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (Hiroshima University)
*
* Copyright (C) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
* University. All rights reserved.
*
* The new BSD License is applied to this software, see LICENSE.txt
*/
#include <string.h>
#include <assert.h>
#include "SFMT.h"
#include "SFMT-params.h"
#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
#define BIG_ENDIAN64 1
#endif
#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
#define BIG_ENDIAN64 1
#endif
#if defined(ONLY64) && !defined(BIG_ENDIAN64)
#if defined(__GNUC__)
#error "-DONLY64 must be specified with -DBIG_ENDIAN64"
#endif
#undef ONLY64
#endif
/*------------------------------------------------------
128-bit SIMD data type for Altivec, SSE2 or standard C
------------------------------------------------------*/
#if defined(HAVE_ALTIVEC)
#if !defined(__APPLE__)
#include <altivec.h>
#endif
/** 128-bit data structure */
union W128_T {
vector unsigned int s;
uint32_t u[4];
};
/** 128-bit data type */
typedef union W128_T w128_t;
#elif defined(HAVE_SSE2)
#include <emmintrin.h>
/** 128-bit data structure */
union W128_T {
__m128i si;
uint32_t u[4];
};
/** 128-bit data type */
typedef union W128_T w128_t;
#else
/** 128-bit data structure */
struct W128_T {
uint32_t u[4];
};
/** 128-bit data type */
typedef struct W128_T w128_t;
#endif
/*--------------------------------------
FILE GLOBAL VARIABLES
internal state, index counter and flag
--------------------------------------*/
/** the 128-bit internal state array */
static w128_t sfmt[N];
/** the 32bit integer pointer to the 128-bit internal state array */
static uint32_t *psfmt32 = &sfmt[0].u[0];
#if !defined(BIG_ENDIAN64) || defined(ONLY64)
/** the 64bit integer pointer to the 128-bit internal state array */
static uint64_t *psfmt64 = (uint64_t *)&sfmt[0].u[0];
#endif
/** index counter to the 32-bit internal state array */
static int idx;
/** a flag: it is 0 if and only if the internal state is not yet
* initialized. */
static int initialized = 0;
/** a parity check vector which certificate the period of 2^{MEXP} */
static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
/*----------------
STATIC FUNCTIONS
----------------*/
inline static int idxof(int i);
inline static void rshift128(w128_t *out, w128_t const *in, int shift);
inline static void lshift128(w128_t *out, w128_t const *in, int shift);
inline static void gen_rand_all(void);
inline static void gen_rand_array(w128_t *array, int size);
inline static uint32_t func1(uint32_t x);
inline static uint32_t func2(uint32_t x);
static void period_certification(void);
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
inline static void swap(w128_t *array, int size);
#endif
#if defined(HAVE_ALTIVEC)
#include "SFMT-alti.h"
#elif defined(HAVE_SSE2)
#include "SFMT-sse2.h"
#endif
/**
* This function simulate a 64-bit index of LITTLE ENDIAN
* in BIG ENDIAN machine.
*/
#ifdef ONLY64
inline static int idxof(int i) {
return i ^ 1;
}
#else
inline static int idxof(int i) {
return i;
}
#endif
/**
* This function simulates SIMD 128-bit right shift by the standard C.
* The 128-bit integer given in in is shifted by (shift * 8) bits.
* This function simulates the LITTLE ENDIAN SIMD.
* @param out the output of this function
* @param in the 128-bit data to be shifted
* @param shift the shift value
*/
#ifdef ONLY64
inline static void rshift128(w128_t *out, w128_t const *in, int shift) {
uint64_t th, tl, oh, ol;
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
oh = th >> (shift * 8);
ol = tl >> (shift * 8);
ol |= th << (64 - shift * 8);
out->u[0] = (uint32_t)(ol >> 32);
out->u[1] = (uint32_t)ol;
out->u[2] = (uint32_t)(oh >> 32);
out->u[3] = (uint32_t)oh;
}
#else
inline static void rshift128(w128_t *out, w128_t const *in, int shift) {
uint64_t th, tl, oh, ol;
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
oh = th >> (shift * 8);
ol = tl >> (shift * 8);
ol |= th << (64 - shift * 8);
out->u[1] = (uint32_t)(ol >> 32);
out->u[0] = (uint32_t)ol;
out->u[3] = (uint32_t)(oh >> 32);
out->u[2] = (uint32_t)oh;
}
#endif
/**
* This function simulates SIMD 128-bit left shift by the standard C.
* The 128-bit integer given in in is shifted by (shift * 8) bits.
* This function simulates the LITTLE ENDIAN SIMD.
* @param out the output of this function
* @param in the 128-bit data to be shifted
* @param shift the shift value
*/
#ifdef ONLY64
inline static void lshift128(w128_t *out, w128_t const *in, int shift) {
uint64_t th, tl, oh, ol;
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
oh = th << (shift * 8);
ol = tl << (shift * 8);
oh |= tl >> (64 - shift * 8);
out->u[0] = (uint32_t)(ol >> 32);
out->u[1] = (uint32_t)ol;
out->u[2] = (uint32_t)(oh >> 32);
out->u[3] = (uint32_t)oh;
}
#else
inline static void lshift128(w128_t *out, w128_t const *in, int shift) {
uint64_t th, tl, oh, ol;
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
oh = th << (shift * 8);
ol = tl << (shift * 8);
oh |= tl >