Skip to content

Commit

Permalink
PORT: Use portable definition of struct clause
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWielemaker committed Jan 4, 2025
1 parent cfb2b8f commit b343b56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/pl-global.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 1997-2024, University of Amsterdam
Copyright (c) 1997-2025, University of Amsterdam
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
Expand Down Expand Up @@ -389,6 +389,8 @@ struct PL_global_data
int cgc_space_factor; /* Max total/margin garbage */
double cgc_stack_factor; /* Price to scan stack space */
double cgc_clause_factor; /* Pce to scan clauses */
Clause top_clause; /* See PL_open_query() */
struct clause_ref top_cref; /* Its reference */
} clauses;

struct
Expand Down
4 changes: 2 additions & 2 deletions src/pl-incl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 1985-2024, University of Amsterdam,
Copyright (c) 1985-2025, University of Amsterdam,
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
Expand Down Expand Up @@ -1419,7 +1419,7 @@ struct clause
unsigned int references; /* # ClauseRef pointing at me */
unsigned int tr_erased_no; /* # transactions that erased me */
code code_size; /* size of ->codes */
code codes[1]; /* VM codes of clause */
code codes[]; /* VM codes of clause */
};

typedef struct arg_info
Expand Down
25 changes: 12 additions & 13 deletions src/pl-wam.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 1985-2024, University of Amsterdam
Copyright (c) 1985-2025, University of Amsterdam
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
Expand Down Expand Up @@ -2721,18 +2721,17 @@ PL_open_query(Module ctx, int flags, Procedure proc, term_t args)
size_t i, arity;
Word ap;
size_t lneeded;
static int top_initialized = false;
static struct clause clause;
static struct clause_ref cref;

if ( !top_initialized )
{ clause.predicate = PROCEDURE_dc_call_prolog->definition;
clause.generation.erased = ~(gen_t)0;
clause.code_size = 1;
clause.codes[0] = encode(I_EXITQUERY);
cref.value.clause = &clause;
if ( !GD->clauses.top_clause )
{ Clause cl = allocHeapOrHalt(sizeofClause(1));

top_initialized = true;
memset(cl, 0, sizeofClause(1));
cl->predicate = PROCEDURE_dc_call_prolog->definition;
cl->generation.erased = ~(gen_t)0;
cl->code_size = 1;
cl->codes[0] = encode(I_EXITQUERY);
GD->clauses.top_cref.value.clause = cl;
GD->clauses.top_clause = cl; /* MT-safe as a init is a single thread */
}

DEBUG(2, { FunctorDef f = proc->definition->functor;
Expand Down Expand Up @@ -2782,7 +2781,7 @@ PL_open_query(Module ctx, int flags, Procedure proc, term_t args)
top->parent = NULL;
top->predicate = PROCEDURE_dc_call_prolog->definition;
top->programPointer= NULL;
top->clause = &cref;
top->clause = &GD->clauses.top_cref;
#ifdef O_PROFILE
if ( LD->profile.active )
top->prof_node = profCall(top->predicate);
Expand All @@ -2801,7 +2800,7 @@ PL_open_query(Module ctx, int flags, Procedure proc, term_t args)
fr->parent = top;
setNextFrameFlags(fr, top);
set(top, FR_HIDE_CHILDS);
fr->programPointer = clause.codes;
fr->programPointer = GD->clauses.top_clause->codes;

DEBUG(CHK_SECURE, checkStacks(NULL));
assert((uintptr_t)fli_context > (uintptr_t)environment_frame);
Expand Down

0 comments on commit b343b56

Please sign in to comment.