MULTIPLICITY与PERL_IMPLICIT_CONTEXT的关系
The relationship between MULTIPLICITY and PERL_IMPLICIT_CONTEXT
Perl API 宏 MULTIPLICITY
和 PERL_IMPLICIT_CONTEXT
之间有什么关系?
根据perlguts
:
One macro controls the major Perl build flavor: MULTIPLICITY
. The
MULTIPLICITY
build has a C structure that packages all the interpreter
state. 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.
(顺便问一下,这里指的是哪个"three data structures"?)
我注意到当我使用 usethreads
:
构建 perl 时
./Configure -des -Dusethreads
宏 PERL_IMPLICIT_CONTEXT
和 MULTIPLICITY
都将被设置(定义)。
此外,在 embedvar.h
中有一条可能相关的评论:
The following combinations of MULTIPLICITY
and
PERL_IMPLICIT_CONTEXT
are supported:
1) none
2) MULTIPLICITY # supported for compatibility
3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
All 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).
那么,写XS代码的时候,写法有什么区别吗
#ifdef MULTIPLICITY
与写作 #ifdef PERL_IMPLICIT_CONTEXT
?
这两个变量背后的历史是什么?看起来他们今天可以减少到一个。例如,如果在 perl 源代码中所有出现的 MULTIPLICITY
都被替换为 PERL_IMPLICIT_CONTEXT
会发生什么?它会破坏什么?
这是我目前的发现。 运行 sh Configure -des
创建 header config.h
。此 header 文件将:
定义 USE_ITHREADS
当且仅当 Configure
被赋予标志 -Dusethreads
,例如:
sh Configure -des -Dusethreads
定义 MULTIPLICITY
当且仅当 Configure
被赋予标志 -Dusemultiplicity
:
sh Configure -des -Dusemultiplicity
通过 ccflags
设置 MULTIPLICITY
将 不会 在 config.h
中设置 MULTIPLICITY
,例如:
sh Configure -des -Accflags="-DMULTIPLICITY"
Configure
没有PERL_IMPLICIT_CONTEXT
的-D
标志,通过ccflags
定义它不会 在config.h
.
中定义
生成的 config.h
header 是由 perl.h
生成的 #include
d。请注意,后者 header 通常也包含在 Perl XS 扩展文件(.xs
-文件)中。
在 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
这意味着:
如果给出-Dusethreads
,则USE_ITHREADS
、MULTIPLICITY
、PERL_IMPLICIT_CONTEXT
都会被定义。
如果给出-Dusemultiplicity
,MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
将被定义,而USE_ITHREADS
将是未定义的。
if none of -Dusethreads
or -Dusemultiplicity
is given USE_ITHREADS
, MULTIPLICITY
, and PERL_IMPLICIT_CONTEXT
will all未定义。
不可能有 MULTIPLICITY
定义和 PERL_IMPLICIT_CONTEXT
未定义(除非使用 ccflags
,但这只会在 perl 构建期间发生。包含 perl.h
的 XS 扩展模块不会看到这个)
所以扩展模块通常可以假设:
MULTIPLICITY
和 PERL_IMPLICIT_CONTEXT
都已定义,或者
MULTIPLICITY
和 PERL_IMPLICIT_CONTEXT
均未定义。
Perl API 宏 MULTIPLICITY
和 PERL_IMPLICIT_CONTEXT
之间有什么关系?
根据perlguts
:
One macro controls the major Perl build flavor:
MULTIPLICITY
. TheMULTIPLICITY
build has a C structure that packages all the interpreter state. 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.
(顺便问一下,这里指的是哪个"three data structures"?)
我注意到当我使用 usethreads
:
./Configure -des -Dusethreads
宏 PERL_IMPLICIT_CONTEXT
和 MULTIPLICITY
都将被设置(定义)。
此外,在 embedvar.h
中有一条可能相关的评论:
The following combinations of
MULTIPLICITY
andPERL_IMPLICIT_CONTEXT
are 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).
那么,写XS代码的时候,写法有什么区别吗
#ifdef MULTIPLICITY
与写作#ifdef PERL_IMPLICIT_CONTEXT
?这两个变量背后的历史是什么?看起来他们今天可以减少到一个。例如,如果在 perl 源代码中所有出现的
MULTIPLICITY
都被替换为PERL_IMPLICIT_CONTEXT
会发生什么?它会破坏什么?
这是我目前的发现。 运行 sh Configure -des
创建 header config.h
。此 header 文件将:
定义
USE_ITHREADS
当且仅当Configure
被赋予标志-Dusethreads
,例如:sh Configure -des -Dusethreads
定义
MULTIPLICITY
当且仅当Configure
被赋予标志-Dusemultiplicity
:sh Configure -des -Dusemultiplicity
通过
ccflags
设置MULTIPLICITY
将 不会 在config.h
中设置MULTIPLICITY
,例如:sh Configure -des -Accflags="-DMULTIPLICITY"
Configure
没有PERL_IMPLICIT_CONTEXT
的-D
标志,通过ccflags
定义它不会 在config.h
. 中定义
生成的 config.h
header 是由 perl.h
生成的 #include
d。请注意,后者 header 通常也包含在 Perl XS 扩展文件(.xs
-文件)中。
在 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
这意味着:
如果给出
-Dusethreads
,则USE_ITHREADS
、MULTIPLICITY
、PERL_IMPLICIT_CONTEXT
都会被定义。如果给出
-Dusemultiplicity
,MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
将被定义,而USE_ITHREADS
将是未定义的。if none of
-Dusethreads
or-Dusemultiplicity
is givenUSE_ITHREADS
,MULTIPLICITY
, andPERL_IMPLICIT_CONTEXT
will all未定义。不可能有
MULTIPLICITY
定义和PERL_IMPLICIT_CONTEXT
未定义(除非使用ccflags
,但这只会在 perl 构建期间发生。包含perl.h
的 XS 扩展模块不会看到这个)
所以扩展模块通常可以假设:
MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
都已定义,或者MULTIPLICITY
和PERL_IMPLICIT_CONTEXT
均未定义。