These are chat archives for cortoproject/corto

7th
Jul 2015
Sander Mertens
@SanderMertens
Jul 07 2015 00:57
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
Jul 07 2015 01:47
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
Jul 07 2015 04:31
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
Jul 07 2015 04:46
I have it reproduced!
Sander Mertens
@SanderMertens
Jul 07 2015 04:56
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
Jul 07 2015 14:36
That worked! Thank you!
Johnny L.
@jleeothon
Jul 07 2015 21:32
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?