development release newLISP v.9.2.10

Started by Lutz, December 17, 2007, 10:39:21 AM

Previous topic - Next topic

Lutz

#15
There are only 3 occurrences of RAND_MAX in the code base and all in nl-math.c. I will code around this introducing MY_RAND_MAX and set it conditionally in newlisp.h.



Lutz

pjot

#16
Thanks, this works now! The (rand) function is surviving the test. One remarks though:



1) There is still a redefinition in 'newlisp.h' of RAND_MAX at line 99-101, can you remove it?



Thanks!



Peter

pjot

#17
Lutz,



Now I found another issue but I also found the cause.



It seems that your change in (ends-with) crashes newlisp when calling this line from a program:

(ends-with "newlisp" "LISP" nil)


However, running in interactive mode, this line work well. But running from a program with shebang "#!/usr/bin/newlisp", the program creates a coredump.



Hunting down this issue I arrive at this piece of code in 'nl-liststr.c':

1312         /* append $ to the pattern for anchoring at the end */
1313         keydollar = alloca(klen + 4);
1314         *keydollar = '(';
1315         memcpy(keydollar + 1, key, klen);
1316         memcpy(keydollar + 1 + klen, ")$", klen);
1317         *(keydollar + klen + 3) = 0;
1318         klen = klen + 3;
1319     if((pos = searchBufferRegex(string, 0, keydollar, slen, options, &klen)) != -1)
1320                 {
1321                 if(pos + klen == slen)
1322                         return(trueCell);
1323                 }      
1324         }      


The program actually crashes when calling searchBufferRegex. The problem here is the usage of 'alloca'. From the Tru64Unix manpages:
Quote
  [Tru64 UNIX]  The alloca() function allocates the number of bytes of space

  specified by the size parameter in the stack frame of the caller. This

  space is automatically freed when the function that called the alloca()

  function returns to its caller. The contents of the memory is undefined.


From the Linux manpages:
Quote
BUGS

       The alloca() function is machine and compiler dependent. On many systems its  implementation

       is buggy. Its use is discouraged.



       On  many  systems  alloca()  cannot be used inside the list of arguments of a function call,

       because the stack space reserved by alloca() would appear on the stack in the middle of  the

       space for the function arguments.


If I change the 'alloca' for a plain 'malloc', everything runs fine and there is no crash. But the memory must be freed afterwards, of course.



Peter

Lutz

#18
no problem I can change to malloc() for TRU64



Lutz

pjot

#19
Maybe you have to also change it for Linux, please check the manpage for 'alloca'...



See my post above, I just changed it.



Thx

Peter

Lutz

#20
seems to be TRU64 specific. alloca() in 'ends-with' is fine on Windows, Linux BSDs and Mac OS X 64bit.



BTW there are 26 places in the newLISP code base where alloca() is used, but TRU64 seems to behave fine on those.  alloca() is allocating memory from the call stack.



There is a new version in your space ;-)



Lutz

pjot

#21
Well, those are convincing arguments... :-)



This latest release is running as a dream:
Quote
[peter@olga]# make

./build



Discovered Tru64 Unix, please read doc/TRU64BUILD

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET newlisp.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-symbol.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-math.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-list.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-liststr.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-string.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-filesys.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-sock.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-import.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-xml.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-web.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-matrix.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET nl-debug.c

cc -ieee -pedantic -c -O3 -DSOLARIS -DTRU64 -DNEWLISP64 -D_POSIX_PII_SOCKET pcre.c

cc newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o  nl-sock.o nl-import.o nl-xml.o nl-web.o nl-matrix.o nl-debug.o pcre.o -lm -lrt -ldb -lbsd -o newlisp

strip newlisp

[peter@olga]#

[peter@olga]# ./qa-dot



Testing built-in functions ...



! != $ % & * + - / : < << <= = > >= >> NaN? ^ abs acos acosh add address amb and append append-file apply args array array-list array? asin asinh assoc atan atan2 atanh atom? base64-dec base64-enc bayes-query bayes-train begin beta betai bind binomial callback case catch ceil change-dir char chop clean close command-line cond cons constant context context? copy-file cos cosh count cpymem crc32 crit-chi2 crit-z current-line curry date date-value debug dec def-new default define define-macro delete delete-file delete-url destroy det device difference directory directory? div do-until do-while doargs dolist dostring dotimes dotree dump dup empty? encrypt ends-with env erf error-event error-number error-text eval eval-string exec exists exit exp expand explode factor fft file-info file? filter find find-all first flat float float? floor flt for for-all fork format fv gammai gammaln gcd get-char get-float get-int get-long get-string get-url global global? if ifft import inc index int integer integer? intersect invert irr join lambda? last legal? length let letex letn list list? load local log lookup lower-case macro? main-args make-dir map mat match max member min mod mul multiply name net-accept net-close net-connect net-error net-eval net-listen net-local net-lookup net-peek net-peer net-ping net-receive net-receive-from net-receive-udp net-select net-send net-send-to net-send-udp net-service net-sessions new nil? normal not now nper npv nth nth-set null? number? open or pack parse parse-date peek pipe pmt pop post-url pow pretty-print primitive? print println prob-chi2 prob-z process protected? push put-url pv quote quote? rand random randomize read-buffer read-char read-file read-key read-line real-path ref ref-all ref-set regex remove-dir rename-file replace replace-assoc reset rest reverse rotate round save search seed seek select semaphore sequence series set set-locale set-nth set-ref set-ref-all setq sgn share signal silent sin sinh sleep slice sort source sqrt starts-with string string? sub swap sym symbol? symbols sys-error sys-info tan tanh throw throw-error time time-of-day timer title-case trace trace-highlight transpose trim true? unify unique unless unpack until upper-case uuid wait-pid when while write-buffer write-char write-file write-line xml-error xml-parse xml-type-tags zero? | ~



Testing contexts as objects and scoping rules ...





ALL FUNCTIONS FINISHED SUCCESSFULL: newlisp



total time: 6588




Thanks for the good work!



Peter



PS The "c:\" with trailing slashes I'll test tomorrow.

_

newdep

#22
QuoteHeee pjot... you are using the Olga! did you pay for that?

You cant simply steal processor power.. you have to declare those..

Ill fax you the paper...Olga is Ours! You have the Lisa and the Pamela ;-)

Damm competitors ..dies days..



but..nice random catch!
-- (define? (Cornflakes))

pjot

#23
Well our company did take over all CB systems, also the Oga ;-)



I have to send you a bill for using newLisp in Tru64Unix ;-)

newdep

#24
I would like to dual Tru64 against our new SUN Blade systems,

we must start a newlisp WarRoom in our server park! ;-)
-- (define? (Cornflakes))