Skip to content

Commit

Permalink
[tidy] Refactor CF_ALLOCc(p, ...) into p = cfAlloc(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
thoni56 committed Apr 9, 2024
1 parent 605790e commit 409fd5e
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 312 deletions.
5 changes: 2 additions & 3 deletions src/classcaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void cctAddSimpleValue(CctNode *node, Symbol *symbol, int depthFactor) {
}
int hash = cctTreeHash(symbol, depthFactor);
if (node->subtree == NULL) {
CctNode *n;
CF_ALLOCC(n, CCT_TREE_INDEX, CctNode);
CctNode *n = cfAllocc(CCT_TREE_INDEX, CctNode);
for (int i=0; i<CCT_TREE_INDEX; i++)
fillCctNode(&n[i], NULL, NULL);
n[hash].symbol = symbol;
Expand Down Expand Up @@ -66,7 +65,7 @@ void cctAddCctTree(CctNode *node, CctNode *symbol, int depthFactor) {
if (symbol->subtree == NULL)
return;
if (node->subtree == NULL) {
CF_ALLOCC(node->subtree, CCT_TREE_INDEX, CctNode);
node->subtree = cfAllocc(CCT_TREE_INDEX, CctNode);
for (int i=0; i<CCT_TREE_INDEX; i++)
node->subtree[i] = symbol->subtree[i];
} else {
Expand Down
23 changes: 11 additions & 12 deletions src/classfilereader.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,14 @@ static ConstantPoolUnion *cfReadConstantPool(CharacterBuffer *cb,
}

GetU2(count, cb, exception);
CF_ALLOCC(cp, count, ConstantPoolUnion);
cp = cfAllocc(count, ConstantPoolUnion);
//& memset(cp,0, count*sizeof(ConstantPoolUnion)); // if broken file
for(index=1; index<count; index++) {
GetU1(tag, cb, exception);
switch (tag) {
case CONSTANT_Utf8:
GetU2(length, cb, exception);
CF_ALLOCC(string, length+1, char);
string = cfAllocc(length+1, char);
for(int i=0; i<length; i++)
GetChar(string[i], cb, exception);
string[length]=0;
Expand Down Expand Up @@ -788,7 +788,7 @@ static TypeModifier *cfUnPackResultType(char *sig, char **restype) {
}
assert(*ssig);
for(; *ssig; ssig++) {
CF_ALLOC(tt, TypeModifier);
tt = cfAlloc(TypeModifier);
*ares = tt;
ares = &(tt->next);
switch (*ssig) {
Expand Down Expand Up @@ -869,7 +869,7 @@ static void cfAddRecordToClass(char *name,
linkName = memb->linkName;
} else {
len = strlen(pp);
CF_ALLOCC(linkName, len+1, char);
linkName = cfAllocc(len+1, char);
strcpy(linkName, pp);
}
prof = strchr(linkName,'(');
Expand All @@ -881,8 +881,8 @@ static void cfAddRecordToClass(char *name,
}

log_trace("adding definition of %s == %s", name, linkName);
/* TODO If this was allocated in "normal" memory we could use newSymbol() */
CF_ALLOC(symbol, Symbol);
/* TODO If this was allocated in "normal" memory we could use newSymbol(), why isn't it??!?! */
symbol = cfAlloc(Symbol);
fillSymbolWithTypeModifier(symbol, name, linkName, noPosition, tt);
symbol->access = accessFlags;
symbol->storage = storage;
Expand Down Expand Up @@ -978,7 +978,7 @@ static void cfReadMethodInfos(CharacterBuffer *cb,
if (getFileItem(memb->u.structSpec->classFileNumber)->directEnclosingInstance != NO_FILE_NUMBER) {
// the first argument is direct enclosing instance, remove it
sign2 = skipFirstArgumentInDescriptorString(descriptor);
CF_ALLOCC(descriptor, strlen(sign2)+2, char);
descriptor = cfAllocc(strlen(sign2)+2, char);
descriptor[0] = '('; strcpy(descriptor+1, sign2);
log_trace("nested constructor '%s' '%s'", name, descriptor);
}
Expand All @@ -1001,7 +1001,7 @@ static void cfReadMethodInfos(CharacterBuffer *cb,
log_trace("throws '%s'", exname);
exsname = simpleClassNameFromFQTName(exname);
exc = javaFQTypeSymbolDefinition(exsname, exname);
CF_ALLOC(ee, SymbolList);
ee = cfAlloc(SymbolList);
/* REPLACED: FILL_symbolList(ee, exc, exclist); with compound literal */
*ee = (SymbolList){.element = exc, .next = exclist};
exclist = ee;
Expand Down Expand Up @@ -1081,9 +1081,8 @@ void addSuperClassOrInterface(Symbol *member, Symbol *super, int originFileNumbe
return;
}
cfAddCastsToModule(member, super);
CF_ALLOC(symbolList, SymbolList);

/* TODO: three occurrences of CF_ALLOC(.. SymbolList) warrants 'newSymbolList()'... */
symbolList = cfAlloc(SymbolList);
/* REPLACED: FILL_symbolList(ssl, supp, NULL); with compound literal */
*symbolList = (SymbolList){.element = super, .next = NULL};
LIST_APPEND(SymbolList, member->u.structSpec->super, symbolList);
Expand Down Expand Up @@ -1251,8 +1250,8 @@ void javaReadClassFile(char *className, Symbol *symbol, LoadSuperOrNot loadSuper
if (inum > 0) {
// I think this should be optimized, not all mentioned here
// are my inners classes
//& CF_ALLOCC(symbol->u.structSpec->nestedClasses, MAX_INNER_CLASSES, S_nestedSpec);
CF_ALLOCC(symbol->u.structSpec->nestedClasses, inum, S_nestedSpec);
//& symbol->u.structSpec->nestedClasses = cfAllocc(MAX_INNER_CLASSES, S_nestedSpec);
symbol->u.structSpec->nestedClasses = cfAllocc(inum, S_nestedSpec);
}
for(rinners=0; rinners<inum; rinners++) {
GetU2(innval, cb, exception);
Expand Down
Loading

0 comments on commit 409fd5e

Please sign in to comment.