2020-01-02 13:57:00 -05:00
|
|
|
// Copyright 2019-2020 the Deno authors. All rights reserved. MIT license.
|
2019-12-27 09:12:16 -05:00
|
|
|
use crate::function::FunctionCallback;
|
|
|
|
use crate::support::intptr_t;
|
|
|
|
use std::ffi::c_void;
|
|
|
|
|
|
|
|
pub struct ExternalReferences {
|
|
|
|
null_terminated: Vec<*const libc::c_void>,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Sync for ExternalReferences {}
|
|
|
|
|
|
|
|
impl ExternalReferences {
|
|
|
|
pub fn new(refs: &[FunctionCallback]) -> Self {
|
|
|
|
let mut null_terminated = Vec::with_capacity(refs.len() + 1);
|
|
|
|
for r in refs {
|
|
|
|
null_terminated.push(*r as *const c_void);
|
|
|
|
}
|
|
|
|
null_terminated.push(std::ptr::null());
|
|
|
|
Self { null_terminated }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_ptr(&self) -> *const intptr_t {
|
|
|
|
self.null_terminated.as_ptr() as *const intptr_t
|
|
|
|
}
|
|
|
|
}
|