]> sigrok.org Git - sigrok-util.git/commitdiff
new-driver: keep driver_info local to the api.c source file
authorGerhard Sittig <redacted>
Sat, 17 Nov 2018 19:32:25 +0000 (20:32 +0100)
committerUwe Hermann <redacted>
Thu, 20 Dec 2018 15:55:09 +0000 (16:55 +0100)
There is a circular reference between the driver info structure (which
lists callback routines) and a driver's routines (one of them may have
to reference the driver info). Add a forward declaration, and keep the
declaration and the implementation 'static' within the api.c source
file. Otherwise linker issues may arise should developers put the
declaration into protocol.h since it's marked as SR_PRIV in the template.

source/drv-api.c

index 3444fd6693b4a7b607340755f360c088a35fe5e4..6a1c20c70b8328a7fa2fcb7e6a1cdc237dc78562 100644 (file)
@@ -20,6 +20,8 @@
 #include <config.h>
 #include "protocol.h"
 
+static struct sr_dev_driver {lib}_driver_info;
+
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {{
        struct drv_context *drvc;
@@ -131,7 +133,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        return SR_OK;
 }}
 
-SR_PRIV struct sr_dev_driver {lib}_driver_info = {{
+static struct sr_dev_driver {lib}_driver_info = {{
        .name = "{short}",
        .longname = "{name}",
        .api_version = 1,
@@ -149,5 +151,4 @@ SR_PRIV struct sr_dev_driver {lib}_driver_info = {{
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 }};
-
 SR_REGISTER_DEV_DRIVER({lib}_driver_info);