summaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
Diffstat (limited to 'libgo')
-rw-r--r--libgo/Makefile.am1
-rw-r--r--libgo/Makefile.in71
-rw-r--r--libgo/runtime/go-make-slice.c57
-rw-r--r--libgo/runtime/go-map-delete.c2
-rw-r--r--libgo/runtime/go-map-index.c4
-rw-r--r--libgo/runtime/go-new-channel.c13
-rw-r--r--libgo/runtime/go-new-map.c4
-rw-r--r--libgo/runtime/go-reflect-call.c2
-rw-r--r--libgo/runtime/go-reflect-chan.c3
-rw-r--r--libgo/runtime/go-reflect.c2
-rw-r--r--libgo/runtime/go-type.h6
-rw-r--r--libgo/runtime/map.h6
12 files changed, 125 insertions, 46 deletions
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index c98a17637d3..761a11ad265 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -381,6 +381,7 @@ runtime_files = \
runtime/go-interface-eface-compare.c \
runtime/go-interface-val-compare.c \
runtime/go-lock-os-thread.c \
+ runtime/go-make-slice.c \
runtime/go-map-delete.c \
runtime/go-map-index.c \
runtime/go-map-len.c \
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index ac5de78dca4..8637ec41b7d 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -184,18 +184,18 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
runtime/go-interface-compare.c \
runtime/go-interface-eface-compare.c \
runtime/go-interface-val-compare.c runtime/go-lock-os-thread.c \
- runtime/go-map-delete.c runtime/go-map-index.c \
- runtime/go-map-len.c runtime/go-map-range.c \
- runtime/go-nanotime.c runtime/go-new-channel.c \
- runtime/go-new-map.c runtime/go-new.c runtime/go-note.c \
- runtime/go-panic.c runtime/go-panic-defer.c runtime/go-print.c \
- runtime/go-rec-big.c runtime/go-rec-nb-big.c \
- runtime/go-rec-nb-small.c runtime/go-rec-small.c \
- runtime/go-recover.c runtime/go-reflect.c \
- runtime/go-reflect-call.c runtime/go-reflect-chan.c \
- runtime/go-reflect-map.c runtime/go-rune.c \
- runtime/go-runtime-error.c runtime/go-sched.c \
- runtime/go-select.c runtime/go-semacquire.c \
+ runtime/go-make-slice.c runtime/go-map-delete.c \
+ runtime/go-map-index.c runtime/go-map-len.c \
+ runtime/go-map-range.c runtime/go-nanotime.c \
+ runtime/go-new-channel.c runtime/go-new-map.c runtime/go-new.c \
+ runtime/go-note.c runtime/go-panic.c runtime/go-panic-defer.c \
+ runtime/go-print.c runtime/go-rec-big.c \
+ runtime/go-rec-nb-big.c runtime/go-rec-nb-small.c \
+ runtime/go-rec-small.c runtime/go-recover.c \
+ runtime/go-reflect.c runtime/go-reflect-call.c \
+ runtime/go-reflect-chan.c runtime/go-reflect-map.c \
+ runtime/go-rune.c runtime/go-runtime-error.c \
+ runtime/go-sched.c runtime/go-select.c runtime/go-semacquire.c \
runtime/go-send-big.c runtime/go-send-nb-big.c \
runtime/go-send-nb-small.c runtime/go-send-small.c \
runtime/go-setenv.c runtime/go-signal.c runtime/go-strcmp.c \
@@ -227,25 +227,25 @@ am__objects_3 = go-append.lo go-assert.lo go-assert-interface.lo \
go-gomaxprocs.lo go-int-array-to-string.lo go-int-to-string.lo \
go-interface-compare.lo go-interface-eface-compare.lo \
go-interface-val-compare.lo go-lock-os-thread.lo \
- go-map-delete.lo go-map-index.lo go-map-len.lo go-map-range.lo \
- go-nanotime.lo go-new-channel.lo go-new-map.lo go-new.lo \
- go-note.lo go-panic.lo go-panic-defer.lo go-print.lo \
- go-rec-big.lo go-rec-nb-big.lo go-rec-nb-small.lo \
- go-rec-small.lo go-recover.lo go-reflect.lo go-reflect-call.lo \
- go-reflect-chan.lo go-reflect-map.lo go-rune.lo \
- go-runtime-error.lo go-sched.lo go-select.lo go-semacquire.lo \
- go-send-big.lo go-send-nb-big.lo go-send-nb-small.lo \
- go-send-small.lo go-setenv.lo go-signal.lo go-strcmp.lo \
- go-string-to-byte-array.lo go-string-to-int-array.lo \
- go-strplus.lo go-strslice.lo go-trampoline.lo go-type-eface.lo \
- go-type-error.lo go-type-identity.lo go-type-interface.lo \
- go-type-string.lo go-typedesc-equal.lo go-typestring.lo \
- go-unreflect.lo go-unsafe-new.lo go-unsafe-newarray.lo \
- go-unsafe-pointer.lo go-unwind.lo cpuprof.lo mcache.lo \
- mcentral.lo $(am__objects_1) mfinal.lo mfixalloc.lo mgc0.lo \
- mheap.lo msize.lo proc.lo thread.lo $(am__objects_2) chan.lo \
- iface.lo malloc.lo map.lo mprof.lo reflect.lo sigqueue.lo \
- string.lo
+ go-make-slice.lo go-map-delete.lo go-map-index.lo \
+ go-map-len.lo go-map-range.lo go-nanotime.lo go-new-channel.lo \
+ go-new-map.lo go-new.lo go-note.lo go-panic.lo \
+ go-panic-defer.lo go-print.lo go-rec-big.lo go-rec-nb-big.lo \
+ go-rec-nb-small.lo go-rec-small.lo go-recover.lo go-reflect.lo \
+ go-reflect-call.lo go-reflect-chan.lo go-reflect-map.lo \
+ go-rune.lo go-runtime-error.lo go-sched.lo go-select.lo \
+ go-semacquire.lo go-send-big.lo go-send-nb-big.lo \
+ go-send-nb-small.lo go-send-small.lo go-setenv.lo go-signal.lo \
+ go-strcmp.lo go-string-to-byte-array.lo \
+ go-string-to-int-array.lo go-strplus.lo go-strslice.lo \
+ go-trampoline.lo go-type-eface.lo go-type-error.lo \
+ go-type-identity.lo go-type-interface.lo go-type-string.lo \
+ go-typedesc-equal.lo go-typestring.lo go-unreflect.lo \
+ go-unsafe-new.lo go-unsafe-newarray.lo go-unsafe-pointer.lo \
+ go-unwind.lo cpuprof.lo mcache.lo mcentral.lo $(am__objects_1) \
+ mfinal.lo mfixalloc.lo mgc0.lo mheap.lo msize.lo proc.lo \
+ thread.lo $(am__objects_2) chan.lo iface.lo malloc.lo map.lo \
+ mprof.lo reflect.lo sigqueue.lo string.lo
am_libgo_la_OBJECTS = $(am__objects_3)
libgo_la_OBJECTS = $(am_libgo_la_OBJECTS)
libgo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@@ -800,6 +800,7 @@ runtime_files = \
runtime/go-interface-eface-compare.c \
runtime/go-interface-val-compare.c \
runtime/go-lock-os-thread.c \
+ runtime/go-make-slice.c \
runtime/go-map-delete.c \
runtime/go-map-index.c \
runtime/go-map-len.c \
@@ -2309,6 +2310,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-interface-val-compare.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-lock-os-thread.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-make-slice.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-map-delete.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-map-index.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-map-len.Plo@am__quote@
@@ -2610,6 +2612,13 @@ go-lock-os-thread.lo: runtime/go-lock-os-thread.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-lock-os-thread.lo `test -f 'runtime/go-lock-os-thread.c' || echo '$(srcdir)/'`runtime/go-lock-os-thread.c
+go-make-slice.lo: runtime/go-make-slice.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-make-slice.lo -MD -MP -MF $(DEPDIR)/go-make-slice.Tpo -c -o go-make-slice.lo `test -f 'runtime/go-make-slice.c' || echo '$(srcdir)/'`runtime/go-make-slice.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/go-make-slice.Tpo $(DEPDIR)/go-make-slice.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='runtime/go-make-slice.c' object='go-make-slice.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-make-slice.lo `test -f 'runtime/go-make-slice.c' || echo '$(srcdir)/'`runtime/go-make-slice.c
+
go-map-delete.lo: runtime/go-map-delete.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-map-delete.lo -MD -MP -MF $(DEPDIR)/go-map-delete.Tpo -c -o go-map-delete.lo `test -f 'runtime/go-map-delete.c' || echo '$(srcdir)/'`runtime/go-map-delete.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/go-map-delete.Tpo $(DEPDIR)/go-map-delete.Plo
diff --git a/libgo/runtime/go-make-slice.c b/libgo/runtime/go-make-slice.c
new file mode 100644
index 00000000000..cd2d55bd538
--- /dev/null
+++ b/libgo/runtime/go-make-slice.c
@@ -0,0 +1,57 @@
+/* go-make-slice.c -- make a slice.
+
+ Copyright 2011 The Go Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style
+ license that can be found in the LICENSE file. */
+
+#include <stdint.h>
+
+#include "go-alloc.h"
+#include "go-assert.h"
+#include "go-panic.h"
+#include "go-type.h"
+#include "array.h"
+#include "runtime.h"
+#include "malloc.h"
+
+struct __go_open_array
+__go_make_slice2 (const struct __go_type_descriptor *td, uintptr_t len,
+ uintptr_t cap)
+{
+ const struct __go_slice_type* std;
+ int ilen;
+ int icap;
+ uintptr_t size;
+ struct __go_open_array ret;
+ unsigned int flag;
+
+ __go_assert (td->__code == GO_SLICE);
+ std = (const struct __go_slice_type *) td;
+
+ ilen = (int) len;
+ if (ilen < 0 || (uintptr_t) ilen != len)
+ __go_panic_msg ("makeslice: len out of range");
+
+ icap = (int) cap;
+ if (cap < len
+ || (uintptr_t) icap != cap
+ || cap > (uintptr_t) -1U / std->__element_type->__size)
+ __go_panic_msg ("makeslice: cap out of range");
+
+ ret.__count = ilen;
+ ret.__capacity = icap;
+
+ size = cap * std->__element_type->__size;
+ flag = ((std->__element_type->__code & GO_NO_POINTERS) != 0
+ ? FlagNoPointers
+ : 0);
+ ret.__values = runtime_mallocgc (size, flag, 1, 1);
+
+ return ret;
+}
+
+struct __go_open_array
+__go_make_slice1 (const struct __go_type_descriptor *td, uintptr_t len)
+{
+ return __go_make_slice2 (td, len, len);
+}
diff --git a/libgo/runtime/go-map-delete.c b/libgo/runtime/go-map-delete.c
index ec851e531d2..7a3a7b83d92 100644
--- a/libgo/runtime/go-map-delete.c
+++ b/libgo/runtime/go-map-delete.c
@@ -18,7 +18,7 @@ __go_map_delete (struct __go_map *map, const void *key)
{
const struct __go_map_descriptor *descriptor;
const struct __go_type_descriptor *key_descriptor;
- size_t key_offset;
+ uintptr_t key_offset;
_Bool (*equalfn) (const void*, const void*, size_t);
size_t key_hash;
size_t key_size;
diff --git a/libgo/runtime/go-map-index.c b/libgo/runtime/go-map-index.c
index 02a0f73f224..a387c4b98bc 100644
--- a/libgo/runtime/go-map-index.c
+++ b/libgo/runtime/go-map-index.c
@@ -18,7 +18,7 @@ __go_map_rehash (struct __go_map *map)
{
const struct __go_map_descriptor *descriptor;
const struct __go_type_descriptor *key_descriptor;
- size_t key_offset;
+ uintptr_t key_offset;
size_t key_size;
size_t (*hashfn) (const void *, size_t);
uintptr_t old_bucket_count;
@@ -78,7 +78,7 @@ __go_map_index (struct __go_map *map, const void *key, _Bool insert)
{
const struct __go_map_descriptor *descriptor;
const struct __go_type_descriptor *key_descriptor;
- size_t key_offset;
+ uintptr_t key_offset;
_Bool (*equalfn) (const void*, const void*, size_t);
size_t key_hash;
size_t key_size;
diff --git a/libgo/runtime/go-new-channel.c b/libgo/runtime/go-new-channel.c
index e440e873652..0c6f39185de 100644
--- a/libgo/runtime/go-new-channel.c
+++ b/libgo/runtime/go-new-channel.c
@@ -13,17 +13,26 @@
#include "channel.h"
struct __go_channel*
-__go_new_channel (const struct __go_type_descriptor *element_type,
+__go_new_channel (const struct __go_type_descriptor *channel_type,
uintptr_t entries)
{
+ const struct __go_channel_type *ctd;
+ const struct __go_type_descriptor *element_type;
uintptr_t element_size;
+ int ientries;
struct __go_channel* ret;
size_t alloc_size;
int i;
+ __go_assert (channel_type->__code == GO_CHAN);
+ ctd = (const struct __go_channel_type *) channel_type;
+ element_type = ctd->__element_type;
+
element_size = element_type->__size;
- if ((uintptr_t) (int) entries != entries
+ ientries = (int) entries;
+ if (ientries < 0
+ || (uintptr_t) ientries != entries
|| entries > (uintptr_t) -1 / element_size)
__go_panic_msg ("chan size out of range");
diff --git a/libgo/runtime/go-new-map.c b/libgo/runtime/go-new-map.c
index 3a471299b22..05ac8a1a40c 100644
--- a/libgo/runtime/go-new-map.c
+++ b/libgo/runtime/go-new-map.c
@@ -106,9 +106,11 @@ __go_map_next_prime (uintptr_t n)
struct __go_map *
__go_new_map (const struct __go_map_descriptor *descriptor, uintptr_t entries)
{
+ int ientries;
struct __go_map *ret;
- if ((uintptr_t) (int) entries != entries)
+ ientries = (int) entries;
+ if (ientries < 0 || (uintptr_t) ientries != entries)
__go_panic_msg ("map size out of range");
if (entries == 0)
diff --git a/libgo/runtime/go-reflect-call.c b/libgo/runtime/go-reflect-call.c
index a769142c3df..27177e2fc73 100644
--- a/libgo/runtime/go-reflect-call.c
+++ b/libgo/runtime/go-reflect-call.c
@@ -161,7 +161,7 @@ go_complex_to_ffi (ffi_type *float_type)
static ffi_type *
go_type_to_ffi (const struct __go_type_descriptor *descriptor)
{
- switch (descriptor->__code)
+ switch (descriptor->__code & GO_CODE_MASK)
{
case GO_BOOL:
if (sizeof (_Bool) == 1)
diff --git a/libgo/runtime/go-reflect-chan.c b/libgo/runtime/go-reflect-chan.c
index d568024b3df..61e360212f0 100644
--- a/libgo/runtime/go-reflect-chan.c
+++ b/libgo/runtime/go-reflect-chan.c
@@ -26,9 +26,6 @@ makechan (const struct __go_type_descriptor *typ, uint32_t size)
struct __go_channel *channel;
void *ret;
- __go_assert (typ->__code == GO_CHAN);
- typ = ((const struct __go_channel_type *) typ)->__element_type;
-
channel = __go_new_channel (typ, size);
ret = __go_alloc (sizeof (void *));
diff --git a/libgo/runtime/go-reflect.c b/libgo/runtime/go-reflect.c
index bf13a11fae2..af7d5e8968f 100644
--- a/libgo/runtime/go-reflect.c
+++ b/libgo/runtime/go-reflect.c
@@ -57,7 +57,7 @@ extern const struct __go_type_descriptor ptr_struct_descriptor
const struct __go_type_descriptor *
get_descriptor (int code)
{
- switch (code)
+ switch (code & GO_CODE_MASK)
{
case GO_BOOL:
return &ptr_bool_descriptor;
diff --git a/libgo/runtime/go-type.h b/libgo/runtime/go-type.h
index e048141e93e..6e2193982d6 100644
--- a/libgo/runtime/go-type.h
+++ b/libgo/runtime/go-type.h
@@ -53,13 +53,17 @@
#define GO_STRUCT 25
#define GO_UNSAFE_POINTER 26
+#define GO_NO_POINTERS (1 << 7)
+
+#define GO_CODE_MASK 0x7f
+
/* For each Go type the compiler constructs one of these structures.
This is used for type reflectin, interfaces, maps, and reference
counting. */
struct __go_type_descriptor
{
- /* The type code for this type, a value in enum __go_type_codes.
+ /* The type code for this type, one of the type kind values above.
This is used by unsafe.Reflect and unsafe.Typeof to determine the
type descriptor to return for this type itself. It is also used
by reflect.toType when mapping to a reflect Type structure. */
diff --git a/libgo/runtime/map.h b/libgo/runtime/map.h
index 40c31f82315..0c587bb2afa 100644
--- a/libgo/runtime/map.h
+++ b/libgo/runtime/map.h
@@ -22,15 +22,15 @@ struct __go_map_descriptor
key_type key;
value_type value;
This is the size of that struct. */
- size_t __entry_size;
+ uintptr_t __entry_size;
/* The offset of the key field in a map entry struct. */
- size_t __key_offset;
+ uintptr_t __key_offset;
/* The offset of the value field in a map entry struct (the value
field immediately follows the key field, but there may be some
bytes inserted for alignment). */
- size_t __val_offset;
+ uintptr_t __val_offset;
};
struct __go_map