More allocvec/malloc replacements

This commit is contained in:
Chris Young 2016-11-19 20:44:17 +00:00
parent 81a7e0cbe9
commit a8bd2af710
8 changed files with 24 additions and 22 deletions

View File

@ -127,10 +127,10 @@ static char *ami_clipboard_cat_collection(struct CollectionItem *ci, LONG codese
default:
if(ci_new) {
ci_next->ci_Next = calloc(1, sizeof(struct CollectionItem), 0);
ci_next->ci_Next = calloc(1, sizeof(struct CollectionItem));
ci_next = ci_next->ci_Next;
} else {
ci_new = calloc(1, sizeof(struct CollectionItem), 0);
ci_new = calloc(1, sizeof(struct CollectionItem));
ci_next = ci_new;
}

View File

@ -100,7 +100,7 @@ static struct gui_download_window *gui_download_window_create(download_context *
char *dl_filename = ami_utf8_easy(download_context_get_filename(ctx));
APTR va[3];
dw = calloc(1, sizeof(struct gui_download_window), 0);
dw = calloc(1, sizeof(struct gui_download_window));
if(gui && (!IsListEmpty(&gui->dllist)) && (dw->dln = (struct dlnode *)FindName(&gui->dllist,url)))
{

View File

@ -40,7 +40,6 @@
#include "amiga/filetype.h"
#include "amiga/icon.h"
#include "amiga/iff_dr2d.h"
#include "amiga/memory.h"
#include "amiga/misc.h"
#include "amiga/save_pdf.h"
#include "amiga/theme.h"
@ -90,7 +89,7 @@ void ami_file_open(struct gui_window_2 *gwin)
ASLFR_FilterFunc, &aslhookfunc,
TAG_DONE))
{
if((temp = AllocVecTagList(1024, NULL)))
if((temp = malloc(1024)))
{
strlcpy(temp, filereq->fr_Drawer, 1024);
AddPart(temp, filereq->fr_File, 1024);
@ -108,7 +107,7 @@ void ami_file_open(struct gui_window_2 *gwin)
nsurl_unref(url);
}
FreeVec(temp);
free(temp);
}
}
}
@ -213,7 +212,7 @@ void ami_file_save(int type, char *fname, struct Window *win,
void ami_file_save_req(int type, struct gui_window_2 *gwin,
struct hlcache_handle *object)
{
char *fname = AllocVecTagList(1024, NULL);
char *fname = malloc(1024);
char *initial_fname = NULL;
char *fname_with_ext = NULL;
bool strip_ext = true;
@ -224,7 +223,7 @@ void ami_file_save_req(int type, struct gui_window_2 *gwin,
}
if(initial_fname != NULL) {
fname_with_ext = AllocVecTagList(strlen(initial_fname) + 5, NULL); /* 5 = .ext\0 */
fname_with_ext = malloc(strlen(initial_fname) + 5); /* 5 = .ext\0 */
strcpy(fname_with_ext, initial_fname);
@ -261,8 +260,8 @@ void ami_file_save_req(int type, struct gui_window_2 *gwin,
ami_file_save(type, fname, gwin->win, object, gwin->gw->favicon, gwin->gw->bw);
}
if(fname) FreeVec(fname);
if(fname_with_ext) FreeVec(fname_with_ext);
if(fname) free(fname);
if(fname_with_ext) free(fname_with_ext);
}
void ami_file_req_init(void)

View File

@ -31,7 +31,6 @@
#include "utils/utils.h"
#include "amiga/filetype.h"
#include "amiga/memory.h"
#include "amiga/object.h"
/**
@ -217,7 +216,7 @@ nserror ami_mime_init(const char *mimefile)
{
if ((node = AddObject(ami_mime_list, AMINS_MIME))) {
ObjectCallback(node, ami_mime_entry_free);
mimeentry = ami_misc_allocvec_clear(sizeof(struct ami_mime_entry), 0);
mimeentry = calloc(1, sizeof(struct ami_mime_entry));
node->objstruct = mimeentry;
if(rarray[AMI_MIME_MIMETYPE])
@ -361,7 +360,7 @@ static APTR ami_mime_guess_add_datatype(struct DataType *dt, lwc_string **lwc_mi
node = AddObject(ami_mime_list, AMINS_MIME);
if(node == NULL) return NULL;
mimeentry = ami_misc_allocvec_clear(sizeof(struct ami_mime_entry), 0);
mimeentry = calloc(1, sizeof(struct ami_mime_entry));
if(mimeentry == NULL) return NULL;
node->objstruct = mimeentry;

View File

@ -363,7 +363,7 @@ static struct ami_font_cache_node *ami_font_open(const char *font, bool critical
{
LOG("Requested font not found: %s", font);
if(critical == true) amiga_warn_user("CompError", font);
FreeVec(nodedata);
free(nodedata);
return NULL;
}
@ -601,7 +601,7 @@ static inline int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPo
TAG_DONE);
#else
/* On OS3 the glyph needs to be in chip RAM */
void *chip_glyph = AllocVec(glyph->glm_BMModulo * glyph->glm_BMRows, MEMF_CHIP);
void *chip_glyph = ami_memory_chip_alloc(glyph->glm_BMModulo * glyph->glm_BMRows);
if(chip_glyph != NULL) {
CopyMem(glyphbm, chip_glyph, glyph->glm_BMModulo * glyph->glm_BMRows);
@ -612,7 +612,7 @@ static inline int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPo
y - glyph->glm_Y0 + glyph->glm_BlackTop,
glyph->glm_BlackWidth, glyph->glm_BlackHeight);
FreeVec(chip_glyph);
ami_memory_chip_free(chip_glyph);
}
#endif
}

View File

@ -158,7 +158,7 @@ struct ami_font_cache_node *ami_font_cache_alloc_entry(const char *font)
uint32 hash = XXH32(font, strlen(font), 0);
nodedata = (struct ami_font_cache_node *)InsertSkipNode(ami_font_cache_list, (APTR)hash, sizeof(struct ami_font_cache_node));
#else
nodedata = AllocVecTagList(sizeof(struct ami_font_cache_node), NULL);
nodedata = malloc(sizeof(struct ami_font_cache_node));
#endif
GetSysTime(&nodedata->lastused);

View File

@ -99,7 +99,7 @@ const char *ami_font_scan_lookup(const uint16 *code, lwc_string **glypharray)
static struct ami_font_scan_window *ami_font_scan_gui_open(int32 fonts)
{
struct ami_font_scan_window *fsw =
AllocVecTagList(sizeof(struct ami_font_scan_window), NULL);
malloc(sizeof(struct ami_font_scan_window));
if(fsw == NULL) return NULL;
@ -201,7 +201,7 @@ static void ami_font_scan_gui_close(struct ami_font_scan_window *fsw)
if(fsw) {
DisposeObject(fsw->objects[FS_OID_MAIN]);
ami_utf8_free(fsw->title);
FreeVec(fsw);
free(fsw);
}
}
@ -317,10 +317,10 @@ static ULONG ami_font_scan_list(struct MinList *list)
struct nsObject *node;
do {
if((afh = (struct AvailFontsHeader *)AllocVecTagList(afSize, NULL))) {
if((afh = (struct AvailFontsHeader *)malloc(afSize))) {
if(((afShortage = AvailFonts((STRPTR)afh, afSize,
AFF_DISK | AFF_OTAG | AFF_SCALED)))) {
FreeVec(afh);
free(afh);
afSize += afShortage;
}
} else {
@ -350,7 +350,7 @@ static ULONG ami_font_scan_list(struct MinList *list)
}
}
}
FreeVec(afh);
free(afh);
} else {
return 0;
}

View File

@ -21,6 +21,10 @@
#include <exec/types.h>
/* Alloc/free chip memory */
#define ami_memory_chip_alloc(s) AllocVec(s, MEMF_CHIP)
#define ami_memory_chip_free(p) FreeVec(p)
/* Alloc/free a block cleared to non-zero */
void *ami_memory_clear_alloc(size_t size, UBYTE value);
void ami_memory_clear_free(void *p);