Skip to content

Commit fbfbf76

Browse files
authored
Merge pull request #844 from yc2lee/new-memory-leak
Hack around issue #836 by using clang executable, which finds the memory leak properly
2 parents 9c07f7d + 78a0d39 commit fbfbf76

File tree

7 files changed

+69
-4
lines changed

7 files changed

+69
-4
lines changed

src/backend/compiler/compiler.cc

+24
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ struct seashell_compiler {
163163
/** Object files discovered by dependency resolution */
164164
std::vector<std::string> object_paths;
165165

166+
/** All source_paths and object_paths joined into one string */
167+
std::string dep_paths;
168+
166169
/** Module compilation messages. */
167170
std::vector<seashell_diag> messages;
168171

@@ -544,6 +547,27 @@ std::string seashell_compiler_get_object(struct seashell_compiler* compiler) {
544547
#endif
545548
}
546549

550+
#ifndef __EMSCRIPTEN__
551+
extern "C" const char *seashell_compiler_get_dep_paths(struct seashell_compiler *compiler) {
552+
#else
553+
std::string seashell_compiler_get_dep_paths(struct seashell_compiler *compiler) {
554+
#endif
555+
compiler->dep_paths = "";
556+
for(int i=0; i<compiler->source_paths.size(); i++) {
557+
compiler->dep_paths += compiler->source_paths[i];
558+
compiler->dep_paths += " ";
559+
}
560+
for(int i=0; i<compiler->object_paths.size(); i++) {
561+
compiler->dep_paths += compiler->object_paths[i];
562+
compiler->dep_paths += " ";
563+
}
564+
#ifndef __EMSCRIPTEN__
565+
return compiler->dep_paths.c_str();
566+
#else
567+
return compiler->dep_paths;
568+
#endif
569+
}
570+
547571
/**
548572
* seashell_compiler_object_arch (struct seashell_compiler* compiler)
549573
* Returns a string representing the resulting object's architecture, if any.

src/backend/compiler/compiler.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ std::string seashell_compiler_get_diagnostic_message(struct seashell_compiler* c
3636
std::string seashell_compiler_object_arch(struct seashell_compiler* compiler);
3737
std::string seashell_compiler_object_os (struct seashell_compiler* compiler);
3838
std::string seashell_compiler_get_object_dep(struct seashell_compiler *compiler, int k);
39+
std::string seashell_compiler_get_dep_paths(struct seashell_compiler *compiler);
3940
#else
4041
extern "C" const char* seashell_clang_version();
4142
extern "C" void seashell_compiler_set_main_file(struct seashell_compiler *compiler, const char *file);
@@ -49,6 +50,7 @@ extern "C" const char * seashell_compiler_get_diagnostic_message (struct seashel
4950
extern "C" const char* seashell_compiler_object_arch (struct seashell_compiler* compiler);
5051
extern "C" const char* seashell_compiler_object_os (struct seashell_compiler* compiler);
5152
extern "C" const char *seashell_compiler_get_object_dep(struct seashell_compiler *compiler, int k);
53+
extern "C" const char *seashell_compiler_get_dep_paths(struct seashell_compiler *compiler);
5254
#endif
5355
extern "C" struct seashell_compiler* seashell_compiler_make (void);
5456
extern "C" void seashell_compiler_free (struct seashell_compiler* compiler);

src/collects/seashell/compiler/compiler.rkt

+35-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
;;
1717
;; You should have received a copy of the GNU General Public License
1818
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19-
(require seashell/compiler/ffi
19+
(require seashell/compiler/ffi seashell/log
2020
(submod seashell/seashell-config typed))
2121
(require/typed racket/base
2222
[file-position (case-lambda
@@ -162,6 +162,40 @@
162162
;; Remove the object file.
163163
(delete-file object-file)
164164

165+
;;-------------------------------------------------------
166+
;;
167+
;; yc2lee's hack to use clang executable instead of
168+
;; custom Seashell clang/llvm wrapper
169+
;;
170+
171+
(define clang-binary-path (build-path SEASHELL_INSTALL_PATH "bin" "clang-3.9"))
172+
(when (and (equal? 0 linker-res)
173+
(file-exists? clang-binary-path)
174+
(member 'execute (file-or-directory-permissions clang-binary-path)))
175+
(define clang-binary-arguments
176+
`("-std=c99"
177+
"-fsanitize=address" "-fno-omit-frame-pointer" "-fno-common"
178+
"-g" "-O0"
179+
,@(map (lambda ([dir : Path]) (string-append "-I" (path->string dir))) source-dirs)
180+
"-lm"
181+
"-o" ,result-file
182+
,@(string-split (seashell_compiler_get_dep_paths compiler))))
183+
(logf 'info "Running clang compiler: ~a ~a" clang-binary-path clang-binary-arguments)
184+
;; Run the clang executable
185+
(define-values (clang-result clang-stdout clang-stdin clang-stderr)
186+
(apply subprocess #f #f #f clang-binary-path clang-binary-arguments))
187+
(close-output-port clang-stdin)
188+
;; Get stdout and stderr contents
189+
(logf 'info "clang compiler stdout: ~a" (port->string clang-stdout))
190+
(close-input-port clang-stdout)
191+
(logf 'info "clang compiler stderr: ~a" (port->string clang-stderr))
192+
(close-input-port clang-stderr)
193+
(define clang-binary-exit-code (subprocess-status (sync clang-result)))
194+
(logf 'info "clang compiler exited with code ~a" clang-binary-exit-code))
195+
196+
;;
197+
;;---------------------------------------------------
198+
165199
;; Read the result:
166200
(define linker-result
167201
(cond

src/collects/seashell/compiler/ffi.rkt

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
seashell_compiler_get_diagnostic_message
4141
seashell_compiler_run
4242
seashell_compiler_get_object
43+
seashell_compiler_get_dep_paths
4344
seashell_clang_version
4445
seashell_compiler_object_arch
4546
seashell_compiler_object_os
@@ -99,6 +100,8 @@
99100
(memcpy result address size)
100101
result]
101102
[else #f])))))
103+
(define-clang seashell_compiler_get_dep_paths
104+
(_fun _seashell_compiler-ptr -> _string/utf-8))
102105
(define-clang seashell_compiler_get_object_dep_count
103106
(_fun _seashell_compiler-ptr -> _int))
104107
(define-clang seashell_compiler_get_object_dep
@@ -122,6 +125,7 @@
122125
[seashell_compiler_get_diagnostic_column (-> Seashell-Compiler-Ptr Nonnegative-Integer Index)]
123126
[seashell_compiler_get_diagnostic_file (-> Seashell-Compiler-Ptr Nonnegative-Integer String)]
124127
[seashell_compiler_get_diagnostic_message (-> Seashell-Compiler-Ptr Nonnegative-Integer String)]
128+
[seashell_compiler_get_dep_paths (-> Seashell-Compiler-Ptr String)]
125129
[seashell_compiler_run (-> Seashell-Compiler-Ptr Boolean Fixnum)]
126130
[seashell_compiler_object_arch (-> Seashell-Compiler-Ptr String)]
127131
[seashell_compiler_object_os (-> Seashell-Compiler-Ptr String)]
@@ -146,6 +150,7 @@
146150
seashell_compiler_get_diagnostic_message
147151
seashell_compiler_run
148152
seashell_compiler_get_object
153+
seashell_compiler_get_dep_paths
149154
seashell_clang_version
150155
seashell_compiler_object_arch
151156
seashell_compiler_object_os

src/frontend/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class App extends React.Component<AppProps&actionsInterface, AppState> {
1616
}
1717
}
1818

19-
export default withRouter<{}>(map<AppProps>(App));
19+
export default withRouter<AppProps>(map<AppProps>(App));

src/frontend/src/Layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ class Layout extends React.Component<LayoutProps & actionsInterface, LayoutState
3737
}
3838
}
3939

40-
export default withRouter<{}>(map<LayoutProps>(Layout));
40+
export default withRouter<LayoutProps>(map<LayoutProps>(Layout));

src/frontend/src/partials/Navigation/AddProject.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ class AddProjectWindow extends React.Component<AddProjectWindowProps&actionsInte
5959
}
6060
}
6161

62-
export default withRouter<{closefunc: Function}>(map<AddProjectWindowProps>(AddProjectWindow));
62+
export default withRouter<AddProjectWindowProps>(map<AddProjectWindowProps>(AddProjectWindow));

0 commit comments

Comments
 (0)