libpkgconf: client: clean up various aspects of error/warn handlers

pull/116/head
William Pitcock 2017-02-04 18:46:33 -06:00
parent d884dc46a2
commit eb98a1e6c3
3 changed files with 28 additions and 22 deletions

View File

@ -138,25 +138,27 @@ thread boundaries.
:param pkgconf_client_t* client: The client object to get the warn handler from. :param pkgconf_client_t* client: The client object to get the warn handler from.
:return: a function pointer to the warn handler or ``NULL`` :return: a function pointer to the warn handler or ``NULL``
.. c:function:: pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler) .. c:function:: pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler, void *warn_handler_data)
Sets a warn handler on a client object or uninstalls one if set to ``NULL``. Sets a warn handler on a client object or uninstalls one if set to ``NULL``.
:param pkgconf_client_t* client: The client object to set the warn handler on. :param pkgconf_client_t* client: The client object to set the warn handler on.
:param pkgconf_error_handler_func_t warn_handler: The warn handler to set. :param pkgconf_error_handler_func_t warn_handler: The warn handler to set.
:param void* warn_handler_data: Optional data to associate with the warn handler.
:return: nothing :return: nothing
.. c:function:: pkgconf_client_get_error_handler(const pkgconf_client_t *client) .. c:function:: pkgconf_client_get_error_handler(const pkgconf_client_t *client)
Returns the warning handler if one is set, else ``NULL``. Returns the error handler if one is set, else ``NULL``.
:param pkgconf_client_t* client: The client object to get the warn handler from. :param pkgconf_client_t* client: The client object to get the error handler from.
:return: a function pointer to the warn handler or ``NULL`` :return: a function pointer to the error handler or ``NULL``
.. c:function:: pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler) .. c:function:: pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler, void *error_handler_data)
Sets a warn handler on a client object or uninstalls one if set to ``NULL``. Sets a warn handler on a client object or uninstalls one if set to ``NULL``.
:param pkgconf_client_t* client: The client object to set the warn handler on. :param pkgconf_client_t* client: The client object to set the error handler on.
:param pkgconf_error_handler_func_t error_handler: The warn handler to set. :param pkgconf_error_handler_func_t error_handler: The error handler to set.
:param void* error_handler_data: Optional data to associate with the error handler.
:return: nothing :return: nothing

View File

@ -52,10 +52,8 @@ pkgconf_client_init(pkgconf_client_t *client, pkgconf_error_handler_func_t error
pkgconf_client_set_buildroot_dir(client, NULL); pkgconf_client_set_buildroot_dir(client, NULL);
pkgconf_client_set_prefix_varname(client, NULL); pkgconf_client_set_prefix_varname(client, NULL);
if (client->error_handler == NULL) pkgconf_client_set_error_handler(client, error_handler, error_handler_data);
client->error_handler = pkgconf_default_error_handler; pkgconf_client_set_warn_handler(client, NULL, NULL);
client->warn_handler = pkgconf_default_error_handler;
pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_LIBRARY_PATH", SYSTEM_LIBDIR, &client->filter_libdirs, false); pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_LIBRARY_PATH", SYSTEM_LIBDIR, &client->filter_libdirs, false);
pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_INCLUDE_PATH", SYSTEM_INCLUDEDIR, &client->filter_includedirs, false); pkgconf_path_build_from_environ("PKG_CONFIG_SYSTEM_INCLUDE_PATH", SYSTEM_INCLUDEDIR, &client->filter_includedirs, false);
@ -363,18 +361,20 @@ pkgconf_client_get_warn_handler(const pkgconf_client_t *client)
/* /*
* !doc * !doc
* *
* .. c:function:: pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler) * .. c:function:: pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler, void *warn_handler_data)
* *
* Sets a warn handler on a client object or uninstalls one if set to ``NULL``. * Sets a warn handler on a client object or uninstalls one if set to ``NULL``.
* *
* :param pkgconf_client_t* client: The client object to set the warn handler on. * :param pkgconf_client_t* client: The client object to set the warn handler on.
* :param pkgconf_error_handler_func_t warn_handler: The warn handler to set. * :param pkgconf_error_handler_func_t warn_handler: The warn handler to set.
* :param void* warn_handler_data: Optional data to associate with the warn handler.
* :return: nothing * :return: nothing
*/ */
void void
pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler) pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler, void *warn_handler_data)
{ {
client->warn_handler = warn_handler; client->warn_handler = warn_handler;
client->warn_handler_data = warn_handler_data;
if (client->warn_handler == NULL) if (client->warn_handler == NULL)
client->warn_handler = pkgconf_default_error_handler; client->warn_handler = pkgconf_default_error_handler;
@ -385,10 +385,10 @@ pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_
* *
* .. c:function:: pkgconf_client_get_error_handler(const pkgconf_client_t *client) * .. c:function:: pkgconf_client_get_error_handler(const pkgconf_client_t *client)
* *
* Returns the warning handler if one is set, else ``NULL``. * Returns the error handler if one is set, else ``NULL``.
* *
* :param pkgconf_client_t* client: The client object to get the warn handler from. * :param pkgconf_client_t* client: The client object to get the error handler from.
* :return: a function pointer to the warn handler or ``NULL`` * :return: a function pointer to the error handler or ``NULL``
*/ */
pkgconf_error_handler_func_t pkgconf_error_handler_func_t
pkgconf_client_get_error_handler(const pkgconf_client_t *client) pkgconf_client_get_error_handler(const pkgconf_client_t *client)
@ -399,18 +399,20 @@ pkgconf_client_get_error_handler(const pkgconf_client_t *client)
/* /*
* !doc * !doc
* *
* .. c:function:: pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler) * .. c:function:: pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler, void *error_handler_data)
* *
* Sets a warn handler on a client object or uninstalls one if set to ``NULL``. * Sets a warn handler on a client object or uninstalls one if set to ``NULL``.
* *
* :param pkgconf_client_t* client: The client object to set the warn handler on. * :param pkgconf_client_t* client: The client object to set the error handler on.
* :param pkgconf_error_handler_func_t error_handler: The warn handler to set. * :param pkgconf_error_handler_func_t error_handler: The error handler to set.
* :param void* error_handler_data: Optional data to associate with the error handler.
* :return: nothing * :return: nothing
*/ */
void void
pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler) pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler, void *error_handler_data)
{ {
client->error_handler = error_handler; client->error_handler = error_handler;
client->error_handler_data = error_handler_data;
if (client->error_handler == NULL) if (client->error_handler == NULL)
client->error_handler = pkgconf_default_error_handler; client->error_handler = pkgconf_default_error_handler;

View File

@ -145,6 +145,8 @@ struct pkgconf_client_ {
pkgconf_list_t global_vars; pkgconf_list_t global_vars;
void *error_handler_data; void *error_handler_data;
void *warn_handler_data;
pkgconf_error_handler_func_t error_handler; pkgconf_error_handler_func_t error_handler;
pkgconf_error_handler_func_t warn_handler; pkgconf_error_handler_func_t warn_handler;
@ -172,9 +174,9 @@ void pkgconf_client_set_flags(pkgconf_client_t *client, unsigned int flags);
const char *pkgconf_client_get_prefix_varname(const pkgconf_client_t *client); const char *pkgconf_client_get_prefix_varname(const pkgconf_client_t *client);
void pkgconf_client_set_prefix_varname(pkgconf_client_t *client, const char *prefix_varname); void pkgconf_client_set_prefix_varname(pkgconf_client_t *client, const char *prefix_varname);
pkgconf_error_handler_func_t pkgconf_client_get_warn_handler(const pkgconf_client_t *client); pkgconf_error_handler_func_t pkgconf_client_get_warn_handler(const pkgconf_client_t *client);
void pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler); void pkgconf_client_set_warn_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t warn_handler, void *warn_handler_data);
pkgconf_error_handler_func_t pkgconf_client_get_error_handler(const pkgconf_client_t *client); pkgconf_error_handler_func_t pkgconf_client_get_error_handler(const pkgconf_client_t *client);
void pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler); void pkgconf_client_set_error_handler(pkgconf_client_t *client, pkgconf_error_handler_func_t error_handler, void *error_handler_data);
#define PKGCONF_IS_MODULE_SEPARATOR(c) ((c) == ',' || isspace ((unsigned int)(c))) #define PKGCONF_IS_MODULE_SEPARATOR(c) ((c) == ',' || isspace ((unsigned int)(c)))
#define PKGCONF_IS_OPERATOR_CHAR(c) ((c) == '<' || (c) == '>' || (c) == '!' || (c) == '=') #define PKGCONF_IS_OPERATOR_CHAR(c) ((c) == '<' || (c) == '>' || (c) == '!' || (c) == '=')