Back to index

php5  5.3.10
Defines | Enumerations | Functions | Variables
assert.c File Reference
#include "php.h"
#include "php_assert.h"
#include "php_ini.h"

Go to the source code of this file.

Defines

#define ASSERTG(v)   (assert_globals.v)
#define SAFE_STRING(s)   ((s)?(s):"")

Enumerations

enum  {
  ASSERT_ACTIVE = 1, ASSERT_CALLBACK, ASSERT_BAIL, ASSERT_WARNING,
  ASSERT_QUIET_EVAL
}

Functions

static PHP_INI_MH (OnChangeCallback)
static void php_assert_init_globals (zend_assert_globals *assert_globals_p TSRMLS_DC)
 PHP_MINIT_FUNCTION (assert)
 PHP_MSHUTDOWN_FUNCTION (assert)
 PHP_RSHUTDOWN_FUNCTION (assert)
 PHP_MINFO_FUNCTION (assert)
 PHP_FUNCTION (assert)
 PHP_FUNCTION (assert_options)

Variables

long active
long bail
long warning
long quiet_eval
zval * callback
char * cb

Define Documentation

#define ASSERTG (   v)    (assert_globals.v)

Definition at line 41 of file assert.c.

#define SAFE_STRING (   s)    ((s)?(s):"")

Definition at line 44 of file assert.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
ASSERT_ACTIVE 
ASSERT_CALLBACK 
ASSERT_BAIL 
ASSERT_WARNING 
ASSERT_QUIET_EVAL 

Definition at line 46 of file assert.c.


Function Documentation

static void php_assert_init_globals ( zend_assert_globals *assert_globals_p  TSRMLS_DC) [static]

Definition at line 89 of file assert.c.

{
       assert_globals_p->callback = NULL;
       assert_globals_p->cb = NULL;
}

Here is the caller graph for this function:

Definition at line 141 of file assert.c.

{
       zval **assertion;
       int val;
       char *myeval = NULL;
       char *compiled_string_description;

       if (! ASSERTG(active)) {
              RETURN_TRUE;
       }

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &assertion) == FAILURE) {
              return;
       }

       if (Z_TYPE_PP(assertion) == IS_STRING) {
              zval retval;
              int old_error_reporting = 0; /* shut up gcc! */

              myeval = Z_STRVAL_PP(assertion);

              if (ASSERTG(quiet_eval)) {
                     old_error_reporting = EG(error_reporting);
                     EG(error_reporting) = 0;
              }

              compiled_string_description = zend_make_compiled_string_description("assert code" TSRMLS_CC);
              if (zend_eval_stringl(myeval, Z_STRLEN_PP(assertion), &retval, compiled_string_description TSRMLS_CC) == FAILURE) {
                     efree(compiled_string_description);
                     php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Failure evaluating code: %s%s", PHP_EOL, myeval);
                     if (ASSERTG(bail)) {
                            zend_bailout();
                     }
                     RETURN_FALSE;
              }
              efree(compiled_string_description);

              if (ASSERTG(quiet_eval)) {
                     EG(error_reporting) = old_error_reporting;
              }

              convert_to_boolean(&retval);
              val = Z_LVAL(retval);
       } else {
              convert_to_boolean_ex(assertion);
              val = Z_LVAL_PP(assertion);
       }

       if (val) {
              RETURN_TRUE;
       }

       if (!ASSERTG(callback) && ASSERTG(cb)) {
              MAKE_STD_ZVAL(ASSERTG(callback));
              ZVAL_STRING(ASSERTG(callback), ASSERTG(cb), 1);
       }

       if (ASSERTG(callback)) {
              zval *args[3];
              zval *retval;
              int i;
              uint lineno = zend_get_executed_lineno(TSRMLS_C);
              char *filename = zend_get_executed_filename(TSRMLS_C);

              MAKE_STD_ZVAL(args[0]);
              MAKE_STD_ZVAL(args[1]);
              MAKE_STD_ZVAL(args[2]);

              ZVAL_STRING(args[0], SAFE_STRING(filename), 1);
              ZVAL_LONG (args[1], lineno);
              ZVAL_STRING(args[2], SAFE_STRING(myeval), 1);

              MAKE_STD_ZVAL(retval);
              ZVAL_FALSE(retval);

              /* XXX do we want to check for error here? */
              call_user_function(CG(function_table), NULL, ASSERTG(callback), retval, 3, args TSRMLS_CC);

              for (i = 0; i <= 2; i++) {
                     zval_ptr_dtor(&(args[i]));
              }
              zval_ptr_dtor(&retval);
       }

       if (ASSERTG(warning)) {
              if (myeval) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Assertion \"%s\" failed", myeval);
              } else {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Assertion failed");
              }
       }

       if (ASSERTG(bail)) {
              zend_bailout();
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( assert_options  )

Definition at line 241 of file assert.c.

{
       zval **value = NULL;
       long what;
       int oldint;
       int ac = ZEND_NUM_ARGS();

       if (zend_parse_parameters(ac TSRMLS_CC, "l|Z", &what, &value) == FAILURE) {
              return;
       }

       switch (what) {
       case ASSERT_ACTIVE:
              oldint = ASSERTG(active);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.active", sizeof("assert.active"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_BAIL:
              oldint = ASSERTG(bail);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.bail", sizeof("assert.bail"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_QUIET_EVAL:
              oldint = ASSERTG(quiet_eval);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.quiet_eval", sizeof("assert.quiet_eval"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_WARNING:
              oldint = ASSERTG(warning);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.warning", sizeof("assert.warning"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_CALLBACK:
              if (ASSERTG(callback) != NULL) {
                     RETVAL_ZVAL(ASSERTG(callback), 1, 0);
              } else if (ASSERTG(cb)) {
                     RETVAL_STRING(ASSERTG(cb), 1);
              } else {
                     RETVAL_NULL();
              }
              if (ac == 2) {
                     if (ASSERTG(callback)) {
                            zval_ptr_dtor(&ASSERTG(callback));
                     }
                     ASSERTG(callback) = *value;
                     zval_add_ref(value);
              }
              return;
              break;

       default:
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value %ld", what);
              break;
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

static PHP_INI_MH ( OnChangeCallback  ) [static]

Definition at line 54 of file assert.c.

{
       if (EG(in_execution)) {
              if (ASSERTG(callback)) {
                     zval_ptr_dtor(&ASSERTG(callback));
                     ASSERTG(callback) = NULL;
              }
              if (new_value && (ASSERTG(callback) || new_value_length)) {
                     MAKE_STD_ZVAL(ASSERTG(callback));
                     ZVAL_STRINGL(ASSERTG(callback), new_value, new_value_length, 1);
              }
       } else {
              if (ASSERTG(cb)) {
                     pefree(ASSERTG(cb), 1);
              }
              if (new_value && new_value_length) {
                     ASSERTG(cb) = pemalloc(new_value_length + 1, 1);
                     memcpy(ASSERTG(cb), new_value, new_value_length);
                     ASSERTG(cb)[new_value_length] = '\0';
              } else {
                     ASSERTG(cb) = NULL;
              }
       }
       return SUCCESS;
}

Definition at line 133 of file assert.c.

Definition at line 112 of file assert.c.

{
       if (ASSERTG(cb)) {
              pefree(ASSERTG(cb), 1);
              ASSERTG(cb) = NULL;
       }
       return SUCCESS;
}

Definition at line 122 of file assert.c.


Variable Documentation

long active

Definition at line 28 of file assert.c.

long bail

Definition at line 29 of file assert.c.

zval* callback

Definition at line 32 of file assert.c.

char* cb

Definition at line 33 of file assert.c.

long quiet_eval

Definition at line 31 of file assert.c.

long warning

Definition at line 30 of file assert.c.