• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_yield函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rb_yield函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_yield函数的具体用法?C++ rb_yield怎么用?C++ rb_yield使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rb_yield函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: rbclt_container_each_callback

static void
rbclt_container_each_callback (ClutterActor *actor, gpointer data)
{
  rb_yield (GOBJ2RVAL (actor));
}
开发者ID:orospakr,项目名称:rbclutter,代码行数:5,代码来源:rbcltcontainer.c


示例2: each_i

static VALUE
each_i(VALUE v, void *arg)
{
    rb_yield(v);
    return Qnil;
}
开发者ID:HumbleRepose,项目名称:MacRuby,代码行数:6,代码来源:range.c


示例3: cCommand_execute_reader

static VALUE cCommand_execute_reader(int argc, VALUE *argv, VALUE self) {
  VALUE query, reader;
  VALUE field_names, field_types;

  unsigned int field_count;
  unsigned int i;

  char guess_default_field_types = 0;
  VALUE connection = rb_iv_get(self, "@connection");
  VALUE mysql_connection = rb_iv_get(connection, "@connection");
  if (Qnil == mysql_connection) {
    rb_raise(eConnectionError, "This connection has already been closed.");
  }

  MYSQL *db = DATA_PTR(mysql_connection);

  MYSQL_RES *response = 0;
  MYSQL_FIELD *field;

  query = build_query_from_args(self, argc, argv);

  response = cCommand_execute(self, connection, db, query);

  if (!response) {
    return Qnil;
  }

  field_count = mysql_field_count(db);

  reader = rb_funcall(cReader, ID_NEW, 0);
  rb_iv_set(reader, "@connection", connection);
  rb_iv_set(reader, "@reader", Data_Wrap_Struct(rb_cObject, 0, 0, response));
  rb_iv_set(reader, "@opened", Qfalse);
  rb_iv_set(reader, "@field_count", INT2NUM(field_count));

  field_names = rb_ary_new();
  field_types = rb_iv_get(self, "@field_types");

  if ( field_types == Qnil || 0 == RARRAY_LEN(field_types) ) {
    field_types = rb_ary_new();
    guess_default_field_types = 1;
  } else if (RARRAY_LEN(field_types) != field_count) {
    // Whoops...  wrong number of types passed to set_types.  Close the reader and raise
    // and error
    rb_funcall(reader, rb_intern("close"), 0);
    rb_raise(rb_eArgError, "Field-count mismatch. Expected %ld fields, but the query yielded %d", RARRAY_LEN(field_types), field_count);
  }

  for(i = 0; i < field_count; i++) {
    field = mysql_fetch_field_direct(response, i);
    rb_ary_push(field_names, rb_str_new2(field->name));

    if (1 == guess_default_field_types) {
      rb_ary_push(field_types, infer_ruby_type(field));
    }
  }

  rb_iv_set(reader, "@fields", field_names);
  rb_iv_set(reader, "@field_types", field_types);

  if (rb_block_given_p()) {
    rb_yield(reader);
    rb_funcall(reader, rb_intern("close"), 0);
  }

  return reader;
}
开发者ID:NZX,项目名称:do,代码行数:67,代码来源:do_mysql.c


示例4: foreach


//.........这里部分代码省略.........
          len+=len2-1;
          nobackslash=start;
          free(line);
          free(line2);
          continue;
        }
      }
      break;
    }
    /* chomp! */
    if(line[len]==EOL){
      if(line[len-1]==CR)
        len-=1;
      line[len]='\0';
    }
    /* skip empty line */
    if(len<2)
      continue;

    ary = rb_ary_new();
    start=line;
    nobackslash=line;
    
    idx = 0;
    flag=1;

    while (nobackslash != NULL) {

      /* get full field */
      while(token=strstr(nobackslash, DELIM)){
        count=0;
        t2=token-1;
        while((t2>=line) && (*t2=='\\'))
          {++count;--t2;}
        if(count%2 ==1){ /* backslashed! skip */
          nobackslash=token;
          continue;
        }
        break;
      }

      if(token)
        *token='\0';
      else
        token=start+strlen(start);

      if(searchfield==idx){
        flag=0;
        /* do check! */
        sscanf(start,"%ld",&check);
        for(i=0;i<pairs_count;++i){
          /*rb_warn("check %ld: [%ld .. %ld]",check,pairs[i].low,pairs[i].high);*/
          if(pairs[i].low<check && pairs[i].high>check){
            /*rb_warn("check passed");*/
            flag=1; /* yahooo! */
            break;
          }
        }
      }

      /* not in ranges! */
      if(flag==0)
        break;

      rb_ary_store(ary, idx, rb_str_new(start, token-start));
      idx++;
      nobackslash=start=token+strlen(DELIM);
      while(token=strstr(nobackslash, DELIM)){
        count=0;
        t2=token-1;
        while((t2>=line) && (*t2=='\\'))
          {++count;--t2;}
        if(count%2 ==1){ /* backslashed! skip */
          nobackslash=token+strlen(DELIM);
          continue;
        }
        break;
      }
      nobackslash=token;
    }
    if(flag==0)
      continue;

    /* last item */
    rb_ary_store(ary, idx, rb_str_new(start, strlen(start)));
    /* OBJ_FREEZE(ary); */

    rb_yield(ary);
    /* FL_UNSET((ary), FL_FREEZE); */

    /* for(idx = 0; idx < RARRAY_LEN(ary); idx ++) {
      rb_ary_store(ary, idx, Qnil);
    } */

  }
  fclose(file);
  free(line);

  return Qnil;
}
开发者ID:JonMidhir,项目名称:ccsv,代码行数:101,代码来源:ccsv.c


示例5: pt_ps


//.........这里部分代码省略.........

    // Get the state of the process
    switch(procs[i].kp_proc.p_stat)
    {
      case SIDL:
        strcpy(state, "idle");
        break;
      case SRUN:
        strcpy(state, "run");
        break;
      case SSLEEP:
        strcpy(state, "sleep");
        break;
      case SSTOP:
        strcpy(state, "stop");
        break;
      case SZOMB:
        strcpy(state, "zombie");
        break;
      default:
        strcpy(state, "unknown");
        break;
    }

    // Get ttynum and ttydev. If ttynum is -1, there is no tty.
    if(procs[i].kp_eproc.e_tdev != -1){
      v_tty_num = INT2FIX(procs[i].kp_eproc.e_tdev),
      v_tty_dev = rb_str_new2(devname(procs[i].kp_eproc.e_tdev, S_IFCHR));
    }

    v_groups = rb_ary_new();

    for (g = 0; g < procs[i].kp_eproc.e_ucred.cr_ngroups; ++g)
      rb_ary_push(v_groups, INT2FIX(procs[i].kp_eproc.e_ucred.cr_groups[g]));

    v_pstruct = rb_struct_new(
      sProcStruct,
      INT2FIX(procs[i].kp_proc.p_pid),
      INT2FIX(procs[i].kp_eproc.e_ppid),
      INT2FIX(procs[i].kp_eproc.e_pgid),
      INT2FIX(procs[i].kp_eproc.e_pcred.p_ruid),
      INT2FIX(procs[i].kp_eproc.e_pcred.p_rgid),
      INT2FIX(procs[i].kp_eproc.e_ucred.cr_uid),
      rb_ary_entry(v_groups, 0),
      v_groups,
      INT2FIX(procs[i].kp_eproc.e_pcred.p_svuid),
      INT2FIX(procs[i].kp_eproc.e_pcred.p_svgid),
      rb_str_new2(procs[i].kp_proc.p_comm),
      rb_str_new2(state),
      rb_float_new(procs[i].kp_proc.p_pctcpu),
      Qnil,
      v_tty_num,
      v_tty_dev,
      rb_str_new2(procs[i].kp_eproc.e_wmesg),
      INT2FIX(procs[i].kp_proc.p_rtime.tv_sec),
      INT2FIX(procs[i].kp_proc.p_priority),
      INT2FIX(procs[i].kp_proc.p_usrpri),
      INT2FIX(procs[i].kp_proc.p_nice),
      v_cmdline,
      v_exe,
      v_environ,
      v_start_time,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_maxrss) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_ixrss) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_idrss) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_isrss) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_minflt) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_majflt) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nswap) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_inblock) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_oublock) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_msgsnd) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_msgrcv) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nsignals) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nvcsw) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nivcsw) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_utime.tv_sec) : Qnil,
      (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_stime.tv_sec) : Qnil
    );

    OBJ_FREEZE(v_pstruct); // This is read-only data

    if(rb_block_given_p())
      rb_yield(v_pstruct);
    else
      rb_ary_push(v_array, v_pstruct);
  }

  if(procs)
    free(procs);

  if(!rb_block_given_p()){
    if(NIL_P(v_pid))
      return v_array;
    else
      return v_pstruct;
  }

  return Qnil;
}
开发者ID:jrafanie,项目名称:sys-proctable,代码行数:101,代码来源:proctable.c


示例6: dict_each_key

static void
dict_each_key (const char *key, xmmsv_t *value, void *udata)
{
	rb_yield (ID2SYM (rb_intern (key)));
}
开发者ID:vdust,项目名称:xmms2-devel,代码行数:5,代码来源:rb_result.c


示例7: each


//.........这里部分代码省略.........
                column = UINT2NUM(*((unsigned char*)result_buffers[i].buffer));
              } else {
                column = INT2NUM(*((signed char*)result_buffers[i].buffer));
              }
              break;
            case MYSQL_TYPE_SHORT:        // short int
              if (result_buffers[i].is_unsigned) {
                column = UINT2NUM(*((unsigned short int*)result_buffers[i].buffer));
              } else  {
                column = INT2NUM(*((short int*)result_buffers[i].buffer));
              }
              break;
            case MYSQL_TYPE_INT24:        // int
            case MYSQL_TYPE_LONG:         // int
            case MYSQL_TYPE_YEAR:         // int
              if (result_buffers[i].is_unsigned) {
                column = UINT2NUM(*((unsigned int*)result_buffers[i].buffer));
              } else {
                column = INT2NUM(*((int*)result_buffers[i].buffer));
              }
              break;
            case MYSQL_TYPE_LONGLONG:     // long long int
              if (result_buffers[i].is_unsigned) {
                column = ULL2NUM(*((unsigned long long int*)result_buffers[i].buffer));
              } else {
                column = LL2NUM(*((long long int*)result_buffers[i].buffer));
              }
              break;
            case MYSQL_TYPE_FLOAT:        // float
              column = rb_float_new((double)(*((float*)result_buffers[i].buffer)));
              break;
            case MYSQL_TYPE_DOUBLE:       // double
              column = rb_float_new((double)(*((double*)result_buffers[i].buffer)));
              break;
            case MYSQL_TYPE_DATE:         // MYSQL_TIME
              ts = (MYSQL_TIME*)result_buffers[i].buffer;
              column = rb_funcall(cDate, rb_intern("new"), 3, INT2NUM(ts->year), INT2NUM(ts->month), INT2NUM(ts->day));
              break;
            case MYSQL_TYPE_TIME:         // MYSQL_TIME
              ts = (MYSQL_TIME*)result_buffers[i].buffer;
              column = rb_funcall(rb_cTime,
                  rb_intern("mktime"), 6,
                  UINT2NUM(Qnil),
                  UINT2NUM(Qnil),
                  UINT2NUM(Qnil),
                  UINT2NUM(ts->hour),
                  UINT2NUM(ts->minute),
                  UINT2NUM(ts->second));
              break;
            case MYSQL_TYPE_NEWDATE:      // MYSQL_TIME
            case MYSQL_TYPE_DATETIME:     // MYSQL_TIME
            case MYSQL_TYPE_TIMESTAMP:    // MYSQL_TIME
              ts = (MYSQL_TIME*)result_buffers[i].buffer;
              column = rb_funcall(rb_cTime,
                  rb_intern("mktime"), 6,
                  UINT2NUM(ts->year),
                  UINT2NUM(ts->month),
                  UINT2NUM(ts->day),
                  UINT2NUM(ts->hour),
                  UINT2NUM(ts->minute),
                  UINT2NUM(ts->second));
              break;
            case MYSQL_TYPE_DECIMAL:      // char[]
            case MYSQL_TYPE_NEWDECIMAL:   // char[]
              column = rb_funcall(cBigDecimal, rb_intern("new"), 1, rb_str_new(result_buffers[i].buffer, *(result_buffers[i].length)));
              break;
            case MYSQL_TYPE_STRING:       // char[]
            case MYSQL_TYPE_VAR_STRING:   // char[]
            case MYSQL_TYPE_VARCHAR:      // char[]
            case MYSQL_TYPE_TINY_BLOB:    // char[]
            case MYSQL_TYPE_BLOB:         // char[]
            case MYSQL_TYPE_MEDIUM_BLOB:  // char[]
            case MYSQL_TYPE_LONG_BLOB:    // char[]
            case MYSQL_TYPE_BIT:          // char[]
            case MYSQL_TYPE_SET:          // char[]
            case MYSQL_TYPE_ENUM:         // char[]
            case MYSQL_TYPE_GEOMETRY:     // char[]
              column = rb_str_new(result_buffers[i].buffer, *(result_buffers[i].length));
              break;
            default:
              rb_raise(cMysql2Error, "unhandled buffer type: %d",
                  result_buffers[i].buffer_type);
              break;
          }
        }

        rb_ary_store(row, (long)i, column);
      }

      rb_yield(row);
    }

    free(result_buffers);
    free(is_null);
    free(error);
    free(length);
  }

  return self;
}
开发者ID:johncant,项目名称:mysql2,代码行数:101,代码来源:statement.c


示例8: draw

/*
  call-seq: draw(hash = nil) { ... }

  Three keys are checked in the given hash : ":buffer" which is the buffer
  on which manipulation are done (by default, the actual buffer is taken),
  ":painter", which tell us to yield a +Joyau::Painter+ instead of a
  +Joyau::Buffer+ when true (false by default), and ":auto_update" which
  tell us whether we should update the buffer (true by default).

  It is mandatory to give a block to this function.

  Examples:
    Joyau.draw(:buffer => a_buffer, :painter => true)
    Joyau.draw(:auto_update => false)
    Joyau.draw(:painter => true)
    Joyau.draw(:buffer => a_buffer)
*/
VALUE Joyau_draw(int argc, VALUE *argv, VALUE self) {
   static bool can_draw = false;

   VALUE hash, block;
   rb_scan_args(argc, argv, "01&", &hash, &block);

   OSL_IMAGE *oldBuffer = oslGetDrawBuffer();
   Buffer *buffer = NULL;
   VALUE rbPainter = Qnil;
   bool painter = false;
   bool auto_update = true;
   bool ruby_buf = false;

   bool could_draw = can_draw;

   if (!NIL_P(hash)) {
      if (TYPE(hash) != T_HASH)
	 rb_raise(rb_eTypeError, "Hash expected for Joyau::draw.");
      
      VALUE rbBuffer = rb_hash_aref(hash, ID2SYM(rb_intern("buffer")));
      
      if (rb_obj_is_kind_of(rbBuffer, getClass("Buffer")) == Qfalse) {
	 if (rbBuffer != Qnil)
	    rb_raise(rb_eTypeError, ":buffer should be a Buffer (or nil).");
      }
      else {
	 buffer = getPtr<Buffer>(rbBuffer);
	 ruby_buf = true;
      }

      if (!buffer)
	 buffer = new Buffer(oldBuffer);

      if (rb_hash_aref(hash, ID2SYM(rb_intern("painter"))) == Qtrue) {
	 painter = true;
	 Painter painter(buffer);
	 rbPainter = createObject(getClass("Painter"), painter);
      }
      
      if (rb_hash_aref(hash, ID2SYM(rb_intern("auto_update"))) == Qfalse)
	 auto_update = false;
   }
   else {
      if (!buffer)
	 buffer = new Buffer(oldBuffer);
   }

   if (buffer->isScreen() && !can_draw) {
      can_draw = true;
      Graphics_startDraw(Qnil);
   }
   if (!NIL_P(block)) {
      buffer->setActual();
      
      if (painter)
	 rb_yield(rbPainter);
      else {
	 VALUE rbBuffer = createObject(getClass("Buffer"), *buffer, true);
	 rb_yield(rbBuffer);
      }

      if (buffer->isScreen() && !could_draw) {
	 can_draw = false;
	 Graphics_endDraw(Qnil);
      }
      if (auto_update && buffer->isScreen())
	 Graphics_sync(Qnil);
   }
   else
      rb_raise(rb_eArgError, "Block expected.");

   if (!ruby_buf) // We do not delete the buffer if it comes from Ruby.
      delete buffer;

   oslSetDrawBuffer(oldBuffer);

   return Qnil;
}
开发者ID:Epictetus,项目名称:Joyau,代码行数:95,代码来源:Buffer.cpp


示例9: enumerator_iter_i

static VALUE
enumerator_iter_i(VALUE i, VALUE enum_obj, int argc, VALUE *argv)
{
    struct enumerator *e = (struct enumerator *)enum_obj;
    return rb_yield(proc_call(e->proc, i));
}
开发者ID:yard,项目名称:yet-another-ruby-database,代码行数:6,代码来源:enumerator.c


示例10: obj_new_with_block_body

static VALUE
obj_new_with_block_body(VALUE arg)
{
  return rb_yield(arg);
}
开发者ID:htrb,项目名称:ngraph-gtk,代码行数:5,代码来源:ngraph.c


示例11: sync_body

static VALUE
sync_body(VALUE a)
{
    return rb_yield(Qundef);
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:5,代码来源:thread.c


示例12: iter_yield

static VALUE iter_yield(VALUE el, VALUE ary) {
  rb_yield(el);
  return Qnil;
}
开发者ID:DavidEGrayson,项目名称:rubyspec,代码行数:4,代码来源:array_spec.c


示例13: rb_tinytds_result_each

static VALUE rb_tinytds_result_each(int argc, VALUE * argv, VALUE self) {
  /* Local Vars */
  VALUE qopts, opts, block;
  ID timezone;
  int symbolize_keys = 0, as_array = 0, cache_rows = 0, first = 0, empty_sets = 0;
  tinytds_client_userdata *userdata;
  GET_RESULT_WRAPPER(self);
  userdata = (tinytds_client_userdata *)dbgetuserdata(rwrap->client);
  /* Merge Options Hash To Query Options. Populate Opts & Block Var. */
  qopts = rb_iv_get(self, "@query_options");
  if (rb_scan_args(argc, argv, "01&", &opts, &block) == 1)
    qopts = rb_funcall(qopts, intern_merge, 1, opts);
  rb_iv_set(self, "@query_options", qopts);
  /* Locals From Options */
  if (rb_hash_aref(qopts, sym_first) == Qtrue)
    first = 1;
  if (rb_hash_aref(qopts, sym_symbolize_keys) == Qtrue)
    symbolize_keys = 1;
  if (rb_hash_aref(qopts, sym_as) == sym_array)
    as_array = 1;
  if (rb_hash_aref(qopts, sym_cache_rows) == Qtrue)
    cache_rows = 1;
  if (rb_hash_aref(qopts, sym_timezone) == sym_local) {
    timezone = intern_local;
  } else if (rb_hash_aref(qopts, sym_timezone) == sym_utc) {
    timezone = intern_utc;
  } else {
    rb_warn(":timezone option must be :utc or :local - defaulting to :local");
    timezone = intern_local;
  }
  if (rb_hash_aref(qopts, sym_empty_sets) == Qtrue)
    empty_sets = 1;
  /* Make The Results Or Yield Existing */
  if (NIL_P(rwrap->results)) {
    RETCODE dbsqlok_rc, dbresults_rc;
    rwrap->results = rb_ary_new();
    dbsqlok_rc = rb_tinytds_result_ok_helper(rwrap->client);
    dbresults_rc = rb_tinytds_result_dbresults_retcode(self);
    while ((dbsqlok_rc == SUCCEED) && (dbresults_rc == SUCCEED)) {
      int has_rows = (DBROWS(rwrap->client) == SUCCEED) ? 1 : 0;
      if (has_rows || empty_sets || (rwrap->number_of_results == 0))
        rb_tinytds_result_fields(self);
      if ((has_rows || empty_sets) && rwrap->number_of_fields > 0) {
        /* Create rows for this result set. */
        unsigned long rowi = 0;
        VALUE result = rb_ary_new();
        while (nogvl_dbnextrow(rwrap->client) != NO_MORE_ROWS) {
          VALUE row = rb_tinytds_result_fetch_row(self, timezone, symbolize_keys, as_array);
          if (cache_rows)
            rb_ary_store(result, rowi, row);
          if (!NIL_P(block))
            rb_yield(row);
          if (first) {
            dbcanquery(rwrap->client);
            userdata->dbcancel_sent = 1;
          }
          rowi++;
        }
        rwrap->number_of_rows = rowi;
        /* Store the result. */
        if (cache_rows) {
          if (rwrap->number_of_results == 0) {
            rwrap->results = result;
          } else if (rwrap->number_of_results == 1) {
            VALUE multi_resultsets = rb_ary_new();
            rb_ary_store(multi_resultsets, 0, rwrap->results);
            rb_ary_store(multi_resultsets, 1, result);
            rwrap->results = multi_resultsets;
          } else {
            rb_ary_store(rwrap->results, rwrap->number_of_results, result);
          }
        }
        // If we find results increment the counter that helpers use and setup the next loop.
        rwrap->number_of_results = rwrap->number_of_results + 1;
        dbresults_rc = rb_tinytds_result_dbresults_retcode(self);
        rb_ary_store(rwrap->fields_processed, rwrap->number_of_results, Qnil);
      } else {
        // If we do not find results, side step the rb_tinytds_result_dbresults_retcode helper and
        // manually populate its memoized array while nullifing any memoized fields too before loop.
        dbresults_rc = nogvl_dbresults(rwrap->client);
        rb_ary_store(rwrap->dbresults_retcodes, rwrap->number_of_results, INT2FIX(dbresults_rc));
        rb_ary_store(rwrap->fields_processed, rwrap->number_of_results, Qnil);
      }
    }
    if (dbresults_rc == FAIL)
      rb_warn("TinyTDS: Something in the dbresults() while loop set the return code to FAIL.\n");
    userdata->dbsql_sent = 0;
  } else if (!NIL_P(block)) {
    unsigned long i;
    for (i = 0; i < rwrap->number_of_rows; i++) {
      rb_yield(rb_ary_entry(rwrap->results, i));
    }
  }
  return rwrap->results;
}
开发者ID:Monishonline,项目名称:tiny_tds,代码行数:95,代码来源:result.c


示例14: sb_yield

static VALUE sb_yield(VALUE self) {
  return rb_yield(INT2FIX(5));
}
开发者ID:atoulme,项目名称:rubinius,代码行数:3,代码来源:language_spec.c


示例15: initialize

/* call-seq: SQLite3::Database.new(file, options = {})
 *
 * Create a new Database object that opens the given file. If utf16
 * is +true+, the filename is interpreted as a UTF-16 encoded string.
 *
 * By default, the new database will return result rows as arrays
 * (#results_as_hash) and has type translation disabled (#type_translation=).
 */
static VALUE initialize(int argc, VALUE *argv, VALUE self)
{
  sqlite3RubyPtr ctx;
  VALUE file;
  VALUE opts;
  VALUE zvfs;
#ifdef HAVE_SQLITE3_OPEN_V2
  int mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
#endif
  int status;

  Data_Get_Struct(self, sqlite3Ruby, ctx);

  rb_scan_args(argc, argv, "12", &file, &opts, &zvfs);
#if defined StringValueCStr
  StringValuePtr(file);
  rb_check_safe_obj(file);
#else
  Check_SafeStr(file);
#endif
  if(NIL_P(opts)) opts = rb_hash_new();
  else Check_Type(opts, T_HASH);

#ifdef HAVE_RUBY_ENCODING_H
  if(UTF16_LE_P(file) || UTF16_BE_P(file)) {
    status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
  } else {
#endif

    if(Qtrue == rb_hash_aref(opts, sym_utf16)) {
      status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
    } else {

#ifdef HAVE_RUBY_ENCODING_H
      if(!UTF8_P(file)) {
        file = rb_str_export_to_enc(file, rb_utf8_encoding());
      }
#endif

      if (Qtrue == rb_hash_aref(opts, ID2SYM(rb_intern("readonly")))) {
#ifdef HAVE_SQLITE3_OPEN_V2
        mode = SQLITE_OPEN_READONLY;
#else
        rb_raise(rb_eNotImpError, "sqlite3-ruby was compiled against a version of sqlite that does not support readonly databases");
#endif
      }
#ifdef HAVE_SQLITE3_OPEN_V2
      status = sqlite3_open_v2(
          StringValuePtr(file),
          &ctx->db,
          mode,
          NIL_P(zvfs) ? NULL : StringValuePtr(zvfs)
      );
#else
      status = sqlite3_open(
          StringValuePtr(file),
          &ctx->db
      );
#endif
    }

#ifdef HAVE_RUBY_ENCODING_H
  }
#endif

  CHECK(ctx->db, status)

  rb_iv_set(self, "@tracefunc", Qnil);
  rb_iv_set(self, "@authorizer", Qnil);
  rb_iv_set(self, "@encoding", Qnil);
  rb_iv_set(self, "@busy_handler", Qnil);
  rb_iv_set(self, "@collations", rb_hash_new());
  rb_iv_set(self, "@functions", rb_hash_new());
  rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash));
  rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation));
#ifdef HAVE_SQLITE3_OPEN_V2
  rb_iv_set(self, "@readonly", mode == SQLITE_OPEN_READONLY ? Qtrue : Qfalse);
#else
  rb_iv_set(self, "@readonly", Qfalse);
#endif

  if(rb_block_given_p()) {
    rb_yield(self);
    rb_funcall(self, rb_intern("close"), 0);
  }

  return self;
}
开发者ID:00zl00,项目名称:AlfredWorkflow.com,代码行数:96,代码来源:database.c


示例16: sym_each_i

static VALUE
sym_each_i(VALUE v, void *arg)
{
    rb_yield(rb_str_intern(v));
    return Qnil;
}
开发者ID:agrimm,项目名称:ruby-benchmark-suite,代码行数:6,代码来源:range.c


示例17: yield_pair

static void
yield_pair(VALUE pair)
{
  rb_yield(pair);
}
开发者ID:sonsongithub,项目名称:sonson,代码行数:5,代码来源:pairmatcher.c


示例18: bdb_i_each_log_get

static VALUE
bdb_i_each_log_get(VALUE obj, int flag)
{
#if ! HAVE_ST_DB_ENV_LOG_CURSOR
    bdb_ENV *envst;
#endif
    struct dblsnst *lsnst, *lsnst1;
    DBT data;
    VALUE lsn, lsn1;
    VALUE res;
    int ret, init, flags;

    init = BDB_LOG_INIT;
#if ! HAVE_ST_DB_ENV_LOG_CURSOR
    GetEnvDB(obj, envst);
#else
    lsn = obj;
    Data_Get_Struct(obj, struct dblsnst, lsnst);
    flag = lsnst->flags;
    if (lsnst->cursor == 0) {
	DB_LSN *lsn1;

	init = BDB_LOG_SET;
	lsn1 = lsnst->lsn;
	lsn = bdb_makelsn(lsnst->env);
	Data_Get_Struct(lsn, struct dblsnst, lsnst);
	MEMCPY(lsnst->lsn, lsn1, DB_LSN, 1);
	bdb_log_cursor(lsn);
    }
#endif

    do {
#if ! HAVE_ST_DB_ENV_LOG_CURSOR
	lsn = bdb_makelsn(obj);
	Data_Get_Struct(lsn, struct dblsnst, lsnst);
#endif
	MEMZERO(&data, DBT, 1);
	data.flags |= DB_DBT_MALLOC;
	switch (init) {
	case BDB_LOG_INIT:
	    flags = (flag == DB_NEXT)?DB_FIRST:DB_LAST;
	    break;
	case BDB_LOG_SET:
	    flags = DB_SET;
	    break;
	default:
	    flags = flag;
	    break;
	}
	init = BDB_LOG_NEXT;
#if HAVE_ST_DB_ENV_LG_INFO
	if (!envst->envp->lg_info) {
	    rb_raise(bdb_eFatal, "log region not open");
	}
	ret = bdb_test_error(log_get(envst->envp->lg_info, lsnst->lsn, &data, flags));
#elif HAVE_ST_DB_ENV_LOG_CURSOR
	ret = bdb_test_error(lsnst->cursor->get(lsnst->cursor, lsnst->lsn, &data, flags));
	lsn1 = bdb_makelsn(lsnst->env);
	Data_Get_Struct(lsn1, struct dblsnst, lsnst1);
	MEMCPY(lsnst1->lsn, lsnst->lsn, DB_LSN, 1);
#else
	ret = bdb_test_error(log_get(envst->envp, lsnst->lsn, &data, flags));
	lsn1 = lsn;
#endif
	if (ret == DB_NOTFOUND) {
	    return Qnil;
	}
	res = rb_tainted_str_new(data.data, data.size);
	free(data.data);
	rb_yield(rb_assoc_new(res, lsn));
    } while (1);
    return Qnil;
}
开发者ID:mallowlabs,项目名称:ruby-bdb,代码行数:73,代码来源:log.c


示例19: rb_u_string_gsub


//.........这里部分代码省略.........
 *
 * @overload gsub(pattern)
 *
 *   Returns an Enumerator over the matches of PATTERN in the receiver.
 *
 *   The Regexp special variables `$&`, `$'`, <code>$\`</code>, `$1`, `$2`, …,
 *   `$`_n_ will be updated accordingly.
 *
 *   @param [Regexp, #to_str] pattern
 *   @return [Enumerator] */
VALUE
rb_u_string_gsub(int argc, VALUE *argv, VALUE self)
{
        VALUE pattern, replacement;
        VALUE replacements = Qnil;
        bool use_block = false;
        bool tainted = false;

        if (argc == 1) {
                RETURN_ENUMERATOR(self, argc, argv);
                use_block = true;
        }

        if (rb_scan_args(argc, argv, "11", &pattern, &replacement) == 2) {
                replacements = rb_check_convert_type(replacement, T_HASH,
                                                     "Hash", "to_hash");
                if (NIL_P(replacements))
                        StringValue(replacement);
                if (OBJ_TAINTED(replacement))
                        tainted = true;
        }

        pattern = rb_u_pattern_argument(pattern, true);

        VALUE str = rb_str_to_str(self);
        long begin = rb_reg_search(pattern, str, 0, 0);
        if (begin < 0)
                return self;

        const char *base = RSTRING_PTR(str);
        const char *p = base;
        const char *end = RSTRING_END(str);
        VALUE substituted = rb_u_str_buf_new(RSTRING_LEN(str) + 30);
        do {
                VALUE match = rb_backref_get();
                struct re_registers *registers = RMATCH_REGS(match);
                VALUE result;

                if (use_block || !NIL_P(replacements)) {
                        if (use_block) {
                                VALUE ustr = rb_u_string_new_rb(rb_reg_nth_match(0, match));
                                result = rb_u_string_object_as_string(rb_yield(ustr));
                        } else {
                                VALUE ustr = rb_u_string_new_c(self,
                                                               base + registers->beg[0],
                                                               registers->end[0] - registers->beg[0]);
                                result = rb_u_string_object_as_string(rb_hash_aref(replacements, ustr));
                        }

                        if (result == substituted)
                                rb_u_raise(rb_eRuntimeError,
                                           "result of block is string being built; please try not to cheat");
                } else
                        result =
#ifdef HAVE_RB_REG_REGSUB4
                        rb_reg_regsub(replacement, str, registers, pattern);
#else
                        rb_reg_regsub(replacement, str, registers);
#endif

                if (OBJ_TAINTED(result))
                        tainted = true;

                const struct rb_u_string *value = RVAL2USTRING_ANY(result);

                rb_str_buf_cat(substituted, p, registers->beg[0] - (p - base));
                rb_str_buf_cat(substituted, USTRING_STR(value), USTRING_LENGTH(value));
                OBJ_INFECT(substituted, result);

                p = base + registers->end[0];
                if (registers->beg[0] == registers->end[0])
                        p = u_next(p);
                if (p >= end)
                        break;

                begin = rb_reg_search(pattern, str, registers->end[0], 0);
        } while (begin >= 0);

        if (p < end)
                rb_str_buf_cat(substituted, p, end - p);

        rb_reg_search(pattern, str, end - p, 0);

        RBASIC(substituted)->klass = rb_obj_class(str);
        OBJ_INFECT(substituted, str);
        if (tainted)
                OBJ_TAINT(substituted);

        return rb_u_string_new_rb(substituted);
}
开发者ID:now,项目名称:u,代码行数:101,代码来源:rb_u_string_gsub.c


示例20: yield

Value yield(const Value& value)
{
	return rb::Value(rb_yield(value.to<VALUE>()));
}
开发者ID:Groogy,项目名称:rbSFML,代码行数:4,代码来源:base.cpp



注:本文中的rb_yield函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_yield_values函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_warning函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap