Add upstream patches to fix bugs (Closes: #973527)
Lev Lamberov
3 years ago
0 | From 0341967e221a953567db1de2d327c63077152187 Mon Sep 17 00:00:00 2001 | |
1 | From: Jan Wielemaker <J.Wielemaker@vu.nl> | |
2 | Date: Thu, 5 Nov 2020 15:07:45 +0100 | |
3 | ubject: TEST: Relax XSB tabling test abol_test3b.P as | |
4 | reclaiming the tables is not guaranteed. | |
5 | ||
6 | --- | |
7 | src/Tests/xsb/table_tests/abol_test3b.P | 7 ++++++- | |
8 | 1 file changed, 6 insertions(+), 1 deletion(-) | |
9 | ||
10 | --- a/src/Tests/xsb/table_tests/abol_test3b.P | |
11 | +++ b/src/Tests/xsb/table_tests/abol_test3b.P | |
12 | @@ -27,7 +27,12 @@ test :- | |
13 | test2, | |
14 | gc_tables(N1), | |
15 | N is N1-N0, | |
16 | - writeln(remaining(N)), | |
17 | + ( N == 0 | |
18 | + -> true | |
19 | + ; format(user_error, | |
20 | + 'Test abol_test3b left %d tables. Can happen.~n', [N]) | |
21 | + ), | |
22 | + writeln(remaining(0)), | |
23 | get_residual(upred(X),_),writeln(first(X)). | |
24 | ||
25 | test2 :- |
0 | From 0e3427afda6a0920a255f258948e6d094d553507 Mon Sep 17 00:00:00 2001 | |
1 | From: Jan Wielemaker <J.Wielemaker@vu.nl> | |
2 | Date: Tue, 3 Nov 2020 17:13:52 +0100 | |
3 | Subject: FIXED: Race between destroying thread-local definitions | |
4 | and clause garbage collection. With Matt Lilley. | |
5 | ||
6 | --- | |
7 | src/pl-funcs.h | 1 + | |
8 | src/pl-index.c | 19 +++++++++++++++++++ | |
9 | src/pl-proc.c | 44 ++++++++++++++++++++++++++++---------------- | |
10 | 3 files changed, 48 insertions(+), 16 deletions(-) | |
11 | ||
12 | --- a/src/pl-funcs.h | |
13 | +++ b/src/pl-funcs.h | |
14 | @@ -130,6 +130,7 @@ COMMON(void) unallocClauseIndexTable(Cl | |
15 | COMMON(void) deleteActiveClauseFromIndexes(Definition def, Clause cl); | |
16 | COMMON(bool) unify_index_pattern(Procedure proc, term_t value); | |
17 | COMMON(void) deleteIndexes(ClauseList cl, int isnew); | |
18 | +COMMON(void) deleteIndexesDefinition(Definition def); | |
19 | COMMON(int) checkClauseIndexSizes(Definition def, int nindexable); | |
20 | COMMON(void) checkClauseIndexes(Definition def); | |
21 | COMMON(void) listIndexGenerations(Definition def, gen_t gen); | |
22 | --- a/src/pl-index.c | |
23 | +++ b/src/pl-index.c | |
24 | @@ -1451,6 +1451,25 @@ deleteIndexes(ClauseList clist, int isne | |
25 | } | |
26 | ||
27 | ||
28 | +void | |
29 | +deleteIndexesDefinition(Definition def) | |
30 | +{ ClauseList clist = &def->impl.clauses; | |
31 | + ClauseIndex *cip0; | |
32 | + | |
33 | + if ( (cip0=clist->clause_indexes) ) | |
34 | + { ClauseIndex *cip; | |
35 | + | |
36 | + for(cip = cip0; *cip; cip++) | |
37 | + { ClauseIndex ci = *cip; | |
38 | + | |
39 | + if ( ISDEADCI(ci) ) | |
40 | + continue; | |
41 | + | |
42 | + deleteIndexP(def, clist, cip); | |
43 | + } | |
44 | + } | |
45 | +} | |
46 | + | |
47 | ||
48 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
49 | Add a clause to an index. If the clause cannot be indexed (typically | |
50 | --- a/src/pl-proc.c | |
51 | +++ b/src/pl-proc.c | |
52 | @@ -171,12 +171,22 @@ destroyDefinition(Definition def) | |
53 | { ATOMIC_DEC(&GD->statistics.predicates); | |
54 | ATOMIC_SUB(&def->module->code_size, sizeof(*def)); | |
55 | ||
56 | + DEBUG(MSG_CGC_PRED, | |
57 | + Sdprintf("destroyDefinition(%s)\n", predicateName(def))); | |
58 | + | |
59 | freeCodesDefinition(def, FALSE); | |
60 | ||
61 | if ( false(def, P_FOREIGN|P_THREAD_LOCAL) ) /* normal Prolog predicate */ | |
62 | - { deleteIndexes(&def->impl.clauses, TRUE); | |
63 | + { GET_LD | |
64 | + | |
65 | + deleteIndexesDefinition(def); | |
66 | removeClausesPredicate(def, 0, FALSE); | |
67 | - freeHeap(def->impl.any.args, sizeof(arg_info)*def->functor->arity); | |
68 | + registerDirtyDefinition(def PASS_LD); | |
69 | + DEBUG(MSG_PROC_COUNT, Sdprintf("Erased %s\n", predicateName(def))); | |
70 | + def->module = NULL; | |
71 | + set(def, P_ERASED); | |
72 | + | |
73 | + return; | |
74 | } else /* foreign and thread-local */ | |
75 | { DEBUG(MSG_PROC_COUNT, Sdprintf("Unalloc foreign/thread-local: %s\n", | |
76 | predicateName(def))); | |
77 | @@ -187,20 +197,10 @@ destroyDefinition(Definition def) | |
78 | } | |
79 | ||
80 | if ( def->tabling ) | |
81 | - { freeHeap(def->tabling, sizeof(*def->tabling)); | |
82 | - def->tabling = NULL; | |
83 | - } | |
84 | + freeHeap(def->tabling, sizeof(*def->tabling)); | |
85 | ||
86 | - DEBUG(MSG_CGC_PRED, | |
87 | - Sdprintf("destroyDefinition(%s)\n", predicateName(def))); | |
88 | - if ( true(def, P_DIRTYREG) ) | |
89 | - { DEBUG(MSG_PROC_COUNT, Sdprintf("Erased %s\n", predicateName(def))); | |
90 | - def->module = NULL; | |
91 | - set(def, P_ERASED); | |
92 | - } else | |
93 | - { DEBUG(MSG_PROC_COUNT, Sdprintf("Unalloc %s\n", predicateName(def))); | |
94 | - freeHeap(def, sizeof(*def)); | |
95 | - } | |
96 | + DEBUG(MSG_PROC_COUNT, Sdprintf("Unalloc %s\n", predicateName(def))); | |
97 | + freeHeap(def, sizeof(*def)); | |
98 | } | |
99 | ||
100 | ||
101 | @@ -2377,7 +2377,19 @@ maybeUnregisterDirtyDefinition(Definitio | |
102 | { DEBUG(MSG_PROC_COUNT, Sdprintf("Delayed unalloc %s\n", predicateName(def))); | |
103 | assert(def->module == NULL); | |
104 | if ( def->impl.clauses.first_clause == NULL ) | |
105 | - { unregisterDirtyDefinition(def); | |
106 | + { if ( def->lingering ) | |
107 | + { static int done = FALSE; | |
108 | + if ( !done ) | |
109 | + { Sdprintf("maybeUnregisterDirtyDefinition(%s): lingering data\n", | |
110 | + predicateName(def)); | |
111 | + done = TRUE; | |
112 | + } | |
113 | + } | |
114 | + unregisterDirtyDefinition(def); | |
115 | + deleteIndexes(&def->impl.clauses, TRUE); | |
116 | + freeHeap(def->impl.any.args, sizeof(arg_info)*def->functor->arity); | |
117 | + if ( def->tabling ) | |
118 | + freeHeap(def->tabling, sizeof(*def->tabling)); | |
119 | freeHeap(def, sizeof(*def)); | |
120 | } | |
121 | } |
0 | From 18bc58fa79a3127d2b70b663ba0a361c9a63ddb2 Mon Sep 17 00:00:00 2001 | |
1 | From: Jan Wielemaker <J.Wielemaker@vu.nl> | |
2 | Date: Tue, 3 Nov 2020 09:31:01 +0100 | |
3 | Subject: FIXED: Thread-local definitions corrupted the argument | |
4 | declaration. Matt Lilley. | |
5 | ||
6 | --- | |
7 | src/pl-incl.h | 8 +++++++- | |
8 | src/pl-proc.c | 2 +- | |
9 | src/pl-thread.c | 10 ++++++++-- | |
10 | src/pl-wam.c | 6 +++--- | |
11 | 4 files changed, 19 insertions(+), 7 deletions(-) | |
12 | ||
13 | --- a/src/pl-incl.h | |
14 | +++ b/src/pl-incl.h | |
15 | @@ -1301,6 +1301,12 @@ typedef struct impl_wrapped | |
16 | Code supervisor; /* Supervisor to use */ | |
17 | } impl_wrapped, *ImplWrapped; | |
18 | ||
19 | +typedef struct impl_local | |
20 | +{ arg_info *args; /* Meta and indexing info */ | |
21 | + LocalDefinitions local; /* P_THREAD_LOCAL predicates */ | |
22 | +} impl_local, *ImplLocal; | |
23 | + | |
24 | + | |
25 | typedef struct clause_list | |
26 | { arg_info *args; /* Meta and indexing info */ | |
27 | ClauseRef first_clause; /* clause list of procedure */ | |
28 | @@ -1471,7 +1477,7 @@ struct definition | |
29 | clause_list clauses; /* (Indexed) list of clauses */ | |
30 | impl_foreign foreign; /* Foreign implementation */ | |
31 | impl_wrapped wrapped; /* Wrapped predicate */ | |
32 | - LocalDefinitions local; /* P_THREAD_LOCAL predicates */ | |
33 | + impl_local local; /* P_THREAD_LOCAL predicates */ | |
34 | } impl; | |
35 | unsigned int flags; /* booleans (P_*) */ | |
36 | unsigned int shared; /* #procedures sharing this def */ | |
37 | --- a/src/pl-proc.c | |
38 | +++ b/src/pl-proc.c | |
39 | @@ -3423,7 +3423,7 @@ setThreadLocalDefinition(Definition def, | |
40 | return PL_error(NULL, 0, NULL, ERR_MODIFY_STATIC_PREDICATE, def); | |
41 | } | |
42 | ||
43 | - def->impl.local = new_ldef_vector(); | |
44 | + def->impl.local.local = new_ldef_vector(); | |
45 | MEMORY_RELEASE(); | |
46 | set(def, P_DYNAMIC|P_VOLATILE|P_THREAD_LOCAL); | |
47 | def->codes = SUPERVISOR(thread_local); | |
48 | --- a/src/pl-thread.c | |
49 | +++ b/src/pl-thread.c | |
50 | @@ -6330,7 +6330,7 @@ we need to scan the entire localization | |
51 | void | |
52 | destroyLocalDefinitions(Definition def) | |
53 | { GET_LD | |
54 | - LocalDefinitions ldefs = def->impl.local; | |
55 | + LocalDefinitions ldefs = def->impl.local.local; | |
56 | int b; | |
57 | ||
58 | for(b=0; b<MAX_BLOCKS; b++) | |
59 | @@ -6437,7 +6437,13 @@ sizeof_local_definitions(PL_local_data_t | |
60 | size_t size = 0; | |
61 | ||
62 | for( ; ch; ch = ch->next) | |
63 | - size += sizeof_predicate(ch->definition); | |
64 | + { Definition def = ch->definition; | |
65 | + Definition local; | |
66 | + | |
67 | + assert(true(def, P_THREAD_LOCAL)); | |
68 | + if ( (local = getProcDefinitionForThread(def, ld->thread.info->pl_tid)) ) | |
69 | + size += sizeof_predicate(local); | |
70 | + } | |
71 | ||
72 | return size; | |
73 | } | |
74 | --- a/src/pl-wam.c | |
75 | +++ b/src/pl-wam.c | |
76 | @@ -1389,7 +1389,7 @@ static Definition | |
77 | localDefinition(Definition def ARG_LD) | |
78 | { unsigned int tid = LD->thread.info->pl_tid; | |
79 | size_t idx = MSB(tid); | |
80 | - LocalDefinitions v = def->impl.local; | |
81 | + LocalDefinitions v = def->impl.local.local; | |
82 | ||
83 | if ( !v->blocks[idx] ) | |
84 | { size_t bs = (size_t)1<<idx; | |
85 | @@ -1412,7 +1412,7 @@ localDefinition(Definition def ARG_LD) | |
86 | void | |
87 | destroyLocalDefinition(Definition def, unsigned int tid) | |
88 | { size_t idx = MSB(tid); | |
89 | - LocalDefinitions v = def->impl.local; | |
90 | + LocalDefinitions v = def->impl.local.local; | |
91 | Definition local; | |
92 | ||
93 | local = v->blocks[idx][tid]; | |
94 | @@ -1438,7 +1438,7 @@ getProcDefinition__LD(Definition def ARG | |
95 | Definition | |
96 | getProcDefinitionForThread(Definition def, unsigned int tid) | |
97 | { size_t idx = MSB(tid); | |
98 | - LocalDefinitions v = def->impl.local; | |
99 | + LocalDefinitions v = def->impl.local.local; | |
100 | ||
101 | if ( !v->blocks[idx] ) | |
102 | return NULL; |
0 | From 22488b4e37cf170ae7cfa0a8f47084620e5c97a1 Mon Sep 17 00:00:00 2001 | |
1 | From: Jan Wielemaker <J.Wielemaker@vu.nl> | |
2 | Date: Wed, 28 Oct 2020 15:42:03 +0100 | |
3 | Subject: FIXED: Avoid double preparation of the libedit signal | |
4 | handling. Double preparation may lead to an infinite recursion in | |
5 | el_sighandler() and can happen if multiple threads prepare the library. | |
6 | ||
7 | --- a/packages/libedit/libedit4pl.c | |
8 | +++ b/packages/libedit/libedit4pl.c | |
9 | @@ -247,6 +247,7 @@ This code is copied from our GNU libread | |
10 | ||
11 | typedef struct | |
12 | { int signo; /* number of the signal */ | |
13 | + int prepared; /* Is currently prepared */ | |
14 | struct sigaction old_state; /* old state for the signal */ | |
15 | } sigstate; | |
16 | ||
17 | @@ -280,11 +281,14 @@ static sigstate cont_signals[] = | |
18 | static void | |
19 | prepare_signals(sigstate *s) | |
20 | { for(; s->signo != -1; s++) | |
21 | - { struct sigaction new; | |
22 | + { if ( !s->prepared ) | |
23 | + { struct sigaction new; | |
24 | ||
25 | - memset(&new, 0, sizeof(new)); | |
26 | - new.sa_handler = el_sighandler; | |
27 | - sigaction(s->signo, &new, &s->old_state); | |
28 | + memset(&new, 0, sizeof(new)); | |
29 | + new.sa_handler = el_sighandler; | |
30 | + sigaction(s->signo, &new, &s->old_state); | |
31 | + s->prepared = TRUE; | |
32 | + } | |
33 | } | |
34 | } | |
35 | ||
36 | @@ -293,6 +297,7 @@ static void | |
37 | restore_signals(sigstate *s) | |
38 | { for(; s->signo != -1; s++) | |
39 | { sigaction(s->signo, &s->old_state, NULL); | |
40 | + s->prepared = FALSE; | |
41 | } | |
42 | } | |
43 |
0 | From 7eb69d2de0491922f942cc9dfdcc19c8ba23c3d9 Mon Sep 17 00:00:00 2001 | |
1 | From: Jan Wielemaker <J.Wielemaker@vu.nl> | |
2 | Date: Thu, 5 Nov 2020 13:52:33 +0100 | |
3 | Subject: FIXED: Possible race in shared table handling. Leads | |
4 | to "Oops, worklist trie doesn't point back at me!" messages. | |
5 | ||
6 | --- | |
7 | src/pl-tabling.c | 1 + | |
8 | 1 file changed, 1 insertion(+) | |
9 | ||
10 | --- a/src/pl-tabling.c | |
11 | +++ b/src/pl-tabling.c | |
12 | @@ -4581,6 +4581,7 @@ PRED_IMPL("$tbl_table_complete_all", 3, | |
13 | ||
14 | if ( true(atrie, TRIE_ABOLISH_ON_COMPLETE) ) | |
15 | { atrie->data.worklist = NULL; | |
16 | + wl->table = NULL; | |
17 | destroy_answer_trie(atrie); | |
18 | free_worklist(wl); | |
19 | } else if ( !wl->undefined && isEmptyBuffer(&wl->delays) ) /* see (*) */ |
7 | 7 | src/pl-tabling.c | 12 +++++++++++- |
8 | 8 | 1 file changed, 11 insertions(+), 1 deletion(-) |
9 | 9 | |
10 | diff --git a/src/pl-tabling.c b/src/pl-tabling.c | |
11 | index ddfc589f04..7d7381acc3 100644 | |
12 | 10 | --- a/src/pl-tabling.c |
13 | 11 | +++ b/src/pl-tabling.c |
14 | @@ -1140,8 +1140,18 @@ update_delay_list(worklist *wl, trie_node *answer, | |
12 | @@ -1140,8 +1140,18 @@ retry: | |
15 | 13 | } |
16 | 14 | deRef2(&f->arguments[1], p); |
17 | 15 | if ( isInteger(*p) ) |
1 | 1 | no_extra_documentation.diff |
2 | 2 | disable_http_proxy_test.diff |
3 | 3 | b218a30b5e4bb92ddd399238666448a102117bad.patch |
4 | 18bc58fa79a3127d2b70b663ba0a361c9a63ddb2.diff | |
5 | 0e3427afda6a0920a255f258948e6d094d553507.diff | |
6 | 7eb69d2de0491922f942cc9dfdcc19c8ba23c3d9.diff | |
7 | 0341967e221a953567db1de2d327c63077152187.diff | |
8 | 22488b4e37cf170ae7cfa0a8f47084620e5c97a1.diff |