Sha256: 0e228be305739f7ecef2abf6e61c7e065042bc2720a214fd582a6a6ad44f32d8

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

/* $Id$ */

#include "ruby_libxml.h"

VALUE cXMLState;
VALUE LIBXML_STATE = Qnil;

static int dummy = 0;

static void rxml_state_free(int dummy)
{
  xmlCleanupParser();
  LIBXML_STATE = Qnil;
}

static VALUE rxml_state_alloc(VALUE klass)
{
#ifdef DEBUG
  fprintf(stderr, "Allocating state");
#endif

  xmlInitParser();

  return Data_Wrap_Struct(cXMLState, NULL, rxml_state_free, &dummy);
}

// Rdoc needs to know
#ifdef RDOC_NEVER_DEFINED
mLibXML = rb_define_module("LibXML");
mXML = rb_define_module_under(mLibXML, "XML");
#endif

void ruby_init_state(void)
{
  VALUE rb_mSingleton;
  cXMLState = rb_define_class_under(mXML, "State", rb_cObject);

  /* Mixin singleton so only one xml state object can be created. */
  rb_require("singleton");
  rb_mSingleton = rb_const_get(rb_cObject, rb_intern("Singleton"));
  rb_include_module(cXMLState, rb_mSingleton);

  rb_define_alloc_func(cXMLState, rxml_state_alloc);

  /* Create one instance of the state object that is used
   to initalize and cleanup libxml. Then register it with
   the garbage collector so its not freed until the process
   exists.*/
  LIBXML_STATE = rb_class_new_instance(0, NULL, cXMLState);
  rb_global_variable(&LIBXML_STATE);
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
libxml-ruby-0.9.6-x86-mswin32-60 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.5 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.5-x86-mswin32-60 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.6 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.7 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.7-x86-mswin32-60 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.8 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.8-x86-mswin32-60 ext/libxml/ruby_xml_state.c