Commit ac6f86bf authored by Greg Williams's avatar Greg Williams
Browse files

Updates to get gcc build working again. Had to disabled const attribute in...

Updates to get gcc build working again. Had to disabled const attribute in byte_array.h for byte_arrays, since they need to be assigned in a ByteBuffer struct at runtime, which GCC will not allow if const.
parent 44323fdc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
0.7.0-beta
0.8.0-beta
+5 −5
Original line number Diff line number Diff line
@@ -13,8 +13,8 @@
 * `NULL`-terminated.
 */
typedef struct _ByteArray {
    const size_t  len;    /**< Number of bytes in the `data` field. */
    uint8_t* const data;  /**< Pointer to an allocated array of data bytes. */
    size_t  len;    /**< Number of bytes in the `data` field. */
    uint8_t* data;  /**< Pointer to an allocated array of data bytes. */
} ByteArray;

/** @brief Convenience macro to represent an empty array with no data */
@@ -32,12 +32,12 @@ void ByteArray_FillWithDummyData(const ByteArray array);
 * byte is consumed, but shall not exceed the `array` length
 */
typedef struct {
    const ByteArray array;     /**< ByteArray holding allocated array w/length = allocated size */
    ByteArray array;  /**< ByteArray holding allocated array w/length = allocated size */
    size_t bytesUsed; /**< Reflects the number of bytes used from the `array` */
} ByteBuffer;

/** @brief Convenience macro to represent an empty buffer with no data */
#define BYTE_BUFFER_NONE (ByteBuffer){.array = BYTE_ARRAY_NONE}
#define BYTE_BUFFER_NONE (ByteBuffer){.array = BYTE_ARRAY_NONE, .bytesUsed = 0}

ByteBuffer ByteBuffer_Create(void* data, size_t max_len, size_t used);
ByteBuffer ByteBuffer_CreateWithArray(ByteArray array);
+44 −14
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
#include <stdlib.h>
#include <pthread.h>

// #define KINETIC_LOG_ALLOCATOR

pthread_mutex_t _global_pdu_lists_mutex = PTHREAD_MUTEX_INITIALIZER;
STATIC bool listsLocked = false;

@@ -48,6 +50,10 @@ void* KineticAllocator_NewItem(KineticList* const list, size_t size)
    }
    memset(newItem, 0, sizeof(KineticListItem));
    newItem->data = malloc(size);
    if (newItem->data == NULL) {
        LOG("Failed allocating data for list item!");
        return NULL;
    }
    memset(newItem->data, 0, size);

    // Add the new item to the list
@@ -62,8 +68,10 @@ void* KineticAllocator_NewItem(KineticList* const list, size_t size)
    list->last = newItem;
    KineticAllocator_Unlock();

    // LOGF("Allocated new list item @ 0x%0llX w/data @ 0x%0llX",
    //      (long long)newItem, (long long)&newItem->data);
    #ifdef KINETIC_LOG_ALLOCATOR
    LOGF("Allocated new list item @ 0x%0llX w/data @ 0x%0llX",
         (long long)newItem, (long long)newItem->data);
    #endif

    return newItem->data;
}
@@ -123,8 +131,10 @@ void KineticAllocator_FreeItem(KineticList* const list, void* item)
            }
        }

        // LOGF("  Freeing item @ 0x%0llX, item @ 0x%0llX",
        //      (long long)cur, (long long)&cur->data);
        #ifdef KINETIC_LOG_ALLOCATOR
        LOGF("  Freeing item @ 0x%0llX, item @ 0x%0llX",
             (long long)cur, (long long)&cur->data);
        #endif
        free(cur->data);
        cur->data = NULL;
        free(cur);
@@ -136,32 +146,42 @@ void KineticAllocator_FreeItem(KineticList* const list, void* item)
void KineticAllocator_FreeList(KineticList* const list)
{
    if (list != NULL) {
        #ifdef KINETIC_LOG_ALLOCATOR
        LOG("Freeing list of all items");
        #endif

        KineticAllocator_Lock();

        KineticListItem* current = list->start;

        while (current->next != NULL) {
            // LOG("Advancing to next list item...");
            #ifdef KINETIC_LOG_ALLOCATOR
            LOG("Advancing to next list item...");
            #endif
            current = current->next;
        }

        while (current != NULL) {
            // LOG("  Current item not freed!");
            // LOGF("  DEALLOCATING item: 0x%0llX, data: 0x%llX, prev: 0x%0llX",
            //     (long long)current, (long long)&current->data, (long long)current->previous);
            #ifdef KINETIC_LOG_ALLOCATOR
            LOG("  Current item not freed!");
            LOGF("  DEALLOCATING item: 0x%0llX, data: 0x%llX, prev: 0x%0llX",
                (long long)current, (long long)&current->data, (long long)current->previous);
            #endif
            KineticListItem* curItem = current;
            KineticListItem* prevItem = current->previous;
            if (curItem != NULL) {
                // LOG("  Freeing list item");
                #ifdef KINETIC_LOG_ALLOCATOR
                LOG("  Freeing list item");
                #endif
                if (curItem->data != NULL) {
                    free(curItem->data);
                }
                free(curItem);
            }
            current = prevItem;
            // LOGF("  on to prev=0x%llX", (long long)current);
            #ifdef KINETIC_LOG_ALLOCATOR
            LOGF("  on to prev=0x%llX", (long long)current);
            #endif
        }

        *list = (KineticList) {
@@ -171,7 +191,9 @@ void KineticAllocator_FreeList(KineticList* const list)
        KineticAllocator_Unlock();
    }
    else {
        #ifdef KINETIC_LOG_ALLOCATOR
        LOG("  Nothing to free!");
        #endif
    }

}
@@ -187,7 +209,9 @@ KineticPDU* KineticAllocator_NewPDU(KineticList* const list, KineticConnection*
    }
    assert(newPDU->proto == NULL);
    KINETIC_PDU_INIT(newPDU, connection);
    // LOGF("Allocated new PDU @ 0x%0llX", (long long)newPDU);
    #ifdef KINETIC_LOG_ALLOCATOR
    LOGF("Allocated new PDU @ 0x%0llX", (long long)newPDU);
    #endif
    return newPDU;
}

@@ -195,7 +219,9 @@ void KineticAllocator_FreePDU(KineticList* const list, KineticPDU* pdu)
{
    KineticAllocator_Lock();
    if ((pdu->proto != NULL) && pdu->protobufDynamicallyExtracted) {
        // LOG("Freeing dynamically allocated protobuf");
        #ifdef KINETIC_LOG_ALLOCATOR
        LOG("Freeing dynamically allocated protobuf");
        #endif
        KineticProto_Message__free_unpacked(pdu->proto, NULL);
    };
    KineticAllocator_Unlock();
@@ -220,14 +246,18 @@ void KineticAllocator_FreeAllPDUs(KineticList* const list)
        KineticAllocator_FreeList(list);
    }
    else {
        #ifdef KINETIC_LOG_ALLOCATOR
        LOG("  Nothing to free!");
        #endif
    }
}

bool KineticAllocator_ValidateAllMemoryFreed(KineticList* const list)
{
    bool empty = (list->start == NULL);
    // LOGF("  PDUList: 0x%0llX, empty=%s",
    // (long long)list->start, empty ? "true" : "false");
    #ifdef KINETIC_LOG_ALLOCATOR
    LOGF("  PDUList: 0x%0llX, empty=%s",
        (long long)list->start, empty ? "true" : "false");
    #endif
    return empty;
}
+1 −0
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ void KineticLogger_LogProtobuf(const KineticProto_Message* msg)
    if (msg->has_commandBytes
      && msg->commandBytes.data != NULL
      && msg->commandBytes.len > 0) {
        
        LOG_PROTO_LEVEL_START("commandBytes");

        KineticProto_Command* cmd = KineticProto_command__unpack(NULL, msg->commandBytes.len, msg->commandBytes.data);
+1 −3
Original line number Diff line number Diff line
@@ -125,7 +125,6 @@ KineticStatus KineticPDU_Send(KineticPDU* request)

KineticStatus KineticPDU_Receive(KineticPDU* const response)
{
LOG_LOCATION; LOG("HERE");
    assert(response != NULL);
    assert(response->connection != NULL);
    const int fd = response->connection->socket;
@@ -223,9 +222,8 @@ LOG_LOCATION; LOG("HERE");
            LOG("Received value payload successfully");
            KineticLogger_LogByteBuffer("ACTUAL VALUE RECEIVED", response->entry.value);
        }
        KineticLogger_LogByteBuffer("Value Buffer", response->entry.value);
#endif

        // KineticLogger_LogByteBuffer("Value Buffer", response->entry.value);
    }

    // Update connectionID to match value returned from device, if provided
Loading