Permalink
Browse files

Merge branch 'master' of git://github.com/nol888/parrot into separato…

…r_fixes
  • Loading branch information...
2 parents ec76d8c + 7c16288 commit 04379ec7f2cc92dd061f8c1ca0051dde5f323743 @Whiteknight Whiteknight committed Nov 26, 2011
Showing with 45 additions and 39 deletions.
  1. +11 −0 include/parrot/library.h
  2. +1 −1 src/dynpmc/os.pmc
  3. +24 −34 src/library.c
  4. +9 −4 src/string/api.c
@@ -59,6 +59,14 @@ void Parrot_lib_add_path_from_cstring(PARROT_INTERP,
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+STRING * Parrot_lib_fix_path_separator(PARROT_INTERP,
+ ARGIN(const STRING *path))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
STRING* Parrot_lib_search_paths_as_string(PARROT_INTERP,
enum_runtime_ft type)
@@ -113,6 +121,9 @@ void parrot_init_library_paths(PARROT_INTERP)
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(path))
+#define ASSERT_ARGS_Parrot_lib_fix_path_separator __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(path))
#define ASSERT_ARGS_Parrot_lib_search_paths_as_string \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
View
@@ -101,7 +101,7 @@ Returns the current working directory.
*/
METHOD cwd() {
- STRING * const cwd = Parrot_file_getcwd(INTERP);
+ STRING * const cwd = Parrot_lib_fix_path_separator(INTERP, Parrot_file_getcwd(INTERP));
RETURN(STRING *cwd);
}
View
@@ -30,13 +30,6 @@ dynext files (via C<loadlib>).
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
-static STRING * cnv_to_win32_filesep(PARROT_INTERP,
- ARGIN(const STRING *path))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
static PMC* get_search_paths(PARROT_INTERP, enum_lib_paths which)
__attribute__nonnull__(1);
@@ -73,9 +66,6 @@ static STRING* try_load_path(PARROT_INTERP, ARGIN(STRING* path))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
-#define ASSERT_ARGS_cnv_to_win32_filesep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(path))
#define ASSERT_ARGS_get_search_paths __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_is_abs_path __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -319,13 +309,8 @@ get_search_paths(PARROT_INTERP, enum_lib_paths which)
}
static const int path_separator = '/';
-
-#ifdef WIN32
-
static const int win32_path_separator = '\\';
-#endif
-
/*
=item C<static int is_abs_path(PARROT_INTERP, const STRING *file)>
@@ -372,27 +357,34 @@ is_abs_path(PARROT_INTERP, ARGIN(const STRING *file))
}
-#ifdef WIN32
-
/*
-=item C<static STRING * cnv_to_win32_filesep(PARROT_INTERP, const STRING *path)>
+=item C<STRING * Parrot_lib_fix_path_separator(PARROT_INTERP, const STRING
+*path)>
-Converts a path with forward slashes to one with backward slashes.
+Converts path separators in a path to use the current platform's separators.
=cut
*/
+PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
-static STRING *
-cnv_to_win32_filesep(PARROT_INTERP, ARGIN(const STRING *path))
+STRING *
+Parrot_lib_fix_path_separator(PARROT_INTERP, ARGIN(const STRING *path))
{
- ASSERT_ARGS(cnv_to_win32_filesep)
+ ASSERT_ARGS(Parrot_lib_fix_path_separator)
const UINTVAL len = STRING_length(path);
- STRING *res = Parrot_str_new_noinit(interp, path->bufused);
+ STRING *res = Parrot_str_new(interp, "", path->bufused);
String_iter src, dst;
+#ifdef WIN32
+ const INTVAL find = path_separator;
+ const INTVAL replace = win32_path_separator;
+#else
+ const INTVAL find = win32_path_separator;
+ const INTVAL replace = path_separator;
+#endif
res->encoding = path->encoding;
@@ -402,8 +394,8 @@ cnv_to_win32_filesep(PARROT_INTERP, ARGIN(const STRING *path))
while (src.charpos < len) {
INTVAL c = STRING_iter_get_and_advance(interp, path, &src);
- if (c == path_separator)
- c = win32_path_separator;
+ if (c == find)
+ c = replace;
STRING_iter_set_and_advance(interp, res, &dst, c);
}
@@ -414,8 +406,6 @@ cnv_to_win32_filesep(PARROT_INTERP, ARGIN(const STRING *path))
return res;
}
-#endif
-
/*
=item C<static STRING* path_guarantee_trailing_separator(PARROT_INTERP, STRING
@@ -441,7 +431,7 @@ path_guarantee_trailing_separator(PARROT_INTERP, ARGIN(STRING *path))
path = Parrot_str_concat(interp, path,
Parrot_str_chr(interp, path_separator));
- return path;
+ return Parrot_lib_fix_path_separator(interp, path);
}
/*
@@ -469,7 +459,7 @@ path_concat(PARROT_INTERP, ARGIN(STRING *l_path),
join = path_guarantee_trailing_separator(interp, l_path);
join = Parrot_str_concat(interp, join, r_path);
- return join;
+ return Parrot_lib_fix_path_separator(interp, join);
}
/*
@@ -490,10 +480,7 @@ static STRING*
try_load_path(PARROT_INTERP, ARGIN(STRING* path))
{
ASSERT_ARGS(try_load_path)
-
-#ifdef WIN32
- path = cnv_to_win32_filesep(interp, path);
-#endif
+ path = Parrot_lib_fix_path_separator(interp, path);
if (Parrot_file_stat_intval(interp, path, STAT_EXISTS)) {
return path;
@@ -604,6 +591,7 @@ Parrot_lib_add_path(PARROT_INTERP,
PMC * const lib_paths = VTABLE_get_pmc_keyed_int(interp, iglobals,
IGLOBALS_LIB_PATHS);
PMC * const paths = VTABLE_get_pmc_keyed_int(interp, lib_paths, which);
+ path_str = Parrot_lib_fix_path_separator(interp, path_str);
VTABLE_unshift_string(interp, paths, path_str);
}
@@ -656,6 +644,8 @@ Parrot_locate_runtime_file_str(PARROT_INTERP, ARGIN(STRING *file),
PMC *paths;
INTVAL i, n;
+ file = Parrot_lib_fix_path_separator(interp, file);
+
/* if this is an absolute path return it as is */
if (is_abs_path(interp, file))
return file;
@@ -783,7 +773,7 @@ Parrot_get_runtime_path(PARROT_INTERP)
else
result = CONST_STRING(interp, ".");
}
- return result;
+ return Parrot_lib_fix_path_separator(interp, result);
}
/*
View
@@ -674,10 +674,15 @@ Parrot_str_new_init(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), UINTVAL len
Parrot_gc_allocate_string_storage(interp, s, len);
- if (buffer && len) {
- mem_sys_memcopy(s->strstart, buffer, len);
- s->bufused = len;
- STRING_scan(interp, s);
+ if (len) {
+ if (buffer) {
+ mem_sys_memcopy(s->strstart, buffer, len);
+ s->bufused = len;
+ STRING_scan(interp, s);
+ }
+ else {
+ s->bufused = len;
+ }
}
else
s->strlen = s->bufused = 0;

0 comments on commit 04379ec

Please sign in to comment.