-
Notifications
You must be signed in to change notification settings - Fork 36
WIP: Attempt to fix quasi-random UTF-8 conversion failures/seg faults #80
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
base: master
Are you sure you want to change the base?
Conversation
…match order in tempo2.h file
…nto update_structures
|
@vallis @vhaasteren @jellis18 @stevertaylor - sorry for spam tagging you, but I'd appreciate if someone else took a look at this PR. I'm trying to fix the occasional error see in, e.g., #49, which I thought might be down to structure layout mismatches. So, I've tried to rearrange the definition of the Along with that, I've added the ability for the test suite to run on a range of tempo2 versions, which will hopefully catch more issues. Currently, not all tests pass, e.g., https://github.com/vallis/libstempo/actions/runs/14718363847/job/41306896014?pr=80#step:8:77, where it always seems to be this test line that fails (although it seems to do this quasi-randomly and often will pass if the test is re-run!), which I expect is still the same failure, i.e., a utf-8 decode issue, as in #49. |
|
Note that (currently) all jobs pass, but only after I manually re-ran the failed jobs. This shows that the failure is quasi-random. Probably down to whether a copied string contains some invalid memory or not. It would be useful to come up with a way to make the problem reproducible so that an actual solution can be found. |
|
Good job modifying the structs @mattpitkin . Those # what is the default encoding here?
string = lambda s: s.decode()
string_dtype = 'U'That's at the top of the file of def string(buf):
# take bytes up to the first '\0'
raw = bytes(buf).split(b'\0', 1)[0]
# try UTF-8, else fall back to Latin-1 (one-to-one byte→codepoint)
try:
return raw.decode('utf-8')
except UnicodeDecodeError:
return raw.decode('latin-1')I am not sure how that can create randomness though, but how would an encoding error be random? My first guess would have also been to double-check the memory layout like you have done. Unfortunately I am not familiar enough with the underlying workings to be of more help, sorry! |
|
@vhaasteren I think that might be part of the issue, so it's worth trying ChatGPT's suggestion. I think a bigger culprit is likely to be the use of
with the suggestion to replace the # Replace the sprintf line with this:
cdef const char* parfile_c_str = parfile_bytes # Cython creates a temp C string
# Use strcpy now that length is checked and source is guaranteed null-terminated
strcpy(parFile, parfile_c_str) |
|
Oh, that's a really good suggestion! Overtall, the random crashes of tempo2/libstempo are a major headache, and it actually prevents people (including myself!) to use it. I have found that the segfaults have increased in frequency when running tempo2 on my M1 macbook, either natively or emulated under rosetta. Any adjustments that address these crashes are very welcome. |
|
So @mattpitkin, @vallis , while this WIP is a good avenue, I decided to go with 'the other' workaround in the meantime: sandboxing! For me that already is a big win. I put it in #81 , for now as a draft. |
This reverts commit 21bf4ed.
This PR attempts to better match the ordering of members of the
observationandpulsarstructures within tempo2.h, in case there are memory mismatch issues.