Compare commits

..

4 Commits

Author SHA1 Message Date
Landon Curt Noll
86c8e6dcf1 Release calc version 2.11.0t9.4.5 2017-05-21 15:38:33 -07:00
Landon Curt Noll
58d32c68f9 Release calc version 2.11.0t9.4.4 2017-05-21 15:38:33 -07:00
Landon Curt Noll
7d0b761de3 Release calc version 2.11.0t9.4.3 2017-05-21 15:38:33 -07:00
Landon Curt Noll
82ff31f246 Release calc version 2.11.0t9.4.2 2017-05-21 15:38:32 -07:00
43 changed files with 1570 additions and 506 deletions

67
BUGS
View File

@@ -31,7 +31,9 @@ The calc web site is located at:
If you have tried all of the above and things still are not right,
then it may be time to send in a bug report. You can send bug reports to:
calc-tester@postofc.corp.sgi.com
calc-bugs at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
When you send your report, please include the following information:
@@ -62,7 +64,12 @@ Stack traces from core dumps are useful to send as well.
Send any comments, compiler warning messages, suggestions and most
importantly, fixes (in the form of a context diff patch) to:
calc-tester@postofc.corp.sgi.com
calc-tester at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
You should use the above calc-bugs address for bug reports, if you are
not currently a member of the calc-tester mailing list.
=-=
@@ -96,31 +103,36 @@ Known bugs:
the terminal in a 'bad' state, as if stty -icanon -echo -echoe
had been executed.
* Dec Alpha Linux compiling with gcc-2.95.1 (or gcc-2.95.2) and
-O2 fails the version 2.11.0t8.10 regression test with:
* Use of 'fmt' in the 2nd arg of printf() calls in c_sysinfo.c
cause some compilers to issue warnings.
make -s check
000: Beginning regression tests
001: Some of these tests may take a while ...
002: Within each section, output should be numbered sequentially
003: parsed global definitions
004: parsed vrfy()
005: parsed prob(str)
006: parsed getglobalvar()
007: parsed test_booleans()
008: parsed test_variables()
make: *** [check] Segmentation fault (core dumped)
We are sure some more bugs exist. When you find them, please let
us know! See the above for details on how to report and were to
EMail your bug reports and hopefully patches to fix them.
Other programs have reported problems when compiling -O2 with
gcc-2.95.1 on the Alpha and Mips.
=-=
One work-a-round is to not compile with -O2 (perhaps just -O).
Another work-a-round is not use gcc-2.95.1.
Other items of note:
* There is a bug in gcc-2.95 that causes calc, when compiled with -O2,
to fail the regression test. The work-a-round is to compile with -O
or to use gcc-2.96 or later.
* There is a bug in some versions of the Dec/Compaq cc for the Alpha
where the following:
#include <stdio.h>
#define SVAL(a,b) (unsigned long)(0x ## a ## b ## ULL)
main(){SVAL(b8a8aeb0,8168eadc);}
fails because it puts a space inside the concatenated hex. Calc
has code that is affected by this bug. This bug has been reported
to Compaq and may be fixed in the future. A work-a-round is to
compile with cc -std0 or to use a later version of their compiler.
* On a Digital UNIX V4.0F (Rev. 1229) on a 500 Mhz 21264, make check
dies a horrible death starting in test 600 and 622 gives 100s of
messages for calc version 2.11.0t9.2 using the Dec's cc with -O2
and without -std0:
messages for calc version 2.11.0t9.4 using the Dec's cc with -O2:
600: Beginning test_bignums
601: muldivcheck 1
@@ -135,6 +147,13 @@ Known bugs:
it finally hangs at test 2000.
We are sure some more bugs exist. When you find them, please let
us know! See the above for details on how to report and were to
EMail your bug reports and hopefully patches to fix them.
The work-a-round is to compile calc without the optimizer. If this
happens to you, try compiling without -O and without -O2. I.e., in
the Makefile, set:
DEBUG= -g
* The sparcv9 support for 64 bit Solaris under gcc-2.96 is able
to compile calc, but calc dumps core very early on in startup.
It is said that sparcv9 support in gcc-2.96 is very unofficial.
There is no work-a-round for this compile problem.

162
CHANGES
View File

@@ -2,14 +2,14 @@ Following is the change from calc version 2.11.0t8.9.1 to date:
The config("verbose_quit") will control the printing of the message:
Quit or abort executed
Quit or abort executed
when a non-interactive ABORT, QUIT or EXIT is encounted. By default,
config("verbose_quit") is TRUE and the message is printed. If one does:
when a non-interactive ABORT, QUIT or EXIT is encounted. By default,
config("verbose_quit") is TRUE and the message is printed. If one does:
config("verbose_quit", 0)
config("verbose_quit", 0)
the message is disabled.
the message is disabled.
Added 8400 regression test set and test8400.cal to test the new
quit and config("verbose_quit") functionality.
@@ -33,34 +33,34 @@ Following is the change from calc version 2.11.0t8.9.1 to date:
When prompt() occurs while reading a file, it will take input from
the terminal rather than taking it from a file. For example:
/* This demonstrates the use of prompt() and some other things */
config("verbose_quit", 0);
define getnumber() {
local x;
for (;;) {
x = eval(prompt(">>> "));
if (isnum(x))
return x;
print "Not a number! Try again";
/* This demonstrates the use of prompt() and some other things */
config("verbose_quit", 0);
define getnumber() {
local x;
for (;;) {
x = eval(prompt(">>> "));
if (isnum(x))
return x;
print "Not a number! Try again";
}
}
}
print "This will display the sqrt of each number you enter";
print "Enter quit to stop";
for (;;) {
print sqrt(getnumber());
}
print "Good bye";
print "This will display the sqrt of each number you enter";
print "Enter quit to stop";
for (;;) {
print sqrt(getnumber());
}
print "Good bye";
Comments entered at input terminal level may be spread over several
lines. For example:
Comments entered at input terminal level may be spread over several
lines. For example:
/*
* Assume that this calc script is called: comment.cal
* Then these commands now work:
* cat comment.cal | calc
* calc < comment.cal
*/
print "Hello";
/*
* Assume that this calc script is called: comment.cal
* Then these commands now work:
* cat comment.cal | calc
* calc < comment.cal
*/
print "Hello";
Added:
@@ -95,21 +95,20 @@ Following is the change from calc version 2.11.0t8.9.1 to date:
GNU-readline. Note that GNU-readline is not shipped with calc.
His patch only provides the hooks to use it. One must comment out:
USE_READLINE=
READLINE_LIB=
READLINE_INCLUDE=
USE_READLINE=
READLINE_LIB=
READLINE_INCLUDE=
and comment in:
and comment in:
USE_READLINE= -DUSE_READLINE
READLINE_LIB= -lreadline -lhistory
READLINE_INCLUDE= -I/usr/include/readline
USE_READLINE= -DUSE_READLINE
READLINE_LIB= -lreadline -lhistory
READLINE_INCLUDE= -I/usr/include/readline
in addition to pre-installing GNU-readline in your system to use
this facility.
in addition to pre-installing GNU-readline in your system to use
this facility.
Changed the "object already defined" math_error message to a
scanerror message.
Changed the "object already defined" math_error to a scanerror message.
Removed the limit on the number of object types.
@@ -154,6 +153,87 @@ Following is the change from calc version 2.11.0t8.9.1 to date:
Fixed the URLs found thruout the source and documentation which did
not and in /, but should for performance and server load reasons.
Cleaned up and improved handling of "mat" and "obj". The comma in:
mat A[2], B[3];
is changed to whatever is appropriate in the context:
+ comma operator
+ separator of arguments in a function call
+ separator of arguments in a defintion
etc.
The expression (mat A[2]), B[3] returns B[3], assuming B already
exists as something created by a statement like: global mat B[4].
What used to be done by the expression:
mat A[2], B[3]
will now require something like:
mat A[2], mat B[3] or A = mat[2], B = mat[3]
For example, if obj point and obj pair are known types, the
following is now allowed:
L = list(mat[2], mat[3], obj point, obj pair)
As another example, the following is allowed:
define f(a = mat[2] = {3,4}) = 5 * a;
as well as the following:
obj point {x,y}, PP = obj pair {A,B} = {obj point, obj point}
which creates two object types at compile time and when executed,
assigns a pair-object value to a variable PP.
Fixed a bug whereby a for loop would behave incorrectly. For example:
config("trace", 2),
global x;
define f() {for ( ; x > 0; x--) {print x;}}
x = 5, f()
will stop after printing 1 instead of looping forever.
Added values l_format, which when CHECK_L_FORMAT is defined ahead
of including longlong.h will help detect when a system can deal with
'long long' but not '%lld' in printf. If a system with 'long long'
uses '%ld' to print a 64 bit value, then l_format will be > 0;
othewise if "%lld" is required, l_format will be < 0.
Added HAVE_STRDUP Makefile variable as well as the have_strdup.c
program that forms the have_strdup.h file. The have_strdup.h file
will define HAVE_STRDUP is the system has strdup(). If HAVE_STRDUP
is not defined, then calc will use calc_strdup() to simulate
the real strdup() function.
Calc no longer makes use of sys_errlist and sys_nerr. Some systems
no longer suppor these values (even though they should from a
legacy prospective). Calc now relies on the fact that strerror()
will return NULL of no such system error exists. System errors >=
10000 will be considered calc errors instead. The Makefile symbol
ERRNO_DECL has gone away as well as calc_errno.c and calc_errno.h.
On system errors are are not known to to the libc strerror() function,
strerror() will now print something such as:
Unknown error 9999
Fixed some insure code inspection tool issues that were discovered
and investigated by Michel van der List <vanderlistmj@sbphrd.com>.
Made an effort to ensure that the v_subtype of VALUES are initialized
to V_NOSUBTYPE thruout the source code.
Established a separate calc-bugs address from the calc-tester
maining list. Using anti-spam address forms in order to try and
stay under the radar of spammers as much as one can do so.
Following is the change from calc version 2.11.0t8 to 2.11.0t8.9:

229
Makefile
View File

@@ -273,6 +273,18 @@ HAVE_URANDOM=
HAVE_GETRUSAGE=
#HAVE_GETRUSAGE= -DHAVE_NO_GETRUSAGE
# Determine if we have strdup()
#
# If HAVE_STRDUP is empty, this makefile will run the have_memmv program
# to determine if strdup() is supported. If HAVE_STRDUP is set to
# -DHAVE_NO_STRDUP, then calc will use internal functions to simulate
# the memory move function that does correct overlapping memory modes.
#
# If in doubt, leave HAVE_STRDUP empty and this Makefile will figure it out.
#
HAVE_STRDUP=
#HAVE_STRDUP= -DHAVE_NO_STRDUP
# Some architectures such as Sparc do not allow one to access 32 bit values
# that are not alligned on a 32 bit boundary.
#
@@ -290,39 +302,6 @@ HAVE_GETRUSAGE=
ALIGN32= -DMUST_ALIGN32
#ALIGN32= -UMUST_ALIGN32
# On most machines: errno sys_errlist and sys_nerr are declared
# by either <stdio.h> and/or <errno.h>. But some systems declare
# them somewhere else or do not declare them at all!
#
# If the system were doing a proper job in headers, this should declare them:
#
# #include <stdio.h>
# #include <errno.h>
#
# But one some systems one must explicitly declare them as:
#
# extern int errno;
# extern const char *const sys_errlist[];
# extern int sys_nerr;
#
# and on some old systems they must be explicitly and incorrectly declared as:
#
# extern int errno;
# extern char *sys_errlist[];
# extern int sys_nerr;
#
# ERRNO_DECL= let calc_errno.c determine how to declare them
# ERRNO_DECL= -DERRNO_NO_DECL headers declare them correctly
# ERRNO_DECL= -DERRNO_STD_DECL one must explicitly declare then
# ERRNO_DECL= -DERRNO_OLD_DECL one must explicitly & incorrectly declare them
#
# When in doubt, be safe leave ERRNO_DECL empty.
#
ERRNO_DECL=
#ERRNO_DECL= -DERRNO_NO_DECL
#ERRNO_DECL= -DERRNO_STD_DECL
#ERRNO_DECL= -DERRNO_OLD_DECL
# where to install binary files
#
BINDIR= /usr/local/bin
@@ -762,7 +741,7 @@ CC= ${PURIFY} ${LCC}
#
###
#
# RS6000 set
# AIX RS/6000 set
#
#CCWARN=
#CCOPT= ${DEBUG} ${NO_SHARED}
@@ -930,9 +909,10 @@ BUILD_H_SRC= align32.h args.h calcerr.h conf.h endian_calc.h \
fposval.h have_const.h have_fpos.h have_malloc.h \
have_memmv.h have_newstr.h have_offscl.h have_posscl.h \
have_stdlib.h have_string.h have_times.h have_uid_t.h \
have_unistd.h longbits.h longlong.h terminal.h calc_errno.h \
have_unistd.h longbits.h longlong.h terminal.h \
have_ustat.h have_getsid.h have_getpgid.h \
have_gettime.h have_getprid.h have_urandom.h have_rusage.h
have_gettime.h have_getprid.h have_urandom.h have_rusage.h \
have_strdup.h
# we build these .c files during the make
#
@@ -944,9 +924,9 @@ BUILD_C_SRC= calcerr.c
#
UTIL_C_SRC= align32.c endian.c longbits.c have_newstr.c have_uid_t.c \
have_const.c have_stdvs.c have_varvs.c fposval.c have_fpos.c \
longlong.c have_offscl.c have_posscl.c have_memmv.c calc_errno.c \
longlong.c have_offscl.c have_posscl.c have_memmv.c \
have_ustat.c have_getsid.c have_getpgid.c \
have_gettime.c have_getprid.c have_rusage.c
have_gettime.c have_getprid.c have_rusage.c have_strdup.c
# these awk and sed tools are used in the process of building BUILD_H_SRC
# and BUILD_C_SRC
@@ -960,22 +940,22 @@ UTIL_MISC_SRC= calcerr_h.sed calcerr_h.awk calcerr_c.sed calcerr_c.awk \
#
UTIL_OBJS= endian.o longbits.o have_newstr.o have_uid_t.o \
have_const.o fposval.o have_fpos.o longlong.o try_strarg.o \
have_stdvs.o have_varvs.o have_posscl.o have_memmv.o calc_errno.o \
have_stdvs.o have_varvs.o have_posscl.o have_memmv.o \
have_ustat.o have_getsid.o have_getpgid.o \
have_gettime.o have_getprid.o ver_calc.o have_rusage.o
have_gettime.o have_getprid.o ver_calc.o have_rusage.o have_strdup.o
# these temp files may be created (and removed) during the build of BUILD_C_SRC
#
UTIL_TMP= ll_tmp fpos_tmp fposv_tmp const_tmp uid_tmp newstr_tmp vs_tmp \
calc_errno_tmp memmv_tmp offscl_tmp posscl_tmp newstr_tmp \
getsid_tmp gettime_tmp getprid_tmp rusage_tmp
memmv_tmp offscl_tmp posscl_tmp newstr_tmp \
getsid_tmp gettime_tmp getprid_tmp rusage_tmp strdup_tmp
# these utility progs may be used in the process of building BUILD_H_SRC
#
UTIL_PROGS= align32 fposval have_uid_t longlong have_const \
endian longbits have_newstr have_stdvs have_varvs calc_errno \
endian longbits have_newstr have_stdvs have_varvs \
have_ustat have_getsid have_getpgid \
have_gettime have_getprid ver_calc
have_gettime have_getprid ver_calc have_strdup
# These files are required by the regress.cal regression test.
#
@@ -1128,13 +1108,14 @@ calc.1: calc.man ${MAKE_FILE}
##
calc.o: calc.c ${MAKE_FILE}
${CC} ${CFLAGS} ${CCOPT} ${ALLOW_CUSTOM} -c calc.c
${CC} ${CFLAGS} ${ALLOW_CUSTOM} -c calc.c
custom.o: custom.c ${MAKE_FILE}
${CC} ${CFLAGS} ${ALLOW_CUSTOM} -c custom.c
hist.o: hist.c ${MAKE_FILE}
${CC} ${CFLAGS} ${TERMCONTROL} ${USE_READLINE} ${READLINE_INCLUDE} -c hist.c
${CC} ${CFLAGS} ${TERMCONTROL} ${USE_READLINE} ${READLINE_INCLUDE} \
-c hist.c
func.o: func.c ${MAKE_FILE}
${CC} ${CFLAGS} ${ALLOW_CUSTOM} -c func.c
@@ -1535,6 +1516,8 @@ longlong.h: longlong.c have_stdlib.h have_string.h ${MAKE_FILE}
else \
echo '#undef HAVE_LONGLONG' >> longlong.h; \
echo '#define LONGLONG_BITS 0 /* no */' >> longlong.h; \
echo '#undef LL_FORMAT' >> longlong.h; \
echo '#undef L_FORMAT' >> longlong.h; \
fi
${Q}echo '' >> longlong.h
${Q}echo '' >> longlong.h
@@ -2174,6 +2157,45 @@ have_rusage.h: have_rusage.c ${MAKE_FILE}
true; \
fi
have_strdup.h: have_strdup.c ${MAKE_FILE}
-${Q}rm -f have_strdup have_strdup.o strdup_tmp have_strdup.h
${Q}echo 'forming have_strdup.h'
${Q}echo '/*' > have_strdup.h
${Q}echo ' * DO NOT EDIT -- generated by the Makefile' >> have_strdup.h
${Q}echo ' */' >> have_strdup.h
${Q}echo '' >> have_strdup.h
${Q}echo '' >> have_strdup.h
${Q}echo '#if !defined(__HAVE_RUSAGE_H__)' >> have_strdup.h
${Q}echo '#define __HAVE_RUSAGE_H__' >> have_strdup.h
${Q}echo '' >> have_strdup.h
${Q}echo '' >> have_strdup.h
${Q}echo '/* do we have or want getstrdup()? */' >> have_strdup.h
-${Q}rm -f have_strdup.o have_strdup
-${Q}${LCC} ${ICFLAGS} ${HAVE_STRDUP} have_strdup.c -c 2>/dev/null; \
true
-${Q}${LCC} ${ILDFLAGS} have_strdup.o -o have_strdup 2>/dev/null; true
-${Q}${SHELL} -c "./have_strdup > strdup_tmp 2>/dev/null" \
>/dev/null 2>&1; true
-${Q}if [ -s strdup_tmp ]; then \
cat strdup_tmp >> have_strdup.h; \
else \
echo '#undef HAVE_STRDUP /* no */' >> have_strdup.h; \
fi
${Q}echo '' >> have_strdup.h
${Q}echo '' >> have_strdup.h
${Q}echo '#endif /* !__HAVE_RUSAGE_H__ */' >> have_strdup.h
-${Q}rm -f have_strdup have_strdup.o strdup_tmp
${Q}echo 'have_strdup.h formed'
-@if [ -z "${Q}" ]; then \
echo ''; \
echo '=-=-= start of $@ =-=-='; \
cat $@; \
echo '=-=-= end of $@ =-=-='; \
echo ''; \
else \
true; \
fi
args.h: have_stdvs.c have_varvs.c have_string.h have_unistd.h have_string.h
-${Q}rm -f args.h have_args
${Q}echo 'forming args.h'
@@ -2233,98 +2255,6 @@ args.h: have_stdvs.c have_varvs.c have_string.h have_unistd.h have_string.h
true; \
fi
calc_errno.h: calc_errno.c ${MAKE_FILE}
-${Q}rm -f calc_errno.h calc_errno calc_errno_tmp
${Q}echo 'forming calc_errno.h'
${Q}echo '/*' > calc_errno.h
${Q}echo ' * DO NOT EDIT -- generated by the Makefile' >> calc_errno.h
${Q}echo ' */' >> calc_errno.h
${Q}echo '' >> calc_errno.h
${Q}echo '' >> calc_errno.h
${Q}echo '#if !defined(__CALC_ERRNO_H__)' >> calc_errno.h
${Q}echo '#define __CALC_ERRNO_H__' >> calc_errno.h
${Q}echo '' >> calc_errno.h
${Q}echo '' >> calc_errno.h
-${Q}if [ X"${ERRNO_DECL}" = X"-DERRNO_NO_DECL" ]; then \
echo '/*' >> calc_errno.h; \
echo ' * The calc Makefile explicitly told us' >> calc_errno.h; \
echo ' * how to declare errno and friends.' >> calc_errno.h; \
echo ' */' >> calc_errno.h; \
echo '' >> calc_errno.h; \
echo '#include <stdio.h>' >> calc_errno.h; \
echo '#include <errno.h>' >> calc_errno.h; \
elif [ X"${ERRNO_DECL}" = X"-DERRNO_STD_DECL" ]; then \
echo '/*' >> calc_errno.h; \
echo ' * The calc Makefile explicitly told us' >> calc_errno.h; \
echo ' * how to declare errno and friends.' >> calc_errno.h; \
echo ' */' >> calc_errno.h; \
echo '' >> calc_errno.h; \
echo 'extern int errno; ' \
'/* last system error */' >> calc_errno.h; \
echo 'extern const char *const sys_errlist[];' \
' /* system error messages*/' >> calc_errno.h; \
echo 'extern int sys_nerr; ' \
'/* number of system errors */' >> calc_errno.h; \
elif [ X"${ERRNO_DECL}" = X"-DERRNO_OLD_DECL" ]; then \
echo '/*' >> calc_errno.h; \
echo ' * The calc Makefile explicitly told us' >> calc_errno.h; \
echo ' * how to declare errno and friends.' >> calc_errno.h; \
echo ' */' >> calc_errno.h; \
echo '' >> calc_errno.h; \
echo 'extern int errno; ' \
'/* last system error */' >> calc_errno.h; \
echo 'extern char *sys_errlist[];' \
' /* system error messages*/' >> calc_errno.h; \
echo 'extern int sys_nerr; ' \
'/* number of system errors */' >> calc_errno.h; \
else \
${LCC} ${ICFLAGS} -DTRY_ERRNO_NO_DECL \
calc_errno.c -o calc_errno 2>calc_errno_tmp; \
if [ -x ./calc_errno ]; then \
./calc_errno >> calc_errno.h; \
else \
${LCC} ${ICFLAGS} -DTRY_ERRNO_STD_DECL \
calc_errno.c -o calc_errno 2>calc_errno_tmp; \
if [ -x ./calc_errno ]; then \
./calc_errno >> calc_errno.h; \
else \
${LCC} ${ICFLAGS} -DTRY_ERRNO_OLD_DECL \
calc_errno.c -o calc_errno 2>calc_errno_tmp; \
if [ -x ./calc_errno ]; then \
./calc_errno >> calc_errno.h; \
else \
echo '/*' >> calc_errno.h; \
echo ' * We were unable to to determine' >> calc_errno.h; \
echo ' * how to declare errno and friends.' >> calc_errno.h; \
echo ' * So we will guess this will work' >> calc_errno.h; \
echo ' * and hope for the best.' >> calc_errno.h; \
echo ' */' >> calc_errno.h; \
echo '' >> calc_errno.h; \
echo 'extern int errno; ' \
'/* last system error */' >> calc_errno.h; \
echo 'extern const char *const sys_errlist[];' \
' /* system error messages*/' >> calc_errno.h; \
echo 'extern int sys_nerr; ' \
'/* number of system errors */' >> calc_errno.h; \
fi; \
fi; \
fi; \
fi
${Q}echo '' >> calc_errno.h
${Q}echo '' >> calc_errno.h
${Q}echo '#endif /* !__CALC_ERRNO_H__ */' >> calc_errno.h
-${Q}rm -f calc_errno calc_errno_tmp
${Q}echo 'calc_errno.h formed'
-@if [ -z "${Q}" ]; then \
echo ''; \
echo '=-=-= start of $@ =-=-='; \
cat $@; \
echo '=-=-= end of $@ =-=-='; \
echo ''; \
else \
true; \
fi
calcerr.h: calcerr.tbl calcerr_h.sed calcerr_h.awk ${MAKE_FILE}
-${Q}rm -f calerr.h
${Q}echo 'forming calcerr.h'
@@ -2700,7 +2630,6 @@ env:
@echo "HAVE_GETPRID=${HAVE_GETPRID}"; echo ""
@echo "HAVE_URANDOM=${HAVE_URANDOM}"; echo ""
@echo "ALIGN32=${ALIGN32}"; echo ""
@echo "ERRNO_DECL=${ERRNO_DECL}"; echo ""
@echo "BINDIR=${BINDIR}"; echo ""
@echo "TOPDIR=${TOPDIR}"; echo ""
@echo "LIBDIR=${LIBDIR}"; echo ""
@@ -3027,6 +2956,8 @@ install: calc libcalc.a ${LIB_H_SRC} ${BUILD_H_SRC} calc.1
-rm -f ${LIBDIR}/stdarg.h stdarg.h
-rm -f ${LIBDIR}/prototype.h prototype.h
-rm -f ${LIBDIR}/libcalcerr.a libcalcerr.a
-rm -f ${LIBDIR}/calc_errno.h calc_errno.h ${INCDIRCALC}/calc_errno.h
-rm -f calc_errno.c calc_errno.o calc_errno
${V} echo '=-=-=-=-= end of $@ rule =-=-=-=-='
##
@@ -3048,6 +2979,7 @@ addop.o: config.h
addop.o: endian_calc.h
addop.o: func.h
addop.o: hash.h
addop.o: have_const.h
addop.o: have_malloc.h
addop.o: have_memmv.h
addop.o: have_newstr.h
@@ -3104,6 +3036,7 @@ blkcpy.o: config.h
blkcpy.o: endian_calc.h
blkcpy.o: file.h
blkcpy.o: hash.h
blkcpy.o: have_const.h
blkcpy.o: have_fpos.h
blkcpy.o: have_malloc.h
blkcpy.o: have_memmv.h
@@ -3192,7 +3125,6 @@ calc.o: symbol.h
calc.o: token.h
calc.o: value.h
calc.o: zmath.h
calc_errno.o: calc_errno.c
calcerr.o: calcerr.c
calcerr.o: calcerr.h
calcerr.o: have_const.h
@@ -3208,6 +3140,7 @@ codegen.o: config.h
codegen.o: endian_calc.h
codegen.o: func.h
codegen.o: hash.h
codegen.o: have_const.h
codegen.o: have_malloc.h
codegen.o: have_memmv.h
codegen.o: have_newstr.h
@@ -3292,6 +3225,7 @@ const.o: config.h
const.o: const.c
const.o: endian_calc.h
const.o: hash.h
const.o: have_const.h
const.o: have_malloc.h
const.o: have_memmv.h
const.o: have_newstr.h
@@ -3346,6 +3280,7 @@ file.o: file.c
file.o: file.h
file.o: fposval.h
file.o: hash.h
file.o: have_const.h
file.o: have_fpos.h
file.o: have_malloc.h
file.o: have_memmv.h
@@ -3370,7 +3305,6 @@ func.o: alloc.h
func.o: block.h
func.o: byteswap.h
func.o: calc.h
func.o: calc_errno.h
func.o: calcerr.h
func.o: cmath.h
func.o: config.h
@@ -3447,6 +3381,7 @@ have_rusage.o: have_rusage.c
have_stdvs.o: have_stdvs.c
have_stdvs.o: have_string.h
have_stdvs.o: have_unistd.h
have_strdup.o: have_strdup.c
have_uid_t.o: have_uid_t.c
have_uid_t.o: have_unistd.h
have_ustat.o: have_ustat.c
@@ -3463,6 +3398,7 @@ help.o: conf.h
help.o: config.h
help.o: endian_calc.h
help.o: hash.h
help.o: have_const.h
help.o: have_malloc.h
help.o: have_memmv.h
help.o: have_newstr.h
@@ -3488,10 +3424,12 @@ hist.o: cmath.h
hist.o: config.h
hist.o: endian_calc.h
hist.o: hash.h
hist.o: have_const.h
hist.o: have_malloc.h
hist.o: have_memmv.h
hist.o: have_newstr.h
hist.o: have_stdlib.h
hist.o: have_strdup.h
hist.o: have_string.h
hist.o: have_unistd.h
hist.o: hist.c
@@ -3516,6 +3454,7 @@ input.o: conf.h
input.o: config.h
input.o: endian_calc.h
input.o: hash.h
input.o: have_const.h
input.o: have_malloc.h
input.o: have_memmv.h
input.o: have_newstr.h
@@ -3546,6 +3485,7 @@ label.o: config.h
label.o: endian_calc.h
label.o: func.h
label.o: hash.h
label.o: have_const.h
label.o: have_malloc.h
label.o: have_memmv.h
label.o: have_newstr.h
@@ -3580,6 +3520,7 @@ lib_calc.o: have_malloc.h
lib_calc.o: have_memmv.h
lib_calc.o: have_newstr.h
lib_calc.o: have_stdlib.h
lib_calc.o: have_strdup.h
lib_calc.o: have_string.h
lib_calc.o: have_unistd.h
lib_calc.o: label.h
@@ -3675,6 +3616,7 @@ math_error.o: cmath.h
math_error.o: config.h
math_error.o: endian_calc.h
math_error.o: hash.h
math_error.o: have_const.h
math_error.o: have_malloc.h
math_error.o: have_memmv.h
math_error.o: have_newstr.h
@@ -3725,6 +3667,7 @@ obj.o: config.h
obj.o: endian_calc.h
obj.o: func.h
obj.o: hash.h
obj.o: have_const.h
obj.o: have_malloc.h
obj.o: have_memmv.h
obj.o: have_newstr.h
@@ -4030,6 +3973,7 @@ string.o: cmath.h
string.o: config.h
string.o: endian_calc.h
string.o: hash.h
string.o: have_const.h
string.o: have_malloc.h
string.o: have_memmv.h
string.o: have_newstr.h
@@ -4055,6 +3999,7 @@ symbol.o: config.h
symbol.o: endian_calc.h
symbol.o: func.h
symbol.o: hash.h
symbol.o: have_const.h
symbol.o: have_malloc.h
symbol.o: have_memmv.h
symbol.o: have_newstr.h
@@ -4084,6 +4029,7 @@ token.o: cmath.h
token.o: config.h
token.o: endian_calc.h
token.o: hash.h
token.o: have_const.h
token.o: have_malloc.h
token.o: have_memmv.h
token.o: have_newstr.h
@@ -4143,6 +4089,7 @@ version.o: cmath.h
version.o: config.h
version.o: endian_calc.h
version.o: hash.h
version.o: have_const.h
version.o: have_malloc.h
version.o: have_memmv.h
version.o: have_newstr.h

12
README
View File

@@ -74,7 +74,9 @@ for a wish/todo list. Code contributions are welcome.
To join the calc-tester mailing list. Send a request to:
calc-tester-request@postofc.corp.sgi.com
calc-tester-request at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
Your message body (not the subject) should consist of:
@@ -85,6 +87,14 @@ Your message body (not the subject) should consist of:
where ``address'' is your EMail address and ``your_full_name'' is
your full name.
Calc bug reports, however should be sent to:
calc-bugs at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
but see the BUGS file first.
The calc web site is located at:
http://reality.sgi.com/chongo/tech/comp/calc/

View File

@@ -114,6 +114,7 @@ beginfunc(char *name, BOOL newflag)
fp->f_localcount = 0;
fp->f_opcodecount = 0;
fp->f_savedvalue.v_type = V_NULL;
fp->f_savedvalue.v_subtype = V_NOSUBTYPE;
fp->f_name = namestr(&funcnames, newindex);
curfunc = fp;
initlocals();

View File

@@ -80,6 +80,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
*/
if (!create) {
val.v_type = V_NULL;
val.v_subtype = V_NOSUBTYPE;
return &val;
}
@@ -292,6 +293,7 @@ assoccopy(ASSOC *oldap)
ep->e_dim = oldep->e_dim;
ep->e_hash = oldep->e_hash;
ep->e_value.v_type = V_NULL;
ep->e_value.v_subtype = V_NOSUBTYPE;
for (i = 0; i < ep->e_dim; i++)
copyvalue(&oldep->e_indices[i], &ep->e_indices[i]);
copyvalue(&oldep->e_value, &ep->e_value);

View File

@@ -330,6 +330,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi)
i = num;
while (i-- > 0) {
vp->v_type = V_NUM;
vp->v_subtype = V_NOSUBTYPE;
vp->v_num = itoq((long) *op++);
vp++;
}

9
calc.c
View File

@@ -39,9 +39,6 @@
/*
* static definitions and functions
*/
static char *usage = "usage: %s [-c] [-C] [-d] [-e] [-h] [-i] [-m mode]\n"
"\t[-D calc_debug[:lib_debug:[user_debug]]]\n"
"\t[-n] [-p] [-q] [-u] [-v] [[--] calc_cmd ...]\n";
static void intint(int arg); /* interrupt routine */
@@ -153,7 +150,11 @@ main(int argc, char **argv)
* we are too early in processing to call
* libcalc_call_me_last() - nothing to cleanup
*/
fprintf(stderr, usage, program);
fprintf(stderr,
"usage: %s [-c] [-C] [-d] [-e] [-h] [-i] [-m mode]\n"
"\t[-D calc_debug[:lib_debug:[user_debug]]]\n"
"\t[-n] [-p] [-q] [-u] [-v] [[--] calc_cmd ...]\n",
program);
exit(1);
}
}

3
calc.h
View File

@@ -14,6 +14,8 @@
#include "value.h"
#include "have_const.h"
/*
* Configuration definitions
@@ -140,6 +142,7 @@ extern void givehelp(char *type);
extern void libcalc_call_me_first(void);
extern void libcalc_call_me_last(void);
extern void showerrors(void);
extern char *calc_strdup(CONST char *);
/*
* Initialization

View File

@@ -570,7 +570,11 @@ The majority of
was written by David I. Bell.
.sp
.B Calc
archives and calc-tester mailing list maintained by Landon Curt Noll.
The Calc primary mirror, calc mailing list and calc bug report
processing is performed by Landon Curt Noll.
.sp
Landon Curt Noll maintains the master reference source, performs
release control functions as well as other calc maintenance functions.
.sp
Thanks for suggestions and encouragement from Peter Miller,
Neil Justusson, and Landon Noll.
@@ -610,9 +614,36 @@ scripts that you would like you see included
in future distributions to:
.sp
.in +0.5i
calc-tester@postofc.corp.sgi.com
.nf
calc-tester at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
.fi
.in -0.5i
.sp
Bug reports are sent to:
.in +0.5i
.nf
calc-bugs at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
.fi
.in -0.5i
.sp
See the
.I BUGS
source file or use the
.I calc
command:
.sp
.in +0.5i
.nf
help bugs
.fi
.in -0.5i
.sp
for more information about bug reporting.
.sp
Landon Noll maintains the the
.B calc
web site is located at:
@@ -626,7 +657,11 @@ One may join the
testing group by sending a request to:
.sp
.in +0.5i
calc-tester-request@postofc.corp.sgi.com
.nf
calc-tester-request at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
.fi
.in -0.5i
.sp
Your message body (not the subject) should consist of:

View File

@@ -1,123 +0,0 @@
/*
* errno - Determine how to declare errno, sys_errlist and sys_nerr
*
* On most machines: errno sys_errlist and sys_nerr are declared
* by either <stdio.h> and/or <errno.h>. But some systems declare
* them somewhere else or do not declare them at all!
*
* If the system were doing a proper job in headers, this should declare them:
*
* #include <stdio.h>
* #include <errno.h>
*
* But one some systems one must explicitly declare them as:
*
* extern int errno;
* extern const char *const sys_errlist[];
* extern int sys_nerr;
*
* and on some old systems they must be explicitly and incorrectly declared as:
*
* extern int errno;
* extern char *sys_errlist[];
* extern int sys_nerr;
*
* The purpose of this utility is try and find the right way to declare
* them and to output the middle of a header file called calc_errno.h.
*/
/*
* Copyright (c) 1999 by Landon Curt Noll. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright, this permission notice and text
* this comment, and the disclaimer below appear in all of the following:
*
* supporting documentation
* source copies
* source works derived from this source
* binaries derived from this source or from derived source
*
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* chongo was here /\../\
*/
#include <stdio.h>
#if defined(TRY_ERRNO_NO_DECL)
# include <errno.h>
#endif /* TRY_ERRNO_NO_DECL */
int
main(void)
{
#if defined(TRY_ERRNO_NO_DECL)
printf("/*\n");
printf(" * The following comments were produced by calc_errno\n");
printf(" * in an effort to see if these values were correctly\n");
printf(" * declared when calc_errno.c was compiled.\n");
printf(" */\n\n");
printf("/* Initially errno is %d */\n", errno);
printf("/* There are %d entries in sys_errlist[] */\n", sys_nerr);
printf("/* The 2nd sys_errlist entry is \"%s\" */\n\n", sys_errlist[1]);
printf("/*\n");
printf(" * Based on the above, calc_errno now knows\n");
printf(" * how to declare errno and friends.\n");
printf(" */\n\n");
printf("#include <stdio.h>\n");
printf("#include <errno.h>\n");
#elif defined(TRY_ERRNO_OLD_DECL)
extern int errno; /* last system error */
extern char *sys_errlist[]; /* system error messages */
extern int sys_nerr; /* number of system errors*/
printf("/*\n");
printf(" * The following comments were produced by calc_errno\n");
printf(" * in an effort to see if these values were correctly\n");
printf(" * declared when calc_errno.c was compiled.\n");
printf(" */\n\n");
printf("/* Initially errno is %d */\n", errno);
printf("/* There are %d entries in sys_errlist[] */\n", sys_nerr);
printf("/* The 2nd sys_errlist entry is \"%s\" */\n\n", sys_errlist[1]);
printf("/*\n");
printf(" * Based on the above, calc_errno now knows\n");
printf(" * how to declare errno and friends.\n");
printf(" */\n\n");
printf("extern int errno;\t\t/* last system error */\n");
printf("extern char *sys_errlist[];\t"
"/* system error messages */\n");
printf("extern int sys_nerr;\t\t/* number of system errors*/\n");
#else /* assume defined(TRY_ERRNO_STD_DECL) */
extern int errno; /* last system error */
extern const char *const sys_errlist[]; /* system error messages */
extern int sys_nerr; /* number of system errors*/
printf("/*\n");
printf(" * The following comments were produced by calc_errno\n");
printf(" * in an effort to see if these values were correctly\n");
printf(" * declared when calc_errno.c was compiled.\n");
printf(" */\n\n");
printf("/* Initially errno is %d */\n", errno);
printf("/* There are %d entries in sys_errlist[] */\n", sys_nerr);
printf("/* The 2nd sys_errlist entry is \"%s\" */\n\n", sys_errlist[1]);
printf("/*\n");
printf(" * Based on the above, calc_errno now knows\n");
printf(" * how to declare errno and friends.\n");
printf(" */\n\n");
printf("extern int errno;\t\t\t/* last system error */\n");
printf("extern const char *const sys_errlist[];\t"
"/* system error messages */\n");
printf("extern int sys_nerr;\t\t\t/* number of system errors*/\n");
#endif
/* exit(0); */
return 0;
}

View File

@@ -263,7 +263,7 @@ ungetfunction(void)
return;
default:
scanerror(T_SEMICOLON,
"Non-name arg for undefine");
"Non-name arg for undefine");
return;
}
}
@@ -521,11 +521,9 @@ getonevariable(int symtype)
* | BREAK ';'
* | RETURN assignment ';'
* | GOTO label ';'
* | MAT name '[' value [ ':' value ] [',' value [ ':' value ] ] ']' ';'
* | OBJ type '{' arg [ ',' arg ] ... '}' ] ';'
* | OBJ type name [ ',' name ] ';'
* | PRINT assignment [, assignment ] ... ';'
* | QUIT [ string ] ';'
* | ABORT [ string ] ';'
* | SHOW item ';'
* | body
* | assignment ';'
@@ -707,14 +705,14 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d
}
}
if (gettoken() != T_RIGHTPAREN) { /* have 'c' part */
if (label1.l_offset <= 0)
if (label1.l_offset < 0)
addoplabel(OP_JUMP, &label3);
setlabel(&label2);
contlabel = &label2;
rescantoken();
(void) getexprlist();
addop(OP_POP);
if (label1.l_offset > 0)
if (label1.l_offset >= 0)
addoplabel(OP_JUMP, &label1);
if (gettoken() != T_RIGHTPAREN) {
(void) tokenmode(oldmode);
@@ -734,15 +732,21 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d
case T_WHILE:
oldmode = tokenmode(TM_DEFAULT);
contlabel = &label1;
breaklabel = &label2;
clearlabel(contlabel);
clearlabel(breaklabel);
setlabel(contlabel);
getcondition();
addoplabel(OP_JUMPZ, breaklabel);
getstatement(contlabel, breaklabel, NULL_LABEL, NULL_LABEL);
addoplabel(OP_JUMP, contlabel);
setlabel(breaklabel);
if (gettoken() != T_SEMICOLON) {
breaklabel = &label2;
clearlabel(breaklabel);
addoplabel(OP_JUMPZ, breaklabel);
rescantoken();
getstatement(contlabel, breaklabel,
NULL_LABEL, NULL_LABEL);
addoplabel(OP_JUMP, contlabel);
setlabel(breaklabel);
} else {
addoplabel(OP_JUMPNZ, contlabel);
}
(void) tokenmode(oldmode);
return;
@@ -1053,18 +1057,14 @@ getoneobj(long index, int symtype)
}
/*
* Routine to collect a set of variables for the specified object type
* and initialize them as being that type of object.
* Here
* objlist = name initlist [ ',' name initlist ] ... ';'.
* If symtype is SYM_UNDEFINED, then this is an OBJ statement where the
* values can be any variable expression, and no symbols are to be defined.
* Otherwise this is part of a declaration, and the variables must be raw
* symbol names which are defined with the specified symbol type.
* Routine to assign a specified object-type value to each of a set of
* variables in a "global", "local" or "static" declaration, or, if
* symtype is SYM_UNDEFINED, to create one object value of the specified
* type.
*
* given:
* name object name
* symtype type of symbol to collect for
* symtype declaration type
*/
static void
getobjvars(char *name, int symtype)
@@ -1078,6 +1078,8 @@ getobjvars(char *name, int symtype)
}
for (;;) {
getoneobj(index, symtype);
if (symtype == SYM_UNDEFINED)
return;
if (gettoken() != T_COMMA) {
rescantoken();
return;
@@ -1921,11 +1923,6 @@ getterm(void)
case T_MAT:
getonematrix(SYM_UNDEFINED);
while (gettoken() == T_COMMA) {
addop(OP_POP);
getonematrix(SYM_UNDEFINED);
}
rescantoken();
type = EXPR_ASSIGN;
break;

View File

@@ -1000,6 +1000,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
* convert element to value
*/
vp->v_type = V_NUM;
vp->v_subtype = V_NOSUBTYPE;
switch (type) {
case CONFIG_ALL:
vp->v_type = V_CONFIG;

View File

@@ -310,6 +310,15 @@ libcustcalc.a: ${CUSTCALC_OBJ} ${MAKE_FILE} ../Makefile
ar qc libcustcalc.a ${CUSTCALC_OBJ}
${RANLIB} libcustcalc.a
##
#
# Special .o files
#
##
c_sysinfo.o: c_sysinfo.c ${MAKE_FILE}
${CC} ${CFLAGS} c_sysinfo.c -c
##
#
# used by the upper level Makefile

View File

@@ -33,6 +33,7 @@
#include "../config.h"
#include "../calc.h"
#include "../longbits.h"
#define CHECK_L_FORMAT
#include "../longlong.h"
#include "../block.h"
#include "../calcerr.h"
@@ -306,17 +307,33 @@ static void
dump_name_value(void)
{
struct infoname *p; /* current infoname */
char *fmt; /* printf value format */
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
if (p->str == NULL) {
#if LONG_BITS == FULL_BITS || FULL_BITS == 32 || !defined(HAVE_LONGLONG)
printf("%s%-23s\t%-8lu\t(0x%lx)\n",
fmt = "%s%-23s\t%-8lu\t(0x%lx)\n";
printf(fmt,
(conf->tab_ok ? "\t" : ""), p->name,
(unsigned long)p->nmbr,
(unsigned long)p->nmbr);
#else
printf("%s%-23s\t%-8llu\t(0x%llx)\n",
/*
* Determine of %ld can print a 64 bit long long.
*
* Some systems that can make use of %ld to print a
* a 64 bit value do not support the %lld type.
* So we will only try %lld if %ld does not work.
*/
if (l_format < 0) {
/* %ld prints lower 32 bits only, use %lld */
fmt = "%s%-23s\t%-8llu\t(0x%llx)\n";
} else {
/* %ld prints all 64 bits, use %ld */
fmt = "%s%-23s\t%-8lu\t(0x%lx)\n";
}
printf(fmt,
(conf->tab_ok ? "\t" : ""), p->name,
(unsigned long long)p->nmbr,
(unsigned long long)p->nmbr);
@@ -337,17 +354,33 @@ static void
dump_mening_value(void)
{
struct infoname *p; /* current infoname */
char *fmt; /* printf value format */
/* dump the entire table */
for (p = sys_info; p->name != NULL; ++p) {
if (p->str == NULL) {
#if LONG_BITS == FULL_BITS || FULL_BITS == 32 || !defined(HAVE_LONGLONG)
printf("%s%-36.36s\t%-8lu\t(0x%lx)\n",
fmt = "%s%-36.36s\t%-8lu\t(0x%lx)\n";
printf(fmt,
(conf->tab_ok ? "\t" : ""), p->meaning,
(unsigned long)p->nmbr,
(unsigned long)p->nmbr);
#else
printf("%s%-36.36s\t%-8llu\t(0x%llx)\n",
/*
* Determine of %ld can print a 64 bit long long.
*
* Some systems that can make use of %ld to print a
* a 64 bit value do not support the %lld type.
* So we will only try %lld if %ld does not work.
*/
if (l_format < 0) {
/* %ld prints lower 32 bits only, use %lld */
fmt = "%s%-36.36s\t%-8llu\t(0x%llx)\n";
} else {
/* %ld prints all 64 bits, use %ld */
fmt = "%s%-36.36s\t%-8lu\t(0x%lx)\n";
}
printf(fmt,
(conf->tab_ok ? "\t" : ""), p->meaning,
(unsigned long long)p->nmbr,
(unsigned long long)p->nmbr);

9
file.c
View File

@@ -2228,15 +2228,16 @@ freadnum(FILE *fp, VALUE *valptr)
ch = fgetc(fp);
}
}
if (ch == 'i' || ch == 'I')
if (ch == 'i' || ch == 'I') {
imag = TRUE;
else {
} else {
ungetc(ch, fp);
}
if (ziszero(num)) {
zfree(num);
val.v_type = V_NUM;
val.v_subtype = V_NOSUBTYPE;
val.v_num = qlink(&_qzero_);
*valptr = val;
return;
@@ -2281,11 +2282,11 @@ freadnum(FILE *fp, VALUE *valptr)
c->imag = q;
val.v_type = V_COM;
val.v_com = c;
}
else {
} else {
val.v_type = V_NUM;
val.v_num = q;
}
val.v_subtype = V_NOSUBTYPE;
*valptr = val;
}

645
func.c

File diff suppressed because it is too large Load Diff

62
have_strdup.c Normal file
View File

@@ -0,0 +1,62 @@
/*
* have_strdup - Determine if we strdup()
*
* usage:
* have_strdup
*
* Not all systems have the strdup() function, so this may not
* compile on your system.
*
* This prog outputs several defines:
*
* HAVE_STRDUP
* defined ==> use strdup()
* undefined ==> do not call or cannot call strdup()
*/
/*
* Copyright (c) 1999 by Landon Curt Noll. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright, this permission notice and text
* this comment, and the disclaimer below appear in all of the following:
*
* supporting documentation
* source copies
* source works derived from this source
* binaries derived from this source or from derived source
*
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* chongo was here /\../\
*/
#include <string.h>
int
main(void)
{
#if defined(HAVE_NO_STRDUP)
printf("#undef HAVE_STRDUP /* no */\n");
#else /* HAVE_NO_STRDUP */
char *p;
p = strdup("#define HAVE_STRDUP /* yes */");
if (p != NULL) {
printf("%s\n", p);
}
#endif /* HAVE_NO_STRDUP */
/* exit(0); */
return 0;
}

View File

@@ -36,17 +36,33 @@ gziped (or compressed) tar file).
You should send submissions to:
calc-tester@postofc.corp.sgi.com
calc-tester at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
Thanks for considering submitting code to calc. Calc is a collective
work by a number of people. It would not be what it is today without
your efforts and submissions!
Calc bug reports, however, should be sent to:
calc-bugs at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
See the BUGS file or try the help command:
help bugs
for details on bug reporting.
=-=
One may join the calc testing group by sending a request to:
calc-tester-request@postofc.corp.sgi.com
calc-tester-request at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
Your message body (not the subject) should consist of:

View File

@@ -2,7 +2,11 @@ Credits
The majority of calc was written by David I. Bell.
Calc archives and calc-tester mailing list maintained by Landon Curt Noll.
The Calc primary mirror, calc mailing list and calc bug report
processing is performed by Landon Curt Noll.
Landon Curt Noll maintains the master reference source, performs
release control functions as well as other calc maintenance functions.
Thanks for suggestions and encouragement from Peter Miller,
Neil Justusson, and Landon Noll.

View File

@@ -3,6 +3,5 @@ s/NUMBER[ ]*\*/int /
s/NUMBER/int/
s/STRINGHEAD/int/
s/\(".*",.*,.*\),.*,.*,.*,.*,/\1, 0, 0, 0, 0,/
s/showbuiltins/main/
s/[ ][ ]*$//
p

View File

@@ -5,10 +5,22 @@ Calc Todo Items:
Code contributions are welcome. Send patches to:
calc-tester@postofc.corp.sgi.com
calc-tester at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
See also the 'wishlist' help files for the calc enhancement wish list.
Calc bug reports, however, should send to:
calc-tester at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
see the BUGS file or try the calc command:
help bugs
=-=
Very High priority items:
@@ -50,6 +62,8 @@ Very High priority items:
* Fix any 'Known bugs' as noted in the BUGS file or as
displayed by 'calc help bugs'.
* Copyleft calc and place it under a LGPL.
=-=
High priority items:
@@ -79,10 +93,9 @@ High priority items:
then a $PAGER should be forked and execed after doing things such
as closing open file descriptors that the $PAGER does not need.
* Inspect changes made since the last major calc release (the
initial x.y.z version ... prior to any t sub-version) to help
ensure that they have not introduced new or re-introduced old bugs
into calc.
* The arg passdown to the lower level Makfiles should be reviewed
to determine which items really need to be passed down. The lower
level Makefiles should default to the shipped values.
* Consider using configure to build the calc Makefile.

View File

@@ -4,11 +4,19 @@ Calc Enhancement Wish List:
interesting calc scripts that you would like you see included in
future distributions to:
calc-tester@postofc.corp.sgi.com
calc-tester at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
The following items are in the calc wish list. Programs like this
can be extended and improved forever.
Calc bug repoers, however, should be sent to:
calc-bugs at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
See the 'todo' help file for higher priority todo items.
=-=

5
hist.c
View File

@@ -31,6 +31,11 @@
#include "terminal.h"
#include "have_string.h"
#include "have_strdup.h"
#if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */
#if defined(USE_TERMIOS)
# include <termios.h>

View File

@@ -33,7 +33,9 @@ the calc language, and/or because the authors thought them to be useful!
If you write something that you think is useful, please send it to:
calc-tester@postofc.corp.sgi.com
calc-tester at postofc dot corp dot sgi dot com
[[ Replace 'at' with @, 'dot' is with . and remove the spaces ]]
By convention, a lib file only defines and/or initializes functions,
objects and variables. (The regress.cal and testxxx.cal regression test

View File

@@ -1694,6 +1694,7 @@ define test_obj()
{
static obj surd a;
static obj surd b;
local PP;
print '1800: Beginning object test';
@@ -1731,7 +1732,10 @@ define test_obj()
vrfy(a <= a, '1828: a < a');
vrfy(isobj(a) == 1, '1829: isobj(a) == 1');
print '1830: Ending object test';
obj pt {x,y}, PP = obj pair {A,B} = {obj pt, obj pt};
print '1830: obj pt {x,y}, PP = obj pair {A,B} = {obj pt, obj pt}';
print '1831: Ending object test';
}
print '028: parsed test_obj()';
@@ -2867,7 +2871,7 @@ print '053: parsed test_frem()';
*/
define test_error()
{
local strx, e99, list1, e999;
local strx, e99, list1, e9999;
local a, b, c, n, x; /* used by newerror() */
print '3600: Beginning test_error';
@@ -3040,11 +3044,12 @@ define test_error()
'3710: newerror() == newerror("???")');
vrfy(newerror("") == newerror(),
'3711: newerror("") == newerror()');
e999 = error(999);
print '3712: e999 = error(999)';
vrfy(errno() == 999, '3713: errno() == 999');
vrfy(error() == e999, '3714: error() == e999');
vrfy(strerror() == "Error 999", '3715: strerror() == "Error 999"');
e9999 = error(9999);
print '3712: e9999 = error(9999)';
vrfy(errno() == 9999, '3713: errno() == 9999');
vrfy(error() == e9999, '3714: error() == e9999');
vrfy(strerror() == "Unknown error 9999",
'3715: strerror() == "Unknown error 9999"');
x = newerror("Alpha");
print '3716: x = newerror("Alpha")';
n = iserror(x);
@@ -3052,10 +3057,11 @@ define test_error()
vrfy(errno() == n, '3718: errno() == n');
vrfy(error() == x, '3719: error() == x');
vrfy(strerror() == "Alpha", '3720: strerror() == "Alpha"');
vrfy(errno(999) == n, '3721: errno() == n');
vrfy(errno() == 999, '3722: errno() == 999');
vrfy(error() == e999, '3723: error() == e999');
vrfy(strerror() == "Error 999", '3724: strerror() == "Error 999"');
vrfy(errno(9999) == n, '3721: errno() == n');
vrfy(errno() == 9999, '3722: errno() == 9999');
vrfy(error() == e9999, '3723: error() == e9999');
vrfy(strerror() == "Unknown error 9999",
'3724: strerror() == "Unknown error 9999"');
a = 1/0;
print '3725: a = 1/0';
vrfy(strerror() == "Division by zero",
@@ -4687,8 +4693,8 @@ define test_commaeq()
/*
* matrix assignment
*/
mat A[3] = {1,2,3}, B[2] = {1,2};
print '5625: mat A[3] = {1,2,3}, B[2] = {1,2}';
mat A[3] = {1,2,3}, mat B[2] = {1,2};
print '5625: mat A[3] = {1,2,3}, mat B[2] = {1,2}';
vrfy(A[0] == 1, '5626: A[0] == 1');
vrfy(B[1] == 2, '5627: B[1] == 2');
@@ -4916,8 +4922,8 @@ define test_assign(base, work)
print base+3: ': X5800 = base+3';
Y5800 = base+4;
print base+4: ': Y5800 = base+4';
obj xy5800 A={1,2}, B={3,4};
print base+5: ': obj xy5800 A={1,2}, B={3,4}';
obj xy5800 A={1,2}, obj xy5800 B={3,4};
print base+5: ': obj xy5800 A={1,2}, obj xy5000 B={3,4}';
/*
* test assignment
@@ -7372,7 +7378,7 @@ vrfy(X5800 == (obj xy5800 = {3,9}),
'5859: X5800 == (obj xy5800 = {3,9})');
vrfy(errno() > 0, '5860: errno() > 0');
vrfy(strerror() == "Incompatible types for =",
'5861: strerror() == "Incompatible types for ="');
'5861: strerror() == "Incompatible types for ="');
X5800 = 2;
print '5862: X5800 = 2';
vrfy(X5800 == (obj xy5800 = {2,0}),
@@ -7381,7 +7387,10 @@ X5800 = obj xy5800 = {1,2};
print '5864: X5800 = obj xy5800 = {1,2}';
vrfy(X5800 == (obj xy5800 = {1,2}),
'5865: X5800 == (obj xy5800 = {1,2})');
print '5866: End of 5800 sequence';
define f5800(a8500 = mat[2] = {3,4}) = 5 * a8500;
print '5866: define f5800(a8500 = mat[2] = {3,4}) = 5 * a8500;'
vrfy(f5800() == (mat[] = {15,20}),'5867: f5800() == (mat[] = {15,20})');
print '5868: End of 5800 sequence';
print;
return test_is();

View File

@@ -34,6 +34,11 @@
#include "symbol.h"
#include "func.h"
#include "have_strdup.h"
#if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
@@ -313,17 +318,16 @@ initenv(void)
char *c;
/* determine the $CALCPATH value */
c = getenv(CALCPATH);
calcpath = ((no_env || c == NULL) ? NULL : strdup(c));
c = (no_env ? NULL : getenv(CALCPATH));
calcpath = (c ? strdup(c) : NULL);
if (calcpath == NULL)
calcpath = DEFAULTCALCPATH;
/* determine the $CALCRC value */
c = getenv(CALCRC);
calcrc = ((no_env || c == NULL) ? NULL : strdup(c));
if (calcrc == NULL) {
c = (no_env ? NULL : getenv(CALCRC));
calcrc = (c ? strdup(c) : NULL);
if (calcrc == NULL)
calcrc = DEFAULTCALCRC;
}
if (strlen(calcrc) > MAX_CALCRC) {
math_error("The $CALCRC variable is longer than %d chars",
MAX_CALCRC);
@@ -331,15 +335,14 @@ initenv(void)
}
/* determine the $CALCBINDINGS value */
c = getenv(CALCBINDINGS);
calcbindings = ((no_env || c == NULL) ? NULL : strdup(c));
if (calcbindings == NULL) {
c = (no_env ? NULL : getenv(CALCBINDINGS));
calcbindings = (c ? strdup(c) : NULL);
if (calcbindings == NULL)
calcbindings = DEFAULTCALCBINDINGS;
}
/* determine the $HOME value */
c = getenv(HOME);
home = ((no_env || c == NULL) ? NULL : strdup(c));
c = (no_env ? NULL : getenv(HOME));
home = (c ? strdup(c) : NULL);
if (home == NULL || home[0] == '\0') {
ent = (struct passwd *)getpwuid(geteuid());
if (ent == NULL) {
@@ -351,16 +354,15 @@ initenv(void)
}
/* determine the $PAGER value */
c = getenv(PAGER);
pager = ((no_env || c == NULL) ? NULL : strdup(c));
if (pager == NULL || *pager == '\0') {
c = (no_env ? NULL : getenv(PAGER));
pager = (c ? strdup(c) : NULL);
if (pager == NULL || *pager == '\0')
pager = DEFAULTCALCPAGER;
}
/* determine the $SHELL value */
c = getenv(SHELL);
shell = ((no_env || c == NULL) ? NULL : strdup(c));
if (shell == NULL)
c = (no_env ? NULL : getenv(SHELL));
shell = (c ? strdup(c) : NULL);
if (shell == NULL || *shell == '\0')
shell = DEFAULTSHELL;
}
@@ -431,3 +433,45 @@ run_state_name(run state)
}
return "RUN_invalid";
}
/*
* calc_strdup - calc interface to provide or simulate strdup()
*/
char *
calc_strdup(CONST char *s1)
{
#if defined(HAVE_STRDUP)
return strdup(s1);
#else /* HAVE_STRDUP */
char *ret; /* return string */
/*
* firewall
*/
if (s1 == NULL) {
return NULL;
}
/*
* allocate duplicate storage
*/
ret = (char *)malloc(sizeof(char) * (strlen(s1)+1));
/*
* if we have storage, duplicate the string
*/
if (ret != NULL) {
strcpy(ret, s1);
}
/*
* return the new string, or NULL if malloc failed
*/
return ret;
#endif /* HAVE_STRDUP */
}

View File

@@ -130,10 +130,12 @@ removelistfirst(LIST *lp, VALUE *vp)
{
if (lp->l_count == 0) {
vp->v_type = V_NULL;
vp->v_subtype = V_NOSUBTYPE;
return;
}
*vp = lp->l_first->e_value;
lp->l_first->e_value.v_type = V_NULL;
lp->l_first->e_value.v_type = V_NOSUBTYPE;
removelistelement(lp, lp->l_first);
}
@@ -151,10 +153,12 @@ removelistlast(LIST *lp, VALUE *vp)
{
if (lp->l_count == 0) {
vp->v_type = V_NULL;
vp->v_subtype = V_NOSUBTYPE;
return;
}
*vp = lp->l_last->e_value;
lp->l_last->e_value.v_type = V_NULL;
lp->l_last->e_value.v_subtype = V_NOSUBTYPE;
removelistelement(lp, lp->l_last);
}
@@ -181,6 +185,7 @@ removelistmiddle(LIST *lp, long index, VALUE *vp)
}
*vp = ep->e_value;
ep->e_value.v_type = V_NULL;
ep->e_value.v_subtype = V_NOSUBTYPE;
removelistelement(lp, ep);
}

View File

@@ -62,8 +62,8 @@
/*
* have the compiler try its hand with unsigned and signed long longs
*/
unsigned long long val = 4294967297ULL;
long long val2 = -4294967297LL;
unsigned long long val = 0x1234567890123456ULL;
long long val2 = -1311768467284833366LL; /* -0x1234567890123456 */
int
@@ -90,14 +90,20 @@ main(int argc, char **argv)
if (longlong_bits > 0) {
/*
* if size is longer than an unsigned long, use it
* if size is longer than an unsigned long,
* and the negative 'long long' works, then use long long's
*/
if (longlong_bits > sizeof(unsigned long)*8) {
if (longlong_bits > sizeof(unsigned long)*8 && val2 < 0) {
/* use long long length */
printf("#define HAVE_LONGLONG\n");
printf("#define LONGLONG_BITS %d /* yes */\n",
longlong_bits);
printf("\n/* does %%lld work or does %%ld? */\n");
printf("#if defined(CHECK_L_FORMAT)\n");
printf("long long l_format = %ld;\n", val);
printf("#endif /* CHECK_L_FORMAT */\n");
}
}
/* exit(0); */

View File

@@ -154,6 +154,7 @@ matmul(MATRIX *m1, MATRIX *m2)
for (i1 = 0; i1 < max1; i1++) {
for (i2 = 0; i2 < max2; i2++) {
sum.v_type = V_NULL;
sum.v_subtype = V_NOSUBTYPE;
v1 = &m1->m_table[i1 * maxindex];
v2 = &m2->m_table[i2];
for (index = 0; index < maxindex; index++) {
@@ -202,6 +203,7 @@ matsquare(MATRIX *m)
for (i1 = 0; i1 < max; i1++) {
for (i2 = 0; i2 < max; i2++) {
sum.v_type = V_NULL;
sum.v_subtype = V_NOSUBTYPE;
v1 = &m->m_table[i1 * max];
v2 = &m->m_table[i2];
for (index = 0; index < max; index++) {
@@ -405,6 +407,7 @@ matscale(MATRIX *m, long n)
if (n == 0)
return matcopy(m);
temp.v_type = V_NUM;
temp.v_subtype = V_NOSUBTYPE;
temp.v_num = itoq(n);
res = matalloc(m->m_size);
*res = *m;
@@ -436,6 +439,7 @@ matshift(MATRIX *m, long n)
if (n == 0)
return matcopy(m);
temp.v_type = V_NUM;
temp.v_subtype = V_NOSUBTYPE;
temp.v_num = itoq(n);
res = matalloc(m->m_size);
*res = *m;
@@ -1062,6 +1066,7 @@ matdet(MATRIX *m)
while (!testvalue(val)) {
if (--i <= 0) {
tmp1.v_type = V_NUM;
tmp1.v_subtype = V_NOSUBTYPE;
tmp1.v_num = qlink(&_qzero_);
matfree(m);
return tmp1;

15
obj.c
View File

@@ -141,6 +141,10 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
VALUE tmp; /* temp value */
char name[SYMBOLSIZE+1]; /* full name of user routine to call */
/* initialize VALUEs */
val.v_subtype = V_NOSUBTYPE;
tmp.v_subtype = V_NOSUBTYPE;
if ((unsigned)action > OBJ_MAXFUNC) {
math_error("Illegal action for object call");
/*NOTREACHED*/
@@ -404,6 +408,7 @@ objpowi(VALUE *vp, NUMBER *q)
case 1:
res.v_obj = objcopy(vp->v_obj);
res.v_type = V_OBJ;
res.v_subtype = V_NOSUBTYPE;
return res;
case -1:
return objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE);
@@ -579,6 +584,16 @@ findelement(char *name)
}
/*
* Returns the name of object type with specified index
*/
char *
objtypename(unsigned long index)
{
return namestr(&objectnames, (long)index);
}
/*
* Return the value table offset to be used for an object element name.
* This converts the element index from the element table into an offset

112
opcodes.c
View File

@@ -230,6 +230,7 @@ o_argvalue(FUNC *fp, int argcount, VALUE *args)
qfree(stack->v_num);
stack->v_num = itoq((long) argcount);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
index = qtoi(vp->v_num) - 1;
@@ -292,6 +293,7 @@ o_string(FUNC *fp, long arg)
stack++;
stack->v_str = slink(findstring(arg));
stack->v_type = V_STR;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -300,6 +302,7 @@ o_undef(void)
{
stack++;
stack->v_type = V_NULL;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -940,6 +943,7 @@ o_swap(void)
/*NOTREACHED*/
}
stack->v_type = V_NULL;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -958,11 +962,13 @@ o_add(void)
v2 = v2->v_addr;
if (v1->v_type == V_OCTET) {
w1.v_type = V_NUM;
w1.v_subtype = V_NOSUBTYPE;
w1.v_num = itoq(*v1->v_octet);
v1 = &w1;
}
if (v2->v_type == V_OCTET) {
w2.v_type = V_NUM;
w2.v_subtype = V_NOSUBTYPE;
w2.v_num = itoq(*v2->v_octet);
v2 = &w2;
}
@@ -993,11 +999,13 @@ o_sub(void)
v2 = v2->v_addr;
if (v1->v_type == V_OCTET) {
w1.v_type = V_NUM;
w1.v_subtype = V_NOSUBTYPE;
w1.v_num = itoq((unsigned char) *v1->v_octet);
v1 = &w1;
}
if (v2->v_type == V_OCTET) {
w2.v_type = V_NUM;
w2.v_subtype = V_NOSUBTYPE;
w2.v_num = itoq((unsigned char) *v2->v_octet);
v2 = &w2;
}
@@ -1028,11 +1036,13 @@ o_mul(void)
v2 = v2->v_addr;
if (v1->v_type == V_OCTET) {
w1.v_type = V_NUM;
w1.v_subtype = V_NOSUBTYPE;
w1.v_num = itoq(*v1->v_octet);
v1 = &w1;
}
if (v2->v_type == V_OCTET) {
w2.v_type = V_NUM;
w2.v_subtype = V_NOSUBTYPE;
w2.v_num = itoq(*v2->v_octet);
v2 = &w2;
}
@@ -1081,11 +1091,13 @@ o_div(void)
v2 = v2->v_addr;
if (v1->v_type == V_OCTET) {
w1.v_type = V_NUM;
w1.v_subtype = V_NOSUBTYPE;
w1.v_num = itoq(*v1->v_octet);
v1 = &w1;
}
if (v2->v_type == V_OCTET) {
w2.v_type = V_NUM;
w2.v_subtype = V_NOSUBTYPE;
w2.v_num = itoq(*v2->v_octet);
v2 = &w2;
}
@@ -1113,6 +1125,7 @@ o_quo(void)
if (v2->v_type == V_ADDR)
v2 = v2->v_addr;
null.v_type = V_NULL;
null.v_subtype = V_NOSUBTYPE;
quovalue(v1, v2, &null, &tmp);
freevalue(stack--);
freevalue(stack);
@@ -1133,6 +1146,7 @@ o_mod(void)
if (v2->v_type == V_ADDR)
v2 = v2->v_addr;
null.v_type = V_NULL;
null.v_subtype = V_NOSUBTYPE;
modvalue(v1, v2, &null, &tmp);
freevalue(stack--);
freevalue(stack);
@@ -1175,7 +1189,9 @@ o_quomod(void)
}
valquo.v_type = V_NUM;
valquo.v_subtype = V_NOSUBTYPE;
valmod.v_type = V_NUM;
valmod.v_subtype = V_NOSUBTYPE;
res = qquomod(v1->v_num, v2->v_num, &valquo.v_num, &valmod.v_num);
stack -= 2;
if (stack->v_type == V_NUM)
@@ -1185,6 +1201,7 @@ o_quomod(void)
qfree(stack->v_num);
stack->v_num = (res ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
freevalue(v3);
freevalue(v4);
@@ -1289,6 +1306,7 @@ o_not(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qzero_) : qlink(&_qone_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1335,6 +1353,7 @@ o_negate(void)
qfree(stack->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
negvalue(vp, &tmp);
@@ -1440,6 +1459,7 @@ o_abs(void)
qfree(stack->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1459,6 +1479,7 @@ o_norm(void)
qfree(stack->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
normvalue(vp, &tmp);
@@ -1483,6 +1504,7 @@ o_square(void)
qfree(stack->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
squarevalue(vp, &tmp);
@@ -1503,6 +1525,7 @@ o_test(void)
i = testvalue(vp);
freevalue(stack);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = i ? qlink(&_qone_) : qlink(&_qzero_);
}
@@ -1534,6 +1557,7 @@ o_links(void)
if (!haveaddress)
links--;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = itoq(links);
}
@@ -1584,6 +1608,7 @@ o_bit (void)
stack->v_type = V_NUM;
stack->v_num = itoq(r);
}
stack->v_subtype = V_NOSUBTYPE;
}
static void
@@ -1628,6 +1653,7 @@ o_highbit (void)
return;
default:
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = itoq(index);
}
}
@@ -1679,6 +1705,7 @@ o_lowbit (void)
return;
default:
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = itoq(index);
}
}
@@ -1772,6 +1799,7 @@ o_istype(void)
freevalue(stack);
stack->v_num = itoq((long) r);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1788,6 +1816,7 @@ o_isint(void)
freevalue(stack);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
if (qisint(vp->v_num))
@@ -1798,6 +1827,7 @@ o_isint(void)
qfree(stack->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1822,10 +1852,12 @@ o_isnum(void)
freevalue(stack);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
stack->v_num = qlink(&_qone_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1841,10 +1873,12 @@ o_ismat(void)
freevalue(stack);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
freevalue(stack);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = qlink(&_qone_);
}
@@ -1862,6 +1896,7 @@ o_islist(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1878,6 +1913,7 @@ o_isobj(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1894,6 +1930,7 @@ o_isstr(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1910,6 +1947,7 @@ o_isfile(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1926,6 +1964,7 @@ o_isrand(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1942,6 +1981,7 @@ o_israndom(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1958,6 +1998,7 @@ o_isconfig(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1976,6 +2017,7 @@ o_ishash(void)
freevalue(stack);
stack->v_num = itoq((long) r);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -1992,6 +2034,7 @@ o_isassoc(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2012,6 +2055,7 @@ o_isblock(void)
freevalue(stack);
stack->v_num = itoq(r);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2028,6 +2072,7 @@ o_isoctet(void)
freevalue(stack);
stack->v_num = itoq(r);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2050,6 +2095,7 @@ o_isptr(void)
freevalue(stack);
stack->v_num = itoq(r);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2079,6 +2125,7 @@ o_isdefined(void)
freevalue(stack);
stack->v_num = itoq(r);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2099,6 +2146,7 @@ o_isobjtype(void)
freevalue(stack);
stack->v_num = itoq(index >= 0);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2122,6 +2170,7 @@ o_issimple(void)
freevalue(stack);
stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2138,11 +2187,13 @@ o_isodd(void)
qfree(stack->v_num);
stack->v_num = qlink(&_qone_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
freevalue(stack);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2159,11 +2210,13 @@ o_iseven(void)
qfree(stack->v_num);
stack->v_num = qlink(&_qone_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
freevalue(stack);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2180,11 +2233,13 @@ o_isreal(void)
qfree(stack->v_num);
stack->v_num = qlink(&_qone_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
freevalue(stack);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2200,11 +2255,13 @@ o_isnull(void)
freevalue(stack);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
freevalue(stack);
stack->v_num = qlink(&_qone_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2221,6 +2278,7 @@ o_re(void)
if (stack->v_type == V_ADDR) {
stack->v_num = qlink(vp->v_num);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
return;
}
@@ -2233,6 +2291,7 @@ o_re(void)
comfree(stack->v_com);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2250,6 +2309,7 @@ o_im(void)
qfree(stack->v_num);
stack->v_num = qlink(&_qzero_);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
if (vp->v_type != V_COM) {
@@ -2261,6 +2321,7 @@ o_im(void)
comfree(stack->v_com);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2277,6 +2338,7 @@ o_conjugate(void)
if (stack->v_type == V_ADDR) {
stack->v_num = qlink(vp->v_num);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
return;
}
@@ -2382,6 +2444,7 @@ o_sgn(void)
qfree(vp->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
return;
}
sgnvalue(vp, &tmp);
@@ -2410,6 +2473,7 @@ o_numerator(void)
qfree(stack->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2431,6 +2495,7 @@ o_denominator(void)
qfree(stack->v_num);
stack->v_num = q;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2687,6 +2752,7 @@ o_eq(void)
freevalue(stack);
stack->v_num = itoq((long) (r == 0));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2707,6 +2773,7 @@ o_ne(void)
freevalue(stack);
stack->v_num = itoq((long) (r != 0));
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -2727,15 +2794,15 @@ o_le(void)
freevalue(stack);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
if (tmp.v_type == V_NUM) {
stack->v_num = !qispos(tmp.v_num) ? qlink(&_qone_):
qlink(&_qzero_);
}
else if (tmp.v_type == V_COM) {
} else if (tmp.v_type == V_COM) {
stack->v_num = qlink(&_qzero_);
}
else
} else {
stack->v_type = V_NULL;
}
freevalue(&tmp);
}
@@ -2756,14 +2823,13 @@ o_ge(void)
freevalue(stack--);
freevalue(stack);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
if (tmp.v_type == V_NUM) {
stack->v_num = !qisneg(tmp.v_num) ? qlink(&_qone_):
qlink(&_qzero_);
}
else if (tmp.v_type == V_COM) {
} else if (tmp.v_type == V_COM) {
stack->v_num = qlink(&_qzero_);
}
else {
} else {
stack->v_type = V_NULL;
}
freevalue(&tmp);
@@ -2786,15 +2852,15 @@ o_lt(void)
freevalue(stack--);
freevalue(stack);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
if (tmp.v_type == V_NUM) {
stack->v_num = qisneg(tmp.v_num) ? qlink(&_qone_):
qlink(&_qzero_);
}
else if (tmp.v_type == V_COM) {
} else if (tmp.v_type == V_COM) {
stack->v_num = qlink(&_qzero_);
}
else
} else {
stack->v_type = V_NULL;
}
freevalue(&tmp);
}
@@ -2815,15 +2881,15 @@ o_gt(void)
freevalue(stack--);
freevalue(stack);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
if (tmp.v_type == V_NUM) {
stack->v_num = qispos(tmp.v_num) ? qlink(&_qone_):
qlink(&_qzero_);
}
else if (tmp.v_type == V_COM) {
} else if (tmp.v_type == V_COM) {
stack->v_num = qlink(&_qzero_);
}
else
} else {
stack->v_type = V_NULL;
}
freevalue(&tmp);
}
@@ -2886,6 +2952,7 @@ o_postinc(void)
if (stack->v_type == V_OCTET) {
stack[1] = stack[0];
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = itoq((long) stack->v_octet[0]);
stack++;
stack->v_octet[0]++;
@@ -2938,8 +3005,8 @@ o_postdec(void)
freevalue(vp);
*vp = tmp;
stack->v_type = V_ADDR;
stack->v_addr = vp;
stack->v_subtype = V_NOSUBTYPE;
stack->v_addr = vp;
}
@@ -3067,6 +3134,7 @@ o_zero(void)
{
stack++;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = qlink(&_qzero_);
}
@@ -3076,6 +3144,7 @@ o_one(void)
{
stack++;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = qlink(&_qone_);
}
@@ -3162,6 +3231,7 @@ o_getepsilon(void)
{
stack++;
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
stack->v_num = qlink(conf->epsilon);
}
@@ -3185,6 +3255,7 @@ o_setepsilon(void)
if (stack->v_type == V_NUM)
qfree(newep);
stack->v_type = V_NUM;
stack->v_subtype = V_NOSUBTYPE;
}
@@ -3254,6 +3325,7 @@ updateoldvalue(FUNC *fp)
freevalue(&oldvalue);
oldvalue = fp->f_savedvalue;
fp->f_savedvalue.v_type = V_NULL;
fp->f_savedvalue.v_subtype = V_NOSUBTYPE;
}
@@ -3275,6 +3347,7 @@ error_value(int e)
/*NOTREACHED*/
}
res.v_type = (short) -e;
res.v_subtype = V_NOSUBTYPE;
return res;
}
@@ -3773,11 +3846,14 @@ dumpop(unsigned long *pc)
return 3;
case OP_PRINT: case OP_JUMPZ: case OP_JUMPNZ: case OP_JUMP:
case OP_CONDORJUMP: case OP_CONDANDJUMP: case OP_CASEJUMP:
case OP_INITSTATIC: case OP_MATCREATE: case OP_OBJCREATE:
case OP_INITSTATIC: case OP_MATCREATE:
case OP_SHOW: case OP_ELEMINIT: case OP_ELEMADDR:
case OP_ELEMVALUE: case OP_JUMPNN:
printf(" %ld\n", *pc);
return 2;
case OP_OBJCREATE:
printf(" %s\n", objtypename(*pc));
return 2;
case OP_NUMBER: case OP_IMAGINARY:
qprintf(" %r", constvalue(*pc));
printf("\n");

15
qmath.c
View File

@@ -1382,10 +1382,23 @@ qalloc(void)
}
freeNum[NNALLOC - 1].next = NULL;
freeNum[NNALLOC - 1].links = 0;
for (temp = freeNum + NNALLOC - 2; temp >= freeNum; --temp) {
/*
* We prevent the temp pointer from walking behind freeNum
* by stopping one short of the end and running the loop one
* more time.
*
* We would stop the loop with just temp >= freeNum, but
* doing this helps make code checkers such as insure happy.
*/
for (temp = freeNum + NNALLOC - 2; temp > freeNum; --temp) {
temp->next = temp + 1;
temp->links = 0;
}
/* run the loop manually one last time */
temp->next = temp + 1;
temp->links = 0;
blockcount++;
if (firstNums == NULL) {
newfn = (NUMBER **) malloc(blockcount * sizeof(NUMBER *));

3
seed.c
View File

@@ -53,9 +53,10 @@
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/resource.h>
#include <setjmp.h>
#include "qmath.h"
#include "longbits.h"

View File

@@ -979,10 +979,23 @@ stralloc(void)
}
freeStr[STRALLOC - 1].s_next = NULL;
freeStr[STRALLOC - 1].s_links = 0;
for (temp = freeStr + STRALLOC - 2; temp >= freeStr; --temp) {
/*
* We prevent the temp pointer from walking behind freeStr
* by stopping one short of the end and running the loop one
* more time.
*
* We would stop the loop with just temp >= freeStr, but
* doing this helps make code checkers such as insure happy.
*/
for (temp = freeStr + STRALLOC - 2; temp > freeStr; --temp) {
temp->s_next = temp + 1;
temp->s_links = 0;
}
/* run the loop manually one last time */
temp->s_next = temp + 1;
temp->s_links = 0;
blockcount++;
if (firstStrs == NULL) {
newfn = (STRING **) malloc( blockcount * sizeof(STRING *));

View File

@@ -175,7 +175,10 @@ showglobals(void)
printf("\n");
}
}
printf(count ? "\n" : "No real-valued global variables\n");
if (count == 0) {
printf("No real-valued global variables\n");
}
putchar('\n');
}
@@ -342,8 +345,17 @@ freeglobals(void)
GLOBAL *sp; /* current global symbol pointer */
long count; /* number of global variables freed */
/*
* We prevent the hp pointer from walking behind globalhash
* by stopping one short of the end and running the loop one
* more time.
*
* We could stop the loop with just hp >= globalhash, but stopping
* short and running the loop one last time manually helps make
* code checkers such as insure happy.
*/
count = 0;
for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) {
for (hp = &globalhash[HASHSIZE-1]; hp > globalhash; hp--) {
for (sp = *hp; sp; sp = sp->g_next) {
if (sp->g_value.v_type != V_NULL) {
freevalue(&sp->g_value);
@@ -351,6 +363,13 @@ freeglobals(void)
}
}
}
/* run the loop manually one last time */
for (sp = *hp; sp; sp = sp->g_next) {
if (sp->g_value.v_type != V_NULL) {
freevalue(&sp->g_value);
count++;
}
}
}
/*
@@ -539,14 +558,22 @@ unscope(void)
register GLOBAL *sp; /* current global symbol pointer */
GLOBAL *prevsp; /* previous kept symbol pointer */
for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) {
/*
* We prevent the hp pointer from walking behind globalhash
* by stopping one short of the end and running the loop one
* more time.
*
* We could stop the loop with just hp >= globalhash, but stopping
* short and running the loop one last time manually helps make
* code checkers such as insure happy.
*/
for (hp = &globalhash[HASHSIZE-1]; hp > globalhash; hp--) {
prevsp = NULL;
for (sp = *hp; sp; sp = sp->g_next) {
if ((sp->g_filescope == SCOPE_GLOBAL) ||
(sp->g_filescope < filescope) ||
((sp->g_filescope == filescope) &&
(sp->g_funcscope <= funcscope)))
{
(sp->g_funcscope <= funcscope))) {
prevsp = sp;
continue;
}
@@ -561,6 +588,26 @@ unscope(void)
*hp = sp->g_next;
}
}
/* run the loop manually one last time */
prevsp = NULL;
for (sp = *hp; sp; sp = sp->g_next) {
if ((sp->g_filescope == SCOPE_GLOBAL) ||
(sp->g_filescope < filescope) ||
((sp->g_filescope == filescope) &&
(sp->g_funcscope <= funcscope))) {
prevsp = sp;
continue;
}
/*
* This symbol needs removing.
*/
addstatic(sp);
if (prevsp)
prevsp->g_next = sp->g_next;
else
*hp = sp->g_next;
}
}

14
value.c
View File

@@ -22,8 +22,6 @@
#define LINELEN 80 /* length of a typical tty line */
extern int sys_nerr;
/*
* Free a value and set its type to undefined.
*
@@ -194,6 +192,7 @@ copyvalue(VALUE *oldvp, VALUE *newvp)
break;
case V_OCTET:
newvp->v_type = V_NUM;
newvp->v_subtype = V_NOSUBTYPE;
newvp->v_num = itoq((long) *oldvp->v_octet);
break;
case V_NBLOCK:
@@ -312,6 +311,7 @@ negvalue(VALUE *vp, VALUE *vres)
return;
case V_OCTET:
vres->v_type = V_NUM;
vres->v_subtype = V_NOSUBTYPE;
vres->v_num = itoq(- (long) *vp->v_octet);
return;
@@ -343,6 +343,7 @@ addnumeric(VALUE *v1, VALUE *v2, VALUE *vres)
/*
* add numeric values
*/
vres->v_subtype = V_NOSUBTYPE;
switch (TWOVAL(v1->v_type, v2->v_type)) {
case TWOVAL(V_NUM, V_NUM):
vres->v_num = qqadd(v1->v_num, v2->v_num);
@@ -2420,9 +2421,11 @@ acceptvalue(VALUE *v1, VALUE *v2)
if (fp) {
++stack;
stack->v_type = V_ADDR;
stack->v_subtype = V_NOSUBTYPE;
stack->v_addr = v1;
++stack;
stack->v_type = V_ADDR;
stack->v_subtype = V_NOSUBTYPE;
stack->v_addr = v2;
calculate(fp, 2);
ret = testvalue(stack);
@@ -2447,9 +2450,11 @@ precvalue(VALUE *v1, VALUE *v2)
if (fp) {
++stack;
stack->v_type = V_ADDR;
stack->v_subtype = V_NOSUBTYPE;
stack->v_addr = v1;
++stack;
stack->v_type = V_ADDR;
stack->v_subtype = V_NOSUBTYPE;
stack->v_addr = v2;
calculate(fp, 2);
ret = testvalue(stack);
@@ -2632,6 +2637,7 @@ sgnvalue(VALUE *vp, VALUE *vres)
switch (vp->v_type) {
case V_NUM:
vres->v_num = qsign(vp->v_num);
vres->v_subtype = vp->v_subtype;
return;
case V_COM:
c = comalloc();
@@ -2641,9 +2647,11 @@ sgnvalue(VALUE *vp, VALUE *vres)
c->imag = qsign(vp->v_com->imag);
vres->v_com = c;
vres->v_type = V_COM;
vres->v_subtype = V_NOSUBTYPE;
return;
case V_OCTET:
vres->v_type = V_NUM;
vres->v_subtype = V_NOSUBTYPE;
vres->v_num = itoq((long) (*vp->v_octet != 0));
return;
case V_OBJ:
@@ -2694,7 +2702,7 @@ printvalue(VALUE *vp, int flags)
if (type < 0) {
if (userfunc("error_print", vp))
return;
if (-type >= sys_nerr)
if (-type >= E__BASE)
printf("Error %d", -type);
else
printf("System error %d", -type);

View File

@@ -451,6 +451,7 @@ extern int checkobject(char *name);
extern void showobjfuncs(void);
extern void showobjtypes(void);
extern int findelement(char *name);
extern char *objtypename(unsigned long index);
extern int objoffset(OBJECT *op, long index);

View File

@@ -18,7 +18,7 @@ static char *program;
#define MAJOR_VER 2 /* major version */
#define MINOR_VER 11 /* minor version */
#define MAJOR_PATCH 0 /* patch level or 0 if no patch */
#define MINOR_PATCH "9.4.1" /* test number or empty string if no patch */
#define MINOR_PATCH "9.4.5" /* test number or empty string if no patch */
/*
* calc version constants

83
zfunc.c
View File

@@ -1109,7 +1109,17 @@ zlog(ZVALUE z1, ZVALUE z2)
*/
val = _one_;
power = 0;
for (; zp >= squares; zp--, worth /= 2) {
/*
* We prevent the zp pointer from walking behind squares
* by stopping one short of the end and running the loop one
* more time.
*
* We could stop the loop with just zp >= squares, but stopping
* short and running the loop one last time manually helps make
* code checkers such as insure happy.
*/
for (; zp > squares; zp--, worth /= 2) {
if ((val.len + zp->len - 1) <= z1.len) {
zmul(val, *zp, &temp);
if (zrel(z1, temp) >= 0) {
@@ -1123,6 +1133,22 @@ zlog(ZVALUE z1, ZVALUE z2)
if (zp != squares)
zfree(*zp);
}
/* run the loop manually one last time */
if (zp == squares) {
if ((val.len + zp->len - 1) <= z1.len) {
zmul(val, *zp, &temp);
if (zrel(z1, temp) >= 0) {
zfree(val);
val = temp;
power += worth;
} else {
zfree(temp);
}
}
if (zp != squares)
zfree(*zp);
}
zfree(val);
return power;
}
@@ -1163,7 +1189,17 @@ zlog10(ZVALUE z)
*/
val = _one_;
power = 0;
for (; zp >= _tenpowers_; zp--, worth /= 2) {
/*
* We prevent the zp pointer from walking behind _tenpowers_
* by stopping one short of the end and running the loop one
* more time.
*
* We could stop the loop with just zp >= _tenpowers_, but stopping
* short and running the loop one last time manually helps make
* code checkers such as insure happy.
*/
for (; zp > _tenpowers_; zp--, worth /= 2) {
if ((val.len + zp->len - 1) <= z.len) {
zmul(val, *zp, &temp);
if (zrel(z, temp) >= 0) {
@@ -1175,6 +1211,20 @@ zlog10(ZVALUE z)
}
}
}
/* run the loop manually one last time */
if (zp == _tenpowers_) {
if ((val.len + zp->len - 1) <= z.len) {
zmul(val, *zp, &temp);
if (zrel(z, temp) >= 0) {
zfree(val);
val = temp;
power += worth;
} else {
zfree(temp);
}
}
}
zfree(val);
return power;
}
@@ -1281,11 +1331,21 @@ zfacrem(ZVALUE z1, ZVALUE z2, ZVALUE *rem)
worth *= 2;
count += worth;
}
/*
* Now back down the list of squares, and see if the lower powers
* will divide any more times.
*/
for (; zp >= squares; zp--, worth /= 2) {
/*
* We prevent the zp pointer from walking behind squares
* by stopping one short of the end and running the loop one
* more time.
*
* We could stop the loop with just zp >= squares, but stopping
* short and running the loop one last time manually helps make
* code checkers such as insure happy.
*/
for (; zp > squares; zp--, worth /= 2) {
if (zp->len <= z1.len) {
zdiv(z1, *zp, &temp1, &temp2, 0);
if (ziszero(temp2)) {
@@ -1300,6 +1360,23 @@ zfacrem(ZVALUE z1, ZVALUE z2, ZVALUE *rem)
if (zp != squares)
zfree(*zp);
}
/* run the loop manually one last time */
if (zp == squares) {
if (zp->len <= z1.len) {
zdiv(z1, *zp, &temp1, &temp2, 0);
if (ziszero(temp2)) {
temp3 = z1;
z1 = temp1;
temp1 = temp3;
count += worth;
}
zfree(temp1);
zfree(temp2);
}
if (zp != squares)
zfree(*zp);
}
*rem = z1;
return count;
}

View File

@@ -733,18 +733,18 @@ done: while (m > 0 && A[m - 1] == 0)
f = g = 0;
t = -1;
if (s) {
while (--i > 0 ) {
while (--i > 0) {
g = (FULL) *--a + (*--b >> 1 | f);
if (g != BASE1)
break;
f = *b & 1 ? TOPHALF : 0;
}
if (g == BASE && f == 0) {
while (i-- && (*a-- | *b--) == 0);
while ((--i > 0) && ((*--a | *--b) == 0));
t = (i > 0);
}
else if (g >= BASE)
} else if (g >= BASE) {
t = 1;
}
} else {
while (--i > 0) {
g = (FULL) *--a - (*--b >> 1 | f);

64
zmul.c
View File

@@ -280,6 +280,8 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans)
baseA = v1 + shift;
baseB = v1;
/*
* XXX - is this still an issue?
*
* Saber-C Version 3.1 says:
*
* W#26, Storing a bad pointer into auto variable dmul`baseC.
@@ -296,11 +298,13 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans)
* config("mul2", 2);
* pmod(3,a-1,a);
*
* [[ NOTE: The above code no longer invokes this code. ]]
*
* When this code is executed, shift == 6 and v2 is 3 shorts
* long (size2 == 2). This baseC points 3 shorts beyond the
* allocated end of v2.
*
* The stack was as follows:
* The stack was as follows: [[NOTE: line numbers may have changed]]
*
* domul(v1=0x2d93d8, size1=12,
* v2=0x2ded30, size2=2, ans=0x2ee8a8) at "zmul.c":313
@@ -314,6 +318,64 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans)
* evaluate(...) at "codegen.c":170
* getcommands(...) at "codegen.c":109
* main(...) at "calc.c":167
*
* The final domul() call point is the next executable line below.
*
****
*
* The insure tool also reports a problem at this position:
*
* [zmul.c:319] **COPY_BAD_RANGE**
* >> baseC = v2 + shift;
*
* Copying pointer which is out-of-range: v2 + shift
*
* [[NOTE: line numbers may have changed]]
*
* Pointer : 0x1400919cc
* Actual block : 0x140090c80 thru 0x140090def (368 bytes,92 elements)
* hp, allocated at:
* malloc()
* alloc() zmath.c, 221
* zmul() zmul.c, 73
* ztenpow() zfunc.c, 441
* str2q() qio.c, 537
* addnumber() const.c, 52
* eatnumber() token.c, 594
* gettoken() token.c, 319
* getcallargs() codegen.c, 2358
*
* Stack trace where the error occurred:
* domul() zmul.c, 319
* zmul() zmul.c, 74
* ztenpow() zfunc.c, 441
* str2q() qio.c, 537
* addnumber() const.c, 52
* eatnumber() token.c, 594
* gettoken() token.c, 319
* getcallargs() codegen.c, 2358
* getidexpr() codegen.c, 1998
* getterm() codegen.c, 1936
* getincdecexpr() codegen.c, 1820
* getreference() codegen.c, 1804
* getshiftexpr() codegen.c, 1758
* getandexpr() codegen.c, 1704
* getorexpr() codegen.c, 1682
* getproduct() codegen.c, 1654
* getsum() codegen.c, 1626
* getrelation() codegen.c, 1585
* getandcond() codegen.c, 1556
* getorcond() codegen.c, 1532
* getaltcond() codegen.c, 1499
* getassignment() codegen.c, 1442
* getopassignment() codegen.c, 1352
* getexprlist() codegen.c, 1318
* getstatement() codegen.c, 921
* evaluate() codegen.c, 219
* getcommands() codegen.c, 165
* main() calc.c, 321
*
* The final domul() call point is the next executable line below.
*/
/* ok to ignore on name domul`baseC */
baseC = v2 + shift;

View File

@@ -2527,7 +2527,8 @@ random_libcalc_cleanup(void)
static void
zfree_random(ZVALUE z)
{
if (z.v != h_ndefvec && z.v != h_rdefvec && z.v != h_rdefvec_2 &&
if (z.v != NULL &&
z.v != h_ndefvec && z.v != h_rdefvec && z.v != h_rdefvec_2 &&
z.v != h_nvec01 && z.v != h_rvec01 &&
z.v != h_nvec02 && z.v != h_rvec02 &&
z.v != h_nvec03 && z.v != h_rvec03 &&