aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-18 02:22:07 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-18 02:22:07 +0200
commit4b8a7626bff72b4c3c087649933910e6adf55f37 (patch)
treeb5479e6fe6260b42d24f2fea98104b802dbb29bd
parent9e0738f6aefb13282437ddcb2e2e888a4d57ff37 (diff)
downloadEpisodeBrowser-4b8a7626bff72b4c3c087649933910e6adf55f37.tar.gz
Avoid leak in Prolog interface.
PL_new_atom(_wchars) creates an atom with a reference count of one, which is never decreased, and the atom is thus never garbage collected.
-rw-r--r--c/pl.h17
1 files changed, 5 insertions, 12 deletions
diff --git a/c/pl.h b/c/pl.h
index 06efe13..276f79a 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -23,10 +23,10 @@ inline int PlPut(const term_t t, const int x) { return PL_put_integer(t, x); }
inline int PlPut(const term_t t, const long x) { return PL_put_integer(t, x); }
inline int PlPut(const term_t t, const long long x) { return PL_put_integer(t, x); }
inline int PlPut(const term_t t, const atom_t x) { return PL_put_atom(t, x); }
-inline int PlPut(const term_t t, char* const x) { return PL_put_atom(t, PL_new_atom(x)); }
-inline int PlPut(const term_t t, const char* const x) { return PL_put_atom(t, PL_new_atom(x)); }
-inline int PlPut(const term_t t, wchar_t* const x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); }
-inline int PlPut(const term_t t, const wchar_t* const x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); }
+inline int PlPut(const term_t t, char* const x) { return PL_put_atom_chars(t, x); }
+inline int PlPut(const term_t t, const char* const x) { return PL_put_atom_chars(t, x); }
+inline int PlPut(const term_t t, wchar_t* const x) { return PL_unify_wchars(t, PL_ATOM, -1, x); }
+inline int PlPut(const term_t t, const wchar_t* const x) { return PL_unify_wchars(t, PL_ATOM, -1, x); }
inline int PlPut(const term_t, int* const) { return -1; }
inline int PlPut(const term_t, long* const) { return -1; }
inline int PlPut(const term_t, long long* const) { return -1; }
@@ -45,14 +45,7 @@ inline int PlGet(const term_t t, long* const x) { return PL_get_long(t, x); }
inline int PlGet(const term_t t, long long* const x) { return PL_get_int64(t, x); }
inline int PlGet(const term_t t, atom_t* const x) { return PL_get_atom(t, x); }
inline int PlGet(const term_t t, char** const x) { return PL_get_atom_chars(t, x); }
-inline int PlGet(const term_t t, wchar_t** const x)
-{
- atom_t a;
- size_t len;
- if (!PL_get_atom(t, &a)) return 0;
- *x = (wchar_t*)PL_atom_wchars(a, &len);
- return *x != NULL;
-}
+inline int PlGet(const term_t t, wchar_t** const x) { size_t len; return PL_get_wchars(t, &len, x, CVT_ATOM); }
/* Helper templates for Plx, Pl. */
template <typename T>