[pulseaudio-discuss] [PATCH] Add pure and const attributes to functions that need them

Maarten Bosmans mkbosmans at gmail.com
Thu Nov 17 07:06:04 PST 2011


---
 src/modules/alsa/alsa-mixer.c       |    4 ++--
 src/modules/module-device-manager.c |    2 +-
 src/modules/rtp/rtp.h               |    5 +++--
 src/pulse/channelmap.h              |    2 +-
 src/pulse/context.h                 |    2 +-
 src/pulse/format.h                  |    6 +++---
 src/pulse/sample.h                  |    2 +-
 src/pulse/timeval.h                 |    2 +-
 src/pulse/util.h                    |    3 ++-
 src/pulsecore/bitset.h              |    2 +-
 src/pulsecore/core-rtclock.h        |    6 ++++--
 src/pulsecore/core-util.c           |    1 -
 src/pulsecore/core-util.h           |    2 +-
 src/pulsecore/dbus-util.c           |    2 +-
 src/pulsecore/idxset.h              |   10 ++++++----
 src/pulsecore/memchunk.c            |    2 +-
 src/pulsecore/memchunk.h            |    2 +-
 src/pulsecore/module.h              |   25 +++++++++++++------------
 src/pulsecore/namereg.h             |    4 ++--
 src/pulsecore/resampler.h           |    4 ++--
 20 files changed, 47 insertions(+), 41 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 151eef5..3f27fdc 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -2907,7 +2907,7 @@ void pa_alsa_path_set_dump(pa_alsa_path_set *ps) {
 }
 
 
-static pa_bool_t options_have_option(pa_alsa_option *options, const char *alsa_name) {
+static PA_GCC_PURE pa_bool_t options_have_option(pa_alsa_option *options, const char *alsa_name) {
     pa_alsa_option *o;
 
     pa_assert(options);
@@ -2920,7 +2920,7 @@ static pa_bool_t options_have_option(pa_alsa_option *options, const char *alsa_n
     return FALSE;
 }
 
-static pa_bool_t enumeration_is_subset(pa_alsa_option *a_options, pa_alsa_option *b_options) {
+static PA_GCC_PURE pa_bool_t enumeration_is_subset(pa_alsa_option *a_options, pa_alsa_option *b_options) {
     pa_alsa_option *oa, *ob;
 
     if (!a_options) return TRUE;
diff --git a/src/modules/module-device-manager.c b/src/modules/module-device-manager.c
index d7f30c6..e1f6ae9 100644
--- a/src/modules/module-device-manager.c
+++ b/src/modules/module-device-manager.c
@@ -533,7 +533,7 @@ static inline struct entry *load_or_initialize_entry(struct userdata *u, struct
     return old;
 }
 
-static uint32_t get_role_index(const char* role) {
+static PA_GCC_PURE uint32_t get_role_index(const char* role) {
     pa_assert(role);
 
     for (uint32_t i = ROLE_NONE; i < NUM_ROLES; ++i)
diff --git a/src/modules/rtp/rtp.h b/src/modules/rtp/rtp.h
index e975e75..a51345d 100644
--- a/src/modules/rtp/rtp.h
+++ b/src/modules/rtp/rtp.h
@@ -25,6 +25,7 @@
 #include <inttypes.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+
 #include <pulsecore/memblockq.h>
 #include <pulsecore/memchunk.h>
 
@@ -56,7 +57,7 @@ int pa_rtp_sample_spec_valid(const pa_sample_spec *ss);
 uint8_t pa_rtp_payload_from_sample_spec(const pa_sample_spec *ss);
 pa_sample_spec *pa_rtp_sample_spec_from_payload(uint8_t payload, pa_sample_spec *ss);
 
-const char* pa_rtp_format_to_string(pa_sample_format_t f);
-pa_sample_format_t pa_rtp_string_to_format(const char *s);
+const char* pa_rtp_format_to_string(pa_sample_format_t f) PA_GCC_CONST;
+pa_sample_format_t pa_rtp_string_to_format(const char *s) PA_GCC_PURE;
 
 #endif
diff --git a/src/pulse/channelmap.h b/src/pulse/channelmap.h
index 8d62226..0c5ddff 100644
--- a/src/pulse/channelmap.h
+++ b/src/pulse/channelmap.h
@@ -293,7 +293,7 @@ pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, p
 pa_channel_map* pa_channel_map_init_extend(pa_channel_map *m, unsigned channels, pa_channel_map_def_t def);
 
 /** Return a text label for the specified channel position */
-const char* pa_channel_position_to_string(pa_channel_position_t pos) PA_GCC_PURE;
+const char* pa_channel_position_to_string(pa_channel_position_t pos) PA_GCC_CONST;
 
 /** The inverse of pa_channel_position_to_string(). \since 0.9.16 */
 pa_channel_position_t pa_channel_position_from_string(const char *s) PA_GCC_PURE;
diff --git a/src/pulse/context.h b/src/pulse/context.h
index b2d4133..ce8423d 100644
--- a/src/pulse/context.h
+++ b/src/pulse/context.h
@@ -237,7 +237,7 @@ pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_su
 const char* pa_context_get_server(pa_context *c);
 
 /** Return the protocol version of the library. */
-uint32_t pa_context_get_protocol_version(pa_context *c);
+uint32_t pa_context_get_protocol_version(pa_context *c) PA_GCC_CONST;
 
 /** Return the protocol version of the connected server. */
 uint32_t pa_context_get_server_protocol_version(pa_context *c);
diff --git a/src/pulse/format.h b/src/pulse/format.h
index 67996c5..7ff1650 100644
--- a/src/pulse/format.h
+++ b/src/pulse/format.h
@@ -63,7 +63,7 @@ typedef enum pa_encoding {
 const char *pa_encoding_to_string(pa_encoding_t e) PA_GCC_CONST;
 
 /** Converts a string of the form returned by \a pa_encoding_to_string() back to a \a pa_encoding_t. \since 1.0 */
-pa_encoding_t pa_encoding_from_string(const char *encoding);
+pa_encoding_t pa_encoding_from_string(const char *encoding) PA_GCC_PURE;
 
 /** Represents the format of data provided in a stream or processed by a sink. \since 1.0 */
 typedef struct pa_format_info {
@@ -84,10 +84,10 @@ pa_format_info* pa_format_info_copy(const pa_format_info *src);
 void pa_format_info_free(pa_format_info *f);
 
 /** Returns non-zero when the format info structure is valid */
-int pa_format_info_valid(const pa_format_info *f);
+int pa_format_info_valid(const pa_format_info *f) PA_GCC_PURE;
 
 /** Returns non-zero when the format info structure represents a PCM (i.e. uncompressed data) format */
-int pa_format_info_is_pcm(const pa_format_info *f);
+int pa_format_info_is_pcm(const pa_format_info *f) PA_GCC_PURE;
 
 /** Returns non-zero if the format represented \a first is a subset of
  * the format represented by \second. This means that \a second must
diff --git a/src/pulse/sample.h b/src/pulse/sample.h
index 965559e..a02442d 100644
--- a/src/pulse/sample.h
+++ b/src/pulse/sample.h
@@ -289,7 +289,7 @@ int pa_sample_spec_valid(const pa_sample_spec *spec) PA_GCC_PURE;
 int pa_sample_spec_equal(const pa_sample_spec*a, const pa_sample_spec*b) PA_GCC_PURE;
 
 /** Return a descriptive string for the specified sample format. \since 0.8 */
-const char *pa_sample_format_to_string(pa_sample_format_t f) PA_GCC_PURE;
+const char *pa_sample_format_to_string(pa_sample_format_t f) PA_GCC_CONST;
 
 /** Parse a sample format text. Inverse of pa_sample_format_to_string() */
 pa_sample_format_t pa_parse_sample_format(const char *format) PA_GCC_PURE;
diff --git a/src/pulse/timeval.h b/src/pulse/timeval.h
index 8f255f9..763040b 100644
--- a/src/pulse/timeval.h
+++ b/src/pulse/timeval.h
@@ -82,7 +82,7 @@ struct timeval* pa_timeval_sub(struct timeval *tv, pa_usec_t v);
 struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v);
 
 /** Load the specified tv value and return it in usec. \since 0.9.7 */
-pa_usec_t pa_timeval_load(const struct timeval *tv);
+pa_usec_t pa_timeval_load(const struct timeval *tv) PA_GCC_PURE;
 
 PA_C_DECL_END
 
diff --git a/src/pulse/util.h b/src/pulse/util.h
index e490d56..6d4cc0b 100644
--- a/src/pulse/util.h
+++ b/src/pulse/util.h
@@ -26,6 +26,7 @@
 #include <stddef.h>
 
 #include <pulse/cdecl.h>
+#include <pulse/gccmacro.h>
 #include <pulse/version.h>
 
 /** \file
@@ -51,7 +52,7 @@ char *pa_get_binary_name(char *s, size_t l);
 
 /** Return a pointer to the filename inside a path (which is the last
  * component). If passed NULL will return NULL. */
-char *pa_path_get_filename(const char *p);
+char *pa_path_get_filename(const char *p) PA_GCC_PURE;
 
 /** Wait t milliseconds */
 int pa_msleep(unsigned long t);
diff --git a/src/pulsecore/bitset.h b/src/pulsecore/bitset.h
index a86a15e..91854f1 100644
--- a/src/pulsecore/bitset.h
+++ b/src/pulsecore/bitset.h
@@ -31,7 +31,7 @@
 typedef uint32_t pa_bitset_t;
 
 void pa_bitset_set(pa_bitset_t *b, unsigned k, pa_bool_t v);
-pa_bool_t pa_bitset_get(const pa_bitset_t *b, unsigned k);
+pa_bool_t pa_bitset_get(const pa_bitset_t *b, unsigned k) PA_GCC_PURE;
 pa_bool_t pa_bitset_equals(const pa_bitset_t *b, unsigned n, ...);
 
 #endif
diff --git a/src/pulsecore/core-rtclock.h b/src/pulsecore/core-rtclock.h
index 6253536..454ecd2 100644
--- a/src/pulsecore/core-rtclock.h
+++ b/src/pulsecore/core-rtclock.h
@@ -22,9 +22,11 @@
   USA.
 ***/
 
-#include <pulsecore/macro.h>
+#include <pulse/gccmacro.h>
 #include <pulse/sample.h>
 
+#include <pulsecore/macro.h>
+
 struct timeval;
 
 /* Something like pulse/timeval.h but based on CLOCK_MONOTONIC */
@@ -44,7 +46,7 @@ void pa_rtclock_hrtimer_enable(void);
 struct timeval* pa_rtclock_from_wallclock(struct timeval *tv);
 
 #ifdef HAVE_CLOCK_GETTIME
-pa_usec_t pa_timespec_load(const struct timespec *ts);
+pa_usec_t pa_timespec_load(const struct timespec *ts) PA_GCC_PURE;
 struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v);
 #endif
 
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 79c8e08..92f3950 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2796,7 +2796,6 @@ unsigned pa_gcd(unsigned a, unsigned b) {
 }
 
 void pa_reduce(unsigned *num, unsigned *den) {
-
     unsigned gcd = pa_gcd(*num, *den);
 
     if (gcd <= 0)
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 4a1c096..64d0d63 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -221,7 +221,7 @@ static inline pa_bool_t pa_in_valgrind(void) {
 }
 #endif
 
-unsigned pa_gcd(unsigned a, unsigned b);
+unsigned pa_gcd(unsigned a, unsigned b) PA_GCC_CONST;
 void pa_reduce(unsigned *num, unsigned *den);
 
 unsigned pa_ncpus(void);
diff --git a/src/pulsecore/dbus-util.c b/src/pulsecore/dbus-util.c
index b79b752..3949780 100644
--- a/src/pulsecore/dbus-util.c
+++ b/src/pulsecore/dbus-util.c
@@ -498,7 +498,7 @@ void pa_dbus_send_basic_value_reply(DBusConnection *c, DBusMessage *in_reply_to,
     dbus_message_unref(reply);
 }
 
-static const char *signature_from_basic_type(int type) {
+static PA_GCC_CONST const char *signature_from_basic_type(int type) {
     switch (type) {
         case DBUS_TYPE_BOOLEAN: return DBUS_TYPE_BOOLEAN_AS_STRING;
         case DBUS_TYPE_BYTE: return DBUS_TYPE_BYTE_AS_STRING;
diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h
index 2d01fb4..b883ef5 100644
--- a/src/pulsecore/idxset.h
+++ b/src/pulsecore/idxset.h
@@ -25,6 +25,8 @@
 
 #include <inttypes.h>
 
+#include <pulse/gccmacro.h>
+
 #include <pulsecore/macro.h>
 
 /* A combination of a set and a dynamic array. Entries are indexable
@@ -41,12 +43,12 @@ typedef void (*pa_free2_cb_t)(void *p, void *userdata);
 /* Generic implementations for hash and comparison functions. Just
  * compares the pointer or calculates the hash value directly from the
  * pointer value. */
-unsigned pa_idxset_trivial_hash_func(const void *p);
-int pa_idxset_trivial_compare_func(const void *a, const void *b);
+unsigned pa_idxset_trivial_hash_func(const void *p) PA_GCC_CONST;
+int pa_idxset_trivial_compare_func(const void *a, const void *b) PA_GCC_CONST;
 
 /* Generic implementations for hash and comparison functions for strings. */
-unsigned pa_idxset_string_hash_func(const void *p);
-int pa_idxset_string_compare_func(const void *a, const void *b);
+unsigned pa_idxset_string_hash_func(const void *p) PA_GCC_PURE;
+int pa_idxset_string_compare_func(const void *a, const void *b) PA_GCC_PURE;
 
 typedef unsigned (*pa_hash_func_t)(const void *p);
 typedef int (*pa_compare_func_t)(const void *a, const void *b);
diff --git a/src/pulsecore/memchunk.c b/src/pulsecore/memchunk.c
index cc242e4..e5851dc 100644
--- a/src/pulsecore/memchunk.c
+++ b/src/pulsecore/memchunk.c
@@ -111,7 +111,7 @@ pa_memchunk* pa_memchunk_memcpy(pa_memchunk *dst, pa_memchunk *src) {
 }
 
 pa_bool_t pa_memchunk_isset(pa_memchunk *chunk) {
-    assert(chunk);
+    pa_assert(chunk);
 
     return
         chunk->memblock ||
diff --git a/src/pulsecore/memchunk.h b/src/pulsecore/memchunk.h
index f9e56be..0b88757 100644
--- a/src/pulsecore/memchunk.h
+++ b/src/pulsecore/memchunk.h
@@ -51,6 +51,6 @@ pa_memchunk *pa_memchunk_will_need(const pa_memchunk *c);
 pa_memchunk* pa_memchunk_memcpy(pa_memchunk *dst, pa_memchunk *src);
 
 /* Return TRUE if any field is set != 0 */
-pa_bool_t pa_memchunk_isset(pa_memchunk *c);
+pa_bool_t pa_memchunk_isset(pa_memchunk *c) PA_GCC_PURE;
 
 #endif
diff --git a/src/pulsecore/module.h b/src/pulsecore/module.h
index 0b6cb7c..93c2403 100644
--- a/src/pulsecore/module.h
+++ b/src/pulsecore/module.h
@@ -27,6 +27,7 @@
 
 typedef struct pa_module pa_module;
 
+#include <pulse/gccmacro.h>
 #include <pulse/proplist.h>
 
 #include <pulsecore/core.h>
@@ -64,28 +65,28 @@ int pa_module_get_n_used(pa_module*m);
 
 void pa_module_update_proplist(pa_module *m, pa_update_mode_t mode, pa_proplist *p);
 
-#define PA_MODULE_AUTHOR(s)                                     \
-    const char *pa__get_author(void) { return s; }              \
+#define PA_MODULE_AUTHOR(s)                                            \
+    PA_GCC_CONST const char *pa__get_author(void) { return s; }        \
     struct __stupid_useless_struct_to_allow_trailing_semicolon
 
-#define PA_MODULE_DESCRIPTION(s)                                \
-    const char *pa__get_description(void) { return s; }         \
+#define PA_MODULE_DESCRIPTION(s)                                       \
+    PA_GCC_CONST const char *pa__get_description(void) { return s; }   \
     struct __stupid_useless_struct_to_allow_trailing_semicolon
 
-#define PA_MODULE_USAGE(s)                                      \
-    const char *pa__get_usage(void) { return s; }               \
+#define PA_MODULE_USAGE(s)                                             \
+    PA_GCC_CONST const char *pa__get_usage(void) { return s; }         \
     struct __stupid_useless_struct_to_allow_trailing_semicolon
 
-#define PA_MODULE_VERSION(s)                                    \
-    const char * pa__get_version(void) { return s; }            \
+#define PA_MODULE_VERSION(s)                                           \
+    PA_GCC_CONST const char * pa__get_version(void) { return s; }      \
     struct __stupid_useless_struct_to_allow_trailing_semicolon
 
-#define PA_MODULE_DEPRECATED(s)                                 \
-    const char * pa__get_deprecated(void) { return s; }         \
+#define PA_MODULE_DEPRECATED(s)                                        \
+    PA_GCC_CONST const char * pa__get_deprecated(void) { return s; }   \
     struct __stupid_useless_struct_to_allow_trailing_semicolon
 
-#define PA_MODULE_LOAD_ONCE(b)                                  \
-    pa_bool_t pa__load_once(void) { return b; }                 \
+#define PA_MODULE_LOAD_ONCE(b)                                         \
+    PA_GCC_CONST pa_bool_t pa__load_once(void) { return b; }           \
     struct __stupid_useless_struct_to_allow_trailing_semicolon
 
 #endif
diff --git a/src/pulsecore/namereg.h b/src/pulsecore/namereg.h
index b5a976d..f8f100f 100644
--- a/src/pulsecore/namereg.h
+++ b/src/pulsecore/namereg.h
@@ -44,8 +44,8 @@ pa_source* pa_namereg_set_default_source(pa_core*c, pa_source *s);
 pa_sink *pa_namereg_get_default_sink(pa_core *c);
 pa_source *pa_namereg_get_default_source(pa_core *c);
 
-pa_bool_t pa_namereg_is_valid_name(const char *name);
-pa_bool_t pa_namereg_is_valid_name_or_wildcard(const char *name, pa_namereg_type_t type);
+pa_bool_t pa_namereg_is_valid_name(const char *name) PA_GCC_PURE;
+pa_bool_t pa_namereg_is_valid_name_or_wildcard(const char *name, pa_namereg_type_t type) PA_GCC_PURE;
 char* pa_namereg_make_valid_name(const char *name);
 
 #endif
diff --git a/src/pulsecore/resampler.h b/src/pulsecore/resampler.h
index 742de6a..e8861a5 100644
--- a/src/pulsecore/resampler.h
+++ b/src/pulsecore/resampler.h
@@ -94,10 +94,10 @@ pa_resample_method_t pa_resampler_get_method(pa_resampler *r);
 pa_resample_method_t pa_parse_resample_method(const char *string);
 
 /* return a human readable string for the specified resampling method. Inverse of pa_parse_resample_method() */
-const char *pa_resample_method_to_string(pa_resample_method_t m);
+const char *pa_resample_method_to_string(pa_resample_method_t m) PA_GCC_CONST;
 
 /* Return 1 when the specified resampling method is supported */
-int pa_resample_method_supported(pa_resample_method_t m);
+int pa_resample_method_supported(pa_resample_method_t m) PA_GCC_CONST;
 
 const pa_channel_map* pa_resampler_input_channel_map(pa_resampler *r);
 const pa_sample_spec* pa_resampler_input_sample_spec(pa_resampler *r);
-- 
1.7.4.1



More information about the pulseaudio-discuss mailing list