[m-dev.] for review: shut up a warning

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Jan 18 18:19:56 AEDT 2001


On 18-Jan-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> The code using strdup() seems to have been committed already, but it
> was never posted to mercury-developers.  Please don't do that!

You have never done that in your life, I am sure :-)

Here is the updated fix.

browser/dl.m:
	Replace a call to strdup with a call to MR_GC_copy_string.

runtime/mercury_memory.[ch]:
	Declare and define MR_GC_copy_string, which is identical to
	MR_copy_string except it calls MR_GC_malloc instead of MR_malloc.

Zoltan.

cvs diff: Diffing browser
Index: browser/dl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/dl.m,v
retrieving revision 1.7
diff -u -b -r1.7 dl.m
--- browser/dl.m	2001/01/18 01:18:25	1.7
+++ browser/dl.m	2001/01/18 07:07:40
@@ -63,6 +63,7 @@
 :- pragma c_header_code("
 	#include <stdio.h>
 	#include ""mercury_conf.h""
+	#include ""mercury_memory.h""
 #ifdef HAVE_DLFCN_H
 	#include <dlfcn.h>
 #endif
@@ -199,7 +200,7 @@
 	closure_id->module_name = ""dl"";
 	closure_id->file_name = __FILE__;
 	closure_id->line_number = __LINE__;
-	closure_id->goal_path = strdup(buf);
+	closure_id->goal_path = MR_GC_copy_string(buf);
 
 	closure_layout = MR_GC_NEW(MR_Closure_Dyn_Link_Layout);
 	closure_layout->closure_id = closure_id;
cvs diff: Diffing runtime
Index: runtime/mercury_memory.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory.c,v
retrieving revision 1.24
diff -u -b -r1.24 mercury_memory.c
--- runtime/mercury_memory.c	2000/11/24 06:03:37	1.24
+++ runtime/mercury_memory.c	2001/01/18 07:06:17
@@ -363,4 +363,16 @@
 	return ptr;
 }
 
+char *
+MR_GC_copy_string(const char *s)
+{
+	int	len;
+	char	*copy;
+
+	len = strlen(s);
+	copy = MR_GC_malloc(len + 1);
+	strcpy(copy, s);
+	return copy;
+}
+
 /*---------------------------------------------------------------------------*/
Index: runtime/mercury_memory.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory.h,v
retrieving revision 1.14
diff -u -b -r1.14 mercury_memory.h
--- runtime/mercury_memory.h	2000/11/23 02:00:34	1.14
+++ runtime/mercury_memory.h	2001/01/18 07:05:30
@@ -163,6 +163,13 @@
 
 char	*MR_copy_string(const char *s);
 
+/*
+** MR_GC_copy_string makes a copy of the given string,
+** using memory allocated with MR_GC_malloc().
+*/
+
+char	*MR_GC_copy_string(const char *s);
+
 /*---------------------------------------------------------------------------*/
 
 /*
cvs diff: Diffing runtime/GETOPT
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list