Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 libwacom/libwacom-database.c | 15 +++++++++------
 libwacom/libwacom.c          | 41 +++++++++++++++++++++++++----------------
 libwacom/libwacomint.h       |  3 ++-
 3 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index e3023e2..f8cad59 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -161,26 +161,29 @@ match_from_string(const char *str, WacomBusType *bus, int 
*vendor_id, int *produ
 }
 
 static gboolean
-libwacom_matchstr_to_match(WacomDevice *device, const char *match)
+libwacom_matchstr_to_match(WacomDevice *device, const char *matchstr)
 {
        char *name = NULL;
        int vendor_id, product_id;
        WacomBusType bus;
+       WacomMatch *match;
 
-       if (match == NULL)
+       if (matchstr == NULL)
                return FALSE;
 
-       if (g_strcmp0 (match, GENERIC_DEVICE_MATCH) == 0) {
+       if (g_strcmp0 (matchstr, GENERIC_DEVICE_MATCH) == 0) {
                name = NULL;
                bus = WBUSTYPE_UNKNOWN;
                vendor_id = 0;
                product_id = 0;
-       } else if (!match_from_string(match, &bus, &vendor_id, &product_id, 
&name)) {
-               DBG("failed to match '%s' for product/vendor IDs. Skipping.\n", 
match);
+       } else if (!match_from_string(matchstr, &bus, &vendor_id, &product_id, 
&name)) {
+               DBG("failed to match '%s' for product/vendor IDs. Skipping.\n", 
matchstr);
                return FALSE;
        }
 
-       libwacom_update_match(device, name, bus, vendor_id, product_id);
+       match = libwacom_match_new(name, bus, vendor_id, product_id);
+       libwacom_update_match(device, match);
+       libwacom_match_destroy(match);
 
        free(name);
        return TRUE;
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index b093021..38b6225 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -487,6 +487,7 @@ libwacom_new_from_path(const WacomDeviceDatabase *db, const 
char *path, WacomFal
        WacomDevice *ret = NULL;
        WacomIntegrationFlags integration_flags;
        char *name, *match_name;
+       WacomMatch *match;
 
        if (!db) {
                libwacom_error_set(error, WERROR_INVALID_DB, "db is NULL");
@@ -526,7 +527,9 @@ libwacom_new_from_path(const WacomDeviceDatabase *db, const 
char *path, WacomFal
        }
 
        /* for multiple-match devices, set to the one we requested */
-       libwacom_update_match(ret, match_name, bus, vendor_id, product_id);
+       match = libwacom_match_new(match_name, bus, vendor_id, product_id);
+       libwacom_update_match(ret, match);
+       libwacom_match_destroy(match);
 
        g_free (name);
 
@@ -799,28 +802,37 @@ libwacom_destroy(WacomDevice *device)
        g_free (device);
 }
 
-void
-libwacom_update_match(WacomDevice *device, const char *name, WacomBusType bus, 
int vendor_id, int product_id)
+WacomMatch*
+libwacom_match_new(const char *name, WacomBusType bus, int vendor_id, int 
product_id)
 {
+       WacomMatch *match;
        char *newmatch;
-       int i;
-       WacomMatch match;
 
+       match = g_malloc(sizeof(*match));
        if (name == NULL && bus == WBUSTYPE_UNKNOWN && vendor_id == 0 && 
product_id == 0)
                newmatch = g_strdup("generic");
        else
                newmatch = make_match_string(name, bus, vendor_id, product_id);
 
-       match.match = newmatch;
-       match.name = g_strdup(name);
-       match.bus = bus;
-       match.vendor_id = vendor_id;
-       match.product_id = product_id;
+       match->match = newmatch;
+       match->name = g_strdup(name);
+       match->bus = bus;
+       match->vendor_id = vendor_id;
+       match->product_id = product_id;
+
+       return match;
+}
+
+void
+libwacom_update_match(WacomDevice *device, const WacomMatch *newmatch)
+{
+       int i;
 
        for (i = 0; i < device->nmatches; i++) {
-               if 
(g_strcmp0(libwacom_match_get_match_string(device->matches[i]), newmatch) == 0) 
{
+               const char *matchstr = 
libwacom_match_get_match_string(device->matches[i]);
+               if (g_strcmp0(matchstr, newmatch->match) == 0) {
                        device->match = i;
-                       goto out;
+                       return;
                }
        }
 
@@ -828,11 +840,8 @@ libwacom_update_match(WacomDevice *device, const char 
*name, WacomBusType bus, i
 
        device->matches = g_realloc_n(device->matches, device->nmatches + 1, 
sizeof(WacomMatch*));
        device->matches[device->nmatches] = NULL;
-       device->matches[device->nmatches - 1] = libwacom_copy_match(&match);
+       device->matches[device->nmatches - 1] = libwacom_copy_match(newmatch);
        device->match = device->nmatches - 1;
-out:
-       g_free(newmatch);
-       g_free(match.name);
 }
 
 int libwacom_get_vendor_id(const WacomDevice *device)
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index af47bd5..c7d8916 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -120,7 +120,8 @@ struct _WacomError {
 /* INTERNAL */
 void libwacom_error_set(WacomError *error, enum WacomErrorCode code, const 
char *msg, ...);
 void libwacom_stylus_destroy(WacomStylus *stylus);
-void libwacom_update_match(WacomDevice *device, const char *name, WacomBusType 
bus, int vendor_id, int product_id);
+void libwacom_update_match(WacomDevice *device, const WacomMatch *match);
+WacomMatch* libwacom_match_new(const char *name, WacomBusType bus, int 
vendor_id, int product_id);
 void libwacom_match_destroy(WacomMatch *match);
 
 WacomBusType  bus_from_str (const char *str);
-- 
2.7.4


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to