summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/lib
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-11-11 14:34:46 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2016-11-11 16:12:01 +0100
commit7c765ea14785a4ad6efd2e30e03447f354bed6b4 (patch)
tree8c1e3836d1c907378f61bb5748aac4219af68ce4 /src/osd/modules/lib
parent5c0edceec3a939ce7804b23beaeebfc700413489 (diff)
No need for osd_malloc, osd_malloc_array and osd_free (nw)
MALLOC_DEBUG not applicable anymore since we use new to allocate in 99.9% of cases
Diffstat (limited to 'src/osd/modules/lib')
-rw-r--r--src/osd/modules/lib/osdlib.h5
-rw-r--r--src/osd/modules/lib/osdlib_macosx.cpp44
-rw-r--r--src/osd/modules/lib/osdlib_unix.cpp43
-rw-r--r--src/osd/modules/lib/osdlib_uwp.cpp30
-rw-r--r--src/osd/modules/lib/osdlib_win32.cpp97
-rw-r--r--src/osd/modules/lib/osdobj_common.cpp2
6 files changed, 6 insertions, 215 deletions
diff --git a/src/osd/modules/lib/osdlib.h b/src/osd/modules/lib/osdlib.h
index 17f341b8934..7580c92dedd 100644
--- a/src/osd/modules/lib/osdlib.h
+++ b/src/osd/modules/lib/osdlib.h
@@ -11,9 +11,6 @@
//
// - osd_ticks
// - osd_sleep
-// - osd_malloc
-// - osd_malloc_array
-// - osd_free
//============================================================
#ifndef __OSDLIB__
@@ -60,7 +57,7 @@ int osd_setenv(const char *name, const char *value, int overwrite);
Return value:
- the returned string needs to be osd_free()-ed!
+ the returned string needs to be free-ed!
-----------------------------------------------------------------------------*/
char *osd_get_clipboard_text(void);
diff --git a/src/osd/modules/lib/osdlib_macosx.cpp b/src/osd/modules/lib/osdlib_macosx.cpp
index 94b935de08d..0d353531b0d 100644
--- a/src/osd/modules/lib/osdlib_macosx.cpp
+++ b/src/osd/modules/lib/osdlib_macosx.cpp
@@ -58,48 +58,6 @@ void osd_process_kill()
}
//============================================================
-// osd_malloc
-//============================================================
-
-void *osd_malloc(size_t size)
-{
-#ifndef MALLOC_DEBUG
- return malloc(size);
-#else
-#error "MALLOC_DEBUG not yet supported"
-#endif
-}
-
-
-//============================================================
-// osd_malloc_array
-//============================================================
-
-void *osd_malloc_array(size_t size)
-{
-#ifndef MALLOC_DEBUG
- return malloc(size);
-#else
-#error "MALLOC_DEBUG not yet supported"
-#endif
-}
-
-
-//============================================================
-// osd_free
-//============================================================
-
-void osd_free(void *ptr)
-{
-#ifndef MALLOC_DEBUG
- free(ptr);
-#else
-#error "MALLOC_DEBUG not yet supported"
-#endif
-}
-
-
-//============================================================
// osd_alloc_executable
//
// allocates "size" bytes of executable memory. this must take
@@ -205,7 +163,7 @@ char *osd_get_clipboard_text(void)
CFIndex const length = CFDataGetLength(data_ref);
CFRange const range = CFRangeMake(0, length);
- result = reinterpret_cast<char *>(osd_malloc_array(length + 1));
+ result = reinterpret_cast<char *>(malloc(length + 1));
if (result)
{
CFDataGetBytes(data_ref, range, reinterpret_cast<unsigned char *>(result));
diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp
index 054c4591f71..f6e892455f8 100644
--- a/src/osd/modules/lib/osdlib_unix.cpp
+++ b/src/osd/modules/lib/osdlib_unix.cpp
@@ -56,47 +56,6 @@ void osd_process_kill()
}
//============================================================
-// osd_malloc
-//============================================================
-
-void *osd_malloc(size_t size)
-{
-#ifndef MALLOC_DEBUG
- return malloc(size);
-#else
-#error "MALLOC_DEBUG not yet supported"
-#endif
-}
-
-
-//============================================================
-// osd_malloc_array
-//============================================================
-
-void *osd_malloc_array(size_t size)
-{
-#ifndef MALLOC_DEBUG
- return malloc(size);
-#else
-#error "MALLOC_DEBUG not yet supported"
-#endif
-}
-
-
-//============================================================
-// osd_free
-//============================================================
-
-void osd_free(void *ptr)
-{
-#ifndef MALLOC_DEBUG
- free(ptr);
-#else
-#error "MALLOC_DEBUG not yet supported"
-#endif
-}
-
-//============================================================
// osd_alloc_executable
//
// allocates "size" bytes of executable memory. this must take
@@ -160,7 +119,7 @@ char *osd_get_clipboard_text(void)
if (SDL_HasClipboardText())
{
char *temp = SDL_GetClipboardText();
- result = (char *) osd_malloc_array(strlen(temp) + 1);
+ result = (char *) malloc(strlen(temp) + 1);
strcpy(result, temp);
SDL_free(temp);
}
diff --git a/src/osd/modules/lib/osdlib_uwp.cpp b/src/osd/modules/lib/osdlib_uwp.cpp
index 344418e7efb..87e3a56e0d6 100644
--- a/src/osd/modules/lib/osdlib_uwp.cpp
+++ b/src/osd/modules/lib/osdlib_uwp.cpp
@@ -112,36 +112,6 @@ void osd_process_kill()
}
//============================================================
-// osd_malloc
-//============================================================
-
-void *osd_malloc(size_t size)
-{
- return malloc(size);
-}
-
-
-//============================================================
-// osd_malloc_array
-//============================================================
-
-void *osd_malloc_array(size_t size)
-{
- return malloc(size);
-}
-
-
-//============================================================
-// osd_free
-//============================================================
-
-void osd_free(void *ptr)
-{
- free(ptr);
-}
-
-
-//============================================================
// osd_alloc_executable
//
// allocates "size" bytes of executable memory. this must take
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp
index d75bbea87e4..8760d4be9a3 100644
--- a/src/osd/modules/lib/osdlib_win32.cpp
+++ b/src/osd/modules/lib/osdlib_win32.cpp
@@ -84,7 +84,7 @@ int osd_setenv(const char *name, const char *value, int overwrite)
if (osd_getenv(name) != nullptr)
return 0;
}
- buf = (char *) osd_malloc_array(strlen(name)+strlen(value)+2);
+ buf = (char *) malloc(strlen(name)+strlen(value)+2);
sprintf(buf, "%s=%s", name, value);
result = putenv(buf);
@@ -107,99 +107,6 @@ void osd_process_kill()
}
//============================================================
-// osd_malloc
-//============================================================
-
-void *osd_malloc(size_t size)
-{
-#ifndef MALLOC_DEBUG
- return malloc(size);
-#else
- // add in space for the size and offset
- size += MAX_ALIGNMENT + sizeof(size_t) + 2;
- size &= ~size_t(1);
-
- // basic objects just come from the heap
- uint8_t *const block = reinterpret_cast<uint8_t *>(HeapAlloc(GetProcessHeap(), 0, size));
- if (block == nullptr)
- return nullptr;
- uint8_t *const result = reinterpret_cast<uint8_t *>(reinterpret_cast<uintptr_t>(block + sizeof(size_t) + MAX_ALIGNMENT) & ~(uintptr_t(MAX_ALIGNMENT) - 1));
-
- // store the size and return and pointer to the data afterward
- *reinterpret_cast<size_t *>(block) = size;
- *(result - 1) = result - block;
- return result;
-#endif
-}
-
-
-//============================================================
-// osd_malloc_array
-//============================================================
-
-void *osd_malloc_array(size_t size)
-{
-#ifndef MALLOC_DEBUG
- return malloc(size);
-#else
- // add in space for the size and offset
- size += MAX_ALIGNMENT + sizeof(size_t) + 2;
- size &= ~size_t(1);
-
- // round the size up to a page boundary
- size_t const rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
-
- // reserve that much memory, plus two guard pages
- void *page_base = VirtualAlloc(nullptr, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
- if (page_base == nullptr)
- return nullptr;
-
- // now allow access to everything but the first and last pages
- page_base = VirtualAlloc(reinterpret_cast<uint8_t *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE);
- if (page_base == nullptr)
- return nullptr;
-
- // work backwards from the page base to get to the block base
- uint8_t *const block = GUARD_ALIGN_START ? reinterpret_cast<uint8_t *>(page_base) : (reinterpret_cast<uint8_t *>(page_base) + rounded_size - size);
- uint8_t *const result = reinterpret_cast<uint8_t *>(reinterpret_cast<uintptr_t>(block + sizeof(size_t) + MAX_ALIGNMENT) & ~(uintptr_t(MAX_ALIGNMENT) - 1));
-
- // store the size at the start with a flag indicating it has a guard page
- *reinterpret_cast<size_t *>(block) = size | 1;
- *(result - 1) = result - block;
- return result;
-#endif
-}
-
-
-//============================================================
-// osd_free
-//============================================================
-
-void osd_free(void *ptr)
-{
-#ifndef MALLOC_DEBUG
- free(ptr);
-#else
- uint8_t const offset = *(reinterpret_cast<uint8_t *>(ptr) - 1);
- uint8_t *const block = reinterpret_cast<uint8_t *>(ptr) - offset;
- size_t const size = *reinterpret_cast<size_t *>(block);
-
- if ((size & 0x1) == 0)
- {
- // if no guard page, just free the pointer
- HeapFree(GetProcessHeap(), 0, block);
- }
- else
- {
- // large items need more care
- ULONG_PTR const page_base = reinterpret_cast<ULONG_PTR>(block) & ~(PAGE_SIZE - 1);
- VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE);
- }
-#endif
-}
-
-
-//============================================================
// osd_alloc_executable
//
// allocates "size" bytes of executable memory. this must take
@@ -275,7 +182,7 @@ static char *get_clipboard_text_by_format(UINT format, std::string (*convert)(LP
std::string s = (*convert)(data);
// copy the string
- result = (char *) osd_malloc(s.size() + 1);
+ result = (char *) malloc(s.size() + 1);
if (result != nullptr)
memcpy(result, s.data(), (s.size() + 1) * sizeof(*result));
diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp
index e9ab4f76060..3f4763626fa 100644
--- a/src/osd/modules/lib/osdobj_common.cpp
+++ b/src/osd/modules/lib/osdobj_common.cpp
@@ -193,7 +193,7 @@ osd_common_t::osd_common_t(osd_options &options)
osd_common_t::~osd_common_t()
{
for(unsigned int i= 0; i < m_video_names.size(); ++i)
- osd_free(const_cast<char*>(m_video_names[i]));
+ free(const_cast<char*>(m_video_names[i]));
//m_video_options,reset();
osd_output::pop(this);
}