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
MY_CXT macros and modules with multiple object files #6259
Comments
From @salvaCreated by @salvaThe MY_CXT family of macros to add local thread storage i.e., imagine an extension module with two files file1.xs When the extension is compiled in a non-threaded perl, "static my_cxt_t *my_cxt" in file1.xs and so as it is "static" it is not accessible To correct it, my_cxt should not be defined as static Bye, - Salva Perl Info
|
From @jkeenanOn Wed Jan 29 11:14:24 2003, salva wrote:
This post has not received a response since it was filed almost nine Is there an XS-expert who could evaluate the poster's argument? Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From @tonycozOn Thu, Jan 19, 2012 at 07:06:40PM -0800, James E Keenan via RT wrote:
It is a real (if uncommon) issue, and the solution makes sense. It could be a problem for both multiple .xs files, but also if you use Tony |
From @tseeOn 01/20/2012 05:40 AM, Tony Cook wrote:
That is my feeling, too. To wit, I think at least on every prolific XS --Steffen |
From @bulk88Glib has multiple XS files that compile to 1 dll. |
From @craigberryOn Fri, Jan 20, 2012 at 12:57 AM, Steffen Mueller <smueller@cpan.org> wrote:
I *think* I understand the question but I don't understand the % ./perl -Ilib Porting/expand-macro.pl dMY_CXT which I certainly hope returns the same answer when called from two "Note that these macros will only work together within the same source I believe it might be possible to pass thread context around with |
From @salvaHi, is nice to see that this issue is getting some attention!
I cared because I wanted my module to support both threaded and non-threaded perls. Under threaded perls, MY_CTX becomes a function call that gets the context from local thread storage and so it is accesible from any compilation unit (.xs and .c files). On the other hand, under non-threaded perls, MY_CTX becomes an alias for the C structure declared as static by the START_MY_CXT macro, and so it is not accesible outside the compilation unit where it is declared (usually the .xs file). % ./perl -Ilib Porting/expand-macro.pl dMY_CXT
I don't think so. Under non-threaded perls, aMY_CXT and pMY_CXT are defined as... # define pMY_CXT void so the non visibility issue of the static structure remains. |
From @craigberryOn Fri, Jan 20, 2012 at 11:45 AM, Salvador Fandino <sfandino@yahoo.com> wrote:
All of the thread-related macros are designed to support that, but
That is true, but it usually doesn't matter. The thread-related But you want them to do something. I'm guessing you want to store <http://perldoc.perl.org/perlxs.html#Safely-Storing-Static-Data-in-XS> I hadn't been aware the docs encouraged people to make up their own |
From @bulk88On Fri Jan 20 09:46:08 2012, salva wrote:
Wrong, threaded MY_CXT STILL uses static data. 2 different compilation units will wind up with different my_cxt_index values which will translate to 2 different "my_cxt_t *" at the end. The compilation unit WITHOUT the "MY_CXT_INIT;" (also means the compilation unit without BOOT:), will probably SEGV due to the -1. from perl.h # define START_MY_CXT static int my_cxt_index = -1;
You will have to declare an extern getter C function that does "dMY_CXT; return MY_CXT;" defined in the compilation unit with BOOT:. If your compiler is advanced enough, ( http://en.wikipedia.org/wiki/Interprocedural_optimization ) it might get auto-inlined. If on threaded MY_CXT, and if my_cxt_index is NOT declared static, there will be a disaster on ELF platforms due to my_cxt_index being an extern symbol and all XS modules, static linked or SO, that use MY_CXT, will be broken. The only solution would be for my_cxt_index to have a C symbol name compatible prefix unique to each XSPP based on "PACKAGE = " (or "MODULE = ", on a per binary/SO basis). A long long time ago (< ~5.9.3) before the more efficient current implementation ( as of http://perl5.git.perl.org/perl.git/commitdiff/f16dd614412ea67a8eb64bb09a88fccdbd9db6b6?hp=85ce96a160e902929b94338ada20cf46b265d595 ), MY_CXT_KEY that each module defined (and still defines to this day because of docs), was used as the unique per module element, instead of my_cxt_index. But we never told anything that MY_CXT_KEY has to be a valid C identifier without double quotes (it has double quotes already and you can't de-stringify), so MY_CXT_KEY can't be used as the following invalid proposal # define START_MY_CXT int MY_CXT_KEY##_my_cxt_index = -1; After reading the old MY_CXT implementation that used a HV with MY_CXT_KEY, I think your feature request was a "bug" that the new MY_CXT implementation fixed (maybe davem can chime in since he wrote it and I dont have time to search the ML archives), since on old MY_CXT, the non-threaded was static, the thread was global to module due to the HV and MY_CXT_KEY (assuming you declared MY_CXT_KEY in a compilation unit, that didn't have BOOT:). In new MY_CXT both the threaded and non-threaded, are compilation unit static. I'm leaning towards this ticket being rejected, unless someone (not me) wants to write a new GMY_CXT api (G for global) that uses symbol name unique my_cxt_index declared as extern, this GMY_CXT will still use PL_my_cxt_list as the new MY_CXT does. I was going to bring up another API design question but the theory is impossible due to a check of my_cxt_index is -1 in Perl_my_cxt_init() and my_cxt_index isn't assigned to if its != -1. Will GMY_CXT have protection against multiple runs of GMY_CXT_INIT or is that nearly impossible to create such a scenario? The only scenario I see is if someone does a "require" inside an ithread, then BOOT: of the DLL will run again and set my_cxt_index to a new value. -- |
From @iabynOn Sat, Jan 25, 2014 at 05:22:36PM -0800, bulk88 via RT wrote:
I haven't followed the thread in depth, but my understanding is that the static struct foo my_foo; wasn't thread-safe, as each thread would need its own copy of my_foo. AFAIKT, the current MY_CXT mechanism does this fine. If people want to access that "static" data from other source files, I have no objection to someone making the API non-static if they can think -- |
This is needed for using the singled-threaded model without global variables. See related issue at rt.perl.org#20609 <Perl/perl5#6259>.
This is needed for using the singled-threaded model without global variables. See related issue at rt.perl.org#20609 <Perl/perl5#6259>.
This is needed for using the singled-threaded model without global variables. See related issue at rt.perl.org#20609 <Perl/perl5#6259>.
This is needed for using the singled-threaded model without global variables. See related issue at rt.perl.org#20609 <Perl/perl5#6259>.
This is needed for using the singled-threaded model without global variables. See related issue at rt.perl.org#20609 <Perl/perl5#6259>.
Migrated from rt.perl.org#20609 (status was 'open')
Searchable as RT20609$
The text was updated successfully, but these errors were encountered: