From aa8abd3fad49130aaf7062c8dd9454fc59af3ef6 Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Mon, 31 Dec 2018 16:44:19 +0100 Subject: [PATCH] configurator: allow sizeof in C symbols import Fixes https://github.com/ocaml/dune/pull/1723 Signed-off-by: Christophe Troestler --- src/configurator/v1.ml | 11 +++++------ .../test-cases/configurator/import-define/run.ml | 5 ++++- test/blackbox-tests/test-cases/configurator/run.t | 2 ++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/configurator/v1.ml b/src/configurator/v1.ml index 19964648d992..8b1424a77ea3 100644 --- a/src/configurator/v1.ml +++ b/src/configurator/v1.ml @@ -350,6 +350,7 @@ module C_define = struct #define D7(x) ('0'+(x/10000000 )%%10), D6(x) #define D8(x) ('0'+(x/100000000 )%%10), D7(x) #define D9(x) ('0'+(x/1000000000)%%10), D8(x) +#define SIGN(x) ((x >= 0)? '+': '-') |} ); List.iteri vars ~f:(fun i (name, t) -> @@ -364,16 +365,14 @@ module C_define = struct Buffer.contents b in pr {| +const int i%i = (%s >= 0)? %s: -(%s); const char s%i[] = { 'B', 'E', 'G', 'I', 'N', '-', %s'-', -#if %s >= 0 - D9((%s)), -#else - '-', D9((- %s)), -#endif + SIGN((%s)), + D9((i%i)), '-', 'E', 'N', 'D' }; -|} i c_arr_i name name name +|} i name name name i c_arr_i name i | String -> pr {|const char *s%i = "BEGIN-%i-" %s "-END";|} i i name; | Switch -> diff --git a/test/blackbox-tests/test-cases/configurator/import-define/run.ml b/test/blackbox-tests/test-cases/configurator/import-define/run.ml index 412b64866977..76c341b9a864 100644 --- a/test/blackbox-tests/test-cases/configurator/import-define/run.ml +++ b/test/blackbox-tests/test-cases/configurator/import-define/run.ml @@ -4,11 +4,14 @@ let () = let module C_define = Configurator.C_define in Configurator.main ~name:"c_test" (fun t -> C_define.import t - ~prelude:{|#define CONFIGURATOR_TESTING "foobar"|} + ~prelude:"#define CONFIGURATOR_TESTING \"foobar\"\n\ + #define CONFIGURATOR_NEG_INT -127\n" ~includes:["caml/config.h"] [ "CAML_CONFIG_H", C_define.Type.Switch ; "Page_log", C_define.Type.Int ; "CONFIGURATOR_TESTING", C_define.Type.String + ; "CONFIGURATOR_NEG_INT", C_define.Type.Int + ; "sizeof(char)", C_define.Type.Int ] |> List.iter (fun (n, v) -> Printf.printf "%s=%s\n" diff --git a/test/blackbox-tests/test-cases/configurator/run.t b/test/blackbox-tests/test-cases/configurator/run.t index 232bb20716b7..b58fb0c26ac2 100644 --- a/test/blackbox-tests/test-cases/configurator/run.t +++ b/test/blackbox-tests/test-cases/configurator/run.t @@ -12,3 +12,5 @@ Importing #define's from code is successful CAML_CONFIG_H=true Page_log=12 CONFIGURATOR_TESTING=foobar + CONFIGURATOR_NEG_INT=-127 + sizeof(char)=1