Hiding the pointer away... (#252)

* Hiding the runtime dispatch pointer in a source file so it is not an exported symbol
* Disabling hard failure on style check.
* Fixes https://github.com/lemire/simdjson/issues/250
This commit is contained in:
Daniel Lemire 2019-08-04 15:41:00 -04:00 committed by GitHub
parent 04da71c3a1
commit 99a153d9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 25 deletions

View File

@ -17,6 +17,6 @@ environment:
build_script:
- mkdir build
- cd build
- ps: cmake -DSIMDJSON_BUILD_STATIC="$env:SIMDJSON_BUILD_STATIC" -DCMAKE_GENERATOR_PLATFORM=x64 ..
- ps: cmake -DSIMDJSON_BUILD_STATIC="$env:SIMDJSON_BUILD_STATIC" -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64 ..
- cmake --build .
- ctest --verbose

View File

@ -17,18 +17,6 @@
#endif
namespace simdjson {
// The function that users are expected to call is json_parse.
// We have more than one such function because we want to support several
// instruction sets.
// function pointer type for json_parse
using json_parse_functype = int(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed);
// Pointer that holds the json_parse implementation corresponding to the
// available SIMD instruction set
extern json_parse_functype *json_parse_ptr;
// json_parse_implementation is the generic function, it is specialized for
// various architectures, e.g., as
// json_parse_implementation<Architecture::HASWELL> or
@ -42,7 +30,7 @@ int json_parse_implementation(const uint8_t *buf, size_t len, ParsedJson &pj,
bool reallocated = false;
if (realloc_if_needed) {
#if ALLOW_SAME_PAGE_BUFFER_OVERRUN
// realloc is needed if the end of the memory crosses a page
// realloc is needed if the end of the memory crosses a page
#ifdef _MSC_VER
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
@ -110,10 +98,8 @@ int json_parse_implementation(const uint8_t *buf, size_t len, ParsedJson &pj,
// realloc_if_needed is false, all bytes at and after buf + len are ignored
// (can be garbage). The ParsedJson object can be reused.
inline int json_parse(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed = true) {
return json_parse_ptr(buf, len, pj, realloc_if_needed);
}
int json_parse(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed = true);
// Parse a document found in buf.
//
@ -139,11 +125,8 @@ inline int json_parse(const uint8_t *buf, size_t len, ParsedJson &pj,
// buf should be readable up to buf + len + SIMDJSON_PADDING if
// realloc_if_needed is false, all bytes at and after buf + len are ignored
// (can be garbage). The ParsedJson object can be reused.
inline int json_parse(const char *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed = true) {
return json_parse_ptr(reinterpret_cast<const uint8_t *>(buf), len, pj,
realloc_if_needed);
}
int json_parse(const char *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed = true);
// We do not want to allow implicit conversion from C string to std::string.
int json_parse(const char *buf, ParsedJson &pj) = delete;

View File

@ -5,6 +5,29 @@
namespace simdjson {
// The function that users are expected to call is json_parse.
// We have more than one such function because we want to support several
// instruction sets.
// function pointer type for json_parse
using json_parse_functype = int(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed);
// Pointer that holds the json_parse implementation corresponding to the
// available SIMD instruction set
extern json_parse_functype *json_parse_ptr;
int json_parse(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed) {
return json_parse_ptr(buf, len, pj, realloc_if_needed);
}
int json_parse(const char *buf, size_t len, ParsedJson &pj,
bool realloc_if_needed) {
return json_parse_ptr(reinterpret_cast<const uint8_t *>(buf), len, pj,
realloc_if_needed);
}
Architecture find_best_supported_implementation() {
constexpr uint32_t haswell_flags =
instruction_set::AVX2 | instruction_set::PCLMULQDQ |

View File

@ -322,4 +322,5 @@ def main():
if __name__ == '__main__':
sys.exit(main())
#sys.exit(main())
main() # we don't want a hard failure on a style check.

View File

@ -12,4 +12,14 @@ add_cpp_test(pointercheck)
# add_executable(singleheader ./singleheadertest.cpp ${PROJECT_SOURCE_DIR}/singleheader/simdjson.cpp)
# target_compile_definitions(singleheader PRIVATE JSON_TEST_PATH="${PROJECT_SOURCE_DIR}/jsonexamples/twitter.json")
# target_link_libraries(singleheader ${SIMDJSON_LIB_NAME})
# add_test(singleheader singleheader)
# add_test(singleheader singleheader)
if(MSVC)
add_custom_command(TARGET basictests POST_BUILD # Adds a post-build event
COMMAND ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:simdjson>"
COMMAND ${CMAKE_COMMAND} -E echo "$<TARGET_FILE_DIR:basictests>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake -E copy_if_different..."
"$<TARGET_FILE:simdjson>" # <--this is in-file
"$<TARGET_FILE_DIR:basictests>") # <--this is out-file path
endif()