Patchwork [gccgo] Better panic messages for send/receive on nil channel

login
register
mail settings
Submitter Ian Taylor
Date Aug. 31, 2010, 6:08 p.m.
Message ID <mcr1v9efyeg.fsf@google.com>
Download mbox | patch
Permalink /patch/63309/
State New
Headers show

Comments

Ian Taylor - Aug. 31, 2010, 6:08 p.m.
Right now a send or receive on a nil channel will give a panic due to a
segmentation violation.  This patch adds checks for the condition and
gives a more relevant panic message.  Committed to gccgo branch.

Ian

Patch

diff -r 6cb25c0c5893 libgo/runtime/go-rec-big.c
--- a/libgo/runtime/go-rec-big.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-rec-big.c	Tue Aug 31 11:06:24 2010 -0700
@@ -6,6 +6,7 @@ 
 
 #include <stdint.h>
 
+#include "go-panic.h"
 #include "channel.h"
 
 void
@@ -14,6 +15,9 @@ 
   size_t alloc_size;
   size_t offset;
 
+  if (channel == NULL)
+    __go_panic_msg ("receive from nil channel");
+
   alloc_size = ((channel->element_size + sizeof (uint64_t) - 1)
 		/ sizeof (uint64_t));
 
diff -r 6cb25c0c5893 libgo/runtime/go-rec-small.c
--- a/libgo/runtime/go-rec-small.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-rec-small.c	Tue Aug 31 11:06:24 2010 -0700
@@ -273,6 +273,9 @@ 
 {
   uint64_t ret;
 
+  if (channel == NULL)
+    __go_panic_msg ("receive from nil channel");
+
   __go_assert (channel->element_size <= sizeof (uint64_t));
 
   if (!__go_receive_acquire (channel, for_select))
diff -r 6cb25c0c5893 libgo/runtime/go-send-big.c
--- a/libgo/runtime/go-send-big.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-send-big.c	Tue Aug 31 11:06:24 2010 -0700
@@ -6,6 +6,7 @@ 
 
 #include <stdint.h>
 
+#include "go-panic.h"
 #include "channel.h"
 
 void
@@ -14,6 +15,9 @@ 
   size_t alloc_size;
   size_t offset;
 
+  if (channel == NULL)
+    __go_panic_msg ("send to nil channel");
+
   alloc_size = ((channel->element_size + sizeof (uint64_t) - 1)
 		/ sizeof (uint64_t));
 
diff -r 6cb25c0c5893 libgo/runtime/go-send-small.c
--- a/libgo/runtime/go-send-small.c	Tue Aug 31 10:07:49 2010 -0700
+++ b/libgo/runtime/go-send-small.c	Tue Aug 31 11:06:24 2010 -0700
@@ -151,6 +151,9 @@ 
 void
 __go_send_small (struct __go_channel *channel, uint64_t val, _Bool for_select)
 {
+  if (channel == NULL)
+    __go_panic_msg ("send to nil channel");
+
   __go_assert (channel->element_size <= sizeof (uint64_t));
 
   if (!__go_send_acquire (channel, for_select))