diff options
author | Aaron Giles <aaron@aarongiles.com> | 2009-04-26 23:54:37 +0000 |
---|---|---|
committer | Aaron Giles <aaron@aarongiles.com> | 2009-04-26 23:54:37 +0000 |
commit | ad4910a8a8c0b1ca6930eee35121fe18aca84cd3 (patch) | |
tree | dab6938694ab159063c0f5f6496e98ea51efd42e /src/osd | |
parent | 7c137ce2a7194bee4dab2e341595898b3410d74d (diff) |
Bulk change alert.
This update changes the way we handle memory allocation. Rather
than allocating in terms of bytes, allocations are now done in
terms of objects. This is done via new set of macros that replace
the malloc_or_die() macro:
alloc_or_die(t) - allocate memory for an object of type 't'
alloc_array_or_die(t,c) - allocate memory for an array of 'c' objects of type 't'
alloc_clear_or_die(t) - same as alloc_or_die but memset's the memory to 0
alloc_array_clear_or_die(t,c) - same as alloc_array_or_die but memset's the memory to 0
All original callers of malloc_or_die have been updated to call these
new macros. If you just need an array of bytes, you can use
alloc_array_or_die(UINT8, numbytes).
Made a similar change to the auto_* allocation macros. In addition,
added 'machine' as a required parameter to the auto-allocation macros,
as the resource pools will eventually be owned by the machine object.
The new macros are:
auto_alloc(m,t) - allocate memory for an object of type 't'
auto_alloc_array(m,t,c) - allocate memory for an array of 'c' objects of type 't'
auto_alloc_clear(m,t) - allocate and memset
auto_alloc_array_clear(m,t,c) - allocate and memset
All original calls or auto_malloc have been updated to use the new
macros. In addition, auto_realloc(), auto_strdup(), auto_astring_alloc(),
and auto_bitmap_alloc() have been updated to take a machine parameter.
Changed validity check allocations to not rely on auto_alloc* anymore
because they are not done in the context of a machine.
One final change that is included is the removal of SMH_BANKn macros.
Just use SMH_BANK(n) instead, which is what the previous macros mapped
to anyhow.
Diffstat (limited to 'src/osd')
-rw-r--r-- | src/osd/windows/d3d8intf.c | 2 | ||||
-rw-r--r-- | src/osd/windows/d3d9intf.c | 2 | ||||
-rw-r--r-- | src/osd/windows/debugwin.c | 3 | ||||
-rw-r--r-- | src/osd/windows/drawd3d.c | 6 | ||||
-rw-r--r-- | src/osd/windows/drawdd.c | 3 | ||||
-rw-r--r-- | src/osd/windows/drawgdi.c | 3 | ||||
-rw-r--r-- | src/osd/windows/input.c | 15 | ||||
-rw-r--r-- | src/osd/windows/output.c | 4 | ||||
-rw-r--r-- | src/osd/windows/video.c | 5 | ||||
-rw-r--r-- | src/osd/windows/window.c | 3 |
10 files changed, 19 insertions, 27 deletions
diff --git a/src/osd/windows/d3d8intf.c b/src/osd/windows/d3d8intf.c index 779d57230ff..a023f1b5cf6 100644 --- a/src/osd/windows/d3d8intf.c +++ b/src/osd/windows/d3d8intf.c @@ -104,7 +104,7 @@ d3d *drawd3d8_init(void) } // allocate an object to hold our data - d3dptr = (d3d *)malloc_or_die(sizeof(*d3dptr)); + d3dptr = alloc_or_die(d3d); d3dptr->version = 8; d3dptr->d3dobj = d3d8; d3dptr->dllhandle = dllhandle; diff --git a/src/osd/windows/d3d9intf.c b/src/osd/windows/d3d9intf.c index 251201487c8..0d9f0e335c8 100644 --- a/src/osd/windows/d3d9intf.c +++ b/src/osd/windows/d3d9intf.c @@ -102,7 +102,7 @@ d3d *drawd3d9_init(void) } // allocate an object to hold our data - d3dptr = (d3d *)malloc_or_die(sizeof(*d3dptr)); + d3dptr = alloc_or_die(d3d); d3dptr->version = 9; d3dptr->d3dobj = d3d9; d3dptr->dllhandle = dllhandle; diff --git a/src/osd/windows/debugwin.c b/src/osd/windows/debugwin.c index 78e3c794ec0..d4cfc7d7faf 100644 --- a/src/osd/windows/debugwin.c +++ b/src/osd/windows/debugwin.c @@ -503,8 +503,7 @@ static debugwin_info *debugwin_window_create(running_machine *machine, LPCSTR ti RECT work_bounds; // allocate memory - info = (debugwin_info *)malloc_or_die(sizeof(*info)); - memset(info, 0, sizeof(*info)); + info = alloc_clear_or_die(debugwin_info); // create the window info->handler = handler; diff --git a/src/osd/windows/drawd3d.c b/src/osd/windows/drawd3d.c index 570822ef5bd..fa72df8d2e2 100644 --- a/src/osd/windows/drawd3d.c +++ b/src/osd/windows/drawd3d.c @@ -500,8 +500,7 @@ static int drawd3d_window_init(win_window_info *window) d3d_info *d3d; // allocate memory for our structures - d3d = (d3d_info *)malloc_or_die(sizeof(*d3d)); - memset(d3d, 0, sizeof(*d3d)); + d3d = alloc_clear_or_die(d3d_info); window->drawdata = d3d; // experimental: load a PNG to use for vector rendering; it is treated @@ -1658,8 +1657,7 @@ static texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsour HRESULT result; // allocate a new texture - texture = (texture_info *)malloc_or_die(sizeof(*texture)); - memset(texture, 0, sizeof(*texture)); + texture = alloc_clear_or_die(texture_info); // fill in the core data texture->hash = texture_compute_hash(texsource, flags); diff --git a/src/osd/windows/drawdd.c b/src/osd/windows/drawdd.c index bff50c0a2af..c8fb908264d 100644 --- a/src/osd/windows/drawdd.c +++ b/src/osd/windows/drawdd.c @@ -249,8 +249,7 @@ static int drawdd_window_init(win_window_info *window) dd_info *dd; // allocate memory for our structures - dd = (dd_info *)malloc_or_die(sizeof(*dd)); - memset(dd, 0, sizeof(*dd)); + dd = alloc_clear_or_die(dd_info); window->drawdata = dd; // configure the adapter for the mode we want diff --git a/src/osd/windows/drawgdi.c b/src/osd/windows/drawgdi.c index 2c3cbb238b0..63e9fdefc23 100644 --- a/src/osd/windows/drawgdi.c +++ b/src/osd/windows/drawgdi.c @@ -89,8 +89,7 @@ static int drawgdi_window_init(win_window_info *window) int i; // allocate memory for our structures - gdi = (gdi_info *)malloc_or_die(sizeof(*gdi)); - memset(gdi, 0, sizeof(*gdi)); + gdi = alloc_clear_or_die(gdi_info); window->drawdata = gdi; // fill in the bitmap info header diff --git a/src/osd/windows/input.c b/src/osd/windows/input.c index 72651deb517..a105e2dd35e 100644 --- a/src/osd/windows/input.c +++ b/src/osd/windows/input.c @@ -794,8 +794,7 @@ static device_info *generic_device_alloc(running_machine *machine, device_info * device_info *devinfo; // allocate memory for the device object - devinfo = (device_info *)malloc_or_die(sizeof(*devinfo)); - memset(devinfo, 0, sizeof(*devinfo)); + devinfo = alloc_clear_or_die(device_info); devinfo->head = devlist_head_ptr; devinfo->machine = machine; @@ -1267,7 +1266,7 @@ static const char *dinput_device_item_name(device_info *devinfo, int offset, con return utf8_from_tstring(namestring); // otherwise, allocate space to add the suffix - combined = (TCHAR *)malloc_or_die(sizeof(TCHAR) * (_tcslen(namestring) + 1 + _tcslen(suffix) + 1)); + combined = alloc_array_or_die(TCHAR, _tcslen(namestring) + 1 + _tcslen(suffix) + 1); _tcscpy(combined, namestring); _tcscat(combined, TEXT(" ")); _tcscat(combined, suffix); @@ -1652,7 +1651,7 @@ static void rawinput_init(running_machine *machine) goto error; if (device_count == 0) goto error; - devlist = (RAWINPUTDEVICELIST *)malloc_or_die(device_count * sizeof(*devlist)); + devlist = alloc_array_or_die(RAWINPUTDEVICELIST, device_count); if ((*get_rawinput_device_list)(devlist, &device_count, sizeof(*devlist)) == -1) goto error; @@ -1732,7 +1731,7 @@ static device_info *rawinput_device_create(running_machine *machine, device_info // determine the length of the device name, allocate it, and fetch it if ((*get_rawinput_device_info)(device->hDevice, RIDI_DEVICENAME, NULL, &name_length) != 0) goto error; - tname = (TCHAR *)malloc_or_die(name_length * sizeof(*tname)); + tname = alloc_array_or_die(TCHAR, name_length); if ((*get_rawinput_device_info)(device->hDevice, RIDI_DEVICENAME, tname, &name_length) == -1) goto error; @@ -1796,7 +1795,7 @@ static TCHAR *rawinput_device_improve_name(TCHAR *name) return name; // allocate a temporary string and concatenate the base path plus the name - regpath = (TCHAR *)malloc_or_die(sizeof(*regpath) * (_tcslen(basepath) + 1 + _tcslen(name))); + regpath = alloc_array_or_die(TCHAR, _tcslen(basepath) + 1 + _tcslen(name)); _tcscpy(regpath, basepath); chdst = regpath + _tcslen(regpath); @@ -1908,7 +1907,7 @@ convert: chsrc++; else chsrc = regstring; - name = (TCHAR *)malloc_or_die(sizeof(*name) * (_tcslen(chsrc) + 1)); + name = alloc_array_or_die(TCHAR, _tcslen(chsrc) + 1); _tcscpy(name, chsrc); exit: @@ -2129,7 +2128,7 @@ static TCHAR *reg_query_string(HKEY key, const TCHAR *path) return NULL; // allocate a buffer - buffer = (TCHAR *)malloc_or_die(datalen + sizeof(*buffer)); + buffer = alloc_array_or_die(TCHAR, datalen + sizeof(*buffer)); buffer[datalen / sizeof(*buffer)] = 0; // now get the actual data diff --git a/src/osd/windows/output.c b/src/osd/windows/output.c index bdb821a4f3a..74169c242b2 100644 --- a/src/osd/windows/output.c +++ b/src/osd/windows/output.c @@ -228,7 +228,7 @@ static LRESULT register_client(HWND hwnd, LPARAM id) } // add us to the end - *client = (registered_client *)malloc_or_die(sizeof(**client)); + *client = alloc_or_die(registered_client); (*client)->next = NULL; (*client)->id = id; (*client)->hwnd = hwnd; @@ -287,7 +287,7 @@ static LRESULT send_id_string(running_machine *machine, HWND hwnd, LPARAM id) // allocate memory for the message datalen = sizeof(*temp) + strlen(name); - temp = (copydata_id_string *)malloc_or_die(datalen); + temp = (copydata_id_string *)alloc_array_or_die(UINT8, datalen); temp->id = id; strcpy(temp->string, name); diff --git a/src/osd/windows/video.c b/src/osd/windows/video.c index 49fe4475268..bf3fc6d90c2 100644 --- a/src/osd/windows/video.c +++ b/src/osd/windows/video.c @@ -255,8 +255,7 @@ static BOOL CALLBACK monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect, assert(result); // allocate a new monitor info - monitor = (win_monitor_info *)malloc_or_die(sizeof(*monitor)); - memset(monitor, 0, sizeof(*monitor)); + monitor = alloc_clear_or_die(win_monitor_info); // copy in the data monitor->handle = handle; @@ -439,7 +438,7 @@ static void extract_video_config(running_machine *machine) static void load_effect_overlay(running_machine *machine, const char *filename) { const device_config *screen; - char *tempstr = (char *)malloc_or_die(strlen(filename) + 5); + char *tempstr = alloc_array_or_die(char, strlen(filename) + 5); char *dest; // append a .PNG extension diff --git a/src/osd/windows/window.c b/src/osd/windows/window.c index d93b34c4bd2..fd93dc9d549 100644 --- a/src/osd/windows/window.c +++ b/src/osd/windows/window.c @@ -582,8 +582,7 @@ void winwindow_video_window_create(running_machine *machine, int index, win_moni assert(GetCurrentThreadId() == main_threadid); // allocate a new window object - window = (win_window_info *)malloc_or_die(sizeof(*window)); - memset(window, 0, sizeof(*window)); + window = alloc_clear_or_die(win_window_info); window->maxwidth = config->width; window->maxheight = config->height; window->refresh = config->refresh; |