From 6ab8a2380ae3c2d38ca3d80ab5848c1afca98893 Mon Sep 17 00:00:00 2001 From: Will Hedgecock Date: Mon, 8 Nov 2021 12:50:17 -0600 Subject: [PATCH] Update tuple storage functions --- src/main/c/Windows/SerialPort_Windows.c | 4 ++-- src/main/c/Windows/WindowsHelperFunctions.c | 18 +++++++++--------- src/main/c/Windows/WindowsHelperFunctions.h | 7 ++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/c/Windows/SerialPort_Windows.c b/src/main/c/Windows/SerialPort_Windows.c index 976cd55..f1c29b9 100644 --- a/src/main/c/Windows/SerialPort_Windows.c +++ b/src/main/c/Windows/SerialPort_Windows.c @@ -2,7 +2,7 @@ * SerialPort_Windows.c * * Created on: Feb 25, 2012 - * Last Updated on: Nov 01, 2021 + * Last Updated on: Nov 03, 2021 * Author: Will Hedgecock * * Copyright (C) 2012-2021 Fazecast, Inc. @@ -107,7 +107,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP wchar_t* descriptionString = wcsrchr(valueName, L'\\') ? (wcsrchr(valueName, L'\\') + 1) : valueName; // Add new SerialComm object to vector - push_back(&serialCommPorts, comPortString, descriptionString, descriptionString); + pushBack(&serialCommPorts, comPortString, descriptionString, descriptionString); } } diff --git a/src/main/c/Windows/WindowsHelperFunctions.c b/src/main/c/Windows/WindowsHelperFunctions.c index eafc123..b56b751 100644 --- a/src/main/c/Windows/WindowsHelperFunctions.c +++ b/src/main/c/Windows/WindowsHelperFunctions.c @@ -2,10 +2,10 @@ * WindowsHelperFunctions.c * * Created on: May 05, 2015 - * Last Updated on: Mar 25, 2016 + * Last Updated on: Nov 03, 2021 * Author: Will Hedgecock * - * Copyright (C) 2012-2020 Fazecast, Inc. + * Copyright (C) 2012-2021 Fazecast, Inc. * * This file is part of jSerialComm. * @@ -28,7 +28,7 @@ #include #include "WindowsHelperFunctions.h" -void push_back(struct charTupleVector* vector, const wchar_t* firstString, const wchar_t* secondString, const wchar_t* thirdString) +void pushBack(struct charTupleVector* vector, const wchar_t* key, const wchar_t* firstString, const wchar_t* secondString) { // Allocate memory for new string storage vector->length++; @@ -43,12 +43,12 @@ void push_back(struct charTupleVector* vector, const wchar_t* firstString, const vector->third = newMemory; // Store new strings - vector->first[vector->length-1] = (wchar_t*)malloc((wcslen(firstString)+1)*sizeof(wchar_t)); - vector->second[vector->length-1] = (wchar_t*)malloc((wcslen(secondString)+1)*sizeof(wchar_t)); - vector->third[vector->length-1] = (wchar_t*)malloc((wcslen(thirdString)+1)*sizeof(wchar_t)); - wcscpy(vector->first[vector->length-1], firstString); - wcscpy(vector->second[vector->length-1], secondString); - wcscpy(vector->third[vector->length-1], thirdString); + vector->first[vector->length-1] = (wchar_t*)malloc((wcslen(key)+1)*sizeof(wchar_t)); + vector->second[vector->length-1] = (wchar_t*)malloc((wcslen(firstString)+1)*sizeof(wchar_t)); + vector->third[vector->length-1] = (wchar_t*)malloc((wcslen(secondString)+1)*sizeof(wchar_t)); + wcscpy(vector->first[vector->length-1], key); + wcscpy(vector->second[vector->length-1], firstString); + wcscpy(vector->third[vector->length-1], secondString); } char keyExists(struct charTupleVector* vector, const wchar_t* key) diff --git a/src/main/c/Windows/WindowsHelperFunctions.h b/src/main/c/Windows/WindowsHelperFunctions.h index 4a2ea70..6387ba2 100644 --- a/src/main/c/Windows/WindowsHelperFunctions.h +++ b/src/main/c/Windows/WindowsHelperFunctions.h @@ -2,10 +2,10 @@ * WindowsHelperFunctions.h * * Created on: May 05, 2015 - * Last Updated on: Apr 01, 2018 + * Last Updated on: Nov 03, 2021 * Author: Will Hedgecock * - * Copyright (C) 2012-2020 Fazecast, Inc. + * Copyright (C) 2012-2021 Fazecast, Inc. * * This file is part of jSerialComm. * @@ -31,7 +31,8 @@ typedef struct charTupleVector wchar_t **first, **second, **third; size_t length; } charTupleVector; -void push_back(struct charTupleVector* vector, const wchar_t* firstString, const wchar_t* secondString, const wchar_t* thirdString); + +void pushBack(struct charTupleVector* vector, const wchar_t* key, const wchar_t* firstString, const wchar_t* secondString); char keyExists(struct charTupleVector* vector, const wchar_t* key); #endif // #ifndef __WINDOWS_HELPER_FUNCTIONS_HEADER_H__