Software /
code /
prosody
Annotate
util-src/table.c @ 12579:ca6a43fe0231 0.12
util.jsonschema: Fix validation to not assume presence of "type" field
MattJ reported a curious issue where validation did not work as
expected. Primarily that the "type" field was expected to be mandatory,
and thus leaving it out would result in no checks being performed.
This was likely caused by misreading during initial development.
Spent some time testing against
https://github.com/json-schema-org/JSON-Schema-Test-Suite.git and
discovered a multitude of issues, far too many to bother splitting into
separate commits.
More than half of them fail. Many because of features not implemented,
which have been marked NYI. For example, some require deep comparisons
e.g. when objects or arrays are present in enums fields.
Some because of quirks with how Lua differs from JavaScript, e.g. no
distinct array or object types. Tests involving fractional floating
point numbers. We're definitely not going to follow references to remote
resources. Or deal with UTF-16 sillyness. One test asserted that 1.0 is
an integer, where Lua 5.3+ will disagree.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 08 Jul 2022 14:38:23 +0200 |
parent | 7969:1c6a07606309 |
child | 12402:8deb401a21f6 |
rev | line source |
---|---|
6610
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 #include <lua.h> |
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 #include <lauxlib.h> |
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7835
diff
changeset
|
4 static int Lcreate_table(lua_State *L) { |
6610
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); |
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 return 1; |
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 } |
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7835
diff
changeset
|
9 static int Lpack(lua_State *L) { |
7519
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
10 unsigned int n_args = lua_gettop(L); |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
11 lua_createtable(L, n_args, 1); |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
12 lua_insert(L, 1); |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7835
diff
changeset
|
13 |
7936
582bfb39337f
Backed out changeset a3a4ed0d34f4 C99 is ok
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
14 for(int arg = n_args; arg >= 1; arg--) { |
7519
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
15 lua_rawseti(L, 1, arg); |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
16 } |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7835
diff
changeset
|
17 |
7519
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
18 lua_pushinteger(L, n_args); |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
19 lua_setfield(L, -2, "n"); |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
20 return 1; |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
21 } |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
22 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7835
diff
changeset
|
23 int luaopen_util_table(lua_State *L) { |
7818
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
7538
diff
changeset
|
24 #if (LUA_VERSION_NUM > 501) |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
7538
diff
changeset
|
25 luaL_checkversion(L); |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
7538
diff
changeset
|
26 #endif |
7969
1c6a07606309
util-src: Specify size of various tables to be allocated
Kim Alvefur <zash@zash.se>
parents:
7936
diff
changeset
|
27 lua_createtable(L, 0, 2); |
6610
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 lua_pushcfunction(L, Lcreate_table); |
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 lua_setfield(L, -2, "create"); |
7519
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
30 lua_pushcfunction(L, Lpack); |
d278a770eddc
util.table: Add pack() function (this is already available in Lua 5.2+)
Matthew Wild <mwild1@gmail.com>
parents:
6615
diff
changeset
|
31 lua_setfield(L, -2, "pack"); |
6610
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 return 1; |
7c4cf87f4dff
util.table, Makefile: New C module that allows pre-allocation of tables to improve performance and decrease memory fragmentation
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 } |