summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-04-03 00:48:42 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2008-05-12 19:57:06 (GMT)
commitfd6f4829916ccdbecf3de724b6db09e5c694a5b8 (patch)
tree8baea9ade7d026bd534cad7bb4dbee9d09568426
parent96071355b15ea3bd7694d94912e38f30fcb1d31f (diff)
downloadmoo-fd6f4829916ccdbecf3de724b6db09e5c694a5b8.zip
moo-fd6f4829916ccdbecf3de724b6db09e5c694a5b8.tar.gz
moo-fd6f4829916ccdbecf3de724b6db09e5c694a5b8.tar.bz2
moo-fd6f4829916ccdbecf3de724b6db09e5c694a5b8.tar.xz
Type handling cleanup
- use [u]int*_t types (autoconf can verify they exist) - use C99-like macros for printf - abstract Num and Objid out - default to 64 bit integers - un-pointerify floating-point numbers (makes no sense on modern hardware)
-rw-r--r--Makefile.in23
-rw-r--r--code_gen.c10
-rw-r--r--config.h.in123
-rw-r--r--configure.in88
-rw-r--r--db.h4
-rw-r--r--db_file.c58
-rw-r--r--db_io.c65
-rw-r--r--db_io.h4
-rw-r--r--db_objects.c1
-rw-r--r--disassemble.c4
-rw-r--r--execute.c29
-rw-r--r--execute.h2
-rw-r--r--functions.c24
-rw-r--r--functions.h6
-rw-r--r--list.c17
-rw-r--r--log.c6
-rw-r--r--log.h6
-rw-r--r--md5.c48
-rw-r--r--md5.h13
-rw-r--r--my-math.h7
-rw-r--r--my-stdio.h1
-rw-r--r--my-time.h2
-rw-r--r--name_lookup.c12
-rw-r--r--name_lookup.h4
-rw-r--r--numbers.c274
-rw-r--r--numbers.h4
-rw-r--r--objects.c14
-rw-r--r--opcode.h2
-rw-r--r--parser.y12
-rw-r--r--program.h2
-rw-r--r--server.c32
-rw-r--r--storage.c1
-rw-r--r--str_intern.c1
-rw-r--r--streams.c125
-rw-r--r--streams.h2
-rw-r--r--structures.h11
-rw-r--r--tasks.c4
-rw-r--r--timers.h2
-rw-r--r--utils.c23
39 files changed, 580 insertions, 486 deletions
diff --git a/Makefile.in b/Makefile.in
index 24e0bda..61d3fa4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -17,14 +17,7 @@ CC = @CC@
LIBRARIES = @LIBS@
YACC = @YACC@
-CFLAGS = -O
-# If you're using GCC, you may prefer:
-# CFLAGS = -O2 -finline-functions
-#
-# If you're not using GCC, and your compiler doesn't understand the
-# inline keyword, use the following. (This will be fixed in autoconf2
-# upgrade).
-# CFLAGS = -O2 -Dinline=
+CFLAGS = @CFLAGS@
YFLAGS = -d
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
@@ -97,12 +90,10 @@ restart:
touch restart
configure: configure.in
- # autoconf
- @echo "Not running autoconf; you must do this by hand."
- touch configure
+ autoconf
config.status: configure
- env CC= YACC= ./configure --no-create
+ ./config.status --recheck || ./configure --no-create
Makefile: Makefile.in config.status
@echo "[ $@ : $? ]"
@@ -154,6 +145,14 @@ depend: ${ALL_CSRCS}
ed - Makefile.in < eddep
rm -f eddep makedep
+.SUFFIXES: .c .o .i .s
+.c.o:
+ ${CC} ${CFLAGS} -c -o $@ $<
+.c.i:
+ ${CC} ${CFLAGS} -E -o $@ $<
+.c.s:
+ ${CC} ${CFLAGS} -S -o $@ $<
+
###############################################################################
# $Log$
# Revision 1.10 2006/12/06 23:44:24 wrog
diff --git a/code_gen.c b/code_gen.c
index 8835aeb..f8c0989 100644
--- a/code_gen.c
+++ b/code_gen.c
@@ -196,7 +196,7 @@ emit_extended_byte(Byte b, State * state)
static int
add_known_fixup(Fixup f, State * state)
{
- int i;
+ unsigned int i;
if (state->num_fixups == state->max_fixups) {
unsigned new_max = 2 * state->max_fixups;
@@ -448,7 +448,7 @@ static void
enter_loop(int id, Fixup top_label, unsigned top_stack,
int bottom_label, unsigned bottom_stack, State * state)
{
- int i;
+ unsigned int i;
Loop *loop;
if (state->num_loops == state->max_loops) {
@@ -1111,11 +1111,11 @@ max(unsigned a, unsigned b)
}
static unsigned
-ref_size(unsigned max)
+ref_size(unsigned rmax)
{
- if (max <= 256)
+ if (rmax <= 256)
return 1;
- else if (max <= 256 * 256)
+ else if (rmax <= 256 * 256)
return 2;
else
return 4;
diff --git a/config.h.in b/config.h.in
index 17d3871..635f2e8 100644
--- a/config.h.in
+++ b/config.h.in
@@ -36,6 +36,8 @@
#undef _MINIX
#undef _POSIX_1_SOURCE
#undef _HPUX_SOURCE
+#undef _XOPEN_SOURCE
+#undef _GNU_SOURCE
/* The following symbols describe whether or not certain functions are declared
* in header files on your system and, if so, where. If, on your system, the
@@ -157,6 +159,15 @@
# define signed __signed__
#endif
+/* Let the C compiler warn us if we do something silly with printf or
+ * scanf, even if they are our own variants...
+ */
+#if defined(__GNUC__) && __GNUC__ >= 3
+# define FORMAT(x,y,z) __attribute__((format (x,y,z)))
+#else
+# define FORMAT(x,y,z)
+#endif
+
/* Certain functions used by the server are `optional', in the sense that the
* server can provide its own definition if necessary. In some cases, there
* are a number of common ways to do the same thing, differing by system type
@@ -249,26 +260,118 @@
#undef POSIX_NONBLOCKING_WORKS
-/* The following code figures out how to express a 32-bit integer type on your
- * machine.
+/*
+ * The following code figures out how to express a 32- and 64-bit integer
+ * types on your machine.
*/
+#undef HAVE_LONG_LONG
+#undef HAVE_INT32_T
+#undef HAVE_INT64_T
+
+#undef HAVE_STRTOIMAX
+
+#undef NEED_STDINT_H
+#undef NEED_INTTYPES_H
+
+#ifdef NEED_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef NEED_STDINT_H
+# include <stdint.h>
+#endif
+
#include <limits.h>
-#if INT_MAX == 2147483647
- typedef int int32;
- typedef unsigned unsigned32;
-# define INT32_MAX INT_MAX
-#else
-# if LONG_MAX == 2147483647
- typedef long int int32;
- typedef unsigned long unsigned32;
+#ifndef HAVE_INT32_T
+# if INT_MAX == 2147483647
+ typedef int int32_t;
+ typedef unsigned uint32_t;
+# define INT32_MAX INT_MAX
+# define PRId32 "d"
+# define PRIi32 "i"
+# define PRIo32 "o"
+# define PRIu32 "u"
+# define PRIx32 "x"
+# define PRIX32 "X"
+# define SCNd32 "d"
+# define SCNi32 "i"
+# define SCNo32 "o"
+# define SCNu32 "u"
+# define SCNx32 "x"
+# elif LONG_MAX == 2147483647
+ typedef long int int32_t;
+ typedef unsigned long uint32_t;
# define INT32_MAX LONG_MAX
+# define PRId32 "ld"
+# define PRIi32 "li"
+# define PRIo32 "lo"
+# define PRIu32 "lu"
+# define PRIx32 "lx"
+# define PRIX32 "lX"
+# define SCNd32 "ld"
+# define SCNi32 "li"
+# define SCNo32 "lo"
+# define SCNu32 "lu"
+# define SCNx32 "lx"
# else
# error I cannot figure out how to express a 32-bit integer on your machine.
# endif
#endif
+#ifndef HAVE_INT64_T
+# if LONG_MAX == 9223372036854775807
+ typedef long int64_t;
+ typedef unsigned long uint64_t;
+# define INT64_MAX LONG_MAX
+# define PRId64 "ld"
+# define PRIi64 "li"
+# define PRIo64 "lo"
+# define PRIu64 "lu"
+# define PRIx64 "lx"
+# define PRIX64 "lX"
+# define SCNd64 "ld"
+# define SCNi64 "li"
+# define SCNo64 "lo"
+# define SCNu64 "lu"
+# define SCNx64 "lx"
+# elif defined(HAVE_LONG_LONG) && LONG_LONG_MAX == 9223372036854775807
+ typedef long long int64;
+ typedef unsigned long long unsigned64;
+# define INT64_MAX LONG_LONG_MAX
+# define PRId64 "lld"
+# define PRIi64 "lli"
+# define PRIo64 "llo"
+# define PRIu64 "llu"
+# define PRIx64 "llx"
+# define PRIX64 "llX"
+# define SCNd64 "lld"
+# define SCNi64 "lli"
+# define SCNo64 "llo"
+# define SCNu64 "llu"
+# define SCNx64 "llx"
+# else
+# error I cannot figure out how to express a 64-bit integer on your machine.
+# endif
+#endif
+
+#ifndef HAVE_STRTOIMAX
+# ifdef HAVE_LONG_LONG
+# define strtoimax strtoll
+# define strtoumax strtoull
+# else
+# define strtoimax strtol
+# define strtoumax strtoul
+# endif
+#endif
+
+/* 8-bit bytes */
+#undef HAVE_UINT8_T
+
+#ifndef HAVE_UINT8_T
+typedef unsigned char uint8_t;
+#endif
+
#endif /* !Config_H */
/*
diff --git a/configure.in b/configure.in
index d8fe691..d8a4158 100644
--- a/configure.in
+++ b/configure.in
@@ -89,15 +89,6 @@ AC_PROGRAM_EGREP(yes, [
AC_DEFINE(_POSIX_SOURCE))])
dnl ***************************************************************************
-dnl MOO_MALLOC_H
-dnl Define NEED_MALLOC_H if `malloc()' is not declared in <stdlib.h> and
-dnl <malloc.h> exists.
-define(MOO_MALLOC_H, [
-echo checking whether stdlib.h declares malloc and friends
-MOO_FUNC_DECL_CHECK(stdlib.h, malloc, ,
- AC_HEADER_CHECK(malloc.h, AC_DEFINE(NEED_MALLOC_H)))])
-
-dnl ***************************************************************************
dnl MOO_FUNC_DECL_CHECK(header, func,
dnl if-declared [, if-not-declared[, extra-hdr]])
dnl Do `if-declared' is `func' is declared in `header', and if-not-declared
@@ -185,12 +176,12 @@ do
trfrom='[a-z]' trto='[A-Z]'
var=HAVE_`echo $func | tr "$trfrom" "$trto"`
changequote([,])dnl
- AC_FUNC_CHECK($func, AC_DEFINE($var), [
+ AC_FUNC_CHECK($func, AC_DEFINE_UNQUOTED($var), [
SAVELIBS="$LIBS"
for lib in $2
do
LIBS="$LIBS $lib"
- AC_FUNC_CHECK($func, [AC_DEFINE($var)
+ AC_FUNC_CHECK($func, [AC_DEFINE_UNQUOTED($var)
break],
LIBS="$SAVELIBS")
done
@@ -225,29 +216,6 @@ done
])
dnl ***************************************************************************
-dnl MOO_CONST
-dnl Check whether or not the C compiler can cope with simple uses of the ANSI C
-dnl `const' keyword, defining `const' as the empty string if it can't.
-define(MOO_CONST, [
-echo checking for a working const keyword
-cat << EOF > conftest.c
-#ifdef __GNUC__
-#define const __const__
-#endif
-int foo(const char *x) { return 17 + (x - x); }
-int bar() { int x = foo("foo"); return x; }
-EOF
-if $CC -c conftest.c > conftest.out 2>&1; then
- if test -s conftest.out; then
- AC_DEFINE(const,)
- fi
-else
- AC_DEFINE(const,)
-fi
-rm -f conftest*
-])
-
-dnl ***************************************************************************
dnl MOO_ANSI_C
dnl Check whether or not the C compiler handles ANSI C (i.e., allows function
dnl prototypes and the `void *' type) and try to make it do so by adding
@@ -274,6 +242,22 @@ exit 1
fi
])
+dnl --------------------------------------------------------------------------
+dnl MOO_ADD_CFLAGS()
+dnl
+dnl Attempt to add the given option to CFLAGS, if it doesn't break compilation
+dnl --------------------------------------------------------------------------
+AC_DEFUN(MOO_ADD_CFLAGS,
+[AC_MSG_CHECKING([if $CC accepts $1])
+ pa_add_cflags__old_cflags="$CFLAGS"
+ CFLAGS="$CFLAGS $1"
+ AC_TRY_LINK([#include <stdio.h>],
+ [printf("Hello, World!\n");],
+ AC_MSG_RESULT([yes]),
+ AC_MSG_RESULT([no])
+ CFLAGS="$pa_add_cflags__old_cflags")])
+
+
dnl ***************************************************************************
dnl Start of actual configuration tests
dnl ***************************************************************************
@@ -281,6 +265,7 @@ dnl ***************************************************************************
AC_PROG_YACC
AC_PROG_CC
AC_GCC_TRADITIONAL
+AC_GNU_SOURCE
AC_PROGRAM_EGREP(yes, [
#if __GNUC__==2
yes
@@ -298,19 +283,39 @@ AC_SCO_INTL
MOO_AUX
MOO_HPUX
MOO_ANSI_C
-MOO_CONST
-CPP=""
-AC_PROG_CPP
-MOO_MALLOC_H
+MOO_ADD_CFLAGS(-Wall)
+MOO_ADD_CFLAGS(-W)
+MOO_ADD_CFLAGS(-Wwrite-strings)
+MOO_ADD_CFLAGS(-Wpointer-arith)
+MOO_ADD_CFLAGS(-Wbad-function-cast)
+MOO_ADD_CFLAGS(-Wcast-equal)
+MOO_ADD_CFLAGS(-Wstrict-prototypes)
+MOO_ADD_CFLAGS(-Wmissing-prototypes)
+MOO_ADD_CFLAGS(-Wmissing-declarations)
+MOO_ADD_CFLAGS(-Wnested-externs)
+MOO_ADD_CFLAGS(-Winline)
+MOO_ADD_CFLAGS(-Wwrite-strings)
+dnl MOO_ADD_CFLAGS(-Wundef)
+dnl MOO_ADD_CFLAGS(-Wshadow)
+dnl MOO_ADD_CFLAGS(-Wsign-compare)
+MOO_ADD_CFLAGS(-pipe)
+MOO_ADD_CFLAGS(-O3)
+AC_C_CONST
+AC_C_INLINE
+AC_C_RESTRICT
+AC_SYS_LARGEFILE
+AC_HEADER_CHECK(malloc.h, AC_DEFINE(NEED_MALLOC_H))
AC_HEADER_CHECK(sys/bsdtypes.h, AC_DEFINE(NEED_BSDTYPES_H))
AC_HEADER_CHECK(sys/select.h, AC_DEFINE(NEED_SELECT_H))
AC_HEADER_CHECK(memory.h, AC_DEFINE(NEED_MEMORY_H))
+AC_HEADER_CHECK(inttypes.h, AC_DEFINE(NEED_INTTYPES_H))
+AC_HEADER_CHECK(stdint.h, AC_DEFINE(NEED_STDINT_H))
AC_PID_T
AC_MODE_T
AC_SIZE_T
AC_STRUCT_TM
AC_TIMEZONE
-MOO_HAVE_FUNC_LIBS(sqrt, -lm /lib/libm.a "-static -lm")
+MOO_HAVE_FUNC_LIBS(atan2 asinh expm1 erfc j1, -lm /lib/libm.a "-static -lm")
MOO_HAVE_FUNC_LIBS(mkfifo waitpid sigemptyset, -lposix /lib/libposix.a)
MOO_HAVE_FUNC_LIBS(accept, "-lsocket -lnsl" -lsocket -linet)
MOO_HAVE_FUNC_LIBS(t_open, -lnsl -lnsl_s)
@@ -318,11 +323,16 @@ MOO_HAVE_FUNC_LIBS(crypt, -lcrypt -lcrypt_d)
AC_HAVE_HEADERS(unistd.h sys/cdefs.h stdlib.h tiuser.h machine/endian.h)
AC_HAVE_FUNCS(remove rename poll select strerror strftime strtoul matherr)
AC_HAVE_FUNCS(random lrand48 wait3 wait2 sigsetmask sigprocmask sigrelse)
+AC_HAVE_FUNCS(strtoimax)
MOO_NDECL_FUNCS(ctype.h, tolower)
MOO_NDECL_FUNCS(fcntl.h, fcntl)
MOO_NDECL_FUNCS(netinet/in.h, htonl)
dnl *** this next should really be some variety of AC_CHECK_TYPE
dnl *** but this is just a grep test anyway --wrog
+AC_CHECK_TYPES(long long)
+AC_CHECK_TYPES(uint8_t)
+AC_CHECK_TYPES(int32_t)
+AC_CHECK_TYPES(int64_t)
MOO_NDECL_VARS(netinet/in.h, in_addr_t)
MOO_NDECL_FUNCS(sys/ioctl.h, ioctl)
MOO_NDECL_FUNCS(poll.h, poll)
diff --git a/db.h b/db.h
index 96743a1..e4f6a7c 100644
--- a/db.h
+++ b/db.h
@@ -61,7 +61,7 @@ extern int db_flush(enum db_flush_type);
* argument. Returns true on success.
*/
-extern int32 db_disk_size(void);
+extern int64_t db_disk_size(void);
/* Return the total size, in bytes, of the most
* recent full representation of the database
* as one or more disk files. Returns -1 if,
@@ -471,7 +471,7 @@ extern db_verb_handle db_find_defined_verb(Objid oid, const char *verb,
* leave the handle intact.
*/
-extern db_verb_handle db_find_indexed_verb(Objid oid, unsigned index);
+extern db_verb_handle db_find_indexed_verb(Objid oid, unsigned idx);
/* Returns a handle on the 1-based INDEX'th
* verb defined on OID. The `ptr' in the
* result is null iff there is no such verb.
diff --git a/db_file.c b/db_file.c
index b9c7827..1788a02 100644
--- a/db_file.c
+++ b/db_file.c
@@ -23,6 +23,7 @@
#include "my-unistd.h"
#include "my-stdio.h"
#include "my-stdlib.h"
+#include "my-string.h"
#include "config.h"
#include "db.h"
@@ -71,7 +72,7 @@ write_verbdef(Verbdef * v)
}
static Propdef
-read_propdef()
+read_propdef(void)
{
const char *name = dbio_read_string_intern();
return dbpriv_new_propdef(name);
@@ -112,7 +113,7 @@ read_object(void)
Verbdef *v, **prevv;
int nprops;
- if (dbio_scanf("#%d", &oid) != 1 || oid != db_last_used_objid() + 1)
+ if (dbio_scanf("#%"SCNdN, &oid) != 1 || oid != db_last_used_objid() + 1)
return 0;
dbio_read_line(s, sizeof(s));
@@ -178,12 +179,12 @@ write_object(Objid oid)
int nverbdefs, nprops;
if (!valid(oid)) {
- dbio_printf("#%d recycled\n", oid);
+ dbio_printf("#%"PRIdN"d recycled\n", oid);
return;
}
o = dbpriv_find_object(oid);
- dbio_printf("#%d\n", oid);
+ dbio_printf("#%"PRIdN"d\n", oid);
dbio_write_string(o->name);
dbio_write_string(""); /* placeholder for old handles string */
dbio_write_num(o->flags);
@@ -220,7 +221,7 @@ write_object(Objid oid)
/*********** File-level Input ***********/
static int
-validate_hierarchies()
+validate_hierarchies(void)
{
Objid oid;
Objid size = db_last_used_objid() + 1;
@@ -232,7 +233,7 @@ validate_hierarchies()
# define MAYBE_LOG_PROGRESS \
{ \
if (log_report_progress()) { \
- oklog("VALIDATE: Done through #%d ...\n", oid); \
+ oklog("VALIDATE: Done through #%"PRIdN" ...\n", oid); \
} \
}
@@ -250,7 +251,7 @@ validate_hierarchies()
{ \
if (o->field != NOTHING \
&& !dbpriv_find_object(o->field)) { \
- errlog("VALIDATE: #%d.%s = #%d <invalid> ... fixed.\n", \
+ errlog("VALIDATE: #%"PRIdN".%s = #%"PRIdN" <invalid> ... fixed.\n", \
oid, name, o->field); \
o->field = NOTHING; \
} \
@@ -288,7 +289,7 @@ validate_hierarchies()
faster = dbpriv_find_object(faster)->field; \
slower = dbpriv_find_object(slower)->field; \
if (faster == slower) { \
- errlog("VALIDATE: Cycle in `%s' chain of #%d\n", \
+ errlog("VALIDATE: Cycle in `%s' chain of #%"PRIdN"\n", \
name, oid); \
broken = 1; \
break; \
@@ -329,7 +330,7 @@ validate_hierarchies()
okid = dbpriv_find_object(oidkid); \
if (okid->up != oid) { \
errlog( \
- "VALIDATE: #%d erroneously on #%d's %s list.\n", \
+ "VALIDATE: #%"PRIdN" erroneously on #%"PRIdN"'s %s list.\n", \
oidkid, oid, down_name); \
broken = 1; \
} \
@@ -357,7 +358,7 @@ validate_hierarchies()
{ \
/* If oid is unclaimed, up must be NOTHING */ \
if ((o->flags & (1<<(FLAG))) && o->up != NOTHING) { \
- errlog("VALIDATE: #%d not in %s (#%d)'s %s list.\n", \
+ errlog("VALIDATE: #%"PRIdN" not in %s (#%"PRIdN")'s %s list.\n", \
oid, up_name, o->up, down_name); \
broken = 1; \
} \
@@ -386,7 +387,7 @@ fmt_verb_name(void *data)
if (!s)
s = new_stream(40);
- stream_printf(s, "#%d:%s", db_verb_definer(*h), db_verb_names(*h));
+ stream_printf(s, "#%"PRIdN"d:%s", db_verb_definer(*h), db_verb_names(*h));
return reset_stream(s);
}
@@ -394,9 +395,8 @@ static int
read_db_file(void)
{
Objid oid;
- int nobjs, nprogs, nusers;
+ Num i, nobjs, nprogs, nusers, vnum, dummy;
Var user_list;
- int i, vnum, dummy;
db_verb_handle h;
Program *program;
@@ -414,7 +414,7 @@ read_db_file(void)
* suppressed assignments are not counted in determining the returned value
* of `scanf'...
*/
- if (dbio_scanf("%d\n%d\n%d\n%d\n",
+ if (dbio_scanf("%"SCNdN"\n%"SCNdN"\n%"SCNdN"\n%"SCNdN"\n",
&nobjs, &nprogs, &dummy, &nusers) != 4) {
errlog("READ_DB_FILE: Bad header\n");
return 0;
@@ -426,44 +426,44 @@ read_db_file(void)
}
dbpriv_set_all_users(user_list);
- oklog("LOADING: Reading %d objects...\n", nobjs);
+ oklog("LOADING: Reading %"PRIdN" objects...\n", nobjs);
for (i = 1; i <= nobjs; i++) {
if (!read_object()) {
- errlog("READ_DB_FILE: Bad object #%d.\n", i - 1);
+ errlog("READ_DB_FILE: Bad object #%"PRIdN".\n", i - 1);
return 0;
}
if (i == nobjs || log_report_progress())
- oklog("LOADING: Done reading %d objects ...\n", i);
+ oklog("LOADING: Done reading %"PRIdN" objects ...\n", i);
}
if (!validate_hierarchies()) {
errlog("READ_DB_FILE: Errors in object hierarchies.\n");
return 0;
}
- oklog("LOADING: Reading %d MOO verb programs...\n", nprogs);
+ oklog("LOADING: Reading %"PRIdN" MOO verb programs...\n", nprogs);
for (i = 1; i <= nprogs; i++) {
- if (dbio_scanf("#%d:%d\n", &oid, &vnum) != 2) {
- errlog("READ_DB_FILE: Bad program header, i = %d.\n", i);
+ if (dbio_scanf("#%"SCNdN":%"SCNdN"\n", &oid, &vnum) != 2) {
+ errlog("READ_DB_FILE: Bad program header, i = %"PRIdN".\n", i);
return 0;
}
if (!valid(oid)) {
- errlog("READ_DB_FILE: Verb for non-existant object: #%d:%d.\n",
+ errlog("READ_DB_FILE: Verb for non-existant object: #%"PRIdN":%"PRIdN".\n",
oid, vnum);
return 0;
}
h = db_find_indexed_verb(oid, vnum + 1); /* DB file is 0-based. */
if (!h.ptr) {
- errlog("READ_DB_FILE: Unknown verb index: #%d:%d.\n", oid, vnum);
+ errlog("READ_DB_FILE: Unknown verb index: #%"PRIdN":%"PRIdN".\n", oid, vnum);
return 0;
}
program = dbio_read_program(dbio_input_version, fmt_verb_name, &h);
if (!program) {
- errlog("READ_DB_FILE: Unparsable program #%d:%d.\n", oid, vnum);
+ errlog("READ_DB_FILE: Unparsable program #%"PRIdN":%"PRIdN".\n", oid, vnum);
return 0;
}
db_set_verb_program(h, program);
if (i == nprogs || log_report_progress())
- oklog("LOADING: Done reading %d verb programs...\n", i);
+ oklog("LOADING: Done reading %"PRIdN" verb programs...\n", i);
}
oklog("LOADING: Reading forked and suspended tasks...\n");
@@ -504,15 +504,15 @@ write_db_file(const char *reason)
TRY {
dbio_printf(header_format_string, current_version);
- dbio_printf("%d\n%d\n%d\n%d\n",
+ dbio_printf("%"PRIdN"\n%d\n%d\n%"PRIdN"\n",
max_oid + 1, nprogs, 0, user_list.v.list[0].v.num);
for (i = 1; i <= user_list.v.list[0].v.num; i++)
dbio_write_objid(user_list.v.list[i].v.obj);
- oklog("%s: Writing %d objects...\n", reason, max_oid + 1);
+ oklog("%s: Writing %"PRIdN" objects...\n", reason, max_oid + 1);
for (oid = 0; oid <= max_oid; oid++) {
write_object(oid);
if (oid == max_oid || log_report_progress())
- oklog("%s: Done writing %d objects...\n", reason, oid + 1);
+ oklog("%s: Done writing %"PRIdN" objects...\n", reason, oid + 1);
}
oklog("%s: Writing %d MOO verb programs...\n", reason, nprogs);
for (i = 0, oid = 0; oid <= max_oid; oid++)
@@ -521,7 +521,7 @@ write_db_file(const char *reason)
for (v = dbpriv_find_object(oid)->verbdefs; v; v = v->next) {
if (v->program) {
- dbio_printf("#%d:%d\n", oid, vcount);
+ dbio_printf("#%"PRIdN":%d\n", oid, vcount);
dbio_write_program(v->program);
if (++i == nprogs || log_report_progress())
oklog("%s: Done writing %d verb programs...\n",
@@ -716,7 +716,7 @@ db_flush(enum db_flush_type type)
return success;
}
-int32
+int64_t
db_disk_size(void)
{
struct stat st;
diff --git a/db_io.c b/db_io.c
index f4366e5..7491be3 100644
--- a/db_io.c
+++ b/db_io.c
@@ -19,11 +19,13 @@
* Routines for use by non-DB modules with persistent state stored in the DB
*****************************************************************************/
+#include "config.h"
#include "my-ctype.h"
#include <float.h>
#include "my-stdarg.h"
#include "my-stdio.h"
#include "my-stdlib.h"
+#include "my-string.h"
#include "db_io.h"
#include "db_private.h"
@@ -64,64 +66,7 @@ dbio_scanf(const char *format,...)
const char *ptr;
va_start(args, format);
- /* The following line would be nice, but unfortunately those darlings on
- * the ANSI C committee apparently didn't feel it worthwhile to include
- * support for functions wrapping `scanf' *even though* they included
- * symmetric such support for functions wrapping `printf'. (*sigh*)
- * Fortunately, we only use a small fraction of the full functionality of
- * scanf in the server, so it's not unbearably unpleasant to have to
- * reimplement it here.
- */
- /* count = vfscanf(input, format, args); */
-
- count = 0;
- for (ptr = format; *ptr; ptr++) {
- int c, n, *ip;
- unsigned *up;
- char *cp;
-
- if (isspace(*ptr)) {
- do
- c = fgetc(input);
- while (isspace(c));
- ungetc(c, input);
- } else if (*ptr != '%') {
- do
- c = fgetc(input);
- while (isspace(c));
-
- if (c == EOF)
- return count ? count : EOF;
- else if (c != *ptr) {
- ungetc(c, input);
- return count;
- }
- } else
- switch (*++ptr) {
- case 'd':
- ip = va_arg(args, int *);
- n = fscanf(input, "%d", ip);
- goto finish;
- case 'u':
- up = va_arg(args, unsigned *);
- n = fscanf(input, "%u", up);
- goto finish;
- case 'c':
- cp = va_arg(args, char *);
- n = fscanf(input, "%c", cp);
- finish:
- if (n == 1)
- count++;
- else if (n == 0)
- return count;
- else /* n == EOF */
- return count ? count : EOF;
- break;
- default:
- panic("DBIO_SCANF: Unsupported directive!");
- }
- }
-
+ count = vfscanf(input, format, args);
va_end(args);
return count;
@@ -232,7 +177,7 @@ dbio_read_var(void)
r.v.num = dbio_read_num();
break;
case _TYPE_FLOAT:
- r = new_float(dbio_read_float());
+ r.v.fnum = dbio_read_float();
break;
case _TYPE_LIST:
l = dbio_read_num();
@@ -386,7 +331,7 @@ dbio_write_var(Var v)
dbio_write_num(v.v.num);
break;
case TYPE_FLOAT:
- dbio_write_float(*v.v.fnum);
+ dbio_write_float(v.v.fnum);
break;
case TYPE_LIST:
dbio_write_num(v.v.list[0].v.num);
diff --git a/db_io.h b/db_io.h
index 6e00cd1..18bd436 100644
--- a/db_io.h
+++ b/db_io.h
@@ -34,7 +34,7 @@ extern void dbio_read_line(char *s, int n);
* null. (Like the `fgets()' function.)
*/
-extern int dbio_scanf(const char *format,...);
+extern int dbio_scanf(const char *format,...) FORMAT(scanf,1,2);
extern int dbio_read_num(void);
extern Objid dbio_read_objid(void);
@@ -80,7 +80,7 @@ extern Program *dbio_read_program(DB_Version version,
* event.
*/
-extern void dbio_printf(const char *format,...);
+extern void dbio_printf(const char *format,...) FORMAT(printf,1,2);
extern void dbio_write_num(int);
extern void dbio_write_objid(Objid);
diff --git a/db_objects.c b/db_objects.c
index 97fd7c9..46bfa67 100644
--- a/db_objects.c
+++ b/db_objects.c
@@ -26,6 +26,7 @@
#include "program.h"
#include "storage.h"
#include "utils.h"
+#include "my-string.h"
static Object **objects;
static int num_objects = 0;
diff --git a/disassemble.c b/disassemble.c
index 0790b8a..2a7fcdd 100644
--- a/disassemble.c
+++ b/disassemble.c
@@ -345,10 +345,10 @@ disassemble(Program * prog, Printer p, void *data)
v = literals[ADD_BYTES(bc.numbytes_literal)];
switch (v.type) {
case TYPE_OBJ:
- stream_printf(insn, " #%d", v.v.obj);
+ stream_printf(insn, " #%"PRIdN, v.v.obj);
break;
case TYPE_INT:
- stream_printf(insn, " %d", v.v.num);
+ stream_printf(insn, " %"PRIdN, v.v.num);
break;
case TYPE_STR:
stream_add_string(insn, " \"");
diff --git a/execute.c b/execute.c
index e2207f0..fd1c251 100644
--- a/execute.c
+++ b/execute.c
@@ -44,11 +44,11 @@
/* the following globals are the guts of the virtual machine: */
static activation *activ_stack = 0;
-static int max_stack_size = 0;
+static Num max_stack_size = 0;
static unsigned top_activ_stack; /* points to top-of-stack
(last-occupied-slot),
not next-empty-slot */
-static int root_activ_vector; /* root_activ_vector == MAIN_VECTOR
+static Num root_activ_vector; /* root_activ_vector == MAIN_VECTOR
iff root activation is main
vector */
@@ -86,7 +86,7 @@ static Var *rt_stack_quick;
#define RT_STACK_QUICKSIZE 15
static void
-alloc_rt_stack(activation * a, int size)
+alloc_rt_stack(activation * a, Num size)
{
Var *res;
@@ -124,10 +124,10 @@ print_error_backtrace(const char *msg, void (*output) (const char *))
for (t = top_activ_stack; t >= 0; t--) {
if (t != top_activ_stack)
stream_printf(str, "... called from ");
- stream_printf(str, "#%d:%s", activ_stack[t].vloc,
+ stream_printf(str, "#%"PRIdN":%s", activ_stack[t].vloc,
activ_stack[t].verbname);
if (activ_stack[t].vloc != activ_stack[t].this)
- stream_printf(str, " (this == #%d)", activ_stack[t].this);
+ stream_printf(str, " (this == #%"PRIdN")", activ_stack[t].this);
stream_printf(str, ", line %d",
find_line_number(activ_stack[t].prog,
@@ -1242,7 +1242,7 @@ do { \
ans.type = TYPE_INT;
ans.v.num = -arg.v.num;
} else if (arg.type == TYPE_FLOAT)
- ans = new_float(-*arg.v.fnum);
+ ans.v.fnum = -arg.v.fnum;
else {
free_var(arg);
PUSH_ERROR(E_TYPE);
@@ -1481,7 +1481,7 @@ do { \
*/
/* First make sure traceback will be accurate. */
STORE_STATE_VARIABLES();
- oklog("%sWIZARDED: #%d by programmer #%d\n",
+ oklog("%sWIZARDED: #%"PRIdN" by programmer #%"PRIdN"\n",
is_wizard(obj.v.obj) ? "DE" : "",
obj.v.obj, progr);
print_error_backtrace(is_wizard(obj.v.obj)
@@ -2647,8 +2647,8 @@ write_activ_as_pi(activation a)
dummy.v.num = -111;
dbio_write_var(dummy);
- dbio_printf("%d %d %d %d %d %d %d %d %d\n",
- a.this, -7, -8, a.player, -9, a.progr, a.vloc, -10, a.debug);
+ dbio_printf("%"PRIdN" -7 -8 %"PRIdN" -9 %"PRIdN" %"PRIdN" -10 %d\n",
+ a.this, a.player, a.progr, a.vloc, a.debug);
dbio_write_string("No");
dbio_write_string("More");
dbio_write_string("Parse");
@@ -2660,7 +2660,7 @@ write_activ_as_pi(activation a)
int
read_activ_as_pi(activation * a)
{
- int dummy;
+ Objid dummy;
char c;
free_var(dbio_read_var());
@@ -2671,7 +2671,7 @@ read_activ_as_pi(activation * a)
* suppressed assignments are not counted in determining the returned value
* of `scanf'...
*/
- if (dbio_scanf("%d %d %d %d %d %d %d %d %d%c",
+ if (dbio_scanf("%"SCNdN" %"SCNdN" %"SCNdN" %"SCNdN" %"SCNdN" %"SCNdN" %"SCNdN" %"SCNdN" %d%c",
&a->this, &dummy, &dummy, &a->player, &dummy, &a->progr,
&a->vloc, &dummy, &a->debug, &c) != 10
|| c != '\n') {
@@ -2796,6 +2796,7 @@ int
read_activ(activation * a, int which_vector)
{
DB_Version version;
+ unsigned int v;
Var *old_rt_env;
const char **old_names;
int old_size, stack_in_use;
@@ -2806,10 +2807,10 @@ read_activ(activation * a, int which_vector)
if (dbio_input_version < DBV_Float)
version = dbio_input_version;
- else if (dbio_scanf("language version %u\n", &version) != 1) {
+ else if (dbio_scanf("language version %u\n", &v) != 1) {
errlog("READ_ACTIV: Malformed language version\n");
return 0;
- } else if (!check_version(version)) {
+ } else if (version = v, !check_version(version)) {
errlog("READ_ACTIV: Unrecognized language version: %d\n",
version);
return 0;
@@ -2839,7 +2840,7 @@ read_activ(activation * a, int which_vector)
*(a->top_rt_stack++) = dbio_read_var();
if (!read_activ_as_pi(a)) {
- errlog("READ_ACTIV: Bad activ.\n", stack_in_use);
+ errlog("READ_ACTIV: Bad activ. stack_in_use = %d\n", stack_in_use);
return 0;
}
a->temp = dbio_read_var();
diff --git a/execute.h b/execute.h
index e394a62..26b3400 100644
--- a/execute.h
+++ b/execute.h
@@ -113,7 +113,7 @@ extern int task_timed_out;
extern void abort_running_task(void);
extern void print_error_backtrace(const char *, void (*)(const char *));
extern void output_to_log(const char *);
-extern Objid caller();
+extern Objid caller(void);
extern void write_activ_as_pi(activation);
extern int read_activ_as_pi(activation *);
diff --git a/functions.c b/functions.c
index 3184482..de201c6 100644
--- a/functions.c
+++ b/functions.c
@@ -349,6 +349,30 @@ no_var_pack(void)
}
package
+make_int_pack(Num v)
+{
+ package p;
+
+ p.kind = BI_RETURN;
+ p.u.ret.type = TYPE_INT;
+ p.u.ret.v.num = v;
+
+ return p;
+}
+
+package
+make_float_pack(double v)
+{
+ package p;
+
+ p.kind = BI_RETURN;
+ p.u.ret.type = TYPE_FLOAT;
+ p.u.ret.v.fnum = v;
+
+ return p;
+}
+
+package
make_call_pack(Byte pc, void *data)
{
package p;
diff --git a/functions.h b/functions.h
index 2c7efb4..36daa62 100644
--- a/functions.h
+++ b/functions.h
@@ -51,12 +51,14 @@ typedef struct {
} u;
} package;
-void register_bi_functions();
+void register_bi_functions(void);
-package make_kill_pack();
+package make_kill_pack(void);
package make_error_pack(enum error err);
package make_raise_pack(enum error err, const char *msg, Var value);
package make_var_pack(Var v);
+package make_int_pack(Num v);
+package make_float_pack(double v);
package no_var_pack(void);
package make_call_pack(Byte pc, void *data);
package tail_call_pack(void);
diff --git a/list.c b/list.c
index ee1f4ac..2e0a4d4 100644
--- a/list.c
+++ b/list.c
@@ -17,6 +17,7 @@
#include "my-ctype.h"
#include "my-string.h"
+#include "my-math.h"
#include "bf_register.h"
#include "config.h"
@@ -232,10 +233,10 @@ list2str(Var * args)
for (i = 1; i <= args[0].v.num; i++) {
switch (args[i].type) {
case TYPE_INT:
- stream_printf(str, "%d", args[i].v.num);
+ stream_printf(str, "%"PRIdN, args[i].v.num);
break;
case TYPE_OBJ:
- stream_printf(str, "#%d", args[i].v.obj);
+ stream_printf(str, "#%"PRIdN, args[i].v.obj);
break;
case TYPE_STR:
stream_add_string(str, args[i].v.str);
@@ -244,7 +245,7 @@ list2str(Var * args)
stream_add_string(str, unparse_error(args[i].v.err));
break;
case TYPE_FLOAT:
- stream_printf(str, "%g", *args[i].v.fnum);
+ stream_printf(str, "%.*g", DBL_DIG, args[i].v.fnum);
break;
case TYPE_LIST:
stream_add_string(str, "{list}");
@@ -275,16 +276,16 @@ print_to_stream(Var v, Stream * s)
{
switch (v.type) {
case TYPE_INT:
- stream_printf(s, "%d", v.v.num);
+ stream_printf(s, "%"PRIdN, v.v.num);
break;
case TYPE_OBJ:
- stream_printf(s, "#%d", v.v.obj);
+ stream_printf(s, "#%"PRIdN, v.v.obj);
break;
case TYPE_ERR:
stream_add_string(s, error_name(v.v.num));
break;
case TYPE_FLOAT:
- stream_printf(s, "%g", *v.v.fnum);
+ stream_printf(s, "%.*g", DBL_DIG, v.v.fnum);
break;
case TYPE_STR:
{
@@ -926,14 +927,14 @@ static const char *
hash_bytes(const char *input, int length)
{
md5ctx_t context;
- uint8 result[16];
+ uint8_t result[16];
int i;
const char digits[] = "0123456789ABCDEF";
char *hex = str_dup("12345678901234567890123456789012");
const char *answer = hex;
md5_Init(&context);
- md5_Update(&context, (uint8 *) input, length);
+ md5_Update(&context, (uint8_t *) input, length);
md5_Final(&context, result);
for (i = 0; i < 16; i++) {
*hex++ = digits[result[i] >> 4];
diff --git a/log.c b/log.c
index 99dd0f0..dd4cdb2 100644
--- a/log.c
+++ b/log.c
@@ -48,7 +48,7 @@ int log_report_progress_cktime()
}
static void
-do_log(const char *fmt, va_list args, const char *prefix)
+do_log(const char *prefix, const char *fmt, va_list args)
{
FILE *f;
@@ -73,7 +73,7 @@ oklog(const char *fmt,...)
va_list args;
va_start(args, fmt);
- do_log(fmt, args, "");
+ do_log("", fmt, args);
va_end(args);
}
@@ -83,7 +83,7 @@ errlog(const char *fmt,...)
va_list args;
va_start(args, fmt);
- do_log(fmt, args, "*** ");
+ do_log("*** ", fmt, args);
va_end(args);
}
diff --git a/log.h b/log.h
index 6363fb4..d06dbcc 100644
--- a/log.h
+++ b/log.h
@@ -22,8 +22,8 @@
extern void set_log_file(FILE *);
-extern void oklog(const char *,...);
-extern void errlog(const char *,...);
+extern void oklog(const char *,...) FORMAT(printf,1,2);
+extern void errlog(const char *,...) FORMAT(printf,1,2);
extern void log_perror(const char *);
extern void reset_command_history(void);
@@ -34,7 +34,7 @@ extern void add_command_to_history(Objid player, const char *command);
#define log_report_progress() ((--log_pcount <= 0) && log_report_progress_cktime())
extern int log_pcount;
-extern int log_report_progress_cktime();
+extern int log_report_progress_cktime(void);
/*
* $Log$
diff --git a/md5.c b/md5.c
index 2cf50ca..064f764 100644
--- a/md5.c
+++ b/md5.c
@@ -68,7 +68,7 @@
#define S43 15
#define S44 21
-static uint8 PADDING[64] =
+static uint8_t PADDING[64] =
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -94,61 +94,61 @@ static uint8 PADDING[64] =
*/
#define FF(a, b, c, d, x, s, ac) \
{ \
- (a) += F((b), (c), (d)) + (x) + (uint32)(ac); \
+ (a) += F((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) \
{ \
- (a) += G((b), (c), (d)) + (x) + (uint32)(ac); \
+ (a) += G((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) \
{ \
- (a) += H((b), (c), (d)) + (x) + (uint32)(ac); \
+ (a) += H((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) \
{ \
- (a) += I((b), (c), (d)) + (x) + (uint32)(ac); \
+ (a) += I((b), (c), (d)) + (x) + (uint32_t)(ac); \
(a) = ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
/*
- * Encodes input (uint32) into output (uint8). Assumes len is a multiple of 4.
+ * Encodes input (uint32_t) into output (uint8_t). Assumes len is a multiple of 4.
*/
static void
-md5_Encode(uint8 * output, uint32 * input, int len)
+md5_Encode(uint8_t * output, uint32_t * input, int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
- output[j] = (uint8) (input[i] & 0xff);
- output[j + 1] = (uint8) ((input[i] >> 8) & 0xff);
- output[j + 2] = (uint8) ((input[i] >> 16) & 0xff);
- output[j + 3] = (uint8) ((input[i] >> 24) & 0xff);
+ output[j] = (uint8_t) (input[i] & 0xff);
+ output[j + 1] = (uint8_t) ((input[i] >> 8) & 0xff);
+ output[j + 2] = (uint8_t) ((input[i] >> 16) & 0xff);
+ output[j + 3] = (uint8_t) ((input[i] >> 24) & 0xff);
}
}
/*
- * Decodes input (uint8) into output (uint32). Assumes len is a multiple of 4.
+ * Decodes input (uint8_t) into output (uint32_t). Assumes len is a multiple of 4.
*/
static void
-md5_Decode(uint32 * output, uint8 * input, int len)
+md5_Decode(uint32_t * output, uint8_t * input, int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
- output[i] = ((uint32) input[j]) |
- (((uint32) input[j + 1]) << 8) |
- (((uint32) input[j + 2]) << 16) |
- (((uint32) input[j + 3]) << 24);
+ output[i] = ((uint32_t) input[j]) |
+ (((uint32_t) input[j + 1]) << 8) |
+ (((uint32_t) input[j + 2]) << 16) |
+ (((uint32_t) input[j + 3]) << 24);
}
}
@@ -156,9 +156,9 @@ md5_Decode(uint32 * output, uint8 * input, int len)
* MD5 basic transformation. Transforms state based on block.
*/
static void
-md5_Transform(uint32 state[4], uint8 block[64])
+md5_Transform(uint32_t state[4], uint8_t block[64])
{
- uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+ uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
md5_Decode(x, block, 64);
@@ -263,7 +263,7 @@ md5_Init(md5ctx_t * context)
* processing another message block, and updating the context.
*/
void
-md5_Update(md5ctx_t * context, uint8 * buf, int len)
+md5_Update(md5ctx_t * context, uint8_t * buf, int len)
{
unsigned int i, index, partLen;
@@ -271,9 +271,9 @@ md5_Update(md5ctx_t * context, uint8 * buf, int len)
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((uint32) len << 3)) < ((uint32) len << 3))
+ if ((context->count[0] += ((uint32_t) len << 3)) < ((uint32_t) len << 3))
context->count[1]++;
- context->count[1] += ((uint32) len >> 29);
+ context->count[1] += ((uint32_t) len >> 29);
partLen = 64 - index;
@@ -299,9 +299,9 @@ md5_Update(md5ctx_t * context, uint8 * buf, int len)
* the message digest and zeroizing the context.
*/
void
-md5_Final(md5ctx_t * context, uint8 digest[16])
+md5_Final(md5ctx_t * context, uint8_t digest[16])
{
- uint8 bits[8];
+ uint8_t bits[8];
unsigned int index, padLen;
/* Save number of bits */
diff --git a/md5.h b/md5.h
index 444054b..e6c36c4 100644
--- a/md5.h
+++ b/md5.h
@@ -49,19 +49,16 @@
#include "config.h"
-typedef unsigned char uint8;
-typedef unsigned32 uint32;
-
/* MD5 context. */
typedef struct {
- uint32 state[4]; /* state (ABCD) */
- uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
- uint8 buffer[64]; /* input buffer */
+ uint32_t state[4]; /* state (ABCD) */
+ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ uint8_t buffer[64]; /* input buffer */
} md5ctx_t;
void md5_Init(md5ctx_t * context);
-void md5_Update(md5ctx_t * context, uint8 * buf, int len);
-void md5_Final(md5ctx_t * context, uint8 digest[16]);
+void md5_Update(md5ctx_t * context, uint8_t * buf, int len);
+void md5_Final(md5ctx_t * context, uint8_t digest[16]);
#endif
diff --git a/my-math.h b/my-math.h
index ca3d37d..f95e072 100644
--- a/my-math.h
+++ b/my-math.h
@@ -20,8 +20,13 @@
#include <float.h>
#include <math.h>
+#include <limits.h>
-#define IS_REAL(x) (-DBL_MAX <= (x) && (x) <= DBL_MAX)
+#define IS_REAL(x) (-HUGE_VAL < (x) && (x) < HUGE_VAL)
+
+#ifndef DECIMAL_DIG
+# define DECIMAL_DIG (DBL_DIG+4)
+#endif
#endif
diff --git a/my-stdio.h b/my-stdio.h
index 58060bd..8a4feb0 100644
--- a/my-stdio.h
+++ b/my-stdio.h
@@ -20,6 +20,7 @@
#include "config.h"
+#include <stdarg.h>
#include <stdio.h>
#if NDECL_FCLOSE
diff --git a/my-time.h b/my-time.h
index 6db883b..240e4fe 100644
--- a/my-time.h
+++ b/my-time.h
@@ -33,6 +33,8 @@
extern time_t time(time_t *);
#endif
+#include <sys/time.h>
+
#if defined(MACH) && defined(CMU)
/* These clowns blew the declaration of strftime() in their <time.h> */
#undef HAVE_STRFTIME
diff --git a/name_lookup.c b/name_lookup.c
index f775621..32cbf39 100644
--- a/name_lookup.c
+++ b/name_lookup.c
@@ -183,10 +183,10 @@ lookup(int to_intermediary, int from_intermediary)
*/
e = gethostbyname((void *) buffer);
cancel_timer(id);
- if (e && e->h_length == sizeof(unsigned32))
+ if (e && e->h_length == sizeof(uint32_t))
write(to_intermediary, e->h_addr_list[0], e->h_length);
else {
- unsigned32 addr;
+ uint32_t addr;
/* This cast is for the same reason as the one above... */
addr = inet_addr((void *) buffer);
@@ -239,7 +239,7 @@ intermediary(int to_server, int from_server)
static char *buffer = 0;
static int buflen = 0;
int len;
- unsigned32 addr;
+ uint32_t addr;
set_server_cmdline("(MOO name-lookup master)");
signal(SIGPIPE, SIG_IGN);
@@ -348,7 +348,7 @@ lookup_name_from_addr(struct sockaddr_in *addr, unsigned timeout)
{
static char decimal[20];
- unsigned32 a = ntohl(addr->sin_addr.s_addr);
+ uint32_t a = ntohl(addr->sin_addr.s_addr);
sprintf(decimal, "%u.%u.%u.%u",
(unsigned) (a >> 24) & 0xff, (unsigned) (a >> 16) & 0xff,
@@ -357,11 +357,11 @@ lookup_name_from_addr(struct sockaddr_in *addr, unsigned timeout)
}
}
-unsigned32
+uint32_t
lookup_addr_from_name(const char *name, unsigned timeout)
{
struct request req;
- unsigned32 addr = 0;
+ uint32_t addr = 0;
if (dead_intermediary) {
/* Numeric addresses should always work... */
diff --git a/name_lookup.h b/name_lookup.h
index b5b30c2..3158549 100644
--- a/name_lookup.h
+++ b/name_lookup.h
@@ -31,8 +31,8 @@ extern int initialize_name_lookup(void);
* this succeeds.
*/
-extern unsigned32 lookup_addr_from_name(const char *name,
- unsigned timeout);
+extern uint32_t lookup_addr_from_name(const char *name,
+ unsigned timeout);
/* Translate a host name to a 32-bit
* internet address in host byte order. If
* anything goes wrong, return 0. Dotted
diff --git a/numbers.c b/numbers.c
index 387cba4..6545ac3 100644
--- a/numbers.c
+++ b/numbers.c
@@ -17,7 +17,6 @@
#include <limits.h>
#include <errno.h>
-#include <float.h>
#include "my-math.h"
#include "my-stdlib.h"
#include "my-string.h"
@@ -31,15 +30,17 @@
#include "structures.h"
#include "utils.h"
+#include "bf_register.h"
+
static int
-parse_number(const char *str, int *result, int try_floating_point)
+parse_number(const char *str, Num *result, int try_floating_point)
{
char *p;
- *result = strtol(str, &p, 10);
+ *result = (Num) strtoimax(str, &p, 10);
if (try_floating_point &&
(p == str || *p == '.' || *p == 'e' || *p == 'E'))
- *result = (int) strtod(str, &p);
+ *result = (Num) strtod(str, &p);
if (p == str)
return 0;
while (*p) {
@@ -53,7 +54,7 @@ parse_number(const char *str, int *result, int try_floating_point)
static int
parse_object(const char *str, Objid * result)
{
- int number;
+ Num number;
while (*str && *str == ' ')
str++;
@@ -92,7 +93,7 @@ parse_float(const char *str, double *result)
}
enum error
-become_integer(Var in, int *ret, int called_from_tonum)
+become_integer(Var in, Num *ret, int called_from_tonum)
{
switch (in.type) {
case TYPE_INT:
@@ -111,9 +112,9 @@ become_integer(Var in, int *ret, int called_from_tonum)
*ret = in.v.err;
break;
case TYPE_FLOAT:
- if (*in.v.fnum < (double) INT_MIN || *in.v.fnum > (double) INT_MAX)
+ if (!IS_REAL(in.v.fnum))
return E_FLOAT;
- *ret = (int) *in.v.fnum;
+ *ret = (Num) in.v.fnum;
break;
case TYPE_LIST:
return E_TYPE;
@@ -141,7 +142,7 @@ become_float(Var in, double *ret)
*ret = (double) in.v.err;
break;
case TYPE_FLOAT:
- *ret = *in.v.fnum;
+ *ret = in.v.fnum;
break;
case TYPE_LIST:
return E_TYPE;
@@ -151,18 +152,6 @@ become_float(Var in, double *ret)
return E_NONE;
}
-Var
-new_float(double d)
-{
- Var v;
-
- v.type = TYPE_FLOAT;
- v.v.fnum = mymalloc(sizeof(double), M_FLOAT);
- *v.v.fnum = d;
-
- return v;
-}
-
#if COERCION_IS_EVER_IMPLEMENTED_AND_DESIRED
static int
to_float(Var v, double *dp)
@@ -220,18 +209,18 @@ do_equals(Var lhs, Var rhs)
if (lhs.type != rhs.type)
return 0;
else
- return *lhs.v.fnum == *rhs.v.fnum;
+ return lhs.v.fnum == rhs.v.fnum;
}
int
-compare_integers(int a, int b)
+compare_integers(Num a, Num b)
{
if (a < b)
return -1;
- else if (a == b)
- return 0;
- else
+ else if (a > b)
return 1;
+ else
+ return 0;
}
Var
@@ -244,17 +233,20 @@ compare_numbers(Var a, Var b)
ans.v.err = E_TYPE;
} else if (a.type == TYPE_INT) {
ans.type = TYPE_INT;
- ans.v.num = compare_integers(a.v.num, b.v.num);
+ if (a.v.num < b.v.num)
+ ans.v.num = -1;
+ else if (a.v.num > b.v.num)
+ ans.v.num = 1;
+ else
+ ans.v.num = 0;
} else {
- double aa = *a.v.fnum, bb = *b.v.fnum;
-
ans.type = TYPE_INT;
- if (aa < bb)
+ if (a.v.fnum < b.v.fnum)
ans.v.num = -1;
- else if (aa == bb)
- ans.v.num = 0;
- else
+ else if (a.v.fnum > b.v.fnum)
ans.v.num = 1;
+ else
+ ans.v.num = 0;
}
return ans;
@@ -273,13 +265,15 @@ compare_numbers(Var a, Var b)
ans.type = TYPE_INT; \
ans.v.num = a.v.num op b.v.num; \
} else { \
- double d = *a.v.fnum op *b.v.fnum; \
+ double d = a.v.fnum op b.v.fnum; \
\
if (!IS_REAL(d)) { \
ans.type = TYPE_ERR; \
ans.v.err = E_FLOAT; \
- } else \
- ans = new_float(d); \
+ } else { \
+ ans.type = TYPE_FLOAT; \
+ ans.v.fnum = d; \
+ } \
} \
\
return ans; \
@@ -302,14 +296,16 @@ SIMPLE_BINARY(multiply, *)
ans.type = TYPE_INT; \
ans.v.num = a.v.num iop b.v.num; \
} else if (a.type == TYPE_FLOAT \
- && *b.v.fnum != 0.0) { \
+ && b.v.fnum != 0.0) { \
double d = fexpr; \
\
if (!IS_REAL(d)) { \
ans.type = TYPE_ERR; \
ans.v.err = E_FLOAT; \
- } else \
- ans = new_float(d); \
+ } else { \
+ ans.type = TYPE_FLOAT; \
+ ans.v.fnum = d; \
+ } \
} else { \
ans.type = TYPE_ERR; \
ans.v.err = E_DIV; \
@@ -318,25 +314,25 @@ SIMPLE_BINARY(multiply, *)
return ans; \
}
-DIVISION_OP(divide, /, *a.v.fnum / *b.v.fnum)
-DIVISION_OP(modulus, %, fmod(*a.v.fnum, *b.v.fnum))
+DIVISION_OP(divide, /, a.v.fnum / b.v.fnum)
+DIVISION_OP(modulus, %, fmod(a.v.fnum, b.v.fnum))
Var
do_power(Var lhs, Var rhs)
{ /* LHS ^ RHS */
Var ans;
if (lhs.type == TYPE_INT) { /* integer exponentiation */
- int a = lhs.v.num, b, r;
+ Num a = lhs.v.num, b, r;
if (rhs.type != TYPE_INT)
goto type_error;
b = rhs.v.num;
ans.type = TYPE_INT;
- if (b < 0)
+ if (b < 0) {
switch (a) {
case -1:
- ans.v.num = (b % 2 == 0 ? 1 : -1);
+ ans.v.num = (b & 1) ? 1 : -1;
break;
case 0:
ans.type = TYPE_ERR;
@@ -347,10 +343,12 @@ do_power(Var lhs, Var rhs)
break;
default:
ans.v.num = 0;
+ break;
+ }
} else {
r = 1;
while (b != 0) {
- if (b % 2 != 0)
+ if (b & 1)
r *= a;
a *= a;
b >>= 1;
@@ -365,18 +363,20 @@ do_power(Var lhs, Var rhs)
d = (double) rhs.v.num;
break;
case TYPE_FLOAT:
- d = *rhs.v.fnum;
+ d = rhs.v.fnum;
break;
default:
goto type_error;
}
errno = 0;
- d = pow(*lhs.v.fnum, d);
+ d = pow(lhs.v.fnum, d);
if (errno != 0 || !IS_REAL(d)) {
ans.type = TYPE_ERR;
ans.v.err = E_FLOAT;
- } else
- ans = new_float(d);
+ } else {
+ ans.type = TYPE_FLOAT;
+ ans.v.fnum = d;
+ }
} else
goto type_error;
@@ -412,15 +412,14 @@ bf_tofloat(Var arglist, Byte next, void *vdata, Objid progr)
Var r;
enum error e;
- r = new_float(0.0);
- e = become_float(arglist.v.list[1], r.v.fnum);
+ r.type = TYPE_FLOAT;
+ e = become_float(arglist.v.list[1], &r.v.fnum);
free_var(arglist);
- if (e == E_NONE)
- return make_var_pack(r);
+ if (e != E_NONE)
+ return make_error_pack(e);
- free_var(r);
- return make_error_pack(e);
+ return make_var_pack(r);
}
static package
@@ -441,7 +440,7 @@ bf_min(Var arglist, Byte next, void *vdata, Objid progr)
for (i = 2; i <= nargs; i++)
if (arglist.v.list[i].type != TYPE_FLOAT)
bad_types = 1;
- else if (*arglist.v.list[i].v.fnum < *r.v.fnum)
+ else if (arglist.v.list[i].v.fnum < r.v.fnum)
r = arglist.v.list[i];
}
@@ -471,7 +470,7 @@ bf_max(Var arglist, Byte next, void *vdata, Objid progr)
for (i = 2; i <= nargs; i++)
if (arglist.v.list[i].type != TYPE_FLOAT)
bad_types = 1;
- else if (*arglist.v.list[i].v.fnum > *r.v.fnum)
+ else if (arglist.v.list[i].v.fnum > r.v.fnum)
r = arglist.v.list[i];
}
@@ -493,7 +492,7 @@ bf_abs(Var arglist, Byte next, void *vdata, Objid progr)
if (r.v.num < 0)
r.v.num = -r.v.num;
} else
- *r.v.fnum = fabs(*r.v.fnum);
+ r.v.fnum = fabs(r.v.fnum);
free_var(arglist);
return make_var_pack(r);
@@ -503,18 +502,17 @@ bf_abs(Var arglist, Byte next, void *vdata, Objid progr)
static package \
bf_ ## name(Var arglist, Byte next, void *vdata, Objid progr) \
{ \
- double d; \
+ double d; \
\
- d = *arglist.v.list[1].v.fnum; \
errno = 0; \
- d = name(d); \
+ d = name (arglist.v.list[1].v.fnum); \
free_var(arglist); \
if (errno == EDOM) \
return make_error_pack(E_INVARG); \
- else if (errno != 0 || !IS_REAL(d)) \
+ else if (errno != 0 || !IS_REAL(d)) \
return make_error_pack(E_FLOAT); \
else \
- return make_var_pack(new_float(d)); \
+ return make_float_pack(d); \
}
MATH_FUNC(sqrt)
@@ -526,17 +524,26 @@ MATH_FUNC(acos)
MATH_FUNC(sinh)
MATH_FUNC(cosh)
MATH_FUNC(tanh)
+MATH_FUNC(asinh)
+MATH_FUNC(acosh)
+MATH_FUNC(atanh)
MATH_FUNC(exp)
MATH_FUNC(log)
MATH_FUNC(log10)
MATH_FUNC(ceil)
MATH_FUNC(floor)
- static package
- bf_trunc(Var arglist, Byte next, void *vdata, Objid progr)
+MATH_FUNC(expm1)
+MATH_FUNC(log1p)
+MATH_FUNC(erf)
+MATH_FUNC(erfc)
+MATH_FUNC(lgamma)
+
+static package
+bf_trunc(Var arglist, Byte next, void *vdata, Objid progr)
{
double d;
- d = *arglist.v.list[1].v.fnum;
+ d = arglist.v.list[1].v.fnum;
errno = 0;
if (d < 0.0)
d = ceil(d);
@@ -548,7 +555,7 @@ MATH_FUNC(floor)
else if (errno != 0 || !IS_REAL(d))
return make_error_pack(E_FLOAT);
else
- return make_var_pack(new_float(d));
+ return make_float_pack(d);
}
static package
@@ -556,10 +563,10 @@ bf_atan(Var arglist, Byte next, void *vdata, Objid progr)
{
double d, dd;
- d = *arglist.v.list[1].v.fnum;
+ d = arglist.v.list[1].v.fnum;
errno = 0;
if (arglist.v.list[0].v.num >= 2) {
- dd = *arglist.v.list[2].v.fnum;
+ dd = arglist.v.list[2].v.fnum;
d = atan2(d, dd);
} else
d = atan(d);
@@ -569,17 +576,84 @@ bf_atan(Var arglist, Byte next, void *vdata, Objid progr)
else if (errno != 0 || !IS_REAL(d))
return make_error_pack(E_FLOAT);
else
- return make_var_pack(new_float(d));
+ return make_float_pack(d);
+}
+
+static package
+bf_j(Var arglist, Byte next, void *vdata, Objid progr)
+{
+ double d;
+
+ d = arglist.v.list[2].v.fnum;
+ errno = 0;
+ switch ( arglist.v.list[1].v.num ) {
+ case 0:
+ d = j0(d);
+ break;
+ case 1:
+ d = j1(d);
+ break;
+ default:
+ d = jn(d, arglist.v.list[1].v.num);
+ break;
+ }
+ free_var(arglist);
+ if (errno == EDOM)
+ return make_error_pack(E_INVARG);
+ else if (errno != 0 || !IS_REAL(d))
+ return make_error_pack(E_FLOAT);
+ else
+ return make_float_pack(d);
+}
+
+static package
+bf_y(Var arglist, Byte next, void *vdata, Objid progr)
+{
+ double d;
+
+ d = arglist.v.list[2].v.fnum;
+ errno = 0;
+ switch ( arglist.v.list[1].v.num ) {
+ case 0:
+ d = y0(d);
+ break;
+ case 1:
+ d = y1(d);
+ break;
+ default:
+ d = jn(d, arglist.v.list[1].v.num);
+ break;
+ }
+ free_var(arglist);
+ if (errno == EDOM)
+ return make_error_pack(E_INVARG);
+ else if (errno != 0 || !IS_REAL(d))
+ return make_error_pack(E_FLOAT);
+ else
+ return make_float_pack(d);
}
static package
bf_time(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
- r.type = TYPE_INT;
- r.v.num = time(0);
free_var(arglist);
- return make_var_pack(r);
+ return make_int_pack(time(0));
+}
+
+static package
+bf_ftime(Var arglist, Byte next, void *vdata, Objid progr)
+{
+ double t;
+ struct timeval tv;
+
+ free_var(arglist);
+
+ gettimeofday(&tv, NULL);
+
+ /* Use division since 1.0e-6 isn't representable in exact binary */
+ t = (double)tv.tv_sec + (double)tv.tv_usec/1.0e+6;
+
+ return make_float_pack(t);
}
static package
@@ -587,17 +661,24 @@ bf_ctime(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
time_t c;
- char buffer[50];
-
- if (arglist.v.list[0].v.num == 1) {
- c = arglist.v.list[1].v.num;
- } else {
- c = time(0);
+ char buffer[128];
+ int has_time = (arglist.v.list[0].v.num >= 1);
+ int has_timezone = (arglist.v.list[0].v.num >= 2);
+ char *current_timezone = NULL;
+
+ c = has_time ? (time_t)arglist.v.list[1].v.num : time(0);
+
+ if (has_timezone) {
+ current_timezone = getenv("TZ");
+ if ( current_timezone )
+ current_timezone = str_dup(current_timezone);
+ setenv("TZ", arglist.v.list[2].v.str, 1);
+ tzset();
}
-
+
{ /* Format the time, including a timezone name */
#if HAVE_STRFTIME
- strftime(buffer, 50, "%a %b %d %H:%M:%S %Y %Z", localtime(&c));
+ strftime(buffer, 128, "%a %b %d %H:%M:%S %Y %Z", localtime(&c));
#else
# if HAVE_TM_ZONE
struct tm *t = localtime(&c);
@@ -615,6 +696,16 @@ bf_ctime(Var arglist, Byte next, void *vdata, Objid progr)
#endif
}
+ if (has_timezone) {
+ if (current_timezone) {
+ setenv("TZ", current_timezone, 1);
+ free_str(current_timezone);
+ } else {
+ unsetenv("TZ");
+ }
+ tzset();
+ }
+
if (buffer[8] == '0')
buffer[8] = ' ';
r.type = TYPE_STR;
@@ -649,7 +740,7 @@ bf_random(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_floatstr(Var arglist, Byte next, void *vdata, Objid progr)
{ /* (float, precision [, sci-notation]) */
- double d = *arglist.v.list[1].v.fnum;
+ double d = arglist.v.list[1].v.fnum;
int prec = arglist.v.list[2].v.num;
int use_sci = (arglist.v.list[0].v.num >= 3
&& is_true(arglist.v.list[3]));
@@ -657,8 +748,8 @@ bf_floatstr(Var arglist, Byte next, void *vdata, Objid progr)
Var r;
free_var(arglist);
- if (prec > DBL_DIG + 4)
- prec = DBL_DIG + 4;
+ if (prec > DECIMAL_DIG)
+ prec = DECIMAL_DIG;
else if (prec < 0)
return make_error_pack(E_INVARG);
sprintf(fmt, "%%.%d%c", prec, use_sci ? 'e' : 'f');
@@ -685,7 +776,8 @@ register_numbers(void)
register_function("abs", 1, 1, bf_abs, TYPE_NUMERIC);
register_function("random", 0, 1, bf_random, TYPE_INT);
register_function("time", 0, 0, bf_time);
- register_function("ctime", 0, 1, bf_ctime, TYPE_INT);
+ register_function("ftime", 0, 0, bf_ftime);
+ register_function("ctime", 0, 2, bf_ctime, TYPE_INT, TYPE_STR);
register_function("floatstr", 2, 3, bf_floatstr,
TYPE_FLOAT, TYPE_INT, TYPE_ANY);
@@ -699,12 +791,22 @@ register_numbers(void)
register_function("sinh", 1, 1, bf_sinh, TYPE_FLOAT);
register_function("cosh", 1, 1, bf_cosh, TYPE_FLOAT);
register_function("tanh", 1, 1, bf_tanh, TYPE_FLOAT);
+ register_function("asinh", 1, 1, bf_asinh, TYPE_FLOAT);
+ register_function("acosh", 1, 1, bf_acosh, TYPE_FLOAT);
+ register_function("atanh", 1, 1, bf_atanh, TYPE_FLOAT);
register_function("exp", 1, 1, bf_exp, TYPE_FLOAT);
register_function("log", 1, 1, bf_log, TYPE_FLOAT);
register_function("log10", 1, 1, bf_log10, TYPE_FLOAT);
register_function("ceil", 1, 1, bf_ceil, TYPE_FLOAT);
register_function("floor", 1, 1, bf_floor, TYPE_FLOAT);
register_function("trunc", 1, 1, bf_trunc, TYPE_FLOAT);
+ register_function("expm1", 1, 1, bf_expm1, TYPE_FLOAT);
+ register_function("log1p", 1, 1, bf_log1p, TYPE_FLOAT);
+ register_function("erf", 1, 1, bf_erf, TYPE_FLOAT);
+ register_function("erfc", 1, 1, bf_erfc, TYPE_FLOAT);
+ register_function("lgamma", 1, 1, bf_lgamma, TYPE_FLOAT);
+ register_function("j", 2, 2, bf_j, TYPE_INT, TYPE_FLOAT);
+ register_function("y", 2, 2, bf_y, TYPE_INT, TYPE_FLOAT);
}
char rcsid_numbers[] = "$Id$";
diff --git a/numbers.h b/numbers.h
index 6e833c5..306f496 100644
--- a/numbers.h
+++ b/numbers.h
@@ -18,10 +18,10 @@
#include "structures.h"
extern Var new_float(double);
-extern enum error become_integer(Var, int *, int);
+extern enum error become_integer(Var, Num *, int);
extern int do_equals(Var, Var);
-extern int compare_integers(int, int);
+extern int compare_integers(Num, Num);
extern Var compare_numbers(Var, Var);
extern Var do_add(Var, Var);
diff --git a/objects.c b/objects.c
index 981a839..24cf4bd 100644
--- a/objects.c
+++ b/objects.c
@@ -167,7 +167,7 @@ bf_move_write(void *vdata)
{
struct bf_move_data *data = vdata;
- dbio_printf("bf_move data: what = %d, where = %d\n",
+ dbio_printf("bf_move data: what = %"PRIdN", where = %"PRIdN"\n",
data->what, data->where);
}
@@ -176,7 +176,7 @@ bf_move_read()
{
struct bf_move_data *data = alloc_data(sizeof(*data));
- if (dbio_scanf("bf_move data: what = %d, where = %d\n",
+ if (dbio_scanf("bf_move data: what = %"PRIdN", where = %"PRIdN"\n",
&data->what, &data->where) == 2)
return data;
else
@@ -187,7 +187,7 @@ static package
bf_toobj(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
- int i;
+ Num i;
enum error e;
r.type = TYPE_OBJ;
@@ -295,7 +295,7 @@ bf_create(Var arglist, Byte next, void *vdata, Objid progr)
static void
bf_create_write(void *vdata)
{
- dbio_printf("bf_create data: oid = %d\n", *((Objid *) vdata));
+ dbio_printf("bf_create data: oid = %"PRIdN"\n", *((Objid *) vdata));
}
static void *
@@ -303,7 +303,7 @@ bf_create_read(void)
{
Objid *data = alloc_data(sizeof(Objid));
- if (dbio_scanf("bf_create data: oid = %d\n", data) == 1)
+ if (dbio_scanf("bf_create data: oid = %"PRIdN"\n", data) == 1)
return data;
else
return 0;
@@ -502,7 +502,7 @@ bf_recycle_write(void *vdata)
{
Objid *data = vdata;
- dbio_printf("bf_recycle data: oid = %d, cont = 0\n", *data);
+ dbio_printf("bf_recycle data: oid = %"PRIdN", cont = 0\n", *data);
}
static void *
@@ -517,7 +517,7 @@ bf_recycle_read(void)
* suppressed assignments are not counted in determining the returned value
* of `scanf'...
*/
- if (dbio_scanf("bf_recycle data: oid = %d, cont = %d\n",
+ if (dbio_scanf("bf_recycle data: oid = %"PRIdN", cont = %d\n",
data, &dummy) == 2)
return data;
else
diff --git a/opcode.h b/opcode.h
index 8eb09f4..504f46a 100644
--- a/opcode.h
+++ b/opcode.h
@@ -104,7 +104,7 @@ enum Opcode {
#define PUT_n_INDEX(o) ((o) - OP_PUT)
#define IS_OPTIM_NUM_OPCODE(o) ((o) >= (unsigned) OPTIM_NUM_START)
-#define OPCODE_TO_OPTIM_NUM(o) ((o) - OPTIM_NUM_START + OPTIM_NUM_LOW)
+#define OPCODE_TO_OPTIM_NUM(o) ((Num)(unsigned)(o) - OPTIM_NUM_START + OPTIM_NUM_LOW)
#define OPTIM_NUM_TO_OPCODE(i) (OPTIM_NUM_START + (i) - OPTIM_NUM_LOW)
#define IN_OPTIM_NUM_RANGE(i) ((i) >= OPTIM_NUM_LOW && (i) <= OPTIM_NUM_HI)
diff --git a/parser.y b/parser.y
index 4e6bb14..86ae5f4 100644
--- a/parser.y
+++ b/parser.y
@@ -42,7 +42,7 @@
#include "structures.h"
#include "sym_table.h"
#include "utils.h"
-#include "version.h"
+#include "version.h"
static Stmt *prog_start;
static int dollars_ok;
@@ -69,9 +69,9 @@ static void check_loop_name(const char *, enum loop_exit_kind);
%union {
Stmt *stmt;
Expr *expr;
- int integer;
+ Num integer;
Objid object;
- double *real;
+ double real;
char *string;
enum error error;
Arg_List *args;
@@ -546,7 +546,7 @@ expr:
$2->e.var.v.num = -$2->e.var.v.num;
break;
case TYPE_FLOAT:
- *($2->e.var.v.fnum) = - (*($2->e.var.v.fnum));
+ $2->e.var.v.fnum = -$2->e.var.v.fnum;
break;
default:
break;
@@ -827,7 +827,7 @@ start_over:
}
if (isdigit(c) || (c == '.' && language_version >= DBV_Float)) {
- int n = 0;
+ Num n = 0;
int type = tINTEGER;
while (isdigit(c)) {
@@ -890,7 +890,7 @@ start_over:
yyerror("Floating-point literal out of range");
d = 0.0;
}
- yylval.real = alloc_float(d);
+ yylval.real = d;
}
return type;
}
diff --git a/program.h b/program.h
index 2a28567..d90dab7 100644
--- a/program.h
+++ b/program.h
@@ -21,7 +21,7 @@
#include "structures.h"
#include "version.h"
-typedef unsigned char Byte;
+typedef uint8_t Byte;
typedef struct {
Byte numbytes_label, numbytes_literal, numbytes_fork, numbytes_var_name,
diff --git a/server.c b/server.c
index a0fab78..2c50274 100644
--- a/server.c
+++ b/server.c
@@ -137,10 +137,10 @@ static int
start_listener(slistener * l)
{
if (network_listen(l->nlistener)) {
- oklog("LISTEN: #%d now listening on %s\n", l->oid, l->name);
+ oklog("LISTEN: #%"PRIdN" now listening on %s\n", l->oid, l->name);
return 1;
} else {
- errlog("LISTEN: Can't start #%d listening on %s!\n", l->oid, l->name);
+ errlog("LISTEN: Can't start #%"PRIdN" listening on %s!\n", l->oid, l->name);
return 0;
}
}
@@ -149,7 +149,7 @@ static void
free_slistener(slistener * l)
{
network_close_listener(l->nlistener);
- oklog("UNLISTEN: #%d no longer listening on %s\n", l->oid, l->name);
+ oklog("UNLISTEN: #%"PRIdN" no longer listening on %s\n", l->oid, l->name);
*(l->prev) = l->next;
if (l->next)
@@ -359,9 +359,9 @@ object_name(Objid oid)
s = new_stream(30);
if (valid(oid))
- stream_printf(s, "%s (#%d)", db_object_name(oid), oid);
+ stream_printf(s, "%s (#%"PRIdN")", db_object_name(oid), oid);
else
- stream_printf(s, "#%d", oid);
+ stream_printf(s, "#%"PRIdN"", oid);
return reset_stream(s);
}
@@ -490,7 +490,7 @@ main_loop(void)
: (now - h->last_activity_time
> DEFAULT_CONNECT_TIMEOUT))) {
call_notifier(h->player, h->listener, "user_disconnected");
- oklog("TIMEOUT: #%d on %s\n",
+ oklog("TIMEOUT: #%"PRIdN" on %s\n",
h->player,
network_connection_name(h->nhandle));
if (h->print_messages)
@@ -500,7 +500,7 @@ main_loop(void)
network_close(h->nhandle);
free_shandle(h);
} else if (h->connection_time != 0 && !valid(h->player)) {
- oklog("RECYCLED: #%d on %s\n",
+ oklog("RECYCLED: #%"PRIdN" on %s\n",
h->player,
network_connection_name(h->nhandle));
if (h->print_messages)
@@ -618,7 +618,7 @@ read_stdin_line()
static void
emergency_notify(Objid player, const char *line)
{
- printf("#%d <- %s\n", player, line);
+ printf("#%"PRIdN" <- %s\n", player, line);
}
static int
@@ -647,7 +647,7 @@ emergency_mode()
Objid first_valid = -1;
if (wizard >= 0)
- printf("** Object #%d is not a wizard...\n", wizard);
+ printf("** Object #%"PRIdN" is not a wizard...\n", wizard);
for (wizard = 0; wizard <= db_last_used_objid(); wizard++)
if (is_wizard(wizard))
@@ -658,16 +658,16 @@ emergency_mode()
if (!is_wizard(wizard)) {
if (first_valid < 0) {
first_valid = db_create_object();
- printf("** No objects in database; created #%d.\n",
+ printf("** No objects in database; created #%"PRIdN".\n",
first_valid);
}
wizard = first_valid;
db_set_object_flag(wizard, FLAG_WIZARD);
- printf("** No wizards in database; wizzed #%d.\n", wizard);
+ printf("** No wizards in database; wizzed #%"PRIdN".\n", wizard);
}
- printf("** Now running emergency commands as #%d ...\n", wizard);
+ printf("** Now running emergency commands as #%"PRIdN" ...\n", wizard);
}
- printf("\nMOO (#%d)%s: ", wizard, debug ? "" : "[!d]");
+ printf("\nMOO (#%"PRIdN")%s: ", wizard, debug ? "" : "[!d]");
line = read_stdin_line();
if (!line)
@@ -820,8 +820,8 @@ emergency_mode()
} else if (!mystrcasecmp(command, "debug") && nargs == 0) {
debug = !debug;
} else if (!mystrcasecmp(command, "wizard") && nargs == 1
- && sscanf(words.v.list[2].v.str, "#%d", &wizard) == 1) {
- printf("** Switching to wizard #%d...\n", wizard);
+ && sscanf(words.v.list[2].v.str, "#%"PRIdN"", &wizard) == 1) {
+ printf("** Switching to wizard #%"PRIdN"...\n", wizard);
} else {
if (mystrcasecmp(command, "help")
&& mystrcasecmp(command, "?"))
@@ -973,7 +973,7 @@ server_new_connection(server_listener sl, network_handle nh, int outbound)
task_suspend_input(h->tasks);
}
- oklog("%s: #%d on %s\n",
+ oklog("%s: #%"PRIdN" on %s\n",
outbound ? "CONNECT" : "ACCEPT",
h->player, network_connection_name(nh));
diff --git a/storage.c b/storage.c
index bf369d8..127091e 100644
--- a/storage.c
+++ b/storage.c
@@ -16,6 +16,7 @@
*****************************************************************************/
#include "my-stdlib.h"
+#include "my-string.h"
#include "config.h"
#include "exceptions.h"
diff --git a/str_intern.c b/str_intern.c
index 78c6413..92ae8c9 100644
--- a/str_intern.c
+++ b/str_intern.c
@@ -1,4 +1,5 @@
#include "my-stdlib.h"
+#include "my-string.h"
#include "log.h"
#include "storage.h"
diff --git a/streams.c b/streams.c
index a3b8ef0..8e9f02d 100644
--- a/streams.c
+++ b/streams.c
@@ -81,129 +81,28 @@ stream_add_string(Stream * s, const char *string)
s->current += len;
}
-static const char *
-itoa(int n, int radix)
-{
- if (n == 0) /* zero produces "" below. */
- return "0";
- else if (n == -2147483647 - 1) /* min. integer won't work below. */
- switch (radix) {
- case 16:
- return "-7FFFFFFF";
- case 10:
- return "-2147483648";
- case 8:
- return "-17777777777";
- default:
- errlog("STREAM_PRINTF: Illegal radix %d!\n", radix);
- return "0";
- } else {
- static char buffer[20];
- char *ptr = buffer + 19;
- int neg = 0;
-
- if (n < 0) {
- neg = 1;
- n = -n;
- }
- *(ptr) = '\0';
- while (n != 0) {
- int digit = n % radix;
- *(--ptr) = (digit < 10 ? '0' + digit : 'A' + digit - 10);
- n /= radix;
- }
- if (neg)
- *(--ptr) = '-';
- return ptr;
- }
-}
-
-static const char *
-dbl_fmt(void)
-{
- static const char *fmt = 0;
- static char buffer[10];
-
- if (!fmt) {
- sprintf(buffer, "%%.%dg", DBL_DIG);
- fmt = buffer;
- }
- return fmt;
-}
-
void
stream_printf(Stream * s, const char *fmt,...)
{
- char buffer[40];
- va_list args;
+ va_list args, pargs;
+ int len;
va_start(args, fmt);
- while (*fmt) {
- char c = *fmt;
-
- if (c == '%') {
- char pad = ' ';
- int width = 0, base;
- const char *string = ""; /* initialized to silence warning */
- while ((c = *(++fmt)) != '\0') {
- switch (c) {
- case 's':
- string = va_arg(args, char *);
- break;
- case 'x':
- base = 16;
- goto finish_number;
- case 'o':
- base = 8;
- goto finish_number;
- case 'd':
- base = 10;
- finish_number:
- string = itoa(va_arg(args, int), base);
- break;
- case 'g':
- sprintf(buffer, dbl_fmt(), va_arg(args, double));
- if (!strchr(buffer, '.') && !strchr(buffer, 'e'))
- strcat(buffer, ".0"); /* make it look floating */
- string = buffer;
- break;
- case '0':
- if (width == 0) {
- pad = '0';
- continue;
- }
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- width = width * 10 + c - '0';
- continue;
- default:
- errlog("STREAM_PRINTF: Unknown format directive: %%%c\n",
- c);
- goto abort;
- }
- break;
- }
+ va_copy(pargs, args);
+ len = vsnprintf(s->buffer + s->current, s->buflen - s->current, fmt, pargs);
+ va_end(pargs);
- if (width && (width -= strlen(string)) > 0)
- while (width--)
- stream_add_char(s, pad);
- stream_add_string(s, string);
- } else
- stream_add_char(s, *fmt);
+ if (s->current + len >= s->buflen) {
+ int newlen = s->buflen * 2;
- fmt++;
+ if (newlen <= s->current + len)
+ newlen = s->current + len + 1;
+ grow(s, newlen);
+ len = vsnprintf(s->buffer + s->current, s->buflen - s->current, fmt, args);
}
-
- abort:
va_end(args);
+ s->current += len;
}
void
diff --git a/streams.h b/streams.h
index 699885f..f42ab42 100644
--- a/streams.h
+++ b/streams.h
@@ -30,7 +30,7 @@ extern Stream *new_stream(int size);
extern void stream_add_char(Stream *, char);
extern void stream_delete_char(Stream *);
extern void stream_add_string(Stream *, const char *);
-extern void stream_printf(Stream *, const char *,...);
+extern void stream_printf(Stream *, const char *,...) FORMAT(printf,2,3);
extern void free_stream(Stream *);
extern char *stream_contents(Stream *);
extern char *reset_stream(Stream *);
diff --git a/structures.h b/structures.h
index 1964e90..7f3c5ae 100644
--- a/structures.h
+++ b/structures.h
@@ -22,7 +22,12 @@
#include "config.h"
-typedef int32 Objid;
+/* Note: it's a pretty hard assumption in MOO that integers and objects
+ are the same data type. */
+typedef int64_t Num;
+#define PRIdN PRId64
+#define SCNdN SCNd64
+typedef Num Objid;
/*
* Special Objid's
@@ -94,11 +99,11 @@ typedef struct Var Var;
struct Var {
union {
const char *str; /* STR */
- int32 num; /* NUM, CATCH, FINALLY */
+ Num num; /* NUM, CATCH, FINALLY */
Objid obj; /* OBJ */
enum error err; /* ERR */
Var *list; /* LIST */
- double *fnum; /* FLOAT */
+ double fnum; /* FLOAT */
} v;
var_type type;
};
diff --git a/tasks.c b/tasks.c
index 6414a55..d2b21bb 100644
--- a/tasks.c
+++ b/tasks.c
@@ -1368,7 +1368,7 @@ write_forked_task(forked_task ft)
{
int lineno = find_line_number(ft.program, ft.f_index, 0);
- dbio_printf("0 %d %d %d\n", lineno, ft.start_time, ft.id);
+ dbio_printf("0 %d %ld %d\n", lineno, (long)ft.start_time, ft.id);
write_activ_as_pi(ft.a);
write_rt_env(ft.program->var_names, ft.rt_env, ft.program->num_var_names);
dbio_write_forked_program(ft.program, ft.f_index);
@@ -1377,7 +1377,7 @@ write_forked_task(forked_task ft)
static void
write_suspended_task(suspended_task st)
{
- dbio_printf("%d %d ", st.start_time, st.the_vm->task_id);
+ dbio_printf("%ld %d ", (long)st.start_time, st.the_vm->task_id);
dbio_write_var(st.value);
write_vm(st.the_vm);
}
diff --git a/timers.h b/timers.h
index e537b5a..c78230a 100644
--- a/timers.h
+++ b/timers.h
@@ -30,7 +30,7 @@ extern int cancel_timer(Timer_ID);
extern void reenable_timers(void);
extern unsigned timer_wakeup_interval(Timer_ID);
extern void timer_sleep(unsigned seconds);
-extern int virtual_timer_available();
+extern int virtual_timer_available(void);
#endif /* !Timers_H */
diff --git a/utils.c b/utils.c
index 2412a0d..27e695c 100644
--- a/utils.c
+++ b/utils.c
@@ -140,7 +140,7 @@ complex_free_var(Var v)
{
int i;
- switch ((int) v.type) {
+ switch (v.type) {
case TYPE_STR:
if (v.v.str)
free_str(v.v.str);
@@ -154,9 +154,7 @@ complex_free_var(Var v)
myfree(v.v.list, M_LIST);
}
break;
- case TYPE_FLOAT:
- if (delref(v.v.fnum) == 0)
- myfree(v.v.fnum, M_FLOAT);
+ default:
break;
}
}
@@ -164,15 +162,14 @@ complex_free_var(Var v)
Var
complex_var_ref(Var v)
{
- switch ((int) v.type) {
+ switch (v.type) {
case TYPE_STR:
addref(v.v.str);
break;
case TYPE_LIST:
addref(v.v.list);
break;
- case TYPE_FLOAT:
- addref(v.v.fnum);
+ default:
break;
}
return v;
@@ -184,7 +181,7 @@ complex_var_dup(Var v)
int i;
Var newlist;
- switch ((int) v.type) {
+ switch (v.type) {
case TYPE_STR:
v.v.str = str_dup(v.v.str);
break;
@@ -195,8 +192,7 @@ complex_var_dup(Var v)
}
v.v.list = newlist.v.list;
break;
- case TYPE_FLOAT:
- v = new_float(*v.v.fnum);
+ default:
break;
}
return v;
@@ -208,15 +204,14 @@ complex_var_dup(Var v)
int
var_refcount(Var v)
{
- switch ((int) v.type) {
+ switch (v.type) {
case TYPE_STR:
return refcount(v.v.str);
break;
case TYPE_LIST:
return refcount(v.v.list);
break;
- case TYPE_FLOAT:
- return refcount(v.v.fnum);
+ default:
break;
}
return 1;
@@ -226,7 +221,7 @@ int
is_true(Var v)
{
return ((v.type == TYPE_INT && v.v.num != 0)
- || (v.type == TYPE_FLOAT && *v.v.fnum != 0.0)
+ || (v.type == TYPE_FLOAT && v.v.fnum != 0.0)
|| (v.type == TYPE_STR && v.v.str && *v.v.str != '\0')
|| (v.type == TYPE_LIST && v.v.list[0].v.num != 0));
}