RetroForum Welcome, Guest. Please login or register.
September 09, 2010, 11:18:06 PM
Home Help Search Calendar Login Register

RetroForth Discussion  |  Older Boards  |  Bugs  |  Topic: zero-length string? « previous next »
Pages: 1 Go Down Print
Author Topic: zero-length string?  (Read 2337 times)
anub
Newbie
*

Karma: +1/-0
Offline Offline

Posts: 4


View Profile
zero-length string?
« on: June 25, 2005, 08:33:37 AM »

i got some funny results with zero-length string:
Code:
$ bin/rf
RetroForth 8.0  ::  Visit http://www.retroforth.org for updates

" "
Segmentation fault (core dumped)
ditto for ."
now, i am a clueless beginner, so it's likely that i am missing something, and this is a feature, but how can i place an empty string?
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: zero-length string?
« Reply #1 on: June 25, 2005, 02:25:07 PM »

Thanks for bringing this up. RetroForth doesn't actually support zero-length strings (mainly because there is no use for them), but this may still be something I need to work on. I can do (and am testing) a patch that ensures that " " will return a string length of one byte, but I don't know if this is actually needed.

Does anyone have an actual use for zero-length strings? And if so, what is it?
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: zero-length string?
« Reply #2 on: June 25, 2005, 03:56:37 PM »

If you want to test the potential patch, you'll have to edit
Code:
source/core.asm
and recompile the source tree.

In core.asm, find the
Code:
query
routine. Goto the
Code:
.cr
label. It should read something like:

Code:
.cr: drop
ret

Replace those lines with:

Code:
.cr:    mov al, 32              ; This is a workaround for
        xchg edi, [tp]          ; some minor problems when
        stosb                   ; parsing zero-length strings
        xchg [tp], edi          ;
        drop                    ; We just convert a CR/LF to a
        ret                     ; space, store it, then exit

Recompile and test it out.
Logged
anub
Newbie
*

Karma: +1/-0
Offline Offline

Posts: 4


View Profile
Re: zero-length string?
« Reply #3 on: June 25, 2005, 07:34:40 PM »

I believe there are uses for zero-length strings:
It is the zero of string concatenation ( a+"" = ""+a = a ).
It denotes a value that has no characters.
(such as: a user is asked to enter an optional piece of data, and enters nothing. during processing, we look at that, get "length=0" and react accordingly)

it can be denoted by either a single zero instead of data pointer, or by a pair 0, 0. (0 for length and 0 for address, since we don't need an address)

In any case, the interpreter should react more gracefully and deterministically to such input. imnsho.
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: zero-length string?
« Reply #4 on: June 25, 2005, 10:58:35 PM »

Another option is to redefine " as:

Code:
: " >in @ dup c@ '" =if 2 + >in ! 0 0 ;; then drop '" parse >pad ;

I really don't want to add code as messy as this to the core though.

Your point is well taken. I've never really run into this in my apps as I've always placed input into defined memory areas and used other means to check for length and such.

Does anyone else have input on this issue? I have a few days left before making a final decision....
Logged
Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: zero-length string?
« Reply #5 on: June 25, 2005, 11:23:10 PM »

Ok, I came up with a fix I can tolerate in the core. Zero-length strings can now be created without causing a segfault.
Logged
Pages: 1 Go Up Print 
RetroForth Discussion  |  Older Boards  |  Bugs  |  Topic: zero-length string? « previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC2 | SMF © 2001-2005, Lewis Media Valid XHTML 1.0! Valid CSS!