-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: preserve 'empty_array_mt' behavior upon multiple loadings of the module #16
Conversation
module Prior to this fix, when the module would be loaded several times (by-passing `package.loaded`), the `lua_cjson_new` function would override the `empty_array_mt` table in the registry with a new one. Comparison for equality between those tables would then fail, and the behavior would be broken. This was discovered after loading `cjson` *and* `cjson.safe` in the same application, resulting in two calls to `lua_cjson_new`.
@doujiang24 Would you be interested in reviewing this change as well? Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thibaultcha Sure, Nice Job 👍
* If multiple calls to lua_cjson_new() are made, | ||
* this prevents overriding the table at the given | ||
* registry's index with a new one. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add lua_pop(L, 1)
is better here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To pop the nil
value from the stack? Yes, indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed :)
empty_array_mt table in the registry
Merged with minor edits in the commit log message. Thanks! |
Thanks! @doujiang24 Thanks for taking a look! |
Use a workaround until openresty/lua-cjson#16 is included in an OpenResty formal release.
Since openresty/lua-cjson#16 has been merged and Openresty we use includes this fix, we can get rid off the workarounds in our code.
Since openresty/lua-cjson#16 has been merged in OpenResty, we can get rid of the workarounds in place for this bug. From #3013
Prior to this fix, when the module would be loaded several times
(by-passing the
package.loaded
lookup), thelua_cjson_new()
function wouldoverride the
empty_array_mt
table in the Lua Registry with a new one.Comparison for equality between those tables would then fail, and the
encoding behavior would be broken.
This was discovered after loading
cjson
andcjson.safe
in the sameapplication, resulting in two calls to
lua_cjson_new()
:DChangelog: