closedch := make(chan int)
close(closedch)
- // sending/receiving from a nil channel outside a select panics
- testPanic(always, func() {
+ // sending/receiving from a nil channel blocks
+ testBlock(always, func() {
nilch <- 7
})
- testPanic(always, func() {
+ testBlock(always, func() {
<-nilch
})
- // sending/receiving from a nil channel inside a select never panics
+ // sending/receiving from a nil channel inside a select is never selected
testPanic(never, func() {
select {
case nilch <- 7:
#include "config.h"
#include "channel.h"
+#define nil NULL
+
typedef _Bool bool;
typedef unsigned char byte;
typedef struct __go_channel chan;
/* Do a channel receive with closed status. */
func chanrecv2(c *chan, val *byte) (received bool) {
- uintptr_t element_size = c->element_type->__size;
+ uintptr_t element_size = c == nil ? 0 : c->element_type->__size;
if (element_size > 8) {
return __go_receive_big(c, val, 0);
} else {
extern int __go_chan_len (struct __go_channel *);
extern int __go_chan_cap (struct __go_channel *);
+
+extern uintptr_t __go_select (uintptr_t, _Bool, struct __go_channel **,
+ _Bool *);
size_t offset;
if (channel == NULL)
- __go_panic_msg ("receive from nil channel");
+ {
+ /* Block forever. */
+ __go_select (0, 0, NULL, NULL);
+ }
element_size = channel->element_type->__size;
alloc_size = (element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t);
size_t alloc_size;
size_t offset;
+ if (channel == NULL)
+ {
+ if (closed != NULL)
+ *closed = 0;
+ return 0;
+ }
+
element_size = channel->element_type->__size;
alloc_size = (element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t);
uintptr_t element_size;
struct __go_receive_nonblocking_small ret;
+ if (channel == NULL)
+ {
+ ret.__val = 0;
+ ret.__success = 0;
+ ret.__closed = 0;
+ return ret;
+ }
+
element_size = channel->element_type->__size;
__go_assert (element_size <= sizeof (uint64_t));
uint64_t ret;
if (channel == NULL)
- __go_panic_msg ("receive from nil channel");
+ {
+ /* Block forever. */
+ __go_select (0, 0, NULL, NULL);
+ }
element_size = channel->element_type->__size;
__go_assert (element_size <= sizeof (uint64_t));
void *pv;
__go_assert (ct->__common.__code == GO_CHAN);
- __go_assert (__go_type_descriptors_equal (ct->__element_type,
- channel->element_type));
- if (channel == NULL)
- __go_panic_msg ("send to nil channel");
-
- if (__go_is_pointer_type (channel->element_type))
+ if (__go_is_pointer_type (ct->__element_type))
pv = &val_i;
else
pv = (void *) val_i;
- element_size = channel->element_type->__size;
+ element_size = ct->__element_type->__size;
if (element_size <= sizeof (uint64_t))
{
union
struct chanrecv_ret ret;
__go_assert (ct->__common.__code == GO_CHAN);
- __go_assert (__go_type_descriptors_equal (ct->__element_type,
- channel->element_type));
- element_size = channel->element_type->__size;
+ element_size = ct->__element_type->__size;
- if (__go_is_pointer_type (channel->element_type))
+ if (__go_is_pointer_type (ct->__element_type))
pv = &ret.val;
else
{
size_t offset;
if (channel == NULL)
- __go_panic_msg ("send to nil channel");
+ {
+ // Block forever.
+ __go_select (0, 0, NULL, NULL);
+ }
element_size = channel->element_type->__size;
alloc_size = (element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t);
size_t alloc_size;
size_t offset;
+ if (channel == NULL)
+ return 0;
+
element_size = channel->element_type->__size;
alloc_size = (element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t);
_Bool
__go_send_nonblocking_small (struct __go_channel *channel, uint64_t val)
{
+ if (channel == NULL)
+ return 0;
+
__go_assert (channel->element_type->__size <= sizeof (uint64_t));
if (!__go_send_nonblocking_acquire (channel))
__go_send_small (struct __go_channel *channel, uint64_t val, _Bool for_select)
{
if (channel == NULL)
- __go_panic_msg ("send to nil channel");
+ {
+ // Block forever.
+ __go_select (0, 0, NULL, NULL);
+ }
__go_assert (channel->element_type->__size <= sizeof (uint64_t));