mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
Review: Remove long_u: memfile: Add to clint.
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
src/nvim/api/buffer.c
|
src/nvim/api/buffer.c
|
||||||
src/nvim/api/buffer.h
|
src/nvim/api/buffer.h
|
||||||
src/nvim/api/private/defs.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.c
|
||||||
src/nvim/api/private/handle.h
|
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.c
|
||||||
src/nvim/api/tabpage.h
|
src/nvim/api/tabpage.h
|
||||||
src/nvim/api/vim.c
|
src/nvim/api/vim.c
|
||||||
@@ -22,6 +22,15 @@ src/nvim/log.h
|
|||||||
src/nvim/map.c
|
src/nvim/map.c
|
||||||
src/nvim/map.h
|
src/nvim/map.h
|
||||||
src/nvim/map_defs.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/env.c
|
||||||
src/nvim/os/event.c
|
src/nvim/os/event.c
|
||||||
src/nvim/os/event.h
|
src/nvim/os/event.h
|
||||||
@@ -42,13 +51,7 @@ src/nvim/os/signal.c
|
|||||||
src/nvim/os/signal.h
|
src/nvim/os/signal.h
|
||||||
src/nvim/os/time.c
|
src/nvim/os/time.c
|
||||||
src/nvim/os/time.h
|
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.c
|
||||||
src/nvim/profile.h
|
src/nvim/profile.h
|
||||||
|
src/nvim/tempfile.c
|
||||||
|
src/nvim/tempfile.h
|
||||||
|
@@ -144,7 +144,7 @@ memfile_T *mf_open(char_u *fname, int flags)
|
|||||||
mfp->mf_infile_count = mfp->mf_blocknr_max;
|
mfp->mf_infile_count = mfp->mf_blocknr_max;
|
||||||
|
|
||||||
// Compute maximum number of pages ('maxmem' is in Kbytes):
|
// Compute maximum number of pages ('maxmem' is in Kbytes):
|
||||||
// 'mammem' * 1Kbyte / page-size-in-bytes.
|
// 'mammem' * 1Kbyte / page-size-in-bytes.
|
||||||
// Avoid overflow by first reducing page size as much as possible.
|
// Avoid overflow by first reducing page size as much as possible.
|
||||||
{
|
{
|
||||||
int shift = 10;
|
int shift = 10;
|
||||||
@@ -222,7 +222,7 @@ void mf_close(memfile_T *mfp, bool del_file)
|
|||||||
/// Close the swap file for a memfile. Used when 'swapfile' is reset.
|
/// Close the swap file for a memfile. Used when 'swapfile' is reset.
|
||||||
///
|
///
|
||||||
/// @param getlines Whether to get all lines into memory.
|
/// @param getlines Whether to get all lines into memory.
|
||||||
void mf_close_file (buf_T *buf, bool getlines)
|
void mf_close_file(buf_T *buf, bool getlines)
|
||||||
{
|
{
|
||||||
memfile_T *mfp = buf->b_ml.ml_mfp;
|
memfile_T *mfp = buf->b_ml.ml_mfp;
|
||||||
if (mfp == NULL || mfp->mf_fd < 0) // nothing to close
|
if (mfp == NULL || mfp->mf_fd < 0) // nothing to close
|
||||||
@@ -230,11 +230,11 @@ void mf_close_file (buf_T *buf, bool getlines)
|
|||||||
|
|
||||||
if (getlines) {
|
if (getlines) {
|
||||||
// get all blocks in memory by accessing all lines (clumsy!)
|
// get all blocks in memory by accessing all lines (clumsy!)
|
||||||
mf_dont_release = TRUE;
|
mf_dont_release = true;
|
||||||
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
|
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
|
||||||
(void)ml_get_buf(buf, lnum, FALSE);
|
(void)ml_get_buf(buf, lnum, false);
|
||||||
mf_dont_release = FALSE;
|
mf_dont_release = false;
|
||||||
// TODO: should check if all blocks are really in core
|
// TODO(elmart): should check if all blocks are really in core
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(mfp->mf_fd) < 0) // close the file
|
if (close(mfp->mf_fd) < 0) // close the file
|
||||||
@@ -265,7 +265,7 @@ void mf_new_page_size(memfile_T *mfp, unsigned new_size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get a new block
|
/// Get a new block
|
||||||
///
|
///
|
||||||
/// @param negative Whether a negative block number is desired (data block).
|
/// @param negative Whether a negative block number is desired (data block).
|
||||||
/// @param page_count Desired number of pages.
|
/// @param page_count Desired number of pages.
|
||||||
bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
|
bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
|
||||||
@@ -283,10 +283,10 @@ bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
|
|||||||
if (!negative && freep != NULL && freep->bh_page_count >= page_count) {
|
if (!negative && freep != NULL && freep->bh_page_count >= page_count) {
|
||||||
// If the block in the free list has more pages, take only the number
|
// If the block in the free list has more pages, take only the number
|
||||||
// of pages needed and allocate a new bhdr_T with data.
|
// of pages needed and allocate a new bhdr_T with data.
|
||||||
//
|
//
|
||||||
// If the number of pages matches and mf_release() did not return a
|
// If the number of pages matches and mf_release() did not return a
|
||||||
// bhdr_T, use the bhdr_T from the free list and allocate the data.
|
// bhdr_T, use the bhdr_T from the free list and allocate the data.
|
||||||
//
|
//
|
||||||
// If the number of pages matches and mf_release() returned a bhdr_T,
|
// If the number of pages matches and mf_release() returned a bhdr_T,
|
||||||
// just use the number and free the bhdr_T from the free list
|
// just use the number and free the bhdr_T from the free list
|
||||||
if (freep->bh_page_count > page_count) {
|
if (freep->bh_page_count > page_count) {
|
||||||
@@ -377,7 +377,7 @@ bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, unsigned page_count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Release the block *hp.
|
/// Release the block *hp.
|
||||||
///
|
///
|
||||||
/// @param dirty Whether block must be written to file later.
|
/// @param dirty Whether block must be written to file later.
|
||||||
/// @param infile Whether block should be in file (needed for recovery).
|
/// @param infile Whether block should be in file (needed for recovery).
|
||||||
void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile)
|
void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile)
|
||||||
@@ -405,8 +405,9 @@ void mf_free(memfile_T *mfp, bhdr_T *hp)
|
|||||||
if (hp->bh_bnum < 0) {
|
if (hp->bh_bnum < 0) {
|
||||||
free(hp); // don't want negative numbers in free list
|
free(hp); // don't want negative numbers in free list
|
||||||
mfp->mf_neg_count--;
|
mfp->mf_neg_count--;
|
||||||
} else
|
} else {
|
||||||
mf_ins_free(mfp, hp); // put *hp in the free list
|
mf_ins_free(mfp, hp); // put *hp in the free list
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sync memory file to disk.
|
/// Sync memory file to disk.
|
||||||
@@ -418,7 +419,7 @@ void mf_free(memfile_T *mfp, bhdr_T *hp)
|
|||||||
/// MFS_FLUSH Make sure buffers are flushed to disk, so they will
|
/// MFS_FLUSH Make sure buffers are flushed to disk, so they will
|
||||||
/// survive a system crash.
|
/// survive a system crash.
|
||||||
/// MFS_ZERO Only write block 0.
|
/// MFS_ZERO Only write block 0.
|
||||||
///
|
///
|
||||||
/// @return FAIL If failure. Possible causes:
|
/// @return FAIL If failure. Possible causes:
|
||||||
/// - No file (nothing to do).
|
/// - No file (nothing to do).
|
||||||
/// - Write error (probably full disk).
|
/// - Write error (probably full disk).
|
||||||
@@ -433,7 +434,7 @@ int mf_sync(memfile_T *mfp, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only a CTRL-C while writing will break us here, not one typed previously.
|
// Only a CTRL-C while writing will break us here, not one typed previously.
|
||||||
got_int = FALSE;
|
got_int = false;
|
||||||
|
|
||||||
// Sync from last to first (may reduce the probability of an inconsistent
|
// Sync from last to first (may reduce the probability of an inconsistent
|
||||||
// file). If a write fails, it is very likely caused by a full filesystem.
|
// file). If a write fails, it is very likely caused by a full filesystem.
|
||||||
@@ -456,8 +457,9 @@ int mf_sync(memfile_T *mfp, int flags)
|
|||||||
if (flags & MFS_STOP) { // Stop when char available now.
|
if (flags & MFS_STOP) { // Stop when char available now.
|
||||||
if (ui_char_avail())
|
if (ui_char_avail())
|
||||||
break;
|
break;
|
||||||
} else
|
} else {
|
||||||
ui_breakcheck();
|
ui_breakcheck();
|
||||||
|
}
|
||||||
if (got_int)
|
if (got_int)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -473,7 +475,7 @@ int mf_sync(memfile_T *mfp, int flags)
|
|||||||
if (STRCMP(p_sws, "fsync") == 0) {
|
if (STRCMP(p_sws, "fsync") == 0) {
|
||||||
if (fsync(mfp->mf_fd))
|
if (fsync(mfp->mf_fd))
|
||||||
status = FAIL;
|
status = FAIL;
|
||||||
} else
|
} else {
|
||||||
# endif
|
# endif
|
||||||
// OpenNT is strictly POSIX (Benzinger).
|
// OpenNT is strictly POSIX (Benzinger).
|
||||||
// Tandem/Himalaya NSK-OSS doesn't have sync()
|
// Tandem/Himalaya NSK-OSS doesn't have sync()
|
||||||
@@ -482,6 +484,9 @@ int mf_sync(memfile_T *mfp, int flags)
|
|||||||
# else
|
# else
|
||||||
sync();
|
sync();
|
||||||
# endif
|
# endif
|
||||||
|
# ifdef HAVE_FSYNC
|
||||||
|
}
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
# ifdef SYNC_DUP_CLOSE
|
# ifdef SYNC_DUP_CLOSE
|
||||||
// Win32 is a bit more work: Duplicate the file handle and close it.
|
// Win32 is a bit more work: Duplicate the file handle and close it.
|
||||||
@@ -559,7 +564,7 @@ static void mf_rem_used(memfile_T *mfp, bhdr_T *hp)
|
|||||||
|
|
||||||
/// Try to release the least recently used block from the used list if the
|
/// Try to release the least recently used block from the used list if the
|
||||||
/// number of used memory blocks gets too big.
|
/// number of used memory blocks gets too big.
|
||||||
///
|
///
|
||||||
/// @return The block header, when release needed and possible.
|
/// @return The block header, when release needed and possible.
|
||||||
/// Resulting block header includes memory block, so it can be
|
/// Resulting block header includes memory block, so it can be
|
||||||
/// reused. Page count is checked to be right.
|
/// reused. Page count is checked to be right.
|
||||||
@@ -633,7 +638,7 @@ static bhdr_T *mf_release(memfile_T *mfp, unsigned page_count)
|
|||||||
/// Release as many blocks as possible.
|
/// Release as many blocks as possible.
|
||||||
///
|
///
|
||||||
/// Used in case of out of memory
|
/// Used in case of out of memory
|
||||||
///
|
///
|
||||||
/// @return Whether any memory was released.
|
/// @return Whether any memory was released.
|
||||||
bool mf_release_all(void)
|
bool mf_release_all(void)
|
||||||
{
|
{
|
||||||
@@ -656,8 +661,9 @@ bool mf_release_all(void)
|
|||||||
mf_free_bhdr(hp);
|
mf_free_bhdr(hp);
|
||||||
hp = mfp->mf_used_last; // restart, list was changed
|
hp = mfp->mf_used_last; // restart, list was changed
|
||||||
retval = true;
|
retval = true;
|
||||||
} else
|
} else {
|
||||||
hp = hp->bh_prev;
|
hp = hp->bh_prev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -699,7 +705,7 @@ static bhdr_T *mf_rem_free(memfile_T *mfp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Read a block from disk.
|
/// Read a block from disk.
|
||||||
///
|
///
|
||||||
/// @return OK On success.
|
/// @return OK On success.
|
||||||
/// FAIL On failure. Could be:
|
/// FAIL On failure. Could be:
|
||||||
/// - No file.
|
/// - No file.
|
||||||
@@ -728,7 +734,7 @@ static int mf_read(memfile_T *mfp, bhdr_T *hp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write a block to disk.
|
/// Write a block to disk.
|
||||||
///
|
///
|
||||||
/// @return OK On success.
|
/// @return OK On success.
|
||||||
/// FAIL On failure. Could be:
|
/// FAIL On failure. Could be:
|
||||||
/// - No file.
|
/// - No file.
|
||||||
@@ -762,8 +768,9 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
|
|||||||
if (nr > mfp->mf_infile_count) { // beyond end of file
|
if (nr > mfp->mf_infile_count) { // beyond end of file
|
||||||
nr = mfp->mf_infile_count;
|
nr = mfp->mf_infile_count;
|
||||||
hp2 = mf_find_hash(mfp, nr); // NULL caught below
|
hp2 = mf_find_hash(mfp, nr); // NULL caught below
|
||||||
} else
|
} else {
|
||||||
hp2 = hp;
|
hp2 = hp;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(elmart): Check (page_size * nr) within off_t bounds.
|
// TODO(elmart): Check (page_size * nr) within off_t bounds.
|
||||||
offset = (off_t)(page_size * nr);
|
offset = (off_t)(page_size * nr);
|
||||||
@@ -783,10 +790,10 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
|
|||||||
/// space becomes available.
|
/// space becomes available.
|
||||||
if (!did_swapwrite_msg)
|
if (!did_swapwrite_msg)
|
||||||
EMSG(_("E297: Write error in swap file"));
|
EMSG(_("E297: Write error in swap file"));
|
||||||
did_swapwrite_msg = TRUE;
|
did_swapwrite_msg = true;
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
did_swapwrite_msg = FALSE;
|
did_swapwrite_msg = false;
|
||||||
if (hp2 != NULL) // written a non-dummy block
|
if (hp2 != NULL) // written a non-dummy block
|
||||||
hp2->bh_flags &= ~BH_DIRTY;
|
hp2->bh_flags &= ~BH_DIRTY;
|
||||||
if (nr + (blocknr_T)page_count > mfp->mf_infile_count) // appended to file
|
if (nr + (blocknr_T)page_count > mfp->mf_infile_count) // appended to file
|
||||||
@@ -812,7 +819,7 @@ static int mf_write_block(memfile_T *mfp, bhdr_T *hp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Make block number positive and add it to the translation list.
|
/// Make block number positive and add it to the translation list.
|
||||||
///
|
///
|
||||||
/// @return OK On success.
|
/// @return OK On success.
|
||||||
/// FAIL On failure.
|
/// FAIL On failure.
|
||||||
static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
|
static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
|
||||||
@@ -858,7 +865,7 @@ static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Lookup translation from trans list and delete the entry.
|
/// Lookup translation from trans list and delete the entry.
|
||||||
///
|
///
|
||||||
/// @return The positive new number When found.
|
/// @return The positive new number When found.
|
||||||
/// The old number When not found.
|
/// The old number When not found.
|
||||||
blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
|
blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
|
||||||
@@ -887,7 +894,7 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
|
|||||||
/// name so we must work out the full path name.
|
/// name so we must work out the full path name.
|
||||||
void mf_set_ffname(memfile_T *mfp)
|
void mf_set_ffname(memfile_T *mfp)
|
||||||
{
|
{
|
||||||
mfp->mf_ffname = FullName_save(mfp->mf_fname, FALSE);
|
mfp->mf_ffname = FullName_save(mfp->mf_fname, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make name of memfile's swapfile a full path.
|
/// Make name of memfile's swapfile a full path.
|
||||||
@@ -913,7 +920,7 @@ bool mf_need_trans(memfile_T *mfp)
|
|||||||
/// "fname" must be in allocated memory, and is consumed (also when error).
|
/// "fname" must be in allocated memory, and is consumed (also when error).
|
||||||
///
|
///
|
||||||
/// @param flags Flags for open().
|
/// @param flags Flags for open().
|
||||||
static void mf_do_open (memfile_T *mfp, char_u *fname, int flags)
|
static void mf_do_open(memfile_T *mfp, char_u *fname, int flags)
|
||||||
{
|
{
|
||||||
// fname cannot be NameBuff, because it must have been allocated.
|
// fname cannot be NameBuff, because it must have been allocated.
|
||||||
mfp->mf_fname = fname;
|
mfp->mf_fname = fname;
|
||||||
@@ -951,9 +958,9 @@ static void mf_do_open (memfile_T *mfp, char_u *fname, int flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Implementation of mf_hashtab_T.
|
// Implementation of mf_hashtab_T.
|
||||||
//
|
//
|
||||||
|
|
||||||
/// The number of buckets in the hashtable is increased by a factor of
|
/// The number of buckets in the hashtable is increased by a factor of
|
||||||
/// MHT_GROWTH_FACTOR when the average number of items per bucket
|
/// MHT_GROWTH_FACTOR when the average number of items per bucket
|
||||||
@@ -1056,7 +1063,7 @@ static void mf_hash_grow(mf_hashtab_T *mht)
|
|||||||
/// within each new bucket. Preserving the order is important because
|
/// within each new bucket. Preserving the order is important because
|
||||||
/// mf_get() tries to keep most recently used items at the front of
|
/// mf_get() tries to keep most recently used items at the front of
|
||||||
/// each bucket.
|
/// each bucket.
|
||||||
///
|
///
|
||||||
/// Here we strongly rely on the fact that hashes are computed modulo
|
/// Here we strongly rely on the fact that hashes are computed modulo
|
||||||
/// a power of two.
|
/// a power of two.
|
||||||
|
|
||||||
|
@@ -105,4 +105,4 @@ typedef struct memfile {
|
|||||||
bool mf_dirty; /// TRUE if there are dirty blocks
|
bool mf_dirty; /// TRUE if there are dirty blocks
|
||||||
} memfile_T;
|
} memfile_T;
|
||||||
|
|
||||||
#endif // NVIM_MEMFILE_DEFS_H
|
#endif // NVIM_MEMFILE_DEFS_H
|
||||||
|
Reference in New Issue
Block a user