From cace15e3d1f7fb566516d8363749a609ae7799f1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 5 Nov 2016 15:47:51 +0000 Subject: [PATCH] [Minor] Add workaround for old debian --- src/lua/lua_fann.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_fann.c b/src/lua/lua_fann.c index 2b2b75c3d..ba57b414a 100644 --- a/src/lua/lua_fann.c +++ b/src/lua/lua_fann.c @@ -203,6 +203,46 @@ string_to_learn_alg (const gchar *str) return FANN_TRAIN_INCREMENTAL; } +/* + * This is needed since libfann provides no versioning macros... + */ +static struct fann_train_data * +rspamd_fann_create_train (guint num_data, guint num_input, guint num_output) +{ + struct fann_train_data *t; + fann_type *inp, *outp; + guint i; + + t = calloc (1, sizeof (*t)); + g_assert (t != NULL); + + t->num_data = num_data; + t->num_input = num_input; + t->num_output = num_output; + + t->input = calloc (num_data, sizeof (fann_type *)); + g_assert (t->input != NULL); + + t->output = calloc (num_data, sizeof (fann_type *)); + g_assert (t->output != NULL); + + inp = calloc (num_data * num_input, sizeof (fann_type)); + g_assert (inp != NULL); + + outp = calloc (num_data * num_output, sizeof (fann_type)); + g_assert (outp != NULL); + + for (i = 0; i < num_data; i ++) { + t->input[i] = inp; + inp += num_input; + t->output[i] = outp; + outp += num_output; + } + + return t; +} + + #endif /*** @@ -662,7 +702,7 @@ lua_fann_train_threaded (lua_State *L) cbdata = g_slice_alloc0 (sizeof (*cbdata)); cbdata->L = L; cbdata->f = f; - cbdata->train = fann_create_train (ndata, ninputs, noutputs); + cbdata->train = rspamd_fann_create_train (ndata, ninputs, noutputs); lua_pushvalue (L, 4); cbdata->cbref = luaL_ref (L, LUA_REGISTRYINDEX); -- 2.39.5