Skip to content

Commit

Permalink
configurator: allow sizeof in C symbols import
Browse files Browse the repository at this point in the history
Fixes #1723

Signed-off-by: Christophe Troestler <Christophe.Troestler@umons.ac.be>
  • Loading branch information
Chris00 committed Dec 31, 2018
1 parent 94f635e commit aa8abd3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/configurator/v1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand All @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions test/blackbox-tests/test-cases/configurator/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aa8abd3

Please sign in to comment.