Skip to content

Commit

Permalink
No need for osd_malloc, osd_malloc_array and osd_free (nw)
Browse files Browse the repository at this point in the history
MALLOC_DEBUG not applicable anymore since we use new to allocate in 99.9% of cases
  • Loading branch information
mmicko committed Nov 11, 2016
1 parent 5c0edce commit 7c765ea
Show file tree
Hide file tree
Showing 25 changed files with 44 additions and 343 deletions.
4 changes: 0 additions & 4 deletions scripts/src/osd/sdl_cfg.lua
Expand Up @@ -111,10 +111,6 @@ if _OPTIONS["targetos"]=="windows" then
"_WIN32_WINNT=0x0501",
}

configuration { "Debug" }
defines {
"MALLOC_DEBUG",
}
configuration { }

elseif _OPTIONS["targetos"]=="linux" then
Expand Down
5 changes: 0 additions & 5 deletions scripts/src/osd/windows_cfg.lua
Expand Up @@ -12,11 +12,6 @@ configuration { "mingw* or vs*" }
"main=utf8_main",
}

configuration { "Debug" }
defines {
"MALLOC_DEBUG",
}

configuration { "vs*" }
flags {
"Unicode",
Expand Down
28 changes: 0 additions & 28 deletions src/devices/cpu/psx/dismips.cpp
Expand Up @@ -331,31 +331,3 @@ int main( int argc, char *argv[] )
free (filebuf);
return 0;
}

void *osd_malloc_array(size_t size)
{
return osd_malloc(size);
}

void *malloc_array_file_line(size_t size, const char *file, int line)
{
// allocate the memory and fail if we can't
return osd_malloc_array(size);
}

void free_file_line( void *memory, const char *file, int line )
{
osd_free( memory );
}

void osd_free( void *memory )
{
#undef free
free( memory );
}

void *osd_malloc( size_t size )
{
#undef malloc
return malloc( size );
}
2 changes: 1 addition & 1 deletion src/devices/machine/ram.cpp
Expand Up @@ -129,7 +129,7 @@ void ram_device::device_validity_check(validity_checker &valid) const
p += 1;
}

osd_free(s);
free(s);
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/mame/media_ident.cpp
Expand Up @@ -157,7 +157,7 @@ void media_identifier::identify_file(const char *name)
if (filerr == osd_file::error::NONE && length > 0)
{
identify_data(name, reinterpret_cast<uint8_t *>(data), length);
osd_free(data);
free(data);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/mame/ui/ui.cpp
Expand Up @@ -900,7 +900,7 @@ bool mame_ui_manager::can_paste()

// free the string if allocated
if (text != nullptr)
osd_free(text);
free(text);

// did we have text?
return text != nullptr;
Expand All @@ -923,7 +923,7 @@ void mame_ui_manager::paste()
machine().ioport().natkeyboard().post_utf8(text);

// free the string
osd_free(text);
free(text);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/corefile.cpp
Expand Up @@ -1207,7 +1207,7 @@ osd_file::error core_file::load(std::string const &filename, void **data, std::u
return osd_file::error::OUT_OF_MEMORY;

// allocate memory
*data = osd_malloc(size);
*data = malloc(size);
length = std::uint32_t(size);

// read the data
Expand Down
4 changes: 2 additions & 2 deletions src/lib/util/corestr.cpp
Expand Up @@ -109,15 +109,15 @@ int core_strwildcmp(const char *sp1, const char *sp2)


/*-------------------------------------------------
core_strdup - string duplication via osd_malloc
core_strdup - string duplication via malloc
-------------------------------------------------*/

char *core_strdup(const char *str)
{
char *cpy = nullptr;
if (str != nullptr)
{
cpy = (char *)osd_malloc_array(strlen(str) + 1);
cpy = (char *)malloc(strlen(str) + 1);
if (cpy != nullptr)
strcpy(cpy, str);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/corestr.h
Expand Up @@ -49,7 +49,7 @@ int core_strnicmp(const char *s1, const char *s2, size_t n);
#define strncasecmp MUST_USE_CORE_STRNICMP_INSTEAD


/* since strdup is not part of the standard, we use this instead - free with osd_free() */
/* since strdup is not part of the standard, we use this instead - free with free() */
char *core_strdup(const char *str);

/* this macro prevents people from using strdup directly */
Expand Down
20 changes: 10 additions & 10 deletions src/mame/machine/gaelco3d.cpp
Expand Up @@ -85,11 +85,11 @@
static osd_shared_mem *osd_sharedmem_alloc(const char *path, int create, size_t size)
{
int fd;
osd_shared_mem *os_shmem = (osd_shared_mem *) osd_malloc(sizeof(osd_shared_mem));
osd_shared_mem *os_shmem = (osd_shared_mem *)malloc(sizeof(osd_shared_mem));

if (create)
{
char *buf = (char *) osd_malloc_array(size);
char *buf = (char *) malloc(size);
memset(buf,0, size);

fd = open(path, O_RDWR | O_CREAT, S_IRWXU);
Expand All @@ -101,12 +101,12 @@ static osd_shared_mem *osd_sharedmem_alloc(const char *path, int create, size_t
fd = open(path, O_RDWR);
if (fd == -1)
{
osd_free(os_shmem);
free(os_shmem);
return nullptr;
}
os_shmem->creator = 0;
}
os_shmem->fn = (char *) osd_malloc_array(strlen(path)+1);
os_shmem->fn = (char *) malloc(strlen(path)+1);
strcpy(os_shmem->fn, path);

assert(fd != -1);
Expand All @@ -122,8 +122,8 @@ static void osd_sharedmem_free(osd_shared_mem *os_shmem)
munmap(os_shmem->ptr, os_shmem->size);
if (os_shmem->creator)
unlink(os_shmem->fn);
osd_free(os_shmem->fn);
osd_free(os_shmem);
free(os_shmem->fn);
free(os_shmem);
}

static void *osd_sharedmem_ptr(osd_shared_mem *os_shmem)
Expand All @@ -133,19 +133,19 @@ static void *osd_sharedmem_ptr(osd_shared_mem *os_shmem)
#else
static osd_shared_mem *osd_sharedmem_alloc(const char *path, int create, size_t size)
{
osd_shared_mem *os_shmem = (osd_shared_mem *) osd_malloc(sizeof(osd_shared_mem));
osd_shared_mem *os_shmem = (osd_shared_mem *) malloc(sizeof(osd_shared_mem));

os_shmem->creator = 0;

os_shmem->ptr = (void *) osd_malloc_array(size);
os_shmem->ptr = (void *) malloc(size);
os_shmem->size = size;
return os_shmem;
}

static void osd_sharedmem_free(osd_shared_mem *os_shmem)
{
osd_free(os_shmem->ptr);
osd_free(os_shmem);
free(os_shmem->ptr);
free(os_shmem);
}

static void *osd_sharedmem_ptr(osd_shared_mem *os_shmem)
Expand Down
2 changes: 1 addition & 1 deletion src/osd/modules/file/posixfile.cpp
Expand Up @@ -276,7 +276,7 @@ osd_file::error osd_file::open(std::string const &path, std::uint32_t openflags,
}
}

// if we still failed, clean up and osd_free
// if we still failed, clean up and free
if (fd < 0)
{
return errno_to_file_error(errno);
Expand Down
2 changes: 1 addition & 1 deletion src/osd/modules/file/stdfile.cpp
Expand Up @@ -197,7 +197,7 @@ osd_directory_entry *osd_stat(const std::string &path)

// create an osd_directory_entry; be sure to make sure that the caller can
// free all resources by just freeing the resulting osd_directory_entry
result = (osd_directory_entry *)osd_malloc_array(sizeof(*result) + path.length() + 1);
result = (osd_directory_entry *)malloc(sizeof(*result) + path.length() + 1);
strcpy((char *)(result + 1), path.c_str());
result->name = (char *)(result + 1);
result->type = ENTTYPE_NONE;
Expand Down
5 changes: 1 addition & 4 deletions src/osd/modules/lib/osdlib.h
Expand Up @@ -11,9 +11,6 @@
//
// - osd_ticks
// - osd_sleep
// - osd_malloc
// - osd_malloc_array
// - osd_free
//============================================================

#ifndef __OSDLIB__
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 1 addition & 43 deletions src/osd/modules/lib/osdlib_macosx.cpp
Expand Up @@ -57,48 +57,6 @@ void osd_process_kill()
kill(getpid(), SIGKILL);
}

//============================================================
// 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
//
Expand Down Expand Up @@ -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));
Expand Down
43 changes: 1 addition & 42 deletions src/osd/modules/lib/osdlib_unix.cpp
Expand Up @@ -55,47 +55,6 @@ void osd_process_kill()
kill(getpid(), SIGKILL);
}

//============================================================
// 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
//
Expand Down Expand Up @@ -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);
}
Expand Down
30 changes: 0 additions & 30 deletions src/osd/modules/lib/osdlib_uwp.cpp
Expand Up @@ -111,36 +111,6 @@ void osd_process_kill()
TerminateProcess(GetCurrentProcess(), -1);
}

//============================================================
// 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
//
Expand Down

0 comments on commit 7c765ea

Please sign in to comment.