Skip to content

Commit

Permalink
[memory] Remove oclxAlloc/Free since they are just malloc/free
Browse files Browse the repository at this point in the history
  • Loading branch information
thoni56 committed Nov 30, 2024
1 parent b5fcfc4 commit ea815cc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 8 additions & 9 deletions src/cxref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -375,7 +375,7 @@ static void deleteOlcxRefs(OlcxReferences **refsP, OlcxReferencesStack *stack) {
stack->root = refs->previous;
}
*refsP = refs->previous;
olcxFree(refs, sizeof(OlcxReferences));
free(refs);
}


Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.line<lmline) {
tt->position.file = nfn;
Expand Down
4 changes: 2 additions & 2 deletions src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ Reference *convertEditorMarkersToReferences(EditorMarkerList **editorMarkerListP
line = 1; col = 0;
for (; text<textMax; text++, col++) {
if (text == offset) {
Reference *r = olcxAlloc(sizeof(Reference));
Reference *r = malloc(sizeof(Reference));
r->position = makePosition(buf->fileNumber, line, col);
fillReference(r, markers->usage, r->position, reference);
reference = r;
Expand All @@ -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;
Expand Down
14 changes: 2 additions & 12 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions src/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/memory_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -26,6 +27,7 @@ static void myInternalCheckFailed(char *expr, char *file, int line) {
internalCheckFailCalled = true;
}


Describe(Memory);
BeforeEach(Memory) {
log_set_level(LOG_ERROR);
Expand Down
12 changes: 4 additions & 8 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit ea815cc

Please sign in to comment.