msvc: use the vectorcall calling convention

This requires declaring external interfaces with the cdecl
calling convention.
This commit is contained in:
Matthew Barr 2017-03-10 15:48:38 +11:00
parent 73765f1f84
commit dba2470ec9
19 changed files with 271 additions and 207 deletions

View File

@ -135,16 +135,21 @@ option(WINDOWS_ICC "Use Intel C++ Compiler on Windows, default off, requires ICC
# TODO: windows generator on cmake always uses msvc, even if we plan to build with icc # TODO: windows generator on cmake always uses msvc, even if we plan to build with icc
if(MSVC OR MSVC_IDE) if(MSVC OR MSVC_IDE)
message(STATUS "Building for Windows") message(STATUS "Building for Windows")
if (MSVC_VERSION LESS 1700) if (MSVC_VERSION LESS 1700)
message(FATAL_ERROR "The project requires C++11 features.") message(FATAL_ERROR "The project requires C++11 features.")
else() else()
if (WINDOWS_ICC) if (WINDOWS_ICC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O3 /Qstd=c99 /Qrestrict /QxHost /wd4267 /Qdiag-disable:remark") set(ARCH_C_FLAGS "/QxHost")
set(ARCH_CXX_FLAGS "/QxHost")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O3 /Qstd=c99 /Qrestrict /wd4267 /Qdiag-disable:remark")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Qstd=c++11 /Qrestrict /QxHost /wd4267 /wd4800 /Qdiag-disable:remark -DBOOST_DETAIL_NO_CONTAINER_FWD -D_SCL_SECURE_NO_WARNINGS") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Qstd=c++11 /Qrestrict /QxHost /wd4267 /wd4800 /Qdiag-disable:remark -DBOOST_DETAIL_NO_CONTAINER_FWD -D_SCL_SECURE_NO_WARNINGS")
else() else()
#TODO: don't hardcode arch # todo: change these as required
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2 /arch:AVX /wd4267") set(ARCH_C_FLAGS "/arch:AVX2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /arch:AVX /wd4244 /wd4267 /wd4800 -DBOOST_DETAIL_NO_CONTAINER_FWD -D_SCL_SECURE_NO_WARNINGS") set(ARCH_CXX_FLAGS "/arch:AVX2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2 /wd4244 /wd4267")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /wd4244 /wd4267 /wd4800 -DBOOST_DETAIL_NO_CONTAINER_FWD -D_SCL_SECURE_NO_WARNINGS")
endif() endif()
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
@ -153,6 +158,10 @@ if(MSVC OR MSVC_IDE)
set(CMAKE_C_FLAGS_DEBUG "/DNDEBUG ${CMAKE_C_FLAGS_DEBUG}") set(CMAKE_C_FLAGS_DEBUG "/DNDEBUG ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "/DNDEBUG ${CMAKE_CXX_FLAGS_DEBUG}") set(CMAKE_CXX_FLAGS_DEBUG "/DNDEBUG ${CMAKE_CXX_FLAGS_DEBUG}")
endif () endif ()
# flags only used to build hs libs
set(HS_C_FLAGS "/Gv")
set(HS_CXX_FLAGS "/Gv")
endif() endif()
else() else()
@ -454,8 +463,8 @@ endif()
# only set these after all tests are done # only set these after all tests are done
if (NOT FAT_RUNTIME) if (NOT FAT_RUNTIME)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS} ${HS_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS} ${HS_CXX_FLAGS}")
else() else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -67,7 +67,7 @@ hs_free_t normalise_free(hs_free_t f) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_set_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) { hs_error_t HS_CDECL hs_set_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) {
hs_set_database_allocator(allocfunc, freefunc); hs_set_database_allocator(allocfunc, freefunc);
hs_set_misc_allocator(allocfunc, freefunc); hs_set_misc_allocator(allocfunc, freefunc);
hs_set_stream_allocator(allocfunc, freefunc); hs_set_stream_allocator(allocfunc, freefunc);
@ -77,7 +77,8 @@ hs_error_t hs_set_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_set_database_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) { hs_error_t HS_CDECL hs_set_database_allocator(hs_alloc_t allocfunc,
hs_free_t freefunc) {
hs_database_alloc = normalise_alloc(allocfunc); hs_database_alloc = normalise_alloc(allocfunc);
hs_database_free = normalise_free(freefunc); hs_database_free = normalise_free(freefunc);
@ -85,7 +86,8 @@ hs_error_t hs_set_database_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_set_misc_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) { hs_error_t HS_CDECL hs_set_misc_allocator(hs_alloc_t allocfunc,
hs_free_t freefunc) {
hs_misc_alloc = normalise_alloc(allocfunc); hs_misc_alloc = normalise_alloc(allocfunc);
hs_misc_free = normalise_free(freefunc); hs_misc_free = normalise_free(freefunc);
@ -93,7 +95,8 @@ hs_error_t hs_set_misc_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_set_scratch_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) { hs_error_t HS_CDECL hs_set_scratch_allocator(hs_alloc_t allocfunc,
hs_free_t freefunc) {
hs_scratch_alloc = normalise_alloc(allocfunc); hs_scratch_alloc = normalise_alloc(allocfunc);
hs_scratch_free = normalise_free(freefunc); hs_scratch_free = normalise_free(freefunc);
@ -101,7 +104,8 @@ hs_error_t hs_set_scratch_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_set_stream_allocator(hs_alloc_t allocfunc, hs_free_t freefunc) { hs_error_t HS_CDECL hs_set_stream_allocator(hs_alloc_t allocfunc,
hs_free_t freefunc) {
hs_stream_alloc = normalise_alloc(allocfunc); hs_stream_alloc = normalise_alloc(allocfunc);
hs_stream_free = normalise_free(freefunc); hs_stream_free = normalise_free(freefunc);

View File

@ -49,7 +49,7 @@ int db_correctly_aligned(const void *db) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_free_database(hs_database_t *db) { hs_error_t HS_CDECL hs_free_database(hs_database_t *db) {
if (db && db->magic != HS_DB_MAGIC) { if (db && db->magic != HS_DB_MAGIC) {
return HS_INVALID; return HS_INVALID;
} }
@ -59,8 +59,8 @@ hs_error_t hs_free_database(hs_database_t *db) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_serialize_database(const hs_database_t *db, char **bytes, hs_error_t HS_CDECL hs_serialize_database(const hs_database_t *db, char **bytes,
size_t *serialized_length) { size_t *serialized_length) {
if (!db || !bytes || !serialized_length) { if (!db || !bytes || !serialized_length) {
return HS_INVALID; return HS_INVALID;
} }
@ -196,8 +196,9 @@ void db_copy_bytecode(const char *serialized, hs_database_t *db) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_deserialize_database_at(const char *bytes, const size_t length, hs_error_t HS_CDECL hs_deserialize_database_at(const char *bytes,
hs_database_t *db) { const size_t length,
hs_database_t *db) {
if (!bytes || !db) { if (!bytes || !db) {
return HS_INVALID; return HS_INVALID;
} }
@ -238,8 +239,9 @@ hs_error_t hs_deserialize_database_at(const char *bytes, const size_t length,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_deserialize_database(const char *bytes, const size_t length, hs_error_t HS_CDECL hs_deserialize_database(const char *bytes,
hs_database_t **db) { const size_t length,
hs_database_t **db) {
if (!bytes || !db) { if (!bytes || !db) {
return HS_INVALID; return HS_INVALID;
} }
@ -287,7 +289,7 @@ hs_error_t hs_deserialize_database(const char *bytes, const size_t length,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_database_size(const hs_database_t *db, size_t *size) { hs_error_t HS_CDECL hs_database_size(const hs_database_t *db, size_t *size) {
if (!size) { if (!size) {
return HS_INVALID; return HS_INVALID;
} }
@ -302,8 +304,9 @@ hs_error_t hs_database_size(const hs_database_t *db, size_t *size) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_serialized_database_size(const char *bytes, const size_t length, hs_error_t HS_CDECL hs_serialized_database_size(const char *bytes,
size_t *size) { const size_t length,
size_t *size) {
// Decode and check the header // Decode and check the header
hs_database_t header; hs_database_t header;
hs_error_t ret = db_decode_header(&bytes, length, &header); hs_error_t ret = db_decode_header(&bytes, length, &header);
@ -417,8 +420,8 @@ hs_error_t print_database_string(char **s, u32 version, const platform_t plat,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_serialized_database_info(const char *bytes, size_t length, hs_error_t HS_CDECL hs_serialized_database_info(const char *bytes,
char **info) { size_t length, char **info) {
if (!info) { if (!info) {
return HS_INVALID; return HS_INVALID;
} }
@ -437,7 +440,7 @@ hs_error_t hs_serialized_database_info(const char *bytes, size_t length,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_database_info(const hs_database_t *db, char **info) { hs_error_t HS_CDECL hs_database_info(const hs_database_t *db, char **info) {
if (!info) { if (!info) {
return HS_INVALID; return HS_INVALID;
} }

View File

@ -279,9 +279,10 @@ hs_compile_multi_int(const char *const *expressions, const unsigned *flags,
} // namespace ue2 } // namespace ue2
extern "C" HS_PUBLIC_API extern "C" HS_PUBLIC_API
hs_error_t hs_compile(const char *expression, unsigned flags, unsigned mode, hs_error_t HS_CDECL hs_compile(const char *expression, unsigned flags,
const hs_platform_info_t *platform, hs_database_t **db, unsigned mode,
hs_compile_error_t **error) { const hs_platform_info_t *platform,
hs_database_t **db, hs_compile_error_t **error) {
if (expression == nullptr) { if (expression == nullptr) {
*db = nullptr; *db = nullptr;
*error = generateCompileError("Invalid parameter: expression is NULL", *error = generateCompileError("Invalid parameter: expression is NULL",
@ -297,24 +298,25 @@ hs_error_t hs_compile(const char *expression, unsigned flags, unsigned mode,
} }
extern "C" HS_PUBLIC_API extern "C" HS_PUBLIC_API
hs_error_t hs_compile_multi(const char * const *expressions, hs_error_t HS_CDECL hs_compile_multi(const char *const *expressions,
const unsigned *flags, const unsigned *ids, const unsigned *flags, const unsigned *ids,
unsigned elements, unsigned mode, unsigned elements, unsigned mode,
const hs_platform_info_t *platform, const hs_platform_info_t *platform,
hs_database_t **db, hs_compile_error_t **error) { hs_database_t **db,
hs_compile_error_t **error) {
const hs_expr_ext * const *ext = nullptr; // unused for this call. const hs_expr_ext * const *ext = nullptr; // unused for this call.
return hs_compile_multi_int(expressions, flags, ids, ext, elements, mode, return hs_compile_multi_int(expressions, flags, ids, ext, elements, mode,
platform, db, error, Grey()); platform, db, error, Grey());
} }
extern "C" HS_PUBLIC_API extern "C" HS_PUBLIC_API
hs_error_t hs_compile_ext_multi(const char * const *expressions, hs_error_t HS_CDECL hs_compile_ext_multi(const char * const *expressions,
const unsigned *flags, const unsigned *ids, const unsigned *flags, const unsigned *ids,
const hs_expr_ext * const *ext, const hs_expr_ext * const *ext,
unsigned elements, unsigned mode, unsigned elements, unsigned mode,
const hs_platform_info_t *platform, const hs_platform_info_t *platform,
hs_database_t **db, hs_database_t **db,
hs_compile_error_t **error) { hs_compile_error_t **error) {
return hs_compile_multi_int(expressions, flags, ids, ext, elements, mode, return hs_compile_multi_int(expressions, flags, ids, ext, elements, mode,
platform, db, error, Grey()); platform, db, error, Grey());
} }
@ -419,24 +421,26 @@ hs_error_t hs_expression_info_int(const char *expression, unsigned int flags,
} }
extern "C" HS_PUBLIC_API extern "C" HS_PUBLIC_API
hs_error_t hs_expression_info(const char *expression, unsigned int flags, hs_error_t HS_CDECL hs_expression_info(const char *expression,
hs_expr_info_t **info, unsigned int flags,
hs_compile_error_t **error) { hs_expr_info_t **info,
hs_compile_error_t **error) {
return hs_expression_info_int(expression, flags, nullptr, HS_MODE_BLOCK, return hs_expression_info_int(expression, flags, nullptr, HS_MODE_BLOCK,
info, error); info, error);
} }
extern "C" HS_PUBLIC_API extern "C" HS_PUBLIC_API
hs_error_t hs_expression_ext_info(const char *expression, unsigned int flags, hs_error_t HS_CDECL hs_expression_ext_info(const char *expression,
const hs_expr_ext_t *ext, unsigned int flags,
hs_expr_info_t **info, const hs_expr_ext_t *ext,
hs_compile_error_t **error) { hs_expr_info_t **info,
hs_compile_error_t **error) {
return hs_expression_info_int(expression, flags, ext, HS_MODE_BLOCK, info, return hs_expression_info_int(expression, flags, ext, HS_MODE_BLOCK, info,
error); error);
} }
extern "C" HS_PUBLIC_API extern "C" HS_PUBLIC_API
hs_error_t hs_populate_platform(hs_platform_info_t *platform) { hs_error_t HS_CDECL hs_populate_platform(hs_platform_info_t *platform) {
if (!platform) { if (!platform) {
return HS_INVALID; return HS_INVALID;
} }
@ -450,7 +454,7 @@ hs_error_t hs_populate_platform(hs_platform_info_t *platform) {
} }
extern "C" HS_PUBLIC_API extern "C" HS_PUBLIC_API
hs_error_t hs_free_compile_error(hs_compile_error_t *error) { hs_error_t HS_CDECL hs_free_compile_error(hs_compile_error_t *error) {
#if defined(FAT_RUNTIME) #if defined(FAT_RUNTIME)
if (!check_ssse3()) { if (!check_ssse3()) {
return HS_ARCH_ERROR; return HS_ARCH_ERROR;

View File

@ -29,6 +29,11 @@
#ifndef HS_COMMON_H_ #ifndef HS_COMMON_H_
#define HS_COMMON_H_ #define HS_COMMON_H_
#if defined(_WIN32)
#define HS_CDECL __cdecl
#else
#define HS_CDECL
#endif
#include <stdlib.h> #include <stdlib.h>
/** /**
@ -76,7 +81,7 @@ typedef int hs_error_t;
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_free_database(hs_database_t *db); hs_error_t HS_CDECL hs_free_database(hs_database_t *db);
/** /**
* Serialize a pattern database to a stream of bytes. * Serialize a pattern database to a stream of bytes.
@ -100,8 +105,8 @@ hs_error_t hs_free_database(hs_database_t *db);
* @ref HS_SUCCESS on success, @ref HS_NOMEM if the byte array cannot be * @ref HS_SUCCESS on success, @ref HS_NOMEM if the byte array cannot be
* allocated, other values may be returned if errors are detected. * allocated, other values may be returned if errors are detected.
*/ */
hs_error_t hs_serialize_database(const hs_database_t *db, char **bytes, hs_error_t HS_CDECL hs_serialize_database(const hs_database_t *db, char **bytes,
size_t *length); size_t *length);
/** /**
* Reconstruct a pattern database from a stream of bytes previously generated * Reconstruct a pattern database from a stream of bytes previously generated
@ -129,8 +134,9 @@ hs_error_t hs_serialize_database(const hs_database_t *db, char **bytes,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_deserialize_database(const char *bytes, const size_t length, hs_error_t HS_CDECL hs_deserialize_database(const char *bytes,
hs_database_t **db); const size_t length,
hs_database_t **db);
/** /**
* Reconstruct a pattern database from a stream of bytes previously generated * Reconstruct a pattern database from a stream of bytes previously generated
@ -160,8 +166,9 @@ hs_error_t hs_deserialize_database(const char *bytes, const size_t length,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_deserialize_database_at(const char *bytes, const size_t length, hs_error_t HS_CDECL hs_deserialize_database_at(const char *bytes,
hs_database_t *db); const size_t length,
hs_database_t *db);
/** /**
* Provides the size of the stream state allocated by a single stream opened * Provides the size of the stream state allocated by a single stream opened
@ -177,7 +184,8 @@ hs_error_t hs_deserialize_database_at(const char *bytes, const size_t length,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_stream_size(const hs_database_t *database, size_t *stream_size); hs_error_t HS_CDECL hs_stream_size(const hs_database_t *database,
size_t *stream_size);
/** /**
* Provides the size of the given database in bytes. * Provides the size of the given database in bytes.
@ -192,8 +200,8 @@ hs_error_t hs_stream_size(const hs_database_t *database, size_t *stream_size);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_database_size(const hs_database_t *database, hs_error_t HS_CDECL hs_database_size(const hs_database_t *database,
size_t *database_size); size_t *database_size);
/** /**
* Utility function for reporting the size that would be required by a * Utility function for reporting the size that would be required by a
@ -219,8 +227,9 @@ hs_error_t hs_database_size(const hs_database_t *database,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_serialized_database_size(const char *bytes, const size_t length, hs_error_t HS_CDECL hs_serialized_database_size(const char *bytes,
size_t *deserialized_size); const size_t length,
size_t *deserialized_size);
/** /**
* Utility function providing information about a database. * Utility function providing information about a database.
@ -237,7 +246,8 @@ hs_error_t hs_serialized_database_size(const char *bytes, const size_t length,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_database_info(const hs_database_t *database, char **info); hs_error_t HS_CDECL hs_database_info(const hs_database_t *database,
char **info);
/** /**
* Utility function providing information about a serialized database. * Utility function providing information about a serialized database.
@ -258,8 +268,8 @@ hs_error_t hs_database_info(const hs_database_t *database, char **info);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_serialized_database_info(const char *bytes, size_t length, hs_error_t HS_CDECL hs_serialized_database_info(const char *bytes,
char **info); size_t length, char **info);
/** /**
* The type of the callback function that will be used by Hyperscan to allocate * The type of the callback function that will be used by Hyperscan to allocate
@ -275,7 +285,7 @@ hs_error_t hs_serialized_database_info(const char *bytes, size_t length,
* @return * @return
* A pointer to the region of memory allocated, or NULL on error. * A pointer to the region of memory allocated, or NULL on error.
*/ */
typedef void *(*hs_alloc_t)(size_t size); typedef void *(HS_CDECL *hs_alloc_t)(size_t size);
/** /**
* The type of the callback function that will be used by Hyperscan to free * The type of the callback function that will be used by Hyperscan to free
@ -284,7 +294,7 @@ typedef void *(*hs_alloc_t)(size_t size);
* @param ptr * @param ptr
* The region of memory to be freed. * The region of memory to be freed.
*/ */
typedef void (*hs_free_t)(void *ptr); typedef void (HS_CDECL *hs_free_t)(void *ptr);
/** /**
* Set the allocate and free functions used by Hyperscan for allocating * Set the allocate and free functions used by Hyperscan for allocating
@ -312,7 +322,8 @@ typedef void (*hs_free_t)(void *ptr);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_set_allocator(hs_alloc_t alloc_func, hs_free_t free_func); hs_error_t HS_CDECL hs_set_allocator(hs_alloc_t alloc_func,
hs_free_t free_func);
/** /**
* Set the allocate and free functions used by Hyperscan for allocating memory * Set the allocate and free functions used by Hyperscan for allocating memory
@ -344,8 +355,8 @@ hs_error_t hs_set_allocator(hs_alloc_t alloc_func, hs_free_t free_func);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_set_database_allocator(hs_alloc_t alloc_func, hs_error_t HS_CDECL hs_set_database_allocator(hs_alloc_t alloc_func,
hs_free_t free_func); hs_free_t free_func);
/** /**
* Set the allocate and free functions used by Hyperscan for allocating memory * Set the allocate and free functions used by Hyperscan for allocating memory
@ -371,7 +382,8 @@ hs_error_t hs_set_database_allocator(hs_alloc_t alloc_func,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_set_misc_allocator(hs_alloc_t alloc_func, hs_free_t free_func); hs_error_t HS_CDECL hs_set_misc_allocator(hs_alloc_t alloc_func,
hs_free_t free_func);
/** /**
* Set the allocate and free functions used by Hyperscan for allocating memory * Set the allocate and free functions used by Hyperscan for allocating memory
@ -397,7 +409,8 @@ hs_error_t hs_set_misc_allocator(hs_alloc_t alloc_func, hs_free_t free_func);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_set_scratch_allocator(hs_alloc_t alloc_func, hs_free_t free_func); hs_error_t HS_CDECL hs_set_scratch_allocator(hs_alloc_t alloc_func,
hs_free_t free_func);
/** /**
* Set the allocate and free functions used by Hyperscan for allocating memory * Set the allocate and free functions used by Hyperscan for allocating memory
@ -423,7 +436,8 @@ hs_error_t hs_set_scratch_allocator(hs_alloc_t alloc_func, hs_free_t free_func);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_set_stream_allocator(hs_alloc_t alloc_func, hs_free_t free_func); hs_error_t HS_CDECL hs_set_stream_allocator(hs_alloc_t alloc_func,
hs_free_t free_func);
/** /**
* Utility function for identifying this release version. * Utility function for identifying this release version.
@ -433,7 +447,7 @@ hs_error_t hs_set_stream_allocator(hs_alloc_t alloc_func, hs_free_t free_func);
* date of the build. It is allocated statically, so it does not need to * date of the build. It is allocated statically, so it does not need to
* be freed by the caller. * be freed by the caller.
*/ */
const char *hs_version(void); const char * HS_CDECL hs_version(void);
/** /**
* Utility function to test the current system architecture. * Utility function to test the current system architecture.
@ -450,7 +464,7 @@ const char *hs_version(void);
* @ref HS_SUCCESS on success, @ref HS_ARCH_ERROR if system does not * @ref HS_SUCCESS on success, @ref HS_ARCH_ERROR if system does not
* support Hyperscan. * support Hyperscan.
*/ */
hs_error_t hs_valid_platform(void); hs_error_t HS_CDECL hs_valid_platform(void);
/** /**
* @defgroup HS_ERROR hs_error_t values * @defgroup HS_ERROR hs_error_t values

View File

@ -333,9 +333,10 @@ typedef struct hs_expr_ext {
* HS_COMPILER_ERROR on failure, with details provided in the error * HS_COMPILER_ERROR on failure, with details provided in the error
* parameter. * parameter.
*/ */
hs_error_t hs_compile(const char *expression, unsigned int flags, hs_error_t HS_CDECL hs_compile(const char *expression, unsigned int flags,
unsigned int mode, const hs_platform_info_t *platform, unsigned int mode,
hs_database_t **db, hs_compile_error_t **error); const hs_platform_info_t *platform,
hs_database_t **db, hs_compile_error_t **error);
/** /**
* The multiple regular expression compiler. * The multiple regular expression compiler.
@ -411,11 +412,13 @@ hs_error_t hs_compile(const char *expression, unsigned int flags,
* parameter. * parameter.
* *
*/ */
hs_error_t hs_compile_multi(const char *const *expressions, hs_error_t HS_CDECL hs_compile_multi(const char *const *expressions,
const unsigned int *flags, const unsigned int *ids, const unsigned int *flags,
unsigned int elements, unsigned int mode, const unsigned int *ids,
const hs_platform_info_t *platform, unsigned int elements, unsigned int mode,
hs_database_t **db, hs_compile_error_t **error); const hs_platform_info_t *platform,
hs_database_t **db,
hs_compile_error_t **error);
/** /**
* The multiple regular expression compiler with extended parameter support. * The multiple regular expression compiler with extended parameter support.
@ -496,7 +499,7 @@ hs_error_t hs_compile_multi(const char *const *expressions,
* parameter. * parameter.
* *
*/ */
hs_error_t hs_compile_ext_multi(const char *const *expressions, hs_error_t HS_CDECL hs_compile_ext_multi(const char *const *expressions,
const unsigned int *flags, const unsigned int *flags,
const unsigned int *ids, const unsigned int *ids,
const hs_expr_ext_t *const *ext, const hs_expr_ext_t *const *ext,
@ -515,7 +518,7 @@ hs_error_t hs_compile_ext_multi(const char *const *expressions,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_free_compile_error(hs_compile_error_t *error); hs_error_t HS_CDECL hs_free_compile_error(hs_compile_error_t *error);
/** /**
* Utility function providing information about a regular expression. The * Utility function providing information about a regular expression. The
@ -563,9 +566,10 @@ hs_error_t hs_free_compile_error(hs_compile_error_t *error);
* HS_COMPILER_ERROR on failure, with details provided in the error * HS_COMPILER_ERROR on failure, with details provided in the error
* parameter. * parameter.
*/ */
hs_error_t hs_expression_info(const char *expression, unsigned int flags, hs_error_t HS_CDECL hs_expression_info(const char *expression,
hs_expr_info_t **info, unsigned int flags,
hs_compile_error_t **error); hs_expr_info_t **info,
hs_compile_error_t **error);
/** /**
* Utility function providing information about a regular expression, with * Utility function providing information about a regular expression, with
@ -618,10 +622,11 @@ hs_error_t hs_expression_info(const char *expression, unsigned int flags,
* HS_COMPILER_ERROR on failure, with details provided in the error * HS_COMPILER_ERROR on failure, with details provided in the error
* parameter. * parameter.
*/ */
hs_error_t hs_expression_ext_info(const char *expression, unsigned int flags, hs_error_t HS_CDECL hs_expression_ext_info(const char *expression,
const hs_expr_ext_t *ext, unsigned int flags,
hs_expr_info_t **info, const hs_expr_ext_t *ext,
hs_compile_error_t **error); hs_expr_info_t **info,
hs_compile_error_t **error);
/** /**
* Populates the platform information based on the current host. * Populates the platform information based on the current host.
@ -633,7 +638,7 @@ hs_error_t hs_expression_ext_info(const char *expression, unsigned int flags,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_populate_platform(hs_platform_info_t *platform); hs_error_t HS_CDECL hs_populate_platform(hs_platform_info_t *platform);
/** /**
* @defgroup HS_PATTERN_FLAG Pattern flags * @defgroup HS_PATTERN_FLAG Pattern flags

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -145,8 +145,8 @@ typedef int (*match_event_handler)(unsigned int id,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_open_stream(const hs_database_t *db, unsigned int flags, hs_error_t HS_CDECL hs_open_stream(const hs_database_t *db, unsigned int flags,
hs_stream_t **stream); hs_stream_t **stream);
/** /**
* Write data to be scanned to the opened stream. * Write data to be scanned to the opened stream.
@ -185,10 +185,10 @@ hs_error_t hs_open_stream(const hs_database_t *db, unsigned int flags,
* match callback indicated that scanning should stop; other values on * match callback indicated that scanning should stop; other values on
* error. * error.
*/ */
hs_error_t hs_scan_stream(hs_stream_t *id, const char *data, hs_error_t HS_CDECL hs_scan_stream(hs_stream_t *id, const char *data,
unsigned int length, unsigned int flags, unsigned int length, unsigned int flags,
hs_scratch_t *scratch, match_event_handler onEvent, hs_scratch_t *scratch,
void *ctxt); match_event_handler onEvent, void *ctxt);
/** /**
* Close a stream. * Close a stream.
@ -223,8 +223,8 @@ hs_error_t hs_scan_stream(hs_stream_t *id, const char *data,
* @return * @return
* Returns @ref HS_SUCCESS on success, other values on failure. * Returns @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch, hs_error_t HS_CDECL hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
match_event_handler onEvent, void *ctxt); match_event_handler onEvent, void *ctxt);
/** /**
* Reset a stream to an initial state. * Reset a stream to an initial state.
@ -264,9 +264,9 @@ hs_error_t hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_reset_stream(hs_stream_t *id, unsigned int flags, hs_error_t HS_CDECL hs_reset_stream(hs_stream_t *id, unsigned int flags,
hs_scratch_t *scratch, match_event_handler onEvent, hs_scratch_t *scratch,
void *context); match_event_handler onEvent, void *context);
/** /**
* Duplicate the given stream. The new stream will have the same state as the * Duplicate the given stream. The new stream will have the same state as the
@ -282,7 +282,8 @@ hs_error_t hs_reset_stream(hs_stream_t *id, unsigned int flags,
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_copy_stream(hs_stream_t **to_id, const hs_stream_t *from_id); hs_error_t HS_CDECL hs_copy_stream(hs_stream_t **to_id,
const hs_stream_t *from_id);
/** /**
* Duplicate the given 'from' stream state onto the 'to' stream. The 'to' stream * Duplicate the given 'from' stream state onto the 'to' stream. The 'to' stream
@ -314,11 +315,11 @@ hs_error_t hs_copy_stream(hs_stream_t **to_id, const hs_stream_t *from_id);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_reset_and_copy_stream(hs_stream_t *to_id, hs_error_t HS_CDECL hs_reset_and_copy_stream(hs_stream_t *to_id,
const hs_stream_t *from_id, const hs_stream_t *from_id,
hs_scratch_t *scratch, hs_scratch_t *scratch,
match_event_handler onEvent, match_event_handler onEvent,
void *context); void *context);
/** /**
* The block (non-streaming) regular expression scanner. * The block (non-streaming) regular expression scanner.
@ -355,10 +356,10 @@ hs_error_t hs_reset_and_copy_stream(hs_stream_t *to_id,
* match callback indicated that scanning should stop; other values on * match callback indicated that scanning should stop; other values on
* error. * error.
*/ */
hs_error_t hs_scan(const hs_database_t *db, const char *data, hs_error_t HS_CDECL hs_scan(const hs_database_t *db, const char *data,
unsigned int length, unsigned int flags, unsigned int length, unsigned int flags,
hs_scratch_t *scratch, match_event_handler onEvent, hs_scratch_t *scratch, match_event_handler onEvent,
void *context); void *context);
/** /**
* The vectored regular expression scanner. * The vectored regular expression scanner.
@ -398,10 +399,12 @@ hs_error_t hs_scan(const hs_database_t *db, const char *data,
* Returns @ref HS_SUCCESS on success; @ref HS_SCAN_TERMINATED if the match * Returns @ref HS_SUCCESS on success; @ref HS_SCAN_TERMINATED if the match
* callback indicated that scanning should stop; other values on error. * callback indicated that scanning should stop; other values on error.
*/ */
hs_error_t hs_scan_vector(const hs_database_t *db, const char *const *data, hs_error_t HS_CDECL hs_scan_vector(const hs_database_t *db,
const unsigned int *length, unsigned int count, const char *const *data,
unsigned int flags, hs_scratch_t *scratch, const unsigned int *length,
match_event_handler onEvent, void *context); unsigned int count, unsigned int flags,
hs_scratch_t *scratch,
match_event_handler onEvent, void *context);
/** /**
* Allocate a "scratch" space for use by Hyperscan. * Allocate a "scratch" space for use by Hyperscan.
@ -429,7 +432,8 @@ hs_error_t hs_scan_vector(const hs_database_t *db, const char *const *data,
* allocation fails. Other errors may be returned if invalid parameters * allocation fails. Other errors may be returned if invalid parameters
* are specified. * are specified.
*/ */
hs_error_t hs_alloc_scratch(const hs_database_t *db, hs_scratch_t **scratch); hs_error_t HS_CDECL hs_alloc_scratch(const hs_database_t *db,
hs_scratch_t **scratch);
/** /**
* Allocate a scratch space that is a clone of an existing scratch space. * Allocate a scratch space that is a clone of an existing scratch space.
@ -449,7 +453,8 @@ hs_error_t hs_alloc_scratch(const hs_database_t *db, hs_scratch_t **scratch);
* @ref HS_SUCCESS on success; @ref HS_NOMEM if the allocation fails. * @ref HS_SUCCESS on success; @ref HS_NOMEM if the allocation fails.
* Other errors may be returned if invalid parameters are specified. * Other errors may be returned if invalid parameters are specified.
*/ */
hs_error_t hs_clone_scratch(const hs_scratch_t *src, hs_scratch_t **dest); hs_error_t HS_CDECL hs_clone_scratch(const hs_scratch_t *src,
hs_scratch_t **dest);
/** /**
* Provides the size of the given scratch space. * Provides the size of the given scratch space.
@ -465,7 +470,8 @@ hs_error_t hs_clone_scratch(const hs_scratch_t *src, hs_scratch_t **dest);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_scratch_size(const hs_scratch_t *scratch, size_t *scratch_size); hs_error_t HS_CDECL hs_scratch_size(const hs_scratch_t *scratch,
size_t *scratch_size);
/** /**
* Free a scratch block previously allocated by @ref hs_alloc_scratch() or @ref * Free a scratch block previously allocated by @ref hs_alloc_scratch() or @ref
@ -480,7 +486,7 @@ hs_error_t hs_scratch_size(const hs_scratch_t *scratch, size_t *scratch_size);
* @return * @return
* @ref HS_SUCCESS on success, other values on failure. * @ref HS_SUCCESS on success, other values on failure.
*/ */
hs_error_t hs_free_scratch(hs_scratch_t *scratch); hs_error_t HS_CDECL hs_free_scratch(hs_scratch_t *scratch);
/** /**
* Callback 'from' return value, indicating that the start of this match was * Callback 'from' return value, indicating that the start of this match was

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Intel Corporation * Copyright (c) 2016-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -30,7 +30,7 @@
#include "util/cpuid_flags.h" #include "util/cpuid_flags.h"
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_valid_platform(void) { hs_error_t HS_CDECL hs_valid_platform(void) {
/* Hyperscan requires SSSE3, anything else is a bonus */ /* Hyperscan requires SSSE3, anything else is a bonus */
if (check_ssse3()) { if (check_ssse3()) {
return HS_SUCCESS; return HS_SUCCESS;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -31,6 +31,6 @@
#include "hs_version.h" #include "hs_version.h"
HS_PUBLIC_API HS_PUBLIC_API
const char *hs_version(void) { const char * HS_CDECL hs_version(void) {
return HS_VERSION_STRING; return HS_VERSION_STRING;
} }

View File

@ -311,9 +311,10 @@ void runSmallWriteEngine(const struct SmallWriteEngine *smwr,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_scan(const hs_database_t *db, const char *data, unsigned length, hs_error_t HS_CDECL hs_scan(const hs_database_t *db, const char *data,
unsigned flags, hs_scratch_t *scratch, unsigned length, unsigned flags,
match_event_handler onEvent, void *userCtx) { hs_scratch_t *scratch, match_event_handler onEvent,
void *userCtx) {
if (unlikely(!scratch || !data)) { if (unlikely(!scratch || !data)) {
return HS_INVALID; return HS_INVALID;
} }
@ -503,8 +504,9 @@ void init_stream(struct hs_stream *s, const struct RoseEngine *rose,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_open_stream(const hs_database_t *db, UNUSED unsigned flags, hs_error_t HS_CDECL hs_open_stream(const hs_database_t *db,
hs_stream_t **stream) { UNUSED unsigned flags,
hs_stream_t **stream) {
if (unlikely(!stream)) { if (unlikely(!stream)) {
return HS_INVALID; return HS_INVALID;
} }
@ -656,7 +658,8 @@ void report_eod_matches(hs_stream_t *id, hs_scratch_t *scratch,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_copy_stream(hs_stream_t **to_id, const hs_stream_t *from_id) { hs_error_t HS_CDECL hs_copy_stream(hs_stream_t **to_id,
const hs_stream_t *from_id) {
if (!to_id) { if (!to_id) {
return HS_INVALID; return HS_INVALID;
} }
@ -683,11 +686,11 @@ hs_error_t hs_copy_stream(hs_stream_t **to_id, const hs_stream_t *from_id) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_reset_and_copy_stream(hs_stream_t *to_id, hs_error_t HS_CDECL hs_reset_and_copy_stream(hs_stream_t *to_id,
const hs_stream_t *from_id, const hs_stream_t *from_id,
hs_scratch_t *scratch, hs_scratch_t *scratch,
match_event_handler onEvent, match_event_handler onEvent,
void *context) { void *context) {
if (!from_id || !from_id->rose) { if (!from_id || !from_id->rose) {
return HS_INVALID; return HS_INVALID;
} }
@ -906,9 +909,10 @@ hs_error_t hs_scan_stream_internal(hs_stream_t *id, const char *data,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_scan_stream(hs_stream_t *id, const char *data, unsigned length, hs_error_t HS_CDECL hs_scan_stream(hs_stream_t *id, const char *data,
unsigned flags, hs_scratch_t *scratch, unsigned length, unsigned flags,
match_event_handler onEvent, void *context) { hs_scratch_t *scratch,
match_event_handler onEvent, void *context) {
if (unlikely(!id || !scratch || !data || if (unlikely(!id || !scratch || !data ||
!validScratch(id->rose, scratch))) { !validScratch(id->rose, scratch))) {
return HS_INVALID; return HS_INVALID;
@ -924,8 +928,9 @@ hs_error_t hs_scan_stream(hs_stream_t *id, const char *data, unsigned length,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch, hs_error_t HS_CDECL hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
match_event_handler onEvent, void *context) { match_event_handler onEvent,
void *context) {
if (!id) { if (!id) {
return HS_INVALID; return HS_INVALID;
} }
@ -947,9 +952,10 @@ hs_error_t hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags, hs_error_t HS_CDECL hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags,
hs_scratch_t *scratch, match_event_handler onEvent, hs_scratch_t *scratch,
void *context) { match_event_handler onEvent,
void *context) {
if (!id) { if (!id) {
return HS_INVALID; return HS_INVALID;
} }
@ -972,7 +978,8 @@ hs_error_t hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags,
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_stream_size(const hs_database_t *db, size_t *stream_size) { hs_error_t HS_CDECL hs_stream_size(const hs_database_t *db,
size_t *stream_size) {
if (!stream_size) { if (!stream_size) {
return HS_INVALID; return HS_INVALID;
} }
@ -1019,10 +1026,13 @@ void dumpData(const char *data, size_t len) {
#endif #endif
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_scan_vector(const hs_database_t *db, const char * const * data, hs_error_t HS_CDECL hs_scan_vector(const hs_database_t *db,
const unsigned int *length, unsigned int count, const char * const * data,
UNUSED unsigned int flags, hs_scratch_t *scratch, const unsigned int *length,
match_event_handler onEvent, void *context) { unsigned int count,
UNUSED unsigned int flags,
hs_scratch_t *scratch,
match_event_handler onEvent, void *context) {
if (unlikely(!scratch || !data || !length)) { if (unlikely(!scratch || !data || !length)) {
return HS_INVALID; return HS_INVALID;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2016, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -240,7 +240,8 @@ hs_error_t alloc_scratch(const hs_scratch_t *proto, hs_scratch_t **scratch) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_alloc_scratch(const hs_database_t *db, hs_scratch_t **scratch) { hs_error_t HS_CDECL hs_alloc_scratch(const hs_database_t *db,
hs_scratch_t **scratch) {
if (!db || !scratch) { if (!db || !scratch) {
return HS_INVALID; return HS_INVALID;
} }
@ -385,7 +386,8 @@ hs_error_t hs_alloc_scratch(const hs_database_t *db, hs_scratch_t **scratch) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_clone_scratch(const hs_scratch_t *src, hs_scratch_t **dest) { hs_error_t HS_CDECL hs_clone_scratch(const hs_scratch_t *src,
hs_scratch_t **dest) {
if (!dest || !src || !ISALIGNED_CL(src) || src->magic != SCRATCH_MAGIC) { if (!dest || !src || !ISALIGNED_CL(src) || src->magic != SCRATCH_MAGIC) {
return HS_INVALID; return HS_INVALID;
} }
@ -402,7 +404,7 @@ hs_error_t hs_clone_scratch(const hs_scratch_t *src, hs_scratch_t **dest) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_free_scratch(hs_scratch_t *scratch) { hs_error_t HS_CDECL hs_free_scratch(hs_scratch_t *scratch) {
if (scratch) { if (scratch) {
/* has to be aligned before we can do anything with it */ /* has to be aligned before we can do anything with it */
if (!ISALIGNED_CL(scratch)) { if (!ISALIGNED_CL(scratch)) {
@ -426,7 +428,7 @@ hs_error_t hs_free_scratch(hs_scratch_t *scratch) {
} }
HS_PUBLIC_API HS_PUBLIC_API
hs_error_t hs_scratch_size(const hs_scratch_t *scratch, size_t *size) { hs_error_t HS_CDECL hs_scratch_size(const hs_scratch_t *scratch, size_t *size) {
if (!size || !scratch || !ISALIGNED_CL(scratch) || if (!size || !scratch || !ISALIGNED_CL(scratch) ||
scratch->magic != SCRATCH_MAGIC) { scratch->magic != SCRATCH_MAGIC) {
return HS_INVALID; return HS_INVALID;

View File

@ -30,12 +30,41 @@ if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-array-bounds") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-array-bounds")
endif() endif()
add_library(gtest STATIC ${gtest_SOURCES})
add_definitions(-DGTEST_HAS_PTHREAD=0 -DSRCDIR=${PROJECT_SOURCE_DIR}) add_definitions(-DGTEST_HAS_PTHREAD=0 -DSRCDIR=${PROJECT_SOURCE_DIR})
set(unit_hyperscan_SOURCES
${gtest_SOURCES}
hyperscan/allocators.cpp
hyperscan/arg_checks.cpp
hyperscan/bad_patterns.cpp
hyperscan/bad_patterns.txt
hyperscan/behaviour.cpp
hyperscan/expr_info.cpp
hyperscan/extparam.cpp
hyperscan/identical.cpp
hyperscan/main.cpp
hyperscan/multi.cpp
hyperscan/order.cpp
hyperscan/scratch_op.cpp
hyperscan/scratch_in_use.cpp
hyperscan/serialize.cpp
hyperscan/single.cpp
hyperscan/som.cpp
hyperscan/stream_op.cpp
hyperscan/test_util.cpp
hyperscan/test_util.h
)
add_executable(unit-hyperscan ${unit_hyperscan_SOURCES})
if (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS)
target_link_libraries(unit-hyperscan hs_shared expressionutil)
else()
target_link_libraries(unit-hyperscan hs expressionutil)
endif()
if (NOT (RELEASE_BUILD OR FAT_RUNTIME)) if (NOT (RELEASE_BUILD OR FAT_RUNTIME))
set(unit_internal_SOURCES set(unit_internal_SOURCES
${gtest_SOURCES}
internal/bitfield.cpp internal/bitfield.cpp
internal/bitutils.cpp internal/bitutils.cpp
internal/charreach.cpp internal/charreach.cpp
@ -83,40 +112,13 @@ set(unit_internal_SOURCES
internal/util_string.cpp internal/util_string.cpp
internal/vermicelli.cpp internal/vermicelli.cpp
internal/main.cpp internal/main.cpp
) )
add_executable(unit-internal ${unit_internal_SOURCES}) add_executable(unit-internal ${unit_internal_SOURCES})
target_link_libraries(unit-internal hs gtest corpusomatic) set_target_properties(unit-internal PROPERTIES COMPILE_FLAGS "${HS_CXX_FLAGS}")
target_link_libraries(unit-internal hs corpusomatic)
endif(NOT (RELEASE_BUILD OR FAT_RUNTIME)) endif(NOT (RELEASE_BUILD OR FAT_RUNTIME))
set(unit_hyperscan_SOURCES
hyperscan/allocators.cpp
hyperscan/arg_checks.cpp
hyperscan/bad_patterns.cpp
hyperscan/bad_patterns.txt
hyperscan/behaviour.cpp
hyperscan/expr_info.cpp
hyperscan/extparam.cpp
hyperscan/identical.cpp
hyperscan/main.cpp
hyperscan/multi.cpp
hyperscan/order.cpp
hyperscan/scratch_op.cpp
hyperscan/scratch_in_use.cpp
hyperscan/serialize.cpp
hyperscan/single.cpp
hyperscan/som.cpp
hyperscan/stream_op.cpp
hyperscan/test_util.cpp
hyperscan/test_util.h
)
add_executable(unit-hyperscan ${unit_hyperscan_SOURCES})
if (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS)
target_link_libraries(unit-hyperscan hs_shared gtest expressionutil)
else()
target_link_libraries(unit-hyperscan hs gtest expressionutil)
endif()
# #
# build target to run unit tests # build target to run unit tests
# #

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -27,9 +27,10 @@
*/ */
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "hs_common.h"
// Driver: run all the tests (defined in other source files in this directory) // Driver: run all the tests (defined in other source files in this directory)
int main(int argc, char **argv) { int HS_CDECL main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -117,6 +117,6 @@ INSTANTIATE_TEST_CASE_P(ValidUtf8, ValidUtf8Test, ValuesIn(valid_utf8_tests));
TEST_P(ValidUtf8Test, check) { TEST_P(ValidUtf8Test, check) {
const auto &info = GetParam(); const auto &info = GetParam();
ASSERT_EQ(info.is_valid, isValidUtf8(info.str.c_str())) SCOPED_TRACE(testing::Message() << "String is: " << printable(info.str));
<< "String is: " << printable(info.str) << std::endl; ASSERT_EQ(info.is_valid, isValidUtf8(info.str.c_str()));
} }

View File

@ -2,7 +2,7 @@
CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP) CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS} ${HS_CXX_FLAGS}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${PROJECT_SOURCE_DIR}) ${PROJECT_SOURCE_DIR})

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -29,12 +29,14 @@
#ifndef EXPRESSIONPARSER_H #ifndef EXPRESSIONPARSER_H
#define EXPRESSIONPARSER_H #define EXPRESSIONPARSER_H
#include "hs_common.h"
#include <string> #include <string>
struct hs_expr_ext; struct hs_expr_ext;
bool readExpression(const std::string &line, std::string &expr, bool HS_CDECL readExpression(const std::string &line, std::string &expr,
unsigned int *flags, hs_expr_ext *ext, unsigned int *flags, hs_expr_ext *ext,
bool *must_be_ordered = nullptr); bool *must_be_ordered = nullptr);
#endif #endif

View File

@ -115,9 +115,9 @@ void initExt(hs_expr_ext *ext) {
ext->max_offset = MAX_OFFSET; ext->max_offset = MAX_OFFSET;
} }
bool readExpression(const std::string &input, std::string &expr, bool HS_CDECL readExpression(const std::string &input, std::string &expr,
unsigned int *flags, hs_expr_ext *ext, unsigned int *flags, hs_expr_ext *ext,
bool *must_be_ordered) { bool *must_be_ordered) {
assert(flags); assert(flags);
assert(ext); assert(ext);

View File

@ -102,7 +102,7 @@ void processLine(string &line, unsigned lineNum,
#define S_ISDIR(st_m) (_S_IFDIR & (st_m)) #define S_ISDIR(st_m) (_S_IFDIR & (st_m))
#define S_ISREG(st_m) (_S_IFREG & (st_m)) #define S_ISREG(st_m) (_S_IFREG & (st_m))
#endif #endif
void loadExpressionsFromFile(const string &fname, ExpressionMap &exprMap) { void HS_CDECL loadExpressionsFromFile(const string &fname, ExpressionMap &exprMap) {
struct stat st; struct stat st;
if (stat(fname.c_str(), &st) != 0) { if (stat(fname.c_str(), &st) != 0) {
return; return;
@ -195,7 +195,7 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
} }
} }
#else // windows TODO: improve #else // windows TODO: improve
void loadExpressions(const string &inPath, ExpressionMap &exprMap) { void HS_CDECL loadExpressions(const string &inPath, ExpressionMap &exprMap) {
// Is our input path a file or a directory? // Is our input path a file or a directory?
struct stat st; struct stat st;
if (stat(inPath.c_str(), &st) != 0) { if (stat(inPath.c_str(), &st) != 0) {
@ -251,8 +251,8 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
} }
#endif #endif
void loadSignatureList(const string &inFile, void HS_CDECL loadSignatureList(const string &inFile,
SignatureSet &signatures) { SignatureSet &signatures) {
ifstream f(inFile.c_str()); ifstream f(inFile.c_str());
if (!f.good()) { if (!f.good()) {
cerr << "Can't open file: '" << inFile << "'" << endl; cerr << "Can't open file: '" << inFile << "'" << endl;

View File

@ -29,6 +29,8 @@
#ifndef EXPRESSIONS_H #ifndef EXPRESSIONS_H
#define EXPRESSIONS_H #define EXPRESSIONS_H
#include "hs_common.h"
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
@ -38,12 +40,12 @@ using SignatureSet = std::vector<unsigned>;
// load all of the expressions from the given directory into the given // load all of the expressions from the given directory into the given
// expression map. Exits on failure. // expression map. Exits on failure.
void loadExpressions(const std::string &inDir, ExpressionMap &exprMap); void HS_CDECL loadExpressions(const std::string &inDir, ExpressionMap &exprMap);
void loadExpressionsFromFile(const std::string &fname, ExpressionMap &exprMap); void HS_CDECL loadExpressionsFromFile(const std::string &fname, ExpressionMap &exprMap);
// load a list of signature IDs // load a list of signature IDs
void loadSignatureList(const std::string &inFile, SignatureSet &signatures); void HS_CDECL loadSignatureList(const std::string &inFile, SignatureSet &signatures);
// trim expression map to only the given signatures, returning result // trim expression map to only the given signatures, returning result
ExpressionMap limitToSignatures(const ExpressionMap &exprMap, ExpressionMap limitToSignatures(const ExpressionMap &exprMap,