Skip to content

Commit 559b285

Browse files
authored
Add AddAssign impl for i64 (#237)
1 parent ac6a820 commit 559b285

4 files changed

Lines changed: 140 additions & 1 deletion

File tree

libcc2rs/src/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ macro_rules! impl_ptr_add_sub_assign {
736736
}
737737
)+ }
738738
}
739-
impl_ptr_add_sub_assign!(i32, u32, u64, isize, usize);
739+
impl_ptr_add_sub_assign!(i32, u32, i64, u64, isize, usize);
740740

741741
macro_rules! impl_ptr_add_sub {
742742
($($rhs:ty),+) => { $(
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
pub fn main() {
10+
std::process::exit(main_0());
11+
}
12+
fn main_0() -> i32 {
13+
let arr: Value<Box<[u8]>> = Rc::new(RefCell::new(Box::new([1_u8, 2_u8, 3_u8])));
14+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
15+
(*p.borrow_mut()) += (1_u8 as i32);
16+
assert!(((((*p.borrow()).read()) as i32) == 2));
17+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
18+
(*p.borrow_mut()) += (1_i8 as i32);
19+
assert!(((((*p.borrow()).read()) as i32) == 2));
20+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
21+
(*p.borrow_mut()) += (1_u16 as i32);
22+
assert!(((((*p.borrow()).read()) as i32) == 2));
23+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
24+
(*p.borrow_mut()) += (1_i16 as i32);
25+
assert!(((((*p.borrow()).read()) as i32) == 2));
26+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
27+
(*p.borrow_mut()) += 1_u32;
28+
assert!(((((*p.borrow()).read()) as i32) == 2));
29+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
30+
(*p.borrow_mut()) += (1 as i32);
31+
assert!(((((*p.borrow()).read()) as i32) == 2));
32+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
33+
(*p.borrow_mut()) += 1_u64;
34+
assert!(((((*p.borrow()).read()) as i32) == 2));
35+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
36+
(*p.borrow_mut()) += 1_i64;
37+
assert!(((((*p.borrow()).read()) as i32) == 2));
38+
return 0;
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
pub fn main() {
10+
unsafe {
11+
std::process::exit(main_0() as i32);
12+
}
13+
}
14+
unsafe fn main_0() -> i32 {
15+
let mut arr: [libc::c_char; 3] = [
16+
(1 as libc::c_char),
17+
(2 as libc::c_char),
18+
(3 as libc::c_char),
19+
];
20+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
21+
p = (p).wrapping_add((1_u8 as i32) as usize);
22+
assert!((((*p) as i32) == (2)));
23+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
24+
p = (p).wrapping_add((1_i8 as i32) as usize);
25+
assert!((((*p) as i32) == (2)));
26+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
27+
p = (p).wrapping_add((1_u16 as i32) as usize);
28+
assert!((((*p) as i32) == (2)));
29+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
30+
p = (p).wrapping_add((1_i16 as i32) as usize);
31+
assert!((((*p) as i32) == (2)));
32+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
33+
p = (p).wrapping_add((1_u32 as u32) as usize);
34+
assert!((((*p) as i32) == (2)));
35+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
36+
p = (p).wrapping_add(((1 as i32) as i32) as usize);
37+
assert!((((*p) as i32) == (2)));
38+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
39+
p = (p).wrapping_add((1_u64 as u64) as usize);
40+
assert!((((*p) as i32) == (2)));
41+
let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char);
42+
p = (p).wrapping_add((1_i64 as i64) as usize);
43+
assert!((((*p) as i32) == (2)));
44+
return 0;
45+
}

tests/unit/pointer_add_assign.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <assert.h>
2+
#include <stdint.h>
3+
4+
int main() {
5+
char arr[] = {1, 2, 3};
6+
{
7+
char *p = &arr[0];
8+
p += static_cast<uint8_t>(1);
9+
assert(*p == 2);
10+
}
11+
12+
{
13+
char *p = &arr[0];
14+
p += static_cast<int8_t>(1);
15+
assert(*p == 2);
16+
}
17+
18+
{
19+
char *p = &arr[0];
20+
p += static_cast<uint16_t>(1);
21+
assert(*p == 2);
22+
}
23+
24+
{
25+
char *p = &arr[0];
26+
p += static_cast<int16_t>(1);
27+
assert(*p == 2);
28+
}
29+
30+
{
31+
char *p = &arr[0];
32+
p += static_cast<uint32_t>(1);
33+
assert(*p == 2);
34+
}
35+
36+
{
37+
char *p = &arr[0];
38+
p += static_cast<int32_t>(1);
39+
assert(*p == 2);
40+
}
41+
42+
{
43+
char *p = &arr[0];
44+
p += static_cast<uint64_t>(1);
45+
assert(*p == 2);
46+
}
47+
48+
{
49+
char *p = &arr[0];
50+
p += static_cast<int64_t>(1);
51+
assert(*p == 2);
52+
}
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)