File tree 6 files changed +109
-11
lines changed
6 files changed +109
-11
lines changed Original file line number Diff line number Diff line change
1
+ name : Rust
2
+
3
+ on :
4
+ push :
5
+ branches : [ '*' ]
6
+ pull_request :
7
+ branches : [ master ]
8
+
9
+ env :
10
+ CARGO_TERM_COLOR : always
11
+
12
+ jobs :
13
+ build :
14
+
15
+ runs-on : ubuntu-latest
16
+
17
+ steps :
18
+ - uses : actions/checkout@v2
19
+ - name : Install dependencies
20
+ run : apt-get update && apt-get install -y llvm-dev libclang-dev clang
21
+ - name : Install ${{ matrix.rust-version }}
22
+ uses : actions-rs/toolchain@v1
23
+ with :
24
+ toolchain : ${{ matrix.rust-version }}-${{ matrix.target.triple }}
25
+ profile : minimal
26
+ override : true
27
+ - name : Build
28
+ run : cargo build --verbose
29
+ - name : Run tests
30
+ run : cargo test --all --examples
31
+
32
+ strategy :
33
+ matrix :
34
+ threaded :
35
+ - ' '
36
+ - ' -threaded'
37
+ perl-version :
38
+ - ' 5.26'
39
+ - ' 5.28'
40
+ - ' 5.30'
41
+ - ' 5.32'
42
+ - ' 5.34'
43
+ - ' 5'
44
+ rust-version :
45
+ - 1.54.0 # MSRV
46
+ - stable
47
+ target :
48
+ - { name: Linux, os: ubuntu-latest, triple: x86_64-unknown-linux-gnu }
49
+
50
+ container :
51
+ image : perl:${{ matrix.perl-version }}${{ matrix.threaded }}
52
+
53
+
Original file line number Diff line number Diff line change 1
1
#![ allow( non_snake_case) ]
2
+
3
+ #[ cfg( perlapi_ver26) ]
4
+ use std:: convert:: TryFrom ;
5
+
2
6
pub use libperl_sys:: op;
3
7
4
8
use libperl_sys:: * ;
@@ -36,10 +40,7 @@ pub enum Name {
36
40
#[ cfg( perlapi_ver26) ]
37
41
pub fn op_extract ( perl : & Perl , cv : * const cv , o : * const op ) -> Op {
38
42
let cls = perl. op_class ( o) ;
39
- let oc = unsafe {
40
- let ty = ( * o) . op_type ( ) ;
41
- * ( & ty as * const u16 as * const opcode )
42
- } ;
43
+ let oc = opcode:: try_from ( o) . unwrap ( ) ;
43
44
match cls {
44
45
OPclass :: OPclass_NULL => Op :: NULL ,
45
46
OPclass :: OPclass_BASEOP => {
@@ -148,7 +149,7 @@ impl Iterator for OpSiblingIter {
148
149
pub fn op_sibling ( op : * const unop ) -> * const op {
149
150
// PERL_OP_PARENT is on since 5.26
150
151
if let Some ( op) = unsafe { op. as_ref ( ) } {
151
- if op. op_moresib ( ) == 1 as u16 {
152
+ if u32 :: try_from ( op. op_moresib ( ) ) . unwrap ( ) == 1 as u32 {
152
153
op. op_sibparent
153
154
} else {
154
155
std:: ptr:: null ( )
Original file line number Diff line number Diff line change 1
1
#![ allow( non_snake_case) ]
2
+
3
+ #[ cfg( perlapi_ver26) ]
4
+ use std:: convert:: TryFrom ;
5
+
2
6
pub use libperl_sys:: op;
3
7
4
8
use if_chain:: if_chain;
@@ -166,11 +170,7 @@ impl<'a> OpExtractor<'a> {
166
170
return self . ops . alloc ( Op :: NULL )
167
171
}
168
172
let cls = self . perl . op_class ( o) ;
169
- let oc = unsafe {
170
- let ty = ( * o) . op_type ( ) ;
171
- * ( & ty as * const u16 as * const opcode )
172
- } ;
173
-
173
+ let oc = opcode:: try_from ( o) . unwrap ( ) ;
174
174
let eo = match cls {
175
175
OPclass :: OPclass_NULL => Op :: NULL ,
176
176
OPclass :: OPclass_BASEOP => {
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ fn main() {
37
37
38
38
perl. emit_features ( & [ "useithreads" ] ) ; // "usemultiplicity"
39
39
40
- perl. emit_perlapi_vers ( 10 , 30 ) ;
40
+ perl. emit_perlapi_vers ( 10 , 34 ) ;
41
41
42
42
let src_file_name = "wrapper.h" ;
43
43
let src_path = cargo_topdir_file ( src_file_name) ;
Original file line number Diff line number Diff line change
1
+ use std:: convert:: TryFrom ;
2
+
3
+ use crate :: perl_core:: { op, opcode} ;
4
+
5
+ impl TryFrom < * const op > for opcode {
6
+ type Error = & ' static str ;
7
+
8
+ fn try_from ( op : * const op ) -> Result < Self , Self :: Error > {
9
+ if op. is_null ( ) {
10
+ return Err ( "Null OP*" )
11
+ }
12
+ opcode:: try_from ( unsafe {
13
+ ( * op) . op_type ( )
14
+ } )
15
+ }
16
+ }
17
+
18
+ impl TryFrom < u32 > for opcode {
19
+ type Error = & ' static str ;
20
+
21
+ fn try_from ( oc : u32 ) -> Result < Self , Self :: Error > {
22
+ if oc <= opcode:: OP_max as u32 {
23
+ let e = unsafe { std:: mem:: transmute ( oc) } ;
24
+ Ok ( e)
25
+ } else {
26
+ Err ( "Invalid opcode" )
27
+ }
28
+ }
29
+ }
30
+
31
+ impl TryFrom < u16 > for opcode {
32
+ type Error = & ' static str ;
33
+
34
+ fn try_from ( oc : u16 ) -> Result < Self , Self :: Error > {
35
+ if oc <= opcode:: OP_max as u16 {
36
+ let e = unsafe { std:: mem:: transmute ( oc as u32 ) } ;
37
+ Ok ( e)
38
+ } else {
39
+ Err ( "Invalid opcode" )
40
+ }
41
+ }
42
+ }
Original file line number Diff line number Diff line change 1
1
pub mod perl_core;
2
2
pub use perl_core:: * ;
3
3
4
+ pub mod conv_opcode;
5
+
4
6
use std:: ffi:: CStr ;
5
7
6
8
// use std::os::raw::{c_char, c_int /*, c_void, c_schar*/};
You can’t perform that action at this time.
0 commit comments