diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-18 02:22:07 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-18 02:22:07 +0200 |
commit | 4b8a7626bff72b4c3c087649933910e6adf55f37 (patch) | |
tree | b5479e6fe6260b42d24f2fea98104b802dbb29bd /c/pl.h | |
parent | 9e0738f6aefb13282437ddcb2e2e888a4d57ff37 (diff) | |
download | EpisodeBrowser-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.
Diffstat (limited to 'c/pl.h')
-rw-r--r-- | c/pl.h | 17 |
1 files changed, 5 insertions, 12 deletions
@@ -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> |