aboutsummaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-09-21 17:37:50 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-09-21 17:37:50 +0000
commite6f8e5901625f2c77ea317a3d770c52d966b5e77 (patch)
tree72d064eacaba81463aeeb1607f050c5b0151b34a /libgo
parentbd352290bcbe1c80ce47ea3aa4d66d17a6e8d482 (diff)
downloadgcc-e6f8e5901625f2c77ea317a3d770c52d966b5e77.zip
gcc-e6f8e5901625f2c77ea317a3d770c52d966b5e77.tar.gz
gcc-e6f8e5901625f2c77ea317a3d770c52d966b5e77.tar.bz2
Support nil maps.
From-SVN: r179054
Diffstat (limited to 'libgo')
-rw-r--r--libgo/runtime/go-map-delete.c4
-rw-r--r--libgo/runtime/go-map-index.c8
-rw-r--r--libgo/runtime/map.goc11
3 files changed, 18 insertions, 5 deletions
diff --git a/libgo/runtime/go-map-delete.c b/libgo/runtime/go-map-delete.c
index 7a3a7b8..9b19ff1 100644
--- a/libgo/runtime/go-map-delete.c
+++ b/libgo/runtime/go-map-delete.c
@@ -9,6 +9,7 @@
#include "go-alloc.h"
#include "go-assert.h"
+#include "go-panic.h"
#include "map.h"
/* Delete the entry matching KEY from MAP. */
@@ -25,6 +26,9 @@ __go_map_delete (struct __go_map *map, const void *key)
size_t bucket_index;
void **pentry;
+ if (map == NULL)
+ __go_panic_msg ("assignment to entry in nil map");
+
descriptor = map->__descriptor;
key_descriptor = descriptor->__map_descriptor->__key_type;
diff --git a/libgo/runtime/go-map-index.c b/libgo/runtime/go-map-index.c
index a387c4b..92a8068 100644
--- a/libgo/runtime/go-map-index.c
+++ b/libgo/runtime/go-map-index.c
@@ -9,6 +9,7 @@
#include "go-alloc.h"
#include "go-assert.h"
+#include "go-panic.h"
#include "map.h"
/* Rehash MAP to a larger size. */
@@ -85,6 +86,13 @@ __go_map_index (struct __go_map *map, const void *key, _Bool insert)
size_t bucket_index;
char *entry;
+ if (map == NULL)
+ {
+ if (insert)
+ __go_panic_msg ("assignment to entry in nil map");
+ return NULL;
+ }
+
descriptor = map->__descriptor;
key_descriptor = descriptor->__map_descriptor->__key_type;
diff --git a/libgo/runtime/map.goc b/libgo/runtime/map.goc
index d6308cb..e19bc96 100644
--- a/libgo/runtime/map.goc
+++ b/libgo/runtime/map.goc
@@ -9,17 +9,18 @@ package runtime
typedef unsigned char byte;
typedef _Bool bool;
-typedef struct __go_map hmap;
+typedef struct __go_map_type MapType;
+typedef struct __go_map Hmap;
typedef struct __go_hash_iter hiter;
/* Access a value in a map, returning a value and a presence indicator. */
-func mapaccess2(h *hmap, key *byte, val *byte) (present bool) {
+func mapaccess2(t *MapType, h *Hmap, key *byte, val *byte) (present bool) {
byte *mapval;
size_t valsize;
mapval = __go_map_index(h, key, 0);
- valsize = h->__descriptor->__map_descriptor->__val_type->__size;
+ valsize = t->__val_type->__size;
if (mapval == nil) {
__builtin_memset(val, 0, valsize);
present = 0;
@@ -31,7 +32,7 @@ func mapaccess2(h *hmap, key *byte, val *byte) (present bool) {
/* Optionally assign a value to a map (m[k] = v, p). */
-func mapassign2(h *hmap, key *byte, val *byte, p bool) {
+func mapassign2(h *Hmap, key *byte, val *byte, p bool) {
if (!p) {
__go_map_delete(h, key);
} else {
@@ -46,7 +47,7 @@ func mapassign2(h *hmap, key *byte, val *byte, p bool) {
/* Initialize a range over a map. */
-func mapiterinit(h *hmap, it *hiter) {
+func mapiterinit(h *Hmap, it *hiter) {
__go_mapiterinit(h, it);
}