// extern void TF_SetAttrFloatList(TF_OperationDescription* desc,
//                                 const char* attr_name, const float* values,
//                                 int num_values);
static PHP_METHOD(TensorFlow_OperationDescription, setAttrFloatList)
{
    zend_string *name;
    zval* values;

    ZEND_PARSE_PARAMETERS_START(2, 2)
        Z_PARAM_STR(name)
        Z_PARAM_ARRAY(values)
    ZEND_PARSE_PARAMETERS_END();


    float* tf_values = NULL;
    int tf_num_values = 0;

    HashTable *values_table = Z_ARRVAL_P(values);
    tf_num_values = zend_hash_num_elements(values_table); // count of array

    if (tf_num_values > 0) {
        tf_values = (float*)emalloc(sizeof(float) * tf_num_values);

        HashPosition pos;
        zval* element;
        int index = 0;

        zend_hash_internal_pointer_reset_ex(values_table, &pos);
        while (zend_hash_has_more_elements_ex(values_table, &pos) == SUCCESS) {
            if (!(element = zend_hash_get_current_data_ex(values_table, &pos))) {
                zend_throw_exception(spl_ce_InvalidArgumentException, "values something wrong", 0);
                return;
            }
            if (zval_get_type(element) != IS_DOUBLE) {
                zend_throw_exception(spl_ce_InvalidArgumentException, "values must be array of float", 0);
                return;
            }
            // insert tf_values
            tf_values[index] = Z_DVAL_P(element);
            // php_printf("%d \n", element->value.lval);
            zend_hash_move_forward_ex(values_table, &pos);

            index++;
        }
    }

    // int i;
    // for (i = 0; i < tf_num_values; i++) {
    //     php_printf("values[%f] ? %d\n", i, tf_values[i]);
    // }
    // php_printf("tf_num_values ? %d\n", tf_num_values);

    // this
    t_tf_operation_description_object* intern = TF_OPERATION_DESCRIPTION_P_ZV(getThis());
    t_tf_operation_description* node = intern->ptr;

    TF_SetAttrFloatList(node->src, name->val, tf_values, tf_num_values);
}
Esempio n. 2
0
static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
{
	zend_string *fname, *mime = NULL, *postname = NULL;
	zval *cf = return_value;

	ZEND_PARSE_PARAMETERS_START(1,3)
		Z_PARAM_PATH_STR(fname)
		Z_PARAM_OPTIONAL
		Z_PARAM_STR(mime)
		Z_PARAM_STR(postname)
	ZEND_PARSE_PARAMETERS_END();

	zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, ZSTR_VAL(fname));

	if (mime) {
		zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, ZSTR_VAL(mime));
	}

	if (postname) {
		zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, ZSTR_VAL(postname));
	}
}
Esempio n. 3
0
/**
 * Construct an instance of the Channel class. If the $args array contains a
 * "credentials" key mapping to a ChannelCredentials object, a secure channel
 * will be created with those credentials.
 * @param string $target The hostname to associate with this channel
 * @param array $args The arguments to pass to the Channel (optional)
 */
PHP_METHOD(Channel, __construct) {
  wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
  zend_string *target;
  zval *args_array = NULL;
  grpc_channel_args args;
  HashTable *array_hash;
  zval *creds_obj = NULL;
  wrapped_grpc_channel_credentials *creds = NULL;

  /* "Sa" == 1 string, 1 array */
#ifndef FAST_ZPP
  if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa", &target, &args_array)
      == FAILURE) {
    zend_throw_exception(spl_ce_InvalidArgumentException,
                         "Channel expects a string and an array", 1);
    return;
  }
#else
  ZEND_PARSE_PARAMETERS_START(2, 2)
    Z_PARAM_STR(target)
    Z_PARAM_ARRAY(args_array)
  ZEND_PARSE_PARAMETERS_END();
#endif

  array_hash = HASH_OF(args_array);
  if ((creds_obj = zend_hash_str_find(array_hash, "credentials",
                                      sizeof("credentials") - 1)) != NULL) {
    if (Z_TYPE_P(creds_obj) == IS_NULL) {
      creds = NULL;
      zend_hash_str_del(array_hash, "credentials", sizeof("credentials") - 1);
    } else if (Z_OBJ_P(creds_obj)->ce != grpc_ce_channel_credentials) {
      zend_throw_exception(spl_ce_InvalidArgumentException,
                           "credentials must be a ChannelCredentials object",
                           1);
      return;
    } else {
      creds = Z_WRAPPED_GRPC_CHANNEL_CREDS_P(creds_obj);
      zend_hash_str_del(array_hash, "credentials", sizeof("credentials") - 1);
    }
  }
  php_grpc_read_args_array(args_array, &args);
  if (creds == NULL) {
    channel->wrapped = grpc_insecure_channel_create(ZSTR_VAL(target),
                                                    &args, NULL);
  } else {
    channel->wrapped =
        grpc_secure_channel_create(creds->wrapped, ZSTR_VAL(target),
                                   &args, NULL);
  }
  efree(args.args);
}
Esempio n. 4
0
/** public function ION\HTTP\Message::withProtocolVersion(string $version) : self */
CLASS_METHOD(ION_HTTP_Message, withProtocolVersion) {
    ion_http_message * message = ION_THIS_OBJECT(ion_http_message);
    zend_string      * version = NULL;

    ZEND_PARSE_PARAMETERS_START(1, 1)
        Z_PARAM_STR(version)
    ZEND_PARSE_PARAMETERS_END_EX(PION_ZPP_THROW);

    if(message->version) {
        zend_string_release(message->version);
    }
    message->version = zend_string_copy(version);

    RETURN_THIS();
}
// extern void TF_SetDevice(TF_OperationDescription* desc, const char* device);
static PHP_METHOD(TensorFlow_OperationDescription, setDevice)
{
    zend_string *device;

    ZEND_PARSE_PARAMETERS_START(1, 1)
        Z_PARAM_STR(device)
    ZEND_PARSE_PARAMETERS_END();

    // php_printf("device : %s\n", device->val);

    t_tf_operation_description_object* intern = TF_OPERATION_DESCRIPTION_P_ZV(getThis());
    t_tf_operation_description* node = intern->ptr;

    TF_SetDevice(node->src, device->val);
}
// extern TF_OperationDescription* TF_NewOperation(TF_Graph* graph,
//         const char* op_type, const char* oper_name);
static PHP_METHOD(TensorFlow_OperationDescription, __construct)
{
    zval *graph;
    zend_string *operatorType;
    zend_string *operatorName;

    ZEND_PARSE_PARAMETERS_START(3, 3)
        Z_PARAM_OBJECT_OF_CLASS_EX(graph, ce_TF_Graph, 0, 1) // last 1 is call by ref.
        Z_PARAM_STR(operatorType)
        Z_PARAM_STR(operatorName)
    ZEND_PARSE_PARAMETERS_END();

    // php_printf("optype : %s\n", operatorType->val);
    // php_printf("opname : %s\n", operatorName->val);

    t_tf_operation_description_object* intern = TF_OPERATION_DESCRIPTION_P_ZV(getThis());
    t_tf_operation_description* node = intern->ptr;

    node->src = TF_NewOperation(
        TF_GRAPH_P_ZV(graph)->ptr->src,
        operatorType->val,
        operatorName->val
    );
}
Esempio n. 7
0
/** public function ION\HTTP\Message::hasHeader(string $name) : bool */
CLASS_METHOD(ION_HTTP_Message, hasHeader) {
    ion_http_message * message = ION_THIS_OBJECT(ion_http_message);
    zend_string      * name = NULL;

    ZEND_PARSE_PARAMETERS_START(1, 1)
        Z_PARAM_STR(name)
    ZEND_PARSE_PARAMETERS_END_EX(PION_ZPP_THROW);

    name = zend_string_tolower(name);
    if(zend_hash_exists(message->headers, name)) {
        RETVAL_TRUE;
    } else {
        RETVAL_FALSE;
    }
    zend_string_release(name);
}
Esempio n. 8
0
/** public function ION\HTTP\Message::getHeader(string $name) : array */
CLASS_METHOD(ION_HTTP_Message, getHeader) {
    ion_http_message * message = ION_THIS_OBJECT(ion_http_message);
    zend_string      * name = NULL;
    zval             * header = NULL;

    ZEND_PARSE_PARAMETERS_START(1, 1)
            Z_PARAM_STR(name)
    ZEND_PARSE_PARAMETERS_END_EX(PION_ZPP_THROW);

    name = zend_string_tolower(name);
    header = zend_hash_find(message->headers, name);
    zend_string_release(name);

    if(header) {
        RETURN_ZVAL(header, 1, 0)
    } else {
// 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);
}
Esempio n. 10
0
/** public function ION\Process\IPC::send(string $data) : self */
CLASS_METHOD(ION_Process_IPC, send) {
    ion_process_ipc * ipc = ION_THIS_OBJECT(ion_process_ipc);
    zend_string * data = NULL;
    size_t frame_size;
    char * frame;

    ZEND_PARSE_PARAMETERS_START(1, 1)
        Z_PARAM_STR(data)
    ZEND_PARSE_PARAMETERS_END_EX(PION_ZPP_THROW);

    frame_size = websocket_calc_frame_size(ION_IPC_FIN | ION_IPC_DATA, ZSTR_LEN(data));
    frame = emalloc(frame_size);
    websocket_build_frame(frame, ION_IPC_FIN | ION_IPC_DATA, NULL, ZSTR_VAL(data), ZSTR_LEN(data));
    bufferevent_write(ipc->buffer, frame, frame_size);
    efree(frame);
    RETURN_THIS();
}
// extern void TF_SetAttrType(TF_OperationDescription* desc, const char* attr_name,
//                            TF_DataType value);
static PHP_METHOD(TensorFlow_OperationDescription, setAttrType)
{
    zend_string *name;
    zend_long dtype;

    ZEND_PARSE_PARAMETERS_START(2, 2)
        Z_PARAM_STR(name)
        Z_PARAM_LONG(dtype)
    ZEND_PARSE_PARAMETERS_END();

    if (!valid_dtype(dtype)) {
        zend_throw_exception(spl_ce_InvalidArgumentException, "dtype must be from 1 to 20", 0);
        return;
    }

    // this
    t_tf_operation_description_object* intern = TF_OPERATION_DESCRIPTION_P_ZV(getThis());
    t_tf_operation_description* node = intern->ptr;

    TF_SetAttrType(node->src, name->val, dtype);
}
Esempio n. 12
0
// extern TF_Buffer* TF_NewBufferFromString(const void* proto, size_t proto_len);
// extern TF_Buffer* TF_NewBuffer();
static PHP_METHOD(TensorFlow_Buffer, __construct)
{
    // arguments
    zend_string* buffer;

    ZEND_PARSE_PARAMETERS_START(0, 1)
        Z_PARAM_OPTIONAL
        Z_PARAM_STR(buffer)
    ZEND_PARSE_PARAMETERS_END();

    // this
    t_tf_buffer_object* intern;
    t_tf_buffer* php_tf_buffer;

    intern = TF_BUFFER_P_ZV(getThis());
    php_tf_buffer = intern->ptr;

    if (ZEND_NUM_ARGS() == 1) {
        php_tf_buffer->src = TF_NewBufferFromString(ZSTR_VAL(buffer), ZSTR_LEN(buffer));
    } else {
        php_tf_buffer->src = TF_NewBuffer();
    }
}