aliases should be global?

This commit is contained in:
Vítor Santos Costa 2016-03-29 01:56:00 +01:00
parent 1be002558c
commit cda490eda8

View File

@ -213,25 +213,25 @@ ExtendAliasArray(void)
{
CACHE_REGS
AliasDesc new;
UInt new_size = LOCAL_SzOfFileAliases+ALIASES_BLOCK_SIZE;
UInt new_size = GLOBAL_SzOfFileAliases+ALIASES_BLOCK_SIZE;
new = (AliasDesc)Yap_AllocCodeSpace(sizeof(AliasDesc *)*new_size);
memcpy((void *)new, (void *)LOCAL_FileAliases, sizeof(AliasDesc *)*LOCAL_SzOfFileAliases);
Yap_FreeCodeSpace((ADDR) LOCAL_FileAliases);
LOCAL_FileAliases = new;
LOCAL_SzOfFileAliases = new_size;
memcpy((void *)new, (void *)GLOBAL_FileAliases, sizeof(AliasDesc *)*GLOBAL_SzOfFileAliases);
Yap_FreeCodeSpace((ADDR) GLOBAL_FileAliases);
GLOBAL_FileAliases = new;
GLOBAL_SzOfFileAliases = new_size;
}
void
Yap_SetAlias (Atom arg, int sno)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases, aliasp_max = LOCAL_FileAliases+LOCAL_NOfFileAliases;
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
// replace alias
if (aliasp->name == arg) {
Int alno = aliasp-LOCAL_FileAliases;
Int alno = aliasp-GLOBAL_FileAliases;
aliasp->alias_stream = sno;
if (!(GLOBAL_Stream[sno].status &
(Null_Stream_f|InMemory_Stream_f|Socket_Stream_f))) {
@ -258,9 +258,9 @@ Yap_SetAlias (Atom arg, int sno)
}
// set new alias
/* we have not found an alias, create one */
if (aliasp == LOCAL_FileAliases+ LOCAL_SzOfFileAliases)
if (aliasp == GLOBAL_FileAliases+ GLOBAL_SzOfFileAliases)
ExtendAliasArray();
LOCAL_NOfFileAliases++;
GLOBAL_NOfFileAliases++;
aliasp->name = arg;
aliasp->alias_stream = sno;
}
@ -270,13 +270,13 @@ void
Yap_DeleteAliases (int sno)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases, aliasp_max = LOCAL_FileAliases+ LOCAL_NOfFileAliases, new_aliasp = aliasp;
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+ GLOBAL_NOfFileAliases, new_aliasp = aliasp;
while (aliasp < aliasp_max) {
if (aliasp->alias_stream == sno) {
if (aliasp - LOCAL_FileAliases < 3) {
if (aliasp - GLOBAL_FileAliases < 3) {
/* get back to std streams, but keep alias around */
Int alno = aliasp-LOCAL_FileAliases;
Int alno = aliasp-GLOBAL_FileAliases;
new_aliasp->alias_stream = alno;
switch(alno) {
case 0:
@ -291,8 +291,8 @@ Yap_DeleteAliases (int sno)
}
new_aliasp++;
} else {
LOCAL_NOfFileAliases--;
// printf("RM %p at %d/%d %d\n", new_aliasp->name, new_aliasp-LOCAL_FileAliases, new_aliasp->alias_stream, sno);
GLOBAL_NOfFileAliases--;
// printf("RM %p at %d/%d %d\n", new_aliasp->name, new_aliasp-GLOBAL_FileAliases, new_aliasp->alias_stream, sno);
}
} else {
/* avoid holes in alias array */
@ -311,7 +311,7 @@ int
Yap_CheckAlias (Atom arg)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases, aliasp_max = LOCAL_FileAliases+LOCAL_NOfFileAliases;
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
@ -328,7 +328,7 @@ static Atom
FetchAlias (int sno)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases, aliasp_max = LOCAL_FileAliases+LOCAL_NOfFileAliases;
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
if (aliasp->alias_stream == sno) {
@ -344,7 +344,7 @@ static bool
ExistsAliasForStream (int sno, Atom al)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases, aliasp_max = LOCAL_FileAliases+LOCAL_NOfFileAliases;
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
if (aliasp->alias_stream == sno && aliasp->name == al) {
@ -360,8 +360,8 @@ bool
Yap_FindStreamForAlias (Atom al)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases,
aliasp_max = LOCAL_FileAliases+LOCAL_NOfFileAliases;
AliasDesc aliasp = GLOBAL_FileAliases,
aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
if (aliasp->name == al) {
@ -378,7 +378,7 @@ Yap_RemoveAlias (Atom arg, int sno)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases, aliasp_max = LOCAL_FileAliases+LOCAL_NOfFileAliases;
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
if (aliasp->name == arg) {
@ -389,11 +389,11 @@ Yap_RemoveAlias (Atom arg, int sno)
}
aliasp++;
}
//printf("RM %p at %d\n", arg, aliasp-LOCAL_FileAliases);
//printf("RM %p at %d\n", arg, aliasp-GLOBAL_FileAliases);
/* we have not found an alias neither a hole */
if (aliasp == LOCAL_FileAliases+LOCAL_SzOfFileAliases)
if (aliasp == GLOBAL_FileAliases+GLOBAL_SzOfFileAliases)
ExtendAliasArray();
LOCAL_NOfFileAliases--;
GLOBAL_NOfFileAliases--;
aliasp->name = arg;
aliasp->alias_stream = sno;
return(TRUE);
@ -405,7 +405,7 @@ Yap_AddAlias (Atom arg, int sno)
{
CACHE_REGS
AliasDesc aliasp = LOCAL_FileAliases, aliasp_max = LOCAL_FileAliases+LOCAL_NOfFileAliases;
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
if (aliasp->name == arg) {
@ -415,10 +415,10 @@ Yap_AddAlias (Atom arg, int sno)
aliasp++;
}
/* we have not found an alias neither a hole */
if (aliasp == LOCAL_FileAliases+LOCAL_SzOfFileAliases)
if (aliasp == GLOBAL_FileAliases+GLOBAL_SzOfFileAliases)
ExtendAliasArray();
LOCAL_NOfFileAliases++;
// printf("ADD %p at %d\n", arg, aliasp-LOCAL_FileAliases);
GLOBAL_NOfFileAliases++;
// printf("ADD %p at %d\n", arg, aliasp-GLOBAL_FileAliases);
aliasp->name = arg;
aliasp->alias_stream = sno;
return true;
@ -432,25 +432,25 @@ Yap_InitStandardAliases(void)
/* init standard aliases */
/* alloca alias array */
LOCAL_FileAliases = (AliasDesc)Yap_AllocCodeSpace(sizeof(struct AliasDescS)*ALIASES_BLOCK_SIZE);
GLOBAL_FileAliases = (AliasDesc)Yap_AllocCodeSpace(sizeof(struct AliasDescS)*ALIASES_BLOCK_SIZE);
if (LOCAL_FileAliases == NULL)
if (GLOBAL_FileAliases == NULL)
return NULL;
LOCAL_FileAliases[0].name = AtomUserIn;
LOCAL_FileAliases[0].alias_stream = 0;
LOCAL_FileAliases[1].name = AtomUserOut;
LOCAL_FileAliases[1].alias_stream = 1;
LOCAL_FileAliases[2].name = AtomUserErr;
LOCAL_FileAliases[2].alias_stream = 2;
LOCAL_FileAliases[3].name = AtomLoopStream;
LOCAL_FileAliases[3].alias_stream = 0;
LOCAL_FileAliases[4].name = AtomDebuggerInput;
LOCAL_FileAliases[4].alias_stream = 0;
LOCAL_NOfFileAliases = 5;
LOCAL_SzOfFileAliases = ALIASES_BLOCK_SIZE;
GLOBAL_FileAliases[0].name = AtomUserIn;
GLOBAL_FileAliases[0].alias_stream = 0;
GLOBAL_FileAliases[1].name = AtomUserOut;
GLOBAL_FileAliases[1].alias_stream = 1;
GLOBAL_FileAliases[2].name = AtomUserErr;
GLOBAL_FileAliases[2].alias_stream = 2;
GLOBAL_FileAliases[3].name = AtomLoopStream;
GLOBAL_FileAliases[3].alias_stream = 0;
GLOBAL_FileAliases[4].name = AtomDebuggerInput;
GLOBAL_FileAliases[4].alias_stream = 0;
GLOBAL_NOfFileAliases = 5;
GLOBAL_SzOfFileAliases = ALIASES_BLOCK_SIZE;
return LOCAL_FileAliases;
return GLOBAL_FileAliases;
}
/* create a new alias arg for stream sno */