lua-users home
lua-l archive

Re: Should tiny utilities be prepackaged?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2 March 2016 at 05:37, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great Daurnimator once stated:
>>
>> If we *do* want to talk about standardisation, I'd like to take it in
>> the direction of common OS data structures being portable between
>> libraries (to pick on an example of mine from another thread:
>> sigset_t).
>
> It being this message, http://lua-users.org/lists/lua-l/2015-09/msg00331.html,
> right? I'm looking over my own code in org.conman, and I have the following
> types:
>
> sigset_t
> DIR*
> pollset__t
> struct sockaddr
> int
>
> sigset_t, DIR* and struct sockaddr are pretty straightforward (although in
> my case, I have struct sockaddr, struct sockaddr_in, struct sockaddr_in6 and
> struct sockaddr_un as a union).
OT: always allocate a struct sockaddr_storage
> The pollset__t is my own invention and
> hides the implementation of select()---on Linux, I actually use
> epoll_wait(), and for other Unix systems, poll() (and I do have a version
> based on select(), but only to be complete). The lone 'int' is wrapped for
> socket handling.
>
> But then you said:
>
>> The key thing I counted on is that we have the same **ABI** per registry
>> key. i.e. that `sigset_t *set = luaL_checkmeta(L, n, "sigset_t")` will
>> always result in a valid sigset_t pointer.
>
> First, I'm not sure if doing
>
> sigset_t *set = luaL_checkmeta(L,n,"sigset_t");
>
> buys you much; I can only think of contrived circumstances where you have
> two different libraries providing signal sets where that would be an issue.
The aim is that a user could create a sigset_t with your library; and
safely pass it to other libraries.
e.g. https://github.com/daurnimator/lua-spawn/blob/6b78e89bece7cc6a64a3bd74ba6ca255edf1eaa5/spawn/posix.c#L123
I picked sigset_t as my example, as it's used across a wide variety of
different syscalls from different "verticals" (lacking a better word).
e.g. you might want to pass a sigset_t to:
 - A classic signal handling library
 - A scheduling library (for ppoll/pselect/epoll_pwait)
 - A threading library (pthread_sigmask)
 - A spawning library (see above lua-spawn example)
> Now, by ABI, do you also mean metamethods?
No. I consider that API vs ABI
I think it's good to have alternative implementations with different
methods and utilities available.
But it sure would be great that you can pass things from one library to another

AltStyle によって変換されたページ (->オリジナル) /