Skip to content

Commit

Permalink
Merge branch 'destructors-fix' of https://github.com/YashasSamaga/pawn
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeex committed Apr 24, 2018
2 parents a840b4a + 0ecffcb commit fd31205
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3815,7 +3815,8 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc
modstk((int)declared*sizeof(cell)); /* remove all local variables */
declared=0;
} /* if */
if ((lastst!=tRETURN) && (lastst!=tGOTO) && (sym->flags & flagNAKED)==0){
if ((lastst!=tRETURN) && (lastst!=tGOTO) && (sym->flags & flagNAKED)==0) {
destructsymbols(&loctab,0);
ldconst(0,sPRI);
ffret(strcmp(sym->name,uENTRYFUNC)!=0);
if ((sym->usage & uRETVALUE)!=0) {
Expand Down Expand Up @@ -4909,7 +4910,7 @@ static cell calc_array_datasize(symbol *sym, cell *offset)
if (offset!=NULL)
*offset=length*(*offset+sizeof(cell));
if (sublength>0)
length*=length*sublength;
length*=sublength;
else
length=0;
} else {
Expand All @@ -4925,7 +4926,7 @@ static void destructsymbols(symbol *root,int level)
int savepri=FALSE;
symbol *sym=root->next;
while (sym!=NULL && sym->compound>=level) {
if (sym->ident==iVARIABLE || sym->ident==iARRAY) {
if ((sym->ident==iVARIABLE || sym->ident==iARRAY) && !(sym->vclass==sSTATIC && sym->fnumber==-1)) {
char symbolname[16];
symbol *opsym;
cell elements;
Expand All @@ -4939,6 +4940,15 @@ static void destructsymbols(symbol *root,int level)
} /* if */
/* if the variable is an array, get the number of elements */
if (sym->ident==iARRAY) {
/* according to the PAWN Implementer Guide, the destructor
* should be triggered for the data of the array only; hence
* if the array is a part of a larger array, it must be ignored
* as it's parent would(or has already) trigger(ed) the destructor
*/
if (sym->parent!=NULL) {
sym=sym->next;
continue;
} /* if */
elements=calc_array_datasize(sym,&offset);
/* "elements" can be zero when the variable is declared like
* new mytag: myvar[2][] = { {1, 2}, {3, 4} }
Expand Down

0 comments on commit fd31205

Please sign in to comment.