// extern void TF_SetAttrBool(TF_OperationDescription* desc, const char* attr_name, // unsigned char value); static PHP_METHOD(TensorFlow_OperationDescription, setAttrBool) { zend_string *name; zend_bool value; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(name) Z_PARAM_BOOL(value) ZEND_PARSE_PARAMETERS_END(); // this t_tf_operation_description_object* intern = TF_OPERATION_DESCRIPTION_P_ZV(getThis()); t_tf_operation_description* node = intern->ptr; TF_SetAttrBool(node->src, name->val, value); }
/* {{{ proto mixed json_decode(string json [, bool assoc [, long depth]]) Decodes the JSON representation into a PHP value */ static PHP_FUNCTION(json_decode) { char *str; size_t str_len; zend_bool assoc = 0; /* return JS objects as PHP objects by default */ zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH; zend_long options = 0; ZEND_PARSE_PARAMETERS_START(1, 4) Z_PARAM_STRING(str, str_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(assoc) Z_PARAM_LONG(depth) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); JSON_G(error_code) = PHP_JSON_ERROR_NONE; if (!str_len) { JSON_G(error_code) = PHP_JSON_ERROR_SYNTAX; RETURN_NULL(); } if (depth <= 0) { php_error_docref(NULL, E_WARNING, "Depth must be greater than zero"); RETURN_NULL(); } if (depth > INT_MAX) { php_error_docref(NULL, E_WARNING, "Depth must be lower than %d", INT_MAX); RETURN_NULL(); } /* For BC reasons, the bool $assoc overrides the long $options bit for PHP_JSON_OBJECT_AS_ARRAY */ if (assoc) { options |= PHP_JSON_OBJECT_AS_ARRAY; } else { options &= ~PHP_JSON_OBJECT_AS_ARRAY; } php_json_decode_ex(return_value, str, str_len, options, depth); }
/** * Get the connectivity state of the channel * @param bool (optional) try to connect on the channel * @return long The grpc connectivity state */ PHP_METHOD(Channel, getConnectivityState) { wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); zend_bool try_to_connect = 0; /* "|b" == 1 optional bool */ #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &try_to_connect) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, "getConnectivityState expects a bool", 1); return; } #else ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_BOOL(try_to_connect) ZEND_PARSE_PARAMETERS_END(); #endif RETURN_LONG(grpc_channel_check_connectivity_state(channel->wrapped, (int)try_to_connect)); }
static zend_always_inline php_hrtime_t _timer_current(void) {/*{{{*/ #if PHP_HRTIME_PLATFORM_WINDOWS LARGE_INTEGER lt = {0}; QueryPerformanceCounter(<); return (php_hrtime_t)((php_hrtime_t)lt.QuadPart * _timer_scale); #elif PHP_HRTIME_PLATFORM_APPLE return (php_hrtime_t)mach_absolute_time() * _timerlib_info.numer / _timerlib_info.denom; #elif PHP_HRTIME_PLATFORM_POSIX struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 }; if (0 == clock_gettime(CLOCK_MONOTONIC, &ts)) { return ((php_hrtime_t) ts.tv_sec * (php_hrtime_t)NANO_IN_SEC) + ts.tv_nsec; } return 0; #elif PHP_HRTIME_PLATFORM_HPUX return (php_hrtime_t) gethrtime(); #elif PHP_HRTIME_PLATFORM_AIX timebasestruct_t t; read_wall_time(&t, TIMEBASE_SZ); time_base_to_time(&t, TIMEBASE_SZ); return (php_hrtime_t) t.tb_high * (php_hrtime_t)NANO_IN_SEC + t.tb_low; #else return 0; #endif }/*}}}*/ #if ZEND_ENABLE_ZVAL_LONG64 #define PHP_RETURN_HRTIME(t) RETURN_LONG((zend_long)t) #else #ifdef _WIN32 # define HRTIME_U64A(i, s, len) _ui64toa_s(i, s, len, 10) #else # define HRTIME_U64A(i, s, len) \ do { \ int st = snprintf(s, len, "%llu", i); \ s[st] = '\0'; \ } while (0) #endif #define PHP_RETURN_HRTIME(t) do { \ char _a[ZEND_LTOA_BUF_LEN]; \ double _d; \ HRTIME_U64A(t, _a, ZEND_LTOA_BUF_LEN); \ _d = zend_strtod(_a, NULL); \ RETURN_DOUBLE(_d); \ } while (0) #endif /* {{{ proto mixed hrtime([bool get_as_number = false]) Returns an array of integers in form [seconds, nanoseconds] counted from an arbitrary point in time. If an optional boolean argument is passed, returns an integer on 64-bit platforms or float on 32-bit containing the current high-resolution time in nanoseconds. The delivered timestamp is monotonic and can not be adjusted. */ PHP_FUNCTION(hrtime) { #if HRTIME_AVAILABLE zend_bool get_as_num = 0; php_hrtime_t t = _timer_current(); ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_BOOL(get_as_num) ZEND_PARSE_PARAMETERS_END(); if (UNEXPECTED(get_as_num)) { PHP_RETURN_HRTIME(t); } else { array_init_size(return_value, 2); zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); add_next_index_long(return_value, (zend_long)(t / (php_hrtime_t)NANO_IN_SEC)); add_next_index_long(return_value, (zend_long)(t % (php_hrtime_t)NANO_IN_SEC)); } #else RETURN_FALSE #endif } /* }}} */ PHPAPI php_hrtime_t php_hrtime_current(void) {/*{{{*/ return _timer_current(); }/*}}}*/