aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_fann.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-05 15:47:51 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-05 15:47:51 +0000
commitcace15e3d1f7fb566516d8363749a609ae7799f1 (patch)
treeb8af20d42162e6cdde0349dc13a8f52651a51363 /src/lua/lua_fann.c
parent1062fb49578891029c735041b0a59ebe5d4e3ab2 (diff)
downloadrspamd-cace15e3d1f7fb566516d8363749a609ae7799f1.tar.gz
rspamd-cace15e3d1f7fb566516d8363749a609ae7799f1.zip
[Minor] Add workaround for old debian
Diffstat (limited to 'src/lua/lua_fann.c')
-rw-r--r--src/lua/lua_fann.c42
1 files changed, 41 insertions, 1 deletions
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);