diff mbox

Go patch committed: Add cgo support routines

Message ID mcrsjwz2rxn.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Jan. 11, 2011, 6:53 p.m. UTC
This patch to libgo adds cgo support routines like the ones I recently
added to the gc compiler.  These routines are used by code generated by
the development version of SWIG (as of this morning).  There is one
routine to allocate memory controlled by the Go garbage collector, and
one routine to invoke the Go builtin function panic.  Bootstrapped and
ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r e9aa16b9895e libgo/Makefile.am
--- a/libgo/Makefile.am	Wed Jan 05 17:32:49 2011 -0800
+++ b/libgo/Makefile.am	Tue Jan 11 10:48:40 2011 -0800
@@ -312,6 +312,7 @@ 
 	runtime/go-breakpoint.c \
 	runtime/go-caller.c \
 	runtime/go-can-convert-interface.c \
+	runtime/go-cgo.c \
 	runtime/go-chan-cap.c \
 	runtime/go-chan-len.c \
 	runtime/go-check-interface.c \
diff -r e9aa16b9895e libgo/Makefile.in
--- a/libgo/Makefile.in	Wed Jan 05 17:32:49 2011 -0800
+++ b/libgo/Makefile.in	Tue Jan 11 10:48:40 2011 -0800
@@ -126,7 +126,7 @@ 
 	runtime/go-assert-interface.c \
 	runtime/go-byte-array-to-string.c runtime/go-breakpoint.c \
 	runtime/go-caller.c runtime/go-can-convert-interface.c \
-	runtime/go-chan-cap.c runtime/go-chan-len.c \
+	runtime/go-cgo.c runtime/go-chan-cap.c runtime/go-chan-len.c \
 	runtime/go-check-interface.c runtime/go-close.c \
 	runtime/go-closed.c runtime/go-construct-map.c \
 	runtime/go-convert-interface.c runtime/go-copy.c \
@@ -172,8 +172,8 @@ 
 @LIBGO_IS_RTEMS_TRUE@am__objects_2 = rtems-task-variable-add.lo
 am__objects_3 = go-append.lo go-assert.lo go-assert-interface.lo \
 	go-byte-array-to-string.lo go-breakpoint.lo go-caller.lo \
-	go-can-convert-interface.lo go-chan-cap.lo go-chan-len.lo \
-	go-check-interface.lo go-close.lo go-closed.lo \
+	go-can-convert-interface.lo go-cgo.lo go-chan-cap.lo \
+	go-chan-len.lo go-check-interface.lo go-close.lo go-closed.lo \
 	go-construct-map.lo go-convert-interface.lo go-copy.lo \
 	go-defer.lo go-deferred-recover.lo go-eface-compare.lo \
 	go-eface-val-compare.lo go-getgoroot.lo go-go.lo \
@@ -678,6 +678,7 @@ 
 	runtime/go-breakpoint.c \
 	runtime/go-caller.c \
 	runtime/go-can-convert-interface.c \
+	runtime/go-cgo.c \
 	runtime/go-chan-cap.c \
 	runtime/go-chan-len.c \
 	runtime/go-check-interface.c \
@@ -1886,6 +1887,7 @@ 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-byte-array-to-string.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-caller.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-can-convert-interface.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-cgo.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-chan-cap.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-chan-len.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-check-interface.Plo@am__quote@
@@ -2062,6 +2064,13 @@ 
 @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-can-convert-interface.lo `test -f 'runtime/go-can-convert-interface.c' || echo '$(srcdir)/'`runtime/go-can-convert-interface.c
 
+go-cgo.lo: runtime/go-cgo.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-cgo.lo -MD -MP -MF $(DEPDIR)/go-cgo.Tpo -c -o go-cgo.lo `test -f 'runtime/go-cgo.c' || echo '$(srcdir)/'`runtime/go-cgo.c
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/go-cgo.Tpo $(DEPDIR)/go-cgo.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='runtime/go-cgo.c' object='go-cgo.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-cgo.lo `test -f 'runtime/go-cgo.c' || echo '$(srcdir)/'`runtime/go-cgo.c
+
 go-chan-cap.lo: runtime/go-chan-cap.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-chan-cap.lo -MD -MP -MF $(DEPDIR)/go-chan-cap.Tpo -c -o go-chan-cap.lo `test -f 'runtime/go-chan-cap.c' || echo '$(srcdir)/'`runtime/go-chan-cap.c
 @am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/go-chan-cap.Tpo $(DEPDIR)/go-chan-cap.Plo
diff -r e9aa16b9895e libgo/runtime/go-cgo.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/runtime/go-cgo.c	Tue Jan 11 10:48:40 2011 -0800
@@ -0,0 +1,42 @@ 
+/* go-cgo.c -- SWIG support routines for libgo.
+
+   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 "go-alloc.h"
+#include "interface.h"
+#include "go-panic.h"
+#include "go-string.h"
+
+/* These are routines used by SWIG.  The gc runtime library provides
+   the same routines under the same name, though in that case the code
+   is required to import runtime/cgo.  */
+
+void *
+_cgo_allocate (size_t n)
+{
+  return __go_alloc (n);
+}
+
+extern const struct __go_type_descriptor string_type_descriptor
+  asm ("__go_tdn_string");
+
+void
+_cgo_panic (const char *p)
+{
+  int len;
+  unsigned char *data;
+  struct __go_string *ps;
+  struct __go_empty_interface e;
+
+  len = __builtin_strlen (p);
+  data = __go_alloc (len);
+  __builtin_memcpy (data, p, len);
+  ps = __go_alloc (sizeof *ps);
+  ps->__data = data;
+  ps->__length = len;
+  e.__type_descriptor = &string_type_descriptor;
+  e.__object = ps;
+  __go_panic (e);
+}