Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Johnny L.
    @jleeothon
    int8 a: 8
    Nifty
    Sander Mertens
    @SanderMertens
    That was a great first post.
    Johnny L.
    @jleeothon
    Hey question
    When one uses cx_declare, I understand that the function will return the existing object if it existed already. When the object could not be declared, a NULL pointer is gotten, but what if there was an existing (reference type) object that was assigned null? Like
    Point a
    a = null
    Johnny L.
    @jleeothon
    Would you get a NULL pointer as well?
    Sander Mertens
    @SanderMertens
    The example you provide is not valid. You can't assign "null" to an object.
    In C code, the equivalent of what you are trying to do in that example is:
    struct Point { ... };
    static struct Point a = NULL; // Doesn't work
    Johnny L.
    @jleeothon
    But that example is for a value type, is it the same for reference types?
    Sander Mertens
    @SanderMertens
    Yes. Objects are always assigned by value. It doesn't make sense to assign them by reference because they ARE the things that one can refer to.
    Consider the following

    in cortex scripting (Point is a reference type):

    Point p: 10, 20
    Point q: 30, 40
    p = q

    Even though p and q are of a reference type, clearly they have to be assigned by value. I can still resolve 'p' after running this script. q did not 'magically' replace p here.

    Johnny L.
    @jleeothon
    Okay! I wasn’t sure. I remember some nuances about assignments with reference types, i.e. the value is copied, the reference is not replaced.
    Sander Mertens
    @SanderMertens
    Yes. The easiest way to remember is that objects are always assigned by value.
    Johnny L.
    @jleeothon
    How do I get the size of a type? E.g. cx_typeof(int64object)->size(?) == 8
    Oh, wait; maybe I don’t need that
    Sander Mertens
    @SanderMertens
    No, you won't need that.
    I'm not sure what you're trying to do, but pretty confident you won't need it :p
    Johnny L.
    @jleeothon
    (lldb) up
    frame #5: 0x00000001004c443a libtest.so`test_Suite_assertEqual_any_any(_this=0x000000010061e688, a=cx_any at 0x00007fff5fbfe1c0, b=cx_any at 0x00007fff5fbfe1d8) + 90 at test_Suite.c:48
       45      /* ::cortex::test::Suite::assertEqual(any a,any b) */
       46      cx_bool test_Suite_assertEqual_any_any(test_Suite _this, cx_any a, cx_any b) {
       47      /* $begin(::cortex::test::Suite::assertEqual(any a,any b)) */
    -> 48          return test_Suite_assertEqual_any_any_string(_this, a, b, NULL);
       49      /* $end */
       50      }
       51      
    (lldb) down
    frame #4: 0x00000001004c44b1 libtest.so`test_Suite_assertEqual_any_any_string(_this=0x000000010061e688, a=cx_any at 0x00007fff5fbfe170, b=cx_any at 0x00007fff5fbfe188, errmsg=0x0000000000000000) + 97 at test_Suite.c:61
       58          cx_string aS, bS;
       59          char *assertmsg;
       60          int length;
    -> 61          eq = cx_type_compare(a, b);
       62          cx_valueValueInit(&aV, NULL, a.type, a.value);
       63          cx_valueValueInit(&bV, NULL, b.type, b.value);
       64          aS = cx_valueToString(&aV, 0);
    (lldb) p a
    (cx_any) $10 = {
      type = 0x00000001000c0440
      value = 0x00000001004dd855
      owner = '\0'
    }
    (lldb) p b
    (cx_any) $11 = {
      type = 0x00000001000c0440
      value = 0x000000010061ffb0
      owner = '\0'
    }
    For some reason, cx_type_compare fails, but I’d understand that both any’s have the same type… it’s literally the same memory address.
    Sander Mertens
    @SanderMertens
    It'd be good to know where exactly the code crashes, and what you're feeding into it (can you print the names of the objects and types?)
    Johnny L.
    @jleeothon
    Yes; they have the same type and equivalent values; I wonder what could fail :/
    This is a fuller stack:
    triton:test JohnnyLee$ lldb cxsh
    (lldb) target create "cxsh"
    Current executable set to 'cxsh' (x86_64).
    (lldb) run ~/cortex/testrunner.cx ./bin/libtestjson.so
    Process 12686 launched: '/Users/JohnnyLee/cortex/bin/cxsh' (x86_64)
    cortex shell - type 'help' for instructions.
    Process 12686 stopped
    * thread #1: tid = 0xaa659, 0x00007fff9521eb13 libsystem_platform.dylib`_platform_strcmp + 19, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
        frame #0: 0x00007fff9521eb13 libsystem_platform.dylib`_platform_strcmp + 19
    libsystem_platform.dylib`_platform_strcmp + 19:
    -> 0x7fff9521eb13:  movzbq (%rdi), %rax
       0x7fff9521eb17:  movzbq (%rsi), %r8
       0x7fff9521eb1b:  incq   %rdi
       0x7fff9521eb1e:  incq   %rsi
    (lldb) up
    frame #1: 0x0000000100027590 libcortex.so`cx_ser_primitive(s=0x00007fff5fbfdf70, info=0x00007fff5fbfdf38, userData=0x00007fff5fbfe010) + 2256 at cx_compare_ser.c:100
       97                  cx_string thisStr = *(cx_string*)_this;
       98                  cx_string valueStr = *(cx_string*)value;
       99                  if (thisStr && valueStr) {
    -> 100                     result = strcmp(thisStr, valueStr);
       101                 } else {
       102                     result = !(thisStr == valueStr);
       103                 }
    (lldb) p thisStr
    (cx_string) $0 = 0x747365743a3a0061 ""
    (lldb) p valueStr
    (cx_string) $1 = 0x0000000000000061 ""
    (lldb) up
    frame #2: 0x000000010005a693 libcortex.so`cx_serializeValue(_this=0x00007fff5fbfdf70, info=0x00007fff5fbfdf38, userData=0x00007fff5fbfe010) + 307 at cx_serializer.c:60
       57      
       58          result = 0;
       59          if (cb) {
    -> 60              result = cb(_this, info, userData);
       61          }
       62      
       63          return result;
    (lldb) up
    frame #3: 0x000000010005fa1c libcortex.so`cx_type_compare(_this=cx_any at 0x00007fff5fbfe070, value=cx_any at 0x00007fff5fbfe088) + 300 at cx_type.c:110
       107         
       108         s = cx_compare_ser(CX_PRIVATE, CX_NOT, CX_SERIALIZER_TRACE_NEVER);
       109     
    -> 110         cx_serializeValue(&s, &v1, &data);
       111     
       112         return data.result;
       113     /* $end */
    (lldb) up
    frame #4: 0x00000001004c4491 libtest.so`test_Suite_assertEqual_any_any_string(_this=0x0000000100271118, a=cx_any at 0x00007fff5fbfe170, b=cx_any at 0x00007fff5fbfe188, errmsg=0x0000000000000000) + 97 at test_Suite.c:61
       58          cx_string aS, bS;
       59          char *assertmsg;
       60          int length;
    -> 61          eq = cx_type_compare(a, b);
       62          cx_valueValueInit(&aV, NULL, a.type, a.value);
       63          cx_valueValueInit(&bV, NULL, b.type, b.value);
       64          aS = cx_valueToString(&aV, 0);
    (lldb) p a
    (cx_any) $2 = {
      type = 0x00000001000c0440
      value = 0x00000001004dd855
      owner = '\0'
    }
    (lldb) p cx_nameof(a.type)
    (cx_string) $3 = 0x00000001000b58b7 "string"
    (lldb) p cx_nameof(b.type)
    (cx_string) $4 = 0x00000001000b58b7 "string"
    (lldb) p b
    (cx_any) $5 = {
      type = 0x00000001000c0440
      value = 0x0000000100339200
      owner = '\0'
    }
    (lldb) p (char *)a.value
    (char *) $6 = 0x00000001004dd855 "a"
    (lldb) p (char *)b.value
    (char *) $7 = 0x0000000100339200 “a”
    Sander Mertens
    @SanderMertens
    It looks like valueStr has been dereferenced one time too many (0x61 is ASCII for 'a'). Could be a bug in the compare routine.
    Sander Mertens
    @SanderMertens
    I have it reproduced!
    Sander Mertens
    @SanderMertens
    I may have found the issue. You might want to check the code that is providing the input for this function.
    The 'value' of an any must be an address to the value, not the actual value.
    So if you'd say, myAny.value = "a", that would fail.
    But myAny.value = &someString is ok.
    Johnny L.
    @jleeothon
    That worked! Thank you!
    Johnny L.
    @jleeothon
    Okay, so this is sufficiently not urgent, but since I’m already working with it maybe I can change it: what should be the prefix for JSON? It’s currently cx_json_ for public functions/structs and no prefix for static ones. But I believe it should be json_ athward?
    Johnny L.
    @jleeothon
    triton:test JohnnyLee$ cxsh ~/cortex/testrunner.cx ./bin/libtestjson.so 
    cortex shell - type 'help' for instructions.
    testing name
    testing parent
    testing type
    failure: testUint8() - int8 != int16
    Segmentation fault: 11
    triton:test JohnnyLee$ cxsh ~/cortex/testrunner.cx ./bin/libtestjson.so 
    cortex shell - type 'help' for instructions.
    testing name
    testing parent
    testing type
    failure: testUint8() - int8 != int16
    Segmentation fault: 11
    triton:test JohnnyLee$ cxsh ~/cortex/testrunner.cx ./bin/libtestjson.so 
    cortex shell - type 'help' for instructions.
    testing name
    testing parent
    testing type
    failure: testUint8() - int8 != int16
    success: testMaxInt16()
    success: testMaxInt32()
    success: testMaxInt64()
    success: testMaxInt8()
    success: testMinInt16()
    success: testMinInt32()
    success: testMinInt64()
    success: testMinInt8()
    success: testNegInt16()
    success: testNegInt32()
    success: testNegInt64()
    success: testNegInt8()
    success: testPosInt16()
    success: testPosInt32()
    success: testPosInt64()
    success: testPosInt8()
    success: testZeroInt16()
    success: testZeroInt32()
    success: testZeroInt64()
    success: testZeroInt8()
    success: testAlpha()
    success: testEmpty()
    success: testEscaped()
    success: testNum()
    success: testPunctuation()
    success: testMaxUint16()
    success: testMaxUint32()
    success: testMaxUint64()
    success: testMaxUint8()
    success: testPosUint16()
    success: testPosUint32()
    success: testPosUint64()
    success: testPosUint8()
    success: testZeroUint16()
    success: testZeroUint32()
    success: testZeroUint64()
    success: testZeroUint8()
    :: $
    Btw my computer is Triton because I was reading too much Percy Jackson and the Olympians at the time
    Gopalakrishna Palem
    @KrishnaPG
    I am trying to understand the Corto by following the tutorials. I have few questions based on practical usage in IOT context (and may sound completely off track) - would be great if some one could help clarify.
    The first and foremost is: is it possible to have different syntax for the data specification (ref: https://www.corto.io/tutorial_3_2.html)
    One of the key success factors for any new system, as you might already, is not how new its syntax is, rather how well it gels with old / traditional techniques.
    For example, how easy / difficult it is to specify my store object in JSON?
    Almost all systems we use in practice today in the industry (for IOT and M2M) rely on JSON for specification (or atleast consolidating towards using JSON).
    Gopalakrishna Palem
    @KrishnaPG
    Is Corto's code-generation system capable of handling such different syntax? Say, a JSON to C generator (either static generator or dynamic serdeclasses)
    Sander Mertens
    @SanderMertens
    @KrishnaPG it is very easy to use JSON with Corto
    If you have an existing object you can use this function: char* str = corto_contentof(NULL, "text/json", obj)
    You can also set the value in JSON, with the corto_fromcontent function:
    corto_fromcontent(o, "text/json", "{\"x\":10,\"y\":20}");
    You can also use the corto_select function to request data from the object store, and specify JSON as the contentType. For example:
    Sander Mertens
    @SanderMertens
    To select all objects from the store, and get the values in JSON:
    corto_resultIter iter;
    corto_select(NULL, "//*").contentType("text/json").iter(&iter);
    corto_resultIterForeach(iter, r) {
        printf("id = %s, type = %s, value = %s\n",
            r.id, r.type, corto_resultGetText(&r));
    }
    Note that JSON is just one possible encoding. The corto framework makes it very easy to create your own encodings (for example, the cortoproject/influxdb repository has an encoding for the influxdb line format).
    For more information on the corto_select function: https://corto.io/doc/api.html#Queries_corto_select