Skip to content

Commit

Permalink
Adds a wrapper for intern_1.
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Jacobs <atheriel@gmail.com>
  • Loading branch information
atheriel committed Jul 22, 2017
1 parent cf392be commit a84daad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rust_src/remacs-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,8 @@ extern "C" {
pub fn make_uninit_multibyte_string(nchars: EmacsInt, nbytes: EmacsInt) -> Lisp_Object;
pub fn string_to_multibyte(string: Lisp_Object) -> Lisp_Object;

pub fn intern_1(s: *const c_char, length: ptrdiff_t) -> Lisp_Object;

pub fn SYMBOL_NAME(s: Lisp_Object) -> Lisp_Object;
pub fn CHECK_IMPURE(obj: Lisp_Object, ptr: *const c_void);
pub fn internal_equal(
Expand Down
13 changes: 12 additions & 1 deletion rust_src/src/symbols.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use libc;
use remacs_macros::lisp_fn;
use lisp::{LispObject, ExternalPtr};
use remacs_sys::Lisp_Symbol;
use remacs_sys::{Lisp_Symbol, intern_1};

pub type LispSymbolRef = ExternalPtr<Lisp_Symbol>;

Expand Down Expand Up @@ -58,3 +59,13 @@ fn symbol_function(object: LispObject) -> LispObject {
fn symbol_plist(object: LispObject) -> LispObject {
object.as_symbol_or_error().get_plist()
}

/// Intern (e.g. create a symbol from) a string slice.
pub fn intern(s: &str) -> LispObject {
unsafe {
LispObject::from_raw(intern_1(
s.as_ptr() as *const libc::c_char,
s.len() as libc::ptrdiff_t,
))
}
}

0 comments on commit a84daad

Please sign in to comment.