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

Use LibC.malloc instead of GC.malloc for LibPCRE allocations #12456

Merged
merged 3 commits into from
Sep 14, 2022

Conversation

lbguilherme
Copy link
Contributor

Follow-up on #12451.

This makes the memory management os LibPCRE manual for the stdlib. So any internal allocations are made with the system allocator, leaving less memory being managed by the GC.

Public interface is unchanged.

As an adicional benefit: libpcre doesn't need to be linked anymore if the program doesn't create any regex!

@HertzDevil
Copy link
Contributor

pcre_malloc and pcre_free could still be assigned by external programs, even if they default to LibC.malloc and LibC.free, in which case the allocator (pcre_malloc called by pcre_compile) and the deallocator (LibC.free) in Crystal may not match. So the appropriate fix is to expose pcre_free as usual and then call it directly without assigning to it.

@straight-shoota straight-shoota added this to the 1.6.0 milestone Sep 9, 2022
@straight-shoota straight-shoota merged commit 6a32cde into crystal-lang:master Sep 14, 2022
@HertzDevil
Copy link
Contributor

It seems the CI failure here is real. There seems to be some kind of infinite recursion during a GC cycle. No idea why.

@asterite
Copy link
Member

We should probably undo this and the other one for 1.6

@straight-shoota
Copy link
Member

It's only a problem in the interpreter, right? So we could just undo it there.

@asterite
Copy link
Member

Aah... maybe interpreting finalize requires allocating memory for some reason and then it crashes.

@asterite
Copy link
Member

I think the problematic line is this:

LibPCRE.free.call @re.as(Void*)

It seems that if you print what's LibPCRE.free in interpreted mode it shows up as a closure, which is incorrect.

I'll see if I can fix this.

@asterite
Copy link
Member

I don't think I'll be able to fix this for 1.6 so it might be better to either undo this for 1.6, or conditionally do this depending on whether this runs in interpreted mode or not.

straight-shoota added a commit to straight-shoota/crystal that referenced this pull request Sep 18, 2022
This is a workaround for an interpreter bug (crystal-lang#12495) and basically
restores the status before crystal-lang#12456.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants