Merge the memory allocation bits from libvex.h into main_util.c.
This is to avoid linkage problems due to unresolved symbols for
some compilers. See also valgrind r14600 and BZ #339542.
git-svn-id: svn://svn.valgrind.org/vex/trunk@2974 8f6e269a-dfd6-0310-a8e1-e2731360e62c
diff --git a/priv/main_util.c b/priv/main_util.c
index 3165230..2031b88 100644
--- a/priv/main_util.c
+++ b/priv/main_util.c
@@ -67,6 +67,11 @@
static HChar* permanent_curr = &permanent[0];
static HChar* permanent_last = &permanent[N_PERMANENT_BYTES-1];
+static HChar* private_LibVEX_alloc_first = &temporary[0];
+static HChar* private_LibVEX_alloc_curr = &temporary[0];
+static HChar* private_LibVEX_alloc_last = &temporary[N_TEMPORARY_BYTES-1];
+
+
static VexAllocMode mode = VexAllocModeTEMP;
void vexAllocSanityCheck ( void )
@@ -149,14 +154,8 @@
return mode;
}
-/* Visible to library client, unfortunately. */
-
-HChar* private_LibVEX_alloc_first = &temporary[0];
-HChar* private_LibVEX_alloc_curr = &temporary[0];
-HChar* private_LibVEX_alloc_last = &temporary[N_TEMPORARY_BYTES-1];
-
__attribute__((noreturn))
-void private_LibVEX_alloc_OOM(void)
+static void private_LibVEX_alloc_OOM(void)
{
const HChar* pool = "???";
if (private_LibVEX_alloc_first == &temporary[0]) pool = "TEMP";
@@ -197,6 +196,51 @@
/* Exported to library client. */
+/* Allocate in Vex's temporary allocation area. Be careful with this.
+ You can only call it inside an instrumentation or optimisation
+ callback that you have previously specified in a call to
+ LibVEX_Translate. The storage allocated will only stay alive until
+ translation of the current basic block is complete.
+ */
+
+void* LibVEX_Alloc ( Int nbytes )
+{
+ struct align {
+ char c;
+ union {
+ char c;
+ short s;
+ int i;
+ long l;
+ long long ll;
+ float f;
+ double d;
+ /* long double is currently not used and would increase alignment
+ unnecessarily. */
+ /* long double ld; */
+ void *pto;
+ void (*ptf)(void);
+ } x;
+ };
+
+#if 0
+ /* Nasty debugging hack, do not use. */
+ return malloc(nbytes);
+#else
+ HChar* curr;
+ HChar* next;
+ Int ALIGN;
+ ALIGN = offsetof(struct align,x) - 1;
+ nbytes = (nbytes + ALIGN) & ~ALIGN;
+ curr = private_LibVEX_alloc_curr;
+ next = curr + nbytes;
+ if (next >= private_LibVEX_alloc_last)
+ private_LibVEX_alloc_OOM();
+ private_LibVEX_alloc_curr = next;
+ return curr;
+#endif
+}
+
void LibVEX_ShowAllocStats ( void )
{
vex_printf("vex storage: T total %lld bytes allocated\n",
diff --git a/pub/libvex.h b/pub/libvex.h
index 7ebe26f..6da02da 100644
--- a/pub/libvex.h
+++ b/pub/libvex.h
@@ -452,50 +452,8 @@
You can only call it inside an instrumentation or optimisation
callback that you have previously specified in a call to
LibVEX_Translate. The storage allocated will only stay alive until
- translation of the current basic block is complete.
- */
-extern HChar* private_LibVEX_alloc_first;
-extern HChar* private_LibVEX_alloc_curr;
-extern HChar* private_LibVEX_alloc_last;
-extern void private_LibVEX_alloc_OOM(void) __attribute__((noreturn));
-
-static inline void* LibVEX_Alloc ( Int nbytes )
-{
- struct align {
- char c;
- union {
- char c;
- short s;
- int i;
- long l;
- long long ll;
- float f;
- double d;
- /* long double is currently not used and would increase alignment
- unnecessarily. */
- /* long double ld; */
- void *pto;
- void (*ptf)(void);
- } x;
- };
-
-#if 0
- /* Nasty debugging hack, do not use. */
- return malloc(nbytes);
-#else
- HChar* curr;
- HChar* next;
- Int ALIGN;
- ALIGN = offsetof(struct align,x) - 1;
- nbytes = (nbytes + ALIGN) & ~ALIGN;
- curr = private_LibVEX_alloc_curr;
- next = curr + nbytes;
- if (next >= private_LibVEX_alloc_last)
- private_LibVEX_alloc_OOM();
- private_LibVEX_alloc_curr = next;
- return curr;
-#endif
-}
+ translation of the current basic block is complete. */
+extern void* LibVEX_Alloc ( Int nbytes );
/* Show Vex allocation statistics. */
extern void LibVEX_ShowAllocStats ( void );