Skip to content

Commit c2e05c3

Browse files
committed
Don't change AKGST during call (but restore it); linenoise arg order
1 parent 99b2862 commit c2e05c3

File tree

7 files changed

+27
-18
lines changed

7 files changed

+27
-18
lines changed

jsrc/af.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static A jtfixa(J jt,A a,A w){A f,g,h,wf,x,y,z=w;V*v;fauxblock(fauxself); A aa;
135135
if(unlikely(AFLAG(x)&AFRO))R w; // If name has readonly value (like cocurrent), leave it as a reference
136136
// if this is an implicit locative, we have to switch the environment before we recur on the name for subsequent lookups
137137
// The value we get from the lookup must be interpreted in the environment of the higher level
138-
A savloc=jt->locsyms; // initial locales
138+
A savloc=jt->locsyms, savglob=jt->global; // initial locales
139139
A thisname=v->fgh[0];// the A block for the name of the function (holding an NM) - unless it's a pseudo-name
140140
if(thisname){ // name given
141141
NM* thisnameinfo=NAV(thisname); // the NM block for the current name
@@ -145,7 +145,7 @@ static A jtfixa(J jt,A a,A w){A f,g,h,wf,x,y,z=w;V*v;fauxblock(fauxself); A aa;
145145
// (1) we want to replace only first-level locatives; (2) there are no more locatives in this branch after the replacement
146146
if(aif&FIXALOCSONLYLOWEST)R x; // return looked-up value once we hit one
147147
// If we have to continue after the replacement, we must do so in the environment of the implicit locative.
148-
SYMRESTOREFROMLOCAL((A)AM(jt->locsyms));
148+
SYMSWITCHTOLOCAL((A)AM(jt->locsyms));
149149
// NO FAILURES ALLOWED FROM HERE TO RESTORE
150150
}
151151
}
@@ -160,7 +160,7 @@ static A jtfixa(J jt,A a,A w){A f,g,h,wf,x,y,z=w;V*v;fauxblock(fauxself); A aa;
160160
if(z=REFIXA(na,x)){
161161
if(ai!=0&&selfq(x))z=fixrecursive(sc(ai),z); // if a lower name contains $:, replace it with explicit equivalent
162162
}
163-
SYMRESTOREFROMLOCAL(savloc); // make sure we restore current symbols
163+
SYMRESTORELOCALGLOBAL(savloc,savglob); // make sure we restore current symbols
164164
AN((A)IAV0(aa)[1])=AS((A)IAV0(aa)[1])[0]=initn; // restore name count
165165
RZ(z);
166166
}

jsrc/ct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ nexttasklocked: ; // come here if already holding the lock, and job is set
472472
memcpy(jt,job->user.inherited,sizeof(job->user.inherited)); // copy inherited state; a little overcopy OK, cleared next
473473
memset(&jt->uflags.init0area,0,offsetof(JTT,initnon0area)-offsetof(JTT,uflags.init0area)); // clear what should be cleared - up to locsyms
474474
A startloc=(UNvoidAV1(job))->kchain.global; // extract the globals pointer from the job
475-
jt->locsyms=(A)(*JT(jt,emptylocale))[THREADID(jt)]; SYMSETGLOBAL(jt->locsyms,startloc); RESETRANK; jt->currslistx=-1; jt->recurstate=RECSTATERUNNING; // init what needs initing. Notably clear the local symbols
475+
jt->locsyms=(A)(*JT(jt,emptylocale))[THREADID(jt)]; SYMSETGLOBALS(jt->locsyms,startloc); RESETRANK; jt->currslistx=-1; jt->recurstate=RECSTATERUNNING; // init what needs initing. Notably clear the local symbols
476476
jtsettaskrunning(jt); // go to RUNNING state, perhaps after waiting for system lock to finish
477477
// run the task, raising & lowering the locale execct. Bivalent
478478
// obsolete if(likely(startloc!=0)){INCREXECCTIF(startloc); fa(startloc);} // raise execcount of current locale to protect it while running; remove the protection installed in taskrun()

jsrc/j.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,8 +2102,10 @@ if(likely(type _i<3)){z=(type _i<1)?1:(type _i==1)?_zzt[0]:_zzt[0]*_zzt[1];}else
21022102
// At all times we keep the k field of locsyms as a copy of jt->global so that if we need it for u./v. we know what the symbol tables were. We could remove jt->global but that would cost
21032103
// some load instructions sometimes. AM(local table) points to the previous local table in the stack, looping to self at end
21042104
#define SYMSETGLOBALINLOCAL(l,g) (AKGST(l)=(g)) // l is jt->locsyms, g is new global value
2105-
#define SYMSETGLOBAL(l,g) (jt->global=(g), SYMSETGLOBALINLOCAL(l,jt->global)) // l is jt->locsyms, g is new global value
2106-
#define SYMRESTOREFROMLOCAL(l) (jt->locsyms=(l), jt->global=AKGST(jt->locsyms)) // go to stacked local l
2105+
#define SYMSETGLOBAL(g) (jt->global=(g)) // g is new global value. Do not disturb AKGST
2106+
#define SYMSETGLOBALS(l,g) (jt->global=(g), SYMSETGLOBALINLOCAL(l,jt->global)) // l is jt->locsyms, g is new global value
2107+
#define SYMSWITCHTOLOCAL(l) (jt->locsyms=(l), jt->global=AKGST(jt->locsyms)) // go to stacked local l
2108+
#define SYMRESTORELOCALGLOBAL(l,g) (jt->locsyms=(l), jt->global=(g)) // set locsyms/global but leave AKGST unchanged
21072109
// unused#define SYMSWAPTOLOCAL(l,lsave) (lsave=jt->locsyms, SYMRESTOREFROMLOCAL(l)) // go to stacked local l, save current in lsave
21082110
#define SYMSETLOCAL(l) (jt->locsyms=(l), AKGST(jt->locsyms)=jt->global) // change the locals to l
21092111
#define SYMPUSHLOCAL(l) (AM(l)=(I)jt->locsyms, SYMSETLOCAL(l)) // push l onto locals stack

jsrc/linenoise.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,7 +2955,7 @@ int linenoiseHistoryAddAllocated(char *line) {
29552955
return 0;
29562956
}
29572957
if (history == NULL) {
2958-
history = (char **)calloc(sizeof(char*), history_max_len);
2958+
history = (char **)calloc(history_max_len, sizeof(char*));
29592959
}
29602960

29612961
/* do not insert duplicate lines into history */
@@ -2988,7 +2988,7 @@ int linenoiseHistorySetMaxLen(int len) {
29882988
if (history) {
29892989
int tocopy = history_len;
29902990

2991-
newHistory = (char **)calloc(sizeof(char*), len);
2991+
newHistory = (char **)calloc(len, sizeof(char*));
29922992

29932993
/* If we can't copy everything, free the elements we'll not use. */
29942994
if (len < tocopy) {

jsrc/sc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ DF2(jtunquote){A z;
5959
FAV(self)->localuse.lu0.cachedloc=explocale; // save named lookup calc for next time
6060
}
6161
flgd0cpC|=((explocale!=jt->global)&~(LXAV0(explocale)[SYMLEXECCT]>>EXECCTPERMX))<<FLGLOCINCRDECRX; // remember that there is a change of locale
62-
SYMSETGLOBAL(jt->locsyms,explocale); // set where we're going
62+
SYMSETGLOBAL(explocale); // switch to the (possibly new) locale.
6363
}
6464
flgd0cpC|=FLGCACHED; // indicate cached lookup, which also tells us that we have not ra()d the name
6565
}else{
@@ -90,7 +90,9 @@ DF2(jtunquote){A z;
9090
}
9191
}
9292
flgd0cpC|=((explocale!=jt->global)&~(LXAV0(explocale)[SYMLEXECCT]>>EXECCTPERMX))<<FLGLOCINCRDECRX; // remember that there is a change of locale to non-PERMANENT
93-
SYMSETGLOBAL(jt->locsyms,explocale); // set where we're going
93+
SYMSETGLOBAL(explocale); // switch to the (possibly new) locale. We DO NOT change AKGST because if we are calling a non-operator modifier we need the old locale if the modifier calls u./v. .
94+
// AKGST changes only from cocurrent. This leads to a divergence between jt->global and AKGST if a non-operator modifier calls an anonymous explicit that issues cocurrent. BFD. The divergence
95+
// is removed by the next named call
9496
}
9597
// Common path for named functions after lookup is finished. fs has QCNAMED semantics
9698
// explocale is the locale we are calling into

jsrc/sl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,6 @@ B jtlocdestroy(J jt,A g){
714714
// The current implied locale can be deleted only after it leaves execution, i. e. after it returns to immex in all threads where it is current.
715715
// We are allowed to change it then because it is not stacked anywhere. We change to z so that (1) we can be assured jt->global is always valid;
716716
// (2) the user doesn't have the disorienting experience of no locale and no path.
717-
if(unlikely(g==jt->global))SYMSETGLOBAL(jt->locsyms,*JT(jt,zpath)); // if we deleted the global locale, throw us into z locale (which is permanent)
717+
if(unlikely(g==jt->global))SYMSETGLOBALS(jt->locsyms,*JT(jt,zpath)); // if we deleted the global locale, throw us into z locale (which is permanent)
718718
R 1;
719719
} /* destroy locale jt->callg[i] (marked earlier by 18!:55) */

test/g310r.ijs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ NB. Going through locatives leaves global path unchanged
9494
a_z_ =: a =: 1 : 0
9595
try.
9696
xxx =. u. f.
97-
1
98-
catch. 0
97+
r =. 1
98+
catch. r =.0
99+
end.
100+
try.
101+
xxx =. u f.
102+
r , 1
103+
catch. r , 0
99104
end.
100105
)
101106
+ a
@@ -107,15 +112,15 @@ g_z_ =: a
107112
f g NB. a runs in base
108113
g =: a_z_
109114
+ g
110-
0 = f g NB. now a runs in z and doesn't find f
115+
1 0 -: f g NB. now a runs in z and doesn't find f through u, but does through u.
111116
3 : 0 ''
112117
assert. + a
113118
ff =. ((coname '') -: coname)
114119
assert. f a
115-
assert. ff a
120+
assert. 1 0 -: ff a
116121
assert. ((coname '') -: coname) g
117-
assert. 0 = f g NB. f not defined in z
118-
assert. ff g
122+
assert. 1 0 -: f g NB. f not defined in z
123+
assert. 1 0 -: ff g
119124
1
120125
)
121126
4!:55 ;:'a a_z_' NB. names used below
@@ -287,7 +292,7 @@ _3 -:+ {{ 0 + v. }} - ]3
287292
NB. call to modifier through locative keeps u./v. info
288293
f_a_ =: {{ u. 5 }}
289294
f =: *:
290-
NB. new 25 = f f_a_
295+
25 = f f_a_
291296

292297

293298
4!:55 ;:'a aa q a_z_ c_z_ d_yyy_ d_xxx_ g_z_ j j_xxx_ dou F f f_a_ F1 f1 F2 f2 G g G1 g1 G2 g2 nameinxxx_xxx_ nln nm nn sum v'

0 commit comments

Comments
 (0)