intfiction.org

The Interactive Fiction Community Forum
It is currently Fri May 24, 2013 1:21 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sat Aug 20, 2011 12:01 pm 
Offline

Joined: Wed Oct 27, 2010 6:15 pm
Posts: 239
In the Glk Specification, Section 5.6.2:
Quote:
You can open a stream which reads from or writes into a space in memory.
Code:
strid_t glk_stream_open_memory(char *buf, glui32 buflen, glui32 fmode, glui32 rock);
...
If buf is NULL, or for that matter if buflen is zero, then everything written to the stream is thrown away. This may be useful if you are interested in the character count.
...
However,
Code:
glk_stream_open_memory(0,0,filemode_Write,0);
provokes the error
Quote:
Zero passed invalidly to Glk function.
whereas
Code:
glk_stream_open_memory(1,0,filemode_Write,0);
does not. Is this a spec violation, or am I misreading things?


Top
 Profile Send private message  
 
PostPosted: Sat Aug 20, 2011 2:35 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 2086
glk_stream_open_memory(1,0,filemode_Write,0) should be legal. Ditto for glk_stream_open_memory(arr,0,filemode_Write,0) where arr is a valid array address.

glk_stream_open_memory(1,1,filemode_Write,0) is probably legal in itself, but as soon as you write to the stream you may get a segfault, because address 1 is who-knows-where.


Top
 Profile Send private message  
 
PostPosted: Sat Aug 20, 2011 3:27 pm 
Offline

Joined: Wed Oct 27, 2010 6:15 pm
Posts: 239
Right, but what about the case where buf is NULL? Section 5.6.2 seems to suggest that that should be equivalent to buflen=0.


Top
 Profile Send private message  
 
PostPosted: Sat Aug 20, 2011 3:47 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 2086
Oh, yes. Sorry -- I thought I'd answered that. That's legal too.


Top
 Profile Send private message  
 
PostPosted: Sat Aug 20, 2011 4:37 pm 
Offline

Joined: Wed Oct 27, 2010 6:15 pm
Posts: 239
Thanks. I'll file a bug report then.


Top
 Profile Send private message  
 
PostPosted: Tue Aug 23, 2011 12:19 pm 
Offline

Joined: Mon Jun 29, 2009 5:51 am
Posts: 288
I don't think this is a problem with the Inform 7 IDEs' Glk libraries. The error message "Zero passed invalidly to Glk function." comes from the routines in the interpreters to decode the arguments to a Glk call (glkop.c in both Glulxe and Git - they're using the same code), which suggests to me a problem in the Glulxe interpreter somewhere.


Top
 Profile Send private message  
 
PostPosted: Tue Aug 23, 2011 1:11 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 2086
Goddammit. I grepped my Glk library source for that message but forgot to look in glkop.c.

Sure enough, I have the "+" notation on glk_stream_open_memory, which means that the dispatch library will reject NULL. I apologize. I will fix that.


Top
 Profile Send private message  
 
PostPosted: Tue Aug 23, 2011 3:01 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 2086
There's a further bug in glkop.c for this case (null-optional array parameters). I will have to do more testing to determine if it's easy to fix, or if ten years of code depend on the legacy behavior. :(


Top
 Profile Send private message  
 
PostPosted: Wed Aug 24, 2011 1:14 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 2086
Okay. The change to gi_dispa.c is checked in (see my cheapglk repository). The bug fix to glkop.c is also (glulxe repository). I've imported the changes into my other libraries (glkterm and quixe).

Anybody who supports a C-based Glk library or Glulx interpreter should pick up these changes. (Both sides have to be fixed, unfortunately. The library fix uncovered the old interpreter-side bug.)

I added a unit test for this to my memstreamtest.ulx text -- see http://eblong.com/zarf/glulx/ . In that test, type "null grape" and "uninull grape", and similarly for the the other objects. Those commands should print the length of the description string (in characters) for the noun object. In unfixed interpreters, you'll see some kind of error.

Since it may take a while for interpreters to absorb these bug fixes, I'll remind you that

glk_stream_open_memory(array,0,filemode_Write,0);

...is a way to accomplish the same thing, without tripping over the bug. ("The same thing" meaning "measure the length of printed text without printing it to either the screen or memory".)


Top
 Profile Send private message  
 
PostPosted: Wed Aug 24, 2011 5:13 pm 
Offline

Joined: Wed Oct 27, 2010 6:15 pm
Posts: 239
Thanks for fixing this, zarf.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group