From e64e66b1941eb0e73305c0dc62486580ecec91b2 Mon Sep 17 00:00:00 2001 From: Aur Saraf Date: Sun, 14 Apr 2013 02:49:12 +0300 Subject: [PATCH 01/13] some tests for base64.c --- examples/base64.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/examples/base64.c b/examples/base64.c index beb2484..0a8f613 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -29,6 +29,35 @@ void init_parser(void) } +#include +#include +#define TRUE (1) +#define FALSE (0) + +void assert_parse(int expected, char *data) { + const HParseResult *result; + + size_t datasize = strlen(data); + result = h_parse(document, (void*)data, datasize); + if((result != NULL) != expected) { + printf("Test failed: %s\n", data); + } +} + +void test() { + assert_parse(TRUE, ""); + assert_parse(TRUE, "YQ=="); + assert_parse(TRUE, "YXU="); + assert_parse(TRUE, "YXVy"); + assert_parse(TRUE, "QVVSIFNBUkFG"); + assert_parse(TRUE, "QVVSIEhFUlUgU0FSQUY="); + assert_parse(FALSE, "A"); + assert_parse(FALSE, "A="); + assert_parse(FALSE, "A=="); + assert_parse(FALSE, "AAA=="); +} + + #include int main(int argc, char **argv) @@ -39,6 +68,8 @@ int main(int argc, char **argv) init_parser(); + test(); + inputsize = fread(input, 1, sizeof(input), stdin); fprintf(stderr, "inputsize=%lu\ninput=", inputsize); fwrite(input, 1, inputsize, stderr); From 9a6a785390202d99556847879d83c4fbd57cf968 Mon Sep 17 00:00:00 2001 From: Aur Saraf Date: Sun, 14 Apr 2013 03:13:07 +0300 Subject: [PATCH 02/13] debugging info in test_parse(), more tests, fixed some of them but not others --- examples/base64.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/base64.c b/examples/base64.c index 0a8f613..33c2ac8 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -1,5 +1,7 @@ #include "../src/hammer.h" +#define DEBUG + const HParser* document = NULL; void init_parser(void) @@ -19,9 +21,14 @@ void init_parser(void) h_ch('Y'), h_ch('c'), h_ch('g'), h_ch('k'), h_ch('o'), h_ch('s'), h_ch('w'), h_ch('0'), h_ch('4'), h_ch('8'), NULL); const HParser *bsfdig_2bit = h_choice(h_ch('A'), h_ch('Q'), h_ch('g'), h_ch('w'), NULL); - const HParser *base64_2 = h_sequence(bsfdig, bsfdig, bsfdig_4bit, equals, NULL); - const HParser *base64_1 = h_sequence(bsfdig, bsfdig_2bit, equals, equals, NULL); - const HParser *base64 = h_choice(base64_2, base64_1, NULL); + + const HParser *base64_quad = h_sequence(bsfdig, bsfdig, bsfdig, bsfdig, NULL); + const HParser *base64_quads = h_many(base64_quad); + + const HParser *base64_2 = h_sequence(bsfdig, bsfdig, bsfdig_4bit, equals, h_end_p(), NULL); + const HParser *base64_1 = h_sequence(bsfdig, bsfdig_2bit, equals, equals, h_end_p(), NULL); + const HParser *base64_ending = h_choice(h_end_p(), base64_2, base64_1, NULL); + const HParser *base64 = h_sequence(base64_quads, base64_ending, NULL); // why does this parse "A=="?! // why does this parse "aaA=" but not "aA=="?! @@ -40,8 +47,15 @@ void assert_parse(int expected, char *data) { size_t datasize = strlen(data); result = h_parse(document, (void*)data, datasize); if((result != NULL) != expected) { - printf("Test failed: %s\n", data); + fprintf(stderr, "Test failed: %s\n", data); } +#ifdef DEBUG + else { + fprintf(stderr, "Test succeeded: %s\n", data); + fprintf(stderr, "parsed=%lld bytes\n", result->bit_length/8); + h_pprint(stdout, result->ast, 0, 0); + } +#endif } void test() { @@ -55,6 +69,7 @@ void test() { assert_parse(FALSE, "A="); assert_parse(FALSE, "A=="); assert_parse(FALSE, "AAA=="); + assert_parse(FALSE, "aa=="); } From dd5cc15a2b020de69992cc9996d8f52ea995acdd Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Sun, 4 Oct 2015 17:07:59 +0200 Subject: [PATCH 03/13] shave off another ~500ns/iter by not initialising HLeftRecs we'll never use --- src/backends/packrat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backends/packrat.c b/src/backends/packrat.c index abb198b..f21e22a 100644 --- a/src/backends/packrat.c +++ b/src/backends/packrat.c @@ -188,9 +188,10 @@ HParseResult* h_do_parse(const HParser* parser, HParseState *state) { // check to see if there is already a result for this object... if (!m) { // It doesn't exist, so create a dummy result to cache - HLeftRec *base = a_new(HLeftRec, 1); + HLeftRec *base = NULL; // But only cache it now if there's some chance it could grow; primitive parsers can't if (parser->vtable->higher) { + base = a_new(HLeftRec, 1); base->seed = NULL; base->rule = parser; base->head = NULL; h_slist_push(state->lr_stack, base); // cache it @@ -207,7 +208,7 @@ HParseResult* h_do_parse(const HParser* parser, HParseState *state) { cached->input_stream = state->input_stream; } // setupLR, used below, mutates the LR to have a head if appropriate, so we check to see if we have one - if (NULL == base->head) { + if (!base || NULL == base->head) { h_hashtable_put(state->cache, key, cached_result(state, tmp_res)); return tmp_res; } else { From f9c6e5f2602147c51152626bdb4b5bf734823aad Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Wed, 24 Feb 2016 23:51:44 +0100 Subject: [PATCH 04/13] bump Travis-CI version to trusty --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b533da3..32a9cac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +sudo: required +dist: trusty language: c compiler: - gcc @@ -87,7 +89,7 @@ matrix: - compiler: gcc language: cpp env: BINDINGS=cpp - - compiler: gcc + - compiler: clang language: cpp env: BINDINGS=cpp CC=clang before_install: From 262a2a544962d822355d670de21ecdc640556bd7 Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 00:28:21 +0100 Subject: [PATCH 05/13] update .travis.yml to trusty settings, too --- .travis.yml | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 32a9cac..b047f77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,35 +10,43 @@ matrix: include: - compiler: gcc language: ruby - rvm: ruby-1.9.3-p484 + rvm: ruby-1.9.3-p551 env: BINDINGS=ruby - compiler: clang language: ruby - rvm: ruby-1.9.3-p484 + rvm: ruby-1.9.3-p551 env: BINDINGS=ruby CC=clang - compiler: gcc language: ruby - rvm: ruby-2.0.0-p353 + rvm: ruby-2.0.0-p647 env: BINDINGS=ruby - compiler: clang language: ruby - rvm: ruby-2.0.0-p353 + rvm: ruby-2.0.0-p647 env: BINDINGS=ruby CC=clang - compiler: gcc language: ruby - rvm: ruby-2.1.0 + rvm: ruby-2.1.7 env: BINDINGS=ruby - compiler: clang language: ruby - rvm: ruby-2.1.0 + rvm: ruby-2.1.7 + env: BINDINGS=ruby CC=clang + - compiler: gcc + language: ruby + rvm: ruby-2.2.3 + env: BINDINGS=ruby + - compiler: clang + language: ruby + rvm: ruby-2.3.3 env: BINDINGS=ruby CC=clang - compiler: gcc language: python - python: "2.7" + python: "2.7.10" env: BINDINGS=python - compiler: clang language: python - python: "2.7" + python: "2.7.10" env: BINDINGS=python CC=clang - compiler: gcc language: perl @@ -94,12 +102,12 @@ matrix: env: BINDINGS=cpp CC=clang before_install: - sudo apt-get update -qq - - sudo apt-get install lcov + - sudo apt-get install -y lcov - gem install coveralls-lcov - - if [ "$BINDINGS" != "none" ]; then sudo apt-get install -qq swig; fi - - if [ "$BINDINGS" == "perl" ]; then sudo add-apt-repository ppa:dns/irc -y; sudo apt-get update -qq; sudo apt-get install -qq swig=2.0.8-1irc1~12.04; fi - - if [ "$BINDINGS" == "python" ]; then sudo apt-get install -qq python-dev; fi - - if [ "$BINDINGS" == "dotnet" ]; then sudo add-apt-repository ppa:directhex/monoxide -y; sudo apt-get update -qq; sudo apt-get install -qq mono-devel mono-mcs nunit nunit-console; mozroots --import --sync; fi + - if [ "$BINDINGS" != "none" ]; then sudo apt-get install -yqq swig; fi + - if [ "$BINDINGS" == "perl" ]; then sudo add-apt-repository ppa:dns/irc -y; sudo apt-get update -qq; sudo apt-get install -yqq swig=2.0.8-1irc1~12.04; fi + - if [ "$BINDINGS" == "python" ]; then sudo apt-get install -yqq python-dev; fi + - if [ "$BINDINGS" == "dotnet" ]; then sudo add-apt-repository ppa:directhex/monoxide -y; sudo apt-get update -qq; sudo apt-get install -yqq mono-devel mono-mcs nunit nunit-console; mozroots --import --sync; fi install: true before_script: - if [ "$BINDINGS" == "php" ]; then phpenv config-add src/bindings/php/hammer.ini; fi From f05b00f1a91eab0c1d144b70406110dc4d237f92 Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 15:07:19 +0100 Subject: [PATCH 06/13] typo in Ruby versions. Config for Perl bindings is broken and will fail. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b047f77..e152f85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ matrix: env: BINDINGS=ruby - compiler: clang language: ruby - rvm: ruby-2.3.3 + rvm: ruby-2.2.3 env: BINDINGS=ruby CC=clang - compiler: gcc language: python From 1fd9e032a8d23b0951fe8dc2b36389900a240105 Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 16:02:40 +0100 Subject: [PATCH 07/13] swig 3 seems to work for perl, so let's try the backport --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e152f85..379ace7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,8 +104,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y lcov - gem install coveralls-lcov - - if [ "$BINDINGS" != "none" ]; then sudo apt-get install -yqq swig; fi - - if [ "$BINDINGS" == "perl" ]; then sudo add-apt-repository ppa:dns/irc -y; sudo apt-get update -qq; sudo apt-get install -yqq swig=2.0.8-1irc1~12.04; fi + - if [ "$BINDINGS" != "none" ]; then sudo apt-get install -yqq swig/trusty-backports; fi - if [ "$BINDINGS" == "python" ]; then sudo apt-get install -yqq python-dev; fi - if [ "$BINDINGS" == "dotnet" ]; then sudo add-apt-repository ppa:directhex/monoxide -y; sudo apt-get update -qq; sudo apt-get install -yqq mono-devel mono-mcs nunit nunit-console; mozroots --import --sync; fi install: true From 8f77a3fcc87e45508e9ccd4a9644af54e4e7372f Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 16:25:07 +0100 Subject: [PATCH 08/13] need to add backports before using it, duh --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 379ace7..ad75fad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y lcov - gem install coveralls-lcov - - if [ "$BINDINGS" != "none" ]; then sudo apt-get install -yqq swig/trusty-backports; fi + - if [ "$BINDINGS" != "none" ]; then sudo sh -c 'echo "deb http://ports.ubuntu.com/ubuntu-ports trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list'; sudo apt-get install -yqq swig/trusty-backports; fi - if [ "$BINDINGS" == "python" ]; then sudo apt-get install -yqq python-dev; fi - if [ "$BINDINGS" == "dotnet" ]; then sudo add-apt-repository ppa:directhex/monoxide -y; sudo apt-get update -qq; sudo apt-get install -yqq mono-devel mono-mcs nunit nunit-console; mozroots --import --sync; fi install: true From 1d1d6c7a609f570b8f284221f4494bfc50e8493e Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 17:26:44 +0100 Subject: [PATCH 09/13] also need to apt-get update again, double duh --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ad75fad..0e25e41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y lcov - gem install coveralls-lcov - - if [ "$BINDINGS" != "none" ]; then sudo sh -c 'echo "deb http://ports.ubuntu.com/ubuntu-ports trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list'; sudo apt-get install -yqq swig/trusty-backports; fi + - if [ "$BINDINGS" != "none" ]; then sudo sh -c 'echo "deb http://ports.ubuntu.com/ubuntu-ports trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list'; sudo apt-get update -qq; sudo apt-get install -yqq swig/trusty-backports; fi - if [ "$BINDINGS" == "python" ]; then sudo apt-get install -yqq python-dev; fi - if [ "$BINDINGS" == "dotnet" ]; then sudo add-apt-repository ppa:directhex/monoxide -y; sudo apt-get update -qq; sudo apt-get install -yqq mono-devel mono-mcs nunit nunit-console; mozroots --import --sync; fi install: true From 541c63e1764f047e4b31afb37e826049595889ce Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 17:55:51 +0100 Subject: [PATCH 10/13] wrong backports address, apparently --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0e25e41..24b10d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y lcov - gem install coveralls-lcov - - if [ "$BINDINGS" != "none" ]; then sudo sh -c 'echo "deb http://ports.ubuntu.com/ubuntu-ports trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list'; sudo apt-get update -qq; sudo apt-get install -yqq swig/trusty-backports; fi + - if [ "$BINDINGS" != "none" ]; then sudo sh -c 'echo "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list'; sudo apt-get update -qq; sudo apt-get install -yqq swig/trusty-backports; fi - if [ "$BINDINGS" == "python" ]; then sudo apt-get install -yqq python-dev; fi - if [ "$BINDINGS" == "dotnet" ]; then sudo add-apt-repository ppa:directhex/monoxide -y; sudo apt-get update -qq; sudo apt-get install -yqq mono-devel mono-mcs nunit nunit-console; mozroots --import --sync; fi install: true From 863c1c093bd20756ff8ad6318f6fa2e6fe36ed2e Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 18:41:44 +0100 Subject: [PATCH 11/13] swig3.0, not swig --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 24b10d6..e0f5c40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y lcov - gem install coveralls-lcov - - if [ "$BINDINGS" != "none" ]; then sudo sh -c 'echo "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list'; sudo apt-get update -qq; sudo apt-get install -yqq swig/trusty-backports; fi + - if [ "$BINDINGS" != "none" ]; then sudo sh -c 'echo "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list'; sudo apt-get update -qq; sudo apt-get install -yqq swig3.0/trusty-backports; fi - if [ "$BINDINGS" == "python" ]; then sudo apt-get install -yqq python-dev; fi - if [ "$BINDINGS" == "dotnet" ]; then sudo add-apt-repository ppa:directhex/monoxide -y; sudo apt-get update -qq; sudo apt-get install -yqq mono-devel mono-mcs nunit nunit-console; mozroots --import --sync; fi install: true From 9ee4fbd87cb5b72e69fbacf00a16a99c0bde42e9 Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Thu, 25 Feb 2016 23:21:12 +0100 Subject: [PATCH 12/13] backports swig is named swig3.0, so fix that across bindings --- src/bindings/dotnet/SConscript | 2 +- src/bindings/perl/SConscript | 2 +- src/bindings/php/SConscript | 2 +- src/bindings/python/SConscript | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/dotnet/SConscript b/src/bindings/dotnet/SConscript index 94f874e..afa4c30 100644 --- a/src/bindings/dotnet/SConscript +++ b/src/bindings/dotnet/SConscript @@ -27,7 +27,7 @@ csfiles = os.path.join(thisdir, "*.cs") # target to stand in for. hammer_wrap = AlwaysBuild(dotnetenv.Command(['hammer_wrap.c'], swig, ["rm %s/*.cs || true" % (thisdir,), - "swig $SWIGFLAGS $SOURCE"])) + "swig3.0 $SWIGFLAGS $SOURCE"])) libhammer_dotnet = dotnetenv.SharedLibrary(['hammer_dotnet'], hammer_wrap) hammer_dll = AlwaysBuild(dotnetenv.Command(['hammer.dll'], Glob('ext/*.cs'), '$CSC -t:library -unsafe -out:$TARGET %s/*.cs $SOURCE' %(thisdir,))) diff --git a/src/bindings/perl/SConscript b/src/bindings/perl/SConscript index 49b693a..8a192a5 100644 --- a/src/bindings/perl/SConscript +++ b/src/bindings/perl/SConscript @@ -20,7 +20,7 @@ if 'PERL5LIB' in os.environ: swig = ['hammer.i'] -hammer_wrap = perlenv.Command(['hammer_wrap.c', 'hammer.pm'], swig, "swig $SWIGFLAGS $SOURCE") +hammer_wrap = perlenv.Command(['hammer_wrap.c', 'hammer.pm'], swig, "swig3.0 $SWIGFLAGS $SOURCE") makefile = perlenv.Command(['Makefile'], ['Makefile.PL'], "perl $SOURCE CC=" + perlenv['ENV']['CC']) targetdir = os.path.dirname(str(hammer_wrap[0].path)) diff --git a/src/bindings/php/SConscript b/src/bindings/php/SConscript index 34728af..6791cbc 100644 --- a/src/bindings/php/SConscript +++ b/src/bindings/php/SConscript @@ -11,7 +11,7 @@ phpenv.Append(LIBS = ['hammer']) phpenv.Append(LIBPATH = ['../../']) swig = ['hammer.i'] -bindings_src = phpenv.Command(['hammer.php', 'hammer_wrap.c', 'php_hammer.h'], swig, 'swig -php -DHAMMER_INTERNAL__NO_STDARG_H -Isrc/ $SOURCE') +bindings_src = phpenv.Command(['hammer.php', 'hammer_wrap.c', 'php_hammer.h'], swig, 'swig3.0 -php -DHAMMER_INTERNAL__NO_STDARG_H -Isrc/ $SOURCE') libhammer_php = phpenv.SharedLibrary('hammer', ['hammer_wrap.c']) Default(swig, bindings_src, libhammer_php) diff --git a/src/bindings/python/SConscript b/src/bindings/python/SConscript index dac2d95..5c7e474 100644 --- a/src/bindings/python/SConscript +++ b/src/bindings/python/SConscript @@ -7,7 +7,7 @@ pythonenv = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0) swig = pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE")) setup = ['setup.py'] pydir = os.path.join(env['BUILD_BASE'], 'src/bindings/python') -libhammer_python = pythonenv.Command(['hammer.py', 'hammer_wrap.c'], [swig, setup], 'python ' + os.path.join(pydir, 'setup.py') + ' build_ext --inplace') +libhammer_python = pythonenv.Command(['hammer.py', 'hammer_wrap.c'], [swig, setup], 'python ' + os.path.join(pydir, 'setup.py') + ' build_ext --swig=swig3.0 --inplace') Default(libhammer_python) pytestenv = pythonenv.Clone() From 996fa914e0e2712edb0f78af5188dd7dff887224 Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Tue, 1 Nov 2016 21:09:40 +0100 Subject: [PATCH 13/13] update std from gnu99 to gnu11 --- SConstruct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index bb2bb85..1af97dd 100644 --- a/SConstruct +++ b/SConstruct @@ -49,7 +49,7 @@ env['backendsincpath'] = calcInstallPath("$prefix", "include", "hammer", "backen env['pkgconfigpath'] = calcInstallPath("$prefix", "lib", "pkgconfig") env.ScanReplace('libhammer.pc.in') -env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable") +env.MergeFlags("-std=gnu11 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable") if env['PLATFORM'] == 'darwin': env.Append(SHLINKFLAGS = '-install_name ' + env["libpath"] + '/${TARGET.file}')