This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgo patch committed: Delete from a nil map is now a no-op


The Go spec was changed slightly: calling delete on a nil map is now a
no-op, rather than causing a runtime panic.  This patch implements that
in gccgo.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Index: libgo/runtime/go-map-delete.c
===================================================================
--- libgo/runtime/go-map-delete.c	(revision 194274)
+++ libgo/runtime/go-map-delete.c	(working copy)
@@ -27,7 +27,7 @@ __go_map_delete (struct __go_map *map, c
   void **pentry;
 
   if (map == NULL)
-    runtime_panicstring ("deletion of entry in nil map");
+    return;
 
   descriptor = map->__descriptor;
 
Index: gcc/testsuite/go.test/test/nil.go
===================================================================
--- gcc/testsuite/go.test/test/nil.go	(revision 193595)
+++ gcc/testsuite/go.test/test/nil.go	(working copy)
@@ -151,9 +151,8 @@ func maptest() {
 	shouldPanic(func() {
 		m[2] = 3
 	})
-	shouldPanic(func() {
-		delete(m, 2)
-	})
+	// can delete (non-existent) entries
+	delete(m, 2)
 }
 
 // nil slice

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]