Extract the function bitcount to a separate module
diff --git a/Makefile.am b/Makefile.am
index 90a3d0d..db16372 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of ltrace.
-# Copyright (C) 2012 Petr Machata, Red Hat Inc.
+# Copyright (C) 2012, 2013 Petr Machata, Red Hat Inc.
# Copyright (C) 2010 Marc Kleine-Budde, Pengutronix
# Copyright (C) 2010 Zachary T Welch, CodeSourcery
#
@@ -28,7 +28,7 @@
noinst_LTLIBRARIES = \
libltrace.la
-libltrace_la_SOURCES = breakpoints.c debug.c demangle.c dict.c \
+libltrace_la_SOURCES = bits.c breakpoints.c debug.c demangle.c dict.c \
ltrace-elf.c execute_program.c handle_event.c libltrace.c \
options.c output.c proc.c read_config_file.c summary.c \
library.c filter.c glob.c type.c value.c value_dict.c expr.c \
@@ -52,12 +52,12 @@
ltrace_LDADD = \
libltrace.la
-noinst_HEADERS = backend.h breakpoint.h common.h debug.h defs.h \
- demangle.h dict.h forward.h ltrace-elf.h ltrace.h options.h \
- output.h proc.h read_config_file.h library.h filter.h glob.h \
- vect.h type.h value.h value_dict.h callback.h expr.h fetch.h \
- vect.h param.h printf.h zero.h lens.h lens_default.h \
- lens_enum.h memstream.h prototype.h
+noinst_HEADERS = bits.h backend.h breakpoint.h common.h debug.h \
+ defs.h demangle.h dict.h forward.h ltrace-elf.h ltrace.h \
+ options.h output.h proc.h read_config_file.h library.h \
+ filter.h glob.h vect.h type.h value.h value_dict.h callback.h \
+ expr.h fetch.h vect.h param.h printf.h zero.h lens.h \
+ lens_default.h lens_enum.h memstream.h prototype.h
dist_man1_MANS = ltrace.1
dist_man5_MANS = ltrace.conf.5
diff --git a/bits.c b/bits.c
new file mode 100644
index 0000000..bde2e71
--- /dev/null
+++ b/bits.c
@@ -0,0 +1,34 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2013 Petr Machata, Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "bits.h"
+
+/* This is called rarely, and any overhead will be lost in ptrace
+ * noise, so the algorithm doesn't need to be terribly clever. For
+ * the same reason we don't bother defining the corresponding _32
+ * variant. */
+unsigned
+bitcount(uint64_t u)
+{
+ int c = 0;
+ for (; u > 0; u &= u - 1)
+ c++;
+ return c;
+}
diff --git a/bits.h b/bits.h
new file mode 100644
index 0000000..7dbe478
--- /dev/null
+++ b/bits.h
@@ -0,0 +1,29 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2013 Petr Machata, Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _BITS_H_
+#define _BITS_H_
+
+#include <stdint.h>
+
+/* Count bits in U that are 1. */
+unsigned bitcount(uint64_t u);
+
+#endif /* _BITS_H_ */
diff --git a/lens_default.c b/lens_default.c
index 26ba22e..e0c0566 100644
--- a/lens_default.c
+++ b/lens_default.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
+#include "bits.h"
#include "proc.h"
#include "lens_default.h"
#include "value.h"
@@ -608,15 +609,6 @@
return fprintf(stream, "%zd-%zd", low, high);
}
-static unsigned
-bitcount(unsigned u)
-{
- int c = 0;
- for (; u > 0; u &= u - 1)
- c++;
- return c;
-}
-
static int
bitvect_lens_format_cb(struct lens *lens, FILE *stream,
struct value *value, struct value_dict *arguments)