Browse Source

cosmetic cleanups; use restrict where pointers don't alias

Julius Pfrommer 9 years ago
parent
commit
e1448f3685
5 changed files with 108 additions and 101 deletions
  1. 8 0
      include/ua_config.h.in
  2. 46 34
      include/ua_types.h
  3. 52 57
      src/ua_types.c
  4. 2 3
      src/ua_types_encoding_binary.c
  5. 0 7
      src/ua_util.h

+ 8 - 0
include/ua_config.h.in

@@ -75,4 +75,12 @@
 # define UA_INLINE inline
 #endif
 
+/* Define non-aliasing pointers */
+#ifdef _MSC_VER
+# define UA_RESTRICT __restrict
+#else
+# define UA_RESTRICT restrict
+#endif
+
+
 #endif /* UA_CONFIG_H_ */

+ 46 - 34
include/ua_types.h

@@ -240,77 +240,88 @@ UA_Boolean UA_EXPORT * UA_Boolean_new(void);
 static UA_INLINE void UA_Boolean_init(UA_Boolean *p) { *p = UA_FALSE; }
 void UA_EXPORT UA_Boolean_delete(UA_Boolean *p);
 static UA_INLINE void UA_Boolean_deleteMembers(UA_Boolean *p) { }
-static UA_INLINE UA_StatusCode UA_Boolean_copy(const UA_Boolean *src, UA_Boolean *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Boolean_copy(const UA_Boolean *src, UA_Boolean *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* SByte */
 UA_SByte UA_EXPORT * UA_SByte_new(void);
 static UA_INLINE void UA_SByte_init(UA_SByte *p) { *p = 0; }
 void UA_EXPORT UA_SByte_delete(UA_SByte *p);
 static UA_INLINE void UA_SByte_deleteMembers(UA_SByte *p) { }
-static UA_INLINE UA_StatusCode UA_SByte_copy(const UA_SByte *src, UA_SByte *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_SByte_copy(const UA_SByte *src, UA_SByte *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* Byte */
 UA_Byte UA_EXPORT * UA_Byte_new(void);
 static UA_INLINE void UA_Byte_init(UA_Byte *p) { *p = 0; }
 void UA_EXPORT UA_Byte_delete(UA_Byte *p);
 static UA_INLINE void UA_Byte_deleteMembers(UA_Byte *p) { }
-static UA_INLINE UA_StatusCode UA_Byte_copy(const UA_Byte *src, UA_Byte *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Byte_copy(const UA_Byte *src, UA_Byte *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* Int16 */
 UA_Int16 UA_EXPORT * UA_Int16_new(void);
 static UA_INLINE void UA_Int16_init(UA_Int16 *p) { *p = 0; }
 void UA_EXPORT UA_Int16_delete(UA_Int16 *p);
 static UA_INLINE void UA_Int16_deleteMembers(UA_Int16 *p) { }
-static UA_INLINE UA_StatusCode UA_Int16_copy(const UA_Int16 *src, UA_Int16 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Int16_copy(const UA_Int16 *src, UA_Int16 *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* UInt16 */
 UA_UInt16 UA_EXPORT * UA_UInt16_new(void);
 static UA_INLINE void UA_UInt16_init(UA_UInt16 *p) { *p = 0; }
 void UA_EXPORT UA_UInt16_delete(UA_UInt16 *p);
 static UA_INLINE void UA_UInt16_deleteMembers(UA_UInt16 *p) { }
-static UA_INLINE UA_StatusCode UA_UInt16_copy(const UA_UInt16 *src, UA_UInt16 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_UInt16_copy(const UA_UInt16 *src, UA_UInt16 *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* Int32 */
 UA_Int32 UA_EXPORT * UA_Int32_new(void);
 static UA_INLINE void UA_Int32_init(UA_Int32 *p) { *p = 0; }
 void UA_EXPORT UA_Int32_delete(UA_Int32 *p);
 static UA_INLINE void UA_Int32_deleteMembers(UA_Int32 *p) { }
-static UA_INLINE UA_StatusCode UA_Int32_copy(const UA_Int32 *src, UA_Int32 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Int32_copy(const UA_Int32 *src, UA_Int32 *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* UInt32 */
 UA_UInt32 UA_EXPORT * UA_UInt32_new(void);
 static UA_INLINE void UA_UInt32_init(UA_UInt32 *p) { *p = 0; }
 void UA_EXPORT UA_UInt32_delete(UA_UInt32 *p);
 static UA_INLINE void UA_UInt32_deleteMembers(UA_UInt32 *p) { }
-static UA_INLINE UA_StatusCode UA_UInt32_copy(const UA_UInt32 *src, UA_UInt32 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_UInt32_copy(const UA_UInt32 *src, UA_UInt32 *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* Int64 */
 UA_Int64 UA_EXPORT * UA_Int64_new(void);
 static UA_INLINE void UA_Int64_init(UA_Int64 *p) { *p = 0; }
 void UA_EXPORT UA_Int64_delete(UA_Int64 *p);
 static UA_INLINE void UA_Int64_deleteMembers(UA_Int64 *p) { }
-static UA_INLINE UA_StatusCode UA_Int64_copy(const UA_Int64 *src, UA_Int64 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Int64_copy(const UA_Int64 *src, UA_Int64 *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* UInt64 */
 UA_UInt64 UA_EXPORT * UA_UInt64_new(void);
 static UA_INLINE void UA_UInt64_init(UA_UInt64 *p) { *p = 0; }
 void UA_EXPORT UA_UInt64_delete(UA_UInt64 *p);
 static UA_INLINE void UA_UInt64_deleteMembers(UA_UInt64 *p) { }
-static UA_INLINE UA_StatusCode UA_UInt64_copy(const UA_UInt64 *src, UA_UInt64 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_UInt64_copy(const UA_UInt64 *src, UA_UInt64 *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* Float */
 UA_Float UA_EXPORT * UA_Float_new(void);
 static UA_INLINE void UA_Float_init(UA_Float *p) { *p = 0.0f; }
 void UA_EXPORT UA_Float_delete(UA_Float *p);
 static UA_INLINE void UA_Float_deleteMembers(UA_Float *p) { }
-static UA_INLINE UA_StatusCode UA_Float_copy(const UA_Float *src, UA_Float *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Float_copy(const UA_Float *src, UA_Float *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* Double */
 UA_Double UA_EXPORT * UA_Double_new(void);
 static UA_INLINE void UA_Double_init(UA_Double *p) { *p = 0.0f; }
 void UA_EXPORT UA_Double_delete(UA_Double *p);
 static UA_INLINE void UA_Double_deleteMembers(UA_Double *p) { }
-static UA_INLINE UA_StatusCode UA_Double_copy(const UA_Double *src, UA_Double *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Double_copy(const UA_Double *src, UA_Double *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 
 /* String */
 UA_String UA_EXPORT * UA_String_new(void);
@@ -334,7 +345,8 @@ UA_DateTime UA_EXPORT * UA_DateTime_new(void);
 static UA_INLINE void UA_DateTime_init(UA_DateTime *p) { *p = (UA_DateTime)0.0f; }
 void UA_EXPORT UA_DateTime_delete(UA_DateTime *p);
 static UA_INLINE void UA_DateTime_deleteMembers(UA_DateTime *p) { }
-static UA_INLINE UA_StatusCode UA_DateTime_copy(const UA_DateTime *src, UA_DateTime *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_DateTime_copy(const UA_DateTime *src, UA_DateTime *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 UA_DateTime UA_EXPORT UA_DateTime_now(void); ///> The current time
 UA_StatusCode UA_EXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
 
@@ -357,7 +369,8 @@ UA_Guid UA_EXPORT * UA_Guid_new(void);
 static UA_INLINE void UA_Guid_init(UA_Guid *p) { memset(p, 0, sizeof(UA_Guid)); }
 void UA_EXPORT UA_Guid_delete(UA_Guid *p);
 static UA_INLINE void UA_Guid_deleteMembers(UA_Guid *p) { }
-static UA_INLINE UA_StatusCode UA_Guid_copy(const UA_Guid *src, UA_Guid *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
+static UA_INLINE UA_StatusCode UA_Guid_copy(const UA_Guid *src, UA_Guid *dst) {
+    *dst = *src; return UA_STATUSCODE_GOOD; }
 UA_Boolean UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
 UA_Guid UA_EXPORT UA_Guid_random(UA_UInt32 *seed); ///> Do not use for security-critical entropy!
 
@@ -567,7 +580,7 @@ UA_Boolean UA_EXPORT UA_Variant_isScalar(const UA_Variant *v);
  * @param type The datatype of the value in question
  * @return Indicates whether the operation succeeded or returns an error code
  */
-UA_StatusCode UA_EXPORT UA_Variant_setScalar(UA_Variant *v, void *p, const UA_DataType *type);
+UA_StatusCode UA_EXPORT UA_Variant_setScalar(UA_Variant *v, void * UA_RESTRICT p, const UA_DataType *type);
 
 /**
  * Set the variant to a scalar value that is copied from an existing variable.
@@ -590,7 +603,7 @@ UA_StatusCode UA_EXPORT UA_Variant_setScalarCopy(UA_Variant *v, const void *p, c
  * @return Indicates whether the operation succeeded or returns an error code
  */
 UA_StatusCode UA_EXPORT
-UA_Variant_setArray(UA_Variant *v, void *array, UA_Int32 elements, const UA_DataType *type);
+UA_Variant_setArray(UA_Variant *v, void * UA_RESTRICT array, UA_Int32 elements, const UA_DataType *type);
 
 /**
  * Set the variant to an array that is copied from an existing array.
@@ -628,7 +641,8 @@ UA_Variant_copyRange(const UA_Variant *src, UA_Variant *dst, const UA_NumericRan
  * @return Returns UA_STATUSCODE_GOOD or an error code
  */
 UA_StatusCode UA_EXPORT
-UA_Variant_setRange(UA_Variant *v, void *dataArray, UA_Int32 dataArraySize, const UA_NumericRange range);
+UA_Variant_setRange(UA_Variant *v, void * UA_RESTRICT dataArray,
+                    UA_Int32 dataArraySize, const UA_NumericRange range);
 
 /**
  * Deep-copy a range of data into an existing variant.
@@ -696,18 +710,18 @@ struct UA_DataType {
 /**
  * Allocates and initializes a variable of type dataType
  *
- * @param dataType The datatype description
+ * @param type The datatype description
  * @return Returns the memory location of the variable or (void*)0 if no memory is available
  */
-void UA_EXPORT * UA_new(const UA_DataType *dataType);
+void UA_EXPORT * UA_new(const UA_DataType *type);
 
 /**
  * Initializes a variable to default values
  *
  * @param p The memory location of the variable
- * @param dataType The datatype description
+ * @param type The datatype description
  */
-void UA_EXPORT UA_init(void *p, const UA_DataType *dataType);
+void UA_EXPORT UA_init(void *p, const UA_DataType *type);
 
 /**
  * Copies the content of two variables. If copying fails (e.g. because no memory was available for
@@ -715,10 +729,10 @@ void UA_EXPORT UA_init(void *p, const UA_DataType *dataType);
  *
  * @param src The memory location of the source variable
  * @param dst The memory location of the destination variable
- * @param dataType The datatype description
+ * @param type The datatype description
  * @return Indicates whether the operation succeeded or returns an error code
  */
-UA_StatusCode UA_EXPORT UA_copy(const void *src, void *dst, const UA_DataType *dataType);
+UA_StatusCode UA_EXPORT UA_copy(const void *src, void *dst, const UA_DataType *type);
 
 /**
  * Deletes the dynamically assigned content of a variable (e.g. a member-array). Afterwards, the
@@ -726,19 +740,17 @@ UA_StatusCode UA_EXPORT UA_copy(const void *src, void *dst, const UA_DataType *d
  * and may contain old data that is not memory-relevant.
  *
  * @param p The memory location of the variable
- * @param dataType The datatype description of the variable
+ * @param type The datatype description of the variable
  */
-void UA_EXPORT UA_deleteMembers(void *p, const UA_DataType *dataType);
-
-void UA_EXPORT UA_deleteMembersUntil(void *p, const UA_DataType *dataType, size_t lastMember);
+void UA_EXPORT UA_deleteMembers(void *p, const UA_DataType *type);
 
 /**
  * Deletes (frees) a variable and all of its content.
  *
  * @param p The memory location of the variable
- * @param dataType The datatype description of the variable
+ * @param type The datatype description of the variable
  */
-void UA_EXPORT UA_delete(void *p, const UA_DataType *dataType);
+void UA_EXPORT UA_delete(void *p, const UA_DataType *type);
 
 /********************/
 /* Array operations */
@@ -749,31 +761,31 @@ void UA_EXPORT UA_delete(void *p, const UA_DataType *dataType);
 /**
  * Allocates and initializes an array of variables of a specific type
  *
- * @param dataType The datatype description
+ * @param type The datatype description
  * @param elements The number of elements in the array
  * @return Returns the memory location of the variable or (void*)0 if no memory could be allocated
  */
-void UA_EXPORT * UA_Array_new(const UA_DataType *dataType, UA_Int32 elements);
+void UA_EXPORT * UA_Array_new(const UA_DataType *type, UA_Int32 elements);
 
 /**
  * Allocates and copies an array. dst is set to (void*)0 if not enough memory is available.
  *
  * @param src The memory location of the source array
  * @param dst The memory location where the pointer to the destination array is written
- * @param dataType The datatype of the array members
+ * @param type The datatype of the array members
  * @param elements The size of the array
  * @return Indicates whether the operation succeeded or returns an error code
  */
-UA_StatusCode UA_EXPORT UA_Array_copy(const void *src, void **dst, const UA_DataType *dataType, UA_Int32 elements);
+UA_StatusCode UA_EXPORT UA_Array_copy(const void *src, void **dst, const UA_DataType *type, UA_Int32 elements);
 
 /**
  * Deletes an array.
  *
  * @param p The memory location of the array
- * @param dataType The datatype of the array members
+ * @param type The datatype of the array members
  * @param elements The size of the array
  */
-void UA_EXPORT UA_Array_delete(void *p, const UA_DataType *dataType, UA_Int32 elements);
+void UA_EXPORT UA_Array_delete(void *p, const UA_DataType *type, UA_Int32 elements);
 
 /**********************/
 /* Node Attribute Ids */

+ 52 - 57
src/ua_types.c

@@ -678,8 +678,8 @@ UA_StatusCode UA_Variant_copyRange(const UA_Variant *src, UA_Variant *dst, const
     return UA_STATUSCODE_GOOD;
 }
 
-UA_StatusCode UA_Variant_setRange(UA_Variant *v, void *dataArray, UA_Int32 dataArraySize,
-                                  const UA_NumericRange range) {
+UA_StatusCode UA_Variant_setRange(UA_Variant *v, void * UA_RESTRICT dataArray,
+                                  UA_Int32 dataArraySize, const UA_NumericRange range) {
     size_t count, block_size, block_distance, first_elem;
     UA_StatusCode retval = testRangeWithVariant(v, range, &count, &block_size, &block_distance, &first_elem);
     if(retval != UA_STATUSCODE_GOOD)
@@ -739,7 +739,7 @@ UA_StatusCode UA_EXPORT UA_Variant_setRangeCopy(UA_Variant *v, const void *dataA
     return UA_STATUSCODE_GOOD;
 }
 
-UA_StatusCode UA_Variant_setScalar(UA_Variant *v, void *p, const UA_DataType *type) {
+UA_StatusCode UA_Variant_setScalar(UA_Variant *v, void * UA_RESTRICT p, const UA_DataType *type) {
     return UA_Variant_setArray(v, p, -1, type);
 }
 
@@ -755,7 +755,7 @@ UA_StatusCode UA_Variant_setScalarCopy(UA_Variant *v, const void *p, const UA_Da
     return UA_Variant_setArray(v, new, -1, type);
 }
 
-UA_StatusCode UA_Variant_setArray(UA_Variant *v, void *array, UA_Int32 elements,
+UA_StatusCode UA_Variant_setArray(UA_Variant *v, void * UA_RESTRICT array, UA_Int32 elements,
                                   const UA_DataType *type) {
     v->type = type;
     v->arrayLength = elements;
@@ -814,9 +814,9 @@ UA_StatusCode UA_DiagnosticInfo_copy(UA_DiagnosticInfo const *src, UA_Diagnostic
 /* Structure Types */
 /*******************/
 
-void UA_init(void *p, const UA_DataType *dataType) {
+void UA_init(void *p, const UA_DataType *type) {
     /* builtin types */
-    switch(dataType->typeIndex + (0x8000 * !dataType->namespaceZero)) {
+    switch(type->typeIndex + (0x8000 * !type->namespaceZero)) {
     case UA_TYPES_BOOLEAN:
     case UA_TYPES_SBYTE:
     case UA_TYPES_BYTE:
@@ -860,15 +860,15 @@ void UA_init(void *p, const UA_DataType *dataType) {
 
     /* structured types */
     uintptr_t ptr = (uintptr_t)p;
-    UA_Byte membersSize = dataType->membersSize;
+    UA_Byte membersSize = type->membersSize;
     for(size_t i = 0; i < membersSize; i++) {
-        const UA_DataTypeMember *member = &dataType->members[i];
+        const UA_DataTypeMember *member = &type->members[i];
         if(!member->isArray) {
             const UA_DataType *memberType;
             if(member->namespaceZero)
                 memberType = &UA_TYPES[member->memberTypeIndex];
             else
-                memberType = &dataType[member->memberTypeIndex - dataType->typeIndex];
+                memberType = &type[member->memberTypeIndex - type->typeIndex];
             ptr += member->padding;
             UA_init((void*)ptr, memberType);
             ptr += memberType->memSize;
@@ -882,19 +882,19 @@ void UA_init(void *p, const UA_DataType *dataType) {
     }
 }
 
-void * UA_new(const UA_DataType *dataType) {
-    void *p = UA_malloc(dataType->memSize);
+void * UA_new(const UA_DataType *type) {
+    void *p = UA_malloc(type->memSize);
     if(p)
-        UA_init(p, dataType);
+        UA_init(p, type);
     return p;
 }
 
-UA_StatusCode UA_copy(const void *src, void *dst, const UA_DataType *dataType) {
-    if(dataType->fixedSize) {
-        memcpy(dst, src, dataType->memSize);
+UA_StatusCode UA_copy(const void *src, void *dst, const UA_DataType *type) {
+    if(type->fixedSize) {
+        memcpy(dst, src, type->memSize);
         return UA_STATUSCODE_GOOD;
     }
-    switch(dataType->typeIndex + (0x8000 * !dataType->namespaceZero)) {
+    switch(type->typeIndex + (0x8000 * !type->namespaceZero)) {
     case UA_TYPES_NODEID:
         return UA_NodeId_copy((const UA_NodeId*)src, (UA_NodeId*)dst);
     case UA_TYPES_EXTENSIONOBJECT:
@@ -907,19 +907,18 @@ UA_StatusCode UA_copy(const void *src, void *dst, const UA_DataType *dataType) {
         return UA_DiagnosticInfo_copy((const UA_DiagnosticInfo*)src, (UA_DiagnosticInfo*)dst);
     }
 
-    UA_init(dst, dataType);
+    UA_init(dst, type);
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     uintptr_t ptrs = (uintptr_t)src;
     uintptr_t ptrd = (uintptr_t)dst;
-    UA_Byte membersSize = dataType->membersSize;
-    size_t i;
-    for(i = 0; i < membersSize && retval == UA_STATUSCODE_GOOD; i++) {
-        const UA_DataTypeMember *member = &dataType->members[i];
+    UA_Byte membersSize = type->membersSize;
+    for(size_t i = 0; i < membersSize && retval == UA_STATUSCODE_GOOD; i++) {
+        const UA_DataTypeMember *member = &type->members[i];
         const UA_DataType *memberType;
         if(member->namespaceZero)
             memberType = &UA_TYPES[member->memberTypeIndex];
         else
-            memberType = &dataType[member->memberTypeIndex - dataType->typeIndex];
+            memberType = &type[member->memberTypeIndex - type->typeIndex];
         if(!member->isArray) {
             ptrs += member->padding;
             ptrd += member->padding;
@@ -941,18 +940,16 @@ UA_StatusCode UA_copy(const void *src, void *dst, const UA_DataType *dataType) {
         }
     }
     if(retval != UA_STATUSCODE_GOOD)
-        UA_deleteMembersUntil(dst, dataType, i);
+        UA_deleteMembers(dst, type);
     return retval;
 }
 
-void UA_deleteMembers(void *p, const UA_DataType *dataType) {
-    UA_deleteMembersUntil(p, dataType, UA_UINT16_MAX); // lastMember is bigger than the possible member count
-}
-
-void UA_deleteMembersUntil(void *p, const UA_DataType *dataType, size_t lastMember) {
-    if(dataType->fixedSize)
+void UA_deleteMembers(void *p, const UA_DataType *type) {
+    if(type->fixedSize)
         return;
-    switch(dataType->typeIndex + (0x8000 * !dataType->namespaceZero)) {
+
+    /* builtin types */
+    switch(type->typeIndex + (0x8000 * !type->namespaceZero)) {
     case UA_TYPES_NODEID:
         UA_NodeId_deleteMembers((UA_NodeId*)p);
         return;
@@ -970,17 +967,15 @@ void UA_deleteMembersUntil(void *p, const UA_DataType *dataType, size_t lastMemb
         return;
     }
 
+    /* structured types */
     uintptr_t ptr = (uintptr_t)p;
-    size_t until = dataType->membersSize;
-    if(lastMember < until)
-        until = lastMember;
-    for(size_t i = 0; i < until; i++) {
-        const UA_DataTypeMember *member = &dataType->members[i];
+    for(size_t i = 0; i < type->membersSize; i++) {
+        const UA_DataTypeMember *member = &type->members[i];
         const UA_DataType *memberType;
         if(member->namespaceZero)
             memberType = &UA_TYPES[member->memberTypeIndex];
         else
-            memberType = &dataType[member->memberTypeIndex - dataType->typeIndex];
+            memberType = &type[member->memberTypeIndex - type->typeIndex];
         if(!member->isArray) {
             ptr += member->padding;
             UA_deleteMembers((void*)ptr, memberType);
@@ -996,8 +991,8 @@ void UA_deleteMembersUntil(void *p, const UA_DataType *dataType, size_t lastMemb
     }
 }
 
-void UA_delete(void *p, const UA_DataType *dataType) {
-    UA_deleteMembers(p, dataType);
+void UA_delete(void *p, const UA_DataType *type) {
+    UA_deleteMembers(p, type);
     UA_free(p);
 }
 
@@ -1005,36 +1000,36 @@ void UA_delete(void *p, const UA_DataType *dataType) {
 /* Array Handling */
 /******************/
 
-void* UA_Array_new(const UA_DataType *dataType, UA_Int32 elements) {
-    if((UA_Int32)dataType->memSize * elements < 0 || dataType->memSize * elements > MAX_ARRAY_SIZE )
+void* UA_Array_new(const UA_DataType *type, UA_Int32 elements) {
+    if((UA_Int32)type->memSize * elements < 0 || type->memSize * elements > MAX_ARRAY_SIZE )
         return UA_NULL;
 
-    if(dataType->fixedSize)
-        return UA_calloc(elements, dataType->memSize);
+    if(type->fixedSize)
+        return UA_calloc(elements, type->memSize);
 
-    void *p = UA_malloc(dataType->memSize * (size_t)elements);
+    void *p = UA_malloc(type->memSize * (size_t)elements);
     if(!p)
         return p;
 
     uintptr_t ptr = (uintptr_t)p;
     for(int i = 0; i<elements; i++) {
-        UA_init((void*)ptr, dataType);
-        ptr += dataType->memSize;
+        UA_init((void*)ptr, type);
+        ptr += type->memSize;
     }
     return p;
 }
 
-UA_StatusCode UA_Array_copy(const void *src, void **dst, const UA_DataType *dataType, UA_Int32 elements) {
+UA_StatusCode UA_Array_copy(const void *src, void **dst, const UA_DataType *type, UA_Int32 elements) {
     if(elements <= 0) {
         *dst = UA_NULL;
         return UA_STATUSCODE_GOOD;
     }
 
-    if(!(*dst = UA_malloc((size_t)elements * dataType->memSize)))
+    if(!(*dst = UA_malloc((size_t)elements * type->memSize)))
         return UA_STATUSCODE_BADOUTOFMEMORY;
 
-    if(dataType->fixedSize) {
-        memcpy(*dst, src, dataType->memSize * (size_t)elements);
+    if(type->fixedSize) {
+        memcpy(*dst, src, type->memSize * (size_t)elements);
         return UA_STATUSCODE_GOOD;
     }
 
@@ -1042,21 +1037,21 @@ UA_StatusCode UA_Array_copy(const void *src, void **dst, const UA_DataType *data
     uintptr_t ptrd = (uintptr_t)*dst;
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     for(int i = 0; i < elements; i++) {
-        retval |= UA_copy((void*)ptrs, (void*)ptrd, dataType);
-        ptrs += dataType->memSize;
-        ptrd += dataType->memSize;
+        retval |= UA_copy((void*)ptrs, (void*)ptrd, type);
+        ptrs += type->memSize;
+        ptrd += type->memSize;
     }
     if(retval != UA_STATUSCODE_GOOD)
-        UA_Array_delete(*dst, dataType, elements);
+        UA_Array_delete(*dst, type, elements);
     return retval;
 }
 
-void UA_Array_delete(void *p, const UA_DataType *dataType, UA_Int32 elements) {
-    if(!dataType->fixedSize) {
+void UA_Array_delete(void *p, const UA_DataType *type, UA_Int32 elements) {
+    if(!type->fixedSize) {
         uintptr_t ptr = (uintptr_t)p;
         for(UA_Int32 i = 0; i < elements; i++) {
-            UA_deleteMembers((void*)ptr, dataType);
-            ptr += dataType->memSize;
+            UA_deleteMembers((void*)ptr, type);
+            ptr += type->memSize;
         }
     }
     UA_free(p);

+ 2 - 3
src/ua_types_encoding_binary.c

@@ -1040,8 +1040,7 @@ UA_StatusCode UA_decodeBinary(const UA_ByteString *src, size_t *UA_RESTRICT offs
     uintptr_t ptr = (uintptr_t) dst;
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     UA_Byte membersSize = dataType->membersSize;
-    size_t i = 0;
-    for(i = 0; i < membersSize && retval == UA_STATUSCODE_GOOD; i++) {
+    for(size_t i = 0; i < membersSize && retval == UA_STATUSCODE_GOOD; i++) {
         const UA_DataTypeMember *member = &dataType->members[i];
         const UA_DataType *memberType;
         if(member->namespaceZero)
@@ -1068,7 +1067,7 @@ UA_StatusCode UA_decodeBinary(const UA_ByteString *src, size_t *UA_RESTRICT offs
         }
     }
     if(retval != UA_STATUSCODE_GOOD)
-        UA_deleteMembersUntil(dst, dataType, i);
+        UA_deleteMembers(dst, dataType);
     return retval;
 }
 

+ 0 - 7
src/ua_util.h

@@ -15,13 +15,6 @@
 # include <malloc.h>
 #endif
 
-/* Visual Studio needs __restrict */
-#ifdef _MSC_VER
-# define UA_RESTRICT __restrict
-#else
-# define UA_RESTRICT restrict
-#endif
-
 /* Visual Studio does not know fnct/unistd file access results */
 #ifdef _MSC_VER
     #ifndef R_OK