From 34b2f7b8f8399704817dd20a0c59fb91eaae728e Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 7 Apr 2021 17:26:58 +0800 Subject: [PATCH] fix compile error --- deps/lua/src/lauxlib.c | 2 +- src/query/src/qScript.c | 4 +- tests/script/sh/demo.c | 72 ++++++++++++++++++++++++++++++++++++ tests/script/sh/sum_double.c | 25 +++++++++++-- 4 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 tests/script/sh/demo.c diff --git a/deps/lua/src/lauxlib.c b/deps/lua/src/lauxlib.c index 317a48d108..7d00b3a992 100644 --- a/deps/lua/src/lauxlib.c +++ b/deps/lua/src/lauxlib.c @@ -570,7 +570,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { if (lf.f == NULL) return errfile(L, "reopen", fnameindex); /* skip eventual `#!...' */ while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; - lf.extraline = 0; + lf.extraline = 0; } ungetc(c, lf.f); status = lua_load(L, getF, &lf, lua_tostring(L, -1)); diff --git a/src/query/src/qScript.c b/src/query/src/qScript.c index 9968362c1c..af9f2db31c 100644 --- a/src/query/src/qScript.c +++ b/src/query/src/qScript.c @@ -107,7 +107,7 @@ int taosLoadScriptInit(SUdfInit* pInit) { pInit->destroyCtxFunc = destroyScriptCtx; ScriptCtx *pCtx = pInit->script_ctx; - char funcName[MAX_FUNC_NAME] = {0}; + char funcName[MAX_FUNC_NAME + 10] = {0}; sprintf(funcName, "%s_init", pCtx->funcName); lua_State* lua = pCtx->pEnv->lua_state; @@ -129,7 +129,7 @@ int taosLoadScriptNormal(char *pInput, int16_t iType, int16_t iBytes, int32_t nu int16_t oType, int16_t oBytes, SUdfInit *pInit) { ScriptCtx* pCtx = pInit->script_ctx; - char funcName[MAX_FUNC_NAME] = {0}; + char funcName[MAX_FUNC_NAME + 10] = {0}; sprintf(funcName, "%s_add", pCtx->funcName); lua_State* lua = pCtx->pEnv->lua_state; lua_getglobal(lua, funcName); diff --git a/tests/script/sh/demo.c b/tests/script/sh/demo.c new file mode 100644 index 0000000000..5b5243f043 --- /dev/null +++ b/tests/script/sh/demo.c @@ -0,0 +1,72 @@ +#include +#include +#include + +typedef struct SUdfInit{ + int maybe_null; /* 1 if function can return NULL */ + int decimals; /* for real functions */ + long long length; /* For string functions */ + char *ptr; /* free pointer for function data */ + int const_item; /* 0 if result is independent of arguments */ +} SUdfInit; + +typedef struct SDemo{ + double sum; + int num; + short otype; +}SDemo; + +void demo(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* tsOutput, + int* numOfOutput, short otype, short obytes, SUdfInit* buf) { + int i; + double r = 0; + SDemo *p = (SDemo *)buf->ptr; + printf("demo input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + + for(i=0;isum += r*r; + } + + p->otype = otype; + p->num += numOfRows; + + *numOfOutput=1; + + printf("demo out, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); +} + + + +void demo_finalize(char* dataOutput, int* numOfOutput, SUdfInit* buf) { + SDemo *p = (SDemo *)buf->ptr; + printf("demo_finalize dataoutput:%p, numOfOutput:%p, buf:%p\n", dataOutput, numOfOutput, buf); + if (p->otype == 6) { + *(float *)dataOutput = (float)(p->sum / p->num); + } else if (p->otype == 7) { + *(double *)dataOutput = (double)(p->sum / p->num); + } + + *numOfOutput=1; + + printf("demo finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); +} + + +int demo_init(SUdfInit* buf) { + buf->ptr = calloc(1, sizeof(SDemo)); + printf("demo init\n"); + return 0; +} + + +void demo_destroy(SUdfInit* buf) { + free(buf->ptr); + printf("demo destroy\n"); +} + diff --git a/tests/script/sh/sum_double.c b/tests/script/sh/sum_double.c index e548b89dac..631564ba62 100644 --- a/tests/script/sh/sum_double.c +++ b/tests/script/sh/sum_double.c @@ -10,12 +10,12 @@ typedef struct SUdfInit{ int const_item; /* 0 if result is independent of arguments */ } SUdfInit; -void sum_double(char* data, char type, int numOfRows, long long* ts, char* dataOutput, char* tsOutput, - int* numOfOutput, SUdfInit* buf) { +void sum_double(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* tsOutput, + int* numOfOutput, short otype, short obytes, SUdfInit* buf) { int i; int r = 0; - printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, type, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); - if (type == 4) { + printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + if (itype == 4) { r=*(int *)dataOutput; for(i=0;imaybe_null=1; buf->ptr = malloc(sizeof(int)); -- GitLab