From 36f7b7051e118005e993641fde9ae7ea0f0b8212 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 25 Jun 2013 09:40:19 +0200 Subject: [PATCH] drop non-relative paths in procedure source locations A path that is not relative to the enclosing file can show up due to cross-module inlining. Package-based modules do not have a good relative path to "collects", which creates trouble for distributing compiled modules where, say, `map' was inlined. It might be possible to keep the path in module-path-index form so that a path can be constructed appropriately at run time, but it's much simpler to just punt on function source locations in this relatively rare case. --- racket/src/racket/src/marshal.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/racket/src/racket/src/marshal.c b/racket/src/racket/src/marshal.c index e351d0036c..b32f349f58 100644 --- a/racket/src/racket/src/marshal.c +++ b/racket/src/racket/src/marshal.c @@ -679,6 +679,21 @@ static Scheme_Object *read_quote_syntax(Scheme_Object *obj) #define BOOL(x) (x ? scheme_true : scheme_false) +static int not_relative_path(Scheme_Object *p) +{ + Scheme_Object *dir, *rel_p; + + dir = scheme_get_param(scheme_current_config(), + MZCONFIG_WRITE_DIRECTORY); + if (SCHEME_TRUEP(dir)) { + rel_p = scheme_extract_relative_to(p, dir); + if (SAME_OBJ(rel_p, p)) + return 1; + } + + return 0; +} + static Scheme_Object *write_compiled_closure(Scheme_Object *obj) { Scheme_Closure_Data *data; @@ -695,8 +710,12 @@ static Scheme_Object *write_compiled_closure(Scheme_Object *obj) paths, symbols, and strings: */ Scheme_Object *src; src = SCHEME_VEC_ELS(name)[1]; - if (!SCHEME_PATHP(src) - && !SCHEME_PATHP(src) + if ((!SCHEME_PATHP(src) + /* If MZCONFIG_WRITE_DIRECTORY, drop any non-relative path + (which might happen due to function inlining, for example) + to avoid embedding absolute paths in bytecode files: */ + || not_relative_path(src)) + && !SCHEME_CHAR_STRINGP(src) && !SCHEME_SYMBOLP(src)) { /* Just keep the name */ name = SCHEME_VEC_ELS(name)[0];