summaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2016-11-18 16:03:13 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2016-11-18 16:03:13 +0000
commitf236585fa498c057604301efbee77852b575a2ab (patch)
tree356d413f3cd82dbe584ad7d102361dc23a5e300a /libgo
parent11f79d589c09e40457ed027190495cdb506227e7 (diff)
downloadgcc-f236585fa498c057604301efbee77852b575a2ab.tar.gz
runtime: don't call __go_alloc/__go_free in environment functions
Reviewed-on: https://go-review.googlesource.com/33363 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@242594 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-rw-r--r--libgo/runtime/go-setenv.c37
-rw-r--r--libgo/runtime/go-unsetenv.c17
2 files changed, 21 insertions, 33 deletions
diff --git a/libgo/runtime/go-setenv.c b/libgo/runtime/go-setenv.c
index a75d7c41277..81b1775d2c9 100644
--- a/libgo/runtime/go-setenv.c
+++ b/libgo/runtime/go-setenv.c
@@ -9,10 +9,7 @@
#include <stddef.h>
#include <stdlib.h>
-#include "go-alloc.h"
#include "runtime.h"
-#include "arch.h"
-#include "malloc.h"
/* Set the C environment from Go. This is called by syscall.Setenv. */
@@ -25,7 +22,6 @@ setenv_c (String k, String v)
unsigned char *kn;
const byte *vs;
unsigned char *vn;
- intgo len;
ks = k.str;
if (ks == NULL)
@@ -39,25 +35,23 @@ setenv_c (String k, String v)
#ifdef HAVE_SETENV
- if (ks != NULL && ks[k.len] != 0)
+ if (ks[k.len] != 0)
{
- // Objects that are explicitly freed must be at least 16 bytes in size,
- // so that they are not allocated using tiny alloc.
- len = k.len + 1;
- if (len < TinySize)
- len = TinySize;
- kn = __go_alloc (len);
+ kn = malloc (k.len + 1);
+ if (kn == NULL)
+ runtime_throw ("out of malloc memory");
__builtin_memcpy (kn, ks, k.len);
+ kn[k.len] = '\0';
ks = kn;
}
- if (vs != NULL && vs[v.len] != 0)
+ if (vs[v.len] != 0)
{
- len = v.len + 1;
- if (len < TinySize)
- len = TinySize;
- vn = __go_alloc (len);
+ vn = malloc (v.len + 1);
+ if (vn == NULL)
+ runtime_throw ("out of malloc memory");
__builtin_memcpy (vn, vs, v.len);
+ vn[v.len] = '\0';
vs = vn;
}
@@ -66,19 +60,20 @@ setenv_c (String k, String v)
#else /* !defined(HAVE_SETENV) */
len = k.len + v.len + 2;
- if (len < TinySize)
- len = TinySize;
- kn = __go_alloc (len);
+ kn = malloc (len);
+ if (kn == NULL)
+ runtime_throw ("out of malloc memory");
__builtin_memcpy (kn, ks, k.len);
kn[k.len] = '=';
__builtin_memcpy (kn + k.len + 1, vs, v.len);
kn[k.len + v.len + 1] = '\0';
putenv ((char *) kn);
+ kn = NULL; /* putenv takes ownership of the string. */
#endif /* !defined(HAVE_SETENV) */
if (kn != NULL)
- __go_free (kn);
+ free (kn);
if (vn != NULL)
- __go_free (vn);
+ free (vn);
}
diff --git a/libgo/runtime/go-unsetenv.c b/libgo/runtime/go-unsetenv.c
index 409436a0d3f..21359975f2b 100644
--- a/libgo/runtime/go-unsetenv.c
+++ b/libgo/runtime/go-unsetenv.c
@@ -9,10 +9,7 @@
#include <stddef.h>
#include <stdlib.h>
-#include "go-alloc.h"
#include "runtime.h"
-#include "arch.h"
-#include "malloc.h"
/* Unset an environment variable from Go. This is called by
syscall.Unsetenv. */
@@ -24,7 +21,6 @@ unsetenv_c (String k)
{
const byte *ks;
unsigned char *kn;
- intgo len;
ks = k.str;
if (ks == NULL)
@@ -33,14 +29,11 @@ unsetenv_c (String k)
#ifdef HAVE_UNSETENV
- if (ks != NULL && ks[k.len] != 0)
+ if (ks[k.len] != 0)
{
- // Objects that are explicitly freed must be at least 16 bytes in size,
- // so that they are not allocated using tiny alloc.
- len = k.len + 1;
- if (len < TinySize)
- len = TinySize;
- kn = __go_alloc (len);
+ kn = malloc (k.len + 1);
+ if (kn == NULL)
+ runtime_throw ("out of malloc memory");
__builtin_memcpy (kn, ks, k.len);
ks = kn;
}
@@ -50,5 +43,5 @@ unsetenv_c (String k)
#endif /* !defined(HAVE_UNSETENV) */
if (kn != NULL)
- __go_free (kn);
+ free (kn);
}