Skip to content

Commit

Permalink
Try to represent ErlNifTermType as c_int consts
Browse files Browse the repository at this point in the history
This may fix a problem in the Windows build.
  • Loading branch information
philss committed Jan 29, 2024
1 parent 7fe5c0d commit 2c7fa51
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
8 changes: 6 additions & 2 deletions rustler/src/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#[cfg(feature = "nif_version_2_15")]
use rustler_sys::ErlNifTermType;
use rustler_sys::{
ErlNifTermType, ERL_NIF_TERM_TYPE_ATOM, ERL_NIF_TERM_TYPE_BITSTRING, ERL_NIF_TERM_TYPE_FLOAT,
ERL_NIF_TERM_TYPE_FUN, ERL_NIF_TERM_TYPE_INTEGER, ERL_NIF_TERM_TYPE_LIST,
ERL_NIF_TERM_TYPE_MAP, ERL_NIF_TERM_TYPE_PID, ERL_NIF_TERM_TYPE_PORT,
ERL_NIF_TERM_TYPE_REFERENCE, ERL_NIF_TERM_TYPE_TUPLE,
};

use crate::wrapper::check;
use crate::Term;
Expand All @@ -23,7 +28,6 @@ pub enum TermType {
#[cfg(feature = "nif_version_2_15")]
impl From<ErlNifTermType> for TermType {
fn from(term_type: ErlNifTermType) -> Self {
use ErlNifTermType::*;
use TermType::*;
match term_type {
ERL_NIF_TERM_TYPE_ATOM => Atom,
Expand Down
55 changes: 33 additions & 22 deletions rustler_sys/src/rustler_sys_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,28 +308,39 @@ pub enum ErlNifHash {

/// See [ErlNifTermType](http://www.erlang.org/doc/man/erl_nif.html#ErlNifTermType) in the Erlang docs.
#[cfg(feature = "nif_version_2_15")]
#[derive(Copy, Clone)]
#[repr(C)]
pub enum ErlNifTermType {
// from https://github.com/erlang/otp/blob/6618ce7b6a621e92db72ea4f01f7d38553c8818c/erts/emulator/beam/erl_nif.h#L291
ERL_NIF_TERM_TYPE_ATOM = 1,
ERL_NIF_TERM_TYPE_BITSTRING = 2,
ERL_NIF_TERM_TYPE_FLOAT = 3,
ERL_NIF_TERM_TYPE_FUN = 4,
ERL_NIF_TERM_TYPE_INTEGER = 5,
ERL_NIF_TERM_TYPE_LIST = 6,
ERL_NIF_TERM_TYPE_MAP = 7,
ERL_NIF_TERM_TYPE_PID = 8,
ERL_NIF_TERM_TYPE_PORT = 9,
ERL_NIF_TERM_TYPE_REFERENCE = 10,
ERL_NIF_TERM_TYPE_TUPLE = 11,

/* This is a dummy value intended to coax the compiler into warning about
* unhandled values in a switch even if all the above values have been
* handled. We can add new entries at any time so the user must always
* have a default case. */
ERL_NIF_TERM_TYPE__MISSING_DEFAULT_CASE__READ_THE_MANUAL = -1,
}
pub type ErlNifTermType = c_int;

// from https://github.com/erlang/otp/blob/6618ce7b6a621e92db72ea4f01f7d38553c8818c/erts/emulator/beam/erl_nif.h#L291
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_ATOM: ErlNifTermType = 1;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_BITSTRING: ErlNifTermType = 2;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_FLOAT: ErlNifTermType = 3;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_FUN: ErlNifTermType = 4;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_INTEGER: ErlNifTermType = 5;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_LIST: ErlNifTermType = 6;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_MAP: ErlNifTermType = 7;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_PID: ErlNifTermType = 8;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_PORT: ErlNifTermType = 9;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_REFERENCE: ErlNifTermType = 10;
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE_TUPLE: ErlNifTermType = 11;

/* This is a dummy value intended to coax the compiler into warning about
* unhandled values in a switch even if all the above values have been
* handled. We can add new entries at any time so the user must always
* have a default case. */
#[allow(non_upper_case_globals)]
#[cfg(feature = "nif_version_2_15")]
pub const ERL_NIF_TERM_TYPE__MISSING_DEFAULT_CASE__READ_THE_MANUAL: ErlNifTermType = -1;

/// See [ErlNifOption](http://www.erlang.org/doc/man/erl_nif.html#ErlNifOption) in the Erlang docs.
#[cfg(feature = "nif_version_2_17")]
Expand Down

0 comments on commit 2c7fa51

Please sign in to comment.