Skip to content

Conversation

@oscarbenjamin
Copy link
Collaborator

Follows gh-291

Comment on lines 21 to 27
cdef char * s
if COEFF_IS_MPZ(x[0]):
s = fmpz_get_str(NULL, 16, x)
v = int(str_from_chars(s), 16)
v = int(bytes(s).decode('ascii'), 16)
libc.stdlib.free(s)
return v
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure why this change seems to have fixed the problem. The function is defined as:

   cdef inline str_from_chars(s):
         return bytes(s).decode('ascii')

However actually inlining the function here prevents the crash that is only seen on Windows when building with windows-2022 or windows-2025 but not if built on windows-2019... (The crash happens when running on any Windows version but not if the binaries were built on windows-2019.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I was tricked. This change does not fix the problem. I fell for the classic printing things makes the segfault go away confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe this should use flint_free?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or maybe it didn't even work then. I might have looked at the wrong CI output. It is late and there are too many jobs to check...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe PyLong_FromString should be used:
https://docs.python.org/3/c-api/long.html#c.PyLong_FromString

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems that using flint_free fixes this although now there is a crash somewhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the observed problems were fixed by using flint_free when using fmpz_get_str. I'm not sure why this issue appears now and not before.

It is probably worth reviewing all other uses of free to see if they should be flint_free...

@oscarbenjamin oscarbenjamin merged commit d0a3be8 into flintlib:main Jun 27, 2025
66 checks passed
@oscarbenjamin oscarbenjamin deleted the pr_windows_2022_2nd branch June 27, 2025 22:44
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.

1 participant