json_pure 1.2.4 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,197 @@
1
+ #ifndef _GENERATOR_H_
2
+ #define _GENERATOR_H_
3
+
4
+ #include <string.h>
5
+ #include <assert.h>
6
+ #include <math.h>
7
+
8
+ #include "ruby.h"
9
+
10
+ #if HAVE_RUBY_RE_H
11
+ #include "ruby/re.h"
12
+ #endif
13
+
14
+ #if HAVE_RE_H
15
+ #include "re.h"
16
+ #endif
17
+
18
+ #ifdef HAVE_RUBY_ENCODING_H
19
+ #include "ruby/encoding.h"
20
+ #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
21
+ #else
22
+ #define FORCE_UTF8(obj)
23
+ #endif
24
+
25
+ #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
26
+
27
+ #ifndef RHASH_SIZE
28
+ #define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
29
+ #endif
30
+
31
+ #ifndef RFLOAT_VALUE
32
+ #define RFLOAT_VALUE(val) (RFLOAT(val)->value)
33
+ #endif
34
+
35
+ #ifndef RARRAY_PTR
36
+ #define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
37
+ #endif
38
+ #ifndef RARRAY_LEN
39
+ #define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
40
+ #endif
41
+ #ifndef RSTRING_PTR
42
+ #define RSTRING_PTR(string) RSTRING(string)->ptr
43
+ #endif
44
+ #ifndef RSTRING_LEN
45
+ #define RSTRING_LEN(string) RSTRING(string)->len
46
+ #endif
47
+
48
+ #define RSTRING_PAIR(string) RSTRING_PTR(string), RSTRING_LEN(string)
49
+
50
+ /* fbuffer implementation */
51
+
52
+ typedef struct FBufferStruct {
53
+ unsigned int initial_length;
54
+ char *ptr;
55
+ unsigned int len;
56
+ unsigned int capa;
57
+ } FBuffer;
58
+
59
+ #define FBUFFER_INITIAL_LENGTH 4096
60
+
61
+ #define FBUFFER_PTR(fb) (fb->ptr)
62
+ #define FBUFFER_LEN(fb) (fb->len)
63
+ #define FBUFFER_CAPA(fb) (fb->capa)
64
+ #define FBUFFER_PAIR(fb) FBUFFER_PTR(fb), FBUFFER_LEN(fb)
65
+
66
+ static char *fstrndup(const char *ptr, int len);
67
+ static FBuffer *fbuffer_alloc();
68
+ static FBuffer *fbuffer_alloc_with_length(unsigned initial_length);
69
+ static void fbuffer_free(FBuffer *fb);
70
+ static void fbuffer_free_only_buffer(FBuffer *fb);
71
+ static void fbuffer_clear(FBuffer *fb);
72
+ static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned int len);
73
+ static void fbuffer_append_long(FBuffer *fb, long number);
74
+ static void fbuffer_append_char(FBuffer *fb, char newchr);
75
+ static FBuffer *fbuffer_dup(FBuffer *fb);
76
+ static VALUE fbuffer_to_s(FBuffer *fb);
77
+
78
+ /* unicode defintions */
79
+
80
+ #define UNI_STRICT_CONVERSION 1
81
+
82
+ typedef unsigned long UTF32; /* at least 32 bits */
83
+ typedef unsigned short UTF16; /* at least 16 bits */
84
+ typedef unsigned char UTF8; /* typically 8 bits */
85
+
86
+ #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
87
+ #define UNI_MAX_BMP (UTF32)0x0000FFFF
88
+ #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
89
+ #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
90
+ #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
91
+
92
+ #define UNI_SUR_HIGH_START (UTF32)0xD800
93
+ #define UNI_SUR_HIGH_END (UTF32)0xDBFF
94
+ #define UNI_SUR_LOW_START (UTF32)0xDC00
95
+ #define UNI_SUR_LOW_END (UTF32)0xDFFF
96
+
97
+ static const int halfShift = 10; /* used for shifting by 10 bits */
98
+
99
+ static const UTF32 halfBase = 0x0010000UL;
100
+ static const UTF32 halfMask = 0x3FFUL;
101
+
102
+ static unsigned char isLegalUTF8(const UTF8 *source, int length);
103
+ static void unicode_escape(char *buf, UTF16 character);
104
+ static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
105
+ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
106
+ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
107
+
108
+ /* ruby api and some helpers */
109
+
110
+ typedef struct JSON_Generator_StateStruct {
111
+ char *indent;
112
+ long indent_len;
113
+ char *space;
114
+ long space_len;
115
+ char *space_before;
116
+ long space_before_len;
117
+ char *object_nl;
118
+ long object_nl_len;
119
+ char *array_nl;
120
+ long array_nl_len;
121
+ FBuffer *array_delim;
122
+ FBuffer *object_delim;
123
+ FBuffer *object_delim2;
124
+ long max_nesting;
125
+ char allow_nan;
126
+ char ascii_only;
127
+ long depth;
128
+ } JSON_Generator_State;
129
+
130
+ #define GET_STATE(self) \
131
+ JSON_Generator_State *state; \
132
+ Data_Get_Struct(self, JSON_Generator_State, state)
133
+
134
+ #define GENERATE_JSON(type) \
135
+ FBuffer *buffer; \
136
+ VALUE Vstate; \
137
+ JSON_Generator_State *state; \
138
+ \
139
+ rb_scan_args(argc, argv, "01", &Vstate); \
140
+ Vstate = cState_from_state_s(cState, Vstate); \
141
+ Data_Get_Struct(Vstate, JSON_Generator_State, state); \
142
+ buffer = cState_prepare_buffer(Vstate); \
143
+ generate_json_##type(buffer, Vstate, state, self); \
144
+ return fbuffer_to_s(buffer)
145
+
146
+ static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
147
+ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
148
+ static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
149
+ static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
150
+ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
151
+ static VALUE mString_included_s(VALUE self, VALUE modul);
152
+ static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
153
+ static VALUE mString_to_json_raw_object(VALUE self);
154
+ static VALUE mString_to_json_raw(int argc, VALUE *argv, VALUE self);
155
+ static VALUE mString_Extend_json_create(VALUE self, VALUE o);
156
+ static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
157
+ static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
158
+ static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
159
+ static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
160
+ static void State_free(JSON_Generator_State *state);
161
+ static JSON_Generator_State *State_allocate();
162
+ static VALUE cState_s_allocate(VALUE klass);
163
+ static VALUE cState_configure(VALUE self, VALUE opts);
164
+ static VALUE cState_to_h(VALUE self);
165
+ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
166
+ static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
167
+ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
168
+ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
169
+ static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
170
+ static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
171
+ static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
172
+ static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
173
+ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
174
+ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
175
+ static VALUE cState_partial_generate(VALUE self, VALUE obj);
176
+ static VALUE cState_generate(VALUE self, VALUE obj);
177
+ static VALUE cState_initialize(int argc, VALUE *argv, VALUE self);
178
+ static VALUE cState_from_state_s(VALUE self, VALUE opts);
179
+ static VALUE cState_indent(VALUE self);
180
+ static VALUE cState_indent_set(VALUE self, VALUE indent);
181
+ static VALUE cState_space(VALUE self);
182
+ static VALUE cState_space_set(VALUE self, VALUE space);
183
+ static VALUE cState_space_before(VALUE self);
184
+ static VALUE cState_space_before_set(VALUE self, VALUE space_before);
185
+ static VALUE cState_object_nl(VALUE self);
186
+ static VALUE cState_object_nl_set(VALUE self, VALUE object_nl);
187
+ static VALUE cState_array_nl(VALUE self);
188
+ static VALUE cState_array_nl_set(VALUE self, VALUE array_nl);
189
+ static VALUE cState_max_nesting(VALUE self);
190
+ static VALUE cState_max_nesting_set(VALUE self, VALUE depth);
191
+ static VALUE cState_allow_nan_p(VALUE self);
192
+ static VALUE cState_ascii_only_p(VALUE self);
193
+ static VALUE cState_depth(VALUE self);
194
+ static VALUE cState_depth_set(VALUE self, VALUE depth);
195
+ static FBuffer *cState_prepare_buffer(VALUE self);
196
+
197
+ #endif
@@ -1,11 +1,15 @@
1
1
  require 'mkmf'
2
2
  require 'rbconfig'
3
3
 
4
+ unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
5
+ $CFLAGS << ' -O3'
6
+ end
4
7
  if CONFIG['CC'] =~ /gcc/
5
- $CFLAGS += ' -Wall'
6
- #$CFLAGS += ' -O0 -ggdb'
8
+ $CFLAGS << ' -Wall'
9
+ #unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
10
+ # $CFLAGS << ' -O0 -ggdb'
11
+ #end
7
12
  end
8
13
 
9
- have_header("ruby/st.h") || have_header("st.h")
10
14
  have_header("re.h")
11
- create_makefile 'parser'
15
+ create_makefile 'json/ext/parser'