Skip to content

Re module #591

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

Merged
merged 2 commits into from
Mar 6, 2019
Merged

Re module #591

merged 2 commits into from
Mar 6, 2019

Conversation

windelbouwman
Copy link
Contributor

No description provided.

pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
let match_type = py_class!(ctx, "Match", ctx.object(), {});
/// Take a found regular expression and convert it to proper match object.
fn create_match(vm: &mut VirtualMachine, match_value: Match<'static>) -> PyResult {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rust expertise required on this line. I added 'static here, but is this even required / legal? The code refuses to compile as I want. I want to add Match inside a Box, but Match has a non-static lifetime :(.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason rust won't compile this is because it would lead to a use-after-free - the string being passed to Regex::find is borrowed by the Match that it returns, but will be dropped at the end of do_search. Rust can tell that the Match is going to outlive the search_text string, and thus point to invalid memory, so it rejects the code.

One solution would be to create your own match type for the payload and copy what you need out of the regex match.

I hope this is helpful!

@codecov-io
Copy link

Codecov Report

Merging #591 into master will increase coverage by 3.19%.
The diff coverage is 39.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #591      +/-   ##
==========================================
+ Coverage   41.25%   44.45%   +3.19%     
==========================================
  Files          75       75              
  Lines       17096    17710     +614     
  Branches     4538     4964     +426     
==========================================
+ Hits         7053     7873     +820     
+ Misses       8005     7770     -235     
- Partials     2038     2067      +29
Impacted Files Coverage Δ
vm/src/stdlib/re.rs 37.5% <39.39%> (-10.78%) ⬇️
parser/src/ast.rs 17.44% <0%> (-5.26%) ⬇️
parser/src/lexer.rs 53.8% <0%> (-3.2%) ⬇️
vm/src/obj/objint.rs 47.34% <0%> (+0.17%) ⬆️
vm/src/vm.rs 54.55% <0%> (+0.27%) ⬆️
vm/src/pyobject.rs 63.76% <0%> (+3.34%) ⬆️
vm/src/function.rs 72.5% <0%> (+5.83%) ⬆️
vm/src/frame.rs 62.69% <0%> (+15.52%) ⬆️
vm/src/obj/objstr.rs 53.23% <0%> (+15.68%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ba25ef...f3791a3. Read the comment docs.

@cthulahoops cthulahoops merged commit 03b4199 into master Mar 6, 2019
@windelbouwman windelbouwman deleted the re_module branch March 23, 2019 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants