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

Case #61

Merged
merged 9 commits into from
Feb 23, 2020
Merged

Case #61

merged 9 commits into from
Feb 23, 2020

Conversation

khwilliamson
Copy link
Contributor

No description provided.

Locale handling was originally not thread safe.  POSIX 2008 created a
parallel universe set of locale functions that are thread safe.  Since
Perl 5.27.9, these are by default used by perl in threaded builds.
However, some C libraries, such as X, continue to use the original
functions.  That means that those libraries don't see the locale as set
by Perl, and Perl doesn't see the locale set by these functions.

Perl does provide functions callable by XS to cope with this situation.
This commit changes Tk to use them.  The thread calling Tk is changed to
use the locale handling functions used by the X library.   As long as
only one thread in an application converts, the entire application
remains thread safe.  (If more than one thread converts, the application
becomes non-thread safe, like it was during most of Perl's history.)  It
is out of Tk's control if the application does this.  The perllocale pod
gives appropriate cautions about this.
The code as-is no longer compiles due to changes in the API required
because of security issues.  However this patch causes it to compile
back to 5.6.0 as long as ppport.h version 3.55 or later is included.

This fix is part of Perl/perl5#17024
@eserte
Copy link
Owner

eserte commented Nov 13, 2019

The PR looks incomplete, it seems (see CI check results). Is something else needed? ppport.h maybe?

I don't know what the best thing to do here is.  When ppport.h is
parsed, it starts output errors as if it thinks it is a perl file
instead of a C hdr, like "Bare word".  So this commit just skips parsing
that file.  Maybe there is a better way.  It is ok to not parse it, as
it won't introduce dependencies.
This function is backported in ppport.h to perl 6.1.  There are several
reasons to use it.  One is security; it has modern security checks that
prevent attacks that older perls are vulnerable to.  Another is
simplicity.  Doing this allows the removal of some source lines from
this file that now ppport.h takes care of.  The final reason is that
should Tk work on EBCDIC, this will automatically too.
Instead of calling the Perl function to see if something is alpha, for
example, use the macro that properly expands to do the right thing.

These macros have all been backported to 5.6.0.  Using them avoids
several bugs in the released perls.  And they are automatically valid on
EBCDIC systems, should someone try to use this on such a platform.

Also a couple of these were using the libc function.  The results of
these functions vary depending on the current locale.  Perl is generally
not supposed to be paying attention to locale, so the use of these is
wrong.
This commit changes to use our own case changing algorithm for early
perls.  This avoids locale sensitivity.  There aren't any equivalent
Perl macros, as the use of these happens only so early as to be
inconsistent with modern ones that have special handling for a few
characters which expand to multiple upon changing case.

The problems arise only of a subset of characters, and these all have
the property that the case mate is 32 ordinal positions away.
@eserte
Copy link
Owner

eserte commented Nov 25, 2019

5.28 and later looks OK now, but unfortunately it fails for older perls.
https://travis-ci.org/eserte/perl-tk/jobs/616867937#L619 looks like ppport.h expects that my_strnlen() is defined somewhere.

@toddr
Copy link

toddr commented Feb 17, 2020

@eserte is this good to merge now?

@eserte
Copy link
Owner

eserte commented Feb 17, 2020

I will do checks and hope to get a devel release of Tk until next weekend.

@eserte eserte merged commit 98fb022 into eserte:master Feb 23, 2020
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