From ca40090460a6e43112c1f9e9d414727c29a9847d Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sun, 4 Jan 2009 12:31:41 +0100 Subject: Setup warning flags and fixes missing static attribute for local funtions. --- Makefile.am | 2 +- autogen.sh | 2 +- configure.ac | 4 ++++ m4/as-compiler-flag.m4 | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/bplist.c | 42 +++++++++++++++++----------------- src/plist.c | 2 +- src/plist.h | 2 ++ 8 files changed, 93 insertions(+), 25 deletions(-) create mode 100644 m4/as-compiler-flag.m4 diff --git a/Makefile.am b/Makefile.am index 7a67ab6..e88e9be 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ AUTOMAKE_OPTIONS = foreign - +ACLOCAL_AMFLAGS = -I m4 SUBDIRS = src include plutil pkgconfigdir = $(libdir)/pkgconfig diff --git a/autogen.sh b/autogen.sh index c17ea96..9aa7170 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,5 +1,5 @@ #!/bin/sh -aclocal +aclocal -I m4 libtoolize autoheader automake --add-missing diff --git a/configure.ac b/configure.ac index aa3a2e2..4af0e49 100644 --- a/configure.ac +++ b/configure.ac @@ -6,6 +6,7 @@ AC_INIT(libplist, 0.1.0, nospam@nowhere.com) AM_INIT_AUTOMAKE(libplist, 0.1.0) AC_CONFIG_SRCDIR([src/]) AC_CONFIG_HEADER([config.h]) +AC_CONFIG_MACRO_DIR([m4]) AC_PROG_LIBTOOL @@ -44,4 +45,7 @@ if test "$no_debug_code" = true; then AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code]) fi +AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default") +AC_SUBST(GLOBAL_CFLAGS) + AC_OUTPUT(Makefile src/Makefile include/Makefile plutil/Makefile libplist-1.0.pc) diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4 new file mode 100644 index 0000000..0f660cf --- /dev/null +++ b/m4/as-compiler-flag.m4 @@ -0,0 +1,62 @@ +dnl as-compiler-flag.m4 0.1.0 + +dnl autostars m4 macro for detection of compiler flags + +dnl David Schleef + +dnl $Id: as-compiler-flag.m4,v 1.1 2005/12/15 23:35:19 ds Exp $ + +dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED]) +dnl Tries to compile with the given CFLAGS. +dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags, +dnl and ACTION-IF-NOT-ACCEPTED otherwise. + +AC_DEFUN([AS_COMPILER_FLAG], +[ + AC_MSG_CHECKING([to see if compiler understands $1]) + + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $1" + + AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) + CFLAGS="$save_CFLAGS" + + if test "X$flag_ok" = Xyes ; then + m4_ifvaln([$2],[$2]) + true + else + m4_ifvaln([$3],[$3]) + true + fi + AC_MSG_RESULT([$flag_ok]) +]) + +dnl AS_COMPILER_FLAGS(VAR, FLAGS) +dnl Tries to compile with the given CFLAGS. + +AC_DEFUN([AS_COMPILER_FLAGS], +[ + list=$2 + flags_supported="" + flags_unsupported="" + AC_MSG_CHECKING([for supported compiler flags]) + for each in $list + do + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $each" + AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) + CFLAGS="$save_CFLAGS" + + if test "X$flag_ok" = Xyes ; then + flags_supported="$flags_supported $each" + else + flags_unsupported="$flags_unsupported $each" + fi + done + AC_MSG_RESULT([$flags_supported]) + if test "X$flags_unsupported" != X ; then + AC_MSG_WARN([unsupported compiler flags: $flags_unsupported]) + fi + $1="$$1 $flags_supported" +]) + diff --git a/src/Makefile.am b/src/Makefile.am index 07143b6..3178d8a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ INCLUDES = -I$(top_srcdir)/include -AM_CFLAGS = $(libxml2_CFLAGS) $(libglib2_CFLAGS) -D_GNU_SOURCE +AM_CFLAGS = $(GLOBAL_CFLAGS) $(libxml2_CFLAGS) $(libglib2_CFLAGS) -D_GNU_SOURCE AM_LDFLAGS = $(libxml2_LIBS) $(libglib2_LIBS) lib_LTLIBRARIES = libplist.la diff --git a/src/bplist.c b/src/bplist.c index 54a4bb2..94d7458 100644 --- a/src/bplist.c +++ b/src/bplist.c @@ -59,9 +59,9 @@ enum { BPLIST_MASK = 0xF0 }; -void byte_convert(char *address, size_t size) +static void byte_convert(char *address, size_t size) { - int i = 0, j = 0; + uint8_t i = 0, j = 0; char tmp = '\0'; for (i = 0; i < (size / 2); i++) { @@ -83,7 +83,7 @@ void byte_convert(char *address, size_t size) #define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= (uint64_t)1<<32 ? 4 : 8))) #define get_real_bytes(x) (x >> 32 ? 4 : 8) -plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object) +static plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object) { plist_data_t data = plist_new_plist_data(); @@ -114,7 +114,7 @@ plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object) return g_node_new(data); } -plist_t parse_real_node(char *bnode, uint8_t size) +static plist_t parse_real_node(char *bnode, uint8_t size) { plist_data_t data = plist_new_plist_data(); @@ -136,7 +136,7 @@ plist_t parse_real_node(char *bnode, uint8_t size) return g_node_new(data); } -plist_t parse_string_node(char *bnode, uint8_t size) +static plist_t parse_string_node(char *bnode, uint8_t size) { plist_data_t data = plist_new_plist_data(); @@ -148,7 +148,7 @@ plist_t parse_string_node(char *bnode, uint8_t size) return g_node_new(data); } -plist_t parse_unicode_node(char *bnode, uint8_t size) +static plist_t parse_unicode_node(char *bnode, uint8_t size) { plist_data_t data = plist_new_plist_data(); @@ -160,7 +160,7 @@ plist_t parse_unicode_node(char *bnode, uint8_t size) return g_node_new(data); } -plist_t parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) +static plist_t parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) { plist_data_t data = plist_new_plist_data(); @@ -172,7 +172,7 @@ plist_t parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) return g_node_new(data); } -plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) +static plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) { plist_data_t data = plist_new_plist_data(); @@ -184,7 +184,7 @@ plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) return g_node_new(data); } -plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) +static plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) { plist_data_t data = plist_new_plist_data(); @@ -198,7 +198,7 @@ plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) -plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_object) +static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_object) { if (!object) return NULL; @@ -297,7 +297,7 @@ plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_object) return NULL; } -gpointer copy_plist_data(gconstpointer src, gpointer data) +static gpointer copy_plist_data(gconstpointer src, gpointer data) { plist_data_t srcdata = (plist_data_t) src; plist_data_t dstdata = plist_new_plist_data(); @@ -387,7 +387,7 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist) } //setup children for structured types - int j = 0, str_i = 0, str_j = 0; + uint32_t j = 0, str_i = 0, str_j = 0; uint32_t index1 = 0, index2 = 0; for (i = 0; i < num_objects; i++) { @@ -449,7 +449,7 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist) *plist = nodeslist[root_object]; } -guint plist_data_hash(gconstpointer key) +static guint plist_data_hash(gconstpointer key) { plist_data_t data = plist_get_data((plist_t) key); @@ -494,7 +494,7 @@ guint plist_data_hash(gconstpointer key) return hash; } -gboolean plist_data_compare(gconstpointer a, gconstpointer b) +static gboolean plist_data_compare(gconstpointer a, gconstpointer b) { if (!a || !b) return FALSE; @@ -550,7 +550,7 @@ struct serialize_s { GHashTable *ref_table; }; -void serialize_plist(GNode * node, gpointer data) +static void serialize_plist(GNode * node, gpointer data) { struct serialize_s *ser = (struct serialize_s *) data; uint64_t current_index = ser->objects->len; @@ -585,7 +585,7 @@ void write_int(GByteArray * bplist, uint64_t val) free(buff); } -void write_real(GByteArray * bplist, double val) +static void write_real(GByteArray * bplist, double val) { uint64_t size = get_real_bytes(*((uint64_t *) & val)); //cheat to know used space uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size); @@ -596,7 +596,7 @@ void write_real(GByteArray * bplist, double val) free(buff); } -void write_raw_data(GByteArray * bplist, uint8_t mark, uint8_t * val, uint64_t size) +static void write_raw_data(GByteArray * bplist, uint8_t mark, uint8_t * val, uint64_t size) { uint8_t marker = mark | (size < 15 ? size : 0xf); g_byte_array_append(bplist, &marker, sizeof(uint8_t)); @@ -612,18 +612,18 @@ void write_raw_data(GByteArray * bplist, uint8_t mark, uint8_t * val, uint64_t s free(buff); } -void write_data(GByteArray * bplist, uint8_t * val, uint64_t size) +static void write_data(GByteArray * bplist, uint8_t * val, uint64_t size) { write_raw_data(bplist, BPLIST_DATA, val, size); } -void write_string(GByteArray * bplist, char *val) +static void write_string(GByteArray * bplist, char *val) { uint64_t size = strlen(val); write_raw_data(bplist, BPLIST_STRING, val, size); } -void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) +static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) { uint64_t size = g_node_n_children(node); uint8_t marker = BPLIST_ARRAY | (size < 15 ? size : 0xf); @@ -652,7 +652,7 @@ void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint } -void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) +static void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) { uint64_t size = g_node_n_children(node) / 2; uint8_t marker = BPLIST_DICT | (size < 15 ? size : 0xf); diff --git a/src/plist.c b/src/plist.c index a3d3cb2..d737ab8 100644 --- a/src/plist.c +++ b/src/plist.c @@ -136,7 +136,7 @@ plist_t plist_get_prev_sibling(plist_t node) return (plist_t) g_node_prev_sibling((GNode *) node); } -char compare_node_value(plist_type type, plist_data_t data, void *value, uint64_t length) +static char compare_node_value(plist_type type, plist_data_t data, void *value, uint64_t length) { char res = FALSE; switch (type) { diff --git a/src/plist.h b/src/plist.h index b7c74d9..3f4036f 100644 --- a/src/plist.h +++ b/src/plist.h @@ -55,6 +55,8 @@ plist_t plist_new_node(plist_data_t data); plist_data_t plist_get_data(const plist_t node); plist_data_t plist_new_plist_data(); void plist_free_plist_data(plist_data_t node); +plist_type plist_get_node_type(plist_t node); +uint64_t plist_get_node_uint_val(plist_t node); #endif -- cgit v1.1-32-gdbae