Merge pull request #1340 from elmart/remove-long_u

Remove project-specific integer types: long_u. (2)
This commit is contained in:
Justin M. Keyes
2014-11-06 17:09:39 -05:00
9 changed files with 648 additions and 756 deletions

View File

@@ -1,10 +1,10 @@
src/nvim/api/buffer.c
src/nvim/api/buffer.h
src/nvim/api/private/defs.h
src/nvim/api/private/helpers.c
src/nvim/api/private/helpers.h
src/nvim/api/private/handle.c
src/nvim/api/private/handle.h
src/nvim/api/private/helpers.c
src/nvim/api/private/helpers.h
src/nvim/api/tabpage.c
src/nvim/api/tabpage.h
src/nvim/api/vim.c
@@ -22,6 +22,15 @@ src/nvim/log.h
src/nvim/map.c
src/nvim/map.h
src/nvim/map_defs.h
src/nvim/memfile.c
src/nvim/memfile.h
src/nvim/memfile_defs.h
src/nvim/msgpack_rpc/channel.c
src/nvim/msgpack_rpc/channel.h
src/nvim/msgpack_rpc/helpers.c
src/nvim/msgpack_rpc/helpers.h
src/nvim/msgpack_rpc/server.c
src/nvim/msgpack_rpc/server.h
src/nvim/os/env.c
src/nvim/os/event.c
src/nvim/os/event.h
@@ -42,13 +51,7 @@ src/nvim/os/signal.c
src/nvim/os/signal.h
src/nvim/os/time.c
src/nvim/os/time.h
src/nvim/msgpack_rpc/server.c
src/nvim/msgpack_rpc/server.h
src/nvim/msgpack_rpc/channel.c
src/nvim/msgpack_rpc/channel.h
src/nvim/msgpack_rpc/helpers.c
src/nvim/msgpack_rpc/helpers.h
src/nvim/tempfile.c
src/nvim/tempfile.h
src/nvim/profile.c
src/nvim/profile.h
src/nvim/tempfile.c
src/nvim/tempfile.h

View File

@@ -45,6 +45,7 @@ set(CONV_SOURCES
hashtab.c
log.c
map.c
memfile.c
memory.c
misc2.c
profile.c

View File

@@ -78,7 +78,6 @@ typedef struct wininfo_S wininfo_T;
typedef struct frame_S frame_T;
typedef int scid_T; /* script ID */
typedef struct file_buffer buf_T; /* forward declaration */
typedef struct memfile memfile_T;
// for struct memline (it needs memfile_T)
#include "nvim/memline_defs.h"

View File

@@ -10,6 +10,7 @@
* eval.c: Expression evaluation.
*/
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdarg.h>
@@ -3034,10 +3035,10 @@ static char_u *cat_prefix_varname(int prefix, char_u *name)
*/
char_u *get_user_var_name(expand_T *xp, int idx)
{
static long_u gdone;
static long_u bdone;
static long_u wdone;
static long_u tdone;
static size_t gdone;
static size_t bdone;
static size_t wdone;
static size_t tdone;
static int vidx;
static hashitem_T *hi;
hashtab_T *ht;
@@ -11749,7 +11750,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
if (*p == '\n' || readlen <= 0) {
listitem_T *li;
char_u *s = NULL;
long_u len = p - start;
size_t len = p - start;
/* Finished a line. Remove CRs before NL. */
if (readlen > 0 && !binary) {
@@ -11760,9 +11761,10 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
while (prevlen > 0 && prev[prevlen - 1] == '\r')
--prevlen;
}
if (prevlen == 0)
if (prevlen == 0) {
assert(len < INT_MAX);
s = vim_strnsave(start, (int)len);
else {
} else {
/* Change "prev" buffer to be the right size. This way
* the bytes are only copied once, and very long lines are
* allocated only once. */
@@ -18152,7 +18154,7 @@ static char_u *autoload_name(char_u *name)
*/
char_u *get_user_func_name(expand_T *xp, int idx)
{
static long_u done;
static size_t done;
static hashitem_T *hi;
ufunc_T *fp;

File diff suppressed because it is too large Load Diff

View File

@@ -4,11 +4,11 @@
#include "nvim/buffer_defs.h"
#include "nvim/memfile_defs.h"
/* flags for mf_sync() */
#define MFS_ALL 1 /* also sync blocks with negative numbers */
#define MFS_STOP 2 /* stop syncing when a character is available */
#define MFS_FLUSH 4 /* flushed file to disk */
#define MFS_ZERO 8 /* only write block 0 */
/// flags for mf_sync()
#define MFS_ALL 1 /// also sync blocks with negative numbers
#define MFS_STOP 2 /// stop syncing when a character is available
#define MFS_FLUSH 4 /// flushed file to disk
#define MFS_ZERO 8 /// only write block 0
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "memfile.h.generated.h"

View File

@@ -1,99 +1,108 @@
#ifndef NVIM_MEMFILE_DEFS_H
#define NVIM_MEMFILE_DEFS_H
#include <stdint.h>
#include <stdbool.h>
#include "nvim/types.h"
typedef struct block_hdr bhdr_T;
typedef long blocknr_T;
/// A block number.
///
/// Blocks numbered from 0 upwards have been assigned a place in the actual
/// file. The block number is equal to the page number in the file. The blocks
/// with negative numbers are currently in memory only.
typedef int64_t blocknr_T;
/*
* mf_hashtab_T is a chained hashtable with blocknr_T key and arbitrary
* structures as items. This is an intrusive data structure: we require
* that items begin with mf_hashitem_T which contains the key and linked
* list pointers. List of items in each bucket is doubly-linked.
*/
typedef struct mf_hashitem_S mf_hashitem_T;
struct mf_hashitem_S {
mf_hashitem_T *mhi_next;
mf_hashitem_T *mhi_prev;
/// A hash item.
///
/// Items' keys are block numbers.
/// Items in the same bucket are organized into a doubly-linked list.
///
/// Therefore, items can be arbitrary data structures beginning with pointers
/// for the list and and a block number key.
typedef struct mf_hashitem {
struct mf_hashitem *mhi_next;
struct mf_hashitem *mhi_prev;
blocknr_T mhi_key;
};
} mf_hashitem_T;
#define MHT_INIT_SIZE 64
/// Initial size for a hashtable.
#define MHT_INIT_SIZE 64
typedef struct mf_hashtab_S {
long_u mht_mask; /* mask used for hash value (nr of items
* in array is "mht_mask" + 1) */
long_u mht_count; /* nr of items inserted into hashtable */
mf_hashitem_T **mht_buckets; /* points to mht_small_buckets or
*dynamically allocated array */
mf_hashitem_T *mht_small_buckets[MHT_INIT_SIZE]; /* initial buckets */
char mht_fixed; /* non-zero value forbids growth */
/// A chained hashtable with block numbers as keys and arbitrary data structures
/// as items.
///
/// This is an intrusive data structure: we require that items begin with
/// mf_hashitem_T which contains the key and linked list pointers. List of items
/// in each bucket is doubly-linked.
typedef struct mf_hashtab {
size_t mht_mask; /// mask used to mod hash value to array index
/// (nr of items in array is 'mht_mask + 1')
size_t mht_count; /// number of items inserted
mf_hashitem_T **mht_buckets; /// points to the array of buckets (can be
/// mht_small_buckets or a newly allocated array
/// when mht_small_buckets becomes too small)
mf_hashitem_T *mht_small_buckets[MHT_INIT_SIZE]; /// initial buckets
} mf_hashtab_T;
/*
* for each (previously) used block in the memfile there is one block header.
*
* The block may be linked in the used list OR in the free list.
* The used blocks are also kept in hash lists.
*
* The used list is a doubly linked list, most recently used block first.
* The blocks in the used list have a block of memory allocated.
* mf_used_count is the number of pages in the used list.
* The hash lists are used to quickly find a block in the used list.
* The free list is a single linked list, not sorted.
* The blocks in the free list have no block of memory allocated and
* the contents of the block in the file (if any) is irrelevant.
*/
/// A block header.
///
/// There is a block header for each previously used block in the memfile.
///
/// The block may be linked in the used list OR in the free list.
/// The used blocks are also kept in hash lists.
///
/// The used list is a doubly linked list, most recently used block first.
/// The blocks in the used list have a block of memory allocated.
/// mf_used_count is the number of pages in the used list.
/// The hash lists are used to quickly find a block in the used list.
/// The free list is a single linked list, not sorted.
/// The blocks in the free list have no block of memory allocated and
/// the contents of the block in the file (if any) is irrelevant.
typedef struct bhdr {
mf_hashitem_T bh_hashitem; /// header for hash table and key
#define bh_bnum bh_hashitem.mhi_key /// block number, part of bh_hashitem
struct block_hdr {
mf_hashitem_T bh_hashitem; /* header for hash table and key */
#define bh_bnum bh_hashitem.mhi_key /* block number, part of bh_hashitem */
struct bhdr *bh_next; /// next block header in free or used list
struct bhdr *bh_prev; /// previous block header in used list
void *bh_data; /// pointer to memory (for used block)
unsigned bh_page_count; /// number of pages in this block
bhdr_T *bh_next; /* next block_hdr in free or used list */
bhdr_T *bh_prev; /* previous block_hdr in used list */
char_u *bh_data; /* pointer to memory (for used block) */
int bh_page_count; /* number of pages in this block */
#define BH_DIRTY 1U
#define BH_LOCKED 2U
unsigned bh_flags; // BH_DIRTY or BH_LOCKED
} bhdr_T;
#define BH_DIRTY 1
#define BH_LOCKED 2
char bh_flags; /* BH_DIRTY or BH_LOCKED */
};
/// A block number translation list item.
///
/// When a block with a negative number is flushed to the file, it gets
/// a positive number. Because the reference to the block is still the negative
/// number, we remember the translation to the new positive number in the
/// double linked trans lists. The structure is the same as the hash lists.
typedef struct mf_blocknr_trans_item {
mf_hashitem_T nt_hashitem; /// header for hash table and key
#define nt_old_bnum nt_hashitem.mhi_key /// old, negative, number
blocknr_T nt_new_bnum; /// new, positive, number
} mf_blocknr_trans_item_T;
/*
* when a block with a negative number is flushed to the file, it gets
* a positive number. Because the reference to the block is still the negative
* number, we remember the translation to the new positive number in the
* double linked trans lists. The structure is the same as the hash lists.
*/
typedef struct nr_trans NR_TRANS;
/// A memory file.
typedef struct memfile {
char_u *mf_fname; /// name of the file
char_u *mf_ffname; /// idem, full path
int mf_fd; /// file descriptor
bhdr_T *mf_free_first; /// first block header in free list
bhdr_T *mf_used_first; /// mru block header in used list
bhdr_T *mf_used_last; /// lru block header in used list
unsigned mf_used_count; /// number of pages in used list
unsigned mf_used_count_max; /// maximum number of pages in memory
mf_hashtab_T mf_hash; /// hash lists
mf_hashtab_T mf_trans; /// trans lists
blocknr_T mf_blocknr_max; /// highest positive block number + 1
blocknr_T mf_blocknr_min; /// lowest negative block number - 1
blocknr_T mf_neg_count; /// number of negative blocks numbers
blocknr_T mf_infile_count; /// number of pages in the file
unsigned mf_page_size; /// number of bytes in a page
bool mf_dirty; /// TRUE if there are dirty blocks
} memfile_T;
struct nr_trans {
mf_hashitem_T nt_hashitem; /* header for hash table and key */
#define nt_old_bnum nt_hashitem.mhi_key /* old, negative, number */
blocknr_T nt_new_bnum; /* new, positive, number */
};
struct memfile {
char_u *mf_fname; /* name of the file */
char_u *mf_ffname; /* idem, full path */
int mf_fd; /* file descriptor */
bhdr_T *mf_free_first; /* first block_hdr in free list */
bhdr_T *mf_used_first; /* mru block_hdr in used list */
bhdr_T *mf_used_last; /* lru block_hdr in used list */
unsigned mf_used_count; /* number of pages in used list */
unsigned mf_used_count_max; /* maximum number of pages in memory */
mf_hashtab_T mf_hash; /* hash lists */
mf_hashtab_T mf_trans; /* trans lists */
blocknr_T mf_blocknr_max; /* highest positive block number + 1*/
blocknr_T mf_blocknr_min; /* lowest negative block number - 1 */
blocknr_T mf_neg_count; /* number of negative blocks numbers */
blocknr_T mf_infile_count; /* number of pages in the file */
unsigned mf_page_size; /* number of bytes in a page */
int mf_dirty; /* TRUE if there are dirty blocks */
};
#endif // NVIM_MEMFILE_DEFS_H
#endif // NVIM_MEMFILE_DEFS_H

View File

@@ -41,6 +41,7 @@
* mf_get().
*/
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <string.h>
@@ -296,12 +297,12 @@ int ml_open(buf_T *buf)
/*
* fill block0 struct and write page 0
*/
hp = mf_new(mfp, FALSE, 1);
hp = mf_new(mfp, false, 1);
if (hp->bh_bnum != 0) {
EMSG(_("E298: Didn't get block nr 0?"));
goto error;
}
b0p = (ZERO_BL *)(hp->bh_data);
b0p = hp->bh_data;
b0p->b0_id[0] = BLOCK0_ID0;
b0p->b0_id[1] = BLOCK0_ID1;
@@ -330,7 +331,7 @@ int ml_open(buf_T *buf)
* Only works when there's a swapfile, otherwise it's done when the file
* is created.
*/
mf_put(mfp, hp, TRUE, FALSE);
mf_put(mfp, hp, true, false);
if (!buf->b_help && !B_SPELL(buf))
(void)mf_sync(mfp, 0);
@@ -343,13 +344,13 @@ int ml_open(buf_T *buf)
EMSG(_("E298: Didn't get block nr 1?"));
goto error;
}
pp = (PTR_BL *)(hp->bh_data);
pp = hp->bh_data;
pp->pb_count = 1;
pp->pb_pointer[0].pe_bnum = 2;
pp->pb_pointer[0].pe_page_count = 1;
pp->pb_pointer[0].pe_old_lnum = 1;
pp->pb_pointer[0].pe_line_count = 1; /* line count after insertion */
mf_put(mfp, hp, TRUE, FALSE);
mf_put(mfp, hp, true, false);
/*
* Allocate first data block and create an empty line 1.
@@ -360,7 +361,7 @@ int ml_open(buf_T *buf)
goto error;
}
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
dp->db_index[0] = --dp->db_txt_start; /* at end of block */
dp->db_free -= 1 + INDEX_SIZE;
dp->db_line_count = 1;
@@ -371,8 +372,8 @@ int ml_open(buf_T *buf)
error:
if (mfp != NULL) {
if (hp)
mf_put(mfp, hp, FALSE, FALSE);
mf_close(mfp, TRUE); /* will also free(mfp->mf_fname) */
mf_put(mfp, hp, false, false);
mf_close(mfp, true); /* will also free(mfp->mf_fname) */
}
buf->b_ml.ml_mfp = NULL;
return FAIL;
@@ -525,7 +526,7 @@ void ml_open_file(buf_T *buf)
break;
}
/* Writing block 0 failed: close the file and try another dir */
mf_close_file(buf, FALSE);
mf_close_file(buf, false);
}
}
@@ -563,7 +564,7 @@ void ml_close(buf_T *buf, int del_file)
{
if (buf->b_ml.ml_mfp == NULL) /* not open */
return;
mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */
mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */
if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY))
free(buf->b_ml.ml_line_ptr);
free(buf->b_ml.ml_stack);
@@ -638,9 +639,9 @@ static void ml_upd_block0(buf_T *buf, upd_block0_T what)
ZERO_BL *b0p;
mfp = buf->b_ml.ml_mfp;
if (mfp == NULL || (hp = mf_get(mfp, (blocknr_T)0, 1)) == NULL)
if (mfp == NULL || (hp = mf_get(mfp, 0, 1)) == NULL)
return;
b0p = (ZERO_BL *)(hp->bh_data);
b0p = hp->bh_data;
if (ml_check_b0_id(b0p) == FAIL)
EMSG(_("E304: ml_upd_block0(): Didn't get block 0??"));
else {
@@ -649,7 +650,7 @@ static void ml_upd_block0(buf_T *buf, upd_block0_T what)
else /* what == UB_SAME_DIR */
set_b0_dir_flag(b0p, buf);
}
mf_put(mfp, hp, TRUE, FALSE);
mf_put(mfp, hp, true, false);
}
/*
@@ -866,7 +867,7 @@ void ml_recover(void)
/*
* try to read block 0
*/
if ((hp = mf_get(mfp, (blocknr_T)0, 1)) == NULL) {
if ((hp = mf_get(mfp, 0, 1)) == NULL) {
msg_start();
MSG_PUTS_ATTR(_("Unable to read block 0 from "), attr | MSG_HIST);
msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST);
@@ -876,7 +877,7 @@ void ml_recover(void)
msg_end();
goto theend;
}
b0p = (ZERO_BL *)(hp->bh_data);
b0p = hp->bh_data;
if (STRNCMP(b0p->b0_version, "VIM 3.0", 7) == 0) {
msg_start();
msg_outtrans_attr(mfp->mf_fname, MSG_HIST);
@@ -924,7 +925,7 @@ void ml_recover(void)
if ((size = lseek(mfp->mf_fd, (off_t)0L, SEEK_END)) <= 0)
mfp->mf_blocknr_max = 0; /* no file or empty file */
else
mfp->mf_blocknr_max = (blocknr_T)(size / mfp->mf_page_size);
mfp->mf_blocknr_max = size / mfp->mf_page_size;
mfp->mf_infile_count = mfp->mf_blocknr_max;
/* need to reallocate the memory used to store the data */
@@ -932,7 +933,7 @@ void ml_recover(void)
memmove(p, hp->bh_data, previous_page_size);
free(hp->bh_data);
hp->bh_data = p;
b0p = (ZERO_BL *)(hp->bh_data);
b0p = hp->bh_data;
}
/*
@@ -980,7 +981,7 @@ void ml_recover(void)
b0_fenc = vim_strnsave(p, (int)(b0p->b0_fname + fnsize - p));
}
mf_put(mfp, hp, FALSE, FALSE); /* release block 0 */
mf_put(mfp, hp, false, false); /* release block 0 */
hp = NULL;
/*
@@ -1025,12 +1026,12 @@ void ml_recover(void)
serious_error = FALSE;
for (; !got_int; line_breakcheck()) {
if (hp != NULL)
mf_put(mfp, hp, FALSE, FALSE); /* release previous block */
mf_put(mfp, hp, false, false); /* release previous block */
/*
* get block
*/
if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL) {
if ((hp = mf_get(mfp, bnum, page_count)) == NULL) {
if (bnum == 1) {
EMSG2(_("E309: Unable to read block 1 from %s"), mfp->mf_fname);
goto theend;
@@ -1039,7 +1040,7 @@ void ml_recover(void)
ml_append(lnum++, (char_u *)_("???MANY LINES MISSING"),
(colnr_T)0, TRUE);
} else { /* there is a block */
pp = (PTR_BL *)(hp->bh_data);
pp = hp->bh_data;
if (pp->pb_id == PTR_ID) { /* it is a pointer block */
/* check line count when using pointer block first time */
if (idx == 0 && line_count != 0) {
@@ -1096,7 +1097,7 @@ void ml_recover(void)
continue;
}
} else { /* not a pointer block */
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
if (dp->db_id != DATA_ID) { /* block id wrong */
if (bnum == 1) {
EMSG2(_("E310: Block 1 ID wrong (%s not a .swp file?)"),
@@ -1236,8 +1237,8 @@ theend:
recoverymode = FALSE;
if (mfp != NULL) {
if (hp != NULL)
mf_put(mfp, hp, FALSE, FALSE);
mf_close(mfp, FALSE); /* will also free(mfp->mf_fname) */
mf_put(mfp, hp, false, false);
mf_close(mfp, false); /* will also free(mfp->mf_fname) */
}
if (buf != NULL) {
free(buf->b_ml.ml_stack);
@@ -1809,7 +1810,7 @@ errorret:
goto errorret;
}
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
ptr = (char_u *)dp +
((dp->db_index[lnum - buf->b_ml.ml_locked_low]) & DB_INDEX_MASK);
@@ -1938,7 +1939,7 @@ ml_append_int (
/* get line count before the insertion */
line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low;
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
/*
* If
@@ -1964,7 +1965,7 @@ ml_append_int (
line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low;
CHECK(buf->b_ml.ml_locked_low != lnum + 1, "locked_low != lnum + 1");
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
}
++buf->b_ml.ml_line_count;
@@ -2083,8 +2084,8 @@ ml_append_int (
line_count_left = line_count;
line_count_right = 0;
}
dp_right = (DATA_BL *)(hp_right->bh_data);
dp_left = (DATA_BL *)(hp_left->bh_data);
dp_right = hp_right->bh_data;
dp_left = hp_left->bh_data;
bnum_left = hp_left->bh_bnum;
bnum_right = hp_right->bh_bnum;
page_count_left = hp_left->bh_page_count;
@@ -2166,7 +2167,7 @@ ml_append_int (
buf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
if (!newfile && db_idx >= 0 && in_left)
buf->b_ml.ml_flags |= ML_LOCKED_POS;
mf_put(mfp, hp_new, TRUE, FALSE);
mf_put(mfp, hp_new, true, false);
/*
* flush the old data block
@@ -2186,10 +2187,10 @@ ml_append_int (
pb_idx = ip->ip_index;
if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
return FAIL;
pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */
pp = hp->bh_data; /* must be pointer block */
if (pp->pb_id != PTR_ID) {
EMSG(_("E317: pointer block id wrong 3"));
mf_put(mfp, hp, FALSE, FALSE);
mf_put(mfp, hp, false, false);
return FAIL;
}
/*
@@ -2215,7 +2216,7 @@ ml_append_int (
if (lnum_right != 0)
pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right;
mf_put(mfp, hp, TRUE, FALSE);
mf_put(mfp, hp, true, false);
buf->b_ml.ml_stack_top = stack_idx + 1; /* truncate stack */
if (lineadd) {
@@ -2243,7 +2244,7 @@ ml_append_int (
hp_new = ml_new_ptr(mfp);
if (hp_new == NULL) /* TODO: try to fix tree */
return FAIL;
pp_new = (PTR_BL *)(hp_new->bh_data);
pp_new = hp_new->bh_data;
if (hp->bh_bnum != 1)
break;
@@ -2260,7 +2261,7 @@ ml_append_int (
pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count;
pp->pb_pointer[0].pe_old_lnum = 1;
pp->pb_pointer[0].pe_page_count = 1;
mf_put(mfp, hp, TRUE, FALSE); /* release block 1 */
mf_put(mfp, hp, true, false); /* release block 1 */
hp = hp_new; /* new block is to be split */
pp = pp_new;
CHECK(stack_idx != 0, _("stack_idx should be 0"));
@@ -2312,8 +2313,8 @@ ml_append_int (
bnum_right = hp_new->bh_bnum;
page_count_left = 1;
page_count_right = 1;
mf_put(mfp, hp, TRUE, FALSE);
mf_put(mfp, hp_new, TRUE, FALSE);
mf_put(mfp, hp, true, false);
mf_put(mfp, hp_new, true, false);
}
}
@@ -2426,7 +2427,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, int message)
if ((hp = ml_find_line(buf, lnum, ML_DELETE)) == NULL)
return FAIL;
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
/* compute line count before the delete */
count = (long)(buf->b_ml.ml_locked_high)
- (long)(buf->b_ml.ml_locked_low) + 2;
@@ -2460,10 +2461,10 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, int message)
idx = ip->ip_index;
if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
return FAIL;
pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */
pp = hp->bh_data; /* must be pointer block */
if (pp->pb_id != PTR_ID) {
EMSG(_("E317: pointer block id wrong 4"));
mf_put(mfp, hp, FALSE, FALSE);
mf_put(mfp, hp, false, false);
return FAIL;
}
count = --(pp->pb_count);
@@ -2473,7 +2474,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, int message)
if (count != idx) /* move entries after the deleted one */
memmove(&pp->pb_pointer[idx], &pp->pb_pointer[idx + 1],
(size_t)(count - idx) * sizeof(PTR_EN));
mf_put(mfp, hp, TRUE, FALSE);
mf_put(mfp, hp, true, false);
buf->b_ml.ml_stack_top = stack_idx; /* truncate stack */
/* fix line count for rest of blocks in the stack */
@@ -2540,7 +2541,7 @@ void ml_setmarked(linenr_T lnum)
if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
return; /* give error message? */
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
dp->db_index[lnum - curbuf->b_ml.ml_locked_low] |= DB_MARKED;
curbuf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
}
@@ -2571,7 +2572,7 @@ linenr_T ml_firstmarked(void)
if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
return (linenr_T)0; /* give error message? */
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
for (i = lnum - curbuf->b_ml.ml_locked_low;
lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum)
@@ -2611,7 +2612,7 @@ void ml_clearmarked(void)
if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
return; /* give error message? */
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
for (i = lnum - curbuf->b_ml.ml_locked_low;
lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum)
@@ -2660,7 +2661,7 @@ static void ml_flush_line(buf_T *buf)
if (hp == NULL)
EMSGN(_("E320: Cannot find line %" PRId64), lnum);
else {
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
idx = lnum - buf->b_ml.ml_locked_low;
start = ((dp->db_index[idx]) & DB_INDEX_MASK);
old_line = (char_u *)dp + start;
@@ -2725,8 +2726,9 @@ static void ml_flush_line(buf_T *buf)
*/
static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count)
{
bhdr_T *hp = mf_new(mfp, negative, page_count);
DATA_BL *dp = (DATA_BL *)(hp->bh_data);
assert(page_count >= 0);
bhdr_T *hp = mf_new(mfp, negative, (unsigned)page_count);
DATA_BL *dp = hp->bh_data;
dp->db_id = DATA_ID;
dp->db_txt_start = dp->db_txt_end = page_count * mfp->mf_page_size;
dp->db_free = dp->db_txt_start - HEADER_SIZE;
@@ -2740,8 +2742,8 @@ static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count)
*/
static bhdr_T *ml_new_ptr(memfile_T *mfp)
{
bhdr_T *hp = mf_new(mfp, FALSE, 1);
PTR_BL *pp = (PTR_BL *)(hp->bh_data);
bhdr_T *hp = mf_new(mfp, false, 1);
PTR_BL *pp = hp->bh_data;
pp->pb_id = PTR_ID;
pp->pb_count = 0;
pp->pb_count_max = (mfp->mf_page_size - sizeof(PTR_BL)) / sizeof(PTR_EN) + 1;
@@ -2855,7 +2857,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
else if (action == ML_DELETE)
--high;
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
if (dp->db_id == DATA_ID) { /* data block */
buf->b_ml.ml_locked = hp;
buf->b_ml.ml_locked_low = low;
@@ -2920,11 +2922,11 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
pp->pb_pointer[idx].pe_line_count++;
dirty = TRUE;
}
mf_put(mfp, hp, dirty, FALSE);
mf_put(mfp, hp, dirty, false);
}
error_block:
mf_put(mfp, hp, FALSE, FALSE);
mf_put(mfp, hp, false, false);
error_noblock:
/*
* If action is ML_DELETE or ML_INSERT we have to correct the tree for
@@ -2986,15 +2988,15 @@ static void ml_lineadd(buf_T *buf, int count)
ip = &(buf->b_ml.ml_stack[idx]);
if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
break;
pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */
pp = hp->bh_data; /* must be pointer block */
if (pp->pb_id != PTR_ID) {
mf_put(mfp, hp, FALSE, FALSE);
mf_put(mfp, hp, false, false);
EMSG(_("E317: pointer block id wrong 2"));
break;
}
pp->pb_pointer[ip->ip_index].pe_line_count += count;
ip->ip_high += count;
mf_put(mfp, hp, TRUE, FALSE);
mf_put(mfp, hp, true, false);
}
}
@@ -3639,7 +3641,7 @@ void ml_setflags(buf_T *buf)
return;
for (hp = buf->b_ml.ml_mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) {
if (hp->bh_bnum == 0) {
b0p = (ZERO_BL *)(hp->bh_data);
b0p = hp->bh_data;
b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0;
b0p->b0_flags = (b0p->b0_flags & ~B0_FF_MASK)
| (get_fileformat(buf) + 1);
@@ -3751,7 +3753,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
buf->b_ml.ml_usedchunks = -1;
return;
}
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
count = (long)(buf->b_ml.ml_locked_high) -
(long)(buf->b_ml.ml_locked_low) + 1;
idx = curline - buf->b_ml.ml_locked_low;
@@ -3800,7 +3802,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
buf->b_ml.ml_usedchunks = -1;
return;
}
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
if (dp->db_line_count == 1)
rest = dp->db_txt_end - dp->db_txt_start;
else
@@ -3911,7 +3913,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
if (curline > buf->b_ml.ml_line_count
|| (hp = ml_find_line(buf, curline, ML_FIND)) == NULL)
return -1;
dp = (DATA_BL *)(hp->bh_data);
dp = hp->bh_data;
count = (long)(buf->b_ml.ml_locked_high) -
(long)(buf->b_ml.ml_locked_low) + 1;
start_idx = idx = curline - buf->b_ml.ml_locked_low;

View File

@@ -5010,7 +5010,7 @@ set_bool_option (
else
/* no need to reset curbuf->b_may_swap, ml_open_file() will check
* buf->b_p_swf */
mf_close_file(curbuf, TRUE); /* remove the swap file */
mf_close_file(curbuf, true); /* remove the swap file */
}
/* when 'terse' is set change 'shortmess' */
else if ((int *)varp == &p_terse) {