diff --git a/lib/glacier/string/str_format.cpp b/lib/glacier/string/str_format.cpp index 8b9fef8..afdff66 100644 --- a/lib/glacier/string/str_format.cpp +++ b/lib/glacier/string/str_format.cpp @@ -70,11 +70,6 @@ void StrFormatValue(StringBuilder& builder, StringView value, StringView opts) { StrFormatInternal(builder, value); } -template <> -void StrFormatValue(StringBuilder& builder, String value, StringView opts) { - StrFormatInternal(builder, value); -} - void StrFormatInternal(StringBuilder& builder, StringView format) { // TODO: Consider throwing an error if there are unhandled format builder.PushBack(format); diff --git a/lib/glacier/string/str_format.h b/lib/glacier/string/str_format.h index 547d608..3f13ec4 100644 --- a/lib/glacier/string/str_format.h +++ b/lib/glacier/string/str_format.h @@ -37,9 +37,6 @@ void StrFormatValue(StringBuilder& builder, const char* value, StringView opts); template <> void StrFormatValue(StringBuilder& builder, StringView value, StringView opts); -template <> -void StrFormatValue(StringBuilder& builder, String value, StringView opts); - void StrFormatInternal(StringBuilder& builder, StringView format); template diff --git a/lib/glacier/string/string.cpp b/lib/glacier/string/string.cpp index c92aa9d..3e7cc16 100644 --- a/lib/glacier/string/string.cpp +++ b/lib/glacier/string/string.cpp @@ -46,5 +46,6 @@ char String::operator[](uint64_t offset) const { } String::operator StringView() const { return StringView(cstr_, length_); } +StringView String::view() const { return this->operator StringView(); } } // namespace glcr diff --git a/lib/glacier/string/string.h b/lib/glacier/string/string.h index e220395..a1c3d8f 100644 --- a/lib/glacier/string/string.h +++ b/lib/glacier/string/string.h @@ -13,13 +13,17 @@ class String { String(const char* cstr, uint64_t str_len); String(StringView str); + String(const String&) = delete; + const char* cstr() const { return cstr_; } uint64_t length() const { return length_; } bool operator==(const String& str); char operator[](uint64_t offset) const; + operator StringView() const; + StringView view() const; private: char* cstr_; diff --git a/sys/denali/lib/denali/denali.yunq.h b/sys/denali/lib/denali/denali.yunq.h index 03b1d0b..79d7322 100644 --- a/sys/denali/lib/denali/denali.yunq.h +++ b/sys/denali/lib/denali/denali.yunq.h @@ -17,11 +17,11 @@ class ReadRequest { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - uint64_t device_id() const { return device_id_; } + const uint64_t& device_id() const { return device_id_; } void set_device_id(const uint64_t& value) { device_id_ = value; } - uint64_t lba() const { return lba_; } + const uint64_t& lba() const { return lba_; } void set_lba(const uint64_t& value) { lba_ = value; } - uint64_t size() const { return size_; } + const uint64_t& size() const { return size_; } void set_size(const uint64_t& value) { size_ = value; } private: @@ -43,7 +43,7 @@ class ReadManyRequest { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - uint64_t device_id() const { return device_id_; } + const uint64_t& device_id() const { return device_id_; } void set_device_id(const uint64_t& value) { device_id_ = value; } const glcr::Vector& lba() const { return lba_; } void add_lba(const uint64_t& value) { lba_.PushBack(value); } @@ -66,11 +66,11 @@ class ReadResponse { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - uint64_t device_id() const { return device_id_; } + const uint64_t& device_id() const { return device_id_; } void set_device_id(const uint64_t& value) { device_id_ = value; } - uint64_t size() const { return size_; } + const uint64_t& size() const { return size_; } void set_size(const uint64_t& value) { size_ = value; } - z_cap_t memory() const { return memory_; } + const z_cap_t& memory() const { return memory_; } void set_memory(const z_cap_t& value) { memory_ = value; } private: diff --git a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h index 7965670..baa88d1 100644 --- a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h +++ b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.h @@ -17,7 +17,7 @@ class OpenFileRequest { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - glcr::String path() const { return path_; } + const glcr::String& path() const { return path_; } void set_path(const glcr::String& value) { path_ = value; } private: @@ -37,11 +37,11 @@ class OpenFileResponse { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - glcr::String path() const { return path_; } + const glcr::String& path() const { return path_; } void set_path(const glcr::String& value) { path_ = value; } - uint64_t size() const { return size_; } + const uint64_t& size() const { return size_; } void set_size(const uint64_t& value) { size_ = value; } - z_cap_t memory() const { return memory_; } + const z_cap_t& memory() const { return memory_; } void set_memory(const z_cap_t& value) { memory_ = value; } private: diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h index e094d7d..797240f 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h @@ -17,9 +17,9 @@ class RegisterEndpointRequest { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - glcr::String endpoint_name() const { return endpoint_name_; } + const glcr::String& endpoint_name() const { return endpoint_name_; } void set_endpoint_name(const glcr::String& value) { endpoint_name_ = value; } - z_cap_t endpoint_capability() const { return endpoint_capability_; } + const z_cap_t& endpoint_capability() const { return endpoint_capability_; } void set_endpoint_capability(const z_cap_t& value) { endpoint_capability_ = value; } private: @@ -57,9 +57,9 @@ class AhciInfo { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - z_cap_t ahci_region() const { return ahci_region_; } + const z_cap_t& ahci_region() const { return ahci_region_; } void set_ahci_region(const z_cap_t& value) { ahci_region_ = value; } - uint64_t region_length() const { return region_length_; } + const uint64_t& region_length() const { return region_length_; } void set_region_length(const uint64_t& value) { region_length_ = value; } private: @@ -80,29 +80,29 @@ class FramebufferInfo { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - uint64_t address_phys() const { return address_phys_; } + const uint64_t& address_phys() const { return address_phys_; } void set_address_phys(const uint64_t& value) { address_phys_ = value; } - uint64_t width() const { return width_; } + const uint64_t& width() const { return width_; } void set_width(const uint64_t& value) { width_ = value; } - uint64_t height() const { return height_; } + const uint64_t& height() const { return height_; } void set_height(const uint64_t& value) { height_ = value; } - uint64_t pitch() const { return pitch_; } + const uint64_t& pitch() const { return pitch_; } void set_pitch(const uint64_t& value) { pitch_ = value; } - uint64_t bpp() const { return bpp_; } + const uint64_t& bpp() const { return bpp_; } void set_bpp(const uint64_t& value) { bpp_ = value; } - uint64_t memory_model() const { return memory_model_; } + const uint64_t& memory_model() const { return memory_model_; } void set_memory_model(const uint64_t& value) { memory_model_ = value; } - uint64_t red_mask_size() const { return red_mask_size_; } + const uint64_t& red_mask_size() const { return red_mask_size_; } void set_red_mask_size(const uint64_t& value) { red_mask_size_ = value; } - uint64_t red_mask_shift() const { return red_mask_shift_; } + const uint64_t& red_mask_shift() const { return red_mask_shift_; } void set_red_mask_shift(const uint64_t& value) { red_mask_shift_ = value; } - uint64_t green_mask_size() const { return green_mask_size_; } + const uint64_t& green_mask_size() const { return green_mask_size_; } void set_green_mask_size(const uint64_t& value) { green_mask_size_ = value; } - uint64_t green_mask_shift() const { return green_mask_shift_; } + const uint64_t& green_mask_shift() const { return green_mask_shift_; } void set_green_mask_shift(const uint64_t& value) { green_mask_shift_ = value; } - uint64_t blue_mask_size() const { return blue_mask_size_; } + const uint64_t& blue_mask_size() const { return blue_mask_size_; } void set_blue_mask_size(const uint64_t& value) { blue_mask_size_ = value; } - uint64_t blue_mask_shift() const { return blue_mask_shift_; } + const uint64_t& blue_mask_shift() const { return blue_mask_shift_; } void set_blue_mask_shift(const uint64_t& value) { blue_mask_shift_ = value; } private: @@ -133,11 +133,11 @@ class DenaliInfo { void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - z_cap_t denali_endpoint() const { return denali_endpoint_; } + const z_cap_t& denali_endpoint() const { return denali_endpoint_; } void set_denali_endpoint(const z_cap_t& value) { denali_endpoint_ = value; } - uint64_t device_id() const { return device_id_; } + const uint64_t& device_id() const { return device_id_; } void set_device_id(const uint64_t& value) { device_id_ = value; } - uint64_t lba_offset() const { return lba_offset_; } + const uint64_t& lba_offset() const { return lba_offset_; } void set_lba_offset(const uint64_t& value) { lba_offset_ = value; } private: diff --git a/sys/yellowstone/yellowstone_server.cpp b/sys/yellowstone/yellowstone_server.cpp index 5ae938e..978e4fd 100644 --- a/sys/yellowstone/yellowstone_server.cpp +++ b/sys/yellowstone/yellowstone_server.cpp @@ -92,7 +92,7 @@ glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&, glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint( const RegisterEndpointRequest& req, Empty&) { - dbgln("Registering {}.", req.endpoint_name()); + dbgln("Registering {}.", req.endpoint_name().view()); if (req.endpoint_name() == "denali") { // FIXME: Rather than blocking and calling the denali service // immediately we should signal the main thread that it can continue init. diff --git a/yunq/message.h.jinja b/yunq/message.h.jinja index 93a29fc..e64c0ee 100644 --- a/yunq/message.h.jinja +++ b/yunq/message.h.jinja @@ -23,7 +23,7 @@ class {{message.name}} { {%- for field in message.fields %} {%- if not field.repeated %} - {{field.cpp_type()}} {{field.name}}() const { return {{field.name}}_; } + const {{field.cpp_type()}}& {{field.name}}() const { return {{field.name}}_; } void set_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_ = value; } {%- else %} const glcr::Vector<{{field.cpp_type()}}>& {{field.name}}() const { return {{field.name}}_; } diff --git a/zion/loader/init_loader.cpp b/zion/loader/init_loader.cpp index cb95b85..5a7fa3e 100644 --- a/zion/loader/init_loader.cpp +++ b/zion/loader/init_loader.cpp @@ -107,7 +107,7 @@ void DumpModules() { #endif } -const limine_file& GetInitProgram(glcr::String path) { +const limine_file& GetInitProgram(const glcr::String& path) { const limine_module_response& resp = boot::GetModules(); for (uint64_t i = 0; i < resp.module_count; i++) { const limine_file& file = *resp.modules[i]; @@ -115,7 +115,7 @@ const limine_file& GetInitProgram(glcr::String path) { return file; } } - panic("Program not found: {}", path); + panic("Program not found: {}", path.view()); UNREACHABLE }