Replace libc dependency with std::os::raw

This commit is contained in:
Joonas Javanainen 2017-02-14 20:22:52 +02:00
parent 0b4837db64
commit ca5c6ac2f8
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
9 changed files with 26 additions and 33 deletions

View File

@ -14,6 +14,7 @@
- Upgrade to bitflags 0.8
- Upgrade to glium 0.16
- Replace libc dependency with `std::os::raw`
### Deprecated

View File

@ -11,9 +11,6 @@ license = "MIT OR Apache-2.0"
[features]
default = ["glium"]
[dependencies]
libc = "0.2"
[dependencies.glium]
version = "0.16"
default-features = false

View File

@ -13,7 +13,6 @@ default = ["glium"]
[dependencies]
bitflags = "0.8"
libc = "0.2"
[dependencies.glium]
version = "0.16"

View File

@ -3,18 +3,17 @@
#[macro_use]
extern crate bitflags;
extern crate libc;
#[cfg(feature = "glium")]
#[macro_use]
extern crate glium;
#[cfg(feature = "glium")]
use glium::vertex::{Attribute, AttributeType, Vertex, VertexFormat};
use libc::*;
#[cfg(feature = "glium")]
use std::borrow::Cow;
use std::convert::From;
use std::mem;
use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
use std::slice;
pub enum ImGuiContext { }
@ -116,7 +115,7 @@ pub const ImGuiKey_COUNT: usize = 19;
bitflags!(
#[repr(C)]
pub flags ImGuiAlign: ::libc::c_int {
pub flags ImGuiAlign: c_int {
const ImGuiAlign_Left = 1 << 0,
const ImGuiAlign_Center = 1 << 1,
const ImGuiAlign_Right = 1 << 2,
@ -152,7 +151,7 @@ pub const ImGuiMouseCursor_COUNT: usize = 7;
bitflags!(
#[repr(C)]
pub flags ImGuiWindowFlags: ::libc::c_int {
pub flags ImGuiWindowFlags: c_int {
const ImGuiWindowFlags_NoTitleBar = 1 << 0,
const ImGuiWindowFlags_NoResize = 1 << 1,
const ImGuiWindowFlags_NoMove = 1 << 2,
@ -196,7 +195,7 @@ impl ImGuiWindowFlags {
bitflags!(
#[repr(C)]
pub flags ImGuiSetCond: ::libc::c_int {
pub flags ImGuiSetCond: c_int {
const ImGuiSetCond_Always = 1 << 0,
const ImGuiSetCond_Once = 1 << 1,
const ImGuiSetCond_FirstUseEver = 1 << 2,
@ -206,7 +205,7 @@ bitflags!(
bitflags!(
#[repr(C)]
pub flags ImGuiInputTextFlags: ::libc::c_int {
pub flags ImGuiInputTextFlags: c_int {
const ImGuiInputTextFlags_CharsDecimal = 1 << 0,
const ImGuiInputTextFlags_CharsHexadecimal = 1 << 1,
const ImGuiInputTextFlags_CharsUppercase = 1 << 2,
@ -243,7 +242,7 @@ impl ImGuiInputTextFlags {
bitflags!(
#[repr(C)]
pub flags ImGuiSelectableFlags: ::libc::c_int {
pub flags ImGuiSelectableFlags: c_int {
const ImGuiSelectableFlags_DontClosePopups = 1 << 0,
const ImGuiSelectableFlags_SpanAllColumns = 1 << 1,
const ImGuiSelectableFlags_AllowDoubleClick = 1 << 2
@ -252,7 +251,7 @@ bitflags!(
bitflags!(
#[repr(C)]
pub flags ImGuiTreeNodeFlags: ::libc::c_int {
pub flags ImGuiTreeNodeFlags: c_int {
const ImGuiTreeNodeFlags_Selected = 1 << 0,
const ImGuiTreeNodeFlags_Framed = 1 << 1,
const ImGuiTreeNodeFlags_AllowOverlapMode = 1 << 2,
@ -415,7 +414,7 @@ pub struct ImGuiIO {
pub render_draw_lists_fn: Option<extern "C" fn(data: *mut ImDrawData)>,
pub get_clipboard_text_fn: Option<extern "C" fn() -> *const c_char>,
pub set_clipboard_text_fn: Option<extern "C" fn(text: *const c_char)>,
pub mem_alloc_fn: Option<extern "C" fn(sz: size_t) -> *mut c_void>,
pub mem_alloc_fn: Option<extern "C" fn(sz: usize) -> *mut c_void>,
pub mem_free_fn: Option<extern "C" fn(ptr: *mut c_void)>,
pub ime_set_input_screen_pos_fn: Option<extern "C" fn(x: c_int, y: c_int)>,
@ -1113,14 +1112,14 @@ extern "C" {
extern "C" {
pub fn igInputText(label: *const c_char,
buf: *mut c_char,
buf_size: size_t,
buf_size: usize,
flags: ImGuiInputTextFlags,
callback: ImGuiTextEditCallback,
user_data: *mut c_void)
-> bool;
pub fn igInputTextMultiline(label: *const c_char,
buf: *mut c_char,
buf_size: size_t,
buf_size: usize,
size: ImVec2,
flags: ImGuiInputTextFlags,
callback: ImGuiTextEditCallback,
@ -1392,7 +1391,7 @@ extern "C" {
// Helpers functions to access functions pointers in ImGui::GetIO()
extern "C" {
pub fn igMemAlloc(sz: size_t) -> *mut c_void;
pub fn igMemAlloc(sz: usize) -> *mut c_void;
pub fn igMemFree(ptr: *mut c_void);
pub fn igGetClipboardText() -> *const c_char;
pub fn igSetClipboardText(text: *const c_char);
@ -1401,7 +1400,7 @@ extern "C" {
// Internal state access
extern "C" {
pub fn igGetVersion() -> *const c_char;
pub fn igCreateContext(malloc_fn: Option<extern "C" fn(size: size_t) -> *mut c_void>,
pub fn igCreateContext(malloc_fn: Option<extern "C" fn(size: usize) -> *mut c_void>,
free_fn: Option<extern "C" fn(ptr: *mut c_void)>)
-> *mut ImGuiContext;
pub fn igDestroyContext(ctx: *mut ImGuiContext);

View File

@ -4,7 +4,6 @@ use glium::program;
use glium::index::{self, PrimitiveType};
use glium::texture;
use glium::vertex;
use libc::uintptr_t;
use std::borrow::Cow;
use std::fmt;
use std::rc::Rc;
@ -98,12 +97,12 @@ impl Renderer {
[0.0, 2.0 / -(height as f32), 0.0, 0.0],
[0.0, 0.0, -1.0, 0.0],
[-1.0, 1.0, 0.0, 1.0]];
let font_texture_id = self.device_objects.texture.get_id() as uintptr_t;
let font_texture_id = self.device_objects.texture.get_id() as usize;
let mut idx_start = 0;
for cmd in draw_list.cmd_buffer {
// We don't support custom textures...yet!
assert!(cmd.texture_id as uintptr_t == font_texture_id);
assert!(cmd.texture_id as usize == font_texture_id);
let idx_end = idx_start + cmd.elem_count as usize;
@ -177,7 +176,7 @@ impl DeviceObjects {
};
Texture2d::new(ctx, data)
}));
im_gui.set_texture_id(texture.get_id() as uintptr_t);
im_gui.set_texture_id(texture.get_id() as usize);
Ok(DeviceObjects {
vertex_buffer: vertex_buffer,

View File

@ -1,5 +1,4 @@
use imgui_sys;
use libc::size_t;
use std::marker::PhantomData;
use std::ptr;
@ -156,7 +155,7 @@ impl<'ui, 'p> InputText<'ui, 'p> {
// TODO: this is evil.
// Perhaps something else than &mut str is better
self.buf.as_ptr() as *mut i8,
self.buf.len() as size_t,
self.buf.len() as usize,
self.flags,
None,
ptr::null_mut())

View File

@ -4,13 +4,11 @@ extern crate glium;
extern crate imgui_sys;
extern crate libc;
use libc::{c_char, c_float, c_int, c_uchar, c_void, uintptr_t};
use std::borrow::Cow;
use std::convert::From;
use std::ffi::CStr;
use std::mem;
use std::os::raw::{c_char, c_float, c_int, c_uchar, c_void};
use std::ptr;
use std::slice;
use std::str;
@ -157,7 +155,7 @@ impl ImGui {
})
}
}
pub fn set_texture_id(&mut self, value: uintptr_t) {
pub fn set_texture_id(&mut self, value: usize) {
unsafe {
(*self.io_mut().fonts).tex_id = value as *mut c_void;
}

View File

@ -1,8 +1,9 @@
use imgui_sys;
use super::ImStr;
use imgui_sys::ImVec2;
use std::{f32, mem, ptr};
use libc::c_float;
use std::os::raw::c_float;
use super::{ImStr, ImVec2};
#[must_use]
pub struct PlotHistogram<'p> {
label: ImStr<'p>,

View File

@ -1,8 +1,8 @@
use imgui_sys;
use super::ImStr;
use imgui_sys::ImVec2;
use std::{f32, mem, ptr};
use libc::c_float;
use std::os::raw::c_float;
use super::{ImStr, ImVec2};
#[must_use]
pub struct PlotLines<'p> {
label: ImStr<'p>,