Coder Social home page Coder Social logo

Comments (4)

CheyiLin avatar CheyiLin commented on September 22, 2024

是 i386 or x86_64 平台?能否提供錯誤訊息?

lz4.lua:122 這段 dest_buf + hdr_len 我實測是沒有問題的
可以看一下 Travis CI 的頁面,LuaJIT 2.0.4 與 2.1 都正常

關於 dest_bufcdata 的算數計算,我是參考 FFI Semantics - Arithmetic on cdata objects

from ljlz4.

huangwei1024 avatar huangwei1024 commented on September 22, 2024

是i386
我的应用场景没有使用dll或so,而是将lz4直接以static lib形式嵌入宿主程序
然后导出C函数给Lua使用
这是该函数代码

static int compress(lua_State *L)
{
    char* dest = (char*)lua_topointer(L, 1);
    int destOff = lua_tonumber(L, 2);
    int destLen = lua_tonumber(L, 3);
    const char* src = lua_tostring(L, 4);
    int srcLen = lua_tonumber(L, 5);

    int cpLen = LZ4_compressBound(srcLen);
    if (cpLen > destLen)
    {
        lua_pushnumber(L, -1);
        return 1;
    }

    cpLen = LZ4_compress_limitedOutput(src, dest + destOff, srcLen, destLen);
    lua_pushnumber(L, cpLen);
    return 1;
}

我简单测试了下,每次dest_buf + hdr_len似乎都会产生的新的cdata,导致压缩数据存放到其它地址,而dest_buf原地址上除了lz4_hdr_t数据,后面的全为0。
我不清楚lz4.so是否做过相应处理,现在我传入destOff是为了能在C中进行正确的指针偏移。
对FFI底层实现不大清楚,求教~

from ljlz4.

CheyiLin avatar CheyiLin commented on September 22, 2024

看來你是混用 Lua C API 與 LuaJIT FFI 了,LuaJIT 作者 Mike 有提示過不能這樣用
供你參考 Re: Accessing ctype of FFI cdata from the Lua C API

from ljlz4.

huangwei1024 avatar huangwei1024 commented on September 22, 2024

非常感谢,看来是混用的问题

from ljlz4.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.