Skip to content

Commit

Permalink
refact(c/libc): fix improper use of &uint8 to represent a C string
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Nov 6, 2023
1 parent 1a8e502 commit 8129789
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/c/src/libc/dirent.ri
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct dirent {
}

extern (C) {
public func opendir(d: &uint8) -> ?&dirent;
public func opendir(d: [&]uint8) -> ?&dirent;
public func readdir(d: &dirent) -> ?&dirent;
public func closedir(d: &dirent) -> int32;
}
2 changes: 1 addition & 1 deletion lib/c/src/libc/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// be found in the LICENSE file.

extern (C) {
public static environ: [&]&uint8;
public static environ: [&][&]uint8;
}
6 changes: 3 additions & 3 deletions lib/c/src/libc/stat.ri
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public struct Stat {
#endif

extern (C) {
public func stat(__file: &uint8, __buf: &mut Stat) -> int32;
public func lstat(file: &uint8, buf: &mut Stat) -> int32;
public func stat(__file: [&]uint8, __buf: &mut Stat) -> int32;
public func lstat(file: [&]uint8, buf: &mut Stat) -> int32;

public func mkdir(path: &uint8, mode: usize) -> int32;
public func mkdir(path: [&]uint8, mode: usize) -> int32;
}
8 changes: 4 additions & 4 deletions lib/c/src/libc/stdio.ri
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ public struct FILE;
#endif

extern (C) {
public func fopen(path: &uint8, mode: &uint8) -> ?&mut FILE;
public func fopen(path: [&]uint8, mode: [&]uint8) -> ?&mut FILE;
public func feof(stream: &FILE) -> int32;
public func ferror(stream: &FILE) -> int32;
public func fseek(stream: &mut FILE, offset: uint64, whence: int32) -> int32;
public func ftell(stream: &mut FILE) -> int64;
public func fread(ptr: rawptr, size: usize, nitems: usize, stream: &mut FILE) -> usize;
public func fputc(c: int32, stream: &mut FILE) -> int32;
public func fputs(s: &uint8, stream: &mut FILE) -> int32;
public func fprintf(stream: &mut FILE, fmt: &uint8, ...) -> int32;
public func fputs(s: [&]uint8, stream: &mut FILE) -> int32;
public func fprintf(stream: &mut FILE, fmt: [&]uint8, ...) -> int32;
public func fwrite(ptr: rawptr, size: usize, nobj: usize, stream: &mut FILE) -> usize;
public func fflush(stream: &mut FILE) -> int32;
public func fgets(s: &mut uint8, n: usize, stream: &mut FILE) -> int32;
public func fgets(s: [&]mut uint8, n: usize, stream: &mut FILE) -> int32;
public func fclose(stream: &mut FILE) -> int32;
public func fileno(stream: &FILE) -> int32;
public func rewind(stream: &mut FILE);
Expand Down
20 changes: 10 additions & 10 deletions lib/c/src/libc/stdlib.ri
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ extern (C) {
public func rand() -> int32;
public func srand(seed: uint32);

public func atof(nptr: ?&uint8) -> float64;
public func atoi(nptr: ?&uint8) -> int32;
public func atol(nptr: ?&uint8) -> int64;
public func atoll(nptr: ?&uint8) -> int64;
public func atof(nptr: ?[&]uint8) -> float64;
public func atoi(nptr: ?[&]uint8) -> int32;
public func atol(nptr: ?[&]uint8) -> int64;
public func atoll(nptr: ?[&]uint8) -> int64;

public func strtod(nptr: [&]uint8, endptr: ?&uint8, base_: int32) -> float64;
public func strtof(nptr: [&]uint8, endptr: ?&uint8, base_: int32) -> float32;
public func strtol(nptr: [&]uint8, endptr: ?&uint8, base_: int32) -> int64;
public func strtoll(nptr: [&]uint8, endptr: ?&uint8, base_: int32) -> int64;
public func strtoul(nptr: [&]uint8, endptr: ?&uint8, base_: int32) -> uint64;
public func strtoull(nptr: [&]uint8, endptr: ?&uint8, base_: int32) -> uint64;
public func strtod(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> float64;
public func strtof(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> float32;
public func strtol(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> int64;
public func strtoll(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> int64;
public func strtoul(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> uint64;
public func strtoull(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> uint64;

public func malloc(size: usize) -> ?rawptr;
public func calloc(nobj: usize, size: usize) -> ?rawptr;
Expand Down
10 changes: 5 additions & 5 deletions lib/c/src/libc/unistd.ri
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// be found in the LICENSE file.

extern (C) {
public func access(a: &uint8, o: int32) -> int32;
public func access(a: [&]uint8, o: int32) -> int32;

public func sysconf(name: int32) -> int64;

Expand All @@ -15,11 +15,11 @@ extern (C) {
public func write(fd: int32, buf: rawptr, count: usize) -> isize;
public func read(fildes: int32, buf: rawptr, nbyte: usize) -> isize;

public func rmdir(path: &uint8) -> int32;
public func chdir(path: &uint8) -> int32;
public func getcwd(buf: &uint8, size: usize) -> ?&uint8;
public func rmdir(path: [&]uint8) -> int32;
public func chdir(path: [&]uint8) -> int32;
public func getcwd(buf: [&]uint8, size: usize) -> ?[&]uint8;

public func readlink(path: &uint8, buf: &uint8, size: usize) -> isize;
public func readlink(path: [&]uint8, buf: [&]uint8, size: usize) -> isize;

#if _LINUX_
public func get_nprocs() -> int32;
Expand Down
4 changes: 3 additions & 1 deletion lib/core/src/StringBuilder.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public struct StringBuilder < Stringable {
Self.new()
} else {
Self(unsafe {
Vector.from_array(@as(&mut uint8, s.ptr), @size_of(uint8), s.len)
Vector.from_array(
@as(&mut uint8, s.ptr), @size_of(uint8), s.len
)
})
};
}
Expand Down
4 changes: 3 additions & 1 deletion lib/core/src/string.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ public struct string < Stringable, Hashable, Throwable {
#[inline]
public func as_bytes(self) -> []uint8 {
return unsafe {
Vector.from_array_no_alloc(@as(&mut uint8, self.ptr), @size_of(uint8), self.len)
Vector.from_array_no_alloc(
@as(&mut uint8, self.ptr), @size_of(uint8), self.len
)
};
}

Expand Down

0 comments on commit 8129789

Please sign in to comment.