本文整理汇总了C++中rb_ary_entry函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_ary_entry函数的具体用法?C++ rb_ary_entry怎么用?C++ rb_ary_entry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_ary_entry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Node_init
static VALUE Node_init(int argc, VALUE *args, VALUE self)
{
vx_graph graph = 0;
vx_kernel kernel = 0;
Check_Type(self, T_DATA);
if (argc <= 1)
rb_raise(rb_eArgError, "Not enough arguments");
graph = (vx_graph)DATA_PTR(args[0]);
if (argc == 2) // Kernel
{
Check_Type(args[1], T_DATA);
kernel = (vx_kernel)DATA_PTR(args[1]);
DATA_PTR(self) = (void *)vxCreateGenericNode(graph, kernel);
}
else if (argc == 3) // graph, [string|enum], array of hashes
{
vx_node node = 0;
VALUE kern = args[1];
VALUE array = args[2];
long param = 0;
if (TYPE(kern) == T_STRING)
kernel = vxGetKernelByName(context, RSTRING_PTR(kern));
else if (TYPE(kern) == T_FIXNUM)
kernel = vxGetKernelByEnum(context, FIX2INT(kern));
else if (TYPE(kern) == T_DATA) // a OpenVX::Kernel
kernel = (vx_kernel)DATA_PTR(kern);
else
rb_raise(rb_eTypeError, "kernel must be a string, fixnum, or OpenVX::Kernel");
if (kernel == 0)
rb_raise(rb_eNameError, "kernel could not be found in OpenVX");
Check_Type(array, T_ARRAY);
node = vxCreateGenericNode(graph, kernel);
if (node == 0)
rb_raise(rb_eTypeError, "node could not be created!");
REXT_PRINT("Array of parameters has len = %ld\n", RARRAY_LEN(array));
for (param = 0; param < RARRAY_LEN(array) ; param++)
{
VALUE ref,hash;
vx_reference ref2 = 0;
vx_status status = 0;
const char *name = NULL;
hash = rb_ary_entry(array, param);
Check_Type(hash, T_HASH);
ref = rb_hash_aref(hash, ID2SYM(rb_intern("ref")));
name = rb_obj_classname(ref);
REXT_PRINT("ref class = %s\n", name);
Check_Type(ref, T_DATA);
ref2 = (vx_reference)DATA_PTR(ref);
status = vxSetParameterByIndex(node, param, ref2);
REXT_PRINT("status = %d\n", status);
}
DATA_PTR(self) = (void *)node;
}
else
{
rb_raise(rb_eArgError, "incorrect number of arguments");
}
return Qnil;
}
示例2: rcsv_raw_parse
/* An rb_rescue()-compatible Ruby pseudo-method that handles the actual parsing */
VALUE rcsv_raw_parse(VALUE ensure_container) {
/* Unpacking multiple variables from a single Ruby VALUE */
VALUE options = rb_ary_entry(ensure_container, 0);
VALUE csvio = rb_ary_entry(ensure_container, 1);
struct rcsv_metadata * meta = (struct rcsv_metadata *)NUM2LONG(rb_ary_entry(ensure_container, 2));
struct csv_parser * cp = (struct csv_parser *)NUM2LONG(rb_ary_entry(ensure_container, 3));
/* Helper temporary variables */
VALUE option, csvstr, buffer_size;
/* libcsv-related temporary variables */
char * csv_string;
size_t csv_string_len;
int error;
/* Generic iterator */
size_t i = 0;
/* IO buffer size can be controller via an option */
buffer_size = rb_hash_aref(options, ID2SYM(rb_intern("buffer_size")));
/* By default, parse as Array of Arrays */
option = rb_hash_aref(options, ID2SYM(rb_intern("row_as_hash")));
if (option && (option != Qnil)) {
meta->row_as_hash = true;
}
/* :col_sep sets the column separator, default is comma (,) */
option = rb_hash_aref(options, ID2SYM(rb_intern("col_sep")));
if (option != Qnil) {
csv_set_delim(cp, (unsigned char)*StringValuePtr(option));
}
/* :quote_char sets the character used for quoting data; default is double-quote (") */
option = rb_hash_aref(options, ID2SYM(rb_intern("quote_char")));
if (option != Qnil) {
csv_set_quote(cp, (unsigned char)*StringValuePtr(option));
}
/* Specify how many rows to skip from the beginning of CSV */
option = rb_hash_aref(options, ID2SYM(rb_intern("offset_rows")));
if (option != Qnil) {
meta->offset_rows = (size_t)NUM2INT(option);
}
/* Specify the character encoding of the input data */
option = rb_hash_aref(options, ID2SYM(rb_intern("output_encoding")));
if (option && (option != Qnil)) {
meta->encoding_index = RB_ENC_FIND_INDEX(StringValueCStr(option));
}
/* :only_rows is a list of values where row is only parsed
if its fields match those in the passed array.
[nil, nil, ["ABC", nil, 1]] skips all rows where 3rd column isn't equal to "ABC", nil or 1 */
option = rb_hash_aref(options, ID2SYM(rb_intern("only_rows")));
if (option != Qnil) {
meta->num_only_rows = (size_t)RARRAY_LEN(option);
meta->only_rows = (VALUE *)malloc(meta->num_only_rows * sizeof(VALUE));
for (i = 0; i < meta->num_only_rows; i++) {
VALUE only_row = rb_ary_entry(option, i);
meta->only_rows[i] = validate_filter_row("only_rows", only_row);
}
}
/* :except_rows is a list of values where row is only parsed
if its fields don't match those in the passed array.
[nil, nil, ["ABC", nil, 1]] skips all rows where 3rd column is equal to "ABC", nil or 1 */
option = rb_hash_aref(options, ID2SYM(rb_intern("except_rows")));
if (option != Qnil) {
meta->num_except_rows = (size_t)RARRAY_LEN(option);
meta->except_rows = (VALUE *)malloc(meta->num_except_rows * sizeof(VALUE));
for (i = 0; i < meta->num_except_rows; i++) {
VALUE except_row = rb_ary_entry(option, i);
meta->except_rows[i] = validate_filter_row("except_rows", except_row);
}
}
/* :row_defaults is an array of default values that are assigned to fields containing empty strings
according to matching field positions */
option = rb_hash_aref(options, ID2SYM(rb_intern("row_defaults")));
if (option != Qnil) {
meta->num_row_defaults = RARRAY_LEN(option);
meta->row_defaults = (VALUE*)malloc(meta->num_row_defaults * sizeof(VALUE*));
for (i = 0; i < meta->num_row_defaults; i++) {
VALUE row_default = rb_ary_entry(option, i);
meta->row_defaults[i] = row_default;
}
}
/* :row_conversions specifies Ruby types that CSV field values should be converted into.
Each char of row_conversions string represents Ruby type for CSV field with matching position. */
option = rb_hash_aref(options, ID2SYM(rb_intern("row_conversions")));
if (option != Qnil) {
meta->num_row_conversions = RSTRING_LEN(option);
meta->row_conversions = StringValuePtr(option);
}
//.........这里部分代码省略.........
示例3: r2d_show
//.........这里部分代码省略.........
int num_keys;
key_state = SDL_GetKeyboardState(&num_keys);
for (int i = 0; i < num_keys; i++) {
if (key_state[i] == 1) {
rb_funcall(self, rb_intern("keys_down_callback"), 1,
rb_str_new2(SDL_GetScancodeName(i))
);
}
}
// Store the cursor position
SDL_GetMouseState(&cursor_x, &cursor_y);
rb_iv_set(self, "@cursor_x", INT2NUM(cursor_x));
rb_iv_set(self, "@cursor_y", INT2NUM(cursor_y));
// Update Application State ////////////////////////////////////////////////
// Call update proc, `window.update`
rb_funcall(self, rb_intern("update_callback"), 0);
// Draw Objects ////////////////////////////////////////////////////////////
glClear(GL_COLOR_BUFFER_BIT);
// Read window objects
VALUE objects = rb_iv_get(self, "@objects");
int num_objects = NUM2INT(rb_funcall(objects, rb_intern("count"), 0));
// Switch on each object type
for (int i = 0; i < num_objects; ++i) {
VALUE el = rb_ary_entry(objects, i);
int type_id = NUM2INT(rb_iv_get(el, "@type_id"));
// Switch on the object's type_id
switch(type_id) {
case TRIANGLE: {
VALUE c1 = rb_iv_get(el, "@c1");
VALUE c2 = rb_iv_get(el, "@c2");
VALUE c3 = rb_iv_get(el, "@c3");
draw_triangle(
NUM2DBL(rb_iv_get(el, "@x1")),
NUM2DBL(rb_iv_get(el, "@y1")),
NUM2DBL(rb_iv_get(c1, "@r")),
NUM2DBL(rb_iv_get(c1, "@g")),
NUM2DBL(rb_iv_get(c1, "@b")),
NUM2DBL(rb_iv_get(c1, "@a")),
NUM2DBL(rb_iv_get(el, "@x2")),
NUM2DBL(rb_iv_get(el, "@y2")),
NUM2DBL(rb_iv_get(c2, "@r")),
NUM2DBL(rb_iv_get(c2, "@g")),
NUM2DBL(rb_iv_get(c2, "@b")),
NUM2DBL(rb_iv_get(c2, "@a")),
NUM2DBL(rb_iv_get(el, "@x3")),
NUM2DBL(rb_iv_get(el, "@y3")),
NUM2DBL(rb_iv_get(c3, "@r")),
NUM2DBL(rb_iv_get(c3, "@g")),
NUM2DBL(rb_iv_get(c3, "@b")),
NUM2DBL(rb_iv_get(c3, "@a"))
);
示例4: ossl_sslctx_setup
/*
* call-seq:
* ctx.setup => Qtrue # first time
* ctx.setup => nil # thereafter
*
* This method is called automatically when a new SSLSocket is created.
* Normally you do not need to call this method (unless you are writing an extension in C).
*/
static VALUE
ossl_sslctx_setup(VALUE self)
{
SSL_CTX *ctx;
X509 *cert = NULL, *client_ca = NULL;
X509_STORE *store;
EVP_PKEY *key = NULL;
char *ca_path = NULL, *ca_file = NULL;
int i, verify_mode;
VALUE val;
Data_Get_Struct(self, SSL_CTX, ctx);
if(SSL_CTX_get_ex_data(ctx, ossl_ssl_ex_ptr_idx) == (void*)self) return Qnil;
SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_ptr_idx, (void*)self);
#if !defined(OPENSSL_NO_DH)
if (RTEST(ossl_sslctx_get_tmp_dh_cb(self))){
SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);
}
else{
SSL_CTX_set_tmp_dh_callback(ctx, ossl_default_tmp_dh_callback);
}
#endif
val = ossl_sslctx_get_cert_store(self);
if(!NIL_P(val)){
/*
* WORKAROUND:
* X509_STORE can count references, but
* X509_STORE_free() doesn't care it.
* So we won't increment it but mark it by ex_data.
*/
store = GetX509StorePtr(val); /* NO NEED TO DUP */
SSL_CTX_set_cert_store(ctx, store);
SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_store_p, (void*)1);
}
val = ossl_sslctx_get_extra_cert(self);
if(!NIL_P(val)){
size_t i;
for(i = 0; i < rb_ary_size(val); i++) {
ossl_sslctx_add_extra_chain_cert_i(rb_ary_entry(val, i), self);
}
}
/* private key may be bundled in certificate file. */
val = ossl_sslctx_get_cert(self);
cert = NIL_P(val) ? NULL : GetX509CertPtr(val); /* NO DUP NEEDED */
val = ossl_sslctx_get_key(self);
key = NIL_P(val) ? NULL : GetPKeyPtr(val); /* NO DUP NEEDED */
if (cert && key) {
if (!SSL_CTX_use_certificate(ctx, cert)) {
/* Adds a ref => Safe to FREE */
ossl_raise(eSSLError, "SSL_CTX_use_certificate:");
}
if (!SSL_CTX_use_PrivateKey(ctx, key)) {
/* Adds a ref => Safe to FREE */
ossl_raise(eSSLError, "SSL_CTX_use_PrivateKey:");
}
if (!SSL_CTX_check_private_key(ctx)) {
ossl_raise(eSSLError, "SSL_CTX_check_private_key:");
}
}
val = ossl_sslctx_get_client_ca(self);
if(!NIL_P(val)){
if(TYPE(val) == T_ARRAY){
for(i = 0; i < RARRAY_LEN(val); i++){
client_ca = GetX509CertPtr(RARRAY_PTR(val)[i]);
if (!SSL_CTX_add_client_CA(ctx, client_ca)){
/* Copies X509_NAME => FREE it. */
ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
}
}
}
else{
client_ca = GetX509CertPtr(val); /* NO DUP NEEDED. */
if (!SSL_CTX_add_client_CA(ctx, client_ca)){
/* Copies X509_NAME => FREE it. */
ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
}
}
}
val = ossl_sslctx_get_ca_file(self);
ca_file = NIL_P(val) ? NULL : StringValuePtr(val);
val = ossl_sslctx_get_ca_path(self);
ca_path = NIL_P(val) ? NULL : StringValuePtr(val);
if(ca_file || ca_path){
if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
rb_warning("can't set verify locations");
//.........这里部分代码省略.........
示例5: grpc_rb_md_ary_fill_hash_cb
/* grpc_rb_md_ary_fill_hash_cb is the hash iteration callback used
to fill grpc_metadata_array.
it's capacity should have been computed via a prior call to
grpc_rb_md_ary_fill_hash_cb
*/
static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
grpc_metadata_array *md_ary = NULL;
long array_length;
long i;
char *key_str;
size_t key_len;
char *value_str;
size_t value_len;
if (TYPE(key) == T_SYMBOL) {
key_str = (char *)rb_id2name(SYM2ID(key));
key_len = strlen(key_str);
} else { /* StringValueCStr does all other type exclusions for us */
key_str = StringValueCStr(key);
key_len = RSTRING_LEN(key);
}
if (!grpc_header_key_is_legal(key_str, key_len)) {
rb_raise(rb_eArgError,
"'%s' is an invalid header key, must match [a-z0-9-_.]+",
key_str);
return ST_STOP;
}
/* Construct a metadata object from key and value and add it */
TypedData_Get_Struct(md_ary_obj, grpc_metadata_array,
&grpc_rb_md_ary_data_type, md_ary);
if (TYPE(val) == T_ARRAY) {
array_length = RARRAY_LEN(val);
/* If the value is an array, add capacity for each value in the array */
for (i = 0; i < array_length; i++) {
value_str = RSTRING_PTR(rb_ary_entry(val, i));
value_len = RSTRING_LEN(rb_ary_entry(val, i));
if (!grpc_is_binary_header(key_str, key_len) &&
!grpc_header_nonbin_value_is_legal(value_str, value_len)) {
// The value has invalid characters
rb_raise(rb_eArgError,
"Header value '%s' has invalid characters", value_str);
return ST_STOP;
}
md_ary->metadata[md_ary->count].key = key_str;
md_ary->metadata[md_ary->count].value = value_str;
md_ary->metadata[md_ary->count].value_length = value_len;
md_ary->count += 1;
}
} else {
value_str = RSTRING_PTR(val);
value_len = RSTRING_LEN(val);
if (!grpc_is_binary_header(key_str, key_len) &&
!grpc_header_nonbin_value_is_legal(value_str, value_len)) {
// The value has invalid characters
rb_raise(rb_eArgError,
"Header value '%s' has invalid characters", value_str);
return ST_STOP;
}
md_ary->metadata[md_ary->count].key = key_str;
md_ary->metadata[md_ary->count].value = value_str;
md_ary->metadata[md_ary->count].value_length = value_len;
md_ary->count += 1;
}
return ST_CONTINUE;
}
示例6: array_spec_rb_ary_entry
static VALUE array_spec_rb_ary_entry(VALUE self, VALUE array, VALUE offset) {
return rb_ary_entry(array, FIX2INT(offset));
}
示例7: coord_seq_from_array
static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char close)
{
Check_Type(array, T_ARRAY);
RGeo_FactoryData* factory_data = RGEO_FACTORY_DATA_PTR(factory);
VALUE point_type = factory_data->globals->feature_point;
unsigned int len = (unsigned int)RARRAY_LEN(array);
char has_z = (char)(RGEO_FACTORY_DATA_PTR(factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
unsigned int dims = has_z ? 3 : 2;
double* coords = ALLOC_N(double, len == 0 ? 1 : len * dims);
if (!coords) {
return NULL;
}
GEOSContextHandle_t context = factory_data->geos_context;
unsigned int i;
for (i=0; i<len; ++i) {
char good = 0;
const GEOSGeometry* entry_geom = rgeo_convert_to_geos_geometry(factory, rb_ary_entry(array, i), point_type);
if (entry_geom) {
const GEOSCoordSequence* entry_cs = GEOSGeom_getCoordSeq_r(context, entry_geom);
if (entry_cs) {
double x;
if (GEOSCoordSeq_getX_r(context, entry_cs, 0, &x)) {
coords[i*dims] = x;
if (GEOSCoordSeq_getY_r(context, entry_cs, 0, &x)) {
coords[i*dims+1] = x;
good = 1;
if (has_z) {
if (GEOSCoordSeq_getZ_r(context, entry_cs, 0, &x)) {
coords[i*dims+2] = x;
}
else {
good = 0;
}
}
}
}
}
}
if (!good) {
free(coords);
return NULL;
}
}
if (len > 0 && close) {
if (coords[0] == coords[(len-1)*dims] && coords[1] == coords[(len-1)*dims+1]) {
close = 0;
}
}
else {
close = 0;
}
GEOSCoordSequence* coord_seq = GEOSCoordSeq_create_r(context, len + close, 3);
if (coord_seq) {
for (i=0; i<len; ++i) {
GEOSCoordSeq_setX_r(context, coord_seq, i, coords[i*dims]);
GEOSCoordSeq_setY_r(context, coord_seq, i, coords[i*dims+1]);
GEOSCoordSeq_setZ_r(context, coord_seq, i, has_z ? coords[i*dims+2] : 0);
}
if (close) {
GEOSCoordSeq_setX_r(context, coord_seq, len, coords[0]);
GEOSCoordSeq_setY_r(context, coord_seq, len, coords[1]);
GEOSCoordSeq_setZ_r(context, coord_seq, len, has_z ? coords[2] : 0);
}
}
free(coords);
return coord_seq;
}
示例8: rb_mysql_result_each_
static VALUE rb_mysql_result_each_(VALUE self,
VALUE(*fetch_row_func)(VALUE, MYSQL_FIELD *fields, const result_each_args *args),
const result_each_args *args)
{
unsigned long i;
const char *errstr;
MYSQL_FIELD *fields = NULL;
GET_RESULT(self);
if (wrapper->is_streaming) {
/* When streaming, we will only yield rows, not return them. */
if (wrapper->rows == Qnil) {
wrapper->rows = rb_ary_new();
}
if (!wrapper->streamingComplete) {
VALUE row;
fields = mysql_fetch_fields(wrapper->result);
do {
row = fetch_row_func(self, fields, args);
if (row != Qnil) {
wrapper->numberOfRows++;
if (args->block_given != Qnil) {
rb_yield(row);
}
}
} while(row != Qnil);
rb_mysql_result_free_result(wrapper);
wrapper->streamingComplete = 1;
// Check for errors, the connection might have gone out from under us
// mysql_error returns an empty string if there is no error
errstr = mysql_error(wrapper->client_wrapper->client);
if (errstr[0]) {
rb_raise(cMysql2Error, "%s", errstr);
}
} else {
rb_raise(cMysql2Error, "You have already fetched all the rows for this query and streaming is true. (to reiterate you must requery).");
}
} else {
if (args->cacheRows && wrapper->lastRowProcessed == wrapper->numberOfRows) {
/* we've already read the entire dataset from the C result into our */
/* internal array. Lets hand that over to the user since it's ready to go */
for (i = 0; i < wrapper->numberOfRows; i++) {
rb_yield(rb_ary_entry(wrapper->rows, i));
}
} else {
unsigned long rowsProcessed = 0;
rowsProcessed = RARRAY_LEN(wrapper->rows);
fields = mysql_fetch_fields(wrapper->result);
for (i = 0; i < wrapper->numberOfRows; i++) {
VALUE row;
if (args->cacheRows && i < rowsProcessed) {
row = rb_ary_entry(wrapper->rows, i);
} else {
row = fetch_row_func(self, fields, args);
if (args->cacheRows) {
rb_ary_store(wrapper->rows, i, row);
}
wrapper->lastRowProcessed++;
}
if (row == Qnil) {
/* we don't need the mysql C dataset around anymore, peace it */
if (args->cacheRows) {
rb_mysql_result_free_result(wrapper);
}
return Qnil;
}
if (args->block_given != Qnil) {
rb_yield(row);
}
}
if (wrapper->lastRowProcessed == wrapper->numberOfRows && args->cacheRows) {
/* we don't need the mysql C dataset around anymore, peace it */
rb_mysql_result_free_result(wrapper);
}
}
}
// FIXME return Enumerator instead?
// return rb_ary_each(wrapper->rows);
return wrapper->rows;
}
示例9: write_element
static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) {
buffer_t buffer = (buffer_t)NUM2LL(rb_ary_entry(extra, 0));
VALUE check_keys = rb_ary_entry(extra, 1);
if (TYPE(key) == T_SYMBOL) {
// TODO better way to do this... ?
key = rb_str_new2(rb_id2name(SYM2ID(key)));
}
if (TYPE(key) != T_STRING) {
buffer_free(buffer);
rb_raise(rb_eTypeError, "keys must be strings or symbols");
}
if (allow_id == 0 && strcmp("_id", RSTRING_PTR(key)) == 0) {
return ST_CONTINUE;
}
if (check_keys == Qtrue) {
int i;
if (RSTRING_LEN(key) > 0 && RSTRING_PTR(key)[0] == '$') {
buffer_free(buffer);
rb_raise(InvalidKeyName, "key must not start with '$'");
}
for (i = 0; i < RSTRING_LEN(key); i++) {
if (RSTRING_PTR(key)[i] == '.') {
buffer_free(buffer);
rb_raise(InvalidKeyName, "key must not contain '.'");
}
}
}
switch(TYPE(value)) {
case T_BIGNUM:
case T_FIXNUM:
{
if (rb_funcall(value, gt_operator, 1, LL2NUM(9223372036854775807LL)) == Qtrue ||
rb_funcall(value, lt_operator, 1, LL2NUM(-9223372036854775808ULL)) == Qtrue) {
buffer_free(buffer);
rb_raise(rb_eRangeError, "MongoDB can only handle 8-byte ints");
}
if (rb_funcall(value, gt_operator, 1, INT2NUM(2147483647L)) == Qtrue ||
rb_funcall(value, lt_operator, 1, INT2NUM(-2147483648L)) == Qtrue) {
long long ll_value;
write_name_and_type(buffer, key, 0x12);
ll_value = NUM2LL(value);
SAFE_WRITE(buffer, (char*)&ll_value, 8);
} else {
int int_value;
write_name_and_type(buffer, key, 0x10);
int_value = NUM2LL(value);
SAFE_WRITE(buffer, (char*)&int_value, 4);
}
break;
}
case T_TRUE:
{
write_name_and_type(buffer, key, 0x08);
SAFE_WRITE(buffer, &one, 1);
break;
}
case T_FALSE:
{
write_name_and_type(buffer, key, 0x08);
SAFE_WRITE(buffer, &zero, 1);
break;
}
case T_FLOAT:
{
double d = NUM2DBL(value);
write_name_and_type(buffer, key, 0x01);
SAFE_WRITE(buffer, (char*)&d, 8);
break;
}
case T_NIL:
{
write_name_and_type(buffer, key, 0x0A);
break;
}
case T_HASH:
{
write_name_and_type(buffer, key, 0x03);
write_doc(buffer, value, check_keys, Qfalse);
break;
}
case T_ARRAY:
{
buffer_position length_location, start_position, obj_length;
int items, i;
VALUE* values;
write_name_and_type(buffer, key, 0x04);
start_position = buffer_get_position(buffer);
// save space for length
length_location = buffer_save_space(buffer, 4);
if (length_location == -1) {
rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c");
}
//.........这里部分代码省略.........
示例10: get_parameter
static void* get_parameter(const ool_conmin_minimizer_type *T, ool_conmin_pgrad_parameters *Pp,
ool_conmin_spg_parameters *Ps, ool_conmin_gencan_parameters *Pg, VALUE ary)
{
if (T == ool_conmin_minimizer_pgrad) {
if (ary == Qnil) {
ool_conmin_parameters_default(T, (void*) Pp);
} else {
Pp->fmin = NUM2DBL(rb_ary_entry(ary, 0));
Pp->tol = NUM2DBL(rb_ary_entry(ary, 1));
Pp->alpha = NUM2DBL(rb_ary_entry(ary, 2));
Pp->sigma1 = NUM2DBL(rb_ary_entry(ary, 3));
Pp->sigma2 = NUM2DBL(rb_ary_entry(ary, 4));
}
return (void*) Pp;
} else if (T == ool_conmin_minimizer_spg) {
if (ary == Qnil) {
ool_conmin_parameters_default(T, (void*) Ps);
} else {
Ps->fmin = NUM2DBL(rb_ary_entry(ary, 0));
Ps->tol = NUM2DBL(rb_ary_entry(ary, 1));
Ps->M = NUM2DBL(rb_ary_entry(ary, 2));
Ps->alphamin = NUM2DBL(rb_ary_entry(ary, 3));
Ps->alphamax = NUM2DBL(rb_ary_entry(ary, 4));
Ps->gamma = NUM2DBL(rb_ary_entry(ary, 5));
Ps->sigma2 = NUM2DBL(rb_ary_entry(ary, 6));
Ps->sigma2 = NUM2DBL(rb_ary_entry(ary, 7));
}
return (void*) Ps;
} else {
if (ary == Qnil) {
ool_conmin_parameters_default(T, (void*) Pg);
} else {
Pg->epsgpen = NUM2DBL(rb_ary_entry(ary, 0));
Pg->epsgpsn = NUM2DBL(rb_ary_entry(ary, 1));
Pg->fmin = NUM2DBL(rb_ary_entry(ary, 2));
Pg->udelta0 = NUM2DBL(rb_ary_entry(ary, 3));
Pg->ucgmia = NUM2DBL(rb_ary_entry(ary, 4));
Pg->ucgmib = NUM2DBL(rb_ary_entry(ary, 5));
Pg->cg_scre = FIX2INT(rb_ary_entry(ary, 6));
Pg->cg_gpnf = NUM2DBL(rb_ary_entry(ary, 7));
Pg->cg_epsi = NUM2DBL(rb_ary_entry(ary, 8));
Pg->cg_epsf = NUM2DBL(rb_ary_entry(ary, 9));
Pg->cg_epsnqmp = NUM2DBL(rb_ary_entry(ary, 10));
Pg->cg_maxitnqmp = (size_t) FIX2INT(rb_ary_entry(ary, 11));
Pg->nearlyq = FIX2INT(rb_ary_entry(ary, 12));
Pg->nint = NUM2DBL(rb_ary_entry(ary, 13));
Pg->next = NUM2DBL(rb_ary_entry(ary, 14));
Pg->mininterp = (size_t) FIX2INT(rb_ary_entry(ary, 15));
Pg->maxextrap = (size_t) FIX2INT(rb_ary_entry(ary, 16));
Pg->trtype = FIX2INT(rb_ary_entry(ary, 17));
Pg->eta = NUM2DBL(rb_ary_entry(ary, 18));
Pg->delmin = NUM2DBL(rb_ary_entry(ary, 19));
Pg->lspgmi = NUM2DBL(rb_ary_entry(ary, 20));
Pg->lspgma = NUM2DBL(rb_ary_entry(ary, 21));
Pg->theta = NUM2DBL(rb_ary_entry(ary, 22));
Pg->gamma = NUM2DBL(rb_ary_entry(ary, 23));
Pg->beta = NUM2DBL(rb_ary_entry(ary, 24));
Pg->sigma1 = NUM2DBL(rb_ary_entry(ary, 25));
Pg->sigma2 = NUM2DBL(rb_ary_entry(ary, 26));
Pg->epsrel = NUM2DBL(rb_ary_entry(ary, 27));
Pg->epsabs = NUM2DBL(rb_ary_entry(ary, 28));
Pg->infrel = NUM2DBL(rb_ary_entry(ary, 29));
Pg->infabs = NUM2DBL(rb_ary_entry(ary, 30));
}
return (void*) Pg;
}
}
示例11: rb_ool_conmin_function_params
static VALUE rb_ool_conmin_function_params(VALUE obj)
{
ool_conmin_function *F;
Data_Get_Struct(obj, ool_conmin_function, F);
return rb_ary_entry((VALUE) F->params, 4);;
}
示例12: reduce0
static VALUE
reduce0(VALUE val, VALUE data, VALUE self)
{
struct cparse_params *v;
VALUE reduce_to, reduce_len, method_id;
long len;
ID mid;
VALUE tmp, tmp_t = Qundef, tmp_v = Qundef;
long i, k1, k2;
VALUE goto_state;
Data_Get_Struct(data, struct cparse_params, v);
reduce_len = rb_ary_entry(v->reduce_table, v->ruleno);
reduce_to = rb_ary_entry(v->reduce_table, v->ruleno+1);
method_id = rb_ary_entry(v->reduce_table, v->ruleno+2);
len = NUM2LONG(reduce_len);
mid = value_to_id(method_id);
/* call action */
if (len == 0) {
tmp = Qnil;
if (mid != id_noreduce)
tmp_v = rb_ary_new();
if (v->debug)
tmp_t = rb_ary_new();
}
else {
if (mid != id_noreduce) {
tmp_v = GET_TAIL(v->vstack, len);
tmp = rb_ary_entry(tmp_v, 0);
}
else {
tmp = rb_ary_entry(v->vstack, RARRAY_LEN(v->vstack) - len);
}
CUT_TAIL(v->vstack, len);
if (v->debug) {
tmp_t = GET_TAIL(v->tstack, len);
CUT_TAIL(v->tstack, len);
}
CUT_TAIL(v->state, len);
}
if (mid != id_noreduce) {
if (v->use_result_var) {
tmp = rb_funcall(v->parser, mid,
3, tmp_v, v->vstack, tmp);
}
else {
tmp = rb_funcall(v->parser, mid,
2, tmp_v, v->vstack);
}
}
/* then push result */
PUSH(v->vstack, tmp);
if (v->debug) {
PUSH(v->tstack, reduce_to);
rb_funcall(v->parser, id_d_reduce,
4, tmp_t, reduce_to, v->tstack, v->vstack);
}
/* calculate transition state */
if (RARRAY_LEN(v->state) == 0)
rb_raise(RaccBug, "state stack unexpectedly empty");
k2 = num_to_long(LAST_I(v->state));
k1 = num_to_long(reduce_to) - v->nt_base;
D_printf("(goto) k1=%ld\n", k1);
D_printf("(goto) k2=%ld\n", k2);
tmp = AREF(v->goto_pointer, k1);
if (NIL_P(tmp)) goto notfound;
i = NUM2LONG(tmp) + k2;
D_printf("(goto) i=%ld\n", i);
if (i < 0) goto notfound;
goto_state = AREF(v->goto_table, i);
if (NIL_P(goto_state)) {
D_puts("(goto) table[i] == nil");
goto notfound;
}
D_printf("(goto) table[i]=%ld (goto_state)\n", NUM2LONG(goto_state));
tmp = AREF(v->goto_check, i);
if (NIL_P(tmp)) {
D_puts("(goto) check[i] == nil");
goto notfound;
}
if (tmp != LONG2NUM(k1)) {
D_puts("(goto) check[i] != table[i]");
goto notfound;
}
D_printf("(goto) check[i]=%ld\n", NUM2LONG(tmp));
D_puts("(goto) found");
transit:
PUSH(v->state, goto_state);
v->curstate = NUM2LONG(goto_state);
return INT2FIX(0);
notfound:
//.........这里部分代码省略.........
示例13: parse_main
//.........这里部分代码省略.........
v->errstatus--;
rb_ivar_set(v->parser, id_errstatus, LONG2NUM(v->errstatus));
}
SHIFT(v, act, v->t, val);
read_next = 1;
}
else if (act < 0 && act > -(v->reduce_n)) {
D_puts("reduce");
REDUCE(v, act);
}
else if (act == -(v->reduce_n)) {
goto error;
error_recovered:
; /* goto label requires stmt */
}
else if (act == v->shift_n) {
D_puts("accept");
goto accept;
}
else {
rb_raise(RaccBug, "[Racc Bug] unknown act value %ld", act);
}
if (v->debug) {
rb_funcall(v->parser, id_d_next_state,
2, LONG2NUM(v->curstate), v->state);
}
}
/* not reach */
accept:
if (v->debug) rb_funcall(v->parser, id_d_accept, 0);
v->retval = rb_ary_entry(v->vstack, 0);
v->fin = CP_FIN_ACCEPT;
return;
error:
D_printf("error detected, status=%ld\n", v->errstatus);
if (v->errstatus == 0) {
v->nerr++;
rb_funcall(v->parser, id_onerror,
3, v->t, val, v->vstack);
}
user_yyerror:
if (v->errstatus == 3) {
if (v->t == vFINAL_TOKEN) {
v->retval = Qfalse;
v->fin = CP_FIN_EOT;
return;
}
read_next = 1;
}
v->errstatus = 3;
rb_ivar_set(v->parser, id_errstatus, LONG2NUM(v->errstatus));
/* check if we can shift/reduce error token */
D_printf("(err) k1=%ld\n", v->curstate);
D_printf("(err) k2=%d (error)\n", ERROR_TOKEN);
while (1) {
tmp = AREF(v->action_pointer, v->curstate);
if (NIL_P(tmp)) goto error_pop;
D_puts("(err) pointer[k1] ok");
i = NUM2LONG(tmp) + ERROR_TOKEN;
示例14: initialize_params
static VALUE
initialize_params(VALUE vparams, VALUE parser, VALUE lexer, VALUE lexmid)
{
struct cparse_params *v;
Data_Get_Struct(vparams, struct cparse_params, v);
v->value_v = vparams;
v->parser = parser;
v->lexer = lexer;
if (! NIL_P(lexmid))
v->lexmid = value_to_id(lexmid);
v->debug = RTEST(rb_ivar_get(parser, id_yydebug));
Check_Type(arg, T_ARRAY);
if (!(13 <= RARRAY_LEN(arg) && RARRAY_LEN(arg) <= 14))
rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY_LEN(arg));
v->action_table = assert_array (rb_ary_entry(arg, 0));
v->action_check = assert_array (rb_ary_entry(arg, 1));
v->action_default = assert_array (rb_ary_entry(arg, 2));
v->action_pointer = assert_array (rb_ary_entry(arg, 3));
v->goto_table = assert_array (rb_ary_entry(arg, 4));
v->goto_check = assert_array (rb_ary_entry(arg, 5));
v->goto_default = assert_array (rb_ary_entry(arg, 6));
v->goto_pointer = assert_array (rb_ary_entry(arg, 7));
v->nt_base = assert_integer(rb_ary_entry(arg, 8));
v->reduce_table = assert_array (rb_ary_entry(arg, 9));
v->token_table = assert_hash (rb_ary_entry(arg, 10));
v->shift_n = assert_integer(rb_ary_entry(arg, 11));
v->reduce_n = assert_integer(rb_ary_entry(arg, 12));
if (RARRAY_LEN(arg) > 13) {
v->use_result_var = RTEST(rb_ary_entry(arg, 13));
}
else {
v->use_result_var = Qtrue;
}
v->use_result_var = NUM2INT(rb_ivar_get(parser, id_use_result));
/* if (RARRAY_LEN(arg) > 13) { */
/* v->use_result_var = RTEST(RARRAY_PTR(arg)[13]); */
/* } */
/* else { */
/* v->use_result_var = Qtrue; */
/* } */
PUSH(v->state, INT2FIX(0));
rb_ivar_set(parser, id_errstatus, LONG2NUM(v->errstatus));
rb_iv_set(parser, "@vstack", v->vstack);
if (v->debug) {
rb_iv_set(parser, "@tstack", v->tstack);
}
else {
rb_iv_set(parser, "@tstack", Qnil);
}
return vparams;
}
示例15: rho_ruby_array_get
VALUE rho_ruby_array_get(VALUE ar, int nIndex)
{
return rb_ary_entry( ar, nIndex);
}