diff --git a/core/bufio/read_writer.odin b/core/bufio/read_writer.odin index ccd59a398..f9ae1ed45 100644 --- a/core/bufio/read_writer.odin +++ b/core/bufio/read_writer.odin @@ -15,12 +15,12 @@ read_writer_init :: proc(rw: ^Read_Writer, r: ^Reader, w: ^Writer) { read_writer_to_stream :: proc(rw: ^Read_Writer) -> (s: io.Stream) { s.stream_data = rw - s.stream_vtable = _read_writer_vtable + s.stream_vtable = &_read_writer_vtable return } @(private) -_read_writer_vtable := &io.Stream_VTable{ +_read_writer_vtable := io.Stream_VTable{ impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { b := (^Read_Writer)(s.stream_data).r return reader_read(b, p) diff --git a/core/bufio/reader.odin b/core/bufio/reader.odin index f17519656..6bfc4cd9d 100644 --- a/core/bufio/reader.odin +++ b/core/bufio/reader.odin @@ -353,14 +353,14 @@ reader_write_to :: proc(b: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) { // reader_to_stream converts a Reader into an io.Stream reader_to_stream :: proc(b: ^Reader) -> (s: io.Stream) { s.stream_data = b - s.stream_vtable = _reader_vtable + s.stream_vtable = &_reader_vtable return } @(private) -_reader_vtable := &io.Stream_VTable{ +_reader_vtable := io.Stream_VTable{ impl_destroy = proc(s: io.Stream) -> io.Error { b := (^Reader)(s.stream_data) reader_destroy(b) diff --git a/core/bufio/writer.odin b/core/bufio/writer.odin index 861358526..9e38395ee 100644 --- a/core/bufio/writer.odin +++ b/core/bufio/writer.odin @@ -223,14 +223,14 @@ writer_read_from :: proc(b: ^Writer, r: io.Reader) -> (n: i64, err: io.Error) { // writer_to_stream converts a Writer into an io.Stream writer_to_stream :: proc(b: ^Writer) -> (s: io.Stream) { s.stream_data = b - s.stream_vtable = _writer_vtable + s.stream_vtable = &_writer_vtable return } @(private) -_writer_vtable := &io.Stream_VTable{ +_writer_vtable := io.Stream_VTable{ impl_destroy = proc(s: io.Stream) -> io.Error { b := (^Writer)(s.stream_data) writer_destroy(b) diff --git a/core/bytes/buffer.odin b/core/bytes/buffer.odin index 96f057a9b..d9f195871 100644 --- a/core/bytes/buffer.odin +++ b/core/bytes/buffer.odin @@ -374,12 +374,12 @@ buffer_read_from :: proc(b: ^Buffer, r: io.Reader) -> (n: i64, err: io.Error) #n buffer_to_stream :: proc(b: ^Buffer) -> (s: io.Stream) { s.stream_data = b - s.stream_vtable = _buffer_vtable + s.stream_vtable = &_buffer_vtable return } @(private) -_buffer_vtable := &io.Stream_VTable{ +_buffer_vtable := io.Stream_VTable{ impl_size = proc(s: io.Stream) -> i64 { b := (^Buffer)(s.stream_data) return i64(buffer_capacity(b)) diff --git a/core/bytes/reader.odin b/core/bytes/reader.odin index b10fd009c..7c37f3061 100644 --- a/core/bytes/reader.odin +++ b/core/bytes/reader.odin @@ -17,7 +17,7 @@ reader_init :: proc(r: ^Reader, s: []byte) { reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) { s.stream_data = r - s.stream_vtable = _reader_vtable + s.stream_vtable = &_reader_vtable return } @@ -137,7 +137,7 @@ reader_write_to :: proc(r: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) { @(private) -_reader_vtable := &io.Stream_VTable{ +_reader_vtable := io.Stream_VTable{ impl_size = proc(s: io.Stream) -> i64 { r := (^Reader)(s.stream_data) return reader_size(r) diff --git a/core/fmt/fmt_js.odin b/core/fmt/fmt_js.odin index 7a9876127..7f6008889 100644 --- a/core/fmt/fmt_js.odin +++ b/core/fmt/fmt_js.odin @@ -11,7 +11,7 @@ foreign odin_env { } @(private="file") -write_vtable := &io.Stream_VTable{ +write_vtable := io.Stream_VTable{ impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { fd := u32(uintptr(s.stream_data)) write(fd, p) @@ -22,14 +22,14 @@ write_vtable := &io.Stream_VTable{ @(private="file") stdout := io.Writer{ stream = { - stream_vtable = write_vtable, + stream_vtable = &write_vtable, stream_data = rawptr(uintptr(1)), }, } @(private="file") stderr := io.Writer{ stream = { - stream_vtable = write_vtable, + stream_vtable = &write_vtable, stream_data = rawptr(uintptr(2)), }, } diff --git a/core/os/os2/file_stream.odin b/core/os/os2/file_stream.odin index 5e3db9370..7edbd68fa 100644 --- a/core/os/os2/file_stream.odin +++ b/core/os/os2/file_stream.odin @@ -4,7 +4,7 @@ import "core:io" to_stream :: proc(f: ^File) -> (s: io.Stream) { s.stream_data = f - s.stream_vtable = _file_stream_vtable + s.stream_vtable = &_file_stream_vtable return } @@ -26,7 +26,7 @@ error_to_io_error :: proc(ferr: Error) -> io.Error { @(private) -_file_stream_vtable := &io.Stream_VTable{ +_file_stream_vtable := io.Stream_VTable{ impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { f := (^File)(s.stream_data) ferr: Error diff --git a/core/os/stream.odin b/core/os/stream.odin index 2c6e1d47f..9506ed3a3 100644 --- a/core/os/stream.odin +++ b/core/os/stream.odin @@ -5,13 +5,13 @@ import "core:io" stream_from_handle :: proc(fd: Handle) -> io.Stream { s: io.Stream s.stream_data = rawptr(uintptr(fd)) - s.stream_vtable = _file_stream_vtable + s.stream_vtable = &_file_stream_vtable return s } @(private) -_file_stream_vtable := &io.Stream_VTable{ +_file_stream_vtable := io.Stream_VTable{ impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { fd := Handle(uintptr(s.stream_data)) os_err: Errno diff --git a/core/strings/builder.odin b/core/strings/builder.odin index 6de42804d..0386431f1 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -67,7 +67,7 @@ builder_init :: proc{ } @(private) -_builder_stream_vtable := &io.Stream_VTable{ +_builder_stream_vtable := io.Stream_VTable{ impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { b := (^Builder)(s.stream_data) n = write_bytes(b, p) @@ -97,7 +97,7 @@ _builder_stream_vtable := &io.Stream_VTable{ // return an `io.Stream` from a builder to_stream :: proc(b: ^Builder) -> io.Stream { - return io.Stream{stream_vtable=_builder_stream_vtable, stream_data=b} + return io.Stream{stream_vtable=&_builder_stream_vtable, stream_data=b} } // return an `io.Writer` from a builder diff --git a/core/strings/reader.odin b/core/strings/reader.odin index a38f1fbe4..038740526 100644 --- a/core/strings/reader.odin +++ b/core/strings/reader.odin @@ -24,7 +24,7 @@ reader_init :: proc(r: ^Reader, s: string) { // returns a stream from the reader data reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) { s.stream_data = r - s.stream_vtable = _reader_vtable + s.stream_vtable = &_reader_vtable return } @@ -177,7 +177,7 @@ reader_write_to :: proc(r: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) { } @(private) -_reader_vtable := &io.Stream_VTable{ +_reader_vtable := io.Stream_VTable{ impl_size = proc(s: io.Stream) -> i64 { r := (^Reader)(s.stream_data) return reader_size(r) diff --git a/core/sys/darwin/xnu_system_call_helpers.odin b/core/sys/darwin/xnu_system_call_helpers.odin index 94fe0bf47..9522b9908 100644 --- a/core/sys/darwin/xnu_system_call_helpers.odin +++ b/core/sys/darwin/xnu_system_call_helpers.odin @@ -1,11 +1,11 @@ package darwin -import "core:strings" import "core:c" +import "core:runtime" // this package uses the sys prefix for the proc names to indicate that these aren't native syscalls but directly call such sys_write_string :: proc (fd: c.int, message: string) -> bool { - return syscall_write(fd, strings.ptr_from_string(message), cast(u64)len(message)) + return syscall_write(fd, raw_data(message), cast(u64)len(message)) } Offset_From :: enum c.int { @@ -87,11 +87,20 @@ _sys_permission_mode :: #force_inline proc (mode: Permission) -> u32 { return cflags } +@(private) +clone_to_cstring :: proc(s: string, allocator: runtime.Allocator, loc := #caller_location) -> cstring { + c := make([]byte, len(s)+1, allocator, loc) + copy(c, s) + c[len(s)] = 0 + return cstring(&c[0]) +} + + sys_open :: proc(path: string, oflag: Open_Flags, mode: Permission) -> (c.int, bool) { cmode: u32 = 0 cflags: u32 = 0 - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags = _sys_permission_mode(mode) @@ -123,32 +132,32 @@ sys_open :: proc(path: string, oflag: Open_Flags, mode: Permission) -> (c.int, b } sys_mkdir :: proc(path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags := _sys_permission_mode(mode) return syscall_mkdir(cpath, cflags) != -1 } sys_mkdir_at :: proc(fd: c.int, path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags := _sys_permission_mode(mode) return syscall_mkdir_at(fd, cpath, cflags) != -1 } sys_rmdir :: proc(path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags := _sys_permission_mode(mode) return syscall_rmdir(cpath, cflags) != -1 } sys_rename :: proc(path: string, new_path: string) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) - cnpath: cstring = strings.clone_to_cstring(new_path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) + cnpath: cstring = clone_to_cstring(new_path, context.temp_allocator) return syscall_rename(cpath, cnpath) != -1 } sys_rename_at :: proc(fd: c.int, path: string, to_fd: c.int, new_path: string) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) - cnpath: cstring = strings.clone_to_cstring(new_path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) + cnpath: cstring = clone_to_cstring(new_path, context.temp_allocator) return syscall_rename_at(fd, cpath, to_fd, cnpath) != -1 } @@ -157,12 +166,12 @@ sys_lseek :: proc(fd: c.int, offset: i64, whence: Offset_From) -> i64 { } sys_chmod :: proc(path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cmode := _sys_permission_mode(mode) return syscall_chmod(cpath, cmode) != -1 } sys_lstat :: proc(path: string, status: ^stat) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) return syscall_lstat(cpath, status) != -1 } diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 45e597a9e..53c7c4dcb 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -390,6 +390,9 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc Entity *e = entity_from_expr(expr); res = lb_find_procedure_value_from_entity(m, e); } + GB_ASSERT(res.value != nullptr); + GB_ASSERT(LLVMGetValueKind(res.value) == LLVMFunctionValueKind); + res.value = LLVMConstPointerCast(res.value, lb_type(m, res.type)); return res; }