summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Oliver Stöneberg <firewave@users.noreply.github.com>2014-05-16 11:44:16 +0000
committer Oliver Stöneberg <firewave@users.noreply.github.com>2014-05-16 11:44:16 +0000
commit4a2c6f727dd6631755da35a3259daa4e94d6028e (patch)
treed32da76b5a8f9bbd2d91c06ced7d2909c6cb6fa4
parent5de2a39c869ed1d2093feb7eb0985c823448ef61 (diff)
converted some global_alloc_array() usage to dynamic_buffer/dynamic_array (nw)
-rw-r--r--src/mess/drivers/psx.c6
-rw-r--r--src/mess/machine/microtan.c24
-rw-r--r--src/mess/machine/primo.c22
-rw-r--r--src/mess/machine/ti99/gromport.c7
4 files changed, 12 insertions, 47 deletions
diff --git a/src/mess/drivers/psx.c b/src/mess/drivers/psx.c
index b248a8926d7..025e9207764 100644
--- a/src/mess/drivers/psx.c
+++ b/src/mess/drivers/psx.c
@@ -356,7 +356,7 @@ int psx1_state::load_psf( cpu_device *cpu, unsigned char *p_n_file, int n_len )
unsigned long n_compressed;
unsigned char *p_n_compressed;
unsigned long n_uncompressed;
- unsigned char *p_n_uncompressed;
+ dynamic_buffer p_n_uncompressed;
struct PSF_HEADER
{
@@ -392,7 +392,7 @@ int psx1_state::load_psf( cpu_device *cpu, unsigned char *p_n_file, int n_len )
}
n_uncompressed = 0x200000;
- p_n_uncompressed = global_alloc_array( unsigned char, n_uncompressed );
+ p_n_uncompressed.resize( n_uncompressed );
if( uncompress( p_n_uncompressed, &n_uncompressed, p_n_compressed, n_compressed ) != Z_OK )
{
@@ -406,8 +406,6 @@ int psx1_state::load_psf( cpu_device *cpu, unsigned char *p_n_file, int n_len )
{
n_return = 1;
}
-
- global_free_array( p_n_uncompressed );
}
return n_return;
}
diff --git a/src/mess/machine/microtan.c b/src/mess/machine/microtan.c
index f7da67aa36b..46301984f15 100644
--- a/src/mess/machine/microtan.c
+++ b/src/mess/machine/microtan.c
@@ -834,27 +834,11 @@ SNAPSHOT_LOAD_MEMBER( microtan_state, microtan )
QUICKLOAD_LOAD_MEMBER( microtan_state, microtan )
{
- int snapshot_size;
- UINT8 *snapshot_buff;
- char *buff;
+ int snapshot_size = 8263; /* magic size */
+ dynamic_buffer snapshot_buff(snapshot_size, 0);
+ dynamic_array<char> buff(quickload_size + 1);
int rc;
- snapshot_size = 8263; /* magic size */
- snapshot_buff = global_alloc_array(UINT8, snapshot_size);
- if (!snapshot_buff)
- {
- logerror("microtan_hexfile_load: could not allocate %d bytes of buffer\n", snapshot_size);
- return IMAGE_INIT_FAIL;
- }
- memset(snapshot_buff, 0, snapshot_size);
-
- buff = global_alloc_array(char, quickload_size + 1);
- if (!buff)
- {
- global_free_array(snapshot_buff);
- logerror("microtan_hexfile_load: could not allocate %d bytes of buffer\n", quickload_size);
- return IMAGE_INIT_FAIL;
- }
image.fread( buff, quickload_size);
buff[quickload_size] = '\0';
@@ -865,7 +849,5 @@ QUICKLOAD_LOAD_MEMBER( microtan_state, microtan )
rc = parse_zillion_hex(snapshot_buff, buff);
if (rc == IMAGE_INIT_PASS)
microtan_snapshot_copy(snapshot_buff, snapshot_size);
- global_free_array(buff);
- global_free_array(snapshot_buff);
return rc;
}
diff --git a/src/mess/machine/primo.c b/src/mess/machine/primo.c
index 2555ec25cfe..9993646e66b 100644
--- a/src/mess/machine/primo.c
+++ b/src/mess/machine/primo.c
@@ -299,26 +299,20 @@ void primo_state::primo_setup_pss (UINT8* snapshot_data, UINT32 snapshot_size)
SNAPSHOT_LOAD_MEMBER( primo_state, primo )
{
- UINT8 *snapshot_data;
+ dynamic_buffer snapshot_data(snapshot_size);
- if (!(snapshot_data = global_alloc_array(UINT8, snapshot_size)))
- return IMAGE_INIT_FAIL;
-
- if (image.fread( snapshot_data, snapshot_size) != snapshot_size)
+ if (image.fread(snapshot_data, snapshot_size) != snapshot_size)
{
- global_free_array(snapshot_data);
return IMAGE_INIT_FAIL;
}
- if (strncmp((char *)snapshot_data, "PS01", 4))
+ if (strncmp((char *)(UINT8 *)snapshot_data, "PS01", 4))
{
- global_free_array(snapshot_data);
return IMAGE_INIT_FAIL;
}
primo_setup_pss(snapshot_data, snapshot_size);
- global_free_array(snapshot_data);
return IMAGE_INIT_PASS;
}
@@ -333,7 +327,6 @@ void primo_state::primo_setup_pp (UINT8* quickload_data, UINT32 quickload_size)
{
int i;
-
UINT16 load_addr;
UINT16 start_addr;
@@ -350,19 +343,14 @@ void primo_state::primo_setup_pp (UINT8* quickload_data, UINT32 quickload_size)
QUICKLOAD_LOAD_MEMBER( primo_state, primo )
{
- UINT8 *quickload_data;
-
- if (!(quickload_data = global_alloc_array(UINT8, quickload_size)))
- return IMAGE_INIT_FAIL;
+ dynamic_buffer quickload_data(quickload_size);
- if (image.fread( quickload_data, quickload_size) != quickload_size)
+ if (image.fread(quickload_data, quickload_size) != quickload_size)
{
- global_free_array(quickload_data);
return IMAGE_INIT_FAIL;
}
primo_setup_pp(quickload_data, quickload_size);
- global_free_array(quickload_data);
return IMAGE_INIT_PASS;
}
diff --git a/src/mess/machine/ti99/gromport.c b/src/mess/machine/ti99/gromport.c
index c126ac7bb9f..8412907e337 100644
--- a/src/mess/machine/ti99/gromport.c
+++ b/src/mess/machine/ti99/gromport.c
@@ -2311,7 +2311,7 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy
zip_file* zipfile;
- char *layout_text = NULL;
+ dynamic_array<char> layout_text;
xml_data_node *layout_xml = NULL;
xml_data_node *romset_node;
xml_data_node *configuration_node;
@@ -2337,8 +2337,7 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy
if (header == NULL) throw rpk_exception(RPK_MISSING_LAYOUT);
/* reserve space for the layout file contents (+1 for the termination) */
- layout_text = global_alloc_array(char, header->uncompressed_length + 1);
- if (layout_text == NULL) throw rpk_exception(RPK_OUT_OF_MEMORY);
+ layout_text.resize(header->uncompressed_length + 1);
/* uncompress the layout text */
ziperr = zip_file_decompress(zipfile, layout_text, header->uncompressed_length);
@@ -2430,7 +2429,6 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy
newrpk->close();
if (layout_xml != NULL) xml_file_free(layout_xml);
if (zipfile != NULL) zip_file_close(zipfile);
- if (layout_text != NULL) global_free_array(layout_text);
// rethrow the exception
throw exp;
@@ -2438,7 +2436,6 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy
if (layout_xml != NULL) xml_file_free(layout_xml);
if (zipfile != NULL) zip_file_close(zipfile);
- if (layout_text != NULL) global_free_array(layout_text);
return newrpk;
}