Drop libc dependency from roc_std

This commit is contained in:
Richard Feldman 2021-08-02 22:16:21 -04:00
parent 27d8f7b821
commit fbc7984818
4 changed files with 9 additions and 18 deletions

3
Cargo.lock generated
View File

@ -3454,9 +3454,6 @@ dependencies = [
[[package]]
name = "roc_std"
version = "0.1.0"
dependencies = [
"libc",
]
[[package]]
name = "roc_types"

View File

@ -19,6 +19,3 @@ checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714"
[[package]]
name = "roc_std"
version = "0.1.0"
dependencies = [
"libc",
]

View File

@ -7,6 +7,3 @@ repository = "https://github.com/rtfeldman/roc"
readme = "README.md"
edition = "2018"
description = "Rust representations of Roc data structures"
[dependencies]
libc = "0.2"

View File

@ -2,7 +2,7 @@
#![no_std]
use core::convert::From;
use core::ffi::c_void;
use core::{fmt, mem, ptr};
use core::{fmt, mem, ptr, slice};
pub mod alloca;
@ -586,17 +586,17 @@ impl Clone for RocStr {
let capacity_size = core::mem::size_of::<usize>();
let copy_length = self.length + capacity_size;
let elements = unsafe {
let raw = roc_alloc(copy_length, core::mem::size_of::<usize>() as u32);
let raw_ptr =
roc_alloc(copy_length, core::mem::size_of::<usize>() as u32) as *mut usize;
let dest_slice = slice::from_raw_parts_mut(raw_ptr, copy_length);
let src_ptr = self.elements.offset(-(capacity_size as isize)) as *mut usize;
let src_slice = slice::from_raw_parts(src_ptr, copy_length);
libc::memcpy(
raw,
self.elements.offset(-(capacity_size as isize)) as *mut c_void,
copy_length,
);
dest_slice.copy_from_slice(src_slice);
*(raw as *mut usize) = self.length;
*(raw_ptr as *mut usize) = self.length;
(raw as *mut u8).add(capacity_size)
(raw_ptr as *mut u8).add(capacity_size)
};
Self {