[m-rev.] for review: c_header_code in string.m

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Aug 8 14:35:26 AEST 2002


That fix is not correct; if the definition is in pragma c_code,
and the function is referenced from pragma foreign_proc, then
the function needs to be declared as "extern" rather than "static".

Another alternative would be to leave the function definition as
"static", keep the definition in "pragma c_header_code",
and add a #ifndef ... #define ... #endif guard around it.

On 08-Aug-2002, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> While I am sure the diff below is a step in the right direction (I got the
> error in the log message during a test install, in grade asm_fast.gc.debug.tr),
> it would also be nice if the compiler ensured that no c_header_code was
> actually included twice. Since this code has been in string.m for almost two
> years without leading to an error, it seems the compiler wasn't doing such
> double inclusions until recently.
> 
> Zoltan.
> 
> library/string.m:
> 	Fix a bug. Move the definition of a function out of a pragma
> 	c_header_code, leaving just its declaration; move its definition
> 	to a pragma c_code. This avoids the compilation errors you could get
> 	if the c_header code was included in a file twice. It seems that this
> 	could actually happen, e.g. when compiling bool.c, with the duplicate
> 	definitions coming from bool.mh and string.opt.
> 
> cvs diff: Diffing .
> Index: string.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/string.m,v
> retrieving revision 1.175
> diff -u -b -r1.175 string.m
> --- string.m	2002/08/06 15:27:10	1.175
> +++ string.m	2002/08/08 03:04:26
> @@ -1999,13 +1999,24 @@
>  	** register spilled' in grade asm_fast.gc.tr.debug
>  	** if we write this inline.
>  	*/
> +	static void MR_set_char(MR_String str, MR_Integer ind, MR_Char ch);
> +#else
> +	#define MR_set_char(str, ind, ch) \\
> +		((str)[ind] = (ch))
> +#endif
> +").
> +
> +:- pragma c_code("
> +#ifdef MR_USE_GCC_GLOBAL_REGISTERS
> +	/*
> +	** GNU C version egcs-1.1.2 crashes with `fixed or forbidden
> +	** register spilled' in grade asm_fast.gc.tr.debug
> +	** if we write this inline.
> +	*/
>  	static void MR_set_char(MR_String str, MR_Integer ind, MR_Char ch)
>  	{
>  		str[ind] = ch;
>  	}
> -#else
> -	#define MR_set_char(str, ind, ch) \\
> -		((str)[ind] = (ch))
>  #endif
>  ").
>  
> --------------------------------------------------------------------------
> mercury-reviews mailing list
> post:  mercury-reviews at cs.mu.oz.au
> administrative address: owner-mercury-reviews at cs.mu.oz.au
> unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
> subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
> --------------------------------------------------------------------------

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list