Fix various gcc 8 compiler warnings related to ARRAY_SIZE. Example: In file included from src/hardware/kecheng-kc-330b/protocol.h:26, from src/hardware/kecheng-kc-330b/api.c:22: src/hardware/kecheng-kc-330b/api.c: In function ‘config_list’: src/libsigrok-internal.h:51:34: warning: division ‘sizeof (void *) / sizeof (void)’ does not compute the number of array elements [-Wsizeof-pointer-div] #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) ^ src/libsigrok-internal.h:55:32: note: in expansion of macro ‘ARRAY_SIZE’ #define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a) ^~~~~~~~~~ src/libsigrok-internal.h:964:43: note: in expansion of macro ‘ARRAY_AND_SIZE’ std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \ ^~~~~~~~~~~~~~ src/hardware/kecheng-kc-330b/api.c:296:10: note: in expansion of macro ‘STD_CONFIG_LIST’ return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); ^~~~~~~~~~~~~~~
drivers: Add and use STD_CONFIG_LIST(). This ensures consistent handling of the SR_CONF_SCAN_OPTIONS and SR_CONF_DEVICE_OPTIONS (with sdi NULL or non-NULL) config keys and also reduces copy-pasted boilerplate in the drivers a bit. This function does not handle channel-group specific items, that's very driver-specific and thus left to the individual drivers. Also move some generic checks and error messages from the drivers into the sr_config_list() wrapper.
Use driver name as the log prefix in standard functions Some of the standard helper functions take a log prefix parameter that is used when printing messages. This log prefix is almost always identical to the name field in the driver's sr_dev_driver struct. The only exception are drivers which register multiple sr_dev_driver structs. Instead of passing the log prefix as a parameter simply use the driver's name. This simplifies the API, gives consistent behaviour between different drivers and also makes it easier to identify where the message originates when a driver registers sr_dev_driver structs. Signed-off-by: Lars-Peter Clausen <redacted>
Add helper function for scan completion A common task during device scan is to add the newly discovered devices to the instance list of the driver. Currently this is done by each driver on its own. This patch introduces a new helper function std_scan_complete() which takes care of this. The function should be called at the end of a driver's scan() callback before returning the device list. Doing this with a helper function provides guaranteed consistent behaviour among drivers and hopefully paves the way to moving more standard functionality directly into the sigrok core. Another common task that every driver has to do for each device instance is to initialize the device's driver field. So this is done in the new helper function as well. All drivers that can make use of the new helper are updated. Signed-off-by: Lars-Peter Clausen <redacted>
Don't reset instance list in scan() callback Some drivers set the device instance list to NULL in their scan() callback. This means the driver loses all references to any devices contained in that list and their resources will be leaked. Drivers can't free the devices at this point either since an application might still use a device on the list. So the existing devices on the instance list need to remain unmodified during the scan() callback, even if that means that there will be duplicates on the instance list. Only an explicit invocation of sr_dev_clear() by the application is allowed to free the devices on the instance list and reset the list. Signed-off-by: Lars-Peter Clausen <redacted>