diff --git a/debian/changelog b/debian/changelog
index 087bd79..d8f752d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+ppl (1:1.2-8.1) unstable; urgency=low
+
+ * Non-maintainer upload.
+ * Fix FTBFS with swi-prolog 8.2. (Closes: #959623)
+
+ -- Adrian Bunk <bunk@debian.org> Tue, 16 Jun 2020 12:46:14 +0300
+
ppl (1:1.2-8) unstable; urgency=medium
* Add latex_include_ifthen_package.patch. (Closes: #943451)
diff --git a/debian/patches/series b/debian/patches/series
index 9afe6a5..ca18528 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -4,3 +4,4 @@ reproducible_builds_gzip_n
fix_latex_build.patch
fix_AC_CHECK_SWI_PROLOG.patch
latex_include_ifthen_package.patch
+swi82.patch
diff --git a/debian/patches/swi82.patch b/debian/patches/swi82.patch
new file mode 100644
index 0000000..287d355
--- /dev/null
+++ b/debian/patches/swi82.patch
@@ -0,0 +1,166 @@
+Description: Fix FTBFS with swi-prolog 8.2
+Author: Adrian Bunk <bunk@debian.org>
+Bug-Debian: https://bugs.debian.org/959623
+
+--- ppl-1.2.orig/interfaces/Prolog/Ciao/ciao_cfli.hh
++++ ppl-1.2/interfaces/Prolog/Ciao/ciao_cfli.hh
+@@ -296,7 +296,7 @@ Prolog_get_atom_name(Prolog_term_ref t,
+ The behavior is undefined if \p t is not a Prolog compound term.
+ */
+ inline int
+-Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, int* ip) {
++Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, size_t* ip) {
+ assert(Prolog_is_compound(t));
+ *ap = ciao_structure_name(t);
+ *ip = ciao_structure_arity(t);
+--- ppl-1.2.orig/interfaces/Prolog/GNU/gprolog_cfli.hh
++++ ppl-1.2/interfaces/Prolog/GNU/gprolog_cfli.hh
+@@ -420,7 +420,7 @@ Prolog_get_atom_name(Prolog_term_ref t,
+ The behavior is undefined if \p t is not a Prolog compound term.
+ */
+ inline int
+-Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, int* ip) {
++Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, size_t* ip) {
+ assert(Prolog_is_compound(t));
+ Rd_Compound_Check(t, ap, ip);
+ return 1;
+--- ppl-1.2.orig/interfaces/Prolog/SICStus/sicstus_cfli.h
++++ ppl-1.2/interfaces/Prolog/SICStus/sicstus_cfli.h
+@@ -134,7 +134,7 @@ Prolog_get_atom_name(Prolog_term_ref t,
+
+ PCFLI_DECLSPEC int
+ Prolog_get_compound_name_arity(Prolog_term_ref t,
+- Prolog_atom& name, int& arity);
++ Prolog_atom& name, size_t& arity);
+
+ PCFLI_DECLSPEC int
+ Prolog_get_arg(int i, Prolog_term_ref t, Prolog_term_ref a);
+--- ppl-1.2.orig/interfaces/Prolog/SICStus/sicstus_cfli.ic
++++ ppl-1.2/interfaces/Prolog/SICStus/sicstus_cfli.ic
+@@ -262,7 +262,7 @@ Prolog_get_atom_name(Prolog_term_ref t,
+ The behavior is undefined if \p t is not a Prolog compound term.
+ */
+ PCFLI_EXTERN_INLINE int
+-Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, int* ip) {
++Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, size_t* ip) {
+ assert(Prolog_is_compound(t));
+ return SP_get_functor(t, ap, ip);
+ }
+--- ppl-1.2.orig/interfaces/Prolog/SWI/swi_cfli.hh
++++ ppl-1.2/interfaces/Prolog/SWI/swi_cfli.hh
+@@ -346,7 +346,7 @@ Prolog_get_atom_name(Prolog_term_ref t,
+ The behavior is undefined if \p t is not a Prolog compound term.
+ */
+ inline int
+-Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, int* ip) {
++Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, size_t* ip) {
+ assert(Prolog_is_compound(t));
+ return PL_get_name_arity(t, ap, ip);
+ }
+--- ppl-1.2.orig/interfaces/Prolog/XSB/xsb_cfli.hh
++++ ppl-1.2/interfaces/Prolog/XSB/xsb_cfli.hh
+@@ -314,7 +314,7 @@ Prolog_get_atom_name(Prolog_term_ref t,
+ The behavior is undefined if \p t is not a Prolog compound term.
+ */
+ inline int
+-Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, int* ip) {
++Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, size_t* ip) {
+ assert(Prolog_is_compound(t));
+ *ap = p2c_functor(t);
+ *ip = p2c_arity(t);
+--- ppl-1.2.orig/interfaces/Prolog/YAP/yap_cfli.hh
++++ ppl-1.2/interfaces/Prolog/YAP/yap_cfli.hh
+@@ -313,7 +313,7 @@ Prolog_get_atom_name(Prolog_term_ref t,
+ The behavior is undefined if \p t is not a Prolog compound term.
+ */
+ inline int
+-Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, int* ip) {
++Prolog_get_compound_name_arity(Prolog_term_ref t, Prolog_atom* ap, size_t* ip) {
+ assert(Prolog_is_compound(t));
+ YAP_Functor f = YAP_FunctorOfTerm(t);
+ *ap = YAP_NameOfFunctor(f);
+--- ppl-1.2.orig/interfaces/Prolog/ppl_interface_generator_prolog_cc_code.m4
++++ ppl-1.2/interfaces/Prolog/ppl_interface_generator_prolog_cc_code.m4
+@@ -1934,7 +1934,7 @@ m4_define(`ppl_@CLASS@_map_space_dimensi
+ while (Prolog_is_cons(t_pfunc)) {
+ Prolog_get_cons(t_pfunc, t_pair, t_pfunc);
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+ Prolog_get_compound_name_arity(t_pair, &functor, &arity);
+ if (arity != 2 || functor != a_minus)
+ return PROLOG_FAILURE;
+--- ppl-1.2.orig/interfaces/Prolog/ppl_prolog_common.cc
++++ ppl-1.2/interfaces/Prolog/ppl_prolog_common.cc
+@@ -937,7 +937,7 @@ build_linear_expression(Prolog_term_ref
+ return Linear_Expression(integer_term_to_Coefficient(t));
+ else if (Prolog_is_compound(t)) {
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+ Prolog_get_compound_name_arity(t, &functor, &arity);
+ switch (arity) {
+ case 1:
+@@ -1000,7 +1000,7 @@ Constraint
+ build_constraint(Prolog_term_ref t, const char* where) {
+ if (Prolog_is_compound(t)) {
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+ Prolog_get_compound_name_arity(t, &functor, &arity);
+ if (arity == 2) {
+ Prolog_term_ref arg1 = Prolog_new_term_ref();
+@@ -1073,7 +1073,7 @@ Congruence
+ build_congruence(Prolog_term_ref t, const char* where) {
+ if (Prolog_is_compound(t)) {
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+ Prolog_get_compound_name_arity(t, &functor, &arity);
+ if (arity == 2) {
+ Prolog_term_ref arg1 = Prolog_new_term_ref();
+@@ -1084,7 +1084,7 @@ build_congruence(Prolog_term_ref t, cons
+ // /
+ if (Prolog_is_integer(arg2)) {
+ Prolog_atom functor1;
+- int arity1;
++ size_t arity1;
+ Prolog_get_compound_name_arity(arg1, &functor1, &arity1);
+ if (arity1 == 2) {
+ if (functor1 == a_is_congruent_to) {
+@@ -1137,7 +1137,7 @@ Generator
+ build_generator(Prolog_term_ref t, const char* where) {
+ if (Prolog_is_compound(t)) {
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+ Prolog_get_compound_name_arity(t, &functor, &arity);
+ if (arity == 1) {
+ Prolog_term_ref arg = Prolog_new_term_ref();
+@@ -1174,7 +1174,7 @@ Grid_Generator
+ build_grid_generator(Prolog_term_ref t, const char* where) {
+ if (Prolog_is_compound(t)) {
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+ Prolog_get_compound_name_arity(t, &functor, &arity);
+ if (arity == 1) {
+ Prolog_term_ref arg = Prolog_new_term_ref();
+@@ -1406,7 +1406,7 @@ Variable
+ term_to_Variable(Prolog_term_ref t, const char* where) {
+ if (Prolog_is_compound(t)) {
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+ Prolog_get_compound_name_arity(t, &functor, &arity);
+ if (functor == a_dollar_VAR && arity == 1) {
+ Prolog_term_ref arg = Prolog_new_term_ref();
+@@ -1554,7 +1554,7 @@ term_to_boundary(Prolog_term_ref t_b, Bo
+ return false;
+
+ Prolog_atom functor;
+- int arity;
++ size_t arity;
+
+ Prolog_get_compound_name_arity(t_b, &functor, &arity);
+ // A boundary term is either of the form c(Limit) or o(Limit).