summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2020-10-03 02:50:49 +1000
committer Vas Crabb <vas@vastheman.com>2020-10-03 03:00:24 +1000
commit4f05917494b22943ab0e7c466e4eb9f7a5896daa (patch)
treeb05a6b7820548f21ab8df21c4e4ca034eff0659f /src/devices/cpu
parent3340fc0d2171011e3f6d7f41f0414e9d3952e364 (diff)
Got rid of global_alloc/global_free.
The global_alloc/global_free functions have outlived their usefulness. They don't allow consistently overriding the default memory allocation behaviour because they aren't used consistently, and we don't have standard library allocator wrappers for them that we'd need to use them consistently with all the standard library containers we're using. If you need to change the default allocator behaviour, you can override the new/delete operators, and there are ways to get more fine-grained control that way. We're already doing that to pre-fill memory in debug builds. Code was already starting to depend on global_alloc/global_free wrapping new/delete. For example some parts of the code (including the UI and Windows debugger) was putting the result of global_alloc in a std::unique_ptr wrappers without custom deleters, and the SPU sound device was assuming it could use global_free to release memory allocated with operator new. There was also code misunderstanding the behaviour of global_alloc, for example the GROM port cartridge code was checking for nullptr when a failure will actually throw std::bad_alloc. As well as substituting new/delete, I've made several things use smart pointers to reduce the chance of leaks, and fixed a couple of leaks, too.
Diffstat (limited to 'src/devices/cpu')
-rw-r--r--src/devices/cpu/x86log.cpp4
-rw-r--r--src/devices/cpu/x86log.h34
2 files changed, 19 insertions, 19 deletions
diff --git a/src/devices/cpu/x86log.cpp b/src/devices/cpu/x86log.cpp
index b97f2553f11..7c7b13d1966 100644
--- a/src/devices/cpu/x86log.cpp
+++ b/src/devices/cpu/x86log.cpp
@@ -37,7 +37,7 @@ x86log_context *x86log_create_context(const char *filename)
x86log_context *log;
/* allocate the log */
- log = global_alloc_clear<x86log_context>();
+ log = new x86log_context;
/* allocate the filename */
log->filename.assign(filename);
@@ -59,7 +59,7 @@ void x86log_free_context(x86log_context *log) noexcept
fclose(log->file);
/* free the structure */
- global_free(log);
+ delete log;
}
diff --git a/src/devices/cpu/x86log.h b/src/devices/cpu/x86log.h
index ba2a349a55f..1383295e720 100644
--- a/src/devices/cpu/x86log.h
+++ b/src/devices/cpu/x86log.h
@@ -8,10 +8,10 @@
***************************************************************************/
-#pragma once
+#ifndef MAME_CPU_X86LOG_H
+#define MAME_CPU_X86LOG_H
-#ifndef __X86LOG_H__
-#define __X86LOG_H__
+#pragma once
#include <cstdint>
#include <cassert>
@@ -38,34 +38,34 @@ typedef uint8_t x86code;
/* code logging info */
struct log_comment
{
- x86code* base;
- const char* string;
+ x86code* base = nullptr;
+ const char* string = nullptr;
};
/* data ranges */
struct data_range_t
{
- x86code* base;
- x86code* end;
- int size;
+ x86code* base = nullptr;
+ x86code* end = nullptr;
+ int size = 0;
};
/* the code logging context */
struct x86log_context
{
- std::string filename; /* name of the file */
- FILE* file; /* file we are logging to */
+ std::string filename; // name of the file
+ FILE* file = nullptr; // file we are logging to
- data_range_t data_range[MAX_DATA_RANGES]; /* list of data ranges */
- int data_range_count; /* number of data ranges */
+ data_range_t data_range[MAX_DATA_RANGES]; // list of data ranges
+ int data_range_count = 0; // number of data ranges
- log_comment comment_list[MAX_COMMENTS]; /* list of comments */
- int comment_count; /* number of live comments */
+ log_comment comment_list[MAX_COMMENTS]; // list of comments
+ int comment_count = 0; // number of live comments
- char comment_pool[COMMENT_POOL_SIZE]; /* string pool to hold comments */
- char* comment_pool_next; /* pointer to next string pool location */
+ char comment_pool[COMMENT_POOL_SIZE]; // string pool to hold comments
+ char* comment_pool_next = nullptr; // pointer to next string pool location
};
@@ -160,4 +160,4 @@ inline void x86log_printf(x86log_context* log, const char* format, Ts&&... xs)
fflush(log->file);
}
-#endif /* __X86LOG_H__ */
+#endif // MAME_CPU_X86LOG_H