Permalink
Browse files

declare functions with gcc attributes

Allow libmpdclient users to compile more efficiently.
  • Loading branch information...
1 parent 6f7bd74 commit 05008db6bbaaa1069147b6494d8a7c8449ad4af1 @MaxKellermann MaxKellermann committed Sep 20, 2009
View
@@ -7,6 +7,7 @@ mpdinclude_HEADERS = \
include/mpd/audio_format.h \
include/mpd/client.h \
include/mpd/capabilities.h \
+ include/mpd/compiler.h \
include/mpd/connection.h \
include/mpd/database.h \
include/mpd/directory.h \
View
@@ -42,6 +42,7 @@
#define MPD_ASYNC_H
#include <mpd/error.h>
+#include <mpd/compiler.h>
#include <stdbool.h>
#include <stdarg.h>
@@ -82,6 +83,7 @@ extern "C" {
* @param fd the socket file descriptor of the stream connection to MPD
* @return a mpd_async object, or NULL on out of memory
*/
+mpd_malloc
struct mpd_async *
mpd_async_new(int fd);
@@ -95,6 +97,7 @@ mpd_async_free(struct mpd_async *async);
* After an error has occured, this function returns the error code.
* If no error has occured, it returns #MPD_ERROR_SUCCESS.
*/
+mpd_pure
enum mpd_error
mpd_async_get_error(const struct mpd_async *async);
@@ -109,6 +112,7 @@ mpd_async_get_error(const struct mpd_async *async);
* system, and thus the locale's character set (and probably language)
* is used. Keep that in mind when you print error messages.
*/
+mpd_pure
const char *
mpd_async_get_error_message(const struct mpd_async *async);
@@ -118,12 +122,14 @@ mpd_async_get_error_message(const struct mpd_async *async);
* file descriptor never changes during the lifetime of this
* #mpd_async object.
*/
+mpd_pure
int
mpd_async_fd(const struct mpd_async *async);
/**
* Returns a bit mask of events which should be polled for.
*/
+mpd_pure
enum mpd_async_event
mpd_async_events(const struct mpd_async *async);
@@ -158,6 +164,7 @@ mpd_async_send_command_v(struct mpd_async *async, const char *command,
* NULL
* @return true on success, false if the buffer is full
*/
+mpd_sentinel
bool
mpd_async_send_command(struct mpd_async *async, const char *command, ...);
@@ -169,6 +176,7 @@ mpd_async_send_command(struct mpd_async *async, const char *command, ...);
* @param async the connection
* @return a line on success, NULL otherwise
*/
+mpd_malloc
char *
mpd_async_recv_line(struct mpd_async *async);
@@ -29,6 +29,8 @@
#ifndef MPD_CAPABILITIES_H
#define MPD_CAPABILITIES_H
+#include <mpd/compiler.h>
+
#include <stdbool.h>
struct mpd_connection;
@@ -68,6 +70,7 @@ mpd_send_disallowed_commands(struct mpd_connection *connection);
* @returns a command name, or NULL on error or if the end of the
* response is reached
*/
+mpd_malloc
char *
mpd_recv_command_name(struct mpd_connection *connection);
@@ -85,6 +88,7 @@ mpd_send_list_url_schemes(struct mpd_connection *connection);
/**
* Receives one line of the mpd_send_urlhandlers() response.
*/
+mpd_malloc
char *
mpd_recv_handler(struct mpd_connection *connection);
@@ -102,6 +106,7 @@ mpd_send_list_tag_types(struct mpd_connection *connection);
* Receives the next tag type name. Call this in a loop after
* mpd_send_tagtypes().
*/
+mpd_malloc
char *
mpd_recv_tag_type_name(struct mpd_connection *connection);
View
@@ -0,0 +1,62 @@
+/* libmpdclient
+ (c) 2003-2009 The Music Player Daemon Project
+ This project's homepage is: http://www.musicpd.org
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*! \file
+ * \brief Compiler specific definitions
+ *
+ * This file is not part of the official libmpdclient2 API. It
+ * provides access to gcc specific extensions.
+ *
+ */
+
+#ifndef MPD_COMPILER_H
+#define MPD_COMPILER_H
+
+#if !defined(SPARSE) && defined(__GNUC__) && __GNUC__ >= 3
+
+/* GCC 4.x */
+
+#define mpd_malloc __attribute__((malloc))
+#define mpd_pure __attribute__((pure))
+#define mpd_const __attribute__((const))
+#define mpd_sentinel __attribute__((const))
+#define mpd_printf(a,b) __attribute__((format(printf, a, b)))
+
+#else
+
+/* generic C compiler */
+
+#define mpd_malloc
+#define mpd_pure
+#define mpd_const
+#define mpd_sentinel
+#define mpd_printf(a,b)
+
+#endif
+
+#endif
View
@@ -35,6 +35,7 @@
#include <mpd/protocol.h>
#include <mpd/error.h>
+#include <mpd/compiler.h>
#include <stdbool.h>
@@ -84,6 +85,7 @@ extern "C" {
* @return a mpd_connection object (which may have failed to connect),
* or NULL on out-of-memory
*/
+mpd_malloc
struct mpd_connection *
mpd_connection_new(const char *host, unsigned port, unsigned timeout_ms);
@@ -99,6 +101,7 @@ mpd_connection_new(const char *host, unsigned port, unsigned timeout_ms);
* @param welcome the first line sent by MPD (the welcome message)
* @return a mpd_connection object, or NULL on out-of-memory
*/
+mpd_malloc
struct mpd_connection *
mpd_connection_new_async(struct mpd_async *async, const char *welcome);
@@ -128,6 +131,7 @@ void mpd_connection_set_timeout(struct mpd_connection *connection,
* Returns the libmpdclient error code. MPD_ERROR_SUCCESS means no
* error occured.
*/
+mpd_pure
enum mpd_error
mpd_get_error(const struct mpd_connection *connection);
@@ -141,13 +145,15 @@ mpd_get_error(const struct mpd_connection *connection);
* system, and thus the locale's character set (and probably language)
* is used. Keep that in mind when you print error messages.
*/
+mpd_pure
const char *
mpd_get_error_message(const struct mpd_connection *connection);
/**
* Returns the error code returned from the server. Calling this
* function is only valid if mpd_get_error() returned MPD_ERROR_ACK.
*/
+mpd_pure
enum mpd_ack
mpd_get_server_error(const struct mpd_connection *connection);
@@ -166,6 +172,7 @@ mpd_clear_error(struct mpd_connection *connection);
* Returns a three-tuple containing the major, minor and patch version
* of the MPD protocol.
*/
+mpd_pure
const unsigned *
mpd_get_server_version(const struct mpd_connection *connection);
@@ -175,6 +182,7 @@ mpd_get_server_version(const struct mpd_connection *connection);
* @return -1 if the server is older, 1 if it is newer, 0 if it is
* equal
*/
+mpd_pure
int
mpd_cmp_server_version(const struct mpd_connection *connection, unsigned major,
unsigned minor, unsigned patch);
View
@@ -33,6 +33,8 @@
#ifndef MPD_DIRECTORY_H
#define MPD_DIRECTORY_H
+#include <mpd/compiler.h>
+
#include <stdbool.h>
struct mpd_pair;
@@ -58,6 +60,7 @@ extern "C" {
* directory. It must not begin or end with a slash
* @return the new object, or NULL on out of memory
*/
+mpd_malloc
struct mpd_directory *
mpd_directory_new(const char *path);
@@ -66,6 +69,7 @@ mpd_directory_new(const char *path);
*
* @return the new object, or NULL on out of memory
*/
+mpd_malloc
struct mpd_directory *
mpd_directory_dup(const struct mpd_directory *directory);
@@ -78,6 +82,7 @@ void mpd_directory_free(struct mpd_directory *directory);
* Returns the path of this directory, relative to the MPD music
* directory. It does not begin with a slash.
*/
+mpd_pure
const char *
mpd_directory_get_path(const struct mpd_directory *directory);
@@ -88,6 +93,7 @@ mpd_directory_get_path(const struct mpd_directory *directory);
* @return the new #mpd_entity object, or NULL on error (out of
* memory, or pair name is not "directory")
*/
+mpd_malloc
struct mpd_directory *
mpd_directory_begin(const struct mpd_pair *pair);
@@ -109,6 +115,7 @@ mpd_directory_feed(struct mpd_directory *directory,
* @return a #mpd_directory object, or NULL on error or if the directory list is
* finished
*/
+mpd_malloc
struct mpd_directory *
mpd_recv_directory(struct mpd_connection *connection);
View
@@ -36,6 +36,7 @@
#include <mpd/song.h>
#include <mpd/directory.h>
#include <mpd/client.h>
+#include <mpd/compiler.h>
struct mpd_pair;
@@ -86,6 +87,7 @@ mpd_entity_free(struct mpd_entity *entity);
/**
* @return the type of this entity.
*/
+mpd_pure
enum mpd_entity_type
mpd_entity_get_type(const struct mpd_entity *entity);
@@ -96,6 +98,7 @@ mpd_entity_get_type(const struct mpd_entity *entity);
*
* @return the directory object
*/
+mpd_pure
const struct mpd_directory *
mpd_entity_get_directory(const struct mpd_entity *entity);
@@ -106,6 +109,7 @@ mpd_entity_get_directory(const struct mpd_entity *entity);
*
* @return the song object
*/
+mpd_pure
const struct mpd_song *
mpd_entity_get_song(const struct mpd_entity *entity);
@@ -116,6 +120,7 @@ mpd_entity_get_song(const struct mpd_entity *entity);
*
* @return the directory object
*/
+mpd_pure
const struct mpd_playlist *
mpd_entity_get_playlist(const struct mpd_entity *entity);
@@ -125,6 +130,7 @@ mpd_entity_get_playlist(const struct mpd_entity *entity);
* @param pair the first pair in this entity
* @return the new #mpd_entity object, or NULL on error (out of memory)
*/
+mpd_malloc
struct mpd_entity *
mpd_entity_begin(const struct mpd_pair *pair);
@@ -145,6 +151,7 @@ mpd_entity_feed(struct mpd_entity *entity, const struct mpd_pair *pair);
* @return an entity object, or NULL on error or if the entity list is
* finished
*/
+mpd_malloc
struct mpd_entity *
mpd_recv_entity(struct mpd_connection *connection);
View
@@ -33,6 +33,8 @@
#ifndef MPD_IDLE_H
#define MPD_IDLE_H
+#include <mpd/compiler.h>
+
#include <stdbool.h>
struct mpd_pair;
@@ -78,6 +80,7 @@ extern "C" {
* @param idle an idle event id
* @return the name, or NULL if that event is not known
*/
+mpd_const
const char *
mpd_idle_name(enum mpd_idle idle);
@@ -87,6 +90,7 @@ mpd_idle_name(enum mpd_idle idle);
* @param name an idle event name
* @return the id, or 0 if that event is not known
*/
+mpd_pure
enum mpd_idle
mpd_idle_name_parse(const char *name);
@@ -123,6 +127,7 @@ mpd_send_noidle(struct mpd_connection *connection);
*
* @return an idle code, or 0 if the pair was not understood
*/
+mpd_pure
enum mpd_idle
mpd_idle_parse_pair(const struct mpd_pair *pair);
Oops, something went wrong.

0 comments on commit 05008db

Please sign in to comment.