From c583a03f81c8a584b0dd38fdb27591b50adc5c90 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 13 Oct 2017 07:58:10 -0400 Subject: [PATCH] allow lua stuff and fix it up --- contrib/backends/srndv2/Makefile | 3 +++ contrib/backends/srndv2/src/srnd/markup_lua.go | 11 ++++++----- contrib/backends/srndv2/src/srnd/varnish_cache.go | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/contrib/backends/srndv2/Makefile b/contrib/backends/srndv2/Makefile index 9aaa846..8d593f8 100644 --- a/contrib/backends/srndv2/Makefile +++ b/contrib/backends/srndv2/Makefile @@ -13,6 +13,9 @@ assert-go: srndv2: assert-go GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) build -ldflags "-X srnd.GitVersion=-$(shell git rev-parse --short HEAD)" -v +srndv2-lua: + GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) build -ldflags "-X srnd.GitVersion=-$(shell git rev-parse --short HEAD)" -tags lua -v + clean: GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) clean -v diff --git a/contrib/backends/srndv2/src/srnd/markup_lua.go b/contrib/backends/srndv2/src/srnd/markup_lua.go index cbcb18d..9989ecf 100644 --- a/contrib/backends/srndv2/src/srnd/markup_lua.go +++ b/contrib/backends/srndv2/src/srnd/markup_lua.go @@ -35,15 +35,16 @@ func (l *Lua) GC() { // close the interpreter // all resources are expunged and no operations can be done after this func (l *Lua) Close() { + l.mtx.Lock() if l.state != nil { C.lua_close(l.state) } l.state = nil + l.mtx.Unlock() } func (l *Lua) LoadFile(fname string) (err error) { cfname := C.CString(fname) - //defer C.free(unsafe.Pointer(cfname)) res := C.luaL_loadfilex(l.state, cfname, nil) if res == 0 { res = C.lua_pcallk(l.state, 0, C.LUA_MULTRET, 0, 0, nil) @@ -54,12 +55,12 @@ func (l *Lua) LoadFile(fname string) (err error) { // failed to load file err = errors.New("failed to load file " + fname) } + C.free(unsafe.Pointer(cfname)) return } func (l *Lua) MEMEPosting(prefix, body string) (meme string) { l.mtx.Lock() - defer l.mtx.Unlock() cf := C.CString(luaFuncName) C.lua_getglobal(l.state, cf) cp := C.CString(prefix) @@ -74,8 +75,6 @@ func (l *Lua) MEMEPosting(prefix, body string) (meme string) { meme = C.GoStringN(cret, C.int(sz)) } - C.lua_settop(l.state, -(1)-1) - if res != C.LUA_OK { // error log.Println("lua error:", meme) @@ -85,6 +84,9 @@ func (l *Lua) MEMEPosting(prefix, body string) (meme string) { // free buffers C.free(unsafe.Pointer(cb)) C.free(unsafe.Pointer(cp)) + C.free(unsafe.Pointer(cf)) + l.GC() + l.mtx.Unlock() return } @@ -107,7 +109,6 @@ func extraMemePosting(src, prefix string) string { if luaInt == nil { return src } - defer luaInt.GC() return luaInt.MEMEPosting(src, prefix) } diff --git a/contrib/backends/srndv2/src/srnd/varnish_cache.go b/contrib/backends/srndv2/src/srnd/varnish_cache.go index b250f7d..3a23723 100644 --- a/contrib/backends/srndv2/src/srnd/varnish_cache.go +++ b/contrib/backends/srndv2/src/srnd/varnish_cache.go @@ -101,6 +101,7 @@ func (self *VarnishCache) poll() { for { ent := <-self.threadsRegenChan self.Regen(ent) + self.RegenerateBoard(ent.Newsgroup()) } }