[m-rev.] for review: make some io procedures return "" instead of NULL

Julien Fischer juliensf at cs.mu.OZ.AU
Fri May 20 01:45:51 AEST 2005


On Thu, 19 May 2005, Ian MacLarty wrote:

> For review by anyone.
>
> Estimated hours taken: 1
> Branches: main and 0.12
>
> Make some procedures in the io library return strings instead of NULL.  This
> is a problem for the debugger since it segfaults when trying to display the
> strings on screen.  mdb should probably be made to handle invalid string
> pointers better, but that requires a bigger change.
>
> library/io.m:
> 	Make ML_maybe_make_err_msg, ML_maybe_make_win32_err_msg and
> 	read_line_as_string_2 return an empty string instead of NULL.
>
> tests/debugger/declarative/Mmakefile:
> tests/debugger/declarative/sort.exp:
> tests/debugger/declarative/sort.inp:
> tests/debugger/declarative/sort.input:
> tests/debugger/declarative/sort.m:
> 	Add a regression test.  This test segfaulted previously.
>
> Index: library/io.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/io.m,v
> retrieving revision 1.329
> diff -u -r1.329 io.m
> --- library/io.m	18 May 2005 05:25:58 -0000	1.329
> +++ library/io.m	18 May 2005 07:38:05 -0000
> @@ -1928,7 +1928,7 @@
>  		memcpy(RetString, read_buffer, i * sizeof(MR_Char));
>  		RetString[i] = '\\0';
>  	} else {
> -		RetString = NULL;
> +		RetString = MR_make_string_const("""");
>  	}
>  	if (read_buffer != initial_read_buffer) {
>  		MR_free(read_buffer);
> @@ -8360,7 +8360,7 @@
>  /*
>  ** ML_maybe_make_err_msg(was_error, errno, msg, procname, error_msg):
>  **	if `was_error' is true, then append `msg' and `strerror(errno)'
> -**	to give `error_msg'; otherwise, set `error_msg' to NULL.
> +**	to give `error_msg'; otherwise, set `error_msg' to "".
>  **
>  ** WARNING: this must only be called when the `hp' register is valid.
>  ** That means it must only be called from procedures declared
> @@ -8390,7 +8390,7 @@
>  			strcpy((error_msg), msg);			\\
>  			strcat((error_msg), errno_msg);			\\
>  		} else {						\\
> -			(error_msg) = NULL;				\\
> +			(error_msg) = MR_make_string_const("""");		\\
>  		}							\\
>  	} while(0)
>
> @@ -8398,7 +8398,7 @@
>  ** ML_maybe_make_win32_err_msg(was_error, error, msg, procname, error_msg):
>  **	if `was_error' is true, then append `msg' and the string
>  **	returned by the Win32 API function FormatMessage() for the
> -**	last error to give `error_msg'; otherwise, set `error_msg' to NULL.
> +**	last error to give `error_msg'; otherwise, set `error_msg' to "".
>  **	Aborts if MR_WIN32 is not defined.
>  **
>  ** WARNING: this must only be called when the `hp' register is valid.
> @@ -8450,7 +8450,7 @@
>  				LocalFree(err_buf);			\\
>  			}						\\
>  		} else {						\\
> -			(error_msg) = NULL;				\\
> +			(error_msg) = MR_make_string_const("""");	\\
>  		}							\\
>  	} while(0)
>
> @@ -8701,7 +8701,7 @@
>  		Status = 1;
>  	}
>  #else /* !MR_HAVE_READLINK */
> -	TargetFileName = NULL;
> +	TargetFileName = MR_make_string_const("""");
>  	Status = 0;
>  #endif
>  	MR_update_io(IO0, IO);

That's fine except that I think you should put a brief comment
at each of those three spots explaining why "" is returned rather
than NULL.

Julien.
--------------------------------------------------------------------------
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