Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/nol888/parrot into separato…
Browse files Browse the repository at this point in the history
…r_fixes
  • Loading branch information
Whiteknight committed Nov 26, 2011
2 parents ec76d8c + 7c16288 commit 04379ec
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
11 changes: 11 additions & 0 deletions include/parrot/library.h
Expand Up @@ -57,6 +57,14 @@ void Parrot_lib_add_path_from_cstring(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);

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
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/dynpmc/os.pmc
Expand Up @@ -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);
}

Expand Down
58 changes: 24 additions & 34 deletions src/library.c
Expand Up @@ -28,13 +28,6 @@ dynext files (via C<loadlib>).
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

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)
Expand Down Expand Up @@ -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 = (\
Expand Down Expand Up @@ -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)>
Expand Down Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -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
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}

/*
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/*
Expand Down
13 changes: 9 additions & 4 deletions src/string/api.c
Expand Up @@ -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;
Expand Down

0 comments on commit 04379ec

Please sign in to comment.