[SCM] zynaddsubfx/master: Add patch to fix build on some archs.

mira-guest at users.alioth.debian.org mira-guest at users.alioth.debian.org
Tue Sep 8 22:18:03 UTC 2015


The following commit has been merged in the master branch:
commit 1c94b855bb5f2c030de1aa0d3ffd7f519dc3c9f3
Author: Jaromír Mikeš <mira.mikes at seznam.cz>
Date:   Wed Sep 9 00:08:01 2015 +0200

    Add patch to fix build on some archs.

diff --git a/debian/patches/04-fix_endianess.patch b/debian/patches/04-fix_endianess.patch
new file mode 100644
index 0000000..ead510d
--- /dev/null
+++ b/debian/patches/04-fix_endianess.patch
@@ -0,0 +1,1014 @@
+Description: Fix Endianess Dependency & Refactor Tests.
+https://github.com/fundamental/rtosc/commit/7509ab50719a01c62548973ec431dc307599ec67
+Author: Jaromír Mikeš <mira.mikes at seznam.cz>
+Forwarded: no
+
+Index: zynaddsubfx/rtosc/src/cpp/subtree-serialize.cpp
+===================================================================
+--- zynaddsubfx.orig/rtosc/src/cpp/subtree-serialize.cpp
++++ zynaddsubfx/rtosc/src/cpp/subtree-serialize.cpp
+@@ -7,6 +7,14 @@
+ 
+ using namespace rtosc;
+ 
++static void emplace_uint32(uint8_t *buffer, uint32_t d)
++{
++    buffer[0] = ((d>>24) & 0xff);
++    buffer[1] = ((d>>16) & 0xff);
++    buffer[2] = ((d>>8)  & 0xff);
++    buffer[3] = ((d>>0)  & 0xff);
++}
++
+ /*
+  * Append another message onto a bundle if the space permits it.
+  * If insufficient space is available, then zero is returned and the buffer is
+@@ -26,7 +34,7 @@ static size_t append_bundle(char *dst, c
+ 
+     if(max_len < dst_len + src_len + 4 || dst_len == 0 || src_len == 0)
+         return 0;
+-    *(int32_t*)(dst+dst_len) = (int32_t)src_len;
++    emplace_uint32((uint8_t*)(dst+dst_len), src_len);
+ 
+     memcpy(dst+dst_len+4, src, src_len);
+ 
+Index: zynaddsubfx/rtosc/src/rtosc.c
+===================================================================
+--- zynaddsubfx.orig/rtosc/src/rtosc.c
++++ zynaddsubfx/rtosc/src/rtosc.c
+@@ -78,6 +78,58 @@ char rtosc_type(const char *msg, unsigne
+     }
+ }
+ 
++static unsigned arg_start(const char *msg_)
++{
++    const uint8_t *msg = (const uint8_t*)msg_;
++    //Iterate to the right position
++    const uint8_t *args = (const uint8_t*) rtosc_argument_string(msg_);
++    const uint8_t *aligned_ptr = args-1;
++    const uint8_t *arg_pos = args;
++
++    while(*++arg_pos);
++    //Alignment
++    arg_pos += 4-(arg_pos-aligned_ptr)%4;
++    return arg_pos-msg;
++}
++
++static unsigned arg_size(const uint8_t *arg_mem, char type)
++{
++    if(!has_reserved(type))
++        return 0;
++    const uint8_t  *arg_pos=arg_mem;
++    uint32_t blob_length = 0;
++    switch(type)
++    {
++        case 'h':
++        case 't':
++        case 'd':
++            return 8;
++        case 'm':
++        case 'r':
++        case 'f':
++        case 'c':
++        case 'i':
++            return 4;
++        case 'S':
++        case 's':
++            while(*++arg_pos);
++            arg_pos += 4-(arg_pos-arg_mem)%4;
++            return arg_pos-arg_mem;
++        case 'b':
++            blob_length |= (*arg_pos++ << 24);
++            blob_length |= (*arg_pos++ << 16);
++            blob_length |= (*arg_pos++ << 8);
++            blob_length |= (*arg_pos++);
++            if(blob_length%4)
++                blob_length += 4-blob_length%4;
++            arg_pos += blob_length;
++            return arg_pos-arg_mem;
++        default:
++            assert("Invalid Type");
++    }
++    return -1;
++}
++
+ static unsigned arg_off(const char *msg, unsigned idx)
+ {
+     if(!has_reserved(rtosc_type(msg,idx)))
+@@ -97,45 +149,11 @@ static unsigned arg_off(const char *msg,
+         ++args;
+ 
+     while(idx--) {
+-        uint32_t bundle_length = 0;
+-        switch(*args++)
+-        {
+-            case 'h':
+-            case 't':
+-            case 'd':
+-                arg_pos +=8;
+-                break;
+-            case 'm':
+-            case 'r':
+-            case 'f':
+-            case 'c':
+-            case 'i':
+-                arg_pos += 4;
+-                break;
+-            case 'S':
+-            case 's':
+-                while(*++arg_pos);
+-                arg_pos += 4-(arg_pos-((uint8_t*)aligned_ptr))%4;
+-                break;
+-            case 'b':
+-                bundle_length |= (*arg_pos++ << 24);
+-                bundle_length |= (*arg_pos++ << 16);
+-                bundle_length |= (*arg_pos++ << 8);
+-                bundle_length |= (*arg_pos++);
+-                if(bundle_length%4)
+-                    bundle_length += 4-bundle_length%4;
+-                arg_pos += bundle_length;
+-                break;
+-            case '[':
+-            case ']':
+-                //completely ignore array chars
+-                ++idx;
+-                break;
+-            case 'T':
+-            case 'F':
+-            case 'I':
+-                ;
+-        }
++        char type = *args++;
++        if(type == '[' || type == ']')
++            idx++;//not a valid arg idx
++        else
++            arg_pos += arg_size(arg_pos, type);
+     }
+     return arg_pos-(uint8_t*)msg;
+ }
+@@ -385,10 +403,9 @@ size_t rtosc_amessage(char
+     return pos;
+ }
+ 
+-rtosc_arg_t rtosc_argument(const char *msg, unsigned idx)
++static rtosc_arg_t extract_arg(const uint8_t *arg_pos, char type)
+ {
+     rtosc_arg_t result = {0};
+-    char type = rtosc_type(msg, idx);
+     //trivial case
+     if(!has_reserved(type)) {
+         switch(type)
+@@ -403,7 +420,6 @@ rtosc_arg_t rtosc_argument(const char *m
+                 ;
+         }
+     } else {
+-        const unsigned char *arg_pos = (const unsigned char*)msg+arg_off(msg,idx);
+         switch(type)
+         {
+             case 'h':
+@@ -450,6 +466,52 @@ rtosc_arg_t rtosc_argument(const char *m
+     return result;
+ }
+ 
++static const char *advance_past_dummy_args(const char *args)
++{
++    while(*args == '[' || *args == ']')
++        args++;
++    return args;
++}
++
++rtosc_arg_itr_t rtosc_itr_begin(const char *msg)
++{
++    rtosc_arg_itr_t itr;
++    itr.type_pos  = advance_past_dummy_args(rtosc_argument_string(msg));
++    itr.value_pos = (uint8_t*)(msg+arg_start(msg));
++
++    return itr;
++}
++
++rtosc_arg_val_t rtosc_itr_next(rtosc_arg_itr_t *itr)
++{
++    //current position provides the value
++    rtosc_arg_val_t result = {0};
++    result.type = *itr->type_pos;
++    if(result.type)
++        result.val = extract_arg(itr->value_pos, result.type);
++
++    //advance
++    itr->type_pos = advance_past_dummy_args(itr->type_pos+1);
++    char type = result.type;
++    int size  = arg_size(itr->value_pos, type);
++    itr->value_pos += size;
++
++
++    return result;
++}
++
++int rtosc_itr_end(rtosc_arg_itr_t itr)
++{
++    return !itr.type_pos  || !*itr.type_pos;
++}
++
++rtosc_arg_t rtosc_argument(const char *msg, unsigned idx)
++{
++    char type = rtosc_type(msg, idx);
++    uint8_t *arg_mem = (uint8_t*)msg + arg_off(msg, idx);
++    return extract_arg(arg_mem, type);
++}
++
+ static unsigned char deref(unsigned pos, ring_t *ring)
+ {
+     return pos<ring[0].len ? ring[0].data[pos] :
+@@ -461,10 +523,10 @@ static size_t bundle_ring_length(ring_t
+     unsigned pos = 8+8;//goto first length field
+     uint32_t advance = 0;
+     do {
+-        advance = deref(pos+0, ring) << (8*0) |
+-                  deref(pos+1, ring) << (8*1) |
+-                  deref(pos+2, ring) << (8*2) |
+-                  deref(pos+3, ring) << (8*3);
++        advance = deref(pos+0, ring) << (8*3) |
++                  deref(pos+1, ring) << (8*2) |
++                  deref(pos+2, ring) << (8*1) |
++                  deref(pos+3, ring) << (8*0);
+         if(advance)
+             pos += 4+advance;
+     } while(advance);
+@@ -598,6 +660,49 @@ bool rtosc_valid_message_p(const char *m
+     size_t observed_length = rtosc_message_length(msg, len);
+     return observed_length == len;
+ }
++static uint64_t extract_uint64(const uint8_t *arg_pos)
++{
++    uint64_t arg = 0;
++    arg |= (((uint64_t)*arg_pos++) << 56);
++    arg |= (((uint64_t)*arg_pos++) << 48);
++    arg |= (((uint64_t)*arg_pos++) << 40);
++    arg |= (((uint64_t)*arg_pos++) << 32);
++    arg |= (((uint64_t)*arg_pos++) << 24);
++    arg |= (((uint64_t)*arg_pos++) << 16);
++    arg |= (((uint64_t)*arg_pos++) << 8);
++    arg |= (((uint64_t)*arg_pos++));
++    return arg;
++}
++
++static uint32_t extract_uint32(const uint8_t *arg_pos)
++{
++    uint32_t arg = 0;
++    arg |= (((uint32_t)*arg_pos++) << 24);
++    arg |= (((uint32_t)*arg_pos++) << 16);
++    arg |= (((uint32_t)*arg_pos++) << 8);
++    arg |= (((uint32_t)*arg_pos++));
++    return arg;
++}
++
++static void emplace_uint64(uint8_t *buffer, uint64_t d)
++{
++    buffer[0] = ((d>>56) & 0xff);
++    buffer[1] = ((d>>48) & 0xff);
++    buffer[2] = ((d>>40) & 0xff);
++    buffer[3] = ((d>>32) & 0xff);
++    buffer[4] = ((d>>24) & 0xff);
++    buffer[5] = ((d>>16) & 0xff);
++    buffer[6] = ((d>>8)  & 0xff);
++    buffer[7] = ((d>>0)  & 0xff);
++}
++
++static void emplace_uint32(uint8_t *buffer, uint32_t d)
++{
++    buffer[0] = ((d>>24) & 0xff);
++    buffer[1] = ((d>>16) & 0xff);
++    buffer[2] = ((d>>8)  & 0xff);
++    buffer[3] = ((d>>0)  & 0xff);
++}
+ 
+ size_t rtosc_bundle(char *buffer, size_t len, uint64_t tt, int elms, ...)
+ {
+@@ -605,15 +710,15 @@ size_t rtosc_bundle(char *buffer, size_t
+     memset(buffer, 0, len);
+     strcpy(buffer, "#bundle");
+     buffer += 8;
+-    (*(uint64_t*)buffer) = tt;
+-    buffer +=8;
++    emplace_uint64((uint8_t*)buffer, tt);
++    buffer += 8;
+     va_list va;
+     va_start(va, elms);
+     for(int i=0; i<elms; ++i) {
+         const char   *msg  = va_arg(va, const char*);
+         //It is assumed that any passed message/bundle is valid
+         size_t        size = rtosc_message_length(msg, -1);
+-        *(uint32_t*)buffer = size;
++        emplace_uint32((uint8_t*)buffer, size);
+         buffer += 4;
+         memcpy(buffer, msg, size);
+         buffer+=size;
+@@ -623,14 +728,14 @@ size_t rtosc_bundle(char *buffer, size_t
+     return buffer-_buffer;
+ }
+ 
++
+ #define POS ((size_t)(((const char *)lengths) - buffer))
+ size_t rtosc_bundle_elements(const char *buffer, size_t len)
+ {
+     const uint32_t *lengths = (const uint32_t*) (buffer+16);
+     size_t elms = 0;
+-    //TODO
+-    while(POS < len && *lengths) {
+-        lengths += *lengths/4+1;
++    while(POS < len && extract_uint32((const uint8_t*)lengths)) {
++        lengths += extract_uint32((const uint8_t*)lengths)/4+1;
+ 
+         if(POS > len)
+             break;
+@@ -644,7 +749,10 @@ const char *rtosc_bundle_fetch(const cha
+ {
+     const uint32_t *lengths = (const uint32_t*) (buffer+16);
+     size_t elm_pos = 0;
+-    while(elm_pos!=elm && *lengths) ++elm_pos, lengths+=*lengths/4+1;
++    while(elm_pos!=elm && extract_uint32((const uint8_t*)lengths)) {
++        ++elm_pos;
++        lengths += extract_uint32((const uint8_t*)lengths)/4+1;
++    }
+ 
+     return (const char*) (elm==elm_pos?lengths+1:NULL);
+ }
+@@ -654,9 +762,9 @@ size_t rtosc_bundle_size(const char *buf
+     const uint32_t *lengths = (const uint32_t*) (buffer+16);
+     size_t elm_pos = 0;
+     size_t last_len = 0;
+-    while(elm_pos!=elm && *lengths) {
+-        last_len = *lengths;
+-        ++elm_pos, lengths+=*lengths/4+1;
++    while(elm_pos!=elm && extract_uint32((const uint8_t*)lengths)) {
++        last_len = extract_uint32((const uint8_t*)lengths);
++        ++elm_pos, lengths+=extract_uint32((const uint8_t*)lengths)/4+1;
+     }
+ 
+     return last_len;
+@@ -669,5 +777,5 @@ int rtosc_bundle_p(const char *msg)
+ 
+ uint64_t rtosc_bundle_timetag(const char *msg)
+ {
+-    return *(uint64_t*)(msg+8);
++    return extract_uint64((const uint8_t*)msg+8);
+ }
+Index: zynaddsubfx/rtosc/test/bundles.c
+===================================================================
+--- zynaddsubfx.orig/rtosc/test/bundles.c
++++ zynaddsubfx/rtosc/test/bundles.c
+@@ -1,6 +1,5 @@
+-#include <stdio.h>
++#include "common.h"
+ #include <stdlib.h>
+-#include <string.h>
+ #include <rtosc/rtosc.h>
+ 
+ char buffer_a[256];
+@@ -11,15 +10,6 @@ size_t len_a;
+ size_t len_b;
+ size_t len_c;
+ 
+-
+-void check(int b, const char *msg, int loc)
+-{
+-    if(!b) {
+-        fprintf(stderr, "%s:%d\n", msg, loc);
+-        exit(1);
+-    }
+-}
+-
+ #define MSG1 "/fly" "ing-" "monk" "ey\0\0" ",s\0\0" "bann" "ana\0"
+ #define MSG2 "/foo" "bar-" "mess" "age\0" ",iT\0" "\0\0\0\x2a"
+ 
+@@ -28,47 +18,55 @@ void check(int b, const char *msg, int l
+                /*size1             size2*/ \
+                "\0\0\0\x1c" MSG1 "\0\0\0\x18" MSG2
+ 
+-//TODO nested bundles (though I swore those were already done)
+ int main()
+ {
+-    printf("%d %d %d\n", (int)sizeof(MSG1)-1, (int)sizeof(MSG2)-1, (int)sizeof(RESULT)-1);
+-    check((len_a = rtosc_message(buffer_a, 256,
+-                    "/flying-monkey", "s", "bannana")) == sizeof(MSG1)-1,
+-            "bad message", __LINE__);
+-    check((len_b = rtosc_message(buffer_b, 256,
+-                    "/foobar-message", "iT", 42)) == sizeof(MSG2)-1,
+-            "bad message", __LINE__);
+-    check(!rtosc_bundle_p(buffer_a),
+-            "False positive bundle_p()", __LINE__);
+-    check(!rtosc_bundle_p(buffer_b),
+-            "False positive bundle_p()", __LINE__);
+-    len_c = rtosc_bundle(buffer_c, 256, 0, 2, buffer_a, buffer_b);
+-        printf("len_c => '%zd'\n correct is %d\n", len_c, (int)sizeof(RESULT)-1);
+-    check((len_c = rtosc_bundle(buffer_c, 256, 0, 2, buffer_a, buffer_b)) == sizeof(RESULT)-1,
+-            "bad bundle", __LINE__);
+-    check(rtosc_message_length(buffer_c, len_c) == len_c,
+-            "bad message length", __LINE__);
+-
+-    check(rtosc_bundle_p(buffer_c),
+-            "Bad bundle detection", __LINE__);
+-    check(rtosc_bundle_elements(buffer_c, 256)==2,
+-            "Bad bundle_elements length", __LINE__);
+-    check(!strcmp("/flying-monkey", rtosc_bundle_fetch(buffer_c, 0)),
+-            "Bad bundle_fetch", __LINE__);
+-    check(!strcmp("/foobar-message", rtosc_bundle_fetch(buffer_c, 1)),
+-            "Bad bundle_fetch", __LINE__);
++    //Message 1
++    assert_int_eq(sizeof(MSG1)-1, len_a = rtosc_message(buffer_a, 256,
++                    "/flying-monkey", "s", "bannana"),
++            "Creating Simple Message 1", __LINE__);
++    assert_hex_eq(MSG1, buffer_a, sizeof(MSG1)-1, len_a,
++            "Verifying Content of Message 1", __LINE__);
++    assert_int_eq(0, rtosc_bundle_p(buffer_a),
++            "Simple Message 1 Is Not A Bundle", __LINE__);
++
++    //Message 2
++    assert_int_eq(sizeof(MSG2)-1, len_b = rtosc_message(buffer_b, 256,
++                    "/foobar-message", "iT", 42),
++            "Creating Simple Message 2", __LINE__);
++    assert_hex_eq(MSG2, buffer_b, sizeof(MSG2)-1, len_b,
++            "Verifying Content of Message 2", __LINE__);
++    assert_int_eq(0, rtosc_bundle_p(buffer_b),
++            "Simple Message 2 Is Not A Bundle", __LINE__);
++
++    //Bundle 1
++    assert_int_eq(sizeof(RESULT)-1, len_c = rtosc_bundle(buffer_c, 256, 0, 2, buffer_a, buffer_b),
++            "Creating Bundle 1", __LINE__);
++    assert_int_eq(len_c, rtosc_message_length(buffer_c, len_c),
++            "Verifying Bundle 1's Length", __LINE__);
++    assert_hex_eq(RESULT, buffer_c, sizeof(RESULT)-1, len_c,
++            "Verifying Bundle 1's Content", __LINE__);
++
++    assert_int_eq(1, rtosc_bundle_p(buffer_c),
++            "Verifying Bundle 1 Is A Bundle", __LINE__);
++    assert_int_eq(2, rtosc_bundle_elements(buffer_c, 256),
++            "Verifying Bundle 2 Has Two Messages", __LINE__);
++
++    assert_str_eq("/flying-monkey", rtosc_bundle_fetch(buffer_c, 0),
++            "Verifying Message 1 Path", __LINE__);
++    assert_str_eq("/foobar-message", rtosc_bundle_fetch(buffer_c, 1),
++            "Verifying Message 2 Path", __LINE__);
+ 
+     //Check minimum bundle size #bundle + time tag
+-    check(rtosc_bundle(buffer_c, 256, 1, 0) == (8+8),
+-            "Bad minimum bundle length", __LINE__);
++    assert_int_eq(8+8, rtosc_bundle(buffer_c, 256, 1, 0),
++            "Verify Minimum Legal Bundle Size", __LINE__);
+ 
+     //check message length support
+-    check(rtosc_message_length(buffer_c, 256) == (8+8),
+-            "Bad message length", __LINE__);
++    assert_int_eq(8+8, rtosc_message_length(buffer_c, 256),
++            "Verify rtosc_message_length() on Minimum Bundle", __LINE__);
+ 
+     //Verify that timetag can be fetched
+-    check(rtosc_bundle_timetag(buffer_c)==1,
+-            "Bad timetag", __LINE__);
++    assert_int_eq(1, rtosc_bundle_timetag(buffer_c),
++            "Verify rtosc_bundle_timetag() Works", __LINE__);
+ 
+-    return 0;
++    return global_err ? EXIT_FAILURE : EXIT_SUCCESS;
+ }
+Index: zynaddsubfx/rtosc/test/liblo.c
+===================================================================
+--- zynaddsubfx.orig/rtosc/test/liblo.c
++++ zynaddsubfx/rtosc/test/liblo.c
+@@ -1,72 +1,77 @@
++#include "common.h"
+ #include <lo/lo.h>
+ #include <rtosc/rtosc.h>
+ #include <string.h>
+ #include <stdio.h>
+ 
+-char buffer[128];
++char buffer1[128];
+ 
+ char buffer2[1024];
+ 
+ char buffer3[2048];
+ 
+-int good = 1;
++char buffer4[2048];
++char buffer5[2048];
++
++
++int result_var = 0;
+ int main()
+ {
+     //clean buffer
+-    memset(buffer, 0, sizeof(buffer));
++    memset(buffer1, 0xc3, sizeof(buffer1));
+ 
+-    //generate liblo message
++    //generate liblo message 1
+     size_t len = 128;
+     lo_message message = lo_message_new();
++    assert_non_null(message, "Generating A Liblo Message 1 (int/float)", __LINE__);
+     lo_message_add_float(message, 24.0);
+     lo_message_add_int32(message, 42);
+-    lo_message_serialise(message, "/path", buffer, &len);
+-    lo_message_free(message);
++    lo_message_serialise(message, "/path", buffer1, &len);
++    //lo_message_free(message);
+ 
+-    printf("Generating a message from liblo '/path\\0\\0\\0,fi\\0iiiiffff'...\n");
++    assert_str_eq("/path", buffer1, "Verifying Path From Message 1", __LINE__);
++    assert_f32_eq(24.0f, rtosc_argument(buffer1, 0).f,
++            "Verifying Float From Message 1", __LINE__);
++    assert_int_eq(42, rtosc_argument(buffer1, 1).i,
++            "Verifying Int From Message 1", __LINE__);
++    assert_int_eq(20, rtosc_message_length(buffer1, 128),
++            "Verifying Length From Message 1", __LINE__);
++
++
++    //Message 2
++    size_t len2 = rtosc_message(buffer2, 1024, "/li", "bb", 4, buffer1, 4, buffer1);
++    assert_int_eq(24, len2, "Generate A Rtosc Message 2 (bb)", __LINE__);
++    lo_message msg2 = lo_message_deserialise((void*)buffer2, len2, &result_var);
++    if(assert_non_null(msg2, "Deserialize Message 2 To Liblo", __LINE__))
++        printf("# Liblo Did Not Accept the Rtosc Message [error '%d']\n", result_var);
++
++    //Message 3
++    size_t len3 = rtosc_message(buffer3+4, 2048, "/close-ui", "");
++    assert_int_eq(16, len3, "Generate A Rtosc Message 3 ()", __LINE__);
++    lo_message msg3 = lo_message_deserialise((void*)(buffer3+4), len3, &result_var);
++    if(assert_non_null(msg2, "Deserialize Message 3 To Liblo", __LINE__))
++        printf("#Liblo Did Not Accept the Rtosc Message [error '%d']\n", result_var);
++
++    //Bundle 4
++    size_t len4 = rtosc_bundle(buffer4, 2048, 0xdeadbeefcafebaad, 3, buffer1, buffer2, buffer3+4);
++    assert_int_eq(88, len4, "Generate A Bundle 4", __LINE__);
++
++    //Bundle 5
++    lo_timetag time;
++    time.sec  = 0xdeadbeef;
++    time.frac = 0xcafebaad;
++    lo_bundle ms4 = lo_bundle_new(time);
++    lo_bundle_add_message(ms4, "/path",     message);
++    lo_bundle_add_message(ms4, "/li",       msg2);
++    lo_bundle_add_message(ms4, "/close-ui", msg3);
++    size_t len5 = 2048;
++    lo_bundle_serialise(ms4,(void*)buffer5, &len5);
++
++    //Verify 4 == 5
++    assert_non_null(ms4, "Generate A Liblo Bundle 5", __LINE__);
++    assert_hex_eq(buffer5, buffer4, len5, len4,
++            "Verify Liblo Style Bundles", __LINE__);
+ 
+-    good &= !strcmp("/path", buffer);
+-    good &= 24.0 == rtosc_argument(buffer, 0).f;
+-    good &= 42   == rtosc_argument(buffer, 1).i;
+-    good &= len  == rtosc_message_length(buffer, 128);
+-    printf("Message sanity is currently '%d'\n", good);
+-
+-    printf("Generating a message from rtosc '/li\\0\\0,bb\\0iiiibbbbiiiibbbb'...\n");
+-    size_t len2 = rtosc_message(buffer2, 1024, "/li", "bb", 4, buffer, 4, buffer);
+-    for(size_t i=0; i<len2; i+=4)  {
+-        for(size_t j=i; j<len2 && j<i+4; ++j) {
+-            printf("%02x", (unsigned char)buffer2[j]);
+-        }
+-        printf(" ");
+-    }
+-    printf("\n");
+-
+-    for(size_t i=0; i<len2; i+=4)  {
+-        for(size_t j=i; j<len2 && j<i+4; ++j) {
+-            printf("%c", (unsigned char)buffer2[j]);
+-        }
+-        printf(" ");
+-    }
+-    printf("\n");
+-    printf("message size is '%zd'\n", len2);
+-
+-    int result = 0;
+-    lo_message msg2 = lo_message_deserialise((void*)buffer2, len2, &result);
+-    good &= msg2 != NULL;
+-    if(msg2 == NULL)
+-        printf("Liblo Did Not Accept the Rtosc Message [error '%d']\n", result);
+-    else
+-        printf("Liblo Accpted The Rtosc Message\n");
+-
+-    printf("Generating a message from rtosc '/close-ui\\0\\0\\0,\\0\\0\\0'...\n");
+-    int len3 = rtosc_message(buffer3+4, 2048, "/close-ui", "");
+-    lo_message msg3 = lo_message_deserialise((void*)buffer3+4, len3, &result);
+-    printf("len3 = %d\n", len3);
+-    good &= msg2 != NULL;
+-    if(msg3 == NULL)
+-        printf("Liblo Did Not Accept the Rtosc Message [error '%d']\n", result);
+-    else
+-        printf("Liblo Accpted The Rtosc Message\n");
+ 
+-    return !good;
++    return global_err ? EXIT_FAILURE : EXIT_SUCCESS;
+ }
+Index: zynaddsubfx/rtosc/test/nested-bundles.c
+===================================================================
+--- zynaddsubfx.orig/rtosc/test/nested-bundles.c
++++ zynaddsubfx/rtosc/test/nested-bundles.c
+@@ -1,6 +1,5 @@
+-#include <stdio.h>
++#include "common.h"
+ #include <stdlib.h>
+-#include <string.h>
+ #include <rtosc/rtosc.h>
+ 
+ char buffer_a[256];
+@@ -9,122 +8,85 @@ char buffer_c[256];
+ char buffer_d[256];
+ char buffer_e[256];
+ 
+-int err = 0;
+-void check(int b, const char *msg, int loc)
+-{
+-    if(!b) {
+-        fprintf(stderr, "%s:%d\n", msg, loc);
+-        err = 1;
+-    }
+-}
++#define TIMETAG_VALUE ((uint64_t)0xdeadbeefcafebaad)
++#define BUNDLE_ARG "bund" "le\0\0"
++#define POUND_BUNDLE "#bun" "dle\0"
++#define TIMETAG "\xde\xad\xbe\xef" "\xca\xfe\xba\xad"
++#define MSG_A "/bun" "dle\0" ",s\0\0" BUNDLE_ARG
++#define MSG_B "/bun" "dle-" "bund" "le\0\0" ",ss\0" BUNDLE_ARG BUNDLE_ARG
++#define LEN_A "\0\0\0\x14"
++#define LEN_B "\0\0\0\x24"
++#define LEN_C "\0\0\0\x40"
+ 
+-#define VERB_BUNDLE \
+-good &= (*msg++ == 'b'); \
+-good &= (*msg++ == 'u'); \
+-good &= (*msg++ == 'n'); \
+-good &= (*msg++ == 'd'); \
+-good &= (*msg++ == 'l'); \
+-good &= (*msg++ == 'e');
+-
+-#define POUND_BUNDLE \
+-good = 1; \
+-good &= (*msg++ == '#'); \
+-VERB_BUNDLE \
+-good &= (*msg++ == '\0'); \
+-check(good, "bad bundle start", __LINE__);
+-
+-#define TIMETAG msg += 8;
+-
+-#define SKIP_SIZE msg += 4;
+-
+-#define MSG_A \
+-good = 1; \
+-good &= (*msg++ == '/'); \
+-VERB_BUNDLE \
+-good &= (*msg++ == '\0'); \
+-\
+-good &= (*msg++ == ','); \
+-good &= (*msg++ == 's'); \
+-good &= (*msg++ == '\0'); \
+-good &= (*msg++ == '\0'); \
+-\
+-VERB_BUNDLE \
+-good &= (*msg++ == '\0'); \
+-good &= (*msg++ == '\0'); \
+-check(good, "bad message 'A'", __LINE__);
+-
+-#define MSG_B \
+-good = 1; \
+-good &= (*msg++ == '/'); \
+-VERB_BUNDLE \
+-good &= (*msg++ == '-'); \
+-VERB_BUNDLE \
+-good &= (*msg++ == '\0'); \
+-good &= (*msg++ == '\0'); \
+-\
+-good &= (*msg++ == ','); \
+-good &= (*msg++ == 's'); \
+-good &= (*msg++ == 's'); \
+-good &= (*msg++ == '\0'); \
+-\
+-VERB_BUNDLE \
+-good &= (*msg++ == '\0'); \
+-good &= (*msg++ == '\0'); \
+-VERB_BUNDLE \
+-good &= (*msg++ == '\0'); \
+-good &= (*msg++ == '\0'); \
+-check(good, "bad message 'B'", __LINE__);
++#define BAD_SIZE "\xba\xad\xca\xfe"
+ 
+ #define BUNDLE_C \
+ POUND_BUNDLE \
+ TIMETAG \
+-SKIP_SIZE \
++LEN_A \
+ MSG_A \
+-SKIP_SIZE \
++LEN_A \
+ MSG_A
+-
++    
++#define BUNDLE_D \
++POUND_BUNDLE \
++TIMETAG \
++LEN_C \
++BUNDLE_C \
++LEN_C \
++BUNDLE_C \
++LEN_B \
++MSG_B
++
++const int La = sizeof(MSG_A)-1;
++const int Lb = sizeof(MSG_B)-1;
++const int Lc = sizeof(BUNDLE_C)-1;
++const int Ld = sizeof(BUNDLE_D)-1;
+ 
+ int main()
+ {
+-    check(rtosc_message(buffer_a, 256, "/bundle", "s", "bundle"),
+-            "bad message", __LINE__);
+-    check(rtosc_message(buffer_b, 256, "/bundle-bundle", "ss", "bundle", "bundle"),
+-            "bad message", __LINE__);
+-    int len;
+-    check(rtosc_bundle(buffer_c, 256, 0, 2, buffer_a, buffer_a) == 64,
+-            "bad bundle", __LINE__);
+-    check(rtosc_message_length(buffer_c, 256) == 64,
+-            "bad bundle length", __LINE__);
+-    check((len = rtosc_bundle(buffer_d, 256, 0, 3, buffer_c, buffer_c, buffer_b)) == 192,
+-            "bad bundle", __LINE__);
+-    check(rtosc_message_length(buffer_d, 256) == 192,
+-            "bad bundle length", __LINE__);
+-    check(rtosc_message_length(buffer_d, len) == 192,
+-            "bad bundle length", __LINE__);
+-
+-    //now to verify the bundle
+-    const char *msg = buffer_d;
+-    int good;
+-    POUND_BUNDLE
+-    TIMETAG
+-    SKIP_SIZE
+-    BUNDLE_C
+-    SKIP_SIZE
+-    BUNDLE_C
+-    SKIP_SIZE
+-    MSG_B
++    //Message 1
++    assert_int_eq(La, rtosc_message(buffer_a, 256, "/bundle", "s", "bundle"),
++            "Create Message 1", __LINE__);
++    assert_hex_eq(MSG_A, buffer_a, La, La,
++            "Verifying Contents Of Message 1", __LINE__);
++
++    //Message 2
++    assert_int_eq(Lb, rtosc_message(buffer_b, 256, "/bundle-bundle", "ss", "bundle", "bundle"),
++            "Create Message 2", __LINE__);
++    assert_hex_eq(MSG_B, buffer_b, Lb, Lb,
++            "Verifying Contents Of Message 2", __LINE__);
+ 
+-    check(rtosc_bundle_elements(buffer_d, len) == 3,
+-            "bad bundle elements", __LINE__);
+-    
+-    check(!strcmp("bundle",
+-                rtosc_argument(rtosc_bundle_fetch(rtosc_bundle_fetch(buffer_d, 1), 1), 0).s),
+-            "bad data retreival", __LINE__);
++    int len;
++    //Bundle 1
++    assert_int_eq(64, rtosc_bundle(buffer_c, 256, TIMETAG_VALUE, 2, buffer_a, buffer_a),
++            "Create Bundle 1", __LINE__);
++    assert_hex_eq(BUNDLE_C, buffer_c, Lc, Lc,
++            "Verifying Bundle 1's Content", __LINE__);
++    assert_int_eq(64, rtosc_message_length(buffer_c, 256),
++            "Verify Bundle 1's Length", __LINE__);
++
++    //Bundle 2
++    assert_int_eq(192, len = rtosc_bundle(buffer_d, 256, TIMETAG_VALUE, 3, buffer_c, buffer_c, buffer_b),
++            "Create Bundle 2", __LINE__);
++    assert_hex_eq(BUNDLE_D, buffer_d, Ld, Ld,
++            "Verifying Bundle 2's Content", __LINE__);
++    assert_int_eq(192, rtosc_message_length(buffer_d, 256),
++            "Verify Bundle 2's Length", __LINE__);
++    assert_int_eq(192, rtosc_message_length(buffer_d, len),
++            "Verify Bundle 2's Length With Tight Bounds", __LINE__);
++
++
++    assert_int_eq(3, rtosc_bundle_elements(buffer_d, len),
++            "Verify Bundle 2's Subelements", __LINE__);
++    assert_str_eq("bundle", rtosc_argument(rtosc_bundle_fetch(rtosc_bundle_fetch(buffer_d, 1), 1), 0).s,
++            "Verify Nested Message's Integrety", __LINE__);
+     
+     //Verify the failure behavior when a bad length is provided
+-    check(rtosc_bundle_elements(buffer_d, len-1) == 2,
+-            "bad truncated bundle elements", __LINE__);
+-    check(rtosc_message_length(buffer_d, len-1) == 0,
+-            "bad truncated bundle length", __LINE__);
+-    return err;
++    assert_int_eq(2, rtosc_bundle_elements(buffer_d, len-1),
++            "Verify Aparent Bundles With Truncated Length", __LINE__);
++    assert_int_eq(0, rtosc_message_length(buffer_d, len-1),
++            "Verify Bad Message Is Detected With Truncation", __LINE__);
++
++    return global_err ? EXIT_FAILURE : EXIT_SUCCESS;
+ }
+Index: zynaddsubfx/rtosc/test/common.h
+===================================================================
+--- /dev/null
++++ zynaddsubfx/rtosc/test/common.h
+@@ -0,0 +1,160 @@
++#include <stdio.h>
++#include <string.h>
++#include <ctype.h>
++#include <stdlib.h>
++
++int global_err = 0;
++int test_counter = 0;
++//expect a
++//actual b
++int assert_int_eq(int a, int b, const char *testcase, int line)
++{
++    test_counter++;
++    int err = a!=b;
++    if(err) {
++        printf("not ok %d - %s...\n", test_counter, testcase);
++        printf("# Expected %d, but observed %d instead (line %d)\n", a, b, line);
++        global_err++;
++    } else
++        printf("ok %d - %s...\n", test_counter, testcase);
++    return err;
++}
++
++int assert_str_eq(const char *a, const char *b, const char *testcase, int line)
++{
++    test_counter++;
++    int err = strcmp(a,b);
++    if(err) {
++        printf("not ok %d - %s...\n", test_counter, testcase);
++        printf("# Expected '%s', but observed '%s' instead (line %d)\n", a, b, line);
++        global_err++;
++    } else
++        printf("ok %d - %s...\n", test_counter, testcase);
++    return err;
++}
++
++int assert_non_null(void *v, const char *testcase, int line)
++{
++    test_counter++;
++    int err = !v;
++    if(err) {
++        printf("not ok %d - %s...\n", test_counter, testcase);
++        printf("# Expected Non-NULL value, but observed NULL instead (line %d)\n", line);
++        global_err++;
++    } else
++        printf("ok %d - %s...\n", test_counter, testcase);
++    return err;
++}
++
++int assert_f32_eq(float a, float b,const char *testcase, int line)
++{
++    test_counter++;
++    int err = a!=b;
++    if(err) {
++        printf("not ok %d - %s...\n", test_counter, testcase);
++        printf("# Expected %f, but observed %f instead (line %d)\n", a, b, line);
++        global_err++;
++    } else
++        printf("ok %d - %s...\n", test_counter, testcase);
++    return err;
++}
++
++//produce a xxd style hexdump with sections highlighted using escape sequences
++//
++//e.g.
++//0000000: 2369 6e63 6c75 6465 203c 7374 6469 6f2e  #include <stdio.
++//0000010: 683e 0a23 696e 636c 7564 6520 3c73 7472  h>.#include <str
++//0000020: 696e 672e 683e 0a0a 696e 7420 676c 6f62  ing.h>..int glob
++//0000030: 616c 5f65 7272 203d 2030 3b0a 696e 7420  al_err = 0;.int 
++//0000040: 7465 7374 5f63 6f75 6e74 6572 203d 2030  test_counter = 0
++//0000050: 3b0a 2f2f 6578 7065 6374 2061 0a2f 2f61  ;.//expect a.//a
++//
++void hexdump(const char *data, const char *mask, size_t len)
++{
++    const char *bold_gray = "\x1b[30;1m";
++    const char *reset      = "\x1b[0m";
++    int offset = 0;
++    while(1)
++    {
++        //print line
++        printf("#%07x: ", offset);
++
++        int char_covered = 0;
++        
++        //print hex groups (8)
++        for(int i=0; i<8; ++i) {
++        
++            //print doublet
++            for(int j=0; j<2; ++j) {
++                int loffset = offset + 2*i + j;
++                if(loffset >= (int)len)
++                    goto escape;
++        
++                //print hex
++                {
++                    //start highlight
++                    if(mask && mask[loffset]){printf("%s", bold_gray);}
++
++                    //print chars
++                    printf("%02x", 0xff&data[loffset]);
++                    
++                    //end highlight
++                    if(mask && mask[loffset]){printf("%s", reset);}
++                    char_covered += 2;
++                }
++            }
++            printf(" ");
++            char_covered += 1;
++        }
++escape:
++
++        //print filler if needed
++        for(int i=char_covered; i<41; ++i)
++            printf(" ");
++
++        //print ascii (16)
++        for(int i=0; i<16; ++i) {
++            if(isprint(data[offset+i]))
++                printf("%c", data[offset+i]);
++            else
++                printf(".");
++        }
++        printf("\n");
++        offset += 16;
++        if(offset >= len)
++            return;
++    }
++}
++
++
++int assert_hex_eq(const char *a, const char *b, size_t size_a, size_t size_b,
++                  const char *testcase, int line)
++{
++    test_counter++;
++    int err = (size_a != size_b) || memcmp(a, b, size_a);
++    if(err) {
++        printf("not ok %d - %s...\n", test_counter, testcase);
++        printf("# Error on line %d\n", line);
++        //printf("# Expected '%s', but observed '%s' instead (line %d)\n", a, b, line);
++        
++        //create difference mask
++        const int longer  = size_a > size_b ? size_a : size_b;
++        const int shorter = size_a < size_b ? size_a : size_b;
++        char mask[longer];
++        memset(mask, 0, longer);
++        for(int i=0; i<shorter; ++i)
++            if(a[i] != b[i])
++                mask[i] = 1;
++
++        printf("#\n");
++        printf("# Expected:\n");
++        hexdump(a, mask, size_a);
++        printf("#\n");
++        printf("# Observed:\n");
++        hexdump(b, mask, size_b);
++
++        global_err++;
++    } else
++        printf("ok %d - %s...\n", test_counter, testcase);
++    return err;
++}
+Index: zynaddsubfx/rtosc/include/rtosc/rtosc.h
+===================================================================
+--- zynaddsubfx.orig/rtosc/include/rtosc/rtosc.h
++++ zynaddsubfx/rtosc/include/rtosc/rtosc.h
+@@ -115,6 +115,37 @@ unsigned rtosc_narguments(const char *ms
+  */
+ char rtosc_type(const char *msg, unsigned i);
+ 
++typedef struct {
++    const char    *type_pos;
++    const uint8_t *value_pos;
++} rtosc_arg_itr_t;
++
++typedef struct {
++    char type;
++    rtosc_arg_t val;
++} rtosc_arg_val_t;
++
++/**
++ * Create an argument iterator for a message
++ * @param msg OSC message
++ * @returns an initialized iterator
++ */
++rtosc_arg_itr_t rtosc_itr_begin(const char *msg);
++
++/**
++ * Gets the next argument in a message
++ * @param itr OSC message iterator
++ * @returns a type value pair from the message
++ */
++rtosc_arg_val_t rtosc_itr_next(rtosc_arg_itr_t *itr);
++
++/**
++ * Determines if the iterator is at the end of the argument list
++ * @param itr OSC message iterator
++ * @returns 1 if there are no more elements, 0 otherwise
++ */
++int rtosc_itr_end(rtosc_arg_itr_t itr);
++
+ /**
+  * Blob data may be safely written to
+  * @param msg OSC message
diff --git a/debian/patches/series b/debian/patches/series
index a15f616..c52e199 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
 0001-no_sse_generic.patch
 0002-misspellings.patch
 03-dont_duplicate_changelog_files.patch
+04-fix_endianess.patch

-- 
zynaddsubfx packaging



More information about the pkg-multimedia-commits mailing list