File tree Expand file tree Collapse file tree 8 files changed +146
-1
lines changed Expand file tree Collapse file tree 8 files changed +146
-1
lines changed Original file line number Diff line number Diff line change 1- ## 0.4.2 (2023-09-09)
1+ ## 0.4.3 (2023-09-09)
22
33* helpers tools and examples added
44
Original file line number Diff line number Diff line change 1+ compile_flags.txt
Original file line number Diff line number Diff line change 1+ Given a file ` foo.ml ` that contains a C stub and a 'foostubs.c' that implements.
2+
3+ Generate some dune rules, for example by doing this:
4+ ```
5+ (include dune.analysis.inc)
6+ (rule
7+ (deps
8+ (:mlfiles (glob_files_rec *.ml))
9+ (:cfiles (glob_files_rec *.c))
10+ )
11+ (action (with-stdout-to dune.analysis.inc.gen
12+ (run %{bin:lintcstubs-dune-rules} %{mlfiles} %{cfiles})
13+ ))
14+ )
15+
16+ (rule
17+ (alias runtest)
18+ (action
19+ (diff dune.analysis.inc dune.analysis.inc.gen)))
20+ ```
21+
22+ And then running:
23+ ```
24+ rm -f dune.analysis.inc; touch dune.analysis.inc && dune runtest --auto-promote
25+ ```
26+
27+ You will have to create a ` compile_commands.json ` , e.g. by using ` bear ` :
28+ ```
29+ bear -- dune build @cstubs
30+ ```
31+
32+ (where ` @cstubs ` is an alias generated by the above tool).
33+
34+ Now you can run ` dune build @analyze ` to trigger a static analysis.
35+
36+ TODO: this is very experimental.
Original file line number Diff line number Diff line change 1+ (library
2+ (package lintcstubs)
3+ (name foo2)
4+ (foreign_stubs
5+ (language c)
6+ (names foostubs)))
7+
8+ (include dune.analysis.inc)
9+
10+ (rule
11+ (deps
12+ (:mlfiles
13+ (glob_files_rec *.ml))
14+ (:cfiles
15+ (glob_files_rec *.c)))
16+ (action
17+ (with-stdout-to
18+ dune.analysis.inc.gen
19+ (run %{bin:lintcstubs-dune-rules} %{mlfiles} %{cfiles}))))
20+
21+ (rule
22+ (alias runtest)
23+ (action
24+ (diff dune.analysis.inc dune.analysis.inc.gen)))
Original file line number Diff line number Diff line change 1+ (rule (targets foo2.model.c ./primitives.h)
2+ (deps (:cmt ./.foo2.objs/byte/foo2.cmt) %{bin:lintcstubs_arity_cmt}
3+ %{bin:lintcstubs_genwrap} %{bin:lintcstubs_genmain})
4+ (action
5+ (progn
6+ (with-stdout-to ./primitives.h (run %{bin:lintcstubs_arity_cmt} %{cmt}))
7+ (with-stdout-to foo2.model.c
8+ (progn (run %{bin:lintcstubs_genwrap} %{cmt})
9+ (run %{bin:lintcstubs_genmain} %{cmt}))))))
10+ (rule (alias cstubs) (deps (:ofiles foo2.model.o foostubs.o))
11+ (action (echo " for BEAR" )))
12+ (rule (targets ./lintcstubs.log ./lintcstubs.sarif)
13+ (deps compile_commands.json (:primitives ./primitives.h)
14+ (:model foo2.model.c) %{bin:lintcstubs} (package lintcstubs))
15+ (action
16+ (with-stdout-to ./lintcstubs.log
17+ (run %{bin:lintcstubs} --conf lintcstubs.json -o ./lintcstubs.sarif -I
18+ %{ocaml_where} --set dbg.solver-stats-interval 0 compile_commands.json
19+ %{model}))))
20+ (rule (alias analyze) (deps (:log ./lintcstubs.log))
21+ (action (diff lintcstubs.out.reference %{deps})))
Original file line number Diff line number Diff line change 1+ type t
2+
3+ external foo_bad : t -> int = " foo_bad"
4+
5+ external foo_good : t -> int = " foo_good"
Original file line number Diff line number Diff line change 1+
2+ #include <caml/mlvalues.h>
3+ #include <caml/memory.h>
4+ #include <caml/alloc.h>
5+ #include <caml/threads.h>
6+
7+ value foo_bad (value v )
8+ {
9+ CAMLparam1 (v );
10+ int x ;
11+ caml_enter_blocking_section ();
12+ x = * (int * )Data_abstract_val (v );
13+ caml_leave_blocking_section ();
14+ CAMLreturn (Val_int (x ));
15+ }
16+
17+ value foo_good (value v )
18+ {
19+ CAMLparam1 (v );
20+ int x = * (int * ) Data_abstract_val (v );
21+ caml_enter_blocking_section ();
22+ caml_leave_blocking_section ();
23+ CAMLreturn (Val_int (x ));
24+ }
Original file line number Diff line number Diff line change 1+ # This file is generated by dune, edit dune-project instead
2+ opam-version: "2.0"
3+ synopsis: "Generate dune rules for lintcstubs integration"
4+ description: "Generates dune rules for running the static analyzer"
5+ maintainer: ["Edwin Török <
[email protected] >"]
6+ authors: ["Edwin Török <
[email protected] >"]
7+ license: "LGPL-2.1-or-later"
8+ homepage: "https://github.com/edwintorok/lintcstubs"
9+ bug-reports: "https://github.com/edwintorok/lintcstubs/issues"
10+ depends: [
11+ "dune" {>= "3.0"}
12+ "ocaml" {>= "4.14"}
13+ "lintcstubs-arity" {>= "0.2.2"}
14+ "lintcstubs-gen" {= version}
15+ "lintcstubs" {= version}
16+ "odoc" {with-doc}
17+ ]
18+ build: [
19+ ["dune" "subst"] {dev}
20+ [
21+ "dune"
22+ "build"
23+ "-p"
24+ name
25+ "-j"
26+ jobs
27+ "--promote-install-files=false"
28+ "@install"
29+ "@runtest" {with-test}
30+ "@doc" {with-doc}
31+ ]
32+ ["dune" "install" "-p" name "--create-install-files" name]
33+ ]
34+ dev-repo: "git+https://github.com/edwintorok/lintcstubs.git"
You can’t perform that action at this time.
0 commit comments