Skip to content

Commit 35aa3f4

Browse files
committed
refactor(backtrace): delete buffer_t
1 parent 39143f0 commit 35aa3f4

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

awesome.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,8 @@ a_glib_poll(GPollFD *ufds, guint nfsd, gint timeout)
492492
static void
493493
signal_fatal(int signum)
494494
{
495-
buffer_t buf;
496-
backtrace_get(&buf);
497-
fatal("signal %d, dumping backtrace\n%s", signum, buf.s);
495+
GString* buf = backtrace_get();
496+
fatal("signal %d, dumping backtrace\n%s", signum, buf->str);
498497
}
499498

500499
/* Signal handler for SIGCHLD. Causes reap_children() to be called. */

common/backtrace.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "config.h"
2323
#include "common/backtrace.h"
24+
#include "common/util.h"
2425

2526
#ifdef HAS_EXECINFO
2627
#include <execinfo.h>
@@ -31,11 +32,10 @@
3132
/** Get a backtrace.
3233
* \param buf The buffer to fill with backtrace.
3334
*/
34-
void
35-
backtrace_get(buffer_t *buf)
35+
GString*
36+
backtrace_get(void)
3637
{
37-
buffer_init(buf);
38-
38+
GString *buf = g_string_new(NULL);
3939
#ifdef HAS_EXECINFO
4040
void *stack[MAX_STACK_SIZE];
4141
char **bt;
@@ -49,14 +49,15 @@ backtrace_get(buffer_t *buf)
4949
for(int i = 0; i < stack_size; i++)
5050
{
5151
if(i > 0)
52-
buffer_addsl(buf, "\n");
53-
buffer_adds(buf, bt[i]);
52+
g_string_append(buf, "\n");
53+
g_string_append(buf, bt[i]);
5454
}
5555
p_delete(&bt);
5656
}
5757
else
5858
#endif
59-
buffer_addsl(buf, "Cannot get backtrace symbols.");
59+
g_string_append(buf, "Cannot get backtrace symbols.");
60+
return buf;
6061
}
6162

6263
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

common/backtrace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#ifndef AWESOME_COMMON_BACKTRACE
2323
#define AWESOME_COMMON_BACKTRACE
2424

25-
#include "common/buffer.h"
25+
#include <glib.h>
2626

27-
void backtrace_get(buffer_t *);
27+
GString* backtrace_get(void);
2828

2929
#endif
3030

common/luaobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ luaA_object_decref(lua_State *L, int tud, const void *pointer)
125125
/* Did we find the item in our table? (tointeger(nil)-1) is -1 */
126126
if (count < 0)
127127
{
128-
buffer_t buf;
129-
backtrace_get(&buf);
130-
warn("BUG: Reference not found: %d %p\n%s", tud, pointer, buf.s);
128+
GString* buf = backtrace_get();
129+
warn("BUG: Reference not found: %d %p\n%s", tud, pointer, buf->str);
130+
g_string_free(buf, TRUE);
131131

132132
/* Pop reference count and metatable */
133133
lua_pop(L, 2);

luaa.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,8 @@ luaA_panic(lua_State *L)
862862
{
863863
warn("unprotected error in call to Lua API (%s)",
864864
lua_tostring(L, -1));
865-
buffer_t buf;
866-
backtrace_get(&buf);
867-
warn("dumping backtrace\n%s", buf.s);
865+
GString* buf = backtrace_get();
866+
warn("dumping backtrace\n%s", buf->str);
868867
warn("restarting awesome");
869868
awesome_restart();
870869
return 0;

0 commit comments

Comments
 (0)