ba0f3 / ngxcmod.nim Goto Github PK
View Code? Open in Web Editor NEWHigh level APIs to build Nginx module with nginx-link-function
Home Page: https://ba0f3.github.io/ngxcmod.nim
License: MIT License
High level APIs to build Nginx module with nginx-link-function
Home Page: https://ba0f3.github.io/ngxcmod.nim
License: MIT License
Hello,
When compiling example code, compiler cannot resolve references to the exported definitions
/usr/bin/ld: /home/rhenvar/.cache/nim/test_d/@mtest.nim.c.o: in function `ngx_link_func_init_cycle':
@mtest.nim.c:(.text+0xad): undefined reference to `ngx_link_func_cyc_log_info'
/usr/bin/ld: /home/rhenvar/.cache/nim/test_d/@mtest.nim.c.o: in function `ngx_link_func_exit_cycle':
@mtest.nim.c:(.text+0x1ad): undefined reference to `ngx_link_func_cyc_log_warn'
/usr/bin/ld: /home/rhenvar/.cache/nim/test_d/@mtest.nim.c.o: in function `hello':
@mtest.nim.c:(.text+0x2b8): undefined reference to `ngx_link_func_log_info'
/usr/bin/ld: @mtest.nim.c:(.text+0x2d6): undefined reference to `ngx_link_func_get_query_param'
/usr/bin/ld: @mtest.nim.c:(.text+0x343): undefined reference to `ngx_link_func_write_resp'
/usr/bin/ld: /home/rhenvar/.cache/nim/test_d/@mtest.nim.c.o: in function `post':
@mtest.nim.c:(.text+0x495): undefined reference to `ngx_link_func_write_resp'
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc -o /home/rhenvar/ParadigmInteractive/dataAPIServer/src/pkg/test /home/rhenvar/.cache/nim/test_d/stdlib_system.nim.c.o /home/rhenvar/.cache/nim/test_d/stdlib_strutils.nim.c.o /home/rhenvar/.cache/nim/test_d/@mtest.nim.c.o -lm -ldl -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'
shell returned 1
Above results were generated from following file:
import ngxcmod, strutils
proc init(ctx: ContextCycle) {.init.} =
ctx.cyc_log(INFO, "hello from Nim")
proc exit(ctx: ContextCycle) {.exit.} =
ctx.cyc_log(WARN, "goodbye, from Nim w/ <3")
proc hello(ctx: Context) {.exportc.} =
ctx.log(INFO, "Calling back and log from hello")
let
name = ctx.getQueryParam("name")
message = "hello $#, greeting from Nim" % name
ctx.response(200, "200 OK", CONTENT_TYPE_PLAINTEXT, message)
proc post(ctx: Context) {.exportc.} =
ctx.response(200, "200 OK", CONTENT_TYPE_PLAINTEXT, ctx.getBodyAsStr())
Nim compiler info:
[rhenvar@manjaro pkg]$ nim --version
Nim Compiler Version 1.0.4 [Linux: amd64]
Compiled at 2019-11-27
Copyright (c) 2006-2019 by Andreas Rumpf
active boot switches: -d:release -d:nativeStackTrace
Hello,
I have just discovered this and the possibility of building apps in Nim and deploying them as Nginx modules is so exciting. Thank you so much for the great work!
I have successfully compiled the module using the example code, but when I start nginx, it keeps crashing with the logs below:
019/10/29 21:26:13 [notice] 8#8: enabled aio threads for link-function module in /etc/nginx/nginx.conf :124
2019/10/29 21:26:13 [info] 8#8: Init Default Share memory with 1M in /etc/nginx/nginx.conf:124
2019/10/29 21:26:13 [notice] 8#8: using the "epoll" event method
2019/10/29 21:26:13 [notice] 8#8: start worker processes
2019/10/29 21:26:13 [notice] 8#8: start worker process 45
2019/10/29 21:26:13 [notice] 45#45: enabled aio threads for link-function module
2019/10/29 21:26:13 [info] 45#45: Application /opt/app/hello.so loaded successfully
2019/10/29 21:26:13 [info] 45#45: application initializing
Traceback (most recent call last)
/home/user/.nimble/pkgs/ngxcmod-0.1.2/ngxcmod.nim(41) onInit
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
2019/10/29 21:26:13 [notice] 8#8: signal 17 (SIGCHLD) received from 45
2019/10/29 21:26:13 [notice] 8#8: worker process 45 exited with code 1
2019/10/29 21:26:13 [notice] 8#8: start worker process 51
2019/10/29 21:26:13 [notice] 8#8: signal 29 (SIGIO) received
2019/10/29 21:26:13 [notice] 9#9: gracefully shutting down
2019/10/29 21:26:13 [notice] 9#9: exiting
2019/10/29 21:26:13 [notice] 9#9: exit
To prevent the crash, I needed to remove ctx.log
calls from both onInit and onExit functions. After commenting out those two lines, it works.
Is it possible that ctx is not initialized or somehow not ready when these two functions are called?
Thank you for the library again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.