Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Zephir constant get #1928

Closed
chrysanthemum opened this issue Sep 27, 2019 · 0 comments
Closed

Improve Zephir constant get #1928

chrysanthemum opened this issue Sep 27, 2019 · 0 comments
Labels

Comments

@chrysanthemum
Copy link
Contributor

chrysanthemum commented Sep 27, 2019

test/flow/switchflow.zep

    public function testSwitch14(result_type = 1)
    {
        var ret;

        switch (result_type) {
            case 1:
            case MYSQL_ASSOC:
            case MYSQLI_ASSOC:
                let ret = "aaa";      <----- cannot execute
                break;

            default:
                let ret = "bbb";      <----- cannot execute
                break;
        }

        return ret;
    }

ext/test/flow/switchflow.zep.c

PHP_METHOD(Test_Flow_SwitchFlow, testSwitch14) {

	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
	zval *result_type = NULL, result_type_sub, ret, _0;
	zval *this_ptr = getThis();

	ZVAL_UNDEF(&result_type_sub);
	ZVAL_UNDEF(&ret);
	ZVAL_UNDEF(&_0);

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 1, &result_type);

	if (!result_type) {
		result_type = &result_type_sub;
		ZEPHIR_INIT_VAR(result_type);
		ZVAL_LONG(result_type, 1);
	}


	do {
		ZEPHIR_INIT_VAR(&_0);
		ZEPHIR_MM_GET_CONSTANT(&_0, "MYSQL_ASSOC");
		if (ZEPHIR_IS_LONG(result_type, 1) || ZEPHIR_IS_LONG(result_type, 1) || ZEPHIR_IS_EQUAL(result_type, &_0)) {
			ZEPHIR_INIT_VAR(&ret);
			ZVAL_LONG(&ret, 2);
			break;
		}
		ZEPHIR_INIT_NVAR(&ret);
		ZVAL_LONG(&ret, 4);
		break;
	} while(0);

	RETURN_CCTOR(&ret);

}

kernel/main.h

#define ZEPHIR_MM_GET_CONSTANT(return_value, const_name) do { \
	zval *_constant_ptr = zend_get_constant_str(SL(const_name)); \
	if (_constant_ptr == NULL) { \
		ZEPHIR_MM_RESTORE(); \         <----------------------------
		return; \                      <----------------------------
	} \
	ZVAL_COPY(return_value, _constant_ptr); \
} while(0)

To such

#define ZEPHIR_MM_GET_CONSTANT(return_value, const_name) do { \
	zval *_constant_ptr = zend_get_constant_str(SL(const_name)); \
	if (_constant_ptr == NULL) { \
		ZVAL_NULL(_constant_ptr); \      <---------------------------
	} \
	ZVAL_COPY(return_value, _constant_ptr); \
} while(0)

question:

The constant MYSQL_ASSOC is not in php7, or cannot find a constant.
Thus, the following code cannot execute because of the ZEPHIR_MM_GET_CONSTANT macro.
In the switch syntax also do constant detection.
I'd like to ask: Does it make sense to delete the direct return code of the ZEPHIR_MM_GET_CONSTANT macro?

Thank you very much!

@sergeyklay @dreamsxin

@sergeyklay sergeyklay added the bug label Sep 27, 2019
sergeyklay added a commit that referenced this issue Sep 28, 2019
dreamsxin pushed a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants