aboutsummaryrefslogtreecommitdiff
path: root/src/memory.h
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-18 02:16:51 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-24 10:31:31 -0300
commit15d8f702a81803cf716b0da2b7b5c88e171580a6 (patch)
treeee4d90c977cbf437354e39a3fa529f9291f07849 /src/memory.h
parent1befc494144fbf1d5bff6d7eaeeae4bc20d75f54 (diff)
downloadrneovim-15d8f702a81803cf716b0da2b7b5c88e171580a6.tar.gz
rneovim-15d8f702a81803cf716b0da2b7b5c88e171580a6.tar.bz2
rneovim-15d8f702a81803cf716b0da2b7b5c88e171580a6.zip
(verbose_)?try_malloc() to use on buf_write()
There will be more use cases for try_malloc(): see #556. - Reimplemented xmalloc() using try_malloc(). - verbose_try_malloc() is just like try_malloc() but shows an out-of-memory error message before returning NULL. - Let the compiler generate size>>1 assembly for signed types. We're not using old compilers here. - Add proper function attributes to the new functions in memory.h
Diffstat (limited to 'src/memory.h')
-rw-r--r--src/memory.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/memory.h b/src/memory.h
index 05ac9359e5..bc20c0420e 100644
--- a/src/memory.h
+++ b/src/memory.h
@@ -10,6 +10,24 @@ char_u *alloc_clear(unsigned size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1);
/// malloc() wrapper
///
+/// try_malloc() is a malloc() wrapper that tries to free some memory before
+/// trying again.
+///
+/// @see {try_to_free_memory}
+/// @param size
+/// @return pointer to allocated space. NULL if out of memory
+void *try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1);
+
+/// try_malloc() wrapper that shows an out-of-memory error message to the user
+/// before returning NULL
+///
+/// @see {try_malloc}
+/// @param size
+/// @return pointer to allocated space. NULL if out of memory
+void *verbose_try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1);
+
+/// malloc() wrapper that never returns NULL
+///
/// xmalloc() succeeds or gracefully aborts when out of memory.
/// Before aborting try to free some memory and call malloc again.
///
@@ -51,7 +69,7 @@ void *xmallocz(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET;
/// @see {xmalloc}
/// @param data Pointer to the data that will be copied
/// @param len number of bytes that will be copied
-void *xmemdupz(const void *data, size_t len);
+void *xmemdupz(const void *data, size_t len) FUNC_ATTR_NONNULL_RET;
/// strdup() wrapper
///