Skip to content
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

Make the CRON module work reliably #2153

Merged
merged 1 commit into from
Oct 30, 2017
Merged

Make the CRON module work reliably #2153

merged 1 commit into from
Oct 30, 2017

Conversation

pjsg
Copy link
Member

@pjsg pjsg commented Oct 29, 2017

Fixes #1924.

  • This PR is for the dev branch rather than for master.
  • This PR is compliant with the other contributing guidelines as well (if not, please describe why).
  • I have thoroughly tested my contribution.

There were two bugs -- the memmove moved the wrong number of bytes (which could have led to a crash) and the lua_touserdata calls were trying to get the pointer from the wrong stack location. It is (somewhat) of a miracle that it worked at all!

@@ -141,7 +141,7 @@ static int lcron_unschedule(lua_State *L) {
size_t i = lcron_findindex(L, ud);
if (i == -1) return 0;
luaL_unref(L, LUA_REGISTRYINDEX, cronent_list[i]);
memmove(cronent_list + i, cronent_list + i + 1, sizeof(int) * cronent_count - i - 1);
memmove(cronent_list + i, cronent_list + i + 1, sizeof(int) * (cronent_count - i - 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers, good catch! Dumb mistake from me...

@@ -104,7 +104,7 @@ static size_t lcron_findindex(lua_State *L, cronent_ud_t *ud) {
size_t i;
for (i = 0; i < cronent_count; i++) {
lua_rawgeti(L, LUA_REGISTRYINDEX, cronent_list[i]);
eud = lua_touserdata(L, 1);
eud = lua_touserdata(L, -1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what it is... But you definitely know inner mechanics better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rawgeti pushes the integer onto the stack. This is element -1. Element 1 is the first argument in the current lua stackframe.

@marcelstoer marcelstoer added this to the 2.1 follow-up II milestone Oct 30, 2017
@marcelstoer marcelstoer merged commit 0f77162 into nodemcu:dev Oct 30, 2017
crasu pushed a commit to crasu/nodemcu-firmware that referenced this pull request Jan 11, 2018
dnc40085 pushed a commit to dnc40085/nodemcu-firmware that referenced this pull request Mar 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants