Skip to content

Conversation

ligurio
Copy link
Owner

@ligurio ligurio commented Jul 21, 2025

The patch add tests for LuaJIT's string buffer library.

  1. https://luajit.org/ext_buffer.html

Blocked by ligurio/luzer#62

@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-string.buffer branch 3 times, most recently from d0a24a8 to 36e5ef8 Compare July 22, 2025 12:19
@ligurio ligurio requested a review from Buristan July 22, 2025 12:20
@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-string.buffer branch 2 times, most recently from 26ef371 to 0837c06 Compare July 22, 2025 14:43
Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Sergey!
Thanks for the patch!
Please consider my comments below.

@Buristan Buristan assigned ligurio and unassigned Buristan Aug 20, 2025
@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-string.buffer branch 3 times, most recently from a59da3c to ddee305 Compare August 27, 2025 19:34
@ligurio
Copy link
Owner Author

ligurio commented Aug 28, 2025

Also, updated buffer_putcdata:

--- a/tests/lapi/string_buffer_torture_test.lua
+++ b/tests/lapi/string_buffer_torture_test.lua
@@ -74,14 +74,16 @@ local function buffer_putf(self)
     self.buf:putf("%s", str)
 end
 
--- Appends the given len number of bytes from the memory pointed
+-- Appends the given `len` number of bytes from the memory pointed
 -- to by the FFI cdata object to the buffer. The object needs to
 -- be convertible to a (constant) pointer.
 -- Usage: buf = buf:putcdata(cdata, len)
 local function buffer_putcdata(self)
     local n = self.fdp:consume_integer(1, test_lib.MAX_INT)
     local cdata = ffi.new("uint8_t", n)
-    self.buf:putcdata(cdata, ffi.sizeof(cdata))
+    -- The function may throw an error "cannot convert
+    -- 'unsigned char' to 'const void *'".
+    pcall(self.buf.putcdata, self.buf, cdata, ffi.sizeof(cdata))
 end
 
 -- This method allows zero-copy consumption of a string or an FFI

@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-string.buffer branch 2 times, most recently from 9c2fbc7 to 863dc3f Compare August 28, 2025 13:28
@ligurio ligurio assigned Buristan and unassigned ligurio Aug 28, 2025
@ligurio ligurio requested a review from Buristan August 28, 2025 13:28
ligurio added a commit to ligurio/lua-c-api-corpus that referenced this pull request Aug 28, 2025
Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sergey,
Thanks for the fixes!
LGTM, after resolving the discussions above.

@Buristan Buristan assigned ligurio and unassigned Buristan Aug 28, 2025
The patch add tests for LuaJIT's string buffer library [1].

Note, as it is stated in documentation [1] this serialization
format is designed for internal use by LuaJIT applications, and
this format is explicitly not intended to be a 'public standard'
for structured data interchange across computer languages (like
JSON or MessagePack). The purpose of the proposed tests is testing
the library because other LuaJIT components relies on it and
also the proposed tests indirectly tests FFI library.

1. https://luajit.org/ext_buffer.html
@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-string.buffer branch from 863dc3f to 4198abb Compare August 29, 2025 11:48
Lua is not supported by OSS-Fuzz [1].

1. google/oss-fuzz#13782
@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-string.buffer branch from a9386f3 to f7bd674 Compare August 29, 2025 12:09
@ligurio ligurio merged commit b8233dc into master Aug 29, 2025
12 checks passed
@ligurio ligurio deleted the ligurio/gh-xxxx-lapi-string.buffer branch August 29, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants