Ruby  2.0.0p645(2015-04-13revision50299)
Data Structures | Macros | Typedefs | Functions | Variables
stringio.c File Reference
#include "ruby.h"
#include "ruby/io.h"
#include "ruby/encoding.h"

Go to the source code of this file.

Data Structures

struct  StringIO
 

Macros

#define IS_STRIO(obj)   (rb_typeddata_is_kind_of((obj), &strio_data_type))
 
#define error_inval(msg)   (errno = EINVAL, rb_sys_fail(msg))
 
#define check_strio(self)   ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
 
#define StringIO(obj)   get_strio(obj)
 
#define STRIO_READABLE   FL_USER4
 
#define STRIO_WRITABLE   FL_USER5
 
#define STRIO_READWRITE   (STRIO_READABLE|STRIO_WRITABLE)
 
#define STRIO_MODE_SET_P(strio, mode)
 
#define CLOSED(strio)   (!STRIO_MODE_SET_P(strio, READWRITE))
 
#define READABLE(strio)   STRIO_MODE_SET_P(strio, READABLE)
 
#define WRITABLE(strio)   STRIO_MODE_SET_P(strio, WRITABLE)
 
#define strio_binmode   strio_self
 
#define strio_fcntl   strio_unimpl
 
#define strio_flush   strio_self
 
#define strio_fsync   strio_0
 
#define strio_set_sync   strio_first
 
#define strio_tell   strio_get_pos
 
#define strio_addstr   rb_io_addstr
 
#define strio_print   rb_io_print
 
#define strio_printf   rb_io_printf
 
#define strio_puts   rb_io_puts
 
#define strio_syswrite   rb_io_write
 
#define strio_isatty   strio_false
 
#define strio_pid   strio_nil
 
#define strio_fileno   strio_nil
 

Typedefs

typedef char strio_flags_check [(STRIO_READABLE/FMODE_READABLE==STRIO_WRITABLE/FMODE_WRITABLE)*2-1]
 

Functions

static void strio_init (int, VALUE *, struct StringIO *, VALUE)
 
static struct StringIOstrio_alloc (void)
 
static void strio_mark (void *p)
 
static void strio_free (void *p)
 
static size_t strio_memsize (const void *p)
 
static struct StringIOget_strio (VALUE self)
 
static VALUE strio_substr (struct StringIO *ptr, long pos, long len)
 
static struct StringIOreadable (VALUE strio)
 
static struct StringIOwritable (VALUE strio)
 
static void check_modifiable (struct StringIO *ptr)
 
static VALUE strio_s_allocate (VALUE klass)
 
static VALUE strio_initialize (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_finalize (VALUE self)
 
static VALUE strio_s_open (int argc, VALUE *argv, VALUE klass)
 
static VALUE strio_false (VALUE self)
 
static VALUE strio_nil (VALUE self)
 
static VALUE strio_self (VALUE self)
 
static VALUE strio_0 (VALUE self)
 
static VALUE strio_first (VALUE self, VALUE arg)
 
static VALUE strio_unimpl (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_get_string (VALUE self)
 
static VALUE strio_set_string (VALUE self, VALUE string)
 
static VALUE strio_close (VALUE self)
 
static VALUE strio_close_read (VALUE self)
 
static VALUE strio_close_write (VALUE self)
 
static VALUE strio_closed (VALUE self)
 
static VALUE strio_closed_read (VALUE self)
 
static VALUE strio_closed_write (VALUE self)
 
static VALUE strio_eof (VALUE self)
 
static VALUE strio_copy (VALUE copy, VALUE orig)
 
static VALUE strio_get_lineno (VALUE self)
 
static VALUE strio_set_lineno (VALUE self, VALUE lineno)
 
static VALUE strio_reopen (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_get_pos (VALUE self)
 
static VALUE strio_set_pos (VALUE self, VALUE pos)
 
static VALUE strio_rewind (VALUE self)
 
static VALUE strio_seek (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_get_sync (VALUE self)
 
static VALUE strio_each_byte (VALUE self)
 
static VALUE strio_bytes (VALUE self)
 
static VALUE strio_getc (VALUE self)
 
static VALUE strio_getbyte (VALUE self)
 
static void strio_extend (struct StringIO *ptr, long pos, long len)
 
static VALUE strio_ungetc (VALUE self, VALUE c)
 
static VALUE strio_ungetbyte (VALUE self, VALUE c)
 
static VALUE strio_readchar (VALUE self)
 
static VALUE strio_readbyte (VALUE self)
 
static VALUE strio_each_char (VALUE self)
 
static VALUE strio_chars (VALUE self)
 
static VALUE strio_each_codepoint (VALUE self)
 
static VALUE strio_codepoints (VALUE self)
 
static void bm_init_skip (long *skip, const char *pat, long m)
 
static long bm_search (const char *little, long llen, const char *big, long blen, const long *skip)
 
static VALUE strio_getline (int argc, VALUE *argv, struct StringIO *ptr)
 
static VALUE strio_gets (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_readline (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_each (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_lines (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_readlines (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_write (VALUE self, VALUE str)
 
static VALUE strio_putc (VALUE self, VALUE ch)
 
static VALUE strio_read (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_sysread (int argc, VALUE *argv, VALUE self)
 
static VALUE strio_size (VALUE self)
 
static VALUE strio_truncate (VALUE self, VALUE len)
 
static VALUE strio_external_encoding (VALUE self)
 
static VALUE strio_internal_encoding (VALUE self)
 
static VALUE strio_set_encoding (int argc, VALUE *argv, VALUE self)
 
void Init_stringio ()
 

Variables

static const rb_data_type_t strio_data_type
 

Macro Definition Documentation

#define check_strio (   self)    ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))

Definition at line 83 of file stringio.c.

Referenced by get_strio(), strio_copy(), and strio_initialize().

#define CLOSED (   strio)    (!STRIO_MODE_SET_P(strio, READWRITE))

Definition at line 117 of file stringio.c.

Referenced by strio_close(), strio_closed(), and strio_seek().

#define error_inval (   msg)    (errno = EINVAL, rb_sys_fail(msg))

Definition at line 34 of file stringio.c.

Referenced by strio_seek(), strio_set_pos(), and strio_truncate().

#define IS_STRIO (   obj)    (rb_typeddata_is_kind_of((obj), &strio_data_type))

Definition at line 33 of file stringio.c.

#define READABLE (   strio)    STRIO_MODE_SET_P(strio, READABLE)

Definition at line 118 of file stringio.c.

Referenced by readable(), strio_close_read(), and strio_closed_read().

#define StringIO (   obj)    get_strio(obj)
#define strio_addstr   rb_io_addstr

Definition at line 1216 of file stringio.c.

Referenced by Init_stringio().

#define strio_binmode   strio_self

Definition at line 498 of file stringio.c.

Referenced by Init_stringio().

#define strio_fcntl   strio_unimpl

Definition at line 501 of file stringio.c.

Referenced by Init_stringio().

#define strio_fileno   strio_nil

Definition at line 1369 of file stringio.c.

Referenced by Init_stringio().

#define strio_flush   strio_self

Definition at line 504 of file stringio.c.

Referenced by Init_stringio().

#define strio_fsync   strio_0

Definition at line 507 of file stringio.c.

Referenced by Init_stringio().

#define strio_isatty   strio_false

Definition at line 1363 of file stringio.c.

Referenced by Init_stringio().

#define STRIO_MODE_SET_P (   strio,
  mode 
)
Value:
((RBASIC(strio)->flags & STRIO_##mode) && \
((struct StringIO*)DATA_PTR(strio))->flags & FMODE_##mode)
int flags
Definition: tcltklib.c:3022
VALUE mode
Definition: tcltklib.c:1663
DATA_PTR(self)
#define RBASIC(obj)

Definition at line 114 of file stringio.c.

#define strio_pid   strio_nil

Definition at line 1366 of file stringio.c.

Referenced by Init_stringio().

#define strio_print   rb_io_print

Definition at line 1225 of file stringio.c.

Referenced by Init_stringio().

#define strio_printf   rb_io_printf

Definition at line 1233 of file stringio.c.

Referenced by Init_stringio().

#define strio_puts   rb_io_puts

Definition at line 1265 of file stringio.c.

Referenced by Init_stringio().

#define STRIO_READABLE   FL_USER4

Definition at line 110 of file stringio.c.

Referenced by strio_close_read(), and strio_init().

#define STRIO_READWRITE   (STRIO_READABLE|STRIO_WRITABLE)

Definition at line 112 of file stringio.c.

Referenced by strio_close(), and strio_copy().

#define strio_set_sync   strio_first

Definition at line 627 of file stringio.c.

Referenced by Init_stringio().

#define strio_syswrite   rb_io_write

Definition at line 1355 of file stringio.c.

Referenced by Init_stringio().

#define strio_tell   strio_get_pos

Definition at line 629 of file stringio.c.

Referenced by Init_stringio().

#define STRIO_WRITABLE   FL_USER5

Definition at line 111 of file stringio.c.

Referenced by strio_close_write().

#define WRITABLE (   strio)    STRIO_MODE_SET_P(strio, WRITABLE)

Definition at line 119 of file stringio.c.

Referenced by strio_close_write(), strio_closed_write(), and writable().

Typedef Documentation

typedef char strio_flags_check[(STRIO_READABLE/FMODE_READABLE==STRIO_WRITABLE/FMODE_WRITABLE)*2-1]

Definition at line 113 of file stringio.c.

Function Documentation

static void bm_init_skip ( long *  skip,
const char *  pat,
long  m 
)
static

Definition at line 930 of file stringio.c.

References c, CHAR_BIT, and m.

Referenced by strio_getline().

static long bm_search ( const char *  little,
long  llen,
const char *  big,
long  blen,
const long *  skip 
)
static

Definition at line 943 of file stringio.c.

References i.

Referenced by strio_getline().

static void check_modifiable ( struct StringIO ptr)
static
static struct StringIO* get_strio ( VALUE  self)
static

Definition at line 86 of file stringio.c.

References check_strio, ptr, rb_eIOError, rb_io_taint_check(), and rb_raise().

void Init_stringio ( )
static struct StringIO* readable ( VALUE  strio)
static
static VALUE strio_0 ( VALUE  self)
static

Definition at line 276 of file stringio.c.

References INT2FIX, and StringIO.

static struct StringIO* strio_alloc ( void  )
static

Definition at line 37 of file stringio.c.

References ALLOC, StringIO::count, StringIO::flags, StringIO::lineno, StringIO::pos, ptr, Qnil, and StringIO::string.

Referenced by strio_initialize().

static VALUE strio_bytes ( VALUE  self)
static

Definition at line 656 of file stringio.c.

References ID2SYM, rb_block_given_p(), rb_enumeratorize(), rb_intern, rb_warn(), and strio_each_byte().

Referenced by Init_stringio().

static VALUE strio_chars ( VALUE  self)
static

Definition at line 876 of file stringio.c.

References ID2SYM, rb_block_given_p(), rb_enumeratorize(), rb_intern, rb_warn(), and strio_each_char().

Referenced by Init_stringio().

static VALUE strio_close ( VALUE  self)
static

Definition at line 343 of file stringio.c.

References CLOSED, Qnil, rb_eIOError, rb_raise(), RBASIC, StringIO, and STRIO_READWRITE.

Referenced by Init_stringio().

static VALUE strio_close_read ( VALUE  self)
static

Definition at line 361 of file stringio.c.

References Qnil, rb_eIOError, rb_raise(), RBASIC, READABLE, StringIO, and STRIO_READABLE.

Referenced by Init_stringio().

static VALUE strio_close_write ( VALUE  self)
static

Definition at line 379 of file stringio.c.

References Qnil, rb_eIOError, rb_raise(), RBASIC, StringIO, STRIO_WRITABLE, and WRITABLE.

Referenced by Init_stringio().

static VALUE strio_closed ( VALUE  self)
static

Definition at line 396 of file stringio.c.

References CLOSED, Qfalse, Qtrue, and StringIO.

Referenced by Init_stringio().

static VALUE strio_closed_read ( VALUE  self)
static

Definition at line 410 of file stringio.c.

References Qfalse, Qtrue, READABLE, and StringIO.

Referenced by Init_stringio().

static VALUE strio_closed_write ( VALUE  self)
static

Definition at line 424 of file stringio.c.

References Qfalse, Qtrue, StringIO, and WRITABLE.

Referenced by Init_stringio().

static VALUE strio_codepoints ( VALUE  self)
static

Definition at line 920 of file stringio.c.

References ID2SYM, rb_block_given_p(), rb_enumeratorize(), rb_intern, rb_warn(), and strio_each_codepoint().

Referenced by Init_stringio().

static VALUE strio_copy ( VALUE  copy,
VALUE  orig 
)
static
static VALUE strio_each ( int  argc,
VALUE argv,
VALUE  self 
)
static
static VALUE strio_each_byte ( VALUE  self)
static
static VALUE strio_each_char ( VALUE  self)
static

Definition at line 860 of file stringio.c.

References c, NIL_P(), rb_yield(), RETURN_ENUMERATOR, and strio_getc().

Referenced by Init_stringio(), and strio_chars().

static VALUE strio_each_codepoint ( VALUE  self)
static
static VALUE strio_eof ( VALUE  self)
static

Definition at line 440 of file stringio.c.

References StringIO::pos, ptr, Qfalse, Qtrue, readable(), RSTRING_LEN, and StringIO::string.

Referenced by Init_stringio().

static void strio_extend ( struct StringIO ptr,
long  pos,
long  len 
)
static
static VALUE strio_external_encoding ( VALUE  self)
static

Definition at line 1419 of file stringio.c.

References rb_enc_from_encoding(), rb_enc_get(), and StringIO.

Referenced by Init_stringio().

static VALUE strio_false ( VALUE  self)
static

Definition at line 246 of file stringio.c.

References Qfalse, and StringIO.

static VALUE strio_finalize ( VALUE  self)
static

Definition at line 219 of file stringio.c.

References StringIO::flags, FMODE_READWRITE, ptr, Qnil, StringIO::string, and StringIO.

Referenced by strio_s_open().

static VALUE strio_first ( VALUE  self,
VALUE  arg 
)
static

Definition at line 286 of file stringio.c.

References arg, and StringIO.

static void strio_free ( void p)
static

Definition at line 58 of file stringio.c.

References StringIO::count, p, ptr, and xfree.

Referenced by strio_copy().

static VALUE strio_get_lineno ( VALUE  self)
static

Definition at line 478 of file stringio.c.

References lineno, LONG2NUM, and StringIO.

Referenced by Init_stringio().

static VALUE strio_get_pos ( VALUE  self)
static

Definition at line 536 of file stringio.c.

References LONG2NUM, StringIO::pos, and StringIO.

Referenced by Init_stringio().

static VALUE strio_get_string ( VALUE  self)
static

Definition at line 310 of file stringio.c.

References StringIO.

Referenced by Init_stringio().

static VALUE strio_get_sync ( VALUE  self)
static

Definition at line 620 of file stringio.c.

References Qtrue, and StringIO.

Referenced by Init_stringio().

static VALUE strio_getbyte ( VALUE  self)
static

Definition at line 694 of file stringio.c.

References c, CHR2FIX, StringIO::pos, ptr, Qnil, readable(), RSTRING_LEN, RSTRING_PTR, and StringIO::string.

Referenced by Init_stringio().

static VALUE strio_getc ( VALUE  self)
static
static VALUE strio_getline ( int  argc,
VALUE argv,
struct StringIO ptr 
)
static
static VALUE strio_gets ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 1063 of file stringio.c.

References rb_lastline_set(), readable(), str, and strio_getline().

Referenced by Init_stringio().

static void strio_init ( int  argc,
VALUE argv,
struct StringIO ptr,
VALUE  self 
)
static
static VALUE strio_initialize ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 164 of file stringio.c.

References check_strio, DATA_PTR(), ptr, rb_call_super(), strio_alloc(), and strio_init().

Referenced by Init_stringio().

static VALUE strio_internal_encoding ( VALUE  self)
static

Definition at line 1433 of file stringio.c.

References Qnil.

Referenced by Init_stringio().

static VALUE strio_lines ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 1124 of file stringio.c.

References ID2SYM, rb_block_given_p(), rb_enumeratorize(), rb_intern, rb_warn(), and strio_each().

Referenced by Init_stringio().

static void strio_mark ( void p)
static

Definition at line 49 of file stringio.c.

References p, ptr, rb_gc_mark(), and StringIO::string.

static size_t strio_memsize ( const void p)
static

Definition at line 67 of file stringio.c.

References p, and ptr.

static VALUE strio_nil ( VALUE  self)
static

Definition at line 256 of file stringio.c.

References Qnil, and StringIO.

static VALUE strio_putc ( VALUE  self,
VALUE  ch 
)
static
static VALUE strio_read ( int  argc,
VALUE argv,
VALUE  self 
)
static
static VALUE strio_readbyte ( VALUE  self)
static

Definition at line 845 of file stringio.c.

References c, NIL_P(), rb_eof_error(), rb_funcall2(), and rb_intern.

Referenced by Init_stringio().

static VALUE strio_readchar ( VALUE  self)
static

Definition at line 831 of file stringio.c.

References c, NIL_P(), rb_eof_error(), rb_funcall2(), and rb_intern.

Referenced by Init_stringio().

static VALUE strio_readline ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 1080 of file stringio.c.

References NIL_P(), rb_eof_error(), rb_funcall2(), and rb_intern.

Referenced by Init_stringio().

static VALUE strio_readlines ( int  argc,
VALUE argv,
VALUE  self 
)
static
static VALUE strio_reopen ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 518 of file stringio.c.

References rb_io_taint_check(), RB_TYPE_P, StringIO, strio_copy(), strio_init(), and T_STRING.

Referenced by Init_stringio().

static VALUE strio_rewind ( VALUE  self)
static

Definition at line 567 of file stringio.c.

References INT2FIX, StringIO::lineno, StringIO::pos, ptr, and StringIO.

Referenced by Init_stringio().

static VALUE strio_s_allocate ( VALUE  klass)
static

Definition at line 153 of file stringio.c.

References TypedData_Wrap_Struct.

Referenced by Init_stringio().

static VALUE strio_s_open ( int  argc,
VALUE argv,
VALUE  klass 
)
static

Definition at line 235 of file stringio.c.

References obj, rb_block_given_p(), rb_class_new_instance(), rb_ensure(), rb_yield(), and strio_finalize().

Referenced by Init_stringio().

static VALUE strio_seek ( int  argc,
VALUE argv,
VALUE  self 
)
static
static VALUE strio_self ( VALUE  self)
static

Definition at line 266 of file stringio.c.

References StringIO.

static VALUE strio_set_encoding ( int  argc,
VALUE argv,
VALUE  self 
)
static
static VALUE strio_set_lineno ( VALUE  self,
VALUE  lineno 
)
static

Definition at line 491 of file stringio.c.

References lineno, NUM2LONG, and StringIO.

Referenced by Init_stringio().

static VALUE strio_set_pos ( VALUE  self,
VALUE  pos 
)
static

Definition at line 548 of file stringio.c.

References error_inval, NUM2LONG, p, StringIO::pos, ptr, and StringIO.

Referenced by Init_stringio().

static VALUE strio_set_string ( VALUE  self,
VALUE  string 
)
static
static VALUE strio_size ( VALUE  self)
static

Definition at line 1378 of file stringio.c.

References NIL_P(), rb_eIOError, rb_raise(), RSTRING_LEN, StringIO, and ULONG2NUM.

Referenced by Init_stringio().

static VALUE strio_substr ( struct StringIO ptr,
long  pos,
long  len 
)
static

Definition at line 97 of file stringio.c.

References enc, StringIO::pos, rb_enc_get(), rb_enc_str_new(), RSTRING_LEN, RSTRING_PTR, str, and StringIO::string.

Referenced by strio_getline(), and strio_read().

static VALUE strio_sysread ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 1346 of file stringio.c.

References NIL_P(), rb_eof_error(), rb_funcall2(), rb_intern, and val.

Referenced by Init_stringio().

static VALUE strio_truncate ( VALUE  self,
VALUE  len 
)
static
static VALUE strio_ungetbyte ( VALUE  self,
VALUE  c 
)
static
static VALUE strio_ungetc ( VALUE  self,
VALUE  c 
)
static
static VALUE strio_unimpl ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 296 of file stringio.c.

References rb_notimplement(), StringIO, and UNREACHABLE.

static VALUE strio_write ( VALUE  self,
VALUE  str 
)
static
static struct StringIO* writable ( VALUE  strio)
static

Variable Documentation

const rb_data_type_t strio_data_type
static
Initial value:
= {
"strio",
{
},
}
static void strio_free(void *p)
Definition: stringio.c:58
static void strio_mark(void *p)
Definition: stringio.c:49
static size_t strio_memsize(const void *p)
Definition: stringio.c:67

Definition at line 74 of file stringio.c.