From: Uwe Hermann Date: Wed, 28 Dec 2011 21:55:21 +0000 (+0100) Subject: Make more variables/functions static and non-global. X-Git-Tag: libsigrok-0.1.0~209 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a0ecd83bc6e07ea412db5cd0108d50d89e36df8f;p=libsigrok.git Make more variables/functions static and non-global. The 'GSList *devices' from device.c was actually really global (i.e., listed in sigrok.h), which is now fixed. --- diff --git a/device.c b/device.c index b7dd710c..5596c173 100644 --- a/device.c +++ b/device.c @@ -22,7 +22,7 @@ #include #include -GSList *devices = NULL; +static GSList *devices = NULL; /** * Scan the system for attached logic analyzers / devices. diff --git a/hardware/common/ezusb.c b/hardware/common/ezusb.c index 30b43beb..058a7a02 100644 --- a/hardware/common/ezusb.c +++ b/hardware/common/ezusb.c @@ -31,7 +31,6 @@ #include #include "config.h" - int ezusb_reset(struct libusb_device_handle *hdl, int set_clear) { int err; diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 33957763..1e03d4df 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -35,7 +35,7 @@ // FIXME: Must be moved, or rather passed as function argument. #ifdef _WIN32 -HANDLE hdl; +static HANDLE hdl; #endif const char *serial_port_glob[] = { diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index 44fe0a4a..ed3ed092 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -564,7 +564,7 @@ static int receive_data(int fd, int revents, void *user_data) return TRUE; } -void receive_transfer(struct libusb_transfer *transfer) +static void receive_transfer(struct libusb_transfer *transfer) { /* TODO: these statics have to move to fx2_device struct */ static int num_samples = 0; diff --git a/hwplugin.c b/hwplugin.c index cd8fad13..0ffd6f2e 100644 --- a/hwplugin.c +++ b/hwplugin.c @@ -28,7 +28,7 @@ #include /* The list of loaded plugins lives here. */ -GSList *plugins; +static GSList *plugins; /* * This enumerates which plugin capabilities correspond to user-settable @@ -68,7 +68,6 @@ extern struct sr_device_plugin link_mso19_plugin_info; extern struct sr_device_plugin alsa_plugin_info; #endif - /* TODO: No linked list needed, this can be a simple array. */ int load_hwplugins(void) { @@ -99,7 +98,6 @@ int load_hwplugins(void) plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info); #endif - return SR_OK; } @@ -133,7 +131,6 @@ void sr_cleanup_hwplugins(void) if (plugin->cleanup) plugin->cleanup(); } - } struct sr_device_instance *sr_device_instance_new(int index, int status, @@ -195,7 +192,6 @@ void sr_device_instance_free(struct sr_device_instance *sdi) g_free(sdi->model); g_free(sdi->version); g_free(sdi); - } #ifdef HAVE_LIBUSB_1_0 diff --git a/input/input_binary.c b/input/input_binary.c index 4286a6c3..109927dc 100644 --- a/input/input_binary.c +++ b/input/input_binary.c @@ -28,7 +28,6 @@ #define CHUNKSIZE 4096 #define DEFAULT_NUM_PROBES 8 - static int format_match(const char *filename) { /* suppress compiler warning */ diff --git a/session.c b/session.c index 54966637..8f8edcce 100644 --- a/session.c +++ b/session.c @@ -38,12 +38,12 @@ struct source { }; /* There can only be one session at a time. */ +/* 'session' is not static, it's used elsewhere (via 'extern'). */ struct sr_session *session; -int num_sources = 0; - -struct source *sources = NULL; -int source_timeout = -1; +static int num_sources = 0; +static struct source *sources = NULL; +static int source_timeout = -1; struct sr_session *sr_session_new(void) { @@ -54,7 +54,6 @@ struct sr_session *sr_session_new(void) void sr_session_destroy(void) { - g_slist_free(session->devices); /* TODO: Loop over protocol decoders and free them. */ @@ -152,7 +151,6 @@ static void sr_session_run_poll() } } free(fds); - } int sr_session_start(void) @@ -174,7 +172,6 @@ int sr_session_start(void) void sr_session_run(void) { - sr_info("session: running"); session->running = TRUE; @@ -186,15 +183,12 @@ void sr_session_run(void) else /* real sources, use g_poll() main loop */ sr_session_run_poll(); - } void sr_session_halt(void) { - sr_info("session: halting"); session->running = FALSE; - } void sr_session_stop(void) @@ -209,7 +203,6 @@ void sr_session_stop(void) if (device->plugin && device->plugin->stop_acquisition) device->plugin->stop_acquisition(device->plugin_index, device); } - } static void datafeed_dump(struct sr_datafeed_packet *packet) @@ -236,7 +229,6 @@ static void datafeed_dump(struct sr_datafeed_packet *packet) default: sr_dbg("bus: received unknown packet type %d", packet->type); } - } void sr_session_bus(struct sr_device *device, struct sr_datafeed_packet *packet) @@ -304,4 +296,3 @@ void sr_session_source_remove(int fd) free(new_sources); } } - diff --git a/session_driver.c b/session_driver.c index e59f49d1..689e1da7 100644 --- a/session_driver.c +++ b/session_driver.c @@ -47,7 +47,6 @@ static int capabilities[] = { 0, }; - static struct session_vdevice *get_vdevice_by_index(int device_index) { struct sr_device_instance *sdi; @@ -147,7 +146,6 @@ static void hw_cleanup(void) sr_session_source_remove(-1); g_free(sessionfile); - } static int hw_opendev(int device_index) @@ -190,7 +188,7 @@ static int hw_get_status(int device_index) /* Avoid compiler warnings. */ (void)device_index; - if (devices) + if (sr_device_list() != NULL) return SR_OK; else return SR_ERR; @@ -198,7 +196,6 @@ static int hw_get_status(int device_index) static int *hw_get_capabilities(void) { - return capabilities; } @@ -296,6 +293,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) return SR_OK; } +/* Not static, it's used elsewhere (via 'extern'). */ struct sr_device_plugin session_driver = { "session", "Session-emulating driver", diff --git a/sigrok.h.in b/sigrok.h.in index 929b5c3f..4f3be935 100644 --- a/sigrok.h.in +++ b/sigrok.h.in @@ -225,9 +225,6 @@ struct sr_probe { char *trigger; }; -/* TODO: Get rid of this global variable. */ -extern GSList *devices; - /* Hardware plugin capabilities */ enum { SR_HWCAP_DUMMY, /* Used to terminate lists */ diff --git a/strutil.c b/strutil.c index 6a9d8622..b26caea0 100644 --- a/strutil.c +++ b/strutil.c @@ -284,4 +284,3 @@ gboolean sr_parse_boolstring(const char *boolstr) return FALSE; } -