zend_API.h 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. | Andrei Zmievski <andrei@php.net> |
  18. | Dmitry Stogov <dmitry@php.net> |
  19. +----------------------------------------------------------------------+
  20. */
  21. #ifndef ZEND_API_H
  22. #define ZEND_API_H
  23. #include "zend_modules.h"
  24. #include "zend_list.h"
  25. #include "zend_operators.h"
  26. #include "zend_variables.h"
  27. #include "zend_execute.h"
  28. #include "zend_type_info.h"
  29. BEGIN_EXTERN_C()
  30. typedef struct _zend_function_entry {
  31. const char *fname;
  32. zif_handler handler;
  33. const struct _zend_internal_arg_info *arg_info;
  34. uint32_t num_args;
  35. uint32_t flags;
  36. } zend_function_entry;
  37. typedef struct _zend_fcall_info {
  38. size_t size;
  39. zval function_name;
  40. zval *retval;
  41. zval *params;
  42. zend_object *object;
  43. uint32_t param_count;
  44. /* This hashtable can also contain positional arguments (with integer keys),
  45. * which will be appended to the normal params[]. This makes it easier to
  46. * integrate APIs like call_user_func_array(). The usual restriction that
  47. * there may not be position arguments after named arguments applies. */
  48. HashTable *named_params;
  49. } zend_fcall_info;
  50. typedef struct _zend_fcall_info_cache {
  51. zend_function *function_handler;
  52. zend_class_entry *calling_scope;
  53. zend_class_entry *called_scope;
  54. zend_object *object;
  55. } zend_fcall_info_cache;
  56. #define ZEND_NS_NAME(ns, name) ns "\\" name
  57. /* ZEND_FN/ZEND_MN are inlined below to prevent pre-scan macro expansion,
  58. * which causes issues if the function name is also a macro name. */
  59. #define ZEND_FN(name) zif_##name
  60. #define ZEND_MN(name) zim_##name
  61. #define ZEND_NAMED_FUNCTION(name) void ZEND_FASTCALL name(INTERNAL_FUNCTION_PARAMETERS)
  62. #define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(zif_##name)
  63. #define ZEND_METHOD(classname, name) ZEND_NAMED_FUNCTION(zim_##classname##_##name)
  64. #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
  65. #define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags) { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
  66. /* Same as ZEND_NAMED_FE */
  67. #define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
  68. #define ZEND_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
  69. #define ZEND_FE(name, arg_info) ZEND_RAW_FENTRY(#name, zif_##name, arg_info, 0)
  70. #define ZEND_DEP_FE(name, arg_info) ZEND_RAW_FENTRY(#name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
  71. #define ZEND_FALIAS(name, alias, arg_info) ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, 0)
  72. #define ZEND_DEP_FALIAS(name, alias, arg_info) ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
  73. #define ZEND_NAMED_ME(zend_name, name, arg_info, flags) ZEND_FENTRY(zend_name, name, arg_info, flags)
  74. #define ZEND_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags)
  75. #define ZEND_DEP_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags | ZEND_ACC_DEPRECATED)
  76. #define ZEND_ABSTRACT_ME(classname, name, arg_info) ZEND_RAW_FENTRY(#name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
  77. #define ZEND_ABSTRACT_ME_WITH_FLAGS(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, NULL, arg_info, flags)
  78. #define ZEND_MALIAS(classname, name, alias, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##alias, arg_info, flags)
  79. #define ZEND_ME_MAPPING(name, func_name, arg_info, flags) ZEND_RAW_FENTRY(#name, zif_##func_name, arg_info, flags)
  80. #define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags) ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)
  81. #define ZEND_NS_RAW_FENTRY(ns, zend_name, name, arg_info, flags) ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, zend_name), name, arg_info, flags)
  82. /* Same as ZEND_NS_NAMED_FE */
  83. #define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info) ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
  84. #define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info) ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
  85. #define ZEND_NS_FE(ns, name, arg_info) ZEND_NS_RAW_FENTRY(ns, #name, zif_##name, arg_info, 0)
  86. #define ZEND_NS_DEP_FE(ns, name, arg_info) ZEND_NS_RAW_FENTRY(ns, #name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
  87. #define ZEND_NS_FALIAS(ns, name, alias, arg_info) ZEND_NS_RAW_FENTRY(ns, #name, zif_##alias, arg_info, 0)
  88. #define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info) ZEND_NS_RAW_FENTRY(ns, #name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
  89. #define ZEND_FE_END { NULL, NULL, NULL, 0, 0 }
  90. #define _ZEND_ARG_INFO_FLAGS(pass_by_ref, is_variadic, is_tentative) \
  91. (((pass_by_ref) << _ZEND_SEND_MODE_SHIFT) | ((is_variadic) ? _ZEND_IS_VARIADIC_BIT : 0) | ((is_tentative) ? _ZEND_IS_TENTATIVE_BIT : 0))
  92. /* Arginfo structures without type information */
  93. #define ZEND_ARG_INFO(pass_by_ref, name) \
  94. { #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
  95. #define ZEND_ARG_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, default_value) \
  96. { #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
  97. #define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name) \
  98. { #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
  99. /* Arginfo structures with simple type information */
  100. #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
  101. { #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
  102. #define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value) \
  103. { #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
  104. #define ZEND_ARG_VARIADIC_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
  105. { #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
  106. /* Arginfo structures with complex type information */
  107. #define ZEND_ARG_TYPE_MASK(pass_by_ref, name, type_mask, default_value) \
  108. { #name, ZEND_TYPE_INIT_MASK(type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
  109. #define ZEND_ARG_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask, default_value) \
  110. { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
  111. /* Arginfo structures with object type information */
  112. #define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) \
  113. { #name, ZEND_TYPE_INIT_CLASS_CONST(#classname, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
  114. #define ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, classname, allow_null, default_value) \
  115. { #name, ZEND_TYPE_INIT_CLASS_CONST(#classname, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
  116. #define ZEND_ARG_VARIADIC_OBJ_INFO(pass_by_ref, name, classname, allow_null) \
  117. { #name, ZEND_TYPE_INIT_CLASS_CONST(#classname, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
  118. /* Legacy arginfo structures */
  119. #define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) \
  120. { #name, ZEND_TYPE_INIT_CODE(IS_ARRAY, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
  121. #define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null) \
  122. { #name, ZEND_TYPE_INIT_CODE(IS_CALLABLE, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
  123. #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, is_tentative_return_type) \
  124. static const zend_internal_arg_info name[] = { \
  125. { (const char*)(zend_uintptr_t)(required_num_args), \
  126. ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
  127. #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
  128. ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, 0)
  129. #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
  130. ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, 1)
  131. #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
  132. ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, 0, -1, class_name, allow_null, 0)
  133. #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, is_tentative_return_type) \
  134. static const zend_internal_arg_info name[] = { \
  135. { (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_MASK(type | _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
  136. #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(name, return_reference, required_num_args, type) \
  137. ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, 0)
  138. #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(name, return_reference, required_num_args, type) \
  139. ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, 1)
  140. #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, is_tentative_return_type) \
  141. static const zend_internal_arg_info name[] = { \
  142. { (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type | _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
  143. #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(name, return_reference, required_num_args, class_name, type) \
  144. ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, 0)
  145. #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(name, return_reference, required_num_args, class_name, type) \
  146. ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, 1)
  147. #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, is_tentative_return_type) \
  148. static const zend_internal_arg_info name[] = { \
  149. { (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_CODE(type, allow_null, _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
  150. #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
  151. ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, 0)
  152. #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
  153. ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, 1)
  154. #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
  155. ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, 0, -1, type, allow_null, 0)
  156. #define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args) \
  157. static const zend_internal_arg_info name[] = { \
  158. { (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(return_reference, 0, 0)), NULL },
  159. #define ZEND_BEGIN_ARG_INFO(name, _unused) \
  160. ZEND_BEGIN_ARG_INFO_EX(name, {}, ZEND_RETURN_VALUE, -1)
  161. #define ZEND_END_ARG_INFO() };
  162. /* Name macros */
  163. #define ZEND_MODULE_STARTUP_N(module) zm_startup_##module
  164. #define ZEND_MODULE_SHUTDOWN_N(module) zm_shutdown_##module
  165. #define ZEND_MODULE_ACTIVATE_N(module) zm_activate_##module
  166. #define ZEND_MODULE_DEACTIVATE_N(module) zm_deactivate_##module
  167. #define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module) zm_post_zend_deactivate_##module
  168. #define ZEND_MODULE_INFO_N(module) zm_info_##module
  169. #define ZEND_MODULE_GLOBALS_CTOR_N(module) zm_globals_ctor_##module
  170. #define ZEND_MODULE_GLOBALS_DTOR_N(module) zm_globals_dtor_##module
  171. /* Declaration macros */
  172. #define ZEND_MODULE_STARTUP_D(module) zend_result ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
  173. #define ZEND_MODULE_SHUTDOWN_D(module) zend_result ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
  174. #define ZEND_MODULE_ACTIVATE_D(module) zend_result ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
  175. #define ZEND_MODULE_DEACTIVATE_D(module) zend_result ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
  176. #define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module) zend_result ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
  177. #define ZEND_MODULE_INFO_D(module) ZEND_COLD void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
  178. #define ZEND_MODULE_GLOBALS_CTOR_D(module) void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals)
  179. #define ZEND_MODULE_GLOBALS_DTOR_D(module) void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals)
  180. #define ZEND_GET_MODULE(name) \
  181. BEGIN_EXTERN_C()\
  182. ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
  183. END_EXTERN_C()
  184. #define ZEND_BEGIN_MODULE_GLOBALS(module_name) \
  185. typedef struct _zend_##module_name##_globals {
  186. #define ZEND_END_MODULE_GLOBALS(module_name) \
  187. } zend_##module_name##_globals;
  188. #ifdef ZTS
  189. #define ZEND_DECLARE_MODULE_GLOBALS(module_name) \
  190. ts_rsrc_id module_name##_globals_id;
  191. #define ZEND_EXTERN_MODULE_GLOBALS(module_name) \
  192. extern ts_rsrc_id module_name##_globals_id;
  193. #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor) \
  194. ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
  195. #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) ZEND_TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
  196. #ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
  197. #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK_STATIC(module_name##_globals_id, zend_##module_name##_globals *)
  198. #else
  199. #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK(module_name##_globals_id, zend_##module_name##_globals *)
  200. #endif
  201. #else
  202. #define ZEND_DECLARE_MODULE_GLOBALS(module_name) \
  203. zend_##module_name##_globals module_name##_globals;
  204. #define ZEND_EXTERN_MODULE_GLOBALS(module_name) \
  205. extern zend_##module_name##_globals module_name##_globals;
  206. #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor) \
  207. globals_ctor(&module_name##_globals);
  208. #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) (module_name##_globals.v)
  209. #define ZEND_MODULE_GLOBALS_BULK(module_name) (&module_name##_globals)
  210. #endif
  211. #define INIT_CLASS_ENTRY(class_container, class_name, functions) \
  212. INIT_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions)
  213. #define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
  214. { \
  215. memset(&class_container, 0, sizeof(zend_class_entry)); \
  216. class_container.name = zend_string_init_interned(class_name, class_name_len, 1); \
  217. class_container.info.internal.builtin_functions = functions; \
  218. }
  219. #define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions) \
  220. { \
  221. class_container.constructor = NULL; \
  222. class_container.destructor = NULL; \
  223. class_container.clone = NULL; \
  224. class_container.serialize = NULL; \
  225. class_container.unserialize = NULL; \
  226. class_container.create_object = NULL; \
  227. class_container.get_static_method = NULL; \
  228. class_container.__call = NULL; \
  229. class_container.__callstatic = NULL; \
  230. class_container.__tostring = NULL; \
  231. class_container.__get = NULL; \
  232. class_container.__set = NULL; \
  233. class_container.__unset = NULL; \
  234. class_container.__isset = NULL; \
  235. class_container.__debugInfo = NULL; \
  236. class_container.__serialize = NULL; \
  237. class_container.__unserialize = NULL; \
  238. class_container.parent = NULL; \
  239. class_container.num_interfaces = 0; \
  240. class_container.trait_names = NULL; \
  241. class_container.num_traits = 0; \
  242. class_container.trait_aliases = NULL; \
  243. class_container.trait_precedences = NULL; \
  244. class_container.interfaces = NULL; \
  245. class_container.get_iterator = NULL; \
  246. class_container.iterator_funcs_ptr = NULL; \
  247. class_container.info.internal.module = NULL; \
  248. class_container.info.internal.builtin_functions = functions; \
  249. }
  250. #define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
  251. INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
  252. #define CE_STATIC_MEMBERS(ce) \
  253. ((zval*)ZEND_MAP_PTR_GET((ce)->static_members_table))
  254. #define CE_CONSTANTS_TABLE(ce) \
  255. zend_class_constants_table(ce)
  256. #define CE_DEFAULT_PROPERTIES_TABLE(ce) \
  257. zend_class_default_properties_table(ce)
  258. #define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
  259. ZEND_API int zend_next_free_module(void);
  260. BEGIN_EXTERN_C()
  261. ZEND_API zend_result _zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array);
  262. /* internal function to efficiently copy parameters when executing __call() */
  263. ZEND_API zend_result zend_copy_parameters_array(uint32_t param_count, zval *argument_array);
  264. #define zend_get_parameters_array(ht, param_count, argument_array) \
  265. _zend_get_parameters_array_ex(param_count, argument_array)
  266. #define zend_get_parameters_array_ex(param_count, argument_array) \
  267. _zend_get_parameters_array_ex(param_count, argument_array)
  268. #define zend_parse_parameters_none() \
  269. (EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : (zend_wrong_parameters_none_error(), FAILURE))
  270. #define zend_parse_parameters_none_throw() \
  271. zend_parse_parameters_none()
  272. /* Parameter parsing API -- andrei */
  273. #define ZEND_PARSE_PARAMS_THROW 0 /* No longer used, zpp always uses exceptions */
  274. #define ZEND_PARSE_PARAMS_QUIET (1<<1)
  275. ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec, ...);
  276. ZEND_API zend_result zend_parse_parameters_ex(int flags, uint32_t num_args, const char *type_spec, ...);
  277. /* NOTE: This must have at least one value in __VA_ARGS__ for the expression to be valid */
  278. #define zend_parse_parameters_throw(num_args, ...) \
  279. zend_parse_parameters(num_args, __VA_ARGS__)
  280. ZEND_API const char *zend_zval_type_name(const zval *arg);
  281. ZEND_API zend_string *zend_zval_get_legacy_type(const zval *arg);
  282. ZEND_API zend_result zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
  283. ZEND_API zend_result zend_parse_method_parameters_ex(int flags, uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
  284. ZEND_API zend_result zend_parse_parameter(int flags, uint32_t arg_num, zval *arg, const char *spec, ...);
  285. /* End of parameter parsing API -- andrei */
  286. ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type);
  287. ZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table);
  288. ZEND_API zend_result zend_startup_module(zend_module_entry *module_entry);
  289. ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry);
  290. ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module);
  291. ZEND_API zend_result zend_startup_module_ex(zend_module_entry *module);
  292. ZEND_API void zend_startup_modules(void);
  293. ZEND_API void zend_collect_module_handlers(void);
  294. ZEND_API void zend_destroy_modules(void);
  295. ZEND_API void zend_check_magic_method_implementation(
  296. const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type);
  297. ZEND_API void zend_add_magic_method(zend_class_entry *ce, zend_function *fptr, zend_string *lcname);
  298. ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
  299. ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
  300. ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
  301. ZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);
  302. ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, bool persistent);
  303. #define zend_register_class_alias(name, ce) \
  304. zend_register_class_alias_ex(name, sizeof(name)-1, ce, 1)
  305. #define zend_register_ns_class_alias(ns, name, ce) \
  306. zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
  307. ZEND_API void zend_disable_functions(const char *function_list);
  308. ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_name_length);
  309. ZEND_API ZEND_COLD void zend_wrong_param_count(void);
  310. #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
  311. #define IS_CALLABLE_CHECK_SILENT (1<<3)
  312. ZEND_API void zend_release_fcall_info_cache(zend_fcall_info_cache *fcc);
  313. ZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *object);
  314. ZEND_API zend_string *zend_get_callable_name(zval *callable);
  315. ZEND_API bool zend_is_callable_at_frame(
  316. zval *callable, zend_object *object, zend_execute_data *frame,
  317. uint32_t check_flags, zend_fcall_info_cache *fcc, char **error);
  318. ZEND_API bool zend_is_callable_ex(zval *callable, zend_object *object, uint32_t check_flags, zend_string **callable_name, zend_fcall_info_cache *fcc, char **error);
  319. ZEND_API bool zend_is_callable(zval *callable, uint32_t check_flags, zend_string **callable_name);
  320. ZEND_API bool zend_make_callable(zval *callable, zend_string **callable_name);
  321. ZEND_API const char *zend_get_module_version(const char *module_name);
  322. ZEND_API int zend_get_module_started(const char *module_name);
  323. ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment, zend_type type);
  324. ZEND_API void zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment);
  325. ZEND_API void zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type);
  326. ZEND_API void zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type);
  327. ZEND_API void zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
  328. ZEND_API void zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
  329. ZEND_API void zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type);
  330. ZEND_API void zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type);
  331. ZEND_API void zend_declare_property_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_len, int access_type);
  332. ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment);
  333. ZEND_API void zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value);
  334. ZEND_API void zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length);
  335. ZEND_API void zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value);
  336. ZEND_API void zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, bool value);
  337. ZEND_API void zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value);
  338. ZEND_API void zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length);
  339. ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
  340. ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type);
  341. ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_type);
  342. static zend_always_inline HashTable *zend_class_constants_table(zend_class_entry *ce) {
  343. if ((ce->ce_flags & ZEND_ACC_HAS_AST_CONSTANTS) && ZEND_MAP_PTR(ce->mutable_data)) {
  344. zend_class_mutable_data *mutable_data =
  345. (zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
  346. if (mutable_data && mutable_data->constants_table) {
  347. return mutable_data->constants_table;
  348. } else {
  349. return zend_separate_class_constants_table(ce);
  350. }
  351. } else {
  352. return &ce->constants_table;
  353. }
  354. }
  355. static zend_always_inline zval *zend_class_default_properties_table(zend_class_entry *ce) {
  356. if ((ce->ce_flags & ZEND_ACC_HAS_AST_PROPERTIES) && ZEND_MAP_PTR(ce->mutable_data)) {
  357. zend_class_mutable_data *mutable_data =
  358. (zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
  359. return mutable_data->default_properties_table;
  360. } else {
  361. return ce->default_properties_table;
  362. }
  363. }
  364. ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value);
  365. ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value);
  366. ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
  367. ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
  368. ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
  369. ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value);
  370. ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value);
  371. ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value);
  372. ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_length);
  373. ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
  374. ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value);
  375. ZEND_API zend_result zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
  376. ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
  377. ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
  378. ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
  379. ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
  380. ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
  381. ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length);
  382. ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv);
  383. ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv);
  384. ZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, bool silent);
  385. ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, bool silent);
  386. ZEND_API const char *zend_get_type_by_const(int type);
  387. #define ZEND_THIS (&EX(This))
  388. #define getThis() ((Z_TYPE_P(ZEND_THIS) == IS_OBJECT) ? ZEND_THIS : NULL)
  389. #define ZEND_IS_METHOD_CALL() (EX(func)->common.scope != NULL)
  390. #define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT()
  391. #define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
  392. #define ZEND_NUM_ARGS() EX_NUM_ARGS()
  393. #define ZEND_WRONG_PARAM_COUNT() { zend_wrong_param_count(); return; }
  394. #define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret) { zend_wrong_param_count(); return ret; }
  395. #ifndef ZEND_WIN32
  396. #define DLEXPORT
  397. #endif
  398. #define array_init(arg) ZVAL_ARR((arg), zend_new_array(0))
  399. #define array_init_size(arg, size) ZVAL_ARR((arg), zend_new_array(size))
  400. ZEND_API void object_init(zval *arg);
  401. ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce);
  402. ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
  403. ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
  404. ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
  405. ZEND_API void object_properties_load(zend_object *object, HashTable *properties);
  406. ZEND_API void zend_merge_properties(zval *obj, HashTable *properties);
  407. ZEND_API void add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
  408. ZEND_API void add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
  409. ZEND_API void add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, bool b);
  410. ZEND_API void add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
  411. ZEND_API void add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
  412. ZEND_API void add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
  413. ZEND_API void add_assoc_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
  414. ZEND_API void add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
  415. ZEND_API void add_assoc_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr);
  416. ZEND_API void add_assoc_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj);
  417. ZEND_API void add_assoc_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref);
  418. ZEND_API void add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
  419. #define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key), __n)
  420. #define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
  421. #define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key), __b)
  422. #define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key), __r)
  423. #define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key), __d)
  424. #define add_assoc_str(__arg, __key, __str) add_assoc_str_ex(__arg, __key, strlen(__key), __str)
  425. #define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
  426. #define add_assoc_stringl(__arg, __key, __str, __length) add_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
  427. #define add_assoc_array(__arg, __key, __arr) add_assoc_array_ex(__arg, __key, strlen(__key), __arr)
  428. #define add_assoc_object(__arg, __key, __obj) add_assoc_object_ex(__arg, __key, strlen(__key), __obj)
  429. #define add_assoc_reference(__arg, __key, __ref) add_assoc_object_ex(__arg, __key, strlen(__key), __ref)
  430. #define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
  431. ZEND_API void add_index_long(zval *arg, zend_ulong index, zend_long n);
  432. ZEND_API void add_index_null(zval *arg, zend_ulong index);
  433. ZEND_API void add_index_bool(zval *arg, zend_ulong index, bool b);
  434. ZEND_API void add_index_resource(zval *arg, zend_ulong index, zend_resource *r);
  435. ZEND_API void add_index_double(zval *arg, zend_ulong index, double d);
  436. ZEND_API void add_index_str(zval *arg, zend_ulong index, zend_string *str);
  437. ZEND_API void add_index_string(zval *arg, zend_ulong index, const char *str);
  438. ZEND_API void add_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length);
  439. ZEND_API void add_index_array(zval *arg, zend_ulong index, zend_array *arr);
  440. ZEND_API void add_index_object(zval *arg, zend_ulong index, zend_object *obj);
  441. ZEND_API void add_index_reference(zval *arg, zend_ulong index, zend_reference *ref);
  442. static zend_always_inline zend_result add_index_zval(zval *arg, zend_ulong index, zval *value)
  443. {
  444. return zend_hash_index_update(Z_ARRVAL_P(arg), index, value) ? SUCCESS : FAILURE;
  445. }
  446. ZEND_API zend_result add_next_index_long(zval *arg, zend_long n);
  447. ZEND_API zend_result add_next_index_null(zval *arg);
  448. ZEND_API zend_result add_next_index_bool(zval *arg, bool b);
  449. ZEND_API zend_result add_next_index_resource(zval *arg, zend_resource *r);
  450. ZEND_API zend_result add_next_index_double(zval *arg, double d);
  451. ZEND_API zend_result add_next_index_str(zval *arg, zend_string *str);
  452. ZEND_API zend_result add_next_index_string(zval *arg, const char *str);
  453. ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length);
  454. ZEND_API zend_result add_next_index_array(zval *arg, zend_array *arr);
  455. ZEND_API zend_result add_next_index_object(zval *arg, zend_object *obj);
  456. ZEND_API zend_result add_next_index_reference(zval *arg, zend_reference *ref);
  457. static zend_always_inline zend_result add_next_index_zval(zval *arg, zval *value)
  458. {
  459. return zend_hash_next_index_insert(Z_ARRVAL_P(arg), value) ? SUCCESS : FAILURE;
  460. }
  461. ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value);
  462. ZEND_API void add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l);
  463. ZEND_API void add_property_null_ex(zval *arg, const char *key, size_t key_len);
  464. ZEND_API void add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b);
  465. ZEND_API void add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
  466. ZEND_API void add_property_double_ex(zval *arg, const char *key, size_t key_len, double d);
  467. ZEND_API void add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
  468. ZEND_API void add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
  469. ZEND_API void add_property_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
  470. ZEND_API void add_property_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr);
  471. ZEND_API void add_property_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj);
  472. ZEND_API void add_property_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref);
  473. ZEND_API void add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
  474. #define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key), __n)
  475. #define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key))
  476. #define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key), __b)
  477. #define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key), __r)
  478. #define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key), __d)
  479. #define add_property_str(__arg, __key, __str) add_property_str_ex(__arg, __key, strlen(__key), __str)
  480. #define add_property_string(__arg, __key, __str) add_property_string_ex(__arg, __key, strlen(__key), __str)
  481. #define add_property_stringl(__arg, __key, __str, __length) add_property_stringl_ex(__arg, __key, strlen(__key), __str, __length)
  482. #define add_property_array(__arg, __key, __arr) add_property_array_ex(__arg, __key, strlen(__key), __arr)
  483. #define add_property_object(__arg, __key, __obj) add_property_object_ex(__arg, __key, strlen(__key), __obj)
  484. #define add_property_reference(__arg, __key, __ref) add_property_reference_ex(__arg, __key, strlen(__key), __ref)
  485. #define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key), __value)
  486. ZEND_API zend_result _call_user_function_impl(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], HashTable *named_params);
  487. #define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
  488. _call_user_function_impl(object, function_name, retval_ptr, param_count, params, NULL)
  489. #define call_user_function_named(function_table, object, function_name, retval_ptr, param_count, params, named_params) \
  490. _call_user_function_impl(object, function_name, retval_ptr, param_count, params, named_params)
  491. ZEND_API extern const zend_fcall_info empty_fcall_info;
  492. ZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
  493. /** Build zend_call_info/cache from a zval*
  494. *
  495. * Caller is responsible to provide a return value (fci->retval), otherwise the we will crash.
  496. * In order to pass parameters the following members need to be set:
  497. * fci->param_count = 0;
  498. * fci->params = NULL;
  499. * The callable_name argument may be NULL.
  500. */
  501. ZEND_API zend_result zend_fcall_info_init(zval *callable, uint32_t check_flags, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string **callable_name, char **error);
  502. /** Clear arguments connected with zend_fcall_info *fci
  503. * If free_mem is not zero then the params array gets free'd as well
  504. */
  505. ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, bool free_mem);
  506. /** Save current arguments from zend_fcall_info *fci
  507. * params array will be set to NULL
  508. */
  509. ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, uint32_t *param_count, zval **params);
  510. /** Free arguments connected with zend_fcall_info *fci and set back saved ones.
  511. */
  512. ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, uint32_t param_count, zval *params);
  513. /** Set or clear the arguments in the zend_call_info struct taking care of
  514. * refcount. If args is NULL and arguments are set then those are cleared.
  515. */
  516. ZEND_API zend_result zend_fcall_info_args(zend_fcall_info *fci, zval *args);
  517. ZEND_API zend_result zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args);
  518. /** Set arguments in the zend_fcall_info struct taking care of refcount.
  519. * If argc is 0 the arguments which are set will be cleared, else pass
  520. * a variable amount of zval** arguments.
  521. */
  522. ZEND_API void zend_fcall_info_argp(zend_fcall_info *fci, uint32_t argc, zval *argv);
  523. /** Set arguments in the zend_fcall_info struct taking care of refcount.
  524. * If argc is 0 the arguments which are set will be cleared, else pass
  525. * a variable amount of zval** arguments.
  526. */
  527. ZEND_API void zend_fcall_info_argv(zend_fcall_info *fci, uint32_t argc, va_list *argv);
  528. /** Set arguments in the zend_fcall_info struct taking care of refcount.
  529. * If argc is 0 the arguments which are set will be cleared, else pass
  530. * a variable amount of zval** arguments.
  531. */
  532. ZEND_API void zend_fcall_info_argn(zend_fcall_info *fci, uint32_t argc, ...);
  533. /** Call a function using information created by zend_fcall_info_init()/args().
  534. * If args is given then those replace the argument info in fci is temporarily.
  535. */
  536. ZEND_API zend_result zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args);
  537. ZEND_API zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
  538. /* Call the provided zend_function with the given params.
  539. * If retval_ptr is NULL, the return value is discarded.
  540. * If object is NULL, this must be a free function or static call.
  541. * called_scope must be provided for instance and static method calls. */
  542. ZEND_API void zend_call_known_function(
  543. zend_function *fn, zend_object *object, zend_class_entry *called_scope, zval *retval_ptr,
  544. uint32_t param_count, zval *params, HashTable *named_params);
  545. /* Call the provided zend_function instance method on an object. */
  546. static zend_always_inline void zend_call_known_instance_method(
  547. zend_function *fn, zend_object *object, zval *retval_ptr,
  548. uint32_t param_count, zval *params)
  549. {
  550. zend_call_known_function(fn, object, object->ce, retval_ptr, param_count, params, NULL);
  551. }
  552. static zend_always_inline void zend_call_known_instance_method_with_0_params(
  553. zend_function *fn, zend_object *object, zval *retval_ptr)
  554. {
  555. zend_call_known_instance_method(fn, object, retval_ptr, 0, NULL);
  556. }
  557. static zend_always_inline void zend_call_known_instance_method_with_1_params(
  558. zend_function *fn, zend_object *object, zval *retval_ptr, zval *param)
  559. {
  560. zend_call_known_instance_method(fn, object, retval_ptr, 1, param);
  561. }
  562. ZEND_API void zend_call_known_instance_method_with_2_params(
  563. zend_function *fn, zend_object *object, zval *retval_ptr, zval *param1, zval *param2);
  564. ZEND_API zend_result zend_set_hash_symbol(zval *symbol, const char *name, size_t name_length, bool is_ref, int num_symbol_tables, ...);
  565. ZEND_API zend_result zend_delete_global_variable(zend_string *name);
  566. ZEND_API zend_array *zend_rebuild_symbol_table(void);
  567. ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
  568. ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
  569. ZEND_API zend_result zend_set_local_var(zend_string *name, zval *value, bool force);
  570. ZEND_API zend_result zend_set_local_var_str(const char *name, size_t len, zval *value, bool force);
  571. static zend_always_inline zend_result zend_forbid_dynamic_call(const char *func_name)
  572. {
  573. zend_execute_data *ex = EG(current_execute_data);
  574. ZEND_ASSERT(ex != NULL && ex->func != NULL);
  575. if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) {
  576. zend_throw_error(NULL, "Cannot call %s dynamically", func_name);
  577. return FAILURE;
  578. }
  579. return SUCCESS;
  580. }
  581. ZEND_API ZEND_COLD const char *zend_get_object_type(const zend_class_entry *ce);
  582. ZEND_API bool zend_is_iterable(zval *iterable);
  583. ZEND_API bool zend_is_countable(zval *countable);
  584. ZEND_API zend_result zend_get_default_from_internal_arg_info(
  585. zval *default_value_zval, zend_internal_arg_info *arg_info);
  586. END_EXTERN_C()
  587. #if ZEND_DEBUG
  588. #define CHECK_ZVAL_STRING(str) \
  589. ZEND_ASSERT(ZSTR_VAL(str)[ZSTR_LEN(str)] == '\0' && "String is not null-terminated");
  590. #else
  591. #define CHECK_ZVAL_STRING(z)
  592. #endif
  593. #define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
  594. #define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
  595. #define ZVAL_STRINGL(z, s, l) do { \
  596. ZVAL_NEW_STR(z, zend_string_init(s, l, 0)); \
  597. } while (0)
  598. #define ZVAL_STRING(z, s) do { \
  599. const char *_s = (s); \
  600. ZVAL_STRINGL(z, _s, strlen(_s)); \
  601. } while (0)
  602. #define ZVAL_EMPTY_STRING(z) do { \
  603. ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC()); \
  604. } while (0)
  605. #define ZVAL_PSTRINGL(z, s, l) do { \
  606. ZVAL_NEW_STR(z, zend_string_init(s, l, 1)); \
  607. } while (0)
  608. #define ZVAL_PSTRING(z, s) do { \
  609. const char *_s = (s); \
  610. ZVAL_PSTRINGL(z, _s, strlen(_s)); \
  611. } while (0)
  612. #define ZVAL_EMPTY_PSTRING(z) do { \
  613. ZVAL_PSTRINGL(z, "", 0); \
  614. } while (0)
  615. #define ZVAL_CHAR(z, c) do { \
  616. char _c = (c); \
  617. ZVAL_INTERNED_STR(z, ZSTR_CHAR((zend_uchar) _c)); \
  618. } while (0)
  619. #define ZVAL_STRINGL_FAST(z, s, l) do { \
  620. ZVAL_STR(z, zend_string_init_fast(s, l)); \
  621. } while (0)
  622. #define ZVAL_STRING_FAST(z, s) do { \
  623. const char *_s = (s); \
  624. ZVAL_STRINGL_FAST(z, _s, strlen(_s)); \
  625. } while (0)
  626. #define ZVAL_ZVAL(z, zv, copy, dtor) do { \
  627. zval *__z = (z); \
  628. zval *__zv = (zv); \
  629. if (EXPECTED(!Z_ISREF_P(__zv))) { \
  630. if (copy && !dtor) { \
  631. ZVAL_COPY(__z, __zv); \
  632. } else { \
  633. ZVAL_COPY_VALUE(__z, __zv); \
  634. } \
  635. } else { \
  636. ZVAL_COPY(__z, Z_REFVAL_P(__zv)); \
  637. if (dtor || !copy) { \
  638. zval_ptr_dtor(__zv); \
  639. } \
  640. } \
  641. } while (0)
  642. #define RETVAL_BOOL(b) ZVAL_BOOL(return_value, b)
  643. #define RETVAL_NULL() ZVAL_NULL(return_value)
  644. #define RETVAL_LONG(l) ZVAL_LONG(return_value, l)
  645. #define RETVAL_DOUBLE(d) ZVAL_DOUBLE(return_value, d)
  646. #define RETVAL_STR(s) ZVAL_STR(return_value, s)
  647. #define RETVAL_INTERNED_STR(s) ZVAL_INTERNED_STR(return_value, s)
  648. #define RETVAL_NEW_STR(s) ZVAL_NEW_STR(return_value, s)
  649. #define RETVAL_STR_COPY(s) ZVAL_STR_COPY(return_value, s)
  650. #define RETVAL_STRING(s) ZVAL_STRING(return_value, s)
  651. #define RETVAL_STRINGL(s, l) ZVAL_STRINGL(return_value, s, l)
  652. #define RETVAL_STRING_FAST(s) ZVAL_STRING_FAST(return_value, s)
  653. #define RETVAL_STRINGL_FAST(s, l) ZVAL_STRINGL_FAST(return_value, s, l)
  654. #define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value)
  655. #define RETVAL_CHAR(c) ZVAL_CHAR(return_value, c)
  656. #define RETVAL_RES(r) ZVAL_RES(return_value, r)
  657. #define RETVAL_ARR(r) ZVAL_ARR(return_value, r)
  658. #define RETVAL_EMPTY_ARRAY() ZVAL_EMPTY_ARRAY(return_value)
  659. #define RETVAL_OBJ(r) ZVAL_OBJ(return_value, r)
  660. #define RETVAL_OBJ_COPY(r) ZVAL_OBJ_COPY(return_value, r)
  661. #define RETVAL_COPY(zv) ZVAL_COPY(return_value, zv)
  662. #define RETVAL_COPY_VALUE(zv) ZVAL_COPY_VALUE(return_value, zv)
  663. #define RETVAL_COPY_DEREF(zv) ZVAL_COPY_DEREF(return_value, zv)
  664. #define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
  665. #define RETVAL_FALSE ZVAL_FALSE(return_value)
  666. #define RETVAL_TRUE ZVAL_TRUE(return_value)
  667. #define RETURN_BOOL(b) do { RETVAL_BOOL(b); return; } while (0)
  668. #define RETURN_NULL() do { RETVAL_NULL(); return;} while (0)
  669. #define RETURN_LONG(l) do { RETVAL_LONG(l); return; } while (0)
  670. #define RETURN_DOUBLE(d) do { RETVAL_DOUBLE(d); return; } while (0)
  671. #define RETURN_STR(s) do { RETVAL_STR(s); return; } while (0)
  672. #define RETURN_INTERNED_STR(s) do { RETVAL_INTERNED_STR(s); return; } while (0)
  673. #define RETURN_NEW_STR(s) do { RETVAL_NEW_STR(s); return; } while (0)
  674. #define RETURN_STR_COPY(s) do { RETVAL_STR_COPY(s); return; } while (0)
  675. #define RETURN_STRING(s) do { RETVAL_STRING(s); return; } while (0)
  676. #define RETURN_STRINGL(s, l) do { RETVAL_STRINGL(s, l); return; } while (0)
  677. #define RETURN_STRING_FAST(s) do { RETVAL_STRING_FAST(s); return; } while (0)
  678. #define RETURN_STRINGL_FAST(s, l) do { RETVAL_STRINGL_FAST(s, l); return; } while (0)
  679. #define RETURN_EMPTY_STRING() do { RETVAL_EMPTY_STRING(); return; } while (0)
  680. #define RETURN_CHAR(c) do { RETVAL_CHAR(c); return; } while (0)
  681. #define RETURN_RES(r) do { RETVAL_RES(r); return; } while (0)
  682. #define RETURN_ARR(r) do { RETVAL_ARR(r); return; } while (0)
  683. #define RETURN_EMPTY_ARRAY() do { RETVAL_EMPTY_ARRAY(); return; } while (0)
  684. #define RETURN_OBJ(r) do { RETVAL_OBJ(r); return; } while (0)
  685. #define RETURN_OBJ_COPY(r) do { RETVAL_OBJ_COPY(r); return; } while (0)
  686. #define RETURN_COPY(zv) do { RETVAL_COPY(zv); return; } while (0)
  687. #define RETURN_COPY_VALUE(zv) do { RETVAL_COPY_VALUE(zv); return; } while (0)
  688. #define RETURN_COPY_DEREF(zv) do { RETVAL_COPY_DEREF(zv); return; } while (0)
  689. #define RETURN_ZVAL(zv, copy, dtor) do { RETVAL_ZVAL(zv, copy, dtor); return; } while (0)
  690. #define RETURN_FALSE do { RETVAL_FALSE; return; } while (0)
  691. #define RETURN_TRUE do { RETVAL_TRUE; return; } while (0)
  692. #define RETURN_THROWS() do { ZEND_ASSERT(EG(exception)); (void) return_value; return; } while (0)
  693. #define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties(Z_OBJ_P(p)) : NULL)))
  694. #define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
  695. /* For compatibility */
  696. #define ZEND_MINIT ZEND_MODULE_STARTUP_N
  697. #define ZEND_MSHUTDOWN ZEND_MODULE_SHUTDOWN_N
  698. #define ZEND_RINIT ZEND_MODULE_ACTIVATE_N
  699. #define ZEND_RSHUTDOWN ZEND_MODULE_DEACTIVATE_N
  700. #define ZEND_MINFO ZEND_MODULE_INFO_N
  701. #define ZEND_GINIT(module) ((void (*)(void*))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
  702. #define ZEND_GSHUTDOWN(module) ((void (*)(void*))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
  703. #define ZEND_MINIT_FUNCTION ZEND_MODULE_STARTUP_D
  704. #define ZEND_MSHUTDOWN_FUNCTION ZEND_MODULE_SHUTDOWN_D
  705. #define ZEND_RINIT_FUNCTION ZEND_MODULE_ACTIVATE_D
  706. #define ZEND_RSHUTDOWN_FUNCTION ZEND_MODULE_DEACTIVATE_D
  707. #define ZEND_MINFO_FUNCTION ZEND_MODULE_INFO_D
  708. #define ZEND_GINIT_FUNCTION ZEND_MODULE_GLOBALS_CTOR_D
  709. #define ZEND_GSHUTDOWN_FUNCTION ZEND_MODULE_GLOBALS_DTOR_D
  710. /* May modify arg in-place. Will free arg in failure case (and take ownership in success case).
  711. * Prefer using the ZEND_TRY_ASSIGN_* macros over these APIs. */
  712. ZEND_API zend_result zend_try_assign_typed_ref_ex(zend_reference *ref, zval *zv, bool strict);
  713. ZEND_API zend_result zend_try_assign_typed_ref(zend_reference *ref, zval *zv);
  714. ZEND_API zend_result zend_try_assign_typed_ref_null(zend_reference *ref);
  715. ZEND_API zend_result zend_try_assign_typed_ref_bool(zend_reference *ref, bool val);
  716. ZEND_API zend_result zend_try_assign_typed_ref_long(zend_reference *ref, zend_long lval);
  717. ZEND_API zend_result zend_try_assign_typed_ref_double(zend_reference *ref, double dval);
  718. ZEND_API zend_result zend_try_assign_typed_ref_empty_string(zend_reference *ref);
  719. ZEND_API zend_result zend_try_assign_typed_ref_str(zend_reference *ref, zend_string *str);
  720. ZEND_API zend_result zend_try_assign_typed_ref_string(zend_reference *ref, const char *string);
  721. ZEND_API zend_result zend_try_assign_typed_ref_stringl(zend_reference *ref, const char *string, size_t len);
  722. ZEND_API zend_result zend_try_assign_typed_ref_arr(zend_reference *ref, zend_array *arr);
  723. ZEND_API zend_result zend_try_assign_typed_ref_res(zend_reference *ref, zend_resource *res);
  724. ZEND_API zend_result zend_try_assign_typed_ref_zval(zend_reference *ref, zval *zv);
  725. ZEND_API zend_result zend_try_assign_typed_ref_zval_ex(zend_reference *ref, zval *zv, bool strict);
  726. #define _ZEND_TRY_ASSIGN_NULL(zv, is_ref) do { \
  727. zval *_zv = zv; \
  728. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  729. zend_reference *ref = Z_REF_P(_zv); \
  730. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  731. zend_try_assign_typed_ref_null(ref); \
  732. break; \
  733. } \
  734. _zv = &ref->val; \
  735. } \
  736. zval_ptr_dtor(_zv); \
  737. ZVAL_NULL(_zv); \
  738. } while (0)
  739. #define ZEND_TRY_ASSIGN_NULL(zv) \
  740. _ZEND_TRY_ASSIGN_NULL(zv, 0)
  741. #define ZEND_TRY_ASSIGN_REF_NULL(zv) do { \
  742. ZEND_ASSERT(Z_ISREF_P(zv)); \
  743. _ZEND_TRY_ASSIGN_NULL(zv, 1); \
  744. } while (0)
  745. #define _ZEND_TRY_ASSIGN_FALSE(zv, is_ref) do { \
  746. zval *_zv = zv; \
  747. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  748. zend_reference *ref = Z_REF_P(_zv); \
  749. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  750. zend_try_assign_typed_ref_bool(ref, 0); \
  751. break; \
  752. } \
  753. _zv = &ref->val; \
  754. } \
  755. zval_ptr_dtor(_zv); \
  756. ZVAL_FALSE(_zv); \
  757. } while (0)
  758. #define ZEND_TRY_ASSIGN_FALSE(zv) \
  759. _ZEND_TRY_ASSIGN_FALSE(zv, 0)
  760. #define ZEND_TRY_ASSIGN_REF_FALSE(zv) do { \
  761. ZEND_ASSERT(Z_ISREF_P(zv)); \
  762. _ZEND_TRY_ASSIGN_FALSE(zv, 1); \
  763. } while (0)
  764. #define _ZEND_TRY_ASSIGN_TRUE(zv, is_ref) do { \
  765. zval *_zv = zv; \
  766. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  767. zend_reference *ref = Z_REF_P(_zv); \
  768. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  769. zend_try_assign_typed_ref_bool(ref, 1); \
  770. break; \
  771. } \
  772. _zv = &ref->val; \
  773. } \
  774. zval_ptr_dtor(_zv); \
  775. ZVAL_TRUE(_zv); \
  776. } while (0)
  777. #define ZEND_TRY_ASSIGN_TRUE(zv) \
  778. _ZEND_TRY_ASSIGN_TRUE(zv, 0)
  779. #define ZEND_TRY_ASSIGN_REF_TRUE(zv) do { \
  780. ZEND_ASSERT(Z_ISREF_P(zv)); \
  781. _ZEND_TRY_ASSIGN_TRUE(zv, 1); \
  782. } while (0)
  783. #define _ZEND_TRY_ASSIGN_BOOL(zv, bval, is_ref) do { \
  784. zval *_zv = zv; \
  785. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  786. zend_reference *ref = Z_REF_P(_zv); \
  787. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  788. zend_try_assign_typed_ref_bool(ref, 1); \
  789. break; \
  790. } \
  791. _zv = &ref->val; \
  792. } \
  793. zval_ptr_dtor(_zv); \
  794. ZVAL_BOOL(_zv, bval); \
  795. } while (0)
  796. #define ZEND_TRY_ASSIGN_BOOL(zv, bval) \
  797. _ZEND_TRY_ASSIGN_BOOL(zv, bval, 0)
  798. #define ZEND_TRY_ASSIGN_REF_BOOL(zv, bval) do { \
  799. ZEND_ASSERT(Z_ISREF_P(zv)); \
  800. _ZEND_TRY_ASSIGN_BOOL(zv, bval, 1); \
  801. } while (0)
  802. #define _ZEND_TRY_ASSIGN_LONG(zv, lval, is_ref) do { \
  803. zval *_zv = zv; \
  804. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  805. zend_reference *ref = Z_REF_P(_zv); \
  806. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  807. zend_try_assign_typed_ref_long(ref, lval); \
  808. break; \
  809. } \
  810. _zv = &ref->val; \
  811. } \
  812. zval_ptr_dtor(_zv); \
  813. ZVAL_LONG(_zv, lval); \
  814. } while (0)
  815. #define ZEND_TRY_ASSIGN_LONG(zv, lval) \
  816. _ZEND_TRY_ASSIGN_LONG(zv, lval, 0)
  817. #define ZEND_TRY_ASSIGN_REF_LONG(zv, lval) do { \
  818. ZEND_ASSERT(Z_ISREF_P(zv)); \
  819. _ZEND_TRY_ASSIGN_LONG(zv, lval, 1); \
  820. } while (0)
  821. #define _ZEND_TRY_ASSIGN_DOUBLE(zv, dval, is_ref) do { \
  822. zval *_zv = zv; \
  823. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  824. zend_reference *ref = Z_REF_P(_zv); \
  825. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  826. zend_try_assign_typed_ref_double(ref, dval); \
  827. break; \
  828. } \
  829. _zv = &ref->val; \
  830. } \
  831. zval_ptr_dtor(_zv); \
  832. ZVAL_DOUBLE(_zv, dval); \
  833. } while (0)
  834. #define ZEND_TRY_ASSIGN_DOUBLE(zv, dval) \
  835. _ZEND_TRY_ASSIGN_DOUBLE(zv, dval, 0)
  836. #define ZEND_TRY_ASSIGN_REF_DOUBLE(zv, dval) do { \
  837. ZEND_ASSERT(Z_ISREF_P(zv)); \
  838. _ZEND_TRY_ASSIGN_DOUBLE(zv, dval, 1); \
  839. } while (0)
  840. #define _ZEND_TRY_ASSIGN_EMPTY_STRING(zv, is_ref) do { \
  841. zval *_zv = zv; \
  842. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  843. zend_reference *ref = Z_REF_P(_zv); \
  844. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  845. zend_try_assign_typed_ref_empty_string(ref); \
  846. break; \
  847. } \
  848. _zv = &ref->val; \
  849. } \
  850. zval_ptr_dtor(_zv); \
  851. ZVAL_EMPTY_STRING(_zv); \
  852. } while (0)
  853. #define ZEND_TRY_ASSIGN_EMPTY_STRING(zv) \
  854. _ZEND_TRY_ASSIGN_EMPTY_STRING(zv, 0)
  855. #define ZEND_TRY_ASSIGN_REF_EMPTY_STRING(zv) do { \
  856. ZEND_ASSERT(Z_ISREF_P(zv)); \
  857. _ZEND_TRY_ASSIGN_EMPTY_STRING(zv, 1); \
  858. } while (0)
  859. #define _ZEND_TRY_ASSIGN_STR(zv, str, is_ref) do { \
  860. zval *_zv = zv; \
  861. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  862. zend_reference *ref = Z_REF_P(_zv); \
  863. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  864. zend_try_assign_typed_ref_str(ref, str); \
  865. break; \
  866. } \
  867. _zv = &ref->val; \
  868. } \
  869. zval_ptr_dtor(_zv); \
  870. ZVAL_STR(_zv, str); \
  871. } while (0)
  872. #define ZEND_TRY_ASSIGN_STR(zv, str) \
  873. _ZEND_TRY_ASSIGN_STR(zv, str, 0)
  874. #define ZEND_TRY_ASSIGN_REF_STR(zv, str) do { \
  875. ZEND_ASSERT(Z_ISREF_P(zv)); \
  876. _ZEND_TRY_ASSIGN_STR(zv, str, 1); \
  877. } while (0)
  878. #define _ZEND_TRY_ASSIGN_NEW_STR(zv, str, is_str) do { \
  879. zval *_zv = zv; \
  880. if (is_str || UNEXPECTED(Z_ISREF_P(_zv))) { \
  881. zend_reference *ref = Z_REF_P(_zv); \
  882. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  883. zend_try_assign_typed_ref_str(ref, str); \
  884. break; \
  885. } \
  886. _zv = &ref->val; \
  887. } \
  888. zval_ptr_dtor(_zv); \
  889. ZVAL_NEW_STR(_zv, str); \
  890. } while (0)
  891. #define ZEND_TRY_ASSIGN_NEW_STR(zv, str) \
  892. _ZEND_TRY_ASSIGN_NEW_STR(zv, str, 0)
  893. #define ZEND_TRY_ASSIGN_REF_NEW_STR(zv, str) do { \
  894. ZEND_ASSERT(Z_ISREF_P(zv)); \
  895. _ZEND_TRY_ASSIGN_NEW_STR(zv, str, 1); \
  896. } while (0)
  897. #define _ZEND_TRY_ASSIGN_STRING(zv, string, is_ref) do { \
  898. zval *_zv = zv; \
  899. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  900. zend_reference *ref = Z_REF_P(_zv); \
  901. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  902. zend_try_assign_typed_ref_string(ref, string); \
  903. break; \
  904. } \
  905. _zv = &ref->val; \
  906. } \
  907. zval_ptr_dtor(_zv); \
  908. ZVAL_STRING(_zv, string); \
  909. } while (0)
  910. #define ZEND_TRY_ASSIGN_STRING(zv, string) \
  911. _ZEND_TRY_ASSIGN_STRING(zv, string, 0)
  912. #define ZEND_TRY_ASSIGN_REF_STRING(zv, string) do { \
  913. ZEND_ASSERT(Z_ISREF_P(zv)); \
  914. _ZEND_TRY_ASSIGN_STRING(zv, string, 1); \
  915. } while (0)
  916. #define _ZEND_TRY_ASSIGN_STRINGL(zv, string, len, is_ref) do { \
  917. zval *_zv = zv; \
  918. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  919. zend_reference *ref = Z_REF_P(_zv); \
  920. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  921. zend_try_assign_typed_ref_stringl(ref, string, len); \
  922. break; \
  923. } \
  924. _zv = &ref->val; \
  925. } \
  926. zval_ptr_dtor(_zv); \
  927. ZVAL_STRINGL(_zv, string, len); \
  928. } while (0)
  929. #define ZEND_TRY_ASSIGN_STRINGL(zv, string, len) \
  930. _ZEND_TRY_ASSIGN_STRINGL(zv, string, len, 0)
  931. #define ZEND_TRY_ASSIGN_REF_STRINGL(zv, string, len) do { \
  932. ZEND_ASSERT(Z_ISREF_P(zv)); \
  933. _ZEND_TRY_ASSIGN_STRINGL(zv, string, len, 1); \
  934. } while (0)
  935. #define _ZEND_TRY_ASSIGN_ARR(zv, arr, is_ref) do { \
  936. zval *_zv = zv; \
  937. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  938. zend_reference *ref = Z_REF_P(_zv); \
  939. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  940. zend_try_assign_typed_ref_arr(ref, arr); \
  941. break; \
  942. } \
  943. _zv = &ref->val; \
  944. } \
  945. zval_ptr_dtor(_zv); \
  946. ZVAL_ARR(_zv, arr); \
  947. } while (0)
  948. #define ZEND_TRY_ASSIGN_ARR(zv, arr) \
  949. _ZEND_TRY_ASSIGN_ARR(zv, arr, 0)
  950. #define ZEND_TRY_ASSIGN_REF_ARR(zv, arr) do { \
  951. ZEND_ASSERT(Z_ISREF_P(zv)); \
  952. _ZEND_TRY_ASSIGN_ARR(zv, arr, 1); \
  953. } while (0)
  954. #define _ZEND_TRY_ASSIGN_RES(zv, res, is_ref) do { \
  955. zval *_zv = zv; \
  956. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  957. zend_reference *ref = Z_REF_P(_zv); \
  958. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  959. zend_try_assign_typed_ref_res(ref, res); \
  960. break; \
  961. } \
  962. _zv = &ref->val; \
  963. } \
  964. zval_ptr_dtor(_zv); \
  965. ZVAL_RES(_zv, res); \
  966. } while (0)
  967. #define ZEND_TRY_ASSIGN_RES(zv, res) \
  968. _ZEND_TRY_ASSIGN_RES(zv, res, 0)
  969. #define ZEND_TRY_ASSIGN_REF_RES(zv, res) do { \
  970. ZEND_ASSERT(Z_ISREF_P(zv)); \
  971. _ZEND_TRY_ASSIGN_RES(zv, res, 1); \
  972. } while (0)
  973. #define _ZEND_TRY_ASSIGN_TMP(zv, other_zv, is_ref) do { \
  974. zval *_zv = zv; \
  975. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  976. zend_reference *ref = Z_REF_P(_zv); \
  977. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  978. zend_try_assign_typed_ref(ref, other_zv); \
  979. break; \
  980. } \
  981. _zv = &ref->val; \
  982. } \
  983. zval_ptr_dtor(_zv); \
  984. ZVAL_COPY_VALUE(_zv, other_zv); \
  985. } while (0)
  986. #define ZEND_TRY_ASSIGN_TMP(zv, other_zv) \
  987. _ZEND_TRY_ASSIGN_TMP(zv, other_zv, 0)
  988. #define ZEND_TRY_ASSIGN_REF_TMP(zv, other_zv) do { \
  989. ZEND_ASSERT(Z_ISREF_P(zv)); \
  990. _ZEND_TRY_ASSIGN_TMP(zv, other_zv, 1); \
  991. } while (0)
  992. #define _ZEND_TRY_ASSIGN_VALUE(zv, other_zv, is_ref) do { \
  993. zval *_zv = zv; \
  994. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  995. zend_reference *ref = Z_REF_P(_zv); \
  996. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  997. zend_try_assign_typed_ref_zval(ref, other_zv); \
  998. break; \
  999. } \
  1000. _zv = &ref->val; \
  1001. } \
  1002. zval_ptr_dtor(_zv); \
  1003. ZVAL_COPY_VALUE(_zv, other_zv); \
  1004. } while (0)
  1005. #define ZEND_TRY_ASSIGN_VALUE(zv, other_zv) \
  1006. _ZEND_TRY_ASSIGN_VALUE(zv, other_zv, 0)
  1007. #define ZEND_TRY_ASSIGN_REF_VALUE(zv, other_zv) do { \
  1008. ZEND_ASSERT(Z_ISREF_P(zv)); \
  1009. _ZEND_TRY_ASSIGN_VALUE(zv, other_zv, 1); \
  1010. } while (0)
  1011. #define ZEND_TRY_ASSIGN_COPY(zv, other_zv) do { \
  1012. Z_TRY_ADDREF_P(other_zv); \
  1013. ZEND_TRY_ASSIGN_VALUE(zv, other_zv); \
  1014. } while (0)
  1015. #define ZEND_TRY_ASSIGN_REF_COPY(zv, other_zv) do { \
  1016. Z_TRY_ADDREF_P(other_zv); \
  1017. ZEND_TRY_ASSIGN_REF_VALUE(zv, other_zv); \
  1018. } while (0)
  1019. #define _ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, is_ref) do { \
  1020. zval *_zv = zv; \
  1021. if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
  1022. zend_reference *ref = Z_REF_P(_zv); \
  1023. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
  1024. zend_try_assign_typed_ref_zval_ex(ref, other_zv, strict); \
  1025. break; \
  1026. } \
  1027. _zv = &ref->val; \
  1028. } \
  1029. zval_ptr_dtor(_zv); \
  1030. ZVAL_COPY_VALUE(_zv, other_zv); \
  1031. } while (0)
  1032. #define ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict) \
  1033. _ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, 0)
  1034. #define ZEND_TRY_ASSIGN_REF_VALUE_EX(zv, other_zv, strict) do { \
  1035. ZEND_ASSERT(Z_ISREF_P(zv)); \
  1036. _ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, 1); \
  1037. } while (0)
  1038. #define ZEND_TRY_ASSIGN_COPY_EX(zv, other_zv, strict) do { \
  1039. Z_TRY_ADDREF_P(other_zv); \
  1040. ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict); \
  1041. } while (0)
  1042. #define ZEND_TRY_ASSIGN_REF_COPY_EX(zv, other_zv, strict) do { \
  1043. Z_TRY_ADDREF_P(other_zv); \
  1044. ZEND_TRY_ASSIGN_REF_VALUE_EX(zv, other_zv, strict); \
  1045. } while (0)
  1046. /* Initializes a reference to an empty array and returns dereferenced zval,
  1047. * or NULL if the initialization failed. */
  1048. static zend_always_inline zval *zend_try_array_init_size(zval *zv, uint32_t size)
  1049. {
  1050. zend_array *arr = zend_new_array(size);
  1051. if (EXPECTED(Z_ISREF_P(zv))) {
  1052. zend_reference *ref = Z_REF_P(zv);
  1053. if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
  1054. if (zend_try_assign_typed_ref_arr(ref, arr) == FAILURE) {
  1055. return NULL;
  1056. }
  1057. return &ref->val;
  1058. }
  1059. zv = &ref->val;
  1060. }
  1061. zval_ptr_dtor(zv);
  1062. ZVAL_ARR(zv, arr);
  1063. return zv;
  1064. }
  1065. static zend_always_inline zval *zend_try_array_init(zval *zv)
  1066. {
  1067. return zend_try_array_init_size(zv, 0);
  1068. }
  1069. /* Fast parameter parsing API */
  1070. /* Fast ZPP is always enabled now; this define is left in for compatibility
  1071. * with any existing conditional compilation blocks.
  1072. */
  1073. #define FAST_ZPP 1
  1074. #define Z_EXPECTED_TYPES(_) \
  1075. _(Z_EXPECTED_LONG, "of type int") \
  1076. _(Z_EXPECTED_LONG_OR_NULL, "of type ?int") \
  1077. _(Z_EXPECTED_BOOL, "of type bool") \
  1078. _(Z_EXPECTED_BOOL_OR_NULL, "of type ?bool") \
  1079. _(Z_EXPECTED_STRING, "of type string") \
  1080. _(Z_EXPECTED_STRING_OR_NULL, "of type ?string") \
  1081. _(Z_EXPECTED_ARRAY, "of type array") \
  1082. _(Z_EXPECTED_ARRAY_OR_NULL, "of type ?array") \
  1083. _(Z_EXPECTED_ARRAY_OR_LONG, "of type array|int") \
  1084. _(Z_EXPECTED_ARRAY_OR_LONG_OR_NULL, "of type array|int|null") \
  1085. _(Z_EXPECTED_ITERABLE, "of type iterable") \
  1086. _(Z_EXPECTED_ITERABLE_OR_NULL, "of type ?iterable") \
  1087. _(Z_EXPECTED_FUNC, "a valid callback") \
  1088. _(Z_EXPECTED_FUNC_OR_NULL, "a valid callback or null") \
  1089. _(Z_EXPECTED_RESOURCE, "of type resource") \
  1090. _(Z_EXPECTED_RESOURCE_OR_NULL, "of type resource or null") \
  1091. _(Z_EXPECTED_PATH, "of type string") \
  1092. _(Z_EXPECTED_PATH_OR_NULL, "of type ?string") \
  1093. _(Z_EXPECTED_OBJECT, "of type object") \
  1094. _(Z_EXPECTED_OBJECT_OR_NULL, "of type ?object") \
  1095. _(Z_EXPECTED_DOUBLE, "of type float") \
  1096. _(Z_EXPECTED_DOUBLE_OR_NULL, "of type ?float") \
  1097. _(Z_EXPECTED_NUMBER, "of type int|float") \
  1098. _(Z_EXPECTED_NUMBER_OR_NULL, "of type int|float|null") \
  1099. _(Z_EXPECTED_ARRAY_OR_STRING, "of type array|string") \
  1100. _(Z_EXPECTED_ARRAY_OR_STRING_OR_NULL, "of type array|string|null") \
  1101. _(Z_EXPECTED_STRING_OR_LONG, "of type string|int") \
  1102. _(Z_EXPECTED_STRING_OR_LONG_OR_NULL, "of type string|int|null") \
  1103. _(Z_EXPECTED_OBJECT_OR_CLASS_NAME, "an object or a valid class name") \
  1104. _(Z_EXPECTED_OBJECT_OR_CLASS_NAME_OR_NULL, "an object, a valid class name, or null") \
  1105. _(Z_EXPECTED_OBJECT_OR_STRING, "of type object|string") \
  1106. _(Z_EXPECTED_OBJECT_OR_STRING_OR_NULL, "of type object|string|null") \
  1107. #define Z_EXPECTED_TYPE
  1108. #define Z_EXPECTED_TYPE_ENUM(id, str) id,
  1109. #define Z_EXPECTED_TYPE_STR(id, str) str,
  1110. typedef enum _zend_expected_type {
  1111. Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
  1112. Z_EXPECTED_LAST
  1113. } zend_expected_type;
  1114. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
  1115. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args);
  1116. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, uint32_t num, char *name, zend_expected_type expected_type, zval *arg);
  1117. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, zval *arg);
  1118. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, zval *arg);
  1119. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(uint32_t num, const char *name, zval *arg);
  1120. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_error(uint32_t num, const char *name, zval *arg);
  1121. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_or_null_error(uint32_t num, const char *name, zval *arg);
  1122. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_string_error(uint32_t num, const char *name, zval *arg);
  1123. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_string_or_null_error(uint32_t num, const char *name, zval *arg);
  1124. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(uint32_t num, char *error);
  1125. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_or_null_error(uint32_t num, char *error);
  1126. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_unexpected_extra_named_error(void);
  1127. ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_entry *error_ce, uint32_t arg_num, const char *format, va_list va);
  1128. ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
  1129. ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
  1130. ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format, ...);
  1131. #define ZPP_ERROR_OK 0
  1132. #define ZPP_ERROR_FAILURE 1
  1133. #define ZPP_ERROR_WRONG_CALLBACK 2
  1134. #define ZPP_ERROR_WRONG_CLASS 3
  1135. #define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
  1136. #define ZPP_ERROR_WRONG_CLASS_OR_STRING 5
  1137. #define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 6
  1138. #define ZPP_ERROR_WRONG_CLASS_OR_LONG 7
  1139. #define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL 8
  1140. #define ZPP_ERROR_WRONG_ARG 9
  1141. #define ZPP_ERROR_WRONG_COUNT 10
  1142. #define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED 11
  1143. #define ZPP_ERROR_WRONG_CALLBACK_OR_NULL 12
  1144. #define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
  1145. const int _flags = (flags); \
  1146. uint32_t _min_num_args = (min_num_args); \
  1147. uint32_t _max_num_args = (uint32_t) (max_num_args); \
  1148. uint32_t _num_args = EX_NUM_ARGS(); \
  1149. uint32_t _i = 0; \
  1150. zval *_real_arg, *_arg = NULL; \
  1151. zend_expected_type _expected_type = Z_EXPECTED_LONG; \
  1152. char *_error = NULL; \
  1153. bool _dummy = 0; \
  1154. bool _optional = 0; \
  1155. int _error_code = ZPP_ERROR_OK; \
  1156. ((void)_i); \
  1157. ((void)_real_arg); \
  1158. ((void)_arg); \
  1159. ((void)_expected_type); \
  1160. ((void)_error); \
  1161. ((void)_optional); \
  1162. ((void)_dummy); \
  1163. \
  1164. do { \
  1165. if (UNEXPECTED(_num_args < _min_num_args) || \
  1166. UNEXPECTED(_num_args > _max_num_args)) { \
  1167. if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
  1168. zend_wrong_parameters_count_error(_min_num_args, _max_num_args); \
  1169. } \
  1170. _error_code = ZPP_ERROR_FAILURE; \
  1171. break; \
  1172. } \
  1173. _real_arg = ZEND_CALL_ARG(execute_data, 0);
  1174. #define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
  1175. ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
  1176. #define ZEND_PARSE_PARAMETERS_NONE() do { \
  1177. if (UNEXPECTED(ZEND_NUM_ARGS() != 0)) { \
  1178. zend_wrong_parameters_none_error(); \
  1179. return; \
  1180. } \
  1181. } while (0)
  1182. #define ZEND_PARSE_PARAMETERS_END_EX(failure) \
  1183. ZEND_ASSERT(_i == _max_num_args || _max_num_args == (uint32_t) -1); \
  1184. } while (0); \
  1185. if (UNEXPECTED(_error_code != ZPP_ERROR_OK)) { \
  1186. if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
  1187. zend_wrong_parameter_error(_error_code, _i, _error, _expected_type, _arg); \
  1188. } \
  1189. failure; \
  1190. } \
  1191. } while (0)
  1192. #define ZEND_PARSE_PARAMETERS_END() \
  1193. ZEND_PARSE_PARAMETERS_END_EX(return)
  1194. #define Z_PARAM_PROLOGUE(deref, separate) \
  1195. ++_i; \
  1196. ZEND_ASSERT(_i <= _min_num_args || _optional==1); \
  1197. ZEND_ASSERT(_i > _min_num_args || _optional==0); \
  1198. if (_optional) { \
  1199. if (UNEXPECTED(_i >_num_args)) break; \
  1200. } \
  1201. _real_arg++; \
  1202. _arg = _real_arg; \
  1203. if (deref) { \
  1204. if (EXPECTED(Z_ISREF_P(_arg))) { \
  1205. _arg = Z_REFVAL_P(_arg); \
  1206. } \
  1207. } \
  1208. if (separate) { \
  1209. SEPARATE_ZVAL_NOREF(_arg); \
  1210. }
  1211. /* old "|" */
  1212. #define Z_PARAM_OPTIONAL \
  1213. _optional = 1;
  1214. /* old "a" */
  1215. #define Z_PARAM_ARRAY_EX2(dest, check_null, deref, separate) \
  1216. Z_PARAM_PROLOGUE(deref, separate); \
  1217. if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
  1218. _expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
  1219. _error_code = ZPP_ERROR_WRONG_ARG; \
  1220. break; \
  1221. }
  1222. #define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
  1223. Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
  1224. #define Z_PARAM_ARRAY(dest) \
  1225. Z_PARAM_ARRAY_EX(dest, 0, 0)
  1226. #define Z_PARAM_ARRAY_OR_NULL(dest) \
  1227. Z_PARAM_ARRAY_EX(dest, 1, 0)
  1228. /* old "A" */
  1229. #define Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, deref, separate) \
  1230. Z_PARAM_PROLOGUE(deref, separate); \
  1231. if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 1))) { \
  1232. _expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
  1233. _error_code = ZPP_ERROR_WRONG_ARG; \
  1234. break; \
  1235. }
  1236. #define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
  1237. Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, separate, separate)
  1238. #define Z_PARAM_ARRAY_OR_OBJECT(dest) \
  1239. Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
  1240. #define Z_PARAM_ITERABLE_EX(dest, check_null) \
  1241. Z_PARAM_PROLOGUE(0, 0); \
  1242. if (UNEXPECTED(!zend_parse_arg_iterable(_arg, &dest, check_null))) { \
  1243. _expected_type = check_null ? Z_EXPECTED_ITERABLE_OR_NULL : Z_EXPECTED_ITERABLE; \
  1244. _error_code = ZPP_ERROR_WRONG_ARG; \
  1245. break; \
  1246. }
  1247. #define Z_PARAM_ITERABLE(dest) \
  1248. Z_PARAM_ITERABLE_EX(dest, 0)
  1249. #define Z_PARAM_ITERABLE_OR_NULL(dest) \
  1250. Z_PARAM_ITERABLE_EX(dest, 1)
  1251. /* old "b" */
  1252. #define Z_PARAM_BOOL_EX(dest, is_null, check_null, deref) \
  1253. Z_PARAM_PROLOGUE(deref, 0); \
  1254. if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null, _i))) { \
  1255. _expected_type = check_null ? Z_EXPECTED_BOOL_OR_NULL : Z_EXPECTED_BOOL; \
  1256. _error_code = ZPP_ERROR_WRONG_ARG; \
  1257. break; \
  1258. }
  1259. #define Z_PARAM_BOOL(dest) \
  1260. Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
  1261. #define Z_PARAM_BOOL_OR_NULL(dest, is_null) \
  1262. Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
  1263. /* old "C" */
  1264. #define Z_PARAM_CLASS_EX(dest, check_null, deref) \
  1265. Z_PARAM_PROLOGUE(deref, 0); \
  1266. if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
  1267. _error_code = ZPP_ERROR_FAILURE; \
  1268. break; \
  1269. }
  1270. #define Z_PARAM_CLASS(dest) \
  1271. Z_PARAM_CLASS_EX(dest, 0, 0)
  1272. #define Z_PARAM_CLASS_OR_NULL(dest) \
  1273. Z_PARAM_CLASS_EX(dest, 1, 0)
  1274. #define Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, allow_null) \
  1275. Z_PARAM_PROLOGUE(0, 0); \
  1276. if (UNEXPECTED(!zend_parse_arg_obj_or_class_name(_arg, &dest, allow_null))) { \
  1277. _expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_CLASS_NAME_OR_NULL : Z_EXPECTED_OBJECT_OR_CLASS_NAME; \
  1278. _error_code = ZPP_ERROR_WRONG_ARG; \
  1279. break; \
  1280. }
  1281. #define Z_PARAM_OBJ_OR_CLASS_NAME(dest) \
  1282. Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, 0);
  1283. #define Z_PARAM_OBJ_OR_CLASS_NAME_OR_NULL(dest) \
  1284. Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, 1);
  1285. #define Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, allow_null) \
  1286. Z_PARAM_PROLOGUE(0, 0); \
  1287. if (UNEXPECTED(!zend_parse_arg_obj_or_str(_arg, &destination_object, NULL, &destination_string, allow_null, _i))) { \
  1288. _expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_STRING_OR_NULL : Z_EXPECTED_OBJECT_OR_STRING; \
  1289. _error_code = ZPP_ERROR_WRONG_ARG; \
  1290. break; \
  1291. }
  1292. #define Z_PARAM_OBJ_OR_STR(destination_object, destination_string) \
  1293. Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, 0);
  1294. #define Z_PARAM_OBJ_OR_STR_OR_NULL(destination_object, destination_string) \
  1295. Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, 1);
  1296. #define Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, allow_null) \
  1297. Z_PARAM_PROLOGUE(0, 0); \
  1298. if (UNEXPECTED(!zend_parse_arg_obj_or_str(_arg, &destination_object, base_ce, &destination_string, allow_null, _i))) { \
  1299. if (base_ce) { \
  1300. _error = ZSTR_VAL((base_ce)->name); \
  1301. _error_code = allow_null ? ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL : ZPP_ERROR_WRONG_CLASS_OR_STRING; \
  1302. break; \
  1303. } else { \
  1304. _expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_STRING_OR_NULL : Z_EXPECTED_OBJECT_OR_STRING; \
  1305. _error_code = ZPP_ERROR_WRONG_ARG; \
  1306. break; \
  1307. } \
  1308. }
  1309. #define Z_PARAM_OBJ_OF_CLASS_OR_STR(destination_object, base_ce, destination_string) \
  1310. Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, 0);
  1311. #define Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(destination_object, base_ce, destination_string) \
  1312. Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, 1);
  1313. /* old "d" */
  1314. #define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, deref) \
  1315. Z_PARAM_PROLOGUE(deref, 0); \
  1316. if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null, _i))) { \
  1317. _expected_type = check_null ? Z_EXPECTED_DOUBLE_OR_NULL : Z_EXPECTED_DOUBLE; \
  1318. _error_code = ZPP_ERROR_WRONG_ARG; \
  1319. break; \
  1320. }
  1321. #define Z_PARAM_DOUBLE(dest) \
  1322. Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
  1323. #define Z_PARAM_DOUBLE_OR_NULL(dest, is_null) \
  1324. Z_PARAM_DOUBLE_EX(dest, is_null, 1, 0)
  1325. /* old "f" */
  1326. #define Z_PARAM_FUNC_EX(dest_fci, dest_fcc, check_null, deref) \
  1327. Z_PARAM_PROLOGUE(deref, 0); \
  1328. if (UNEXPECTED(!zend_parse_arg_func(_arg, &dest_fci, &dest_fcc, check_null, &_error))) { \
  1329. if (!_error) { \
  1330. _expected_type = check_null ? Z_EXPECTED_FUNC_OR_NULL : Z_EXPECTED_FUNC; \
  1331. _error_code = ZPP_ERROR_WRONG_ARG; \
  1332. } else { \
  1333. _error_code = check_null ? ZPP_ERROR_WRONG_CALLBACK_OR_NULL : ZPP_ERROR_WRONG_CALLBACK; \
  1334. } \
  1335. break; \
  1336. } \
  1337. #define Z_PARAM_FUNC(dest_fci, dest_fcc) \
  1338. Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
  1339. #define Z_PARAM_FUNC_OR_NULL(dest_fci, dest_fcc) \
  1340. Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 1, 0)
  1341. /* old "h" */
  1342. #define Z_PARAM_ARRAY_HT_EX2(dest, check_null, deref, separate) \
  1343. Z_PARAM_PROLOGUE(deref, separate); \
  1344. if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 0, separate))) { \
  1345. _expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
  1346. _error_code = ZPP_ERROR_WRONG_ARG; \
  1347. break; \
  1348. }
  1349. #define Z_PARAM_ARRAY_HT_EX(dest, check_null, separate) \
  1350. Z_PARAM_ARRAY_HT_EX2(dest, check_null, separate, separate)
  1351. #define Z_PARAM_ARRAY_HT(dest) \
  1352. Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
  1353. #define Z_PARAM_ARRAY_HT_OR_NULL(dest) \
  1354. Z_PARAM_ARRAY_HT_EX(dest, 1, 0)
  1355. #define Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, is_null, allow_null) \
  1356. Z_PARAM_PROLOGUE(0, 0); \
  1357. if (UNEXPECTED(!zend_parse_arg_array_ht_or_long(_arg, &dest_ht, &dest_long, &is_null, allow_null, _i))) { \
  1358. _expected_type = allow_null ? Z_EXPECTED_ARRAY_OR_LONG_OR_NULL : Z_EXPECTED_ARRAY_OR_LONG; \
  1359. _error_code = ZPP_ERROR_WRONG_ARG; \
  1360. break; \
  1361. }
  1362. #define Z_PARAM_ARRAY_HT_OR_LONG(dest_ht, dest_long) \
  1363. Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, _dummy, 0)
  1364. #define Z_PARAM_ARRAY_HT_OR_LONG_OR_NULL(dest_ht, dest_long, is_null) \
  1365. Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, is_null, 1)
  1366. /* old "H" */
  1367. #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, deref, separate) \
  1368. Z_PARAM_PROLOGUE(deref, separate); \
  1369. if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 1, separate))) { \
  1370. _expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
  1371. _error_code = ZPP_ERROR_WRONG_ARG; \
  1372. break; \
  1373. }
  1374. #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, check_null, separate) \
  1375. Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, separate, separate)
  1376. #define Z_PARAM_ARRAY_OR_OBJECT_HT(dest) \
  1377. Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, 0, 0)
  1378. /* old "l" */
  1379. #define Z_PARAM_LONG_EX(dest, is_null, check_null, deref) \
  1380. Z_PARAM_PROLOGUE(deref, 0); \
  1381. if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, _i))) { \
  1382. _expected_type = check_null ? Z_EXPECTED_LONG_OR_NULL : Z_EXPECTED_LONG; \
  1383. _error_code = ZPP_ERROR_WRONG_ARG; \
  1384. break; \
  1385. }
  1386. #define Z_PARAM_LONG(dest) \
  1387. Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
  1388. #define Z_PARAM_LONG_OR_NULL(dest, is_null) \
  1389. Z_PARAM_LONG_EX(dest, is_null, 1, 0)
  1390. /* old "n" */
  1391. #define Z_PARAM_NUMBER_EX(dest, check_null) \
  1392. Z_PARAM_PROLOGUE(0, 0); \
  1393. if (UNEXPECTED(!zend_parse_arg_number(_arg, &dest, check_null, _i))) { \
  1394. _expected_type = check_null ? Z_EXPECTED_NUMBER_OR_NULL : Z_EXPECTED_NUMBER; \
  1395. _error_code = ZPP_ERROR_WRONG_ARG; \
  1396. break; \
  1397. }
  1398. #define Z_PARAM_NUMBER_OR_NULL(dest) \
  1399. Z_PARAM_NUMBER_EX(dest, 1)
  1400. #define Z_PARAM_NUMBER(dest) \
  1401. Z_PARAM_NUMBER_EX(dest, 0)
  1402. /* old "o" */
  1403. #define Z_PARAM_OBJECT_EX(dest, check_null, deref) \
  1404. Z_PARAM_PROLOGUE(deref, 0); \
  1405. if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, NULL, check_null))) { \
  1406. _expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
  1407. _error_code = ZPP_ERROR_WRONG_ARG; \
  1408. break; \
  1409. }
  1410. #define Z_PARAM_OBJECT(dest) \
  1411. Z_PARAM_OBJECT_EX(dest, 0, 0)
  1412. #define Z_PARAM_OBJECT_OR_NULL(dest) \
  1413. Z_PARAM_OBJECT_EX(dest, 1, 0)
  1414. /* The same as Z_PARAM_OBJECT_EX except that dest is a zend_object rather than a zval */
  1415. #define Z_PARAM_OBJ_EX(dest, check_null, deref) \
  1416. Z_PARAM_PROLOGUE(deref, 0); \
  1417. if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, NULL, check_null))) { \
  1418. _expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
  1419. _error_code = ZPP_ERROR_WRONG_ARG; \
  1420. break; \
  1421. }
  1422. #define Z_PARAM_OBJ(dest) \
  1423. Z_PARAM_OBJ_EX(dest, 0, 0)
  1424. #define Z_PARAM_OBJ_OR_NULL(dest) \
  1425. Z_PARAM_OBJ_EX(dest, 1, 0)
  1426. /* old "O" */
  1427. #define Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, check_null, deref) \
  1428. Z_PARAM_PROLOGUE(deref, 0); \
  1429. if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, _ce, check_null))) { \
  1430. if (_ce) { \
  1431. _error = ZSTR_VAL((_ce)->name); \
  1432. _error_code = check_null ? ZPP_ERROR_WRONG_CLASS_OR_NULL : ZPP_ERROR_WRONG_CLASS; \
  1433. break; \
  1434. } else { \
  1435. _expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
  1436. _error_code = ZPP_ERROR_WRONG_ARG; \
  1437. break; \
  1438. } \
  1439. }
  1440. #define Z_PARAM_OBJECT_OF_CLASS(dest, _ce) \
  1441. Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 0, 0)
  1442. #define Z_PARAM_OBJECT_OF_CLASS_OR_NULL(dest, _ce) \
  1443. Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 1, 0)
  1444. /* The same as Z_PARAM_OBJECT_OF_CLASS_EX except that dest is a zend_object rather than a zval */
  1445. #define Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, check_null, deref) \
  1446. Z_PARAM_PROLOGUE(deref, 0); \
  1447. if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, _ce, check_null))) { \
  1448. if (_ce) { \
  1449. _error = ZSTR_VAL((_ce)->name); \
  1450. _error_code = check_null ? ZPP_ERROR_WRONG_CLASS_OR_NULL : ZPP_ERROR_WRONG_CLASS; \
  1451. break; \
  1452. } else { \
  1453. _expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
  1454. _error_code = ZPP_ERROR_WRONG_ARG; \
  1455. break; \
  1456. } \
  1457. }
  1458. #define Z_PARAM_OBJ_OF_CLASS(dest, _ce) \
  1459. Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 0, 0)
  1460. #define Z_PARAM_OBJ_OF_CLASS_OR_NULL(dest, _ce) \
  1461. Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 1, 0)
  1462. #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, is_null, allow_null) \
  1463. Z_PARAM_PROLOGUE(0, 0); \
  1464. if (UNEXPECTED(!zend_parse_arg_obj_or_long(_arg, &dest_obj, _ce, &dest_long, &is_null, allow_null, _i))) { \
  1465. _error = ZSTR_VAL((_ce)->name); \
  1466. _error_code = allow_null ? ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL : ZPP_ERROR_WRONG_CLASS_OR_LONG; \
  1467. break; \
  1468. }
  1469. #define Z_PARAM_OBJ_OF_CLASS_OR_LONG(dest_obj, _ce, dest_long) \
  1470. Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, _dummy, 0)
  1471. #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL(dest_obj, _ce, dest_long, is_null) \
  1472. Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, is_null, 1)
  1473. /* old "p" */
  1474. #define Z_PARAM_PATH_EX(dest, dest_len, check_null, deref) \
  1475. Z_PARAM_PROLOGUE(deref, 0); \
  1476. if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null, _i))) { \
  1477. _expected_type = check_null ? Z_EXPECTED_PATH_OR_NULL : Z_EXPECTED_PATH; \
  1478. _error_code = ZPP_ERROR_WRONG_ARG; \
  1479. break; \
  1480. }
  1481. #define Z_PARAM_PATH(dest, dest_len) \
  1482. Z_PARAM_PATH_EX(dest, dest_len, 0, 0)
  1483. #define Z_PARAM_PATH_OR_NULL(dest, dest_len) \
  1484. Z_PARAM_PATH_EX(dest, dest_len, 1, 0)
  1485. /* old "P" */
  1486. #define Z_PARAM_PATH_STR_EX(dest, check_null, deref) \
  1487. Z_PARAM_PROLOGUE(deref, 0); \
  1488. if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null, _i))) { \
  1489. _expected_type = check_null ? Z_EXPECTED_PATH_OR_NULL : Z_EXPECTED_PATH; \
  1490. _error_code = ZPP_ERROR_WRONG_ARG; \
  1491. break; \
  1492. }
  1493. #define Z_PARAM_PATH_STR(dest) \
  1494. Z_PARAM_PATH_STR_EX(dest, 0, 0)
  1495. #define Z_PARAM_PATH_STR_OR_NULL(dest) \
  1496. Z_PARAM_PATH_STR_EX(dest, 1, 0)
  1497. /* old "r" */
  1498. #define Z_PARAM_RESOURCE_EX(dest, check_null, deref) \
  1499. Z_PARAM_PROLOGUE(deref, 0); \
  1500. if (UNEXPECTED(!zend_parse_arg_resource(_arg, &dest, check_null))) { \
  1501. _expected_type = check_null ? Z_EXPECTED_RESOURCE_OR_NULL : Z_EXPECTED_RESOURCE; \
  1502. _error_code = ZPP_ERROR_WRONG_ARG; \
  1503. break; \
  1504. }
  1505. #define Z_PARAM_RESOURCE(dest) \
  1506. Z_PARAM_RESOURCE_EX(dest, 0, 0)
  1507. #define Z_PARAM_RESOURCE_OR_NULL(dest) \
  1508. Z_PARAM_RESOURCE_EX(dest, 1, 0)
  1509. /* old "s" */
  1510. #define Z_PARAM_STRING_EX(dest, dest_len, check_null, deref) \
  1511. Z_PARAM_PROLOGUE(deref, 0); \
  1512. if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null, _i))) { \
  1513. _expected_type = check_null ? Z_EXPECTED_STRING_OR_NULL : Z_EXPECTED_STRING; \
  1514. _error_code = ZPP_ERROR_WRONG_ARG; \
  1515. break; \
  1516. }
  1517. #define Z_PARAM_STRING(dest, dest_len) \
  1518. Z_PARAM_STRING_EX(dest, dest_len, 0, 0)
  1519. #define Z_PARAM_STRING_OR_NULL(dest, dest_len) \
  1520. Z_PARAM_STRING_EX(dest, dest_len, 1, 0)
  1521. /* old "S" */
  1522. #define Z_PARAM_STR_EX(dest, check_null, deref) \
  1523. Z_PARAM_PROLOGUE(deref, 0); \
  1524. if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null, _i))) { \
  1525. _expected_type = check_null ? Z_EXPECTED_STRING_OR_NULL : Z_EXPECTED_STRING; \
  1526. _error_code = ZPP_ERROR_WRONG_ARG; \
  1527. break; \
  1528. }
  1529. #define Z_PARAM_STR(dest) \
  1530. Z_PARAM_STR_EX(dest, 0, 0)
  1531. #define Z_PARAM_STR_OR_NULL(dest) \
  1532. Z_PARAM_STR_EX(dest, 1, 0)
  1533. /* old "z" */
  1534. #define Z_PARAM_ZVAL_EX2(dest, check_null, deref, separate) \
  1535. Z_PARAM_PROLOGUE(deref, separate); \
  1536. zend_parse_arg_zval_deref(_arg, &dest, check_null);
  1537. #define Z_PARAM_ZVAL_EX(dest, check_null, separate) \
  1538. Z_PARAM_ZVAL_EX2(dest, check_null, separate, separate)
  1539. #define Z_PARAM_ZVAL(dest) \
  1540. Z_PARAM_ZVAL_EX(dest, 0, 0)
  1541. #define Z_PARAM_ZVAL_OR_NULL(dest) \
  1542. Z_PARAM_ZVAL_EX(dest, 1, 0)
  1543. /* old "+" and "*" */
  1544. #define Z_PARAM_VARIADIC_EX(spec, dest, dest_num, post_varargs) do { \
  1545. uint32_t _num_varargs = _num_args - _i - (post_varargs); \
  1546. if (EXPECTED(_num_varargs > 0)) { \
  1547. dest = _real_arg + 1; \
  1548. dest_num = _num_varargs; \
  1549. _i += _num_varargs; \
  1550. _real_arg += _num_varargs; \
  1551. } else { \
  1552. dest = NULL; \
  1553. dest_num = 0; \
  1554. } \
  1555. if (UNEXPECTED(ZEND_CALL_INFO(execute_data) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) { \
  1556. _error_code = ZPP_ERROR_UNEXPECTED_EXTRA_NAMED; \
  1557. break; \
  1558. } \
  1559. } while (0);
  1560. #define Z_PARAM_VARIADIC(spec, dest, dest_num) \
  1561. Z_PARAM_VARIADIC_EX(spec, dest, dest_num, 0)
  1562. #define Z_PARAM_VARIADIC_WITH_NAMED(dest, dest_num, dest_named) do { \
  1563. int _num_varargs = _num_args - _i; \
  1564. if (EXPECTED(_num_varargs > 0)) { \
  1565. dest = _real_arg + 1; \
  1566. dest_num = _num_varargs; \
  1567. } else { \
  1568. dest = NULL; \
  1569. dest_num = 0; \
  1570. } \
  1571. if (ZEND_CALL_INFO(execute_data) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { \
  1572. dest_named = execute_data->extra_named_params; \
  1573. } else { \
  1574. dest_named = NULL; \
  1575. } \
  1576. } while (0);
  1577. #define Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, allow_null) \
  1578. Z_PARAM_PROLOGUE(0, 0); \
  1579. if (UNEXPECTED(!zend_parse_arg_array_ht_or_str(_arg, &dest_ht, &dest_str, allow_null, _i))) { \
  1580. _expected_type = allow_null ? Z_EXPECTED_ARRAY_OR_STRING_OR_NULL : Z_EXPECTED_ARRAY_OR_STRING; \
  1581. _error_code = ZPP_ERROR_WRONG_ARG; \
  1582. break; \
  1583. }
  1584. #define Z_PARAM_ARRAY_HT_OR_STR(dest_ht, dest_str) \
  1585. Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, 0);
  1586. #define Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(dest_ht, dest_str) \
  1587. Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, 1);
  1588. #define Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, is_null, allow_null) \
  1589. Z_PARAM_PROLOGUE(0, 0); \
  1590. if (UNEXPECTED(!zend_parse_arg_str_or_long(_arg, &dest_str, &dest_long, &is_null, allow_null, _i))) { \
  1591. _expected_type = allow_null ? Z_EXPECTED_STRING_OR_LONG_OR_NULL : Z_EXPECTED_STRING_OR_LONG; \
  1592. _error_code = ZPP_ERROR_WRONG_ARG; \
  1593. break; \
  1594. }
  1595. #define Z_PARAM_STR_OR_LONG(dest_str, dest_long) \
  1596. Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, _dummy, 0);
  1597. #define Z_PARAM_STR_OR_LONG_OR_NULL(dest_str, dest_long, is_null) \
  1598. Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, is_null, 1);
  1599. /* End of new parameter parsing API */
  1600. /* Inlined implementations shared by new and old parameter parsing APIs */
  1601. ZEND_API bool ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, uint32_t num, bool check_null);
  1602. ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_slow(zval *arg, bool *dest, uint32_t arg_num);
  1603. ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, bool *dest, uint32_t arg_num);
  1604. ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_slow(zval *arg, zend_long *dest, uint32_t arg_num);
  1605. ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest, uint32_t arg_num);
  1606. ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_slow(zval *arg, double *dest, uint32_t arg_num);
  1607. ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest, uint32_t arg_num);
  1608. ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_slow(zval *arg, zend_string **dest, uint32_t arg_num);
  1609. ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest, uint32_t arg_num);
  1610. ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest, uint32_t arg_num);
  1611. ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_or_long_slow(zval *arg, zend_string **dest_str, zend_long *dest_long, uint32_t arg_num);
  1612. static zend_always_inline bool zend_parse_arg_bool(zval *arg, bool *dest, bool *is_null, bool check_null, uint32_t arg_num)
  1613. {
  1614. if (check_null) {
  1615. *is_null = 0;
  1616. }
  1617. if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
  1618. *dest = 1;
  1619. } else if (EXPECTED(Z_TYPE_P(arg) == IS_FALSE)) {
  1620. *dest = 0;
  1621. } else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
  1622. *is_null = 1;
  1623. *dest = 0;
  1624. } else {
  1625. return zend_parse_arg_bool_slow(arg, dest, arg_num);
  1626. }
  1627. return 1;
  1628. }
  1629. static zend_always_inline bool zend_parse_arg_long(zval *arg, zend_long *dest, bool *is_null, bool check_null, uint32_t arg_num)
  1630. {
  1631. if (check_null) {
  1632. *is_null = 0;
  1633. }
  1634. if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
  1635. *dest = Z_LVAL_P(arg);
  1636. } else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
  1637. *is_null = 1;
  1638. *dest = 0;
  1639. } else {
  1640. return zend_parse_arg_long_slow(arg, dest, arg_num);
  1641. }
  1642. return 1;
  1643. }
  1644. static zend_always_inline bool zend_parse_arg_double(zval *arg, double *dest, bool *is_null, bool check_null, uint32_t arg_num)
  1645. {
  1646. if (check_null) {
  1647. *is_null = 0;
  1648. }
  1649. if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
  1650. *dest = Z_DVAL_P(arg);
  1651. } else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
  1652. *is_null = 1;
  1653. *dest = 0.0;
  1654. } else {
  1655. return zend_parse_arg_double_slow(arg, dest, arg_num);
  1656. }
  1657. return 1;
  1658. }
  1659. static zend_always_inline bool zend_parse_arg_number(zval *arg, zval **dest, bool check_null, uint32_t arg_num)
  1660. {
  1661. if (EXPECTED(Z_TYPE_P(arg) == IS_LONG || Z_TYPE_P(arg) == IS_DOUBLE)) {
  1662. *dest = arg;
  1663. } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1664. *dest = NULL;
  1665. } else {
  1666. return zend_parse_arg_number_slow(arg, dest, arg_num);
  1667. }
  1668. return 1;
  1669. }
  1670. static zend_always_inline bool zend_parse_arg_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
  1671. {
  1672. if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
  1673. *dest = Z_STR_P(arg);
  1674. } else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
  1675. *dest = NULL;
  1676. } else {
  1677. return zend_parse_arg_str_slow(arg, dest, arg_num);
  1678. }
  1679. return 1;
  1680. }
  1681. static zend_always_inline bool zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, bool check_null, uint32_t arg_num)
  1682. {
  1683. zend_string *str;
  1684. if (!zend_parse_arg_str(arg, &str, check_null, arg_num)) {
  1685. return 0;
  1686. }
  1687. if (check_null && UNEXPECTED(!str)) {
  1688. *dest = NULL;
  1689. *dest_len = 0;
  1690. } else {
  1691. *dest = ZSTR_VAL(str);
  1692. *dest_len = ZSTR_LEN(str);
  1693. }
  1694. return 1;
  1695. }
  1696. static zend_always_inline bool zend_parse_arg_path_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
  1697. {
  1698. if (!zend_parse_arg_str(arg, dest, check_null, arg_num) ||
  1699. (*dest && UNEXPECTED(CHECK_NULL_PATH(ZSTR_VAL(*dest), ZSTR_LEN(*dest))))) {
  1700. return 0;
  1701. }
  1702. return 1;
  1703. }
  1704. static zend_always_inline bool zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, bool check_null, uint32_t arg_num)
  1705. {
  1706. zend_string *str;
  1707. if (!zend_parse_arg_path_str(arg, &str, check_null, arg_num)) {
  1708. return 0;
  1709. }
  1710. if (check_null && UNEXPECTED(!str)) {
  1711. *dest = NULL;
  1712. *dest_len = 0;
  1713. } else {
  1714. *dest = ZSTR_VAL(str);
  1715. *dest_len = ZSTR_LEN(str);
  1716. }
  1717. return 1;
  1718. }
  1719. static zend_always_inline bool zend_parse_arg_iterable(zval *arg, zval **dest, bool check_null)
  1720. {
  1721. if (EXPECTED(zend_is_iterable(arg))) {
  1722. *dest = arg;
  1723. return 1;
  1724. }
  1725. if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1726. *dest = NULL;
  1727. return 1;
  1728. }
  1729. return 0;
  1730. }
  1731. static zend_always_inline bool zend_parse_arg_array(zval *arg, zval **dest, bool check_null, bool or_object)
  1732. {
  1733. if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY) ||
  1734. (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT))) {
  1735. *dest = arg;
  1736. } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1737. *dest = NULL;
  1738. } else {
  1739. return 0;
  1740. }
  1741. return 1;
  1742. }
  1743. static zend_always_inline bool zend_parse_arg_array_ht(zval *arg, HashTable **dest, bool check_null, bool or_object, bool separate)
  1744. {
  1745. if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
  1746. *dest = Z_ARRVAL_P(arg);
  1747. } else if (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
  1748. zend_object *zobj = Z_OBJ_P(arg);
  1749. if (separate
  1750. && zobj->properties
  1751. && UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
  1752. if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
  1753. GC_DELREF(zobj->properties);
  1754. }
  1755. zobj->properties = zend_array_dup(zobj->properties);
  1756. }
  1757. *dest = zobj->handlers->get_properties(zobj);
  1758. } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1759. *dest = NULL;
  1760. } else {
  1761. return 0;
  1762. }
  1763. return 1;
  1764. }
  1765. static zend_always_inline bool zend_parse_arg_array_ht_or_long(
  1766. zval *arg, HashTable **dest_ht, zend_long *dest_long, bool *is_null, bool allow_null, uint32_t arg_num
  1767. ) {
  1768. if (allow_null) {
  1769. *is_null = 0;
  1770. }
  1771. if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
  1772. *dest_ht = Z_ARRVAL_P(arg);
  1773. } else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
  1774. *dest_ht = NULL;
  1775. *dest_long = Z_LVAL_P(arg);
  1776. } else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1777. *dest_ht = NULL;
  1778. *is_null = 1;
  1779. } else {
  1780. *dest_ht = NULL;
  1781. return zend_parse_arg_long_slow(arg, dest_long, arg_num);
  1782. }
  1783. return 1;
  1784. }
  1785. static zend_always_inline bool zend_parse_arg_object(zval *arg, zval **dest, zend_class_entry *ce, bool check_null)
  1786. {
  1787. if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
  1788. (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
  1789. *dest = arg;
  1790. } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1791. *dest = NULL;
  1792. } else {
  1793. return 0;
  1794. }
  1795. return 1;
  1796. }
  1797. static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest, zend_class_entry *ce, bool check_null)
  1798. {
  1799. if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
  1800. (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
  1801. *dest = Z_OBJ_P(arg);
  1802. } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1803. *dest = NULL;
  1804. } else {
  1805. return 0;
  1806. }
  1807. return 1;
  1808. }
  1809. static zend_always_inline bool zend_parse_arg_obj_or_long(
  1810. zval *arg, zend_object **dest_obj, zend_class_entry *ce, zend_long *dest_long, bool *is_null, bool allow_null, uint32_t arg_num
  1811. ) {
  1812. if (allow_null) {
  1813. *is_null = 0;
  1814. }
  1815. if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) && EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0)) {
  1816. *dest_obj = Z_OBJ_P(arg);
  1817. } else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
  1818. *dest_obj = NULL;
  1819. *dest_long = Z_LVAL_P(arg);
  1820. } else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1821. *dest_obj = NULL;
  1822. *is_null = 1;
  1823. } else {
  1824. *dest_obj = NULL;
  1825. return zend_parse_arg_long_slow(arg, dest_long, arg_num);
  1826. }
  1827. return 1;
  1828. }
  1829. static zend_always_inline bool zend_parse_arg_resource(zval *arg, zval **dest, bool check_null)
  1830. {
  1831. if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
  1832. *dest = arg;
  1833. } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1834. *dest = NULL;
  1835. } else {
  1836. return 0;
  1837. }
  1838. return 1;
  1839. }
  1840. static zend_always_inline bool zend_parse_arg_func(zval *arg, zend_fcall_info *dest_fci, zend_fcall_info_cache *dest_fcc, bool check_null, char **error)
  1841. {
  1842. if (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1843. dest_fci->size = 0;
  1844. dest_fcc->function_handler = NULL;
  1845. *error = NULL;
  1846. } else if (UNEXPECTED(zend_fcall_info_init(arg, 0, dest_fci, dest_fcc, NULL, error) != SUCCESS)) {
  1847. return 0;
  1848. }
  1849. /* Release call trampolines: The function may not get called, in which case
  1850. * the trampoline will leak. Force it to be refetched during
  1851. * zend_call_function instead. */
  1852. zend_release_fcall_info_cache(dest_fcc);
  1853. return 1;
  1854. }
  1855. static zend_always_inline void zend_parse_arg_zval(zval *arg, zval **dest, bool check_null)
  1856. {
  1857. *dest = (check_null &&
  1858. (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) ||
  1859. (UNEXPECTED(Z_ISREF_P(arg)) &&
  1860. UNEXPECTED(Z_TYPE_P(Z_REFVAL_P(arg)) == IS_NULL)))) ? NULL : arg;
  1861. }
  1862. static zend_always_inline void zend_parse_arg_zval_deref(zval *arg, zval **dest, bool check_null)
  1863. {
  1864. *dest = (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) ? NULL : arg;
  1865. }
  1866. static zend_always_inline bool zend_parse_arg_array_ht_or_str(
  1867. zval *arg, HashTable **dest_ht, zend_string **dest_str, bool allow_null, uint32_t arg_num)
  1868. {
  1869. if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
  1870. *dest_ht = NULL;
  1871. *dest_str = Z_STR_P(arg);
  1872. } else if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
  1873. *dest_ht = Z_ARRVAL_P(arg);
  1874. *dest_str = NULL;
  1875. } else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1876. *dest_ht = NULL;
  1877. *dest_str = NULL;
  1878. } else {
  1879. *dest_ht = NULL;
  1880. return zend_parse_arg_str_slow(arg, dest_str, arg_num);
  1881. }
  1882. return 1;
  1883. }
  1884. static zend_always_inline bool zend_parse_arg_str_or_long(zval *arg, zend_string **dest_str, zend_long *dest_long,
  1885. bool *is_null, bool allow_null, uint32_t arg_num)
  1886. {
  1887. if (allow_null) {
  1888. *is_null = 0;
  1889. }
  1890. if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
  1891. *dest_str = Z_STR_P(arg);
  1892. } else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
  1893. *dest_str = NULL;
  1894. *dest_long = Z_LVAL_P(arg);
  1895. } else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1896. *dest_str = NULL;
  1897. *is_null = 1;
  1898. } else {
  1899. return zend_parse_arg_str_or_long_slow(arg, dest_str, dest_long, arg_num);
  1900. }
  1901. return 1;
  1902. }
  1903. static zend_always_inline bool zend_parse_arg_obj_or_class_name(
  1904. zval *arg, zend_class_entry **destination, bool allow_null
  1905. ) {
  1906. if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
  1907. *destination = zend_lookup_class(Z_STR_P(arg));
  1908. return *destination != NULL;
  1909. } else if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
  1910. *destination = Z_OBJ_P(arg)->ce;
  1911. } else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
  1912. *destination = NULL;
  1913. } else {
  1914. return 0;
  1915. }
  1916. return 1;
  1917. }
  1918. static zend_always_inline bool zend_parse_arg_obj_or_str(
  1919. zval *arg, zend_object **destination_object, zend_class_entry *base_ce, zend_string **destination_string, bool allow_null, uint32_t arg_num
  1920. ) {
  1921. if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
  1922. if (!base_ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), base_ce))) {
  1923. *destination_object = Z_OBJ_P(arg);
  1924. *destination_string = NULL;
  1925. return 1;
  1926. }
  1927. }
  1928. *destination_object = NULL;
  1929. return zend_parse_arg_str(arg, destination_string, allow_null, arg_num);
  1930. }
  1931. END_EXTERN_C()
  1932. #endif /* ZEND_API_H */