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

Add ctypes workaround to bootstrap (fixes ctypes.util.find_library() crash) #1433

Closed
wants to merge 1 commit into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Oct 25, 2018

This adds the missing ctypes workaround for Python 3. Since it's in start.c it will apply to any sort of Python 3 used, no matter if it's Crystax or any other python install that lacks a properly patched ctypes.util.find_library() function.

While this should probably be patched in the Python 3 itself in the long run, I suggest this fix is merged some time soon because:

  • it's available & works now (at least in my test it did)
  • it is rather local and can easily be removed once it is no longer necessary
  • even if applied on top of a working ctypes.util.find_library() function, it shouldn't render it inoperable

For my app, this worked perfectly fine and allowed me to get rid of ugly import order issues related to monkey patching this in the app code. It'd be very nice to have this finally fixed upstream.

See also ticket #1337

result_buf[targetoffset] = '\\';
targetoffset++;
result_buf[targetoffset] = 'n';
} else if (inline_code_arg[sourceoffset] == '\n') {
Copy link
Member

Choose a reason for hiding this comment

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

I didn't follow the discussion, but you probably mean '\r' here, right?

Copy link
Author

Choose a reason for hiding this comment

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

Oh right. \r in paths are so rare I wasn't sure whether to put it in at all, but yea that's supposed to be \r

* occurances of \n and \r with \\n and \\r for inline string literals.
* (Unix paths can contain line breaks, so to be super safe, we need this) */
char *escape_quotes_of_inline_string(const char* inline_code_arg) {
char *result_buf = malloc(strlen(inline_code_arg) * 2 + 1);
Copy link
Member

@AndreMiras AndreMiras Oct 25, 2018

Choose a reason for hiding this comment

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

I don't see where this is freed?
Edit: never mind I found it 😄

Copy link
Author

Choose a reason for hiding this comment

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

Good point, I should really add a note to the comment above the function that it returns something that needs to be free()'d

@@ -66,6 +66,38 @@ int file_exists(const char *filename) {
return 0;
}

/* Helper function to escape all occurances of ' as \', and all
* occurances of \n and \r with \\n and \\r for inline string literals.
Copy link
Member

Choose a reason for hiding this comment

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

s/occurances/occurrences/

Copy link
Member

@inclement inclement left a comment

Choose a reason for hiding this comment

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

Could you also make sure this fails nicely if ctypes isn't available? I guess in this case the import would fail, so it should be enough to catch that and do nothing.

Edit: But other than that, great, it will be nice to not have to worry about this.

Copy link
Member

@tito tito left a comment

Choose a reason for hiding this comment

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

Hi, i understand you have a fast fix, but that the kind of stuff that nobody will look and change later. IMO, it should not be merged because you implies that all the apk requires ctypes, which is not the case. There is build where you can blacklist. A such patch make it a implicit requirement.
Plus, this code is only for ctypes, but execute for everybody at the start.
A last one, the patch you did is only for SDL2 bootstrap, while all the boostrap are impacted.

Best is to adapt your code to make it work under python3crystax and prepare it for python3 recipe that will be here in a matter of days. You may just be able to fix it using the previous patches done for Python 2!

@tito
Copy link
Member

tito commented Oct 25, 2018

Also, it has an impact on current Python 2 apps, as the patch done in the source will be applied after this one. Unsure about the implication of both running on another.

@ghost
Copy link
Author

ghost commented Oct 25, 2018

For what it's worth, I updated it to catch a possible import error (no longer requiring ctypes) and it has an #if directive to only compile for Python 3 (so it won't affect Python 2). Of course the other issues with it still apply

Edit: and yes, since this has been broken for months, at this point I'm kind of looking for a "quick fix". I mainly stepped in because it didn't seem like this was going to be addressed soon, and it's quite a pain to work with

@ghost
Copy link
Author

ghost commented Oct 26, 2018

Based on @tito 's feedback, it seems to make the most sense to close this. I am nevertheless already using this pull request for myself because I'm not interested in moving this hack back into my program, but that's my own problem for now

Edit: I'll not be making a follow up pull request for this specific issue though, unless there is some consensus on the exact way it should be done. Aimlessly playing around with various variants of this hack doesn't feel like the best use of my limited expertise for the project

@ghost
Copy link
Author

ghost commented Dec 16, 2018

Followup attempt is here: #1517

This pull request was closed.
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.

3 participants