Sha256: db1828d82ffdf1c3c86b872797d23307acb018f0d7c45061ad0bac4e70702118

Contents?: true

Size: 1.09 KB

Versions: 165

Compression:

Stored size: 1.09 KB

Contents

#include <xml_io.h>

static ID id_read, id_write;

VALUE read_check(VALUE *args) {
  return rb_funcall(args[0], id_read, 1, args[1]);
}

VALUE read_failed(void) {
	return Qnil;
}

int io_read_callback(void * ctx, char * buffer, int len) {
  VALUE string, args[2];
  size_t str_len, safe_len;

  args[0] = (VALUE)ctx;
  args[1] = INT2NUM(len);

  string = rb_rescue(read_check, (VALUE)args, read_failed, 0);

  if(NIL_P(string)) return 0;

  str_len = (size_t)RSTRING_LEN(string);
  safe_len = str_len > (size_t)len ? (size_t)len : str_len;
  memcpy(buffer, StringValuePtr(string), safe_len);

  return (int)safe_len;
}

VALUE write_check(VALUE *args) {
  return rb_funcall(args[0], id_write, 1, args[1]);
}

VALUE write_failed(void) {
	return Qnil;
}

int io_write_callback(void * ctx, char * buffer, int len) {
  VALUE args[2];

  args[0] = (VALUE)ctx;
  args[1] = rb_str_new(buffer, (long)len);

  rb_rescue(write_check, (VALUE)args, write_failed, 0);
  return len;
}

int io_close_callback(void * ctx) {
  return 0;
}

void init_nokogiri_io() {
  id_read = rb_intern("read");
  id_write = rb_intern("write");
}

Version data entries

165 entries across 165 versions & 12 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.3.1-x64-mingw32/ext/nokogiri/xml_io.c
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.3.1-x64-mingw32/ext/nokogiri/xml_io.c
vagrant-cloudstack-1.2.0 vendor/bundle/gems/nokogiri-1.6.3.1-x86-mingw32/ext/nokogiri/xml_io.c
vagrant-cloudstack-1.1.0 vendor/bundle/gems/nokogiri-1.6.3.1/ext/nokogiri/xml_io.c
nokogiri-1.6.3.1 ext/nokogiri/xml_io.c
nokogiri-1.6.3.1-x86-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.6.3.1-x64-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.6.3.1-java ext/nokogiri/xml_io.c
nokogiri-1.6.3 ext/nokogiri/xml_io.c
nokogiri-1.6.3-x86-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.6.3-x64-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.6.3-java ext/nokogiri/xml_io.c
gss-0.0.7 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.6.2.1-x86-mingw32/ext/nokogiri/xml_io.c
gss-0.0.6 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.6.2.1-x86-mingw32/ext/nokogiri/xml_io.c
gss-0.0.5 vendor/bundle/ruby/1.9.1/gems/nokogiri-1.6.2.1-x86-mingw32/ext/nokogiri/xml_io.c
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.2.1/ext/nokogiri/xml_io.c
nokogiri-1.6.3.rc3 ext/nokogiri/xml_io.c
nokogiri-1.6.3.rc3-x86-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.6.3.rc3-x64-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.6.3.rc3-java ext/nokogiri/xml_io.c