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

login
register
mail settings
Submitter Ian Taylor
Date Dec. 12, 2012, 11:29 p.m.
Message ID <mcrvcc6df3r.fsf@google.com>
Download mbox | patch
Permalink /patch/205687/
State New
Headers show

Comments

Ian Taylor - Dec. 12, 2012, 11:29 p.m.
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

Patch

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