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

Cython 0.29 does not free duplicate tuples from the constant pool #2750

Closed
orivej opened this issue Dec 8, 2018 · 2 comments
Closed

Cython 0.29 does not free duplicate tuples from the constant pool #2750

orivej opened this issue Dec 8, 2018 · 2 comments

Comments

@orivej
Copy link
Contributor

orivej commented Dec 8, 2018

Since #2624 Cython compiles this:

with open('a', 'r') as f:
    f.read()

with open('a', 'r') as f:
    f.read()

to this:

static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
…
  /* "x.pyx":1
 * with open('a', 'r') as f:             # <<<<<<<<<<<<<<
 *     f.read()
 * 
 */
…
    __pyx_tuple__2 = PyTuple_Pack(3, Py_None, Py_None, Py_None);
…
  /* "x.pyx":4
 *     f.read()
 * 
 * with open('a', 'r') as f:             # <<<<<<<<<<<<<<
 *     f.read()
 */
…
  __pyx_tuple__2 = PyTuple_Pack(3, Py_None, Py_None, Py_None);
…
}

It allocates two tuples, assigns them to the same variable, and hence can later free only one of them.

@orivej orivej closed this as completed Dec 8, 2018
@orivej orivej changed the title Cython 0.29 does not free in due to deduplicated constant tuples Cython 0.29 does not free duplicate tuples from the constant pool Dec 8, 2018
@orivej orivej reopened this Dec 8, 2018
@scoder scoder added this to the 0.29.2 milestone Dec 8, 2018
@scoder
Copy link
Contributor

scoder commented Dec 8, 2018

Interesting. Yes, that's definitely a bug. It should only be allocated once.

@scoder scoder closed this as completed in cfa02c2 Dec 12, 2018
@orivej
Copy link
Contributor Author

orivej commented Dec 12, 2018

Thank you! I have checked that your commit works as expected, and ASAN reports no issues with Cython-generated code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants