From 07443aa8a89d760e7babde0701ae80fb72f39698 Mon Sep 17 00:00:00 2001 From: simon-p-r Date: Mon, 17 Sep 2018 19:46:24 +0100 Subject: [PATCH] fixed broken test with constant ov array size set to 30 --- BUILD.WINDOWS.txt | 25 +++++++++++++++++++++++++ src/node.c | 8 +++----- tests/check_tree.c | 6 +++--- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/BUILD.WINDOWS.txt b/BUILD.WINDOWS.txt index e69de29..f85aa81 100644 --- a/BUILD.WINDOWS.txt +++ b/BUILD.WINDOWS.txt @@ -0,0 +1,25 @@ +Building with CMAKE on Windows using VCPKG +======================================= + + This document describes how to compile, build and install libr3 on Windows using CMake, MSVC compiler and VCPKG + + VCPKG can be installed from + + https://github.com/Microsoft/vcpkg + + Once VCPKG is installed you must install libcheck and pcre before running the folloiwing command to configure build + + cmake -H"." -B"" -G"" -DCMAKE_TOOLCHAIN_FILE= -DVCPKG_TARGET_TRIPLET= + + Then to perform build + + cmake --build -B"" --target ALL_BUILD --config "" + + Then to run tests, you must copy pcre.dll and pcre.pdb file to output directory prior to running tests + + cmake --build -B"" --target RUN_TESTS --config "" + + Window build is currently WIP. + + + diff --git a/src/node.c b/src/node.c index 683aaa1..29992f1 100644 --- a/src/node.c +++ b/src/node.c @@ -8,6 +8,8 @@ // PCRE #include +#define MAX_SUBSTRINGS 30 + #include "r3.h" #include "r3_slug.h" #include "slug.h" @@ -329,7 +331,7 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l info("COMPARE PCRE_PATTERN\n"); const char *substring_start = 0; int substring_length = 0; - int *ov = malloc(sizeof(int) * n->ov_cnt); + int ov[MAX_SUBSTRINGS]; int rc; info("pcre matching %s on %s\n", n->combined_pattern, path); @@ -360,7 +362,6 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l break; } #endif - free(ov); return NULL; } @@ -388,7 +389,6 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l str_array_append(&entry->vars, substring_start, substring_length); } - free(ov); // since restlen == 0 return the edge quickly. return e->child && e->child->endpoint ? e->child : NULL; } @@ -415,12 +415,10 @@ R3Node * r3_tree_matchl(const R3Node * n, const char * path, unsigned int path_l str_array_append(&entry->vars , substring_start, substring_length); } - free(ov); // get the length of orginal string: $0 return r3_tree_matchl( e->child, path + (ov[1] - ov[0]), restlen, entry); } // does not match - free(ov); return NULL; } diff --git a/tests/check_tree.c b/tests/check_tree.c index 547d56d..b8543b2 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -305,7 +305,7 @@ START_TEST (test_compile) entry = match_entry_createl( "/foo/xxx" , strlen("/foo/xxx") ); m = r3_tree_matchl( n , "/foo/xxx", strlen("/foo/xxx"), entry); - // ck_assert( m ); + ck_assert( m ); match_entry_free(entry); entry = match_entry_createl( "/some_id" , strlen("/some_id") ); @@ -472,8 +472,8 @@ START_TEST (test_pcre_patterns_insert_2) // r3_tree_dump(n, 0); R3Node *matched; matched = r3_tree_match(n, "/post/11/22", NULL); - // ck_assert(matched); - // ck_assert(matched->endpoint > 0); + ck_assert(matched); + ck_assert(matched->endpoint > 0); r3_tree_free(n); }