Skip to content

Commit 91c3e7d

Browse files
authoredApr 6, 2022
Merge pull request #4 from hkoba/tkt-2-gh-actions
Switch to Github Action
2 parents 58e12c3 + c3e225d commit 91c3e7d

File tree

6 files changed

+109
-11
lines changed

6 files changed

+109
-11
lines changed
 

‎.github/workflows/rust.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+

‎examples/eg/op0.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#![allow(non_snake_case)]
2+
3+
#[cfg(perlapi_ver26)]
4+
use std::convert::TryFrom;
5+
26
pub use libperl_sys::op;
37

48
use libperl_sys::*;
@@ -36,10 +40,7 @@ pub enum Name {
3640
#[cfg(perlapi_ver26)]
3741
pub fn op_extract(perl: &Perl, cv: *const cv, o: *const op) -> Op {
3842
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();
4344
match cls {
4445
OPclass::OPclass_NULL => Op::NULL,
4546
OPclass::OPclass_BASEOP => {
@@ -148,7 +149,7 @@ impl Iterator for OpSiblingIter {
148149
pub fn op_sibling(op: *const unop) -> *const op {
149150
// PERL_OP_PARENT is on since 5.26
150151
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 {
152153
op.op_sibparent
153154
} else {
154155
std::ptr::null()

‎examples/eg/op1.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#![allow(non_snake_case)]
2+
3+
#[cfg(perlapi_ver26)]
4+
use std::convert::TryFrom;
5+
26
pub use libperl_sys::op;
37

48
use if_chain::if_chain;
@@ -166,11 +170,7 @@ impl<'a> OpExtractor<'a> {
166170
return self.ops.alloc(Op::NULL)
167171
}
168172
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();
174174
let eo = match cls {
175175
OPclass::OPclass_NULL => Op::NULL,
176176
OPclass::OPclass_BASEOP => {

‎libperl-sys/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737

3838
perl.emit_features(&["useithreads"]); // "usemultiplicity"
3939

40-
perl.emit_perlapi_vers(10, 30);
40+
perl.emit_perlapi_vers(10, 34);
4141

4242
let src_file_name = "wrapper.h";
4343
let src_path = cargo_topdir_file(src_file_name);

‎libperl-sys/src/conv_opcode.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

‎libperl-sys/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pub mod perl_core;
22
pub use perl_core::*;
33

4+
pub mod conv_opcode;
5+
46
use std::ffi::CStr;
57

68
// use std::os::raw::{c_char, c_int /*, c_void, c_schar*/};

0 commit comments

Comments
 (0)