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

modules: Add newlen == 0 handling to RM_StringTruncate (#3717) #3718

Merged
merged 7 commits into from Jun 22, 2021

Conversation

neomantra
Copy link
Contributor

@neomantra neomantra commented Dec 29, 2016

Previously, passing 0 for newlen would not truncate the string at all.
This adds handling of this case, freeing the old string and creating a new empty string.

Other changes:

  • Move src/modules/testmodule.c to tests/modules/basics.c
  • Introduce that basic test into the test suite
  • Add tests to cover StringTruncate
  • Add test-modules build target for the main makefile
  • Extend distclean build target to clean modules too

neomantra added a commit to neomantra/redex that referenced this pull request Jul 17, 2017
Since Redis 4 was released without redis/redis#3718
this change was required to make CHOP work properly with Redis 4.0.0.

Now all tests pass on stock Redis 4.0.0.
itamarhaber
itamarhaber previously approved these changes Jun 11, 2018
src/modules/testmodule.c Show resolved Hide resolved
@itamarhaber
Copy link
Member

@neomantra thanks for this fix - it looks good.

@antirez - please consider merging.

Copy link
Contributor

@artix75 artix75 left a comment

Choose a reason for hiding this comment

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

It looks good to me.

@neomantra
Copy link
Contributor Author

I just rebased this branch to the latest. Any chance to make it into 5.0?

@neomantra neomantra force-pushed the StringTruncate_newLenZero branch 2 times, most recently from 7602dc0 to 8aed0ee Compare May 29, 2019 16:33
@neomantra
Copy link
Contributor Author

@antirez @itamarhaber I saw the Tweet about "[Refactoring...] requires a lot of care, and a lot of tests." I remembered that I had added some unmerged module test tooling in this PR and also remembered that the workflow for testing modules could use some improvement. So I put some effort into this last commit 9c7f3d7 (improve module build/test tooling).

If you like this and would prefer it on its own branch (without the StringTruncate bugfix), I can do that.

Previously, passing 0 for newlen would not truncate the string at all.

This adds handling of this case, freeing the old string and creating a new empty string.
…XXXReply functions

 * adds TEST.STRING.TRUNCATE and includes it in TEST.IT

   This test fails unless issue redis#3717 is resolved

 * add handling for ERROR replies in TestAssertStringReply and TestAssertIntegerReply

   Previously these TestAssert functions would output something like,
    `<test> Unexpected reply type 1`
   rather than emitting the error message of what was wrong.
 * add `test-module` make target

 * `make distclean` now cleans module src/test directories

 * `runtest-moduleapi` now builds and exercises `testmodule`

 * add `clean` target for `commandfilter`

 * add `.gitignore` for `commandfilter`

 * typo "SOME TEST NOT PASSED!" -> "SOME TEST DID NOT PASS!"
zuiderkwast
zuiderkwast previously approved these changes Feb 4, 2021
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

Merge?

src/modules/testmodule.c Show resolved Hide resolved
tests/modules/.gitignore Outdated Show resolved Hide resolved
src/Makefile Show resolved Hide resolved
@neomantra
Copy link
Contributor Author

If I take the time to rebase this, will you actually merge it?

I've rebased it 4 times already over 5 years -- it is an obvious bug in a public modules interface.

@zuiderkwast zuiderkwast added the state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten label Jun 9, 2021
@zuiderkwast
Copy link
Contributor

This one must have been forgotten. @redis/core-team anyone have a look?

@madolson
Copy link
Contributor

madolson commented Jun 21, 2021

Oh sad, it was forgotten. @neomantra Would you mind doing a rebase of the code. I looked through the code and thumbs'd up a couple of other comments that still weren't addressed. Sorry for dropping this!

src/module.c Outdated Show resolved Hide resolved
tests/unit/moduleapi/commandfilter.tcl Outdated Show resolved Hide resolved
tests/unit/moduleapi/testmodule.tcl Outdated Show resolved Hide resolved
@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Jun 22, 2021
@oranagra oranagra dismissed stale reviews from zuiderkwast and itamarhaber via f0097eb June 22, 2021 05:52
@oranagra oranagra merged commit 1ccf2ca into redis:unstable Jun 22, 2021
Copy link
Contributor

@yoav-steinberg yoav-steinberg left a comment

Choose a reason for hiding this comment

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

lgtm

oranagra added a commit to oranagra/redis that referenced this pull request Jun 22, 2021
- Introduce a new sdssubstr api as a building block for sdsrange.
  The API of sdsrange is many times hard to work with and also has
  corner case that cause bugs. sdsrange is easy to work with and also
  simplifies the implementation of sdsrange.
- Revert the fix to RM_StringTruncate and just use sdssubstr instead of
  sdsrange.
- Solve valgrind warnings from the new tests introduced by the previous
  PR.
@oranagra
Copy link
Member

This is not the first time i see the bad API of sdsrange introduce bugs.
i think it's about time to introduce sdssubstr that will be easier to use rather than the change this PR makes to RM_StringTruncate.
see: #9125

@oranagra oranagra added this to To do in 6.2 Backport via automation Jun 22, 2021
oranagra added a commit that referenced this pull request Jun 22, 2021
- Introduce a new sdssubstr api as a building block for sdsrange.
  The API of sdsrange is many times hard to work with and also has
  corner case that cause bugs. sdsrange is easy to work with and also
  simplifies the implementation of sdsrange.
- Revert the fix to RM_StringTruncate and just use sdssubstr instead of
  sdsrange.
- Solve valgrind warnings from the new tests introduced by the previous
  PR.
x77a1 pushed a commit to x77a1/redis that referenced this pull request Jul 11, 2021
…edis#3718)

Previously, passing 0 for newlen would not truncate the string at all.
This adds handling of this case, freeing the old string and creating a new empty string.

Other changes:
- Move `src/modules/testmodule.c` to `tests/modules/basics.c`
- Introduce that basic test into the test suite
- Add tests to cover StringTruncate
- Add `test-modules` build target for the main makefile
- Extend `distclean` build target to clean modules too
x77a1 pushed a commit to x77a1/redis that referenced this pull request Jul 11, 2021
- Introduce a new sdssubstr api as a building block for sdsrange.
  The API of sdsrange is many times hard to work with and also has
  corner case that cause bugs. sdsrange is easy to work with and also
  simplifies the implementation of sdsrange.
- Revert the fix to RM_StringTruncate and just use sdssubstr instead of
  sdsrange.
- Solve valgrind warnings from the new tests introduced by the previous
  PR.
oranagra pushed a commit that referenced this pull request Jul 19, 2021
src/modules make failed. As in #3718 testmodule.c was removed. But the makefile was not updated
oranagra pushed a commit to oranagra/redis that referenced this pull request Jul 20, 2021
…edis#3718)

Previously, passing 0 for newlen would not truncate the string at all.
This adds handling of this case, freeing the old string and creating a new empty string.

Other changes:
- Move `src/modules/testmodule.c` to `tests/modules/basics.c`
- Introduce that basic test into the test suite
- Add tests to cover StringTruncate
- Add `test-modules` build target for the main makefile
- Extend `distclean` build target to clean modules too

(cherry picked from commit 1ccf2ca)
oranagra added a commit to oranagra/redis that referenced this pull request Jul 20, 2021
- Introduce a new sdssubstr api as a building block for sdsrange.
  The API of sdsrange is many times hard to work with and also has
  corner case that cause bugs. sdsrange is easy to work with and also
  simplifies the implementation of sdsrange.
- Revert the fix to RM_StringTruncate and just use sdssubstr instead of
  sdsrange.
- Solve valgrind warnings from the new tests introduced by the previous
  PR.

(cherry picked from commit ae418ec)
oranagra pushed a commit to oranagra/redis that referenced this pull request Jul 20, 2021
src/modules make failed. As in redis#3718 testmodule.c was removed. But the makefile was not updated

(cherry picked from commit d54c908)
@oranagra oranagra mentioned this pull request Jul 21, 2021
oranagra pushed a commit that referenced this pull request Jul 21, 2021
Previously, passing 0 for newlen would not truncate the string at all.
This adds handling of this case, freeing the old string and creating a new empty string.

Other changes:
- Move `src/modules/testmodule.c` to `tests/modules/basics.c`
- Introduce that basic test into the test suite
- Add tests to cover StringTruncate
- Add `test-modules` build target for the main makefile
- Extend `distclean` build target to clean modules too

(cherry picked from commit 1ccf2ca)
oranagra added a commit that referenced this pull request Jul 21, 2021
- Introduce a new sdssubstr api as a building block for sdsrange.
  The API of sdsrange is many times hard to work with and also has
  corner case that cause bugs. sdsrange is easy to work with and also
  simplifies the implementation of sdsrange.
- Revert the fix to RM_StringTruncate and just use sdssubstr instead of
  sdsrange.
- Solve valgrind warnings from the new tests introduced by the previous
  PR.

(cherry picked from commit ae418ec)
oranagra pushed a commit that referenced this pull request Jul 21, 2021
src/modules make failed. As in #3718 testmodule.c was removed. But the makefile was not updated

(cherry picked from commit d54c908)
@oranagra oranagra moved this from To Do to Done in 6.2 Backport Jul 22, 2021
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
…edis#3718)

Previously, passing 0 for newlen would not truncate the string at all.
This adds handling of this case, freeing the old string and creating a new empty string.

Other changes:
- Move `src/modules/testmodule.c` to `tests/modules/basics.c`
- Introduce that basic test into the test suite
- Add tests to cover StringTruncate
- Add `test-modules` build target for the main makefile
- Extend `distclean` build target to clean modules too
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
- Introduce a new sdssubstr api as a building block for sdsrange.
  The API of sdsrange is many times hard to work with and also has
  corner case that cause bugs. sdsrange is easy to work with and also
  simplifies the implementation of sdsrange.
- Revert the fix to RM_StringTruncate and just use sdssubstr instead of
  sdsrange.
- Solve valgrind warnings from the new tests introduced by the previous
  PR.
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
src/modules make failed. As in redis#3718 testmodule.c was removed. But the makefile was not updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes indication that this issue needs to be mentioned in the release notes state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten
Projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants