本文整理汇总了C++中RSTRING_PTR函数的典型用法代码示例。如果您正苦于以下问题:C++ RSTRING_PTR函数的具体用法?C++ RSTRING_PTR怎么用?C++ RSTRING_PTR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RSTRING_PTR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rb_feature_p
static int
rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn)
{
VALUE v, features, p, load_path = 0;
const char *f, *e;
long i, len, elen, n;
st_table *loading_tbl;
st_data_t data;
int type;
if (fn) *fn = 0;
if (ext) {
elen = strlen(ext);
len = strlen(feature) - elen;
type = rb ? 'r' : 's';
}
else {
len = strlen(feature);
elen = 0;
type = 0;
}
features = get_loaded_features();
for (i = 0; i < RARRAY_LEN(features); ++i) {
v = RARRAY_PTR(features)[i];
f = StringValuePtr(v);
if ((n = RSTRING_LEN(v)) < len) continue;
if (strncmp(f, feature, len) != 0) {
if (expanded) continue;
if (!load_path) load_path = rb_get_expanded_load_path();
if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
continue;
expanded = 1;
f += RSTRING_LEN(p) + 1;
}
if (!*(e = f + len)) {
if (ext) continue;
return 'u';
}
if (*e != '.') continue;
if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
return 's';
}
if ((rb || !ext) && (IS_RBEXT(e))) {
return 'r';
}
}
loading_tbl = get_loading_table();
if (loading_tbl) {
f = 0;
if (!expanded) {
struct loaded_feature_searching fs;
fs.name = feature;
fs.len = len;
fs.type = type;
fs.load_path = load_path ? load_path : rb_get_load_path();
fs.result = 0;
st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
if ((f = fs.result) != 0) {
if (fn) *fn = f;
goto loading;
}
}
if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
if (fn) *fn = (const char*)data;
loading:
if (!ext) return 'u';
return !IS_RBEXT(ext) ? 's' : 'r';
}
else {
VALUE bufstr;
char *buf;
if (ext && *ext) return 0;
bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
buf = RSTRING_PTR(bufstr);
MEMCPY(buf, feature, char, len);
for (i = 0; (e = loadable_ext[i]) != 0; i++) {
strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
rb_str_resize(bufstr, 0);
if (fn) *fn = (const char*)data;
return i ? 's' : 'r';
}
}
rb_str_resize(bufstr, 0);
}
}
return 0;
}
示例2: mrb_check_intern_str
MRB_API mrb_value
mrb_check_intern_str(mrb_state *mrb, mrb_value str)
{
return mrb_check_intern(mrb, RSTRING_PTR(str), RSTRING_LEN(str));
}
示例3: fntype_initialize
/*
* call-seq: initialize(return_type, param_types, options={})
* @param [Type, Symbol] return_type return type for the function
* @param [Array<Type, Symbol>] param_types array of parameters types
* @param [Hash] options
* @option options [Boolean] :blocking set to true if the C function is a blocking call
* @option options [Symbol] :convention calling convention see {FFI::Library#calling_convention}
* @option options [FFI::Enums] :enums
* @return [self]
* A new FunctionType instance.
*/
static VALUE
fntype_initialize(int argc, VALUE* argv, VALUE self)
{
FunctionType *fnInfo;
ffi_status status;
VALUE rbReturnType = Qnil, rbParamTypes = Qnil, rbOptions = Qnil;
VALUE rbEnums = Qnil, rbConvention = Qnil, rbBlocking = Qnil;
#if defined(_WIN32) || defined(__WIN32__)
VALUE rbConventionStr;
#endif
int i, nargs;
nargs = rb_scan_args(argc, argv, "21", &rbReturnType, &rbParamTypes, &rbOptions);
if (nargs >= 3 && rbOptions != Qnil) {
rbConvention = rb_hash_aref(rbOptions, ID2SYM(rb_intern("convention")));
rbEnums = rb_hash_aref(rbOptions, ID2SYM(rb_intern("enums")));
rbBlocking = rb_hash_aref(rbOptions, ID2SYM(rb_intern("blocking")));
}
Check_Type(rbParamTypes, T_ARRAY);
Data_Get_Struct(self, FunctionType, fnInfo);
fnInfo->parameterCount = (int) RARRAY_LEN(rbParamTypes);
fnInfo->parameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->parameterTypes));
fnInfo->ffiParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(ffi_type *));
fnInfo->nativeParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->nativeParameterTypes));
fnInfo->rbParameterTypes = rb_ary_new2(fnInfo->parameterCount);
fnInfo->rbEnums = rbEnums;
fnInfo->blocking = RTEST(rbBlocking);
fnInfo->hasStruct = false;
for (i = 0; i < fnInfo->parameterCount; ++i) {
VALUE entry = rb_ary_entry(rbParamTypes, i);
VALUE type = rbffi_Type_Lookup(entry);
if (!RTEST(type)) {
VALUE typeName = rb_funcall2(entry, rb_intern("inspect"), 0, NULL);
rb_raise(rb_eTypeError, "Invalid parameter type (%s)", RSTRING_PTR(typeName));
}
if (rb_obj_is_kind_of(type, rbffi_FunctionTypeClass)) {
REALLOC_N(fnInfo->callbackParameters, VALUE, fnInfo->callbackCount + 1);
fnInfo->callbackParameters[fnInfo->callbackCount++] = type;
}
if (rb_obj_is_kind_of(type, rbffi_StructByValueClass)) {
fnInfo->hasStruct = true;
}
rb_ary_push(fnInfo->rbParameterTypes, type);
Data_Get_Struct(type, Type, fnInfo->parameterTypes[i]);
fnInfo->ffiParameterTypes[i] = fnInfo->parameterTypes[i]->ffiType;
fnInfo->nativeParameterTypes[i] = fnInfo->parameterTypes[i]->nativeType;
}
fnInfo->rbReturnType = rbffi_Type_Lookup(rbReturnType);
if (!RTEST(fnInfo->rbReturnType)) {
VALUE typeName = rb_funcall2(rbReturnType, rb_intern("inspect"), 0, NULL);
rb_raise(rb_eTypeError, "Invalid return type (%s)", RSTRING_PTR(typeName));
}
if (rb_obj_is_kind_of(fnInfo->rbReturnType, rbffi_StructByValueClass)) {
fnInfo->hasStruct = true;
}
Data_Get_Struct(fnInfo->rbReturnType, Type, fnInfo->returnType);
fnInfo->ffiReturnType = fnInfo->returnType->ffiType;
#if (defined(_WIN32) || defined(__WIN32__)) && defined(FFI_STDCALL)
rbConventionStr = (rbConvention != Qnil) ? rb_funcall2(rbConvention, rb_intern("to_s"), 0, NULL) : Qnil;
fnInfo->abi = (rbConventionStr != Qnil && strcmp(StringValueCStr(rbConventionStr), "stdcall") == 0)
? FFI_STDCALL : FFI_DEFAULT_ABI;
#else
fnInfo->abi = FFI_DEFAULT_ABI;
#endif
status = ffi_prep_cif(&fnInfo->ffi_cif, fnInfo->abi, fnInfo->parameterCount,
fnInfo->ffiReturnType, fnInfo->ffiParameterTypes);
switch (status) {
case FFI_BAD_ABI:
rb_raise(rb_eArgError, "Invalid ABI specified");
case FFI_BAD_TYPEDEF:
rb_raise(rb_eArgError, "Invalid argument type specified");
case FFI_OK:
break;
default:
rb_raise(rb_eArgError, "Unknown FFI error");
}
//.........这里部分代码省略.........
示例4: 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 if (TYPE(val) == T_STRING) {
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;
} else {
rb_raise(rb_eArgError,
"Header values must be of type string or array");
return ST_STOP;
}
return ST_CONTINUE;
}
示例5: control_frame_dump
static void
control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
{
ptrdiff_t pc = -1, bp = -1;
ptrdiff_t lfp = cfp->lfp - th->stack;
ptrdiff_t dfp = cfp->dfp - th->stack;
char lfp_in_heap = ' ', dfp_in_heap = ' ';
char posbuf[MAX_POSBUF+1];
int line = 0;
int nopos = 0;
const char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-";
VALUE tmp;
if (cfp->block_iseq != 0 && BUILTIN_TYPE(cfp->block_iseq) != T_NODE) {
biseq_name = ""; /* RSTRING(cfp->block_iseq->name)->ptr; */
}
if (lfp < 0 || (size_t)lfp > th->stack_size) {
lfp = (ptrdiff_t)cfp->lfp;
lfp_in_heap = 'p';
}
if (dfp < 0 || (size_t)dfp > th->stack_size) {
dfp = (ptrdiff_t)cfp->dfp;
dfp_in_heap = 'p';
}
if (cfp->bp) {
bp = cfp->bp - th->stack;
}
switch (VM_FRAME_TYPE(cfp)) {
case VM_FRAME_MAGIC_TOP:
magic = "TOP";
break;
case VM_FRAME_MAGIC_METHOD:
magic = "METHOD";
break;
case VM_FRAME_MAGIC_CLASS:
magic = "CLASS";
break;
case VM_FRAME_MAGIC_BLOCK:
magic = "BLOCK";
break;
case VM_FRAME_MAGIC_FINISH:
magic = "FINISH";
nopos = 1;
break;
case VM_FRAME_MAGIC_CFUNC:
magic = "CFUNC";
break;
case VM_FRAME_MAGIC_PROC:
magic = "PROC";
break;
case VM_FRAME_MAGIC_LAMBDA:
magic = "LAMBDA";
break;
case VM_FRAME_MAGIC_IFUNC:
magic = "IFUNC";
break;
case VM_FRAME_MAGIC_EVAL:
magic = "EVAL";
break;
case 0:
magic = "------";
break;
default:
magic = "(none)";
break;
}
if (0) {
tmp = rb_inspect(cfp->self);
selfstr = StringValueCStr(tmp);
}
else {
selfstr = "";
}
if (nopos) {
/* no name */
}
else if (cfp->iseq != 0) {
if (RUBY_VM_IFUNC_P(cfp->iseq)) {
iseq_name = "<ifunc>";
}
else {
int rb_vm_get_sourceline(rb_control_frame_t *);
pc = cfp->pc - cfp->iseq->iseq_encoded;
iseq_name = RSTRING_PTR(cfp->iseq->name);
line = rb_vm_get_sourceline(cfp);
if (line) {
snprintf(posbuf, MAX_POSBUF, "%s:%d", RSTRING_PTR(cfp->iseq->filename), line);
}
}
}
else if (cfp->me) {
iseq_name = rb_id2name(cfp->me->def->original_id);
snprintf(posbuf, MAX_POSBUF, ":%s", iseq_name);
line = -1;
//.........这里部分代码省略.........
示例6: db_execute
static VALUE db_execute(int argc, VALUE *argv, VALUE self)
{
sqlite3 * db = NULL;
void **ppDB = NULL;
sqlite3_stmt *statement = NULL;
const char* sql = NULL;
VALUE arRes = rb_ary_new();
VALUE* colNames = NULL;
int nRes = 0;
char * szErrMsg = 0;
int is_batch = 0;
if ((argc < 2) || (argc > 3))
rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc);
Data_Get_Struct(self, void *, ppDB);
db = (sqlite3 *)rho_db_get_handle(*ppDB);
sql = RSTRING_PTR(argv[0]);
is_batch = argv[1] == Qtrue ? 1 : 0;
RAWTRACE1("db_execute: %s", sql);
if ( is_batch )
{
rho_db_lock(*ppDB);
nRes = sqlite3_exec(db, sql, NULL, NULL, &szErrMsg);
rho_db_unlock(*ppDB);
}
else
{
rho_db_lock(*ppDB);
nRes = rho_db_prepare_statement(*ppDB, sql, -1, &statement);
//nRes = sqlite3_prepare_v2(db, sql, -1, &statement, NULL);
if ( nRes != SQLITE_OK)
{
szErrMsg = (char *)sqlite3_errmsg(db);
rho_db_unlock(*ppDB);
rb_raise(rb_eArgError, "could not prepare statement: %d; Message: %s",nRes, (szErrMsg?szErrMsg:""));
}
if ( argc > 2 )
{
int i = 0;
VALUE args = argv[2];
if ( RARRAY_LEN(args) > 0 && TYPE(RARRAY_PTR(args)[0]) == T_ARRAY )
args = RARRAY_PTR(args)[0];
for( ; i < RARRAY_LEN(args); i++ )
{
VALUE arg = RARRAY_PTR(args)[i];
if (NIL_P(arg))
{
sqlite3_bind_null(statement, i+1);
continue;
}
switch( TYPE(arg) )
{
case T_STRING:
sqlite3_bind_text(statement, i+1, RSTRING_PTR(arg), RSTRING_LEN(arg), SQLITE_TRANSIENT);
break;
case T_FLOAT:
sqlite3_bind_double(statement, i+1, NUM2DBL(arg));
break;
case T_FIXNUM:
case T_BIGNUM:
sqlite3_bind_int64(statement, i+1, NUM2LL(arg));
break;
default:
{
VALUE strVal = rb_funcall(arg, rb_intern("to_s"), 0);
sqlite3_bind_text(statement, i+1, RSTRING_PTR(strVal), -1, SQLITE_TRANSIENT);
}
break;
}
}
}
while( (nRes=sqlite3_step(statement)) == SQLITE_ROW) {
int nCount = sqlite3_data_count(statement);
int nCol = 0;
VALUE hashRec = rb_hash_new();
//if ( !colNames )
// colNames = getColNames(statement, nCount);
for(;nCol<nCount;nCol++){
int nColType = sqlite3_column_type(statement,nCol);
const char* szColName = sqlite3_column_name(statement,nCol);
VALUE colName = rb_str_new2(szColName);
VALUE colValue = Qnil;
switch(nColType){
case SQLITE_NULL:
break;
case SQLITE_FLOAT:
{
double dVal = sqlite3_column_double(statement, nCol);
//.........这里部分代码省略.........
示例7: rb_process_number
static VALUE rb_process_number(VALUE process_name)
{
char *p_className = RSTRING_PTR(process_name);
return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)),
rb_intern("getCount"), 0);
}
示例8: 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;
}
示例9: rb_str_clear_bang
/* call-seq: String#clear!
*
* Zero out the string contents.
*/
VALUE rb_str_clear_bang(VALUE str)
{
memset(RSTRING_PTR(str), 0, RSTRING_LEN(str));
return str;
}
示例10: mrb_str_format
mrb_value
mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
{
const char *p, *end;
char *buf;
long blen, bsiz;
mrb_value result;
int n;
int width, prec, flags = FNONE;
int nextarg = 1;
int posarg = 0;
mrb_value nextvalue;
mrb_value tmp;
mrb_value str;
mrb_value hash = mrb_undef_value();
#define CHECK_FOR_WIDTH(f) \
if ((f) & FWIDTH) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "width given twice"); \
} \
if ((f) & FPREC0) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "width after precision"); \
}
#define CHECK_FOR_FLAGS(f) \
if ((f) & FWIDTH) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "flag after width"); \
} \
if ((f) & FPREC0) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "flag after precision"); \
}
++argc;
--argv;
mrb_string_value(mrb, &fmt);
p = RSTRING_PTR(fmt);
end = p + RSTRING_LEN(fmt);
blen = 0;
bsiz = 120;
result = mrb_str_buf_new(mrb, bsiz);
buf = RSTRING_PTR(result);
memset(buf, 0, bsiz);
for (; p < end; p++) {
const char *t;
mrb_sym id = 0;
for (t = p; t < end && *t != '%'; t++) ;
PUSH(p, t - p);
if (t >= end)
goto sprint_exit; /* end of fmt string */
p = t + 1; /* skip `%' */
width = prec = -1;
nextvalue = mrb_undef_value();
retry:
switch (*p) {
default:
mrb_raisef(mrb, E_ARGUMENT_ERROR, "malformed format string - %%%c", *p);
break;
case ' ':
CHECK_FOR_FLAGS(flags);
flags |= FSPACE;
p++;
goto retry;
case '#':
CHECK_FOR_FLAGS(flags);
flags |= FSHARP;
p++;
goto retry;
case '+':
CHECK_FOR_FLAGS(flags);
flags |= FPLUS;
p++;
goto retry;
case '-':
CHECK_FOR_FLAGS(flags);
flags |= FMINUS;
p++;
goto retry;
case '0':
CHECK_FOR_FLAGS(flags);
flags |= FZERO;
p++;
goto retry;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = 0;
GETNUM(n, width);
if (*p == '$') {
if (!mrb_undef_p(nextvalue)) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "value given twice - %d$", n);
}
//.........这里部分代码省略.........
示例11: parse
/*
* call-seq:
* parser.parse(yaml)
*
* Parse the YAML document contained in +yaml+. Events will be called on
* the handler set on the parser instance.
*
* See Psych::Parser and Psych::Parser#handler
*/
static VALUE parse(int argc, VALUE *argv, VALUE self)
{
VALUE yaml, path;
yaml_parser_t * parser;
yaml_event_t event;
int done = 0;
int tainted = 0;
int state = 0;
int parser_encoding = YAML_ANY_ENCODING;
#ifdef HAVE_RUBY_ENCODING_H
int encoding = rb_utf8_encindex();
rb_encoding * internal_enc = rb_default_internal_encoding();
#endif
VALUE handler = rb_iv_get(self, "@handler");
if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) {
if(rb_respond_to(yaml, id_path))
path = rb_funcall(yaml, id_path, 0);
else
path = rb_str_new2("<unknown>");
}
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
yaml_parser_delete(parser);
yaml_parser_initialize(parser);
if (OBJ_TAINTED(yaml)) tainted = 1;
if (rb_respond_to(yaml, id_read)) {
#ifdef HAVE_RUBY_ENCODING_H
yaml = transcode_io(yaml, &parser_encoding);
yaml_parser_set_encoding(parser, parser_encoding);
#endif
yaml_parser_set_input(parser, io_reader, (void *)yaml);
if (RTEST(rb_obj_is_kind_of(yaml, rb_cIO))) tainted = 1;
} else {
StringValue(yaml);
#ifdef HAVE_RUBY_ENCODING_H
yaml = transcode_string(yaml, &parser_encoding);
yaml_parser_set_encoding(parser, parser_encoding);
#endif
yaml_parser_set_input_string(
parser,
(const unsigned char *)RSTRING_PTR(yaml),
(size_t)RSTRING_LEN(yaml)
);
}
while(!done) {
if(!yaml_parser_parse(parser, &event)) {
VALUE exception;
exception = make_exception(parser, path);
yaml_parser_delete(parser);
yaml_parser_initialize(parser);
rb_exc_raise(exception);
}
switch(event.type) {
case YAML_STREAM_START_EVENT:
{
VALUE args[2];
args[0] = handler;
args[1] = INT2NUM((long)event.data.stream_start.encoding);
rb_protect(protected_start_stream, (VALUE)args, &state);
}
break;
case YAML_DOCUMENT_START_EVENT:
{
VALUE args[4];
/* Get a list of tag directives (if any) */
VALUE tag_directives = rb_ary_new();
/* Grab the document version */
VALUE version = event.data.document_start.version_directive ?
rb_ary_new3(
(long)2,
INT2NUM((long)event.data.document_start.version_directive->major),
INT2NUM((long)event.data.document_start.version_directive->minor)
) : rb_ary_new();
if(event.data.document_start.tag_directives.start) {
yaml_tag_directive_t *start =
event.data.document_start.tag_directives.start;
yaml_tag_directive_t *end =
event.data.document_start.tag_directives.end;
for(; start != end; start++) {
VALUE handle = Qnil;
VALUE prefix = Qnil;
//.........这里部分代码省略.........
示例12: load_ext
static VALUE
load_ext(VALUE path)
{
SCOPE_SET(NOEX_PUBLIC);
return (VALUE)dln_load(RSTRING_PTR(path));
}
示例13: search_required
static int
search_required(VALUE fname, volatile VALUE *path, int safe_level)
{
VALUE tmp;
char *ext, *ftptr;
int type, ft = 0;
const char *loading;
*path = 0;
ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
if (ext && !strchr(ext, '/')) {
if (IS_RBEXT(ext)) {
if (rb_feature_p(ftptr, ext, TRUE, FALSE, &loading)) {
if (loading) *path = rb_str_new2(loading);
return 'r';
}
if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) {
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
if (!rb_feature_p(ftptr, ext, TRUE, TRUE, &loading) || loading)
*path = tmp;
return 'r';
}
return 0;
}
else if (IS_SOEXT(ext)) {
if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) {
if (loading) *path = rb_str_new2(loading);
return 's';
}
tmp = rb_str_new(RSTRING_PTR(fname), ext - RSTRING_PTR(fname));
#ifdef DLEXT2
OBJ_FREEZE(tmp);
if (rb_find_file_ext_safe(&tmp, loadable_ext + 1, safe_level)) {
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
*path = tmp;
return 's';
}
#else
rb_str_cat2(tmp, DLEXT);
OBJ_FREEZE(tmp);
if ((tmp = rb_find_file_safe(tmp, safe_level)) != 0) {
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
*path = tmp;
return 's';
}
#endif
}
else if (IS_DLEXT(ext)) {
if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) {
if (loading) *path = rb_str_new2(loading);
return 's';
}
if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) {
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
*path = tmp;
return 's';
}
}
}
else if ((ft = rb_feature_p(ftptr, 0, FALSE, FALSE, &loading)) == 'r') {
if (loading) *path = rb_str_new2(loading);
return 'r';
}
tmp = fname;
type = rb_find_file_ext_safe(&tmp, loadable_ext, safe_level);
switch (type) {
case 0:
if (ft)
break;
ftptr = RSTRING_PTR(tmp);
return rb_feature_p(ftptr, 0, FALSE, TRUE, 0);
default:
if (ft)
break;
case 1:
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
if (rb_feature_p(ftptr, ext, !--type, TRUE, &loading) && !loading)
break;
*path = tmp;
}
return type ? 's' : 'r';
}
示例14: rb_load_internal
static void
rb_load_internal(VALUE fname, int wrap)
{
int state;
rb_thread_t *th = GET_THREAD();
volatile VALUE wrapper = th->top_wrapper;
volatile VALUE self = th->top_self;
volatile int loaded = FALSE;
volatile int mild_compile_error;
#ifndef __GNUC__
rb_thread_t *volatile th0 = th;
#endif
th->errinfo = Qnil; /* ensure */
if (!wrap) {
rb_secure(4); /* should alter global state */
th->top_wrapper = 0;
}
else {
/* load in anonymous module as toplevel */
th->top_self = rb_obj_clone(rb_vm_top_self());
th->top_wrapper = rb_module_new();
rb_extend_object(th->top_self, th->top_wrapper);
}
mild_compile_error = th->mild_compile_error;
PUSH_TAG();
state = EXEC_TAG();
if (state == 0) {
NODE *node;
VALUE iseq;
th->mild_compile_error++;
node = (NODE *)rb_load_file(RSTRING_PTR(fname));
loaded = TRUE;
iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse);
th->mild_compile_error--;
rb_iseq_eval(iseq);
}
POP_TAG();
#ifndef __GNUC__
th = th0;
fname = RB_GC_GUARD(fname);
#endif
th->mild_compile_error = mild_compile_error;
th->top_self = self;
th->top_wrapper = wrapper;
if (!loaded) {
rb_exc_raise(GET_THREAD()->errinfo);
}
if (state) {
rb_vm_jump_tag_but_local_jump(state, Qundef);
}
if (!NIL_P(GET_THREAD()->errinfo)) {
/* exception during load */
rb_exc_raise(th->errinfo);
}
}
示例15: INT2BOOL
{
return INT2BOOL(Mix_Playing(NUM2INT(channel)));
}
static VALUE Mixer_s_playing_channels(VALUE mod)
{
return INT2NUM(Mix_Playing(-1));
}
static VALUE Wave_s_load(VALUE class, VALUE filename)
{
Mix_Chunk *chunk;
ExportFilenameStringValue(filename);
chunk = Mix_LoadWAV(RSTRING_PTR(filename));
if( chunk == NULL ) {
rb_raise(eSDLError, "Couldn't load wave file %s: %s",
RSTRING_PTR(filename), SDL_GetError());
}
return Wave_create(chunk);
}
static VALUE Wave_s_loadFromIO(VALUE class, VALUE io)
{
Mix_Chunk *wave;
wave = Mix_LoadWAV_RW(rubysdl_RWops_from_ruby_obj(io), 1);
if( wave == NULL ) {
rb_raise(eSDLError, "Couldn't load wave file from IO: %s",
Mix_GetError());
}