@@ -277,6 +277,16 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
277277 directly -- instead of bothering with the whole prototype
278278 mess. */
279279
280+ case 0x0047 : /* stream_set_current */
281+ if (numargs != 1 )
282+ goto WrongArgNum ;
283+ glk_stream_set_current (git_find_stream_by_id (arglist [0 ]));
284+ break ;
285+ case 0x0048 : /* stream_get_current */
286+ if (numargs != 0 )
287+ goto WrongArgNum ;
288+ retval = git_find_id_for_stream (glk_stream_get_current ());
289+ break ;
280290 case 0x0080 : /* put_char */
281291 if (numargs != 1 )
282292 goto WrongArgNum ;
@@ -297,6 +307,16 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
297307 goto WrongArgNum ;
298308 retval = glk_char_to_upper (arglist [0 ] & 0xFF );
299309 break ;
310+ case 0x0128 : /* put_char_uni */
311+ if (numargs != 1 )
312+ goto WrongArgNum ;
313+ glk_put_char_uni (arglist [0 ]);
314+ break ;
315+ case 0x012B : /* put_char_stream_uni */
316+ if (numargs != 2 )
317+ goto WrongArgNum ;
318+ glk_put_char_stream_uni (git_find_stream_by_id (arglist [0 ]), arglist [1 ]);
319+ break ;
300320
301321 WrongArgNum :
302322 fatalError ("Wrong number of arguments to Glk function." );
@@ -306,7 +326,7 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
306326 /* Go through the full dispatcher prototype foo. */
307327 char * proto , * cx ;
308328 dispatch_splot_t splot ;
309- int argnum ;
329+ int argnum , argnum2 ;
310330
311331 /* Grab the string. */
312332 proto = gidispatch_prototype (funcnum );
@@ -335,9 +355,11 @@ glui32 git_perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist)
335355 gidispatch_call (funcnum , argnum , splot .garglist );
336356
337357 /* Phase 3. */
338- argnum = 0 ;
358+ argnum2 = 0 ;
339359 cx = proto ;
340- unparse_glk_args (& splot , & cx , 0 , & argnum , 0 , 0 );
360+ unparse_glk_args (& splot , & cx , 0 , & argnum2 , 0 , 0 );
361+ if (argnum != argnum2 )
362+ fatalError ("Argument counts did not match." );
341363
342364 break ;
343365 }
@@ -560,6 +582,12 @@ static void parse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
560582
561583 switch (typeclass ) {
562584 case 'C' :
585+ /* This test checks for a giant array length, and cuts it down to
586+ something reasonable. Future releases of this interpreter may
587+ treat this case as a fatal error. */
588+ if (varglist [ix + 1 ] > gEndMem || varglist [ix ]+ varglist [ix + 1 ] > gEndMem )
589+ varglist [ix + 1 ] = gEndMem - varglist [ix ];
590+
563591 garglist [gargnum ].array = (void * ) AddressOfArray (varglist [ix ]);
564592 gargnum ++ ;
565593 ix ++ ;
@@ -568,6 +596,10 @@ static void parse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
568596 cx ++ ;
569597 break ;
570598 case 'I' :
599+ /* See comment above. */
600+ if (varglist [ix + 1 ] > gEndMem /4 || varglist [ix + 1 ] > (gEndMem - varglist [ix ])/4 )
601+ varglist [ix + 1 ] = (gEndMem - varglist [ix ]) / 4 ;
602+
571603 garglist [gargnum ].array = CaptureIArray (varglist [ix ], varglist [ix + 1 ], passin );
572604 gargnum ++ ;
573605 ix ++ ;
@@ -679,6 +711,8 @@ static void parse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
679711 }
680712 else {
681713 cx ++ ;
714+ if (isarray )
715+ ix ++ ;
682716 }
683717 }
684718 }
@@ -885,6 +919,8 @@ static void unparse_glk_args(dispatch_splot_t *splot, char **proto, int depth,
885919 }
886920 else {
887921 cx ++ ;
922+ if (isarray )
923+ ix ++ ;
888924 }
889925 }
890926 }
@@ -916,6 +952,21 @@ strid_t git_find_stream_by_id(glui32 objid)
916952 return classes_get (1 , objid );
917953}
918954
955+ /* find_id_for_stream():
956+ The converse of find_stream_by_id().
957+ This is only needed in this file, so it's static.
958+ */
959+ glui32 git_find_id_for_stream (strid_t str )
960+ {
961+ gidispatch_rock_t objrock ;
962+
963+ if (!str )
964+ return 0 ;
965+
966+ objrock = gidispatch_get_objrock (str , 1 );
967+ return ((classref_t * )objrock .ptr )-> id ;
968+ }
969+
919970/* Build a hash table to hold a set of Glk objects. */
920971static classtable_t * new_classtable (glui32 firstid )
921972{
0 commit comments