mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
Merge pull request #975 from aktau/remove-gettimeofday
remove gettimeofday() usage
This commit is contained in:
commit
9550beda61
@ -44,7 +44,6 @@ check_function_exists(fsync HAVE_FSYNC)
|
||||
check_function_exists(getpwent HAVE_GETPWENT)
|
||||
check_function_exists(getpwnam HAVE_GETPWNAM)
|
||||
check_function_exists(getpwuid HAVE_GETPWUID)
|
||||
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
|
||||
check_function_exists(iconv HAVE_ICONV)
|
||||
check_function_exists(lstat HAVE_LSTAT)
|
||||
if(NOT HAVE_LSTAT)
|
||||
|
@ -26,7 +26,6 @@
|
||||
#cmakedefine HAVE_GETPWENT
|
||||
#cmakedefine HAVE_GETPWNAM
|
||||
#cmakedefine HAVE_GETPWUID
|
||||
#cmakedefine HAVE_GETTIMEOFDAY
|
||||
#cmakedefine HAVE_ICONV
|
||||
#cmakedefine USE_ICONV
|
||||
#cmakedefine HAVE_ICONV_H
|
||||
|
@ -6490,6 +6490,7 @@ static struct fst {
|
||||
{"settabvar", 3, 3, f_settabvar},
|
||||
{"settabwinvar", 4, 4, f_settabwinvar},
|
||||
{"setwinvar", 3, 3, f_setwinvar},
|
||||
{"sha256", 1, 1, f_sha256},
|
||||
{"shellescape", 1, 2, f_shellescape},
|
||||
{"shiftwidth", 0, 0, f_shiftwidth},
|
||||
{"simplify", 1, 1, f_simplify},
|
||||
@ -13102,6 +13103,17 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
|
||||
}
|
||||
}
|
||||
|
||||
/// f_sha256 - sha256({string}) function
|
||||
static void f_sha256(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
char_u *p = get_tv_string(&argvars[0]);
|
||||
const char_u *hash = sha256_bytes(p, (int) STRLEN(p) , NULL, 0);
|
||||
|
||||
// make a copy of the hash (sha256_bytes returns a static buffer)
|
||||
rettv->vval.v_string = (char_u *) xstrdup((char *) hash);
|
||||
rettv->v_type = VAR_STRING;
|
||||
}
|
||||
|
||||
/*
|
||||
* "shellescape({string})" function
|
||||
*/
|
||||
|
@ -15,10 +15,10 @@
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nvim/os/time.h"
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/sha256.h"
|
||||
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "sha256.c.generated.h"
|
||||
#endif
|
||||
@ -350,21 +350,6 @@ int sha256_self_test(void)
|
||||
return failures > 0 ? FAIL : OK;
|
||||
}
|
||||
|
||||
static unsigned int get_some_time(void)
|
||||
{
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
struct timeval tv;
|
||||
|
||||
// Using usec makes it less predictable.
|
||||
gettimeofday(&tv, NULL);
|
||||
return (unsigned int) (tv.tv_sec + tv.tv_usec);
|
||||
|
||||
#else // ifdef HAVE_GETTIMEOFDAY
|
||||
return (unsigned int) time(NULL);
|
||||
|
||||
#endif // ifdef HAVE_GETTIMEOFDAY
|
||||
}
|
||||
|
||||
/// Fill "header[header_len]" with random_data.
|
||||
/// Also "salt[salt_len]" when "salt" is not NULL.
|
||||
///
|
||||
@ -378,11 +363,11 @@ void sha2_seed(char_u *header, int header_len, char_u *salt, int salt_len)
|
||||
char_u sha256sum[32];
|
||||
context_sha256_T ctx;
|
||||
|
||||
srand(get_some_time());
|
||||
srand((unsigned int) os_hrtime());
|
||||
|
||||
int i;
|
||||
for (i = 0; i < (int) sizeof(random_data) - 1; i++) {
|
||||
random_data[i] = (char_u) ((get_some_time() ^ rand()) & 0xff);
|
||||
random_data[i] = (char_u) ((os_hrtime() ^ rand()) & 0xff);
|
||||
}
|
||||
sha256_start(&ctx);
|
||||
sha256_update(&ctx, (char_u *) random_data, sizeof(random_data));
|
||||
|
@ -3179,14 +3179,6 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen)
|
||||
static int held_button = MOUSE_RELEASE;
|
||||
static int orig_num_clicks = 1;
|
||||
static int orig_mouse_code = 0x0;
|
||||
# ifdef CHECK_DOUBLE_CLICK
|
||||
static int orig_mouse_col = 0;
|
||||
static int orig_mouse_row = 0;
|
||||
static struct timeval orig_mouse_time = {0, 0};
|
||||
/* time of previous mouse click */
|
||||
struct timeval mouse_time; /* time of current mouse click */
|
||||
long timediff; /* elapsed time in msec */
|
||||
# endif
|
||||
int cpo_koffset;
|
||||
|
||||
cpo_koffset = (vim_strchr(p_cpo, CPO_KOFFSET) != NULL);
|
||||
@ -3955,17 +3947,17 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen)
|
||||
} else if (wheel_code == 0) {
|
||||
# ifdef CHECK_DOUBLE_CLICK
|
||||
{
|
||||
/*
|
||||
* Compute the time elapsed since the previous mouse click.
|
||||
*/
|
||||
gettimeofday(&mouse_time, NULL);
|
||||
timediff = (mouse_time.tv_usec
|
||||
- orig_mouse_time.tv_usec) / 1000;
|
||||
if (timediff < 0)
|
||||
--orig_mouse_time.tv_sec;
|
||||
timediff += (mouse_time.tv_sec
|
||||
- orig_mouse_time.tv_sec) * 1000;
|
||||
static int orig_mouse_col = 0;
|
||||
static int orig_mouse_row = 0;
|
||||
|
||||
static uint64_t orig_mouse_time = 0; // time of previous mouse click
|
||||
uint64_t mouse_time = os_hrtime(); // time of current mouse click
|
||||
|
||||
// compute the time elapsed since the previous mouse click and
|
||||
// convert it from ns to ms because p_mouset is stored as ms
|
||||
long timediff = (long) (mouse_time - orig_mouse_time) / 1E6;
|
||||
orig_mouse_time = mouse_time;
|
||||
|
||||
if (mouse_code == orig_mouse_code
|
||||
&& timediff < p_mouset
|
||||
&& orig_num_clicks != 4
|
||||
|
@ -52,7 +52,7 @@
|
||||
* 128 = 16384 columns, now it's reduced to 10000. */
|
||||
#define MOUSE_COLOFF 10000
|
||||
|
||||
#if defined(UNIX) && defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
|
||||
#if defined(UNIX)
|
||||
# define CHECK_DOUBLE_CLICK 1 /* Checking for double clicks ourselves. */
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user