Alien-SVN

 view release on metacpan or  search on metacpan

src/subversion/subversion/bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.c  view on Meta::CPAN

/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

/* -*- c-file-style: "ruby" -*- */
/* Tell swigutil_rb.h that we're inside the implementation */
#define SVN_SWIG_SWIGUTIL_RB_C

#include "swig_ruby_external_runtime.swg"
#include "swigutil_rb.h"
#include <st.h>

#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#undef _

#include "svn_private_config.h"

#ifndef RE_OPTION_IGNORECASE
#  ifdef ONIG_OPTION_IGNORECASE
#    define RE_OPTION_IGNORECASE ONIG_OPTION_IGNORECASE
#  endif
#endif

#ifndef RSTRING_LEN
#  define RSTRING_LEN(str) (RSTRING(str)->len)
#endif

#ifndef RSTRING_PTR
#  define RSTRING_PTR(str) (RSTRING(str)->ptr)
#endif

#include <locale.h>
#include <math.h>

#include "svn_hash.h"
#include "svn_nls.h"
#include "svn_pools.h"
#include "svn_props.h"
#include "svn_time.h"
#include "svn_utf.h"


#if APR_HAS_LARGE_FILES
#  define AOFF2NUM(num) LL2NUM(num)
#else
#  define AOFF2NUM(num) LONG2NUM(num)
#endif

#if SIZEOF_LONG_LONG == 8
#  define AI642NUM(num) LL2NUM(num)
#else
#  define AI642NUM(num) LONG2NUM(num)
#endif

#define EMPTY_CPP_ARGUMENT

#define POOL_P(obj) (RTEST(rb_obj_is_kind_of(obj, rb_svn_core_pool())))
#define CONTEXT_P(obj) (RTEST(rb_obj_is_kind_of(obj, rb_svn_client_context())))
#define SVN_ERR_P(obj) (RTEST(rb_obj_is_kind_of(obj, rb_svn_error())))

static VALUE mSvn = Qnil;
static VALUE mSvnClient = Qnil;
static VALUE mSvnUtil = Qnil;
static VALUE cSvnClientContext = Qnil;
static VALUE mSvnCore = Qnil;
static VALUE cSvnCorePool = Qnil;
static VALUE cSvnCoreStream = Qnil;
static VALUE cSvnDelta = Qnil;
static VALUE cSvnDeltaEditor = Qnil;
static VALUE cSvnDeltaTextDeltaWindowHandler = Qnil;
static VALUE cSvnError = Qnil;
static VALUE cSvnErrorSvnError = Qnil;
static VALUE cSvnFs = Qnil;
static VALUE cSvnFsFileSystem = Qnil;
static VALUE cSvnRa = Qnil;
static VALUE cSvnRaReporter3 = Qnil;

static apr_pool_t *swig_rb_pool;
static apr_allocator_t *swig_rb_allocator;

#define DECLARE_ID(key) static ID id_ ## key
#define DEFINE_ID(key) DEFINE_ID_WITH_NAME(key, #key)
#define DEFINE_ID_WITH_NAME(key, name) id_ ## key = rb_intern(name)

DECLARE_ID(code);
DECLARE_ID(message);
DECLARE_ID(call);
DECLARE_ID(read);
DECLARE_ID(write);
DECLARE_ID(eqq);
DECLARE_ID(baton);
DECLARE_ID(new);

src/subversion/subversion/bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.c  view on Meta::CPAN

  if (NIL_P(cSvnErrorSvnError)) {
    cSvnErrorSvnError = rb_const_get(rb_svn_error(), rb_intern("SvnError"));
  }
  return cSvnErrorSvnError;
}

static VALUE
rb_svn_fs(void)
{
  if (NIL_P(cSvnFs)) {
    cSvnFs = rb_const_get(rb_svn(), rb_intern("Fs"));
  }
  return cSvnFs;
}

static VALUE
rb_svn_fs_file_system(void)
{
  if (NIL_P(cSvnFsFileSystem)) {
    cSvnFsFileSystem = rb_const_get(rb_svn_fs(), rb_intern("FileSystem"));
    rb_ivar_set(cSvnFsFileSystem, id___batons__, rb_hash_new());
  }
  return cSvnFsFileSystem;
}

static VALUE
rb_svn_ra(void)
{
  if (NIL_P(cSvnRa)) {
    cSvnRa = rb_const_get(rb_svn(), rb_intern("Ra"));
  }
  return cSvnRa;
}

static VALUE
rb_svn_ra_reporter3(void)
{
  if (NIL_P(cSvnRaReporter3)) {
    cSvnRaReporter3 = rb_const_get(rb_svn_ra(), rb_intern("Reporter3"));
  }
  return cSvnRaReporter3;
}


/* constant resolver */
static VALUE
resolve_constant(VALUE parent, const char *prefix, VALUE name)
{
    VALUE const_name;

    const_name = rb_str_new2(prefix);
    rb_str_concat(const_name,
                  rb_funcall(rb_funcall(name, id_to_s, 0),
                             id_upcase, 0));
    return rb_const_get(parent, rb_intern(StringValuePtr(const_name)));
}


/* initialize */
static VALUE
svn_swig_rb_converter_to_locale_encoding(VALUE self, VALUE str)
{
  apr_pool_t *pool;
  svn_error_t *err;
  const char *dest;
  VALUE result;

  pool = svn_pool_create(NULL);
  err = svn_utf_cstring_from_utf8(&dest, StringValueCStr(str), pool);
  if (err) {
    svn_pool_destroy(pool);
    svn_swig_rb_handle_svn_error(err);
  }

  result = rb_str_new2(dest);
  svn_pool_destroy(pool);
  return result;
}

static VALUE
svn_swig_rb_locale_set(int argc, VALUE *argv, VALUE self)
{
  char *result;
  int category;
  const char *locale;
  VALUE rb_category, rb_locale;

  rb_scan_args(argc, argv, "02", &rb_category, &rb_locale);

  if (NIL_P(rb_category))
    category = LC_ALL;
  else
    category = NUM2INT(rb_category);

  if (NIL_P(rb_locale))
    locale = "";
  else
    locale = StringValueCStr(rb_locale);

  result = setlocale(category, locale);

  return result ? rb_str_new2(result) : Qnil;
}

static VALUE
svn_swig_rb_gettext_bindtextdomain(VALUE self, VALUE path)
{
#ifdef ENABLE_NLS
  bindtextdomain(PACKAGE_NAME, StringValueCStr(path));
#endif
  return Qnil;
}

static VALUE
svn_swig_rb_gettext__(VALUE self, VALUE message)
{
#ifdef ENABLE_NLS
  return rb_str_new2(_(StringValueCStr(message)));
#else
  return message;
#endif
}

static void
svn_swig_rb_initialize_ids(void)
{
  DEFINE_ID(code);
  DEFINE_ID(message);
  DEFINE_ID(call);
  DEFINE_ID(read);
  DEFINE_ID(write);
  DEFINE_ID_WITH_NAME(eqq, "===");
  DEFINE_ID(baton);
  DEFINE_ID(new);
  DEFINE_ID(new_corresponding_error);
  DEFINE_ID(set_target_revision);
  DEFINE_ID(open_root);
  DEFINE_ID(delete_entry);
  DEFINE_ID(add_directory);
  DEFINE_ID(open_directory);
  DEFINE_ID(change_dir_prop);
  DEFINE_ID(close_directory);
  DEFINE_ID(absent_directory);
  DEFINE_ID(add_file);
  DEFINE_ID(open_file);
  DEFINE_ID(apply_textdelta);
  DEFINE_ID(change_file_prop);
  DEFINE_ID(absent_file);
  DEFINE_ID(close_file);
  DEFINE_ID(close_edit);
  DEFINE_ID(abort_edit);
  DEFINE_ID(__pool__);
  DEFINE_ID(__pools__);
  DEFINE_ID(name);
  DEFINE_ID(value);
  DEFINE_ID(swig_type_regex);
  DEFINE_ID(open_tmp_file);
  DEFINE_ID(get_wc_prop);
  DEFINE_ID(set_wc_prop);
  DEFINE_ID(push_wc_prop);

src/subversion/subversion/bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.c  view on Meta::CPAN

    if (RTEST(rb_reg_match(re,
                           rb_funcall(rb_obj_class(objects[i]),
                                      id_name,
                                      0)))) {
      return objects[i];
    }
  }

  return Qnil;
}

static VALUE
svn_swig_rb_destroyer_destroy(VALUE self, VALUE target)
{
    VALUE objects[1];

    objects[0] = target;
    if (find_swig_type_object(1, objects) && DATA_PTR(target)) {
	svn_swig_rb_destroy_internal_pool(target);
	DATA_PTR(target) = NULL;
    }

    return Qnil;
}

void
svn_swig_rb_initialize(void)
{
  VALUE mSvnConverter, mSvnLocale, mSvnGetText, mSvnDestroyer;

  check_apr_status(apr_initialize(), rb_eLoadError, "cannot initialize APR: %s");

  if (atexit(apr_terminate)) {
    rb_raise(rb_eLoadError, "atexit registration failed");
  }

  check_apr_status(apr_allocator_create(&swig_rb_allocator),
		   rb_eLoadError, "failed to create allocator: %s");
  apr_allocator_max_free_set(swig_rb_allocator,
			     SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);

  swig_rb_pool = svn_pool_create_ex(NULL, swig_rb_allocator);
  apr_pool_tag(swig_rb_pool, "svn-ruby-pool");
#if APR_HAS_THREADS
  {
    apr_thread_mutex_t *mutex;

    check_apr_status(apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT,
					     swig_rb_pool),
		     rb_eLoadError, "failed to create allocator: %s");
    apr_allocator_mutex_set(swig_rb_allocator, mutex);
  }
#endif
  apr_allocator_owner_set(swig_rb_allocator, swig_rb_pool);

  svn_utf_initialize(swig_rb_pool);

  svn_swig_rb_initialize_ids();

  mSvnConverter = rb_define_module_under(rb_svn(), "Converter");
  rb_define_module_function(mSvnConverter, "to_locale_encoding",
                            svn_swig_rb_converter_to_locale_encoding, 1);

  mSvnLocale = rb_define_module_under(rb_svn(), "Locale");
  rb_define_const(mSvnLocale, "ALL", INT2NUM(LC_ALL));
  rb_define_const(mSvnLocale, "COLLATE", INT2NUM(LC_COLLATE));
  rb_define_const(mSvnLocale, "CTYPE", INT2NUM(LC_CTYPE));
#ifdef LC_MESSAGES
  rb_define_const(mSvnLocale, "MESSAGES", INT2NUM(LC_MESSAGES));
#endif
  rb_define_const(mSvnLocale, "MONETARY", INT2NUM(LC_MONETARY));
  rb_define_const(mSvnLocale, "NUMERIC", INT2NUM(LC_NUMERIC));
  rb_define_const(mSvnLocale, "TIME", INT2NUM(LC_TIME));
  rb_define_module_function(mSvnLocale, "set", svn_swig_rb_locale_set, -1);

  mSvnGetText = rb_define_module_under(rb_svn(), "GetText");
  rb_define_module_function(mSvnGetText, "bindtextdomain",
                            svn_swig_rb_gettext_bindtextdomain, 1);
  rb_define_module_function(mSvnGetText, "_", svn_swig_rb_gettext__, 1);

  mSvnDestroyer = rb_define_module_under(rb_svn(), "Destroyer");
  rb_define_module_function(mSvnDestroyer, "destroy",
			    svn_swig_rb_destroyer_destroy, 1);
}

apr_pool_t *
svn_swig_rb_pool(void)
{
    return swig_rb_pool;
}

apr_allocator_t *
svn_swig_rb_allocator(void)
{
    return swig_rb_allocator;
}


/* pool holder */
static VALUE
rb_svn_pool_holder(void)
{
  return rb_ivar_get(rb_svn_core_pool(), id___pools__);
}

static VALUE
rb_svn_fs_warning_callback_baton_holder(void)
{
  return rb_ivar_get(rb_svn_fs_file_system(), id___batons__);
}

static VALUE
rb_holder_push(VALUE holder, VALUE obj)
{
  VALUE key, objs;

  key = rb_obj_id(obj);
  objs = rb_hash_aref(holder, key);

  if (NIL_P(objs)) {
    objs = rb_ary_new();
    rb_hash_aset(holder, key, objs);
  }

  rb_ary_push(objs, obj);

  return Qnil;
}

static VALUE
rb_holder_pop(VALUE holder, VALUE obj)
{
  VALUE key, objs;
  VALUE result = Qnil;



( run in 0.709 second using v1.01-cache-2.11-cpan-ceb78f64989 )