Compare commits

..

No commits in common. "b69d3f8692b1d34f9b8616e046cdabe0d2fb67c0" and "0f20cce9c8cbda57b95f789e325686ee9c1c53f2" have entirely different histories.

4 changed files with 19 additions and 44 deletions

View File

@ -93,12 +93,10 @@ and always-present field, which must be a tag *enum*:
case CAR: void;
case LORRY: i8 axles;
case PLANE: i8 engines;
default: void;
};
There is no *case* fall-through.
Unless *default* is present, only the listed enumeration values are valid.
Any *default* must currently be empty.
All possible enumeration values must be named, and there is no *case*
fall-through.
Framing
-------

View File

@ -25,7 +25,5 @@ struct Struct {
union Onion switch (Enum tag) {
case NOTHING:
void;
default:
void;
} o;
};

View File

@ -1,6 +1,6 @@
# lxdrgen.awk: an XDR-derived code generator for network protocols.
#
# Copyright (c) 2022 - 2025, Přemysl Eric Janouch <p@janouch.name>
# Copyright (c) 2022 - 2023, Přemysl Eric Janouch <p@janouch.name>
# SPDX-License-Identifier: 0BSD
#
# Usage: env LC_ALL=C awk -f lxdrgen.awk -f lxdrgen-{c,go,mjs}.awk \
@ -218,7 +218,7 @@ function defstruct( name, d, cg) {
}
function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i,
unseen, defaulted, exhaustive) {
unseen, exhaustive) {
delete cg[0]
delete scg[0]
delete d[0]
@ -249,22 +249,9 @@ function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i,
if (!unseen[tagvalue]--)
fatal("no such value or duplicate case: " tagtype "." tagvalue)
codegen_struct_tag(tag, scg)
} else if (accept("default")) {
if (tagvalue)
codegen_union_struct(name, tagvalue, cg, scg)
expect(accept(":"))
if (defaulted)
fatal("duplicate default")
tagvalue = ""
defaulted = 1
} else if (tagvalue) {
if (readfield(d))
codegen_struct_field(d, scg)
} else if (defaulted) {
if (readfield(d))
fatal("default must not contain fields")
} else {
fatal("union fields must fall under a case")
}
@ -272,17 +259,11 @@ function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i,
if (tagvalue)
codegen_union_struct(name, tagvalue, cg, scg)
# Unseen cases are only recognized/allowed when default is present.
# Unseen cases are simply not recognized/allowed.
exhaustive = 1
for (i in unseen)
if (i && unseen[i]) {
if (defaulted) {
codegen_struct_tag(tag, scg)
codegen_union_struct(name, i, cg, scg)
} else {
exhaustive = 0
}
}
if (i && unseen[i])
exhaustive = 0
Types[name] = "union"
codegen_union(name, cg, exhaustive)

View File

@ -890,11 +890,10 @@ environ_map_serialize (struct str_map *env, struct strv *envv)
static int
spawn_protected (lua_State *L)
{
struct spawn_context *ctx = lua_touserdata (L, lua_upvalueindex (1));
luaL_checktype (L, 1, LUA_TTABLE);
struct spawn_context *ctx = lua_touserdata (L, 1);
// Step 1: Prepare process environment.
if (xlua_getfield (L, 1, "environ", LUA_TTABLE, true))
if (xlua_getfield (L, 2, "environ", LUA_TTABLE, true))
{
environ_map_update (&ctx->env, L);
lua_pop (L, 1);
@ -914,11 +913,11 @@ spawn_protected (lua_State *L)
#endif
// Step 3: Prepare process command line.
size_t argc = lua_rawlen (L, 1);
size_t argc = lua_rawlen (L, 2);
for (size_t i = 1; i <= argc; i++)
{
lua_pushinteger (L, i);
lua_rawget (L, 1);
lua_rawget (L, 2);
const char *arg = lua_tostring (L, -1);
if (!arg)
return luaL_error (L, "spawn arguments must be strings");
@ -1005,24 +1004,23 @@ spawn_protected (lua_State *L)
static int
xlua_spawn (lua_State *L)
{
lua_pushcfunction (L, xlua_error_handler);
lua_insert (L, 1);
luaL_checktype (L, 1, LUA_TTABLE);
struct spawn_context ctx = {};
lua_pushlightuserdata (L, &ctx);
lua_pushcclosure (L, spawn_protected, 1);
lua_insert (L, 2);
lua_pushcfunction (L, xlua_error_handler);
lua_pushcfunction (L, spawn_protected);
// There are way too many opportunities for Lua to throw,
// so maintain a context to clean up in one go.
ctx = spawn_context_make ();
int result = lua_pcall (L, lua_gettop (L) - 2, 1, 1);
struct spawn_context ctx = spawn_context_make ();
lua_pushlightuserdata (L, &ctx);
lua_rotate (L, 1, -1);
int result = lua_pcall (L, 2, 1, -4);
spawn_context_free (&ctx);
if (result)
return lua_error (L);
// Remove the error handler ("good programming practice").
lua_remove (L, 1);
lua_remove (L, -2);
return 1;
}