From: Uwe Hermann Date: Sat, 2 May 2020 14:11:42 +0000 (+0200) Subject: Fix compiler warnings related to -Wcast-function-type. X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=6cfc6c5c7a2fbb8be10b282b0b2bfe9ce9653984;hp=4c5ac0cf5b3e8a13d6f0ff4255fa21ed6874774a Fix compiler warnings related to -Wcast-function-type. This fixes bug #1297. --- diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 4caceef6..1d45eea3 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -56,6 +56,13 @@ struct zip_stat; #define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a) #endif +#ifndef G_SOURCE_FUNC +#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) /* Since 2.58. */ +#endif + +#define SR_RECEIVE_DATA_CALLBACK(f) \ + ((sr_receive_data_callback) (void (*)(void)) (f)) + /** * Read a 8 bits unsigned integer out of memory. * @param x a pointer to the input memory diff --git a/src/scpi/vxi_clnt.c b/src/scpi/vxi_clnt.c index a7c24465..f824f676 100644 --- a/src/scpi/vxi_clnt.c +++ b/src/scpi/vxi_clnt.c @@ -7,6 +7,8 @@ #include "vxi.h" #include /* for memset */ +#define SR_XDRPROC_CALLBACK(f) ((xdrproc_t) (void (*)(void)) (f)) + /* Default timeout can be changed using clnt_control() */ static struct timeval TIMEOUT = { 25, 0 }; @@ -242,7 +244,7 @@ destroy_intr_chan_1(void *argp, CLIENT *clnt) memset((char *)&clnt_res, 0, sizeof(clnt_res)); if (clnt_call (clnt, destroy_intr_chan, - (xdrproc_t) xdr_void, (caddr_t) argp, + SR_XDRPROC_CALLBACK(xdr_void), (caddr_t) argp, (xdrproc_t) xdr_Device_Error, (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); @@ -258,7 +260,7 @@ device_intr_srq_1(Device_SrqParms *argp, CLIENT *clnt) memset((char *)&clnt_res, 0, sizeof(clnt_res)); if (clnt_call (clnt, device_intr_srq, (xdrproc_t) xdr_Device_SrqParms, (caddr_t) argp, - (xdrproc_t) xdr_void, (caddr_t) &clnt_res, + SR_XDRPROC_CALLBACK(xdr_void), (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } diff --git a/src/session.c b/src/session.c index 5e48f4a5..d1a19c56 100644 --- a/src/session.c +++ b/src/session.c @@ -126,7 +126,7 @@ static gboolean fd_source_dispatch(GSource *source, sr_err("Callback not set, cannot dispatch event."); return G_SOURCE_REMOVE; } - keep = (*(sr_receive_data_callback)callback) + keep = (*SR_RECEIVE_DATA_CALLBACK(callback)) (fsource->pollfd.fd, revents, user_data); if (fsource->timeout_us >= 0 && G_LIKELY(keep) @@ -1237,7 +1237,7 @@ SR_PRIV int sr_session_fd_source_add(struct sr_session *session, if (!source) return SR_ERR; - g_source_set_callback(source, (GSourceFunc)cb, cb_data, NULL); + g_source_set_callback(source, G_SOURCE_FUNC(cb), cb_data, NULL); ret = sr_session_source_add_internal(session, key, source); g_source_unref(source); diff --git a/src/usb.c b/src/usb.c index 93286e8a..6bd9e818 100644 --- a/src/usb.c +++ b/src/usb.c @@ -138,7 +138,7 @@ static gboolean usb_source_dispatch(GSource *source, sr_err("Callback not set, cannot dispatch event."); return G_SOURCE_REMOVE; } - keep = (*(sr_receive_data_callback)callback)(-1, revents, user_data); + keep = (*SR_RECEIVE_DATA_CALLBACK(callback))(-1, revents, user_data); if (G_LIKELY(keep) && G_LIKELY(!g_source_is_destroyed(source))) { if (usource->timeout_us >= 0) @@ -455,7 +455,7 @@ SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx, if (!source) return SR_ERR; - g_source_set_callback(source, (GSourceFunc)cb, cb_data, NULL); + g_source_set_callback(source, G_SOURCE_FUNC(cb), cb_data, NULL); ret = sr_session_source_add_internal(session, ctx->libusb_ctx, source); g_source_unref(source);