From ea815cc32ca4a9795cde31721489887d1714fd99 Mon Sep 17 00:00:00 2001 From: Thomas Nilefalk Date: Sat, 30 Nov 2024 11:59:51 +0100 Subject: [PATCH] [memory] Remove oclxAlloc/Free since they are just malloc/free --- src/completion.c | 2 +- src/cxref.c | 17 ++++++++--------- src/editor.c | 4 ++-- src/memory.c | 14 ++------------ src/memory.h | 5 ----- src/memory_tests.c | 2 ++ src/menu.c | 12 ++++-------- src/misc.c | 4 ++-- src/reference.c | 4 ++-- 9 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/completion.c b/src/completion.c index f7a9d3e8..d5f3c3e4 100644 --- a/src/completion.c +++ b/src/completion.c @@ -12,7 +12,7 @@ #include "symbol.h" -// Will create olcxAlloc():ed copies of name and fullName so caller don't have to +// Will create malloc():ed copies of name and fullName so caller don't have to protected Completion *newCompletion(char *name, char *fullName, int lineCount, Visibility visibility, Type csymType, struct reference ref, struct referenceItem sym) { diff --git a/src/cxref.c b/src/cxref.c index d61d25f4..1d1697d3 100644 --- a/src/cxref.c +++ b/src/cxref.c @@ -43,12 +43,12 @@ static void renameCollationSymbols(SymbolsMenu *menu) { char *newName; int len = strlen(m->references.linkName); assert(len>=2); - newName = olcxAlloc(len-1); + newName = malloc(len-1); int len1 = cs-m->references.linkName; strncpy(newName, m->references.linkName, len1); strcpy(newName+len1, cs+2); log_debug("renaming %s to %s", m->references.linkName, newName); - olcxFree(m->references.linkName, len+1); + free(m->references.linkName); m->references.linkName = newName; } } @@ -375,7 +375,7 @@ static void deleteOlcxRefs(OlcxReferences **refsP, OlcxReferencesStack *stack) { stack->root = refs->previous; } *refsP = refs->previous; - olcxFree(refs, sizeof(OlcxReferences)); + free(refs); } @@ -409,7 +409,7 @@ static void freePoppedBrowserStackItems(OlcxReferencesStack *stack) { static OlcxReferences *pushEmptyReference(OlcxReferencesStack *stack) { OlcxReferences *res; - res = olcxAlloc(sizeof(OlcxReferences)); + res = malloc(sizeof(OlcxReferences)); *res = (OlcxReferences){.references = NULL, .actual = NULL, .command = options.serverOperation, @@ -432,7 +432,7 @@ void pushEmptySession(OlcxReferencesStack *stack) { static Reference *olcxCopyReference(Reference *reference) { Reference *r; - r = olcxAlloc(sizeof(Reference)); + r = malloc(sizeof(Reference)); *r = *reference; r->next = NULL; return r; @@ -1583,11 +1583,10 @@ int getFileNumberFromName(char *name) { } } -static Reference *olcxCreateFileShiftedRefListForCheck(Reference *rr) { +static Reference *olcxCreateFileShiftedRefListForCheck(Reference *reference) { Reference *res, **resa; int ofn, nfn, fmline, lmline; - //&fprintf(dumpOut,"!shifting enter\n"); if (options.checkFileMovedFrom==NULL) return NULL; if (options.checkFileMovedTo==NULL) return NULL; //&fprintf(dumpOut,"!shifting %s --> %s\n", options.checkFileMovedFrom, options.checkFileMovedTo); @@ -1599,8 +1598,8 @@ static Reference *olcxCreateFileShiftedRefListForCheck(Reference *rr) { fmline = options.checkFirstMovedLine; lmline = options.checkFirstMovedLine + options.checkLinesMoved; res = NULL; resa = &res; - for (Reference *r=rr; r!=NULL; r=r->next) { - Reference *tt = olcxAlloc(sizeof(Reference)); + for (Reference *r=reference; r!=NULL; r=r->next) { + Reference *tt = malloc(sizeof(Reference)); *tt = *r; if (tt->position.file==ofn && tt->position.line>=fmline && tt->position.lineposition.file = nfn; diff --git a/src/editor.c b/src/editor.c index 7053a14c..dc5fc6b6 100644 --- a/src/editor.c +++ b/src/editor.c @@ -916,7 +916,7 @@ Reference *convertEditorMarkersToReferences(EditorMarkerList **editorMarkerListP line = 1; col = 0; for (; textposition = makePosition(buf->fileNumber, line, col); fillReference(r, markers->usage, r->position, reference); reference = r; @@ -931,7 +931,7 @@ Reference *convertEditorMarkersToReferences(EditorMarkerList **editorMarkerListP } } while (markers!=NULL && markers->marker->buffer==buf) { - Reference *r = olcxAlloc(sizeof(Reference)); + Reference *r = malloc(sizeof(Reference)); r->position = makePosition(buf->fileNumber, line, 0); fillReference(r, markers->usage, r->position, reference); reference = r; diff --git a/src/memory.c b/src/memory.c index f2758f74..a037c07a 100644 --- a/src/memory.c +++ b/src/memory.c @@ -149,23 +149,13 @@ bool isFreedCxMemory(void *pointer) { return dm_isFreedPointer(cxMemory, pointer); } -/* OLCX */ -void *olcxAlloc(size_t size) { - return malloc(size); -} - - -void olcxFree(void *pointer, size_t size) { - free(pointer); -} - /* EDITOR */ void *editorAlloc(size_t size) { - return olcxAlloc(size); + return malloc(size); } void editorFree(void *pointer, size_t size) { - olcxFree(pointer, size); + free(pointer); } static bool isInMemory(Memory2 *memory, void *pointer) { diff --git a/src/memory.h b/src/memory.h index 9d7d59d7..909f0d51 100644 --- a/src/memory.h +++ b/src/memory.h @@ -86,11 +86,6 @@ extern void cxFreeUntil(void *until); extern bool isFreedCxMemory(void *pointer); -/* on-line dialogs allocation */ -extern void *olcxAlloc(size_t size); -extern void olcxFree(void *pointer, size_t size); - - /* editor allocations, for now, store it in olcxmemory */ extern void *editorAlloc(size_t size); extern void editorFree(void *pointer, size_t size); diff --git a/src/memory_tests.c b/src/memory_tests.c index 8fb237f7..fe206337 100644 --- a/src/memory_tests.c +++ b/src/memory_tests.c @@ -10,6 +10,7 @@ #include "cxref.mock" /* For freeOldestOlcx() */ #include "globals.mock" + static bool fatalErrorAllowed = false; static bool fatalErrorCalled = false; static void myFatalError(int errCode, char *mess, int exitStatus, char *file, int line) { @@ -26,6 +27,7 @@ static void myInternalCheckFailed(char *expr, char *file, int line) { internalCheckFailCalled = true; } + Describe(Memory); BeforeEach(Memory) { log_set_level(LOG_ERROR); diff --git a/src/menu.c b/src/menu.c index cdfb9209..684b7523 100644 --- a/src/menu.c +++ b/src/menu.c @@ -29,10 +29,10 @@ void fillSymbolsMenu(SymbolsMenu *menu, ReferenceItem references, bool selected, } SymbolsMenu *freeSymbolsMenu(SymbolsMenu *menu) { - olcxFree(menu->references.linkName, strlen(menu->references.linkName)+1); + free(menu->references.linkName); freeReferences(menu->references.references); SymbolsMenu *next = menu->next; - olcxFree(menu, sizeof(*menu)); + free(menu); return next; } @@ -77,11 +77,7 @@ void olcxPrintSelectionMenu(SymbolsMenu *menu) { } static char *olcxStringCopy(char *string) { - int length; - char *copy; - length = strlen(string); - copy = olcxAlloc(length+1); - strcpy(copy, string); + char *copy = strdup(string); return copy; } @@ -98,7 +94,7 @@ SymbolsMenu *olCreateNewMenuItem(ReferenceItem *symbol, int vApplClass, int vFun symbol->type, symbol->storage, symbol->scope, symbol->visibility); - symbolsMenu = olcxAlloc(sizeof(SymbolsMenu)); + symbolsMenu = malloc(sizeof(SymbolsMenu)); fillSymbolsMenu(symbolsMenu, refItem, selected, visible, ooBits, olusage, vlevel, defusage, *defpos); return symbolsMenu; } diff --git a/src/misc.c b/src/misc.c index 8636ddbb..4fe1870a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -470,7 +470,7 @@ int compareFileNames(char *name1, char *name2) { // ------------------------------------------- SHELL (SUB)EXPRESSIONS --- static IntegerList *shellMatchNewState(int s, IntegerList *next) { - IntegerList *res = olcxAlloc(sizeof(IntegerList)); + IntegerList *res = malloc(sizeof(IntegerList)); res->integer = s; res->next = next; return res; @@ -480,7 +480,7 @@ static void shellMatchDeleteState(IntegerList **s) { IntegerList *p; p = *s; *s = (*s)->next; - olcxFree(p, sizeof(IntegerList)); + free(p); } static int shellMatchParseBracketPattern(char *pattern, int pi, bool caseSensitive, char *asciiMap) { diff --git a/src/reference.c b/src/reference.c index 9a8da626..cd5c18a9 100644 --- a/src/reference.c +++ b/src/reference.c @@ -43,7 +43,7 @@ void fillReferenceItem(ReferenceItem *referencesItem, char *name, int vApplClass void freeReferences(Reference *references) { while (references != NULL) { Reference *next = references->next; - olcxFree(references, sizeof(Reference)); + free(references); references = next; } } @@ -87,7 +87,7 @@ Reference *olcxAddReferenceNoUsageCheck(Reference **rlist, Reference *ref) { rr = NULL; SORTED_LIST_PLACE2(place, *ref, rlist); if (*place==NULL || SORTED_LIST_NEQ(*place,*ref)) { - rr = olcxAlloc(sizeof(Reference)); + rr = malloc(sizeof(Reference)); *rr = *ref; LIST_CONS(rr,(*place)); log_trace("olcx adding %s %s:%d:%d", usageKindEnumName[ref->usage.kind],