Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex class: fix build error and, modify default enable. #454

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/mrbconf.h
Expand Up @@ -41,13 +41,15 @@
//#define POOL_PAGE_SIZE 16000

/* -DDISABLE_XXXX to drop the feature */
#define DISABLE_REGEXP /* regular expression classes */
//#define DISABLE_REGEXP /* regular expression classes */
//#define DISABLE_SPRINTF /* Kernel.sprintf method */
//#define DISABLE_MATH /* Math functions */
//#define DISABLE_TIME /* Time class */
//#define DISABLE_STRUCT /* Struct class */
//#define DISABLE_STDIO /* use of stdio */

#define INCLUDE_ENCODING

#undef HAVE_UNISTD_H /* WINDOWS */
#define HAVE_UNISTD_H /* LINUX */

Expand Down
6 changes: 5 additions & 1 deletion include/mruby.h
Expand Up @@ -107,6 +107,10 @@ typedef struct mrb_state {
struct RClass *nil_class;
struct RClass *symbol_class;
struct RClass *kernel_module;
#ifdef ENABLE_REGEXP
struct RClass *regex_class;
struct RClass *match_class;
#endif

struct heap_page *heaps;
struct heap_page *sweeps;
Expand All @@ -128,7 +132,7 @@ typedef struct mrb_state {

mrb_sym symidx;
struct kh_n2s *name2sym; /* symbol table */
#ifdef INCLUDE_REGEXP
#ifdef ENABLE_REGEXP
struct RNode *local_svar;/* regexp */
#endif

Expand Down
8 changes: 5 additions & 3 deletions include/mruby/class.h
Expand Up @@ -44,10 +44,12 @@ mrb_class(mrb_state *mrb, mrb_value v)

#ifdef ENABLE_REGEXP
case MRB_TT_REGEX:
/* mrb_raise(mrb, E_TYPE_ERROR, "type mismatch: %s given",
mrb_obj_classname(mrb, v)); */
/* return mrb->nil_class; */ /* not reach */
return mrb->regex_class;
case MRB_TT_MATCH:
mrb_raise(mrb, E_TYPE_ERROR, "type mismatch: %s given",
mrb_obj_classname(mrb, v));
return mrb->nil_class; /* not reach */
return mrb->match_class;
#endif
default:
return mrb_object(v)->c;
Expand Down
5 changes: 5 additions & 0 deletions include/mruby/string.h
Expand Up @@ -83,6 +83,11 @@ mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);

int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);

#ifdef ENABLE_REGEXP
mrb_value mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len);
mrb_value mrb_str_size(mrb_state *mrb, mrb_value self);
#endif

#if defined(__cplusplus)
} /* extern "C" { */
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Expand Up @@ -13,7 +13,7 @@ EXCEPT1 := $(YC) $(BASEDIR)/minimain.c
OBJY := $(patsubst %.c,%.o,$(YC))
OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard $(BASEDIR)/*.c)))
#OBJ2 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/regex/*.c))
#OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c))
OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c))
OBJS := $(OBJ1) $(OBJ2) $(OBJ3)

# libraries, includes
Expand Down
58 changes: 58 additions & 0 deletions src/ext/enc/ascii.c
@@ -0,0 +1,58 @@
/**********************************************************************
ascii.c - Oniguruma (regular expression library)
**********************************************************************/
/*-
* Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include "regenc.h"

static int
ascii_is_code_ctype(OnigCodePoint code, unsigned int ctype)
{
if (code < 128)
return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
else
return 0; /* return FALSE; */
}

OnigEncodingType OnigEncodingASCII = {
onigenc_single_byte_mbc_enc_len,
"US-ASCII", /* name */
1, /* max byte length */
1, /* min byte length */
onigenc_is_mbc_newline_0x0a,
onigenc_single_byte_mbc_to_code,
onigenc_single_byte_code_to_mbclen,
onigenc_single_byte_code_to_mbc,
onigenc_ascii_mbc_case_fold,
onigenc_ascii_apply_all_case_fold,
onigenc_ascii_get_case_fold_codes_by_str,
onigenc_minimum_property_name_to_ctype,
ascii_is_code_ctype,
onigenc_not_support_get_ctype_code_range,
onigenc_single_byte_left_adjust_char_head,
onigenc_always_true_is_allowed_reverse_match
};
3 changes: 3 additions & 0 deletions src/load.c
Expand Up @@ -329,6 +329,9 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32
mrb_int fix_num;
mrb_float f;
int ai = mrb_gc_arena_save(mrb);
#ifdef ENABLE_REGEXP
mrb_value str;
#endif

recordStart = src;
buf = (char *)mrb_malloc(mrb, bufsize);
Expand Down