Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor EmacsDouble and LispNumber handling. #1565

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions docker/fedora/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ ENV PATH "/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb
RUN curl https://sh.rustup.rs -o rustup.sh && \
sh rustup.sh \
--default-host x86_64-unknown-linux-gnu \
--default-toolchain nightly-2019-02-27 -y && \
rustup default nightly-2019-02-27
--default-toolchain nightly-2020-01-08 -y && \
rustup default nightly-2020-01-08

4 changes: 2 additions & 2 deletions docker/ubuntu/32bit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ ENV PATH "/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb
RUN curl https://sh.rustup.rs -o rustup.sh && \
sh rustup.sh \
--default-host i686-unknown-linux-gnu \
--default-toolchain nightly-2019-02-27 -y && \
rustup default nightly-2019-02-27
--default-toolchain nightly-2020-01-08 -y && \
rustup default nightly-2020-01-08

4 changes: 2 additions & 2 deletions docker/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ ENV PATH "/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb
RUN curl https://sh.rustup.rs -o rustup.sh && \
sh rustup.sh \
--default-host x86_64-unknown-linux-gnu \
--default-toolchain nightly-2019-02-27 -y && \
rustup default nightly-2019-02-27
--default-toolchain nightly-2020-01-08 -y && \
rustup default nightly-2020-01-08

4 changes: 2 additions & 2 deletions docker/ubuntu/cosmic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ ENV PATH "/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sb
RUN curl https://sh.rustup.rs -o rustup.sh && \
sh rustup.sh \
--default-host x86_64-unknown-linux-gnu \
--default-toolchain nightly-2019-02-27 -y && \
rustup default nightly-2019-02-27
--default-toolchain nightly-2020-01-08 -y && \
rustup default nightly-2020-01-08

59 changes: 25 additions & 34 deletions rust_src/src/buffers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Functions operating on buffers.

use std::{self, iter, mem, ops, ptr, slice};
use std::{self, cmp, iter, mem, ops, ptr, slice};

use field_offset::FieldOffset;
use libc::{self, c_char, c_uchar, c_void, ptrdiff_t};
Expand Down Expand Up @@ -28,11 +28,10 @@ use crate::{
build_marker, build_marker_rust, marker_buffer, marker_position_lisp, set_marker,
set_marker_both, LispMarkerRef, MARKER_DEBUG,
},
math::{max, min},
multibyte::MAX_MULTIBYTE_LENGTH,
multibyte::{multibyte_char_at, multibyte_chars_in_text, multibyte_length_by_head},
multibyte::{Codepoint, LispStringRef, LispSymbolOrString},
numbers::{LispNumber, MOST_POSITIVE_FIXNUM},
numbers::{LispNumberOrMarker, MOST_POSITIVE_FIXNUM},
obarray::intern,
remacs_sys::symbol_trapped_write::SYMBOL_TRAPPED_WRITE,
remacs_sys::Fmake_marker,
Expand All @@ -49,13 +48,12 @@ use crate::{
buffer_defaults, equal_kind, pvec_type, EmacsInt, Lisp_Buffer, Lisp_Buffer_Local_Value,
Lisp_Misc_Type, Lisp_Overlay, Lisp_Type, Vbuffer_alist, Vrun_hooks,
},
remacs_sys::{buffer_permanent_local_flags, UNKNOWN_MODTIME_NSECS},
remacs_sys::{
buffer_permanent_local_flags, Qafter_string, Qbefore_string, Qbuffer_list_update_hook,
Qbuffer_read_only, Qbufferp, Qfundamental_mode, Qget_file_buffer, Qinhibit_quit,
Qinhibit_read_only, Qmakunbound, Qnil, Qoverlayp, Qpermanent_local, Qpermanent_local_hook,
Qt, Qunbound, UNKNOWN_MODTIME_NSECS,
Qafter_string, Qbefore_string, Qbuffer_list_update_hook, Qbuffer_read_only, Qbufferp,
Qerror, Qevaporate, Qfundamental_mode, Qget_file_buffer, Qinhibit_quit, Qinhibit_read_only,
Qmakunbound, Qnil, Qoverlayp, Qpermanent_local, Qpermanent_local_hook, Qt, Qunbound,
},
remacs_sys::{Qerror, Qevaporate},
strings::string_equal,
textprop::get_text_property,
threads::{c_specpdl_index, ThreadState},
Expand Down Expand Up @@ -1411,7 +1409,7 @@ fn get_truename_buffer_1(filename: LispSymbolOrString) -> LispObject {
/// That makes overlay lookup faster for positions near POS (but perhaps slower
/// for positions far away from POS).
#[lisp_fn]
pub fn overlay_recenter(pos: LispNumber) {
pub fn overlay_recenter(pos: LispNumberOrMarker) {
let p = clip_to_bounds(isize::min_value(), pos.to_fixnum(), isize::max_value());
unsafe {
recenter_overlay_lists(ThreadState::current_buffer_unchecked().as_mut(), p);
Expand Down Expand Up @@ -1834,8 +1832,8 @@ pub fn rename_buffer(newname: LispStringRef, unique: LispObject) -> LispStringRe
#[lisp_fn(min = "3")]
pub fn move_overlay(
overlay: LispObject,
beg: LispObject,
end: LispObject,
beg: LispNumberOrMarker,
end: LispNumberOrMarker,
buffer: LispObject,
) -> LispObject {
let count = c_specpdl_index();
Expand All @@ -1849,21 +1847,24 @@ pub fn move_overlay(
error!("Attempt to move overlay to a dead buffer");
}

if beg.is_marker() && !buf.eq(&marker_buffer(beg.into()).unwrap()) {
xsignal!(Qerror, "Marker points into wrong buffer", beg);
if let Some(m) = beg.as_marker() {
if !buf.eq(&marker_buffer(m).unwrap()) {
xsignal!(Qerror, "Marker points into wrong buffer", beg);
}
}

if end.is_marker() && !buf.eq(&marker_buffer(end.into()).unwrap()) {
xsignal!(Qerror, "Marker points into wrong buffer", end);
if let Some(m) = end.as_marker() {
if !buf.eq(&marker_buffer(m).unwrap()) {
xsignal!(Qerror, "Marker points into wrong buffer", end);
}
}

let beg_num = LispNumber::from(beg);
let end_num = LispNumber::from(end);
let (beg_num, end_num) = if beg_num.to_fixnum() > end_num.to_fixnum() {
(end_num, beg_num)
let (beg, end) = if beg.to_fixnum() > end.to_fixnum() {
(end, beg)
} else {
(beg_num, end_num)
(beg, end)
};

unsafe { specbind(Qinhibit_quit, Qt) };
let obuffer = overlay_buffer(overlay_ref);
let (o_beg, o_end) = match obuffer {
Expand All @@ -1878,14 +1879,10 @@ pub fn move_overlay(
// Set the overlay boundaries, which may clip them
set_marker(
LispMarkerRef::from(overlay_ref.start),
beg_num.into(),
buf.into(),
);
set_marker(
LispMarkerRef::from(overlay_ref.end),
end_num.into(),
beg.into(),
buf.into(),
);
set_marker(LispMarkerRef::from(overlay_ref.end), end.into(), buf.into());
let n_beg = overlay_start(overlay_ref);
let n_end = overlay_end(overlay_ref);
// If the overlay has changed buffers, do a thorough redisplay
Expand Down Expand Up @@ -1928,14 +1925,8 @@ pub fn move_overlay(
unsafe {
modify_overlay(
buf.as_mut(),
EmacsInt::from(min(&[
LispObject::from(o_beg.unwrap_or(0)),
LispObject::from(n_beg.unwrap_or(0)),
])) as ptrdiff_t,
EmacsInt::from(max(&[
LispObject::from(o_end.unwrap_or(0)),
LispObject::from(n_end.unwrap_or(0)),
])) as ptrdiff_t,
cmp::min(o_beg.unwrap_or(0), n_beg.unwrap_or(0)) as ptrdiff_t,
cmp::max(o_end.unwrap_or(0), n_end.unwrap_or(0)) as ptrdiff_t,
)
};
}
Expand Down
7 changes: 4 additions & 3 deletions rust_src/src/dispnew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
frame::{LispFrameLiveOrSelected, LispFrameRef},
lisp::{ExternalPtr, LispObject},
lists::{LispConsCircularChecks, LispConsEndChecks},
numbers::LispNumber,
remacs_sys::{
clear_current_matrices, detect_input_pending_run_timers, dtotimespec, fset_redisplay,
mark_window_display_accurate, putchar_unlocked, redisplay_preserve_echo_area, ring_bell,
Expand All @@ -20,7 +21,7 @@ use crate::{
globals, noninteractive, redisplaying_p, Qnil, Qredisplay_dont_pause, Qt, Vframe_list,
WAIT_READING_MAX,
},
remacs_sys::{EmacsDouble, EmacsInt, Lisp_Glyph},
remacs_sys::{EmacsInt, Lisp_Glyph},
terminal::{clear_frame, update_begin, update_end},
threads::c_specpdl_index,
windows::{LispWindowOrSelected, LispWindowRef},
Expand All @@ -34,8 +35,8 @@ pub type LispGlyphRef = ExternalPtr<Lisp_Glyph>;
/// additional wait period, in milliseconds; this is for backwards compatibility.
/// (Not all operating systems support waiting for a fraction of a second.)
#[lisp_fn(min = "1")]
pub fn sleep_for(seconds: EmacsDouble, milliseconds: Option<EmacsInt>) {
let duration = seconds + (milliseconds.unwrap_or(0) as f64 / 1000.0);
pub fn sleep_for(seconds: LispNumber, milliseconds: Option<EmacsInt>) {
let duration = seconds.to_float() + (milliseconds.unwrap_or(0) as f64 / 1000.0);
if duration > 0.0 {
let mut t = unsafe { dtotimespec(duration) };
let tend = unsafe { timespec_add(current_timespec(), t) };
Expand Down