Skip to content

Commit 68a8d8b

Browse files
committed
---
yaml --- r: 3851 b: refs/heads/master c: 598b50e h: refs/heads/master i: 3849: 7c6b418 3847: 68fddce v: v3
1 parent 8bc26f1 commit 68a8d8b

File tree

6 files changed

+49
-8
lines changed

6 files changed

+49
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 27834c2a65f88a01a897e69b53b106e5021260f6
2+
refs/heads/master: 598b50e10a347b29d235bb99110975b96fdab160

trunk/src/lib/fs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ fn connect(path pre, path post) -> path {
4343

4444
fn file_is_dir(path p) -> bool { ret rustrt::rust_file_is_dir(p) != 0; }
4545

46-
fn list_dir(path p) -> vec[str] {
46+
fn list_dir(path p) -> str[] {
4747
auto pl = str::byte_len(p);
4848
if (pl == 0u || p.(pl - 1u) as char != os_fs::path_sep) {
4949
p += path_sep();
5050
}
51-
let vec[str] full_paths = [];
51+
let str[] full_paths = ~[];
5252
for (str filename in os_fs::list_dir(p)) {
5353
if (!str::eq(filename, ".")) {
5454
if (!str::eq(filename, "..")) {
55-
vec::push[str](full_paths, p + filename);
55+
full_paths += ~[p + filename];
5656
}
5757
}
5858
}

trunk/src/lib/posix_fs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11

22
native "rust" mod rustrt {
33
fn rust_list_files(str path) -> vec[str];
4+
fn rust_list_files_ivec(str path) -> @str[];
45
fn rust_dirent_filename(os::libc::dirent ent) -> str;
56
}
67

7-
fn list_dir(str path) -> vec[str] {
8-
ret rustrt::rust_list_files(path);
8+
fn list_dir(str path) -> str[] {
9+
ret *rustrt::rust_list_files_ivec(path);
910
// TODO ensure this is always closed
1011

1112
// FIXME: No idea why, but this appears to corrupt memory on OSX. I

trunk/src/lib/win32_fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
native "rust" mod rustrt {
44
fn rust_list_files(str path) -> vec[str];
5+
fn rust_list_files_ivec(str path) -> @str[];
56
fn rust_file_is_dir(str path) -> int;
67
}
78

8-
fn list_dir(str path) -> vec[str] { ret rustrt::rust_list_files(path + "*"); }
9+
fn list_dir(str path) -> str[] { ret *rustrt::rust_list_files(path + "*"); }
910

1011
fn path_is_absolute(str p) -> bool {
1112
ret str::char_at(p, 0u) == '/'

trunk/src/rt/rust_builtin.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ debug_opaque(rust_task *task, type_desc *t, uint8_t *front)
454454
}
455455
}
456456

457-
struct rust_box : rc_base<rust_box> {
457+
struct rust_box {
458+
RUST_REFCOUNTED(rust_box)
459+
458460
// FIXME `data` could be aligned differently from the actual box body data
459461
uint8_t data[];
460462
};
@@ -580,6 +582,42 @@ rust_list_files(rust_task *task, rust_str *path) {
580582
sizeof(rust_str*), strings.data());
581583
}
582584

585+
extern "C" CDECL rust_box*
586+
rust_list_files_ivec(rust_task *task, rust_str *path) {
587+
array_list<rust_str*> strings;
588+
#if defined(__WIN32__)
589+
WIN32_FIND_DATA FindFileData;
590+
HANDLE hFind = FindFirstFile((char*)path->data, &FindFileData);
591+
if (hFind != INVALID_HANDLE_VALUE) {
592+
do {
593+
strings.push(c_str_to_rust(task, FindFileData.cFileName));
594+
} while (FindNextFile(hFind, &FindFileData));
595+
FindClose(hFind);
596+
}
597+
#else
598+
DIR *dirp = opendir((char*)path->data);
599+
if (dirp) {
600+
struct dirent *dp;
601+
while ((dp = readdir(dirp)))
602+
strings.push(c_str_to_rust(task, dp->d_name));
603+
closedir(dirp);
604+
}
605+
#endif
606+
rust_box *box = (rust_box *)task->malloc(sizeof(rust_box) +
607+
sizeof(rust_ivec));
608+
box->ref_count = 1;
609+
rust_ivec *iv = (rust_ivec *)&box->data;
610+
iv->fill = 0;
611+
612+
size_t alloc_sz = sizeof(rust_str *) * strings.size();
613+
iv->alloc = alloc_sz;
614+
iv->payload.ptr = (rust_ivec_heap *)
615+
task->kernel->malloc(alloc_sz + sizeof(size_t));
616+
iv->payload.ptr->fill = alloc_sz;
617+
memcpy(&iv->payload.ptr->data, strings.data(), alloc_sz);
618+
return box;
619+
}
620+
583621
#if defined(__WIN32__)
584622
extern "C" CDECL rust_str *
585623
rust_dirent_filename(rust_task *task, void* ent) {

trunk/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rust_file_is_dir
2929
rust_get_stdin
3030
rust_get_stdout
3131
rust_list_files
32+
rust_list_files_ivec
3233
rust_process_wait
3334
rust_ptr_eq
3435
rust_run_program

0 commit comments

Comments
 (0)