Commit graph

607 commits

Author SHA1 Message Date
kyren b35ff5fa12 Remove out of date documentation, simpler scope lifetimes
The documentation describing it being a logic bug to access "outer" callback
handles when inside an "inner" callback is inaccurate, that was only true when
using an older design for handle values.

Also, there is no reason to have a separate 'callback lifetime, because 'scope
is already invariant and just using 'scope seems equivalent.
2018-08-05 19:02:19 -04:00
kyren e4de847395 (cargo-release) start next development iteration 0.14.2-alpha.0 2018-08-05 12:35:05 -04:00
kyren e6ca00b65c (cargo-release) version 0.14.1 2018-08-05 12:33:26 -04:00
kyren 294f3e64ca Update changelog in preparation for 0.14.1 release
I'm a bit unclear on whether bumping a dependency's minor version is considered
a semver breaking change, but without doing this everyone probably gets
deprecation warnings?
2018-08-05 12:31:33 -04:00
kyren a2615a8cbb Fix for a soundness bug around scope, don't allow callback parameters to escape
Also includes other fixes for compiletest_rs failures, and a small reorg of tests
2018-08-05 11:54:33 -04:00
kyren 8366960368 Update to failure 0.1.2, rename deprecated methods 2018-08-05 11:48:25 -04:00
kyren 2e1bdb64c0 format with up-to-date rustfmt 2018-08-05 09:51:39 -04:00
kyren e6688e1db2 very small doc fixes 2018-08-05 09:51:32 -04:00
kyren 73306d2286 Upgrade embedded Lua to 5.3.5 2018-07-18 05:29:27 -04:00
kyren 2d4f4b95c8 (cargo-release) start next development iteration 0.14.1-alpha.0 2018-06-29 01:28:28 -04:00
kyren 0cab2e25de (cargo-release) version 0.14.0 2018-06-29 01:25:15 -04:00
kyren 02bc8da203 Prepare for 0.14.0 release 2018-06-29 01:24:28 -04:00
Tony Crisci 66e49518d3 find system lua with pkg-config 2018-05-14 08:51:51 -04:00
kyren 31fa9173ae Fix #78 2018-05-02 20:05:43 -04:00
kyren 71f3dd50a1 New approach for ref types, use an auxillary thread stack
Vastly simpler and less magical than using a fixed size magical section of the
active stack, and seems to be no slower.  The only real downside is that
it *seems* extremely extremely hacky (and to be fair, it is).
2018-03-28 01:09:51 -04:00
kyren 60bfe1fb07 Nope, require failure 1.0 because otherwise it depends on backtrace automatically 2018-03-20 16:23:23 -04:00
kyren a22c23ae26 rely on failure 0.1.2 from git to get backtrace disabled by default
without relying on an unreleased 1.0 API.  Trying to get rid of the special
chucklefish hack branches in the meantime before 1.0.
2018-03-20 15:17:27 -04:00
kyren 5aa22de68e Use git dependency on failure 1.0 for right now 2018-03-20 14:07:32 -04:00
kyren 8b9ab3d031 Small renames and comments to better communicate the intention of stack checking functions 2018-03-19 17:42:10 -04:00
kyren a05f0d5cd0 Where possible, don't call to_lua / from_lua / to_lua_multi / from_lua_multi callbacks during Lua stack manipulation
This should protect against being able to trigger a stack assert in Lua.  Lua
and associated types shoul be able to assume that LUA_MINSTACK stack slots are
available on any user entry point.  In the future, we could turn check_stack
into something that only checked the Lua stack when debug_assertions is true.
2018-03-19 15:16:40 -04:00
kyren 0d5e45e800 Always ensure LUA_MINSTACK available stack spaces on callback
Otherwise, cleanly error with an appropriate stack error.  Part of an effort to
ensure that it should not be possible to trigger a stack space assert.
2018-03-19 14:36:01 -04:00
kyren 4b6809c766 Clean up some lifetime specification 2018-03-19 14:35:46 -04:00
kyren 985636267c Fix some bad potential unsafety on inner callback calls.
Since we now optionally use stack spaces for handle values, we have to be
mindful of whether our stack handle points to the stack in an outer level of
Lua "stack protection".  We now keep track of the "recursion level" of Lua
instances, and do not allow ref manipulation on "outer" Lua instances until the
inner callback has returned.  Also, update the documentation to reflect the
additional panic behavior.
2018-03-12 22:36:52 -04:00
kyren c1e1ac432c changelog fixes 2018-03-12 21:06:31 -04:00
kyren 1019ab8a3f Use rlua_ asserts instead of unreachable!, changelog updates for 0.14
0.14 will be released alongside `failure` 1.0 with a dependency update.
2018-03-12 20:36:39 -04:00
kyren c252668ba6 Fix README mention of "registry handles" 2018-03-12 18:13:22 -04:00
kyren c6c90f201c Documentation updates for new handle behavior, and some minor cleanup 2018-03-12 17:50:48 -04:00
kyren 4358034bbf Do not crash in release when accessing an AnyUserData
Also, don't bother asserting if the userdata has no metatable, just behave as
though the userdata has no type.  This should be impossible to trigger currently
without the debug library, but it is not really that useful of an assert anyway.
2018-03-12 17:48:05 -04:00
kyren f0775f4a1a Move several asserts to only be active with debug, bump alpha version number 2018-03-12 16:14:52 -04:00
kyren f79d771f1a Documentation improvements, split scope into its own module, improved tests
Also makes `Lua` and associated types !UnwindSafe and !RefUnwindSafe, which they
should be because they are intensely internally mutable.  Lua IS still panic
safe, but that doesn't mean it should be marked as UnwindSafe (as I understand
it).
2018-03-12 16:00:11 -04:00
kyren ee23f199f0 Remove stack_guard function and instead just use StackGuard directly 2018-03-12 13:13:44 -04:00
kyren 7b2f7a2932 Add a simple userdata benchmark 2018-03-12 12:48:20 -04:00
kyren 95633ce915 Merge branch 'bench' 2018-03-12 12:29:27 -04:00
kyren 601e9f4cac A lot of performance changes.
Okay, so this is kind of a mega-commit of a lot of performance related changes
to rlua, some of which are pretty complicated.

There are some small improvements here and there, but most of the benefits of
this change are from a few big changes.  The simplest big change is that there
is now `protect_lua` as well as `protect_lua_call`, which allows skipping a
lightuserdata parameter and some stack manipulation in some cases.  Second
simplest is the change to use Vec instead of VecDeque for MultiValue, and to
have MultiValue be used as a sort of "backwards-only" Vec so that ToLuaMulti /
FromLuaMulti still work correctly.

The most complex change, though, is a change to the way LuaRef works, so that
LuaRef can optionally point into the Lua stack instead of only registry values.
At state creation a set number of stack slots is reserved for the first N LuaRef
types (currently 16), and space for these are also allocated separately
allocated at callback time.  There is a huge breaking change here, which is that
now any LuaRef types MUST only be used with the Lua on which they were created,
and CANNOT be used with any other Lua callback instance.  This mostly will
affect people using LuaRef types from inside a scope callback, but hopefully in
those cases `Function::bind` will be a suitable replacement.  On the plus side,
the rules for LuaRef types are easier to state now.

There is probably more easy-ish perf on the table here, but here's the
preliminary results, based on my very limited benchmarks:

create table            time:   [314.13 ns 315.71 ns 317.44 ns]
                        change: [-36.154% -35.670% -35.205%] (p = 0.00 < 0.05)
create array 10         time:   [2.9731 us 2.9816 us 2.9901 us]
                        change: [-16.996% -16.600% -16.196%] (p = 0.00 < 0.05)
                        Performance has improved.
create string table 10  time:   [5.6904 us 5.7164 us 5.7411 us]
                        change: [-53.536% -53.309% -53.079%] (p = 0.00 < 0.05)
                        Performance has improved.
call add function 3 10  time:   [5.1134 us 5.1222 us 5.1320 us]
                        change: [-4.1095% -3.6910% -3.1781%] (p = 0.00 < 0.05)
                        Performance has improved.
call callback add 2 10  time:   [5.4408 us 5.4480 us 5.4560 us]
                        change: [-6.4203% -5.7780% -5.0013%] (p = 0.00 < 0.05)
                        Performance has improved.
call callback append 10 time:   [9.8243 us 9.8410 us 9.8586 us]
                        change: [-26.937% -26.702% -26.469%] (p = 0.00 < 0.05)
                        Performance has improved.
create registry 10      time:   [3.7005 us 3.7089 us 3.7174 us]
                        change: [-8.4965% -8.1042% -7.6926%] (p = 0.00 < 0.05)
                        Performance has improved.

I think that a lot of these benchmarks are too "easy", and most API usage is
going to be more like the 'create string table 10' benchmark, where there are a
lot of handles and tables and strings, so I think that 25%-50% improvement is a
good guess for most use cases.
2018-03-11 23:20:10 -04:00
kyren 84ee394b1d Additional benchmarks 2018-03-11 17:50:17 -04:00
kyren a5377b959f Add some more benchmarks 2018-03-11 14:26:26 -04:00
kyren 964666e11b Use criterion for benchmarking, add some simple benchmarks 2018-03-10 10:31:57 -05:00
kyren 6470b6eefc Improve documentation about __index vs regular methods 2018-03-10 10:30:17 -05:00
kyren 431f84012a Enable stack leak panic universally
This will potentially panic on Drop of a `Lua` instance, which may be an abort
if this is a double panic, but that is more desirable than such a bug being
hidden.
2018-03-08 12:36:03 -05:00
kyren d06890afc6 Simplify stack_guard / stack_err_guard
The expected change is always zero, because stack_guard / stack_err_guard are
always used at `rlua` entry / exit points.
2018-03-08 11:40:24 -05:00
kyren 10802bf70f Whoops, fix an assert that was improperly changed to an internal error 2018-03-08 11:14:02 -05:00
kyren adfeaeab49 Change strategies for handling the Lua stack during panics
Previously, on an internal panic, the Lua stack would be reset before panicking
in an attempt to make sure that such panics would not cause stack leaks or leave
the stack in an unknown state.  Now, such panic handling is done in stack_guard
and stack_err_guard instead, and this is for a few reasons:

1) The previous approach did NOT handle user triggered panics that were outside
   of `rlua`, such as a panic in a ToLua / FromLua implementation.  This is
   especially bad since most other panics would be indicative of an internal bug
   anyway, so the utility of keeping `rlua` types usable after such panics was
   questionable.  It is much more sensible to ensure that `rlua` types are
   usable after *user generated* panics.
2) Every entry point into `rlua` should be guarded by a stack_guard or
   stack_err_guard anyway, so this should restore the Lua stack on exiting back
   to user code in all cases.
3) The method of stack restoration no longer *clears* the stack, only resets it
   to what it previously was.  This allows us, potentially, to keep values at
   the beginning of the Lua stack long term and know that panics will not
   clobber them.  There may be a way of dramatically speeding up ref types by
   using a small static area at the beginning of the stack instead of only the
   registry, so this may be important.
2018-03-08 10:59:50 -05:00
kyren 6a0264169a README updates 2018-03-06 07:04:50 -05:00
kyren 6ab7f99315 Revert "Temporary fix for #71. Remove when rust #48251 is fixed in stable."
This reverts commit 5d96ddc52a.
2018-03-06 07:03:58 -05:00
kyren 1e76de1d08 Update docs to include warning about RegistryKey in callbacks 2018-03-06 06:23:04 -05:00
kyren eb154e4a9e Further safety updates of protect_lua_call
Only allow Copy result types and Fn parameter functions, do not risk dropping
anything inside function passed to lua_pcall.
2018-03-06 06:22:05 -05:00
kyren 37feaebdce Also describe how protect_lua_call functions should not hold types that Drop 2018-03-01 17:56:19 -05:00
kyren 8ac78c4585 Make some changes whose necessity became recently apparent while reading rustc 1.24.1 change notes.
So, despite staring intently at the params structure magic in protect_lua_call,
there is still a nasty bug.  In the event of an error, the return value of the
parameters structure could be dropped despite being mem::unintialized.  Of
course, the actual return values are incidentally always Copy I think, so this
wasn't an actual bug, but I've proven to myself the danger of such dark majyyks.
Just use Option and be done with it, it doesn't have to be so complicated!

Also document why there are a slew of random functions in the ffi module.
2018-03-01 17:17:18 -05:00
kyren 0e9a70e688 (cargo-release) start next development iteration 0.13.1-alpha.0 2018-02-28 14:51:50 -05:00
kyren e98d4d1827 Update changelog / cargo.toml in prep for 0.13 2018-02-28 14:44:16 -05:00