[英]The relationship between MULTIPLICITY and PERL_IMPLICIT_CONTEXT
What is the relationship between the Perl API macros MULTIPLICITY
and PERL_IMPLICIT_CONTEXT
? Perl API宏MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
之间是什么关系?
According to perlguts
: 根据perlguts
:
One macro controls the major Perl build flavor:
MULTIPLICITY
. 一个宏控制着主要的Perl构建风格:MULTIPLICITY
。 TheMULTIPLICITY
build has a C structure that packages all the interpreter state.MULTIPLICITY
构建具有一个C结构,该结构打包了所有解释器状态。 With multiplicity-enabled perls,PERL_IMPLICIT_CONTEXT
is also normally defined, and enables the support for passing in a "hidden" first argument that represents all three data structures. 对于启用多重性的perls,通常也会定义PERL_IMPLICIT_CONTEXT
,并启用对传递表示所有三个数据结构的“隐藏”第一个参数的支持。
(by the way, which "three data structures" are referred to here?) (顺便说一下,这里指的是“三个数据结构” ?)
I have noticed that when I build perl with usethreads
: 我注意到当我使用usethreads
构建perl时:
./Configure -des -Dusethreads
the macros PERL_IMPLICIT_CONTEXT
and MULTIPLICITY
will both be set (defined). 宏PERL_IMPLICIT_CONTEXT
和MULTIPLICITY
都将被设置(定义)。 Also, in embedvar.h
there is a comment that may be relevant: 另外,在embedvar.h
,可能存在相关的注释:
The following combinations of
MULTIPLICITY
andPERL_IMPLICIT_CONTEXT
are supported: 支持MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
的以下组合:
1) none 1)没有
2) MULTIPLICITY # supported for compatibility 2)支持MULTIPLICITY#以实现兼容性
3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT 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). 仅直接支持#3,而#2是#3的特殊情况(通过适当地重新定义vTHX来支持)。
So, when writing XS code is there any difference in writing #ifdef MULTIPLICITY
versus writing #ifdef PERL_IMPLICIT_CONTEXT
? 因此,编写XS代码时,编写#ifdef MULTIPLICITY
与编写#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 MULTIPLICITY
was replaced with PERL_IMPLICIT_CONTEXT
in the perl source? 例如,如果在perl源代码PERL_IMPLICIT_CONTEXT
所有出现的MULTIPLICITY
都替换为PERL_IMPLICIT_CONTEXT
,该怎么办? What would it break? 它会破坏什么?
Here is what I have found so far. 到目前为止,这是我所发现的。 Running sh Configure -des
creates the header config.h
. 运行sh Configure -des
创建头config.h
。 This header file will: 该头文件将:
define USE_ITHREADS
if and only if Configure
was given the flag -Dusethreads
, eg: 仅当Configure
被赋予标志-Dusethreads
,才定义USE_ITHREADS
,例如:
sh Configure -des -Dusethreads
define MULTIPLICITY
if and only if Configure
was given the flag -Dusemultiplicity
: 当且仅当Configure
被赋予标志-Dusemultiplicity
时,才定义MULTIPLICITY
:
sh Configure -des -Dusemultiplicity
Setting MULTIPLICITY
through ccflags
will not set MULTIPLICITY
in config.h
, eg: 通过ccflags
设置MULTIPLICITY
不会在config.h
设置MULTIPLICITY
,例如:
sh Configure -des -Accflags="-DMULTIPLICITY"
Configure
has no -D
flag for PERL_IMPLICIT_CONTEXT
, and defining it through ccflags
will not define it in config.h
. Configure
对PERL_IMPLICIT_CONTEXT
没有-D
标志,并且通过ccflags
定义它不会在config.h
定义它。
The generated config.h
header is #include
d by perl.h
. 生成的config.h
标头是perl.h
#include
d。 Note, that the latter header is also usually included by Perl XS extension files ( .xs
-files). 请注意,后者标头通常也包含在Perl XS扩展文件( .xs
-files)中。 At line 59 in perl.h
we have: 在perl.h
第59行,我们有:
#ifdef USE_ITHREADS
# if !defined(MULTIPLICITY)
# define MULTIPLICITY
# endif
#endif
#ifdef PERL_GLOBAL_STRUCT_PRIVATE
# ifndef PERL_GLOBAL_STRUCT
# define PERL_GLOBAL_STRUCT
# endif
#endif
#ifdef PERL_GLOBAL_STRUCT
# ifndef MULTIPLICITY
# define MULTIPLICITY
# endif
#endif
#ifdef MULTIPLICITY
# ifndef PERL_IMPLICIT_CONTEXT
# define PERL_IMPLICIT_CONTEXT
# endif
#endif
This means that: 这意味着:
if -Dusethreads
is given, USE_ITHREADS
, MULTIPLICITY
, and PERL_IMPLICIT_CONTEXT
will all be defined. 如果-Dusethreads
给出, USE_ITHREADS
, MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
都将被定义。
if -Dusemultiplicity
is given, MULTIPLICITY
and PERL_IMPLICIT_CONTEXT
will be defined, whereas USE_ITHREADS
will be undefined. 如果-Dusemultiplicity
给出, MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
将被定义的,而USE_ITHREADS
是不确定的。
if none of -Dusethreads
or -Dusemultiplicity
is given USE_ITHREADS
, MULTIPLICITY
, and PERL_IMPLICIT_CONTEXT
will all be undefined. 如果-Dusemultiplicity
给-Dusethreads
或-Dusemultiplicity
任何一个,则USE_ITHREADS
, MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
都将是未定义的。
it is not possible to have MULTIPLICITY
defined and PERL_IMPLICIT_CONTEXT
undefined (unless one uses ccflags
, but then this will only be during the perl build. XS extension modules that include perl.h
will not see this) 不可能定义MULTIPLICITY
而未定义PERL_IMPLICIT_CONTEXT
(除非一个使用ccflags
,但是这只会在perl构建期间进行。包含perl.h
XS扩展模块将不会看到此信息)
So extension modules can usually assume that either: 因此扩展模块通常可以假定:
MULTIPLICITY
and PERL_IMPLICIT_CONTEXT
are both defined, or MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
都已定义,或者 MULTIPLICITY
and PERL_IMPLICIT_CONTEXT
are both undefined. MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
都未定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.