diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/ext/-test-/string |
Fresh start
Diffstat (limited to 'jni/ruby/ext/-test-/string')
-rw-r--r-- | jni/ruby/ext/-test-/string/Makefile | 384 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/coderange.c | 47 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/cstr.c | 57 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/depend | 115 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/ellipsize.c | 13 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/enc_associate.c | 14 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/enc_str_buf_cat.c | 14 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/extconf.h | 4 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/extconf.rb | 7 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/init.c | 11 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/modify.c | 22 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/nofree.c | 13 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/normalize.c | 17 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/qsort.c | 61 | ||||
-rw-r--r-- | jni/ruby/ext/-test-/string/set_len.c | 14 |
15 files changed, 793 insertions, 0 deletions
diff --git a/jni/ruby/ext/-test-/string/Makefile b/jni/ruby/ext/-test-/string/Makefile new file mode 100644 index 0000000..353778b --- /dev/null +++ b/jni/ruby/ext/-test-/string/Makefile @@ -0,0 +1,384 @@ + +SHELL = /bin/sh + +# V=0 quiet, V=1 verbose. other values don't work. +V = 0 +Q1 = $(V:1=) +Q = $(Q1:0=@) +ECHO1 = $(V:1=@:) +ECHO = $(ECHO1:0=@echo) +NULLCMD = : + +#### Start of system configuration section. #### +top_srcdir = $(topdir)/. +srcdir = $(top_srcdir)/ext/-test-/string +topdir = ../../.. +hdrdir = $(top_srcdir)/include +arch_hdrdir = $(extout)/include/$(arch) +PATH_SEPARATOR = : +VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby +RUBYLIB = +RUBYOPT = - +prefix = $(DESTDIR)/usr/local +rubysitearchprefix = $(rubylibprefix)/$(sitearch) +rubyarchprefix = $(rubylibprefix)/$(arch) +rubylibprefix = $(libdir)/$(RUBY_BASE_NAME) +exec_prefix = $(prefix) +vendorarchhdrdir = $(vendorhdrdir)/$(sitearch) +sitearchhdrdir = $(sitehdrdir)/$(sitearch) +rubyarchhdrdir = $(rubyhdrdir)/$(arch) +vendorhdrdir = $(rubyhdrdir)/vendor_ruby +sitehdrdir = $(rubyhdrdir)/site_ruby +rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME) +vendorarchdir = $(vendorlibdir)/$(sitearch) +vendorlibdir = $(vendordir)/$(ruby_version) +vendordir = $(rubylibprefix)/vendor_ruby +sitearchdir = $(sitelibdir)/$(sitearch) +sitelibdir = $(sitedir)/$(ruby_version) +sitedir = $(rubylibprefix)/site_ruby +rubyarchdir = $(rubylibdir)/$(arch) +rubylibdir = $(rubylibprefix)/$(ruby_version) +sitearchincludedir = $(includedir)/$(sitearch) +archincludedir = $(includedir)/$(arch) +sitearchlibdir = $(libdir)/$(sitearch) +archlibdir = $(libdir)/$(arch) +ridir = $(datarootdir)/$(RI_BASE_NAME) +mandir = $(datarootdir)/man +localedir = $(datarootdir)/locale +libdir = $(exec_prefix)/lib +psdir = $(docdir) +pdfdir = $(docdir) +dvidir = $(docdir) +htmldir = $(docdir) +infodir = $(datarootdir)/info +docdir = $(datarootdir)/doc/$(PACKAGE) +oldincludedir = $(DESTDIR)/usr/include +includedir = $(prefix)/include +localstatedir = $(prefix)/var +sharedstatedir = $(prefix)/com +sysconfdir = $(prefix)/etc +datadir = $(datarootdir) +datarootdir = $(prefix)/share +libexecdir = $(exec_prefix)/libexec +sbindir = $(exec_prefix)/sbin +bindir = $(exec_prefix)/bin +archdir = $(rubyarchdir) + + +CC = gcc +CXX = g++ +LIBRUBY = $(LIBRUBY_SO) +LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a +LIBRUBYARG_SHARED = -Wl,-R$(libdir) -L$(libdir) -l$(RUBY_SO_NAME) +LIBRUBYARG_STATIC = -Wl,-R$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static +empty = +OUTFLAG = -o $(empty) +COUTFLAG = -o $(empty) + +RUBY_EXTCONF_H = extconf.h +cflags = $(optflags) $(debugflags) $(warnflags) +optflags = -O3 -fno-fast-math +debugflags = -ggdb3 +warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat +CCDLFLAGS = -fPIC +CFLAGS = $(CCDLFLAGS) $(cflags) -fPIC $(ARCH_FLAG) +INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir) -I$(srcdir) -I$(topdir) -I$(top_srcdir) +DEFS = +CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" $(DEFS) $(cppflags) +CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG) +ldflags = -L. -fstack-protector -rdynamic -Wl,-export-dynamic +dldflags = +ARCH_FLAG = +DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG) +LDSHARED = $(CC) -shared +LDSHAREDXX = $(CXX) -shared +AR = ar +EXEEXT = + +RUBY_INSTALL_NAME = $(RUBY_BASE_NAME) +RUBY_SO_NAME = ruby +RUBYW_INSTALL_NAME = +RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version) +RUBYW_BASE_NAME = rubyw +RUBY_BASE_NAME = ruby + +arch = x86_64-linux +sitearch = $(arch) +ruby_version = 2.2.0 +ruby = $(topdir)/miniruby -I'$(topdir)' -I'$(top_srcdir)/lib' -I'$(extout)/$(arch)' -I'$(extout)/common' +RUBY = $(ruby) +ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h $(RUBY_EXTCONF_H) + +RM = rm -f +RM_RF = $(RUBY) -run -e rm -- -rf +RMDIRS = rmdir --ignore-fail-on-non-empty -p +MAKEDIRS = /bin/mkdir -p +INSTALL = /usr/bin/install -c +INSTALL_PROG = $(INSTALL) -m 0755 +INSTALL_DATA = $(INSTALL) -m 644 +COPY = cp +TOUCH = exit > + +#### End of system configuration section. #### + +preload = + +libpath = . $(topdir) +LIBPATH = -L. -L$(topdir) +DEFFILE = + +CLEANFILES = mkmf.log +DISTCLEANFILES = +DISTCLEANDIRS = + +extout = $(topdir)/.ext +extout_prefix = $(extout)$(target_prefix)/ +target_prefix = /-test-/string +LOCAL_LIBS = +LIBS = $(LIBRUBYARG_SHARED) -lpthread -lgmp -ldl -lcrypt -lm -lc +ORIG_SRCS = enc_associate.c qsort.c cstr.c init.c coderange.c normalize.c set_len.c nofree.c enc_str_buf_cat.c ellipsize.c modify.c +SRCS = $(ORIG_SRCS) +OBJS = enc_associate.o qsort.o cstr.o init.o coderange.o normalize.o set_len.o nofree.o enc_str_buf_cat.o ellipsize.o modify.o +HDRS = $(srcdir)/extconf.h +TARGET = string +TARGET_NAME = string +TARGET_ENTRY = Init_$(TARGET_NAME) +DLLIB = $(TARGET).so +EXTSTATIC = +STATIC_LIB = $(TARGET).a + +TIMESTAMP_DIR = $(extout)/.timestamp +BINDIR = $(extout)/bin +RUBYCOMMONDIR = $(extout)/common +RUBYLIBDIR = $(RUBYCOMMONDIR)$(target_prefix) +RUBYARCHDIR = $(extout)/$(arch)$(target_prefix) +HDRDIR = $(extout)/include/ruby$(target_prefix) +ARCHHDRDIR = $(extout)/include/$(arch)/ruby$(target_prefix) + +TARGET_SO = $(RUBYARCHDIR)/$(DLLIB) +CLEANLIBS = $(RUBYARCHDIR)/$(TARGET).so +CLEANOBJS = *.o *.bak + +all: install +static: all +.PHONY: all install static install-so install-rb +.PHONY: clean clean-so clean-static clean-rb + +clean-static:: +clean-rb-default:: +clean-rb:: +clean-so:: +clean: clean-so clean-static clean-rb-default clean-rb + -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time + +distclean-rb-default:: +distclean-rb:: +distclean-so:: +distclean-static:: +distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb + -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log + -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) + -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true + +realclean: distclean +install: install-so install-rb + +install-so: $(RUBYARCHDIR)/$(DLLIB) +clean-so:: + -$(Q)$(RM) $(RUBYARCHDIR)/$(DLLIB) + -$(Q)$(RMDIRS) $(RUBYARCHDIR) 2> /dev/null || true +clean-static:: + -$(Q)$(RM) $(STATIC_LIB) +install-rb: pre-install-rb install-rb-default +install-rb-default: pre-install-rb-default +pre-install-rb: Makefile +pre-install-rb-default: Makefile +pre-install-rb-default: + @$(NULLCMD) +$(TIMESTAMP_DIR)/.RUBYARCHDIR.-.-test-.-.string.time: + $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR) + $(Q) $(TOUCH) $@ + +site-install: site-install-so site-install-rb +site-install-so: install-so +site-install-rb: install-rb + +.SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S + +.cc.o: + $(ECHO) compiling $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< + +.cc.S: + $(ECHO) translating $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< + +.mm.o: + $(ECHO) compiling $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< + +.mm.S: + $(ECHO) translating $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< + +.cxx.o: + $(ECHO) compiling $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< + +.cxx.S: + $(ECHO) translating $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< + +.cpp.o: + $(ECHO) compiling $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< + +.cpp.S: + $(ECHO) translating $(<) + $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< + +.c.o: + $(ECHO) compiling $(<) + $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< + +.c.S: + $(ECHO) translating $(<) + $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $< + +.m.o: + $(ECHO) compiling $(<) + $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< + +.m.S: + $(ECHO) translating $(<) + $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $< + +$(RUBYARCHDIR)/$(DLLIB): $(OBJS) Makefile $(TIMESTAMP_DIR)/.RUBYARCHDIR.-.-test-.-.string.time + $(ECHO) linking shared-object -test-/string/$(DLLIB) + -$(Q)$(RM) $(@) + $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) + +$(STATIC_LIB): $(OBJS) + -$(Q)$(RM) $(@) + $(ECHO) linking static-library $(@) + $(Q) $(AR) cru $@ $(OBJS) + -$(Q)ranlib $(@) 2> /dev/null || true + +### +$(OBJS): $(RUBY_EXTCONF_H) + +# AUTOGENERATED DEPENDENCIES START +coderange.o: $(RUBY_EXTCONF_H) +coderange.o: $(arch_hdrdir)/ruby/config.h +coderange.o: $(hdrdir)/ruby/defines.h +coderange.o: $(hdrdir)/ruby/encoding.h +coderange.o: $(hdrdir)/ruby/intern.h +coderange.o: $(hdrdir)/ruby/missing.h +coderange.o: $(hdrdir)/ruby/oniguruma.h +coderange.o: $(hdrdir)/ruby/ruby.h +coderange.o: $(hdrdir)/ruby/st.h +coderange.o: $(hdrdir)/ruby/subst.h +coderange.o: coderange.c +cstr.o: $(RUBY_EXTCONF_H) +cstr.o: $(arch_hdrdir)/ruby/config.h +cstr.o: $(hdrdir)/ruby/defines.h +cstr.o: $(hdrdir)/ruby/encoding.h +cstr.o: $(hdrdir)/ruby/intern.h +cstr.o: $(hdrdir)/ruby/missing.h +cstr.o: $(hdrdir)/ruby/oniguruma.h +cstr.o: $(hdrdir)/ruby/ruby.h +cstr.o: $(hdrdir)/ruby/st.h +cstr.o: $(hdrdir)/ruby/subst.h +cstr.o: $(top_srcdir)/include/ruby.h +cstr.o: cstr.c +ellipsize.o: $(RUBY_EXTCONF_H) +ellipsize.o: $(arch_hdrdir)/ruby/config.h +ellipsize.o: $(hdrdir)/ruby/defines.h +ellipsize.o: $(hdrdir)/ruby/intern.h +ellipsize.o: $(hdrdir)/ruby/missing.h +ellipsize.o: $(hdrdir)/ruby/ruby.h +ellipsize.o: $(hdrdir)/ruby/st.h +ellipsize.o: $(hdrdir)/ruby/subst.h +ellipsize.o: $(top_srcdir)/include/ruby.h +ellipsize.o: ellipsize.c +enc_associate.o: $(RUBY_EXTCONF_H) +enc_associate.o: $(arch_hdrdir)/ruby/config.h +enc_associate.o: $(hdrdir)/ruby/defines.h +enc_associate.o: $(hdrdir)/ruby/encoding.h +enc_associate.o: $(hdrdir)/ruby/intern.h +enc_associate.o: $(hdrdir)/ruby/missing.h +enc_associate.o: $(hdrdir)/ruby/oniguruma.h +enc_associate.o: $(hdrdir)/ruby/ruby.h +enc_associate.o: $(hdrdir)/ruby/st.h +enc_associate.o: $(hdrdir)/ruby/subst.h +enc_associate.o: $(top_srcdir)/include/ruby.h +enc_associate.o: enc_associate.c +enc_str_buf_cat.o: $(RUBY_EXTCONF_H) +enc_str_buf_cat.o: $(arch_hdrdir)/ruby/config.h +enc_str_buf_cat.o: $(hdrdir)/ruby/defines.h +enc_str_buf_cat.o: $(hdrdir)/ruby/encoding.h +enc_str_buf_cat.o: $(hdrdir)/ruby/intern.h +enc_str_buf_cat.o: $(hdrdir)/ruby/missing.h +enc_str_buf_cat.o: $(hdrdir)/ruby/oniguruma.h +enc_str_buf_cat.o: $(hdrdir)/ruby/ruby.h +enc_str_buf_cat.o: $(hdrdir)/ruby/st.h +enc_str_buf_cat.o: $(hdrdir)/ruby/subst.h +enc_str_buf_cat.o: enc_str_buf_cat.c +init.o: $(RUBY_EXTCONF_H) +init.o: $(arch_hdrdir)/ruby/config.h +init.o: $(hdrdir)/ruby/defines.h +init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/missing.h +init.o: $(hdrdir)/ruby/ruby.h +init.o: $(hdrdir)/ruby/st.h +init.o: $(hdrdir)/ruby/subst.h +init.o: $(top_srcdir)/include/ruby.h +init.o: init.c +modify.o: $(RUBY_EXTCONF_H) +modify.o: $(arch_hdrdir)/ruby/config.h +modify.o: $(hdrdir)/ruby/defines.h +modify.o: $(hdrdir)/ruby/intern.h +modify.o: $(hdrdir)/ruby/missing.h +modify.o: $(hdrdir)/ruby/ruby.h +modify.o: $(hdrdir)/ruby/st.h +modify.o: $(hdrdir)/ruby/subst.h +modify.o: $(top_srcdir)/include/ruby.h +modify.o: modify.c +normalize.o: $(RUBY_EXTCONF_H) +normalize.o: $(arch_hdrdir)/ruby/config.h +normalize.o: $(hdrdir)/ruby/defines.h +normalize.o: $(hdrdir)/ruby/encoding.h +normalize.o: $(hdrdir)/ruby/intern.h +normalize.o: $(hdrdir)/ruby/io.h +normalize.o: $(hdrdir)/ruby/missing.h +normalize.o: $(hdrdir)/ruby/oniguruma.h +normalize.o: $(hdrdir)/ruby/ruby.h +normalize.o: $(hdrdir)/ruby/st.h +normalize.o: $(hdrdir)/ruby/subst.h +normalize.o: $(top_srcdir)/include/ruby.h +normalize.o: $(top_srcdir)/internal.h +normalize.o: normalize.c +qsort.o: $(RUBY_EXTCONF_H) +qsort.o: $(arch_hdrdir)/ruby/config.h +qsort.o: $(hdrdir)/ruby/defines.h +qsort.o: $(hdrdir)/ruby/encoding.h +qsort.o: $(hdrdir)/ruby/intern.h +qsort.o: $(hdrdir)/ruby/missing.h +qsort.o: $(hdrdir)/ruby/oniguruma.h +qsort.o: $(hdrdir)/ruby/ruby.h +qsort.o: $(hdrdir)/ruby/st.h +qsort.o: $(hdrdir)/ruby/subst.h +qsort.o: $(hdrdir)/ruby/util.h +qsort.o: $(top_srcdir)/include/ruby.h +qsort.o: qsort.c +set_len.o: $(RUBY_EXTCONF_H) +set_len.o: $(arch_hdrdir)/ruby/config.h +set_len.o: $(hdrdir)/ruby/defines.h +set_len.o: $(hdrdir)/ruby/intern.h +set_len.o: $(hdrdir)/ruby/missing.h +set_len.o: $(hdrdir)/ruby/ruby.h +set_len.o: $(hdrdir)/ruby/st.h +set_len.o: $(hdrdir)/ruby/subst.h +set_len.o: $(top_srcdir)/include/ruby.h +set_len.o: set_len.c +# AUTOGENERATED DEPENDENCIES END diff --git a/jni/ruby/ext/-test-/string/coderange.c b/jni/ruby/ext/-test-/string/coderange.c new file mode 100644 index 0000000..b93172d --- /dev/null +++ b/jni/ruby/ext/-test-/string/coderange.c @@ -0,0 +1,47 @@ +#include "ruby/ruby.h" +#include "ruby/encoding.h" + +static VALUE sym_7bit, sym_valid, sym_unknown, sym_broken; + +static VALUE +coderange_int2sym(int coderange) +{ + switch (coderange) { + case ENC_CODERANGE_7BIT: + return sym_7bit; + case ENC_CODERANGE_VALID: + return sym_valid; + case ENC_CODERANGE_UNKNOWN: + return sym_unknown; + case ENC_CODERANGE_BROKEN: + return sym_broken; + } + rb_bug("wrong condition of coderange"); + UNREACHABLE; +} + +/* return coderange without scan */ +static VALUE +str_coderange(VALUE str) +{ + return coderange_int2sym(ENC_CODERANGE(str)); +} + +/* scan coderange and return the result */ +static VALUE +str_coderange_scan(VALUE str) +{ + ENC_CODERANGE_SET(str, ENC_CODERANGE_UNKNOWN); + return coderange_int2sym(rb_enc_str_coderange(str)); +} + +void +Init_coderange(VALUE klass) +{ + sym_7bit = ID2SYM(rb_intern("7bit")); + sym_valid = ID2SYM(rb_intern("valid")); + sym_unknown = ID2SYM(rb_intern("unknown")); + sym_broken = ID2SYM(rb_intern("broken")); + rb_define_method(klass, "coderange", str_coderange, 0); + rb_define_method(klass, "coderange_scan", str_coderange_scan, 0); +} diff --git a/jni/ruby/ext/-test-/string/cstr.c b/jni/ruby/ext/-test-/string/cstr.c new file mode 100644 index 0000000..ba2e46b --- /dev/null +++ b/jni/ruby/ext/-test-/string/cstr.c @@ -0,0 +1,57 @@ +#include "ruby.h" +#include "ruby/encoding.h" + +static VALUE +bug_str_cstr_term(VALUE str) +{ + long len; + char *s; + int c; + rb_encoding *enc; + + rb_str_modify(str); + len = RSTRING_LEN(str); + RSTRING_PTR(str)[len] = 'x'; + s = StringValueCStr(str); + rb_gc(); + enc = rb_enc_get(str); + c = rb_enc_codepoint(&s[len], &s[len+rb_enc_mbminlen(enc)], enc); + return INT2NUM(c); +} + +static VALUE +bug_str_cstr_term_char(VALUE str) +{ + long len; + char *s; + int c; + rb_encoding *enc = rb_enc_get(str); + + RSTRING_GETMEM(str, s, len); + s += len; + len = rb_enc_mbminlen(enc); + c = rb_enc_precise_mbclen(s, s + len, enc); + if (!MBCLEN_CHARFOUND_P(c)) { + c = (unsigned char)*s; + } + else { + c = rb_enc_mbc_to_codepoint(s, s + len, enc); + if (!c) return Qnil; + } + return rb_enc_uint_chr((unsigned int)c, enc); +} + +static VALUE +bug_str_s_cstr_term_char(VALUE self, VALUE str) +{ + Check_Type(str, T_STRING); + return bug_str_cstr_term_char(str); +} + +void +Init_cstr(VALUE klass) +{ + rb_define_method(klass, "cstr_term", bug_str_cstr_term, 0); + rb_define_method(klass, "cstr_term_char", bug_str_cstr_term_char, 0); + rb_define_singleton_method(klass, "cstr_term_char", bug_str_s_cstr_term_char, 1); +} diff --git a/jni/ruby/ext/-test-/string/depend b/jni/ruby/ext/-test-/string/depend new file mode 100644 index 0000000..ef13e44 --- /dev/null +++ b/jni/ruby/ext/-test-/string/depend @@ -0,0 +1,115 @@ +# AUTOGENERATED DEPENDENCIES START +coderange.o: $(RUBY_EXTCONF_H) +coderange.o: $(arch_hdrdir)/ruby/config.h +coderange.o: $(hdrdir)/ruby/defines.h +coderange.o: $(hdrdir)/ruby/encoding.h +coderange.o: $(hdrdir)/ruby/intern.h +coderange.o: $(hdrdir)/ruby/missing.h +coderange.o: $(hdrdir)/ruby/oniguruma.h +coderange.o: $(hdrdir)/ruby/ruby.h +coderange.o: $(hdrdir)/ruby/st.h +coderange.o: $(hdrdir)/ruby/subst.h +coderange.o: coderange.c +cstr.o: $(RUBY_EXTCONF_H) +cstr.o: $(arch_hdrdir)/ruby/config.h +cstr.o: $(hdrdir)/ruby/defines.h +cstr.o: $(hdrdir)/ruby/encoding.h +cstr.o: $(hdrdir)/ruby/intern.h +cstr.o: $(hdrdir)/ruby/missing.h +cstr.o: $(hdrdir)/ruby/oniguruma.h +cstr.o: $(hdrdir)/ruby/ruby.h +cstr.o: $(hdrdir)/ruby/st.h +cstr.o: $(hdrdir)/ruby/subst.h +cstr.o: $(top_srcdir)/include/ruby.h +cstr.o: cstr.c +ellipsize.o: $(RUBY_EXTCONF_H) +ellipsize.o: $(arch_hdrdir)/ruby/config.h +ellipsize.o: $(hdrdir)/ruby/defines.h +ellipsize.o: $(hdrdir)/ruby/intern.h +ellipsize.o: $(hdrdir)/ruby/missing.h +ellipsize.o: $(hdrdir)/ruby/ruby.h +ellipsize.o: $(hdrdir)/ruby/st.h +ellipsize.o: $(hdrdir)/ruby/subst.h +ellipsize.o: $(top_srcdir)/include/ruby.h +ellipsize.o: ellipsize.c +enc_associate.o: $(RUBY_EXTCONF_H) +enc_associate.o: $(arch_hdrdir)/ruby/config.h +enc_associate.o: $(hdrdir)/ruby/defines.h +enc_associate.o: $(hdrdir)/ruby/encoding.h +enc_associate.o: $(hdrdir)/ruby/intern.h +enc_associate.o: $(hdrdir)/ruby/missing.h +enc_associate.o: $(hdrdir)/ruby/oniguruma.h +enc_associate.o: $(hdrdir)/ruby/ruby.h +enc_associate.o: $(hdrdir)/ruby/st.h +enc_associate.o: $(hdrdir)/ruby/subst.h +enc_associate.o: $(top_srcdir)/include/ruby.h +enc_associate.o: enc_associate.c +enc_str_buf_cat.o: $(RUBY_EXTCONF_H) +enc_str_buf_cat.o: $(arch_hdrdir)/ruby/config.h +enc_str_buf_cat.o: $(hdrdir)/ruby/defines.h +enc_str_buf_cat.o: $(hdrdir)/ruby/encoding.h +enc_str_buf_cat.o: $(hdrdir)/ruby/intern.h +enc_str_buf_cat.o: $(hdrdir)/ruby/missing.h +enc_str_buf_cat.o: $(hdrdir)/ruby/oniguruma.h +enc_str_buf_cat.o: $(hdrdir)/ruby/ruby.h +enc_str_buf_cat.o: $(hdrdir)/ruby/st.h +enc_str_buf_cat.o: $(hdrdir)/ruby/subst.h +enc_str_buf_cat.o: enc_str_buf_cat.c +init.o: $(RUBY_EXTCONF_H) +init.o: $(arch_hdrdir)/ruby/config.h +init.o: $(hdrdir)/ruby/defines.h +init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/missing.h +init.o: $(hdrdir)/ruby/ruby.h +init.o: $(hdrdir)/ruby/st.h +init.o: $(hdrdir)/ruby/subst.h +init.o: $(top_srcdir)/include/ruby.h +init.o: init.c +modify.o: $(RUBY_EXTCONF_H) +modify.o: $(arch_hdrdir)/ruby/config.h +modify.o: $(hdrdir)/ruby/defines.h +modify.o: $(hdrdir)/ruby/intern.h +modify.o: $(hdrdir)/ruby/missing.h +modify.o: $(hdrdir)/ruby/ruby.h +modify.o: $(hdrdir)/ruby/st.h +modify.o: $(hdrdir)/ruby/subst.h +modify.o: $(top_srcdir)/include/ruby.h +modify.o: modify.c +normalize.o: $(RUBY_EXTCONF_H) +normalize.o: $(arch_hdrdir)/ruby/config.h +normalize.o: $(hdrdir)/ruby/defines.h +normalize.o: $(hdrdir)/ruby/encoding.h +normalize.o: $(hdrdir)/ruby/intern.h +normalize.o: $(hdrdir)/ruby/io.h +normalize.o: $(hdrdir)/ruby/missing.h +normalize.o: $(hdrdir)/ruby/oniguruma.h +normalize.o: $(hdrdir)/ruby/ruby.h +normalize.o: $(hdrdir)/ruby/st.h +normalize.o: $(hdrdir)/ruby/subst.h +normalize.o: $(top_srcdir)/include/ruby.h +normalize.o: $(top_srcdir)/internal.h +normalize.o: normalize.c +qsort.o: $(RUBY_EXTCONF_H) +qsort.o: $(arch_hdrdir)/ruby/config.h +qsort.o: $(hdrdir)/ruby/defines.h +qsort.o: $(hdrdir)/ruby/encoding.h +qsort.o: $(hdrdir)/ruby/intern.h +qsort.o: $(hdrdir)/ruby/missing.h +qsort.o: $(hdrdir)/ruby/oniguruma.h +qsort.o: $(hdrdir)/ruby/ruby.h +qsort.o: $(hdrdir)/ruby/st.h +qsort.o: $(hdrdir)/ruby/subst.h +qsort.o: $(hdrdir)/ruby/util.h +qsort.o: $(top_srcdir)/include/ruby.h +qsort.o: qsort.c +set_len.o: $(RUBY_EXTCONF_H) +set_len.o: $(arch_hdrdir)/ruby/config.h +set_len.o: $(hdrdir)/ruby/defines.h +set_len.o: $(hdrdir)/ruby/intern.h +set_len.o: $(hdrdir)/ruby/missing.h +set_len.o: $(hdrdir)/ruby/ruby.h +set_len.o: $(hdrdir)/ruby/st.h +set_len.o: $(hdrdir)/ruby/subst.h +set_len.o: $(top_srcdir)/include/ruby.h +set_len.o: set_len.c +# AUTOGENERATED DEPENDENCIES END diff --git a/jni/ruby/ext/-test-/string/ellipsize.c b/jni/ruby/ext/-test-/string/ellipsize.c new file mode 100644 index 0000000..0451519 --- /dev/null +++ b/jni/ruby/ext/-test-/string/ellipsize.c @@ -0,0 +1,13 @@ +#include "ruby.h" + +static VALUE +bug_str_ellipsize(VALUE str, VALUE len) +{ + return rb_str_ellipsize(str, NUM2LONG(len)); +} + +void +Init_ellipsize(VALUE klass) +{ + rb_define_method(klass, "ellipsize", bug_str_ellipsize, 1); +} diff --git a/jni/ruby/ext/-test-/string/enc_associate.c b/jni/ruby/ext/-test-/string/enc_associate.c new file mode 100644 index 0000000..d6614fb --- /dev/null +++ b/jni/ruby/ext/-test-/string/enc_associate.c @@ -0,0 +1,14 @@ +#include "ruby.h" +#include "ruby/encoding.h" + +VALUE +bug_str_enc_associate(VALUE str, VALUE enc) +{ + return rb_enc_associate(str, rb_to_encoding(enc)); +} + +void +Init_enc_associate(VALUE klass) +{ + rb_define_method(klass, "associate_encoding!", bug_str_enc_associate, 1); +} diff --git a/jni/ruby/ext/-test-/string/enc_str_buf_cat.c b/jni/ruby/ext/-test-/string/enc_str_buf_cat.c new file mode 100644 index 0000000..5d583c6 --- /dev/null +++ b/jni/ruby/ext/-test-/string/enc_str_buf_cat.c @@ -0,0 +1,14 @@ +#include "ruby/ruby.h" +#include "ruby/encoding.h" + +static VALUE +enc_str_buf_cat(VALUE str, VALUE str2) +{ + return rb_enc_str_buf_cat(str, RSTRING_PTR(str2), RSTRING_LEN(str2), rb_enc_get(str2)); +} + +void +Init_enc_str_buf_cat(VALUE klass) +{ + rb_define_method(klass, "enc_str_buf_cat", enc_str_buf_cat, 1); +} diff --git a/jni/ruby/ext/-test-/string/extconf.h b/jni/ruby/ext/-test-/string/extconf.h new file mode 100644 index 0000000..48f039d --- /dev/null +++ b/jni/ruby/ext/-test-/string/extconf.h @@ -0,0 +1,4 @@ +#ifndef EXTCONF_H +#define EXTCONF_H +#define TEST_INIT_FUNCS(X) X(enc_associate) X(qsort) X(cstr) X(coderange) X(normalize) X(set_len) X(nofree) X(enc_str_buf_cat) X(ellipsize) X(modify) +#endif diff --git a/jni/ruby/ext/-test-/string/extconf.rb b/jni/ruby/ext/-test-/string/extconf.rb new file mode 100644 index 0000000..10d33cb --- /dev/null +++ b/jni/ruby/ext/-test-/string/extconf.rb @@ -0,0 +1,7 @@ +$INCFLAGS << " -I$(topdir) -I$(top_srcdir)" +$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] +inits = $srcs.map {|s| File.basename(s, ".*")} +inits.delete("init") +inits.map! {|s|"X(#{s})"} +$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\"" +create_makefile("-test-/string/string") diff --git a/jni/ruby/ext/-test-/string/init.c b/jni/ruby/ext/-test-/string/init.c new file mode 100644 index 0000000..0b3e4a6 --- /dev/null +++ b/jni/ruby/ext/-test-/string/init.c @@ -0,0 +1,11 @@ +#include "ruby.h" + +#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);} + +void +Init_string(void) +{ + VALUE mBug = rb_define_module("Bug"); + VALUE klass = rb_define_class_under(mBug, "String", rb_cString); + TEST_INIT_FUNCS(init); +} diff --git a/jni/ruby/ext/-test-/string/modify.c b/jni/ruby/ext/-test-/string/modify.c new file mode 100644 index 0000000..ddd2efd --- /dev/null +++ b/jni/ruby/ext/-test-/string/modify.c @@ -0,0 +1,22 @@ +#include "ruby.h" + +VALUE +bug_str_modify(VALUE str) +{ + rb_str_modify(str); + return str; +} + +VALUE +bug_str_modify_expand(VALUE str, VALUE expand) +{ + rb_str_modify_expand(str, NUM2LONG(expand)); + return str; +} + +void +Init_modify(VALUE klass) +{ + rb_define_method(klass, "modify!", bug_str_modify, 0); + rb_define_method(klass, "modify_expand!", bug_str_modify_expand, 1); +} diff --git a/jni/ruby/ext/-test-/string/nofree.c b/jni/ruby/ext/-test-/string/nofree.c new file mode 100644 index 0000000..d3d8071 --- /dev/null +++ b/jni/ruby/ext/-test-/string/nofree.c @@ -0,0 +1,13 @@ +#include "ruby.h" + +VALUE +bug_str_nofree(VALUE self) +{ + return rb_str_new_cstr("abcdef"); +} + +void +Init_nofree(VALUE klass) +{ + rb_define_singleton_method(klass, "nofree", bug_str_nofree, 0); +} diff --git a/jni/ruby/ext/-test-/string/normalize.c b/jni/ruby/ext/-test-/string/normalize.c new file mode 100644 index 0000000..2e16a46 --- /dev/null +++ b/jni/ruby/ext/-test-/string/normalize.c @@ -0,0 +1,17 @@ +#include "internal.h" + +#ifdef __APPLE__ +static VALUE +normalize_ospath(VALUE str) +{ + return rb_str_normalize_ospath(RSTRING_PTR(str), RSTRING_LEN(str)); +} +#else +#define normalize_ospath rb_f_notimplement +#endif + +void +Init_normalize(VALUE klass) +{ + rb_define_method(klass, "normalize_ospath", normalize_ospath, 0); +} diff --git a/jni/ruby/ext/-test-/string/qsort.c b/jni/ruby/ext/-test-/string/qsort.c new file mode 100644 index 0000000..0b34936 --- /dev/null +++ b/jni/ruby/ext/-test-/string/qsort.c @@ -0,0 +1,61 @@ +#include "ruby.h" +#include "ruby/util.h" +#include "ruby/encoding.h" + +struct sort_data { + rb_encoding *enc; + long elsize; +}; + +static int +cmp_1(const void *ap, const void *bp, void *dummy) +{ + struct sort_data *d = dummy; + VALUE a = rb_enc_str_new(ap, d->elsize, d->enc); + VALUE b = rb_enc_str_new(bp, d->elsize, d->enc); + VALUE retval = rb_yield_values(2, a, b); + return rb_cmpint(retval, a, b); +} + +static int +cmp_2(const void *ap, const void *bp, void *dummy) +{ + int a = *(const unsigned char *)ap; + int b = *(const unsigned char *)bp; + return a - b; +} + +static VALUE +bug_str_qsort_bang(int argc, VALUE *argv, VALUE str) +{ + VALUE beg, len, size; + long l, b = 0, n, s = 1; + struct sort_data d; + + rb_scan_args(argc, argv, "03", &beg, &len, &size); + l = RSTRING_LEN(str); + if (!NIL_P(beg) && (b = NUM2INT(beg)) < 0 && (b += l) < 0) { + rb_raise(rb_eArgError, "out of bounds"); + } + if (!NIL_P(size) && (s = NUM2INT(size)) < 0) { + rb_raise(rb_eArgError, "negative size"); + } + if (NIL_P(len) || + (((n = NUM2INT(len)) < 0) ? + (rb_raise(rb_eArgError, "negative length"), 0) : + (b + n * s > l))) { + n = (l - b) / s; + } + rb_str_modify(str); + d.enc = rb_enc_get(str); + d.elsize = s; + ruby_qsort(RSTRING_PTR(str) + b, n, s, + rb_block_given_p() ? cmp_1 : cmp_2, &d); + return str; +} + +void +Init_qsort(VALUE klass) +{ + rb_define_method(klass, "qsort!", bug_str_qsort_bang, -1); +} diff --git a/jni/ruby/ext/-test-/string/set_len.c b/jni/ruby/ext/-test-/string/set_len.c new file mode 100644 index 0000000..3c7d19d --- /dev/null +++ b/jni/ruby/ext/-test-/string/set_len.c @@ -0,0 +1,14 @@ +#include "ruby.h" + +static VALUE +bug_str_set_len(VALUE str, VALUE len) +{ + rb_str_set_len(str, NUM2LONG(len)); + return str; +} + +void +Init_set_len(VALUE klass) +{ + rb_define_method(klass, "set_len", bug_str_set_len, 1); +} |