What is the relationship between the Perl API macros MULTIPLICITY and PERL_IMPLICIT_CONTEXT?
According to perlguts:
One macro controls the major Perl build flavor:
MULTIPLICITY. TheMULTIPLICITYbuild has a C structure that packages all the interpreter state. With multiplicity-enabled perls,PERL_IMPLICIT_CONTEXTis also normally defined, and enables the support for passing in a "hidden" first argument that represents all three data structures.
(by the way, which "three data structures" are referred to here?)
I have noticed that when I build perl with usethreads:
./Configure -des -Dusethreads
the macros PERL_IMPLICIT_CONTEXT and MULTIPLICITY will both be set (defined).
Also, in embedvar.h there is a comment that may be relevant:
The following combinations of
MULTIPLICITYandPERL_IMPLICIT_CONTEXTare supported:
1) none
2) MULTIPLICITY # supported for compatibility
3) MULTIPLICITY && PERL_IMPLICIT_CONTEXTAll other combinations of these flags are errors.
only #3 is supported directly, while #2 is a special case of #3 (supported by redefining vTHX appropriately).
So, when writing XS code is there any difference in writing
#ifdef MULTIPLICITYversus writing#ifdef PERL_IMPLICIT_CONTEXT?What is the history behind the two variables? It seems like they today could be reduced to a single. For example, what would happen if all occurences of
MULTIPLICITYwas replaced withPERL_IMPLICIT_CONTEXTin the perl source? What would it break?
Here is what I have found so far. Running
sh Configure -descreates the headerconfig.h. This header file will:define
USE_ITHREADSif and only ifConfigurewas given the flag-Dusethreads, e.g.:define
MULTIPLICITYif and only ifConfigurewas given the flag-Dusemultiplicity:Setting
MULTIPLICITYthroughccflagswill not setMULTIPLICITYinconfig.h, e.g.:Configurehas no-Dflag forPERL_IMPLICIT_CONTEXT, and defining it throughccflagswill not define it inconfig.h.The generated
config.hheader is#included byperl.h. Note, that the latter header is also usually included by Perl XS extension files (.xs-files). At line 59 inperl.hwe have:This means that:
if
-Dusethreadsis given,USE_ITHREADS,MULTIPLICITY, andPERL_IMPLICIT_CONTEXTwill all be defined.if
-Dusemultiplicityis given,MULTIPLICITYandPERL_IMPLICIT_CONTEXTwill be defined, whereasUSE_ITHREADSwill be undefined.if none of
-Dusethreadsor-Dusemultiplicityis givenUSE_ITHREADS,MULTIPLICITY, andPERL_IMPLICIT_CONTEXTwill all be undefined.it is not possible to have
MULTIPLICITYdefined andPERL_IMPLICIT_CONTEXTundefined (unless one usesccflags, but then this will only be during the perl build. XS extension modules that includeperl.hwill not see this)So extension modules can usually assume that either:
MULTIPLICITYandPERL_IMPLICIT_CONTEXTare both defined, orMULTIPLICITYandPERL_IMPLICIT_CONTEXTare both undefined.