diff options
| author | Zeev Suraski <zeev@php.net> | 1999-09-20 13:00:35 +0000 |
|---|---|---|
| committer | Zeev Suraski <zeev@php.net> | 1999-09-20 13:00:35 +0000 |
| commit | 7a4a5944f903aaedcb3e4c5f108f0cb77b43d999 (patch) | |
| tree | 3eaede9fce374e76f9155bb41755ccb050e0a18d | |
| parent | 6c0c410acfc63dbac09e12597cb5c27b3bf9f467 (diff) | |
| download | php-git-7a4a5944f903aaedcb3e4c5f108f0cb77b43d999.tar.gz | |
Added zend_num_args() and zend_get_arg()
| -rw-r--r-- | Zend/libzend.dsp | 16 | ||||
| -rw-r--r-- | Zend/libzendts.dsp | 8 | ||||
| -rw-r--r-- | Zend/zend_builtin_functions.c | 61 |
3 files changed, 81 insertions, 4 deletions
diff --git a/Zend/libzend.dsp b/Zend/libzend.dsp index df47400dbd..89ee8f85a3 100644 --- a/Zend/libzend.dsp +++ b/Zend/libzend.dsp @@ -102,6 +102,10 @@ SOURCE=.\zend_API.c # End Source File # Begin Source File +SOURCE=.\zend_builtin_functions.c +# End Source File +# Begin Source File + SOURCE=.\zend_compile.c # End Source File # Begin Source File @@ -170,10 +174,6 @@ SOURCE=.\zend_variables.c # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File -SOURCE=.\zend_config.w32.h -# End Source File -# Begin Source File - SOURCE=.\FlexLexer.h # End Source File # Begin Source File @@ -202,10 +202,18 @@ SOURCE=.\zend_API.h # End Source File # Begin Source File +SOURCE=.\zend_builtin_functions.h +# End Source File +# Begin Source File + SOURCE=.\zend_compile.h # End Source File # Begin Source File +SOURCE=.\zend_config.w32.h +# End Source File +# Begin Source File + SOURCE=.\zend_constants.h # End Source File # Begin Source File diff --git a/Zend/libzendts.dsp b/Zend/libzendts.dsp index 2af91a1742..7c6e8054bc 100644 --- a/Zend/libzendts.dsp +++ b/Zend/libzendts.dsp @@ -102,6 +102,10 @@ SOURCE=.\zend_API.c # End Source File # Begin Source File +SOURCE=.\zend_builtin_functions.c +# End Source File +# Begin Source File + SOURCE=.\zend_compile.c # End Source File # Begin Source File @@ -198,6 +202,10 @@ SOURCE=.\zend_API.h # End Source File # Begin Source File +SOURCE=.\zend_builtin_functions.h +# End Source File +# Begin Source File + SOURCE=.\zend_compile.h # End Source File # Begin Source File diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index f4f972ba78..e5c7dbbbf9 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -21,11 +21,17 @@ #include "zend.h" #include "zend_API.h" #include "zend_builtin_functions.h" +#include "zend_operators.h" +#include "zend_variables.h" static ZEND_FUNCTION(zend_version); +static ZEND_FUNCTION(zend_num_args); +static ZEND_FUNCTION(zend_get_arg); static zend_function_entry builtin_functions[] = { ZEND_FE(zend_version, NULL) + ZEND_FE(zend_num_args, NULL) + ZEND_FE(zend_get_arg, NULL) { NULL, NULL, NULL } }; @@ -40,3 +46,58 @@ ZEND_FUNCTION(zend_version) { RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1, 1); } + + +ZEND_FUNCTION(zend_num_args) +{ + void **p; + int arg_count; + ELS_FETCH(); + + p = EG(argument_stack).top_element-1; + arg_count = (ulong) *p; /* this is the amount of arguments passed to zend_num_args(); */ + + p = EG(argument_stack).top_element-1-arg_count-1; + if (p>=EG(argument_stack).elements) { + RETURN_LONG((ulong) *p); + } else { + zend_error(E_WARNING, "zend_num_args(): Called from the global scope - no function context"); + RETURN_LONG(-1); + } +} + + +ZEND_FUNCTION(zend_get_arg) +{ + void **p; + int arg_count; + zval **z_requested_offset; + zval *arg; + long requested_offset; + ELS_FETCH(); + + if (ARG_COUNT(ht)!=1 || getParametersEx(1, &z_requested_offset)==FAILURE) { + RETURN_FALSE; + } + convert_to_long_ex(z_requested_offset); + requested_offset = (*z_requested_offset)->value.lval; + + p = EG(argument_stack).top_element-1; + arg_count = (ulong) *p; /* this is the amount of arguments passed to zend_num_args(); */ + + p = EG(argument_stack).top_element-1-arg_count-1; + if (p<EG(argument_stack).elements) { + RETURN_FALSE; + } + arg_count = (ulong) *p; + + if (requested_offset>arg_count) { + zend_error(E_WARNING, "zend_get_arg(): Only %d arguments passed to function (argument %d requested)", arg_count, requested_offset); + RETURN_FALSE; + } + + arg = *(p-(arg_count-requested_offset)); + *return_value = *arg; + zval_copy_ctor(return_value); +} + |
