Project

General

Profile

Feature #6129 » patch.diff

Glass_saga (Masaki Matsushita), 03/11/2012 11:35 PM

View differences:

configure.in
1426 1426
	      setuid setgid daemon select_large_fdset setenv unsetenv\
1427 1427
              mktime timegm gmtime_r clock_gettime gettimeofday poll ppoll\
1428 1428
              pread sendfile shutdown sigaltstack dl_iterate_phdr\
1429
              dup3 pipe2 posix_memalign memalign)
1429
              dup3 pipe2 posix_memalign memalign memmem)
1430 1430

  
1431 1431
AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
1432 1432
  [AC_TRY_COMPILE([
......
2726 2726
    AC_MSG_ERROR([failed])
2727 2727
    ])])
2728 2728
fi
2729
AC_CACHE_CHECK(for broken memmem, rb_cv_broken_memmem,
2730
  [AC_TRY_RUN([
2731
#include <string.h>
2732

  
2733
int
2734
main()
2735
{
2736
  char *str = "hogefugafoobar";
2737
  char *rs = "foo";
2738
  char *p;
2739

  
2740
  p = memmem(str, strlen(str), rs, strlen(rs));
2741
  if (p == str+8)
2742
    return 0;
2743
  else
2744
    return 1;
2745
}
2746
  ],
2747
  rb_cv_broken_memmem=no,
2748
  rb_cv_broken_memmem=yes,
2749
  rb_cv_broken_memmem=yes)
2750
])
2751

  
2752
if test "$rb_cv_broken_memmem" = yes; then
2753
  AC_DEFINE(BROKEN_MEMMEM, 1)
2754
fi
2729 2755

  
2730 2756
CPPFLAGS="$CPPFLAGS "'$(DEFS)'
2731 2757
test -z "$CPPFLAGS" || CPPFLAGS="$CPPFLAGS "; CPPFLAGS="$CPPFLAGS"'${cppflags}'
string.c
5979 5979
    return rb_str_split_m(1, &sep, str);
5980 5980
}
5981 5981

  
5982
static VALUE rb_str_valid_encoding_p(VALUE str);
5982 5983

  
5983 5984
/*
5984 5985
 *  call-seq:
......
6070 6071

  
6071 6072
    enc = rb_enc_check(str, rs);
6072 6073
    rslen = RSTRING_LEN(rs);
6074
#if defined(HAVE_MEMMEM) && !defined(BROKEN_MEMMEM)
6075
    if (rb_str_valid_encoding_p(str) && rb_str_valid_encoding_p(rs)) {
6076
	int rspara = 0;
6077
	long sublen, rest = len;
6078
	const char *e, *rsptr;
6079

  
6080
	if (rslen == 0) {
6081
	    rspara = 1;
6082
	    newline = '\n';
6083
	    rs = rb_usascii_str_new("\n\n", 2);
6084
	    if (!rb_enc_asciicompat(enc))
6085
		rs = rb_str_encode(rs, rb_enc_from_encoding(enc), 0, Qnil);
6086
	    rslen = RSTRING_LEN(rs);
6087
	}
6088

  
6089
	rsptr = RSTRING_PTR(rs);
6090

  
6091
	while (e = memmem(s, rest, rsptr, rslen)) {
6092
	    if (rspara) {
6093
		p = e;
6094
		rb_enc_codepoint_len(p, pend, &n, enc);
6095
		while (p < pend && rb_enc_codepoint(p, pend, enc) == newline)
6096
		    p += n;
6097
		sublen = p-s;
6098
	    }
6099
	    else {
6100
		sublen = e-s+rslen;
6101
	    }
6102
	    line = rb_str_new5(str, s, sublen);
6103
	    OBJ_INFECT(line, str);
6104
	    rb_enc_cr_str_copy_for_substr(line, str);
6105
	    rb_yield(line);
6106
	    str_mod_check(str, ptr, len);
6107
	    s += sublen;
6108
	    rest -= sublen;
6109
	}
6110
	goto finish;
6111
    }
6112
#endif
6073 6113
    if (rslen == 0) {
6074 6114
	newline = '\n';
6075 6115
    }