aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-27 12:35:42 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-27 12:36:19 +0100
commit3c9f4621d2459366bb6fe6120991baad41ce6fc0 (patch)
tree5788285d4bea71a1a35fb9024e3254b3a62768e2
parent357bbf4c92ddb3fbc0c4292600b2ad9e95cd0a13 (diff)
downloadrspamd-3c9f4621d2459366bb6fe6120991baad41ce6fc0.tar.gz
rspamd-3c9f4621d2459366bb6fe6120991baad41ce6fc0.zip
[Minor] Allow to get rspamd text from torch storage
-rw-r--r--contrib/torch/torch7/Storage.c6
-rw-r--r--contrib/torch/torch7/generic/Storage.c23
2 files changed, 29 insertions, 0 deletions
diff --git a/contrib/torch/torch7/Storage.c b/contrib/torch/torch7/Storage.c
index 874838e8c..730d97476 100644
--- a/contrib/torch/torch7/Storage.c
+++ b/contrib/torch/torch7/Storage.c
@@ -1,5 +1,11 @@
#include "general.h"
+struct _rspamd_lua_text {
+ const char *start;
+ unsigned int len;
+ unsigned int flags;
+};
+
#define torch_Storage_(NAME) TH_CONCAT_4(torch_,Real,Storage_,NAME)
#define THFile_readRealRaw TH_CONCAT_3(THFile_read, Real, Raw)
#define THFile_writeRealRaw TH_CONCAT_3(THFile_write, Real, Raw)
diff --git a/contrib/torch/torch7/generic/Storage.c b/contrib/torch/torch7/generic/Storage.c
index a6652a5da..b936e5714 100644
--- a/contrib/torch/torch7/generic/Storage.c
+++ b/contrib/torch/torch7/generic/Storage.c
@@ -213,6 +213,28 @@ static int torch_Storage_(string)(lua_State *L)
}
#endif
+static int torch_Storage_(text)(lua_State *L)
+{
+ THStorage *storage = luaT_checkudata(L, 1, torch_Storage);
+ struct _rspamd_lua_text *t;
+
+ if(lua_type(L, -1) == LUA_TUSERDATA)
+ {
+ t = lua_touserdata(L, -1);
+ THStorage_(resize)(storage, t->len);
+ memmove(storage->data, t->start, t->len);
+ lua_settop(L, 1);
+ }
+ else {
+ t = lua_newuserdata (L, sizeof (*t));
+ t->start = (const char *)storage->data;
+ t->len = t->len;
+ t->flags = 0;
+ }
+
+ return 1; /* either storage or string */
+}
+
static int torch_Storage_(totable)(lua_State *L)
{
THStorage *storage = luaT_checkudata(L, 1, torch_Storage);
@@ -274,6 +296,7 @@ static const struct luaL_Reg torch_Storage_(_) [] = {
{"totable", torch_Storage_(totable)},
{"write", torch_Storage_(write)},
{"read", torch_Storage_(read)},
+ {"text", torch_Storage_(text)},
#if defined(TH_REAL_IS_CHAR) || defined(TH_REAL_IS_BYTE)
{"string", torch_Storage_(string)},
#endif