Skip to content

Conversation

@Physic69
Copy link
Contributor

@Physic69 Physic69 commented Dec 9, 2025

add senddata, receivedata methods that operate directly on luadata buffer memory without Lua string copies.

@Physic69 Physic69 force-pushed the comeback branch 3 times, most recently from 08d3ffd to 1cb07fa Compare December 11, 2025 19:20
@Physic69 Physic69 force-pushed the comeback branch 3 times, most recently from 256df79 to 3e45962 Compare December 11, 2025 21:34
@Physic69 Physic69 force-pushed the comeback branch 2 times, most recently from a0f46d6 to 4bcb6e6 Compare December 12, 2025 18:26
@Physic69 Physic69 force-pushed the comeback branch 3 times, most recently from 90c2ea5 to 44f99db Compare December 14, 2025 21:58
lib/luadata.h Outdated
return (void *)(data->ptr + offset);
}

static inline void *luadata_checkrange(lua_State *L, int idata, int ioffset, int ilen, size_t *len_out)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should pass just one index on the stack and assume them sequential.. like a CFunction..

module_exit(luadata_exit);
MODULE_LICENSE("Dual MIT/GPL");
MODULE_AUTHOR("Lourival Vieira Neto <lourival.neto@ring-0.io>");

Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

lib/luadata.h Outdated
return (void *)(data->ptr + offset);
}

static inline void *luadata_checkrange(lua_State *L, int idata, int ioffset, int ilen, size_t *len_out)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not fond of calling this function checkrange because it's too similar to checkbounds.. I would call it something like checkpointer (if we can't figure a better name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getrange..How does it sound?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be check* to be clear it can raise an error and validate the args..

Copy link
Contributor

Choose a reason for hiding this comment

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

checkbuffer will do as well.. I think.. couldn't figure anything better.. heh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

checkbuffer works for me. Sounds good 👍

lib/luasocket.c Outdated
vec.iov_base = (void *)luaL_buffinitsize(L, &B, len);
}
else {
data = luadata_check(L, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need this line anymore, right?

lib/luadata.h Outdated
return (void *)(data->ptr + offset);
}

static inline void *luadata_checkrange(lua_State *L, int idata, int ioffset, int ilen, size_t *len_out)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this need to be an inline.. I would have a regular function and export its prototype here, keeping the struct and checkbounds on the .c file

lib/luasocket.c Outdated

vec.iov_base = (void *)luaL_buffinitsize(L, &B, len);
vec.iov_len = len;
if (t2 != LUA_TUSERDATA && t2 != LUA_TLIGHTUSERDATA) {
Copy link
Contributor

Choose a reason for hiding this comment

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

that's weird.. why that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix it, i thought( if not data) use string, else data. will make it similar like send function

Copy link
Contributor

Choose a reason for hiding this comment

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

but why checking for light userdata? I would just use the same pattern you used on send() indeed..

Copy link
Contributor

Choose a reason for hiding this comment

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

then, you can use type the type as a flag to take the decision later on to pushbuffer

lib/luasocket.c Outdated
Comment on lines 280 to 281
flags = luaL_optinteger(L, ixopt, 0);
from = lua_toboolean(L, ixopt + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

as we are using C99, let's declare these vars in-here..

Copy link
Contributor

Choose a reason for hiding this comment

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

.. removing their declaration from the beginning of the function block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought we were following C89, so i made the early declerations. Will fix it up

@Physic69 Physic69 force-pushed the comeback branch 2 times, most recently from 93a333a to 401e160 Compare December 15, 2025 16:04
@Physic69 Physic69 marked this pull request as ready for review December 15, 2025 16:06
@Physic69 Physic69 marked this pull request as draft December 15, 2025 19:58
#define LUADATA_OPT_FREE 0x02
#define LUADATA_OPT_KEEP 0x80


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

please review your patch regarding things like this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants