|
From: <sv...@va...> - 2014-08-23 21:31:43
|
Author: florian
Date: Sat Aug 23 21:31:36 2014
New Revision: 14345
Log:
Replace CLG_(sprint_eventmapping) with CLG_(eventmapping_as_string)
which returns the string in a dynamically allocated but local buffer.
Fix call sites.
Modified:
branches/BUF_REMOVAL/callgrind/dump.c
branches/BUF_REMOVAL/callgrind/events.c
branches/BUF_REMOVAL/callgrind/events.h
branches/BUF_REMOVAL/callgrind/main.c
Modified: branches/BUF_REMOVAL/callgrind/dump.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/dump.c (original)
+++ branches/BUF_REMOVAL/callgrind/dump.c Sat Aug 23 21:31:36 2014
@@ -1376,10 +1376,9 @@
my_fwrite(fd, buf, VG_(strlen)(buf));
/* "events:" line */
- i = VG_(sprintf)(buf, "events: ");
- CLG_(sprint_eventmapping)(buf+i, CLG_(dumpmap));
+ VG_(sprintf)(buf, "events: %s\n",
+ CLG_(eventmapping_as_string)(CLG_(dumpmap)));
my_fwrite(fd, buf, VG_(strlen)(buf));
- my_fwrite(fd, "\n", 1);
/* summary lines */
sum = CLG_(get_eventset_cost)( CLG_(sets).full );
Modified: branches/BUF_REMOVAL/callgrind/events.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/events.c (original)
+++ branches/BUF_REMOVAL/callgrind/events.c Sat Aug 23 21:31:36 2014
@@ -517,23 +517,35 @@
}
-/* Returns number of characters written */
-Int CLG_(sprint_eventmapping)(HChar* buf, EventMapping* em)
+/* Returns pointer to dynamically string. The string will be overwritten
+ with each invocation. */
+const HChar *CLG_(eventmapping_as_string)(EventMapping* em)
{
Int i, pos = 0;
EventGroup* eg;
CLG_ASSERT(em != 0);
+ static HChar *buf = NULL;
+ static SizeT bufsiz = 0;
+
+ if (buf == NULL)
+ grow_buffer(&buf, &bufsiz, 100); // initial size
+ buf[0] = '\0';
+
for(i=0; i< em->size; i++) {
- if (pos>0) buf[pos++] = ' ';
+ if (pos>0) {
+ grow_buffer(&buf, &bufsiz, pos + 1);
+ buf[pos++] = ' ';
+ }
eg = eventGroup[em->entry[i].group];
CLG_ASSERT(eg != 0);
+ grow_buffer(&buf, &bufsiz,
+ pos + VG_(strlen)(eg->name[em->entry[i].index]) + 1);
pos += VG_(sprintf)(buf + pos, "%s", eg->name[em->entry[i].index]);
}
- buf[pos] = 0;
- return pos;
+ return buf;
}
/* Returns pointer to dynamically string. The string will be overwritten
Modified: branches/BUF_REMOVAL/callgrind/events.h
==============================================================================
--- branches/BUF_REMOVAL/callgrind/events.h (original)
+++ branches/BUF_REMOVAL/callgrind/events.h Sat Aug 23 21:31:36 2014
@@ -127,8 +127,10 @@
/* Allocate space for an event mapping */
EventMapping* CLG_(get_eventmapping)(EventSet*);
void CLG_(append_event)(EventMapping*, const HChar*);
-/* Returns number of characters written */
-Int CLG_(sprint_eventmapping)(HChar* buf, EventMapping*);
+/* Returns event mapping as a character string. That string is dnamically
+ allocated in a static buffer and will be overwritten with every allocation.
+ The function never returns NULL. */
+const HChar *CLG_(eventmapping_as_string)(EventMapping*);
/* Returns mapping cost as a character string. That string is dnamically
allocated in a static buffer and will be overwritten with every allocation.
The function never returns NULL. */
Modified: branches/BUF_REMOVAL/callgrind/main.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/main.c (original)
+++ branches/BUF_REMOVAL/callgrind/main.c Sat Aug 23 21:31:36 2014
@@ -1539,9 +1539,8 @@
VG_(gdb_printf)("distinct-contexts: %d\n", CLG_(stat).distinct_contexts);
/* "events:" line. Given here because it will be dynamic in the future */
- p = VG_(sprintf)(buf, "events: ");
- CLG_(sprint_eventmapping)(buf+p, CLG_(dumpmap));
- VG_(gdb_printf)("%s\n", buf);
+ VG_(gdb_printf)("events: %s\n",
+ CLG_(eventmapping_as_string)(CLG_(dumpmap)));
/* "part:" line (number of last part. Is 0 at start */
VG_(gdb_printf)("part: %d\n", CLG_(get_dump_counter)());
@@ -1884,8 +1883,7 @@
static
void finish(void)
{
- HChar buf[32+COSTS_LEN];
- HChar fmt[128];
+ HChar fmt[128]; // large enough
Int l1, l2, l3;
FullCost total;
@@ -1907,8 +1905,8 @@
VG_(message)(Vg_DebugMsg, "\n");
}
- CLG_(sprint_eventmapping)(buf, CLG_(dumpmap));
- VG_(message)(Vg_UserMsg, "Events : %s\n", buf);
+ VG_(message)(Vg_UserMsg, "Events : %s\n",
+ CLG_(eventmapping_as_string)(CLG_(dumpmap)));
VG_(message)(Vg_UserMsg, "Collected : %s\n",
CLG_(mappingcost_as_string)(CLG_(dumpmap), CLG_(total_cost)));
VG_(message)(Vg_UserMsg, "\n");
|