Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tempdir usage in ffi-infer #459

Merged
merged 1 commit into from
Dec 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions pixie/ffi-infer.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,35 @@ return 0;
`(def ~(symbol name)
~(callback-type of-type false)))

(def mkdtemp (ffi-fn libc "mkdtemp" [CCharP] CCharP))
(def unlink (ffi-fn libc "unlink" [CCharP] CInt))
(def rmdir (ffi-fn libc "rmdir" [CCharP] CInt))
(def tempdir-template (str (or (getenv "TMPDIR") "/tmp")
"/ffiXXXXXX"))

(defn run-infer [config cmds]
(io/spit "/tmp/tmp.cpp" (str (start-string)
(apply str (map emit-infer-code
cmds))
(end-string)))
(println @load-paths)
(let [cmd-str (str "c++ "
(apply str (interpose " " pixie.platform/c-flags))
" /tmp/tmp.cpp "
(apply str (map (fn [x] ( str " -I " x " "))
@load-paths))
(apply str " " (interpose " " (:cxx-flags *config*)))
" -o /tmp/a.out && /tmp/a.out")
_ (println cmd-str)
result (read-string (io/run-command cmd-str))
gen (vec (map generate-code cmds result))]
`(do ~@gen)))
(let [tempdir (mkdtemp tempdir-template)
infile (str tempdir "/ffi.cpp")
outfile (str tempdir "/ffi.out")]
(io/spit infile (str (start-string)
(apply str (map emit-infer-code
cmds))
(end-string)))
(println @load-paths)
(let [cmd-str (str "c++ "
(apply str (interpose " " pixie.platform/c-flags))
" " infile " "
(apply str (map (fn [x] ( str " -I " x " "))
@load-paths))
(apply str " " (interpose " " (:cxx-flags *config*)))
" -o " outfile " && " outfile)
_ (println cmd-str)
result (read-string (io/run-command cmd-str))
gen (vec (map generate-code cmds result))]
(unlink infile)
(unlink outfile)
(rmdir tempdir)
`(do ~@gen))))

(defn full-lib-name [library-name]
(if (= library-name "c")
Expand Down