浏览代码

Merge branch '0.2' into feature/add_spec_file_1

Stefan Profanter 7 年之前
父节点
当前提交
c93462f026
共有 6 个文件被更改,包括 45 次插入40 次删除
  1. 3 3
      CMakeLists.txt
  2. 10 8
      src/ua_util.h
  3. 5 1
      tests/CMakeLists.txt
  4. 1 1
      tools/amalgamate.py
  5. 22 24
      tools/generate_statuscode_descriptions.py
  6. 4 3
      tools/hex2bin.py

+ 3 - 3
CMakeLists.txt

@@ -113,7 +113,7 @@ mark_as_advanced(UA_COMPILE_AS_CXX)
 list(APPEND open62541_LIBRARIES "")
 if(NOT WIN32)
   list(APPEND open62541_LIBRARIES pthread)
-  if (NOT APPLE)
+  if(NOT APPLE AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
     list(APPEND open62541_LIBRARIES rt)
   endif()
 else()
@@ -128,8 +128,8 @@ if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
     add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat -Wno-unused-parameter
                     -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare
                     -Wmultichar -Wstrict-overflow -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes
-                    -Winit-self -Wuninitialized -Wformat-security -Wformat-nonliteral)
-    if(NOT WIN32 AND NOT CYGWIN)
+                    -Winit-self -Wformat-security -Wformat-nonliteral)
+    if(NOT WIN32 AND NOT CYGWIN AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
         add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
     endif()
 

+ 10 - 8
src/ua_util.h

@@ -19,16 +19,18 @@
     (type *)((uintptr_t)ptr - offsetof(type,member))
 
 /* Thread Local Storage */
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
-# define UA_THREAD_LOCAL _Thread_local /* C11 */
-#elif defined(__GNUC__)
-# define UA_THREAD_LOCAL __thread /* GNU extension */
-#elif defined(_MSC_VER)
-# define UA_THREAD_LOCAL __declspec(thread) /* MSVC extension */
+#ifdef UA_ENABLE_MULTITHREADING
+# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#  define UA_THREAD_LOCAL _Thread_local /* C11 */
+# elif defined(__GNUC__)
+#  define UA_THREAD_LOCAL __thread /* GNU extension */
+# elif defined(_MSC_VER)
+#  define UA_THREAD_LOCAL __declspec(thread) /* MSVC extension */
+# else
+#  error The compiler does not support thread-local variables.
+# endif
 #else
 # define UA_THREAD_LOCAL
-# warning The compiler does not allow thread-local variables. \
-  The library can be built, but will not be thread-safe.
 #endif
 
 /* Atomic Operations

+ 5 - 1
tests/CMakeLists.txt

@@ -14,6 +14,10 @@ endif()
 
 set(LIBS ${CHECK_LIBRARIES} ${open62541_LIBRARIES})
 
+if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
+  link_directories("/usr/local/lib")
+endif()
+
 # Build the plugins used for testing
 set(test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
                         ${PROJECT_SOURCE_DIR}/tests/testing_clock.c
@@ -25,7 +29,7 @@ add_library(open62541-testplugins OBJECT ${test_plugin_sources})
 add_dependencies(open62541-testplugins open62541)
 
 # Workaround some clang warnings in the uni tests
-if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
+if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND (CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang"))
     add_definitions(-Wno-sign-conversion)
 endif()
 

+ 1 - 1
tools/amalgamate.py

@@ -26,7 +26,7 @@ guard_re = re.compile("^#(?:(?:ifndef|define) [A-Z_]+_H_|endif /\* [A-Z_]+_H_ \*
 
 print ("Starting amalgamating file "+ args.outfile)
 
-file = io.open(args.outfile, 'w', encoding='utf8', errors='replace')
+file = io.open(args.outfile, 'wt', encoding='utf8', errors='replace')
 file.write(u"""/* THIS IS A SINGLE-FILE DISTRIBUTION CONCATENATED FROM THE OPEN62541 SOURCES
  * visit http://open62541.org/ for information about this software
  * Git-Revision: %s

+ 22 - 24
tools/generate_statuscode_descriptions.py

@@ -8,56 +8,54 @@ import platform
 import getpass
 import time
 import argparse
+from io import open
 
 parser = argparse.ArgumentParser()
 parser.add_argument('statuscodes', help='path/to/Opc.Ua.StatusCodes.csv')
 parser.add_argument('outfile', help='outfile w/o extension')
 args = parser.parse_args()
 
-f = open(args.statuscodes)
-input_str = f.read()
-f.close()
-input_str = input_str.replace('\r','')
-rows = map(lambda x:tuple(x.split(',')), input_str.split('\n'))
+rows = []
+with open(args.statuscodes, mode="rt") as f:
+    lines = f.readlines()
+    for l in lines:
+        rows.append(tuple(l.strip().split(',')))
 
-fc = open(args.outfile + ".c",'w')
+fc = open(args.outfile + ".c", "wt", encoding='utf8')
 def printc(string):
-    print(string, end='\n', file=fc)
+    print(string, end=u'\n', file=fc)
 
-printc('''/**********************************************************
- * '''+args.outfile+'''.hgen -- do not modify
- **********************************************************
- * Generated from '''+args.statuscodes+''' with script '''+sys.argv[0]+'''
- * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+
-       time.strftime("%Y-%m-%d %I:%M:%S")+'''
- **********************************************************/\n
+printc(u'''/**********************************************************
+ * Autogenerated -- do not modify
+ * Generated from %s with script %s
+ *********************************************************/
 
-#include "ua_types.h"''')
+#include "ua_types.h"''' % (args.statuscodes, sys.argv[0]))
 
 count = 2
 for row in rows:
     count += 1
 
-printc('''
+printc(u'''
 #ifndef UA_ENABLE_STATUSCODE_DESCRIPTIONS
 static const size_t statusCodeDescriptionsSize = 1;
 static const UA_StatusCodeDescription statusCodeDescriptions[1] = {
-{0xffffffff, \"StatusCode descriptions not available\", \"open62541 was compiled without support for statuscode descriptions\"}
+    {0xffffffff, \"StatusCode descriptions not available\", \"open62541 was compiled without support for statuscode descriptions\"}
 };
 #else
 static const size_t statusCodeDescriptionsSize = %s;
 static const UA_StatusCodeDescription statusCodeDescriptions[%i] =
 {''' % (count, count))
 
-printc(" {UA_STATUSCODE_GOOD, \"Good\", \"Success / No error\"},")
+printc(u"    {UA_STATUSCODE_GOOD, \"Good\", \"Success / No error\"},")
 for row in rows:
-    printc(" {UA_STATUSCODE_%s, \"%s\", \"%s\"}," % (row[0].upper(), row[0], row[2]))
-printc(" {0xffffffff, \"Unknown\", \"Unknown StatusCode\"},")
-printc('''\n};
-#endif''')
+    printc(u"    {UA_STATUSCODE_%s, \"%s\", \"%s\"}," % (row[0].upper(), row[0], row[2]))
+printc(u'''    {0xffffffff, \"Unknown\", \"Unknown StatusCode\"},
+};
+#endif
 
-printc('''
-const UA_StatusCodeDescription * UA_StatusCode_description(UA_StatusCode code) {
+const UA_StatusCodeDescription *
+UA_StatusCode_description(UA_StatusCode code) {
     for(size_t i = 0; i < statusCodeDescriptionsSize; ++i) {
         if(statusCodeDescriptions[i].code == code)
             return &statusCodeDescriptions[i];

+ 4 - 3
tools/hex2bin.py

@@ -4,12 +4,13 @@
 
 import sys
 import os
+from io import open
 import binascii
 import re
 
 def clean_line(string):
     comment_re = re.compile("/\*.*?\*/") # matches C-style comments /* */ at the end of a line
-    return re.sub(comment_re, "" ,string).replace(' ','').replace('\n','')
+    return re.sub(comment_re, "" ,string).replace(" ","").replace("\n","")
 
 if len(sys.argv) < 2:
     print("Usage: python hex2bin.py file1.hex file2.hex ...")
@@ -18,8 +19,8 @@ if len(sys.argv) < 2:
 filenames = sys.argv[1:]
 for f in filenames:
     bn = os.path.basename(f)
-    with open(f) as ff:
-        with open(bn[:-4] + ".bin", 'w') as out:
+    with open(f, mode="rt") as ff:
+        with open(bn[:-4] + ".bin", "wb") as out:
             lines = ff.readlines()
             for l in lines:
                 c = clean_line(l)