Explorar o código

simplify decoding

Julius Pfrommer %!s(int64=10) %!d(string=hai) anos
pai
achega
b1a8c01209
Modificáronse 3 ficheiros con 7 adicións e 7 borrados
  1. 1 1
      src/ua_types.c
  2. 1 1
      tests/check_memory.c
  3. 5 5
      tools/generate_builtin.py

+ 1 - 1
src/ua_types.c

@@ -331,7 +331,7 @@ UA_Int32 UA_Guid_init(UA_Guid *p) {
 	p->data1 = 0;
 	p->data2 = 0;
 	p->data3 = 0;
-	memset(p->data4, 8, sizeof(UA_Byte));
+	memset(p->data4, 0, sizeof(UA_Byte)*8);
 	return UA_SUCCESS;
 }
 

+ 1 - 1
tests/check_memory.c

@@ -57,7 +57,7 @@ START_TEST(encodeShallYieldDecode) {
 	UA_Int32      retval;
 	UA_UInt32     pos = 0;
 	retval = UA_.types[_i].new(&obj1);
-	UA_ByteString_newMembers(&msg1, UA_.types[_i].encodings[0].calcSize(obj1));
+	UA_ByteString_newMembers(&msg1, UA_.types[_i].encodings[UA_ENCODING_BINARY].calcSize(obj1));
 	retval |= UA_.types[_i].encodings[UA_ENCODING_BINARY].encode(obj1, &msg1, &pos);
 	if(retval != UA_SUCCESS) {
 		// this happens, e.g. when we encode a variant (with UA_.types[UA_INVALIDTYPE] in the vtable)

+ 5 - 5
tools/generate_builtin.py

@@ -178,12 +178,12 @@ def createStructured(element):
     printc('\t'+name+'_init(dst);')
     for n,t in membermap.iteritems():
         if t.find("*") != -1:
-            printc('\tCHECKED_DECODE(UA_Int32_decodeBinary(src,offset,&dst->%(n)sSize),' +
-                   '%(name)s_deleteMembers(dst));')
-            printc('\tCHECKED_DECODE(UA_Array_decodeBinary(src,offset,dst->%(n)sSize,&UA_.types[' +
-                   t[0:t.find("*")].upper() + '],(void**)&dst->%(n)s), %(name)s_deleteMembers(dst));')
+            printc('\tretval |= UA_Int32_decodeBinary(src,offset,&dst->%(n)sSize);')
+            printc('\tretval |= UA_Array_decodeBinary(src,offset,dst->%(n)sSize,&UA_.types[' +
+                   t[0:t.find("*")].upper() + '],(void**)&dst->%(n)s);')
+            printc('if(retval != UA_SUCCESS) { dst->%(n)sSize = -1; return retval; }') # arrays clean up internally. But the size needs to be set here for the eventual deleteMembers.
         else:
-            printc('\tCHECKED_DECODE(%(t)s_decodeBinary(src,offset,&dst->%(n)s), %(name)s_deleteMembers(dst));')
+            printc('\tretval |= %(t)s_decodeBinary(src,offset,&dst->%(n)s);')
     printc("\treturn retval;\n}\n")
 
     # 7) Xml