Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: replace ustr literals by cstr literals #222

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/gfx_apis/gl/gl/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use {
},
RenderError,
},
std::rc::Rc,
uapi::Ustr,
std::{ffi::CStr, rc::Rc},
};

pub struct GlProgram {
Expand Down Expand Up @@ -51,11 +50,11 @@ impl GlProgram {
Ok(res)
}

pub unsafe fn get_uniform_location(&self, name: &Ustr) -> GLint {
pub unsafe fn get_uniform_location(&self, name: &CStr) -> GLint {
(self.ctx.dpy.gles.glGetUniformLocation)(self.prog, name.as_ptr() as _)
}

pub unsafe fn get_attrib_location(&self, name: &Ustr) -> GLint {
pub unsafe fn get_attrib_location(&self, name: &CStr) -> GLint {
(self.ctx.dpy.gles.glGetAttribLocation)(self.prog, name.as_ptr() as _)
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/gfx_apis/gl/renderer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use {
fmt::{Debug, Formatter},
rc::Rc,
},
uapi::ustr,
};

pub(crate) struct TexProg {
Expand All @@ -44,13 +43,13 @@ pub(crate) struct TexProg {
impl TexProg {
unsafe fn from(prog: GlProgram, alpha_multiplier: bool) -> Self {
let alpha = match alpha_multiplier {
true => prog.get_uniform_location(ustr!("alpha")),
true => prog.get_uniform_location(c"alpha"),
false => 0,
};
Self {
pos: prog.get_attrib_location(ustr!("pos")),
texcoord: prog.get_attrib_location(ustr!("texcoord")),
tex: prog.get_uniform_location(ustr!("tex")),
pos: prog.get_attrib_location(c"pos"),
texcoord: prog.get_attrib_location(c"texcoord"),
tex: prog.get_uniform_location(c"tex"),
alpha,
prog,
}
Expand Down Expand Up @@ -164,8 +163,8 @@ impl GlRenderContext {
tex_internal,
tex_external,

fill_prog_pos: fill_prog.get_attrib_location(ustr!("pos")),
fill_prog_color: fill_prog.get_uniform_location(ustr!("color")),
fill_prog_pos: fill_prog.get_attrib_location(c"pos"),
fill_prog_color: fill_prog.get_uniform_location(c"color"),
fill_prog,

gfx_ops: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/gfx_apis/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl VulkanInstance {
.collect();
let app_info = ApplicationInfo::default()
.api_version(API_VERSION)
.application_name(ustr!("jay").as_c_str().unwrap())
.application_name(c"jay")
.application_version(1);
let mut severity = DebugUtilsMessageSeverityFlagsEXT::empty()
| DebugUtilsMessageSeverityFlagsEXT::ERROR
Expand Down
6 changes: 2 additions & 4 deletions src/gfx_apis/vulkan/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use {
PrimitiveTopology, PushConstantRange, SampleCountFlags, ShaderStageFlags,
},
std::{mem, rc::Rc, slice},
uapi::ustr,
};

pub(super) struct VulkanPipeline {
Expand Down Expand Up @@ -87,16 +86,15 @@ impl VulkanDevice {
let destroy_layout =
OnDrop(|| unsafe { self.device.destroy_pipeline_layout(pipeline_layout, None) });
let pipeline = {
let main = ustr!("main").as_c_str().unwrap();
let stages = [
PipelineShaderStageCreateInfo::default()
.stage(ShaderStageFlags::VERTEX)
.module(info.vert.module)
.name(main),
.name(c"main"),
PipelineShaderStageCreateInfo::default()
.stage(ShaderStageFlags::FRAGMENT)
.module(info.frag.module)
.name(main),
.name(c"main"),
];
let input_assembly_state = PipelineInputAssemblyStateCreateInfo::default()
.topology(PrimitiveTopology::TRIANGLE_STRIP);
Expand Down
10 changes: 5 additions & 5 deletions src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
crate::utils::oserror::OsError,
std::{ffi::CStr, marker::PhantomData, ptr, rc::Rc},
thiserror::Error,
uapi::{c, ustr, Errno, IntoUstr, Ustr},
uapi::{c, Errno, IntoUstr},
};

#[repr(transparent)]
Expand Down Expand Up @@ -375,7 +375,7 @@ impl UdevDevice {
unsafe { udev_device_get_is_initialized(self.device) != 0 }
}

fn get_property(&self, prop: &Ustr) -> Option<&CStr> {
fn get_property(&self, prop: &CStr) -> Option<&CStr> {
let prop = unsafe { udev_device_get_property_value(self.device, prop.as_ptr()) };
if prop.is_null() {
None
Expand All @@ -385,15 +385,15 @@ impl UdevDevice {
}

pub fn vendor(&self) -> Option<&CStr> {
self.get_property(ustr!("ID_VENDOR_FROM_DATABASE"))
self.get_property(c"ID_VENDOR_FROM_DATABASE")
}

pub fn model(&self) -> Option<&CStr> {
self.get_property(ustr!("ID_MODEL_FROM_DATABASE"))
self.get_property(c"ID_MODEL_FROM_DATABASE")
}

pub fn pci_id(&self) -> Option<&CStr> {
self.get_property(ustr!("PCI_ID"))
self.get_property(c"PCI_ID")
}
}

Expand Down
Loading