libyajl2 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +65 -10
- data/ext/libyajl2/api/yajl_common.h +75 -0
- data/ext/libyajl2/api/yajl_gen.h +167 -0
- data/ext/libyajl2/api/yajl_parse.h +226 -0
- data/ext/libyajl2/api/yajl_tree.h +186 -0
- data/ext/libyajl2/api/yajl_version.h +23 -0
- data/ext/libyajl2/extconf.rb +24 -177
- data/ext/libyajl2/patches/000-mingw-gcc.patch +26 -0
- data/ext/libyajl2/yajl/yajl_common.h +75 -0
- data/ext/libyajl2/yajl/yajl_gen.h +167 -0
- data/ext/libyajl2/yajl/yajl_parse.h +226 -0
- data/ext/libyajl2/yajl/yajl_tree.h +186 -0
- data/ext/libyajl2/yajl/yajl_version.h +23 -0
- data/ext/libyajl2/yajl.c +175 -0
- data/ext/libyajl2/yajl_alloc.c +52 -0
- data/ext/libyajl2/yajl_alloc.h +34 -0
- data/ext/libyajl2/yajl_buf.c +103 -0
- data/ext/libyajl2/yajl_buf.h +57 -0
- data/ext/libyajl2/yajl_bytestack.h +69 -0
- data/ext/libyajl2/yajl_encode.c +220 -0
- data/ext/libyajl2/yajl_encode.h +34 -0
- data/ext/libyajl2/yajl_gen.c +362 -0
- data/ext/libyajl2/yajl_lex.c +763 -0
- data/ext/libyajl2/yajl_lex.h +117 -0
- data/ext/libyajl2/yajl_parser.c +498 -0
- data/ext/libyajl2/yajl_parser.h +78 -0
- data/ext/libyajl2/yajl_tree.c +503 -0
- data/ext/libyajl2/yajl_version.c +7 -0
- data/lib/libyajl2/version.rb +1 -1
- metadata +28 -3
- data/ext/libyajl2/Makefile +0 -9
@@ -0,0 +1,186 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2010-2011 Florian Forster <ff at octo.it>
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
*/
|
16
|
+
|
17
|
+
/**
|
18
|
+
* \file yajl_tree.h
|
19
|
+
*
|
20
|
+
* Parses JSON data and returns the data in tree form.
|
21
|
+
*
|
22
|
+
* \author Florian Forster
|
23
|
+
* \date August 2010
|
24
|
+
*
|
25
|
+
* This interface makes quick parsing and extraction of
|
26
|
+
* smallish JSON docs trivial:
|
27
|
+
*
|
28
|
+
* \include example/parse_config.c
|
29
|
+
*/
|
30
|
+
|
31
|
+
#ifndef YAJL_TREE_H
|
32
|
+
#define YAJL_TREE_H 1
|
33
|
+
|
34
|
+
#include <yajl/yajl_common.h>
|
35
|
+
|
36
|
+
#ifdef __cplusplus
|
37
|
+
extern "C" {
|
38
|
+
#endif
|
39
|
+
|
40
|
+
/** possible data types that a yajl_val_s can hold */
|
41
|
+
typedef enum {
|
42
|
+
yajl_t_string = 1,
|
43
|
+
yajl_t_number = 2,
|
44
|
+
yajl_t_object = 3,
|
45
|
+
yajl_t_array = 4,
|
46
|
+
yajl_t_true = 5,
|
47
|
+
yajl_t_false = 6,
|
48
|
+
yajl_t_null = 7,
|
49
|
+
/** The any type isn't valid for yajl_val_s.type, but can be
|
50
|
+
* used as an argument to routines like yajl_tree_get().
|
51
|
+
*/
|
52
|
+
yajl_t_any = 8
|
53
|
+
} yajl_type;
|
54
|
+
|
55
|
+
#define YAJL_NUMBER_INT_VALID 0x01
|
56
|
+
#define YAJL_NUMBER_DOUBLE_VALID 0x02
|
57
|
+
|
58
|
+
/** A pointer to a node in the parse tree */
|
59
|
+
typedef struct yajl_val_s * yajl_val;
|
60
|
+
|
61
|
+
/**
|
62
|
+
* A JSON value representation capable of holding one of the seven
|
63
|
+
* types above. For "string", "number", "object", and "array"
|
64
|
+
* additional data is available in the union. The "YAJL_IS_*"
|
65
|
+
* and "YAJL_GET_*" macros below allow type checking and convenient
|
66
|
+
* value extraction.
|
67
|
+
*/
|
68
|
+
struct yajl_val_s
|
69
|
+
{
|
70
|
+
/** Type of the value contained. Use the "YAJL_IS_*" macros to check for a
|
71
|
+
* specific type. */
|
72
|
+
yajl_type type;
|
73
|
+
/** Type-specific data. You may use the "YAJL_GET_*" macros to access these
|
74
|
+
* members. */
|
75
|
+
union
|
76
|
+
{
|
77
|
+
char * string;
|
78
|
+
struct {
|
79
|
+
long long i; /*< integer value, if representable. */
|
80
|
+
double d; /*< double value, if representable. */
|
81
|
+
char *r; /*< unparsed number in string form. */
|
82
|
+
/** Signals whether the \em i and \em d members are
|
83
|
+
* valid. See \c YAJL_NUMBER_INT_VALID and
|
84
|
+
* \c YAJL_NUMBER_DOUBLE_VALID. */
|
85
|
+
unsigned int flags;
|
86
|
+
} number;
|
87
|
+
struct {
|
88
|
+
const char **keys; /*< Array of keys */
|
89
|
+
yajl_val *values; /*< Array of values. */
|
90
|
+
size_t len; /*< Number of key-value-pairs. */
|
91
|
+
} object;
|
92
|
+
struct {
|
93
|
+
yajl_val *values; /*< Array of elements. */
|
94
|
+
size_t len; /*< Number of elements. */
|
95
|
+
} array;
|
96
|
+
} u;
|
97
|
+
};
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Parse a string.
|
101
|
+
*
|
102
|
+
* Parses an null-terminated string containing JSON data and returns a pointer
|
103
|
+
* to the top-level value (root of the parse tree).
|
104
|
+
*
|
105
|
+
* \param input Pointer to a null-terminated utf8 string containing
|
106
|
+
* JSON data.
|
107
|
+
* \param error_buffer Pointer to a buffer in which an error message will
|
108
|
+
* be stored if \em yajl_tree_parse fails, or
|
109
|
+
* \c NULL. The buffer will be initialized before
|
110
|
+
* parsing, so its content will be destroyed even if
|
111
|
+
* \em yajl_tree_parse succeeds.
|
112
|
+
* \param error_buffer_size Size of the memory area pointed to by
|
113
|
+
* \em error_buffer_size. If \em error_buffer_size is
|
114
|
+
* \c NULL, this argument is ignored.
|
115
|
+
*
|
116
|
+
* \returns Pointer to the top-level value or \c NULL on error. The memory
|
117
|
+
* pointed to must be freed using \em yajl_tree_free. In case of an error, a
|
118
|
+
* null terminated message describing the error in more detail is stored in
|
119
|
+
* \em error_buffer if it is not \c NULL.
|
120
|
+
*/
|
121
|
+
YAJL_API yajl_val yajl_tree_parse (const char *input,
|
122
|
+
char *error_buffer, size_t error_buffer_size);
|
123
|
+
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Free a parse tree returned by "yajl_tree_parse".
|
127
|
+
*
|
128
|
+
* \param v Pointer to a JSON value returned by "yajl_tree_parse". Passing NULL
|
129
|
+
* is valid and results in a no-op.
|
130
|
+
*/
|
131
|
+
YAJL_API void yajl_tree_free (yajl_val v);
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Access a nested value inside a tree.
|
135
|
+
*
|
136
|
+
* \param parent the node under which you'd like to extract values.
|
137
|
+
* \param path A null terminated array of strings, each the name of an object key
|
138
|
+
* \param type the yajl_type of the object you seek, or yajl_t_any if any will do.
|
139
|
+
*
|
140
|
+
* \returns a pointer to the found value, or NULL if we came up empty.
|
141
|
+
*
|
142
|
+
* Future Ideas: it'd be nice to move path to a string and implement support for
|
143
|
+
* a teeny tiny micro language here, so you can extract array elements, do things
|
144
|
+
* like .first and .last, even .length. Inspiration from JSONPath and css selectors?
|
145
|
+
* No it wouldn't be fast, but that's not what this API is about.
|
146
|
+
*/
|
147
|
+
YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type);
|
148
|
+
|
149
|
+
/* Various convenience macros to check the type of a `yajl_val` */
|
150
|
+
#define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string))
|
151
|
+
#define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number))
|
152
|
+
#define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_INT_VALID))
|
153
|
+
#define YAJL_IS_DOUBLE(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_DOUBLE_VALID))
|
154
|
+
#define YAJL_IS_OBJECT(v) (((v) != NULL) && ((v)->type == yajl_t_object))
|
155
|
+
#define YAJL_IS_ARRAY(v) (((v) != NULL) && ((v)->type == yajl_t_array ))
|
156
|
+
#define YAJL_IS_TRUE(v) (((v) != NULL) && ((v)->type == yajl_t_true ))
|
157
|
+
#define YAJL_IS_FALSE(v) (((v) != NULL) && ((v)->type == yajl_t_false ))
|
158
|
+
#define YAJL_IS_NULL(v) (((v) != NULL) && ((v)->type == yajl_t_null ))
|
159
|
+
|
160
|
+
/** Given a yajl_val_string return a ptr to the bare string it contains,
|
161
|
+
* or NULL if the value is not a string. */
|
162
|
+
#define YAJL_GET_STRING(v) (YAJL_IS_STRING(v) ? (v)->u.string : NULL)
|
163
|
+
|
164
|
+
/** Get the string representation of a number. You should check type first,
|
165
|
+
* perhaps using YAJL_IS_NUMBER */
|
166
|
+
#define YAJL_GET_NUMBER(v) ((v)->u.number.r)
|
167
|
+
|
168
|
+
/** Get the double representation of a number. You should check type first,
|
169
|
+
* perhaps using YAJL_IS_DOUBLE */
|
170
|
+
#define YAJL_GET_DOUBLE(v) ((v)->u.number.d)
|
171
|
+
|
172
|
+
/** Get the 64bit (long long) integer representation of a number. You should
|
173
|
+
* check type first, perhaps using YAJL_IS_INTEGER */
|
174
|
+
#define YAJL_GET_INTEGER(v) ((v)->u.number.i)
|
175
|
+
|
176
|
+
/** Get a pointer to a yajl_val_object or NULL if the value is not an object. */
|
177
|
+
#define YAJL_GET_OBJECT(v) (YAJL_IS_OBJECT(v) ? &(v)->u.object : NULL)
|
178
|
+
|
179
|
+
/** Get a pointer to a yajl_val_array or NULL if the value is not an object. */
|
180
|
+
#define YAJL_GET_ARRAY(v) (YAJL_IS_ARRAY(v) ? &(v)->u.array : NULL)
|
181
|
+
|
182
|
+
#ifdef __cplusplus
|
183
|
+
}
|
184
|
+
#endif
|
185
|
+
|
186
|
+
#endif /* YAJL_TREE_H */
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#ifndef YAJL_VERSION_H_
|
2
|
+
#define YAJL_VERSION_H_
|
3
|
+
|
4
|
+
#include <yajl/yajl_common.h>
|
5
|
+
|
6
|
+
#define YAJL_MAJOR 2
|
7
|
+
#define YAJL_MINOR 1
|
8
|
+
#define YAJL_MICRO 1
|
9
|
+
|
10
|
+
#define YAJL_VERSION ((YAJL_MAJOR * 10000) + (YAJL_MINOR * 100) + YAJL_MICRO)
|
11
|
+
|
12
|
+
#ifdef __cplusplus
|
13
|
+
extern "C" {
|
14
|
+
#endif
|
15
|
+
|
16
|
+
extern int YAJL_API yajl_version(void);
|
17
|
+
|
18
|
+
#ifdef __cplusplus
|
19
|
+
}
|
20
|
+
#endif
|
21
|
+
|
22
|
+
#endif /* YAJL_VERSION_H_ */
|
23
|
+
|
data/ext/libyajl2/extconf.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
exit(0) if ENV["USE_SYSTEM_LIBYAJL2"]
|
2
2
|
|
3
3
|
require 'rbconfig'
|
4
|
-
require '
|
4
|
+
require 'fileutils'
|
5
|
+
require 'mkmf'
|
5
6
|
|
6
7
|
module Libyajl2Build
|
7
8
|
class BuildError < StandardError; end
|
@@ -23,201 +24,47 @@ module Libyajl2Build
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.setup_env
|
26
|
-
|
27
|
-
config['CFLAGS'] << " -std=c99 -pedantic -Wpointer-arith -Wno-format-y2k -Wstrict-prototypes -Wmissing-declarations -Wnested-externs -Wextra -Wundef -Wwrite-strings -Wold-style-definition -Wredundant-decls -Wno-unused-parameter -Wno-sign-compare -Wmissing-prototypes"
|
28
|
-
end
|
29
|
-
end
|
27
|
+
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
# set some sane defaults
|
30
|
+
if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/
|
31
|
+
# magic flags copied from upstream yajl build system (-std=c99 is necessary for older gcc)
|
32
|
+
$CFLAGS << " -std=c99 -pedantic -Wpointer-arith -Wno-format-y2k -Wstrict-prototypes -Wmissing-declarations -Wnested-externs -Wextra -Wundef -Wwrite-strings -Wold-style-definition -Wredundant-decls -Wno-unused-parameter -Wno-sign-compare -Wmissing-prototypes"
|
33
|
+
$CFLAGS << " -O2" # match what the upstream uses for optimization
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
path = path.dup
|
40
|
-
path.tr!('\\', '/')
|
41
|
-
path.sub!(/\A([A-Za-z]):(?=\/)/, '/\1')
|
42
|
-
path
|
43
|
-
when 'cygwin'
|
44
|
-
if config['target_os'] != 'cygwin'
|
45
|
-
IO.popen(["cygpath", "-u", path], &:read).chomp
|
46
|
-
else
|
47
|
-
path
|
35
|
+
# create the implib on windows
|
36
|
+
if windows?
|
37
|
+
$LDFLAGS << " -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--out-implib=libyajl.dll.a"
|
48
38
|
end
|
49
|
-
else
|
50
|
-
path
|
51
39
|
end
|
52
|
-
end
|
53
40
|
|
54
|
-
|
55
|
-
print("-> #{args.join(' ')}\n")
|
56
|
-
super(*args)
|
57
|
-
end
|
58
|
-
|
59
|
-
# since we're not using cmake we have to mangle up yajl_version.h ourselves
|
60
|
-
def self.generate_yajl_version
|
61
|
-
yajl_major = yajl_minor = yajl_micro = nil
|
62
|
-
File.open("#{libyajl2_vendor_dir}/CMakeLists.txt").each do |line|
|
63
|
-
if m = line.match(/YAJL_MAJOR (\d+)/)
|
64
|
-
yajl_major = m[1]
|
65
|
-
end
|
66
|
-
if m = line.match(/YAJL_MINOR (\d+)/)
|
67
|
-
yajl_minor = m[1]
|
68
|
-
end
|
69
|
-
if m = line.match(/YAJL_MICRO (\d+)/)
|
70
|
-
yajl_micro = m[1]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
File.open("#{libyajl2_vendor_dir}/src/api/yajl_version.h", "w+") do |out|
|
74
|
-
File.open("#{libyajl2_vendor_dir}/src/api/yajl_version.h.cmake").each do |line|
|
75
|
-
line.gsub!(/\$\{YAJL_MAJOR\}/, yajl_major)
|
76
|
-
line.gsub!(/\$\{YAJL_MINOR\}/, yajl_minor)
|
77
|
-
line.gsub!(/\$\{YAJL_MICRO\}/, yajl_micro)
|
78
|
-
out.write(line)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
41
|
+
$CFLAGS << " -DNDEBUG"
|
82
42
|
|
83
|
-
def self.yajl_makefile
|
84
|
-
File.open("Makefile", "w+") do |f|
|
85
|
-
f.write <<EOF
|
86
|
-
SHELL = /bin/sh
|
87
|
-
|
88
|
-
# V=0 quiet, V=1 verbose. other values don't work.
|
89
|
-
V = 0
|
90
|
-
Q1 = $(V:1=)
|
91
|
-
Q = $(Q1:0=@)
|
92
|
-
ECHO1 = $(V:1=@:)
|
93
|
-
ECHO = $(ECHO1:0=@echo)
|
94
|
-
|
95
|
-
#### Start of system configuration section. ####
|
96
|
-
|
97
|
-
srcdir = .
|
98
|
-
prefix = #{mkintpath(config['prefix'])}
|
99
|
-
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
100
|
-
exec_prefix = $(prefix)
|
101
|
-
sitearchdir = $(sitelibdir)/$(sitearch)
|
102
|
-
sitelibdir = $(sitedir)/$(ruby_version)
|
103
|
-
sitedir = $(rubylibprefix)/site_ruby
|
104
|
-
libdir = $(exec_prefix)/lib
|
105
|
-
|
106
|
-
CC = #{config['CC']}
|
107
|
-
COUTFLAG = '-o'
|
108
|
-
|
109
|
-
cflags = #{config['cflags']}
|
110
|
-
optflags = #{config['optflags']}
|
111
|
-
debugflags = #{config['debugflags']}
|
112
|
-
warnflags = #{config['warnflags']}
|
113
|
-
CCDLFLAGS = #{config['CCDLFLAGS']}
|
114
|
-
CFLAGS = $(CCDLFLAGS) -I#{libyajl2_vendor_dir}/src/api -I. #{config['CFLAGS']} $(ARCH_FLAG)
|
115
|
-
INCFLAGS = -I. -I$(srcdir)
|
116
|
-
DEFS = #{config['DEFS']}
|
117
|
-
CPPFLAGS = #{config['CPPFLAGS']} $(cppflags)
|
118
|
-
ldflags = #{config['LDFLAGS']}
|
119
|
-
#dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
|
120
|
-
dldflags = #{config['DLDFLAGS']} #{config['EXTDLDFLAGS']}
|
121
|
-
ARCH_FLAG = #{config['ARCH_FLAG']}
|
122
|
-
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
123
|
-
LDSHARED = #{config['LDSHARED']}
|
124
|
-
|
125
|
-
RUBY_INSTALL_NAME = #{config['RUBY_INSTALL_NAME']}
|
126
|
-
RUBY_SO_NAME = #{config['RUBY_SO_NAME']}
|
127
|
-
RUBYW_INSTALL_NAME = #{config['RUBYW_INSTALL_NAME']}
|
128
|
-
RUBY_VERSION_NAME = #{config['RUBY_VERSION_NAME']}
|
129
|
-
RUBYW_BASE_NAME = #{config['RUBYW_BASE_NAME']}
|
130
|
-
RUBY_BASE_NAME = #{config['RUBY_BASE_NAME']}
|
131
|
-
|
132
|
-
arch = #{config['arch']}
|
133
|
-
sitearch = #{config['sitearch']}
|
134
|
-
ruby_version = #{RbConfig::CONFIG['ruby_version']}
|
135
|
-
ruby = #{File.join(RbConfig::CONFIG["bindir"], config["ruby_install_name"])}
|
136
|
-
RUBY = $(ruby)
|
137
|
-
|
138
|
-
RM = $(RUBY) -run -e rm -- -f
|
139
|
-
MAKEDIRS = $(RUBY) -run -e mkdir -- -p
|
140
|
-
INSTALL = $(RUBY) -run -e install -- -vp
|
141
|
-
INSTALL_PROG = $(INSTALL) -m 0755
|
142
|
-
TOUCH = exit >
|
143
|
-
|
144
|
-
#### End of system configuration section. ####
|
145
|
-
|
146
|
-
libpath = . $(libdir)
|
147
|
-
LIBPATH = -L. -L$(libdir)
|
148
|
-
|
149
|
-
CLEANFILES = mkmf.log
|
150
|
-
|
151
|
-
target_prefix =
|
152
|
-
LIBS = #{config['LIBS']} #{config['DLDLIBS']}
|
153
|
-
ORIG_SRCS = yajl.c yajl_alloc.c yajl_buf.c yajl_encode.c yajl_gen.c yajl_lex.c yajl_parser.c yajl_tree.c yajl_version.c
|
154
|
-
SRCS = $(ORIG_SRCS)
|
155
|
-
OBJS = yajl.o yajl_alloc.o yajl_buf.o yajl_encode.o yajl_gen.o yajl_lex.o yajl_parser.o yajl_tree.o yajl_version.o
|
156
|
-
HDRS = yajl_alloc.h yajl_buf.h yajl_bytestack.h yajl_encode.h yajl_lex.h yajl_parser.h
|
157
|
-
TARGET = libyajl
|
158
|
-
DLLIB = $(TARGET).#{config['DLEXT']}
|
159
43
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
CLEANLIBS = $(TARGET).bundle
|
164
|
-
CLEANOBJS = *.o *.bak
|
165
|
-
|
166
|
-
all: $(DLLIB)
|
167
|
-
|
168
|
-
clean:
|
169
|
-
\t-$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
|
170
|
-
|
171
|
-
install: install-so install-rb
|
172
|
-
|
173
|
-
install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.time
|
174
|
-
\t$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
175
|
-
|
176
|
-
install-rb:
|
177
|
-
\t$(ECHO) installing default libyajl libraries
|
178
|
-
$(TIMESTAMP_DIR)/.RUBYARCHDIR.time:
|
179
|
-
\t$(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
|
180
|
-
\t$(Q) $(TOUCH) $@
|
181
|
-
|
182
|
-
.SUFFIXES: .c .o
|
183
|
-
|
184
|
-
.c.o:
|
185
|
-
\t$(ECHO) compiling $(<)
|
186
|
-
\t$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
187
|
-
|
188
|
-
$(DLLIB): $(OBJS) Makefile
|
189
|
-
\t$(ECHO) linking shared-object $(DLLIB)
|
190
|
-
\t-$(Q)$(RM) $(@)
|
191
|
-
\t$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LIBS)
|
192
|
-
|
193
|
-
$(OBJS): $(HDRS)
|
194
|
-
EOF
|
195
|
-
end
|
44
|
+
# ENV vars can override everything
|
45
|
+
$CFLAGS = ENV['CFLAGS'] if ENV['CFLAGS']
|
46
|
+
$LDFLAGS = ENV['LDFLAGS'] if ENV['LDFLAGS']
|
196
47
|
end
|
197
48
|
|
198
49
|
def self.makemakefiles
|
199
50
|
setup_env
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
end
|
51
|
+
dir_config("libyajl")
|
52
|
+
create_makefile("libyajl")
|
53
|
+
# we cheat and build it right away...
|
54
|
+
system("make V=1")
|
55
|
+
# ...so we can hack up what install does later and copy over the include files
|
56
|
+
|
207
57
|
File.open("Makefile", "w+") do |f|
|
208
58
|
f.write <<EOF
|
209
59
|
TARGET = libyajl
|
210
|
-
DLLIB = $(TARGET).#{
|
60
|
+
DLLIB = $(TARGET).#{RbConfig::MAKEFILE_CONFIG['DLEXT']}
|
211
61
|
all:
|
212
|
-
|
213
|
-
\tcp #{libyajl2_vendor_dir}/src/$(DLLIB) .
|
62
|
+
|
214
63
|
install:
|
215
64
|
\tmkdir -p #{prefix}/lib
|
216
65
|
\tcp $(DLLIB) #{prefix}/lib
|
217
66
|
\tmkdir -p #{prefix}/include/yajl
|
218
|
-
\tcp
|
219
|
-
clean:
|
220
|
-
\tcd #{libyajl2_vendor_dir}/src && make clean
|
67
|
+
\tcp yajl/*.h #{prefix}/include/yajl
|
221
68
|
EOF
|
222
69
|
end
|
223
70
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
diff --git a/src/yajl_gen.c b/src/yajl_gen.c
|
2
|
+
index 0f5c68e..a86a6ed 100644
|
3
|
+
--- a/src/yajl_gen.c
|
4
|
+
+++ b/src/yajl_gen.c
|
5
|
+
@@ -217,7 +217,7 @@ yajl_gen_integer(yajl_gen g, long long int number)
|
6
|
+
return yajl_gen_status_ok;
|
7
|
+
}
|
8
|
+
|
9
|
+
-#if defined(_WIN32) || defined(WIN32)
|
10
|
+
+#if ( defined(_WIN32) || defined(WIN32) ) && !defined(__GCC__)
|
11
|
+
#include <float.h>
|
12
|
+
#define isnan _isnan
|
13
|
+
#define isinf !_finite
|
14
|
+
diff --git a/src/yajl_tree.c b/src/yajl_tree.c
|
15
|
+
index 3d357a3..2b4c183 100644
|
16
|
+
--- a/src/yajl_tree.c
|
17
|
+
+++ b/src/yajl_tree.c
|
18
|
+
@@ -25,7 +25,7 @@
|
19
|
+
|
20
|
+
#include "yajl_parser.h"
|
21
|
+
|
22
|
+
-#if defined(_WIN32) || defined(WIN32)
|
23
|
+
+#if ( defined(_WIN32) || defined(WIN32) ) && !defined(__GCC__)
|
24
|
+
#define snprintf sprintf_s
|
25
|
+
#endif
|
26
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef __YAJL_COMMON_H__
|
18
|
+
#define __YAJL_COMMON_H__
|
19
|
+
|
20
|
+
#include <stddef.h>
|
21
|
+
|
22
|
+
#ifdef __cplusplus
|
23
|
+
extern "C" {
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#define YAJL_MAX_DEPTH 128
|
27
|
+
|
28
|
+
/* msft dll export gunk. To build a DLL on windows, you
|
29
|
+
* must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
|
30
|
+
* DLL, you must define YAJL_SHARED and WIN32 */
|
31
|
+
#if (defined(_WIN32) || defined(WIN32)) && defined(YAJL_SHARED)
|
32
|
+
# ifdef YAJL_BUILD
|
33
|
+
# define YAJL_API __declspec(dllexport)
|
34
|
+
# else
|
35
|
+
# define YAJL_API __declspec(dllimport)
|
36
|
+
# endif
|
37
|
+
#else
|
38
|
+
# if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
|
39
|
+
# define YAJL_API __attribute__ ((visibility("default")))
|
40
|
+
# else
|
41
|
+
# define YAJL_API
|
42
|
+
# endif
|
43
|
+
#endif
|
44
|
+
|
45
|
+
/** pointer to a malloc function, supporting client overriding memory
|
46
|
+
* allocation routines */
|
47
|
+
typedef void * (*yajl_malloc_func)(void *ctx, size_t sz);
|
48
|
+
|
49
|
+
/** pointer to a free function, supporting client overriding memory
|
50
|
+
* allocation routines */
|
51
|
+
typedef void (*yajl_free_func)(void *ctx, void * ptr);
|
52
|
+
|
53
|
+
/** pointer to a realloc function which can resize an allocation. */
|
54
|
+
typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz);
|
55
|
+
|
56
|
+
/** A structure which can be passed to yajl_*_alloc routines to allow the
|
57
|
+
* client to specify memory allocation functions to be used. */
|
58
|
+
typedef struct
|
59
|
+
{
|
60
|
+
/** pointer to a function that can allocate uninitialized memory */
|
61
|
+
yajl_malloc_func malloc;
|
62
|
+
/** pointer to a function that can resize memory allocations */
|
63
|
+
yajl_realloc_func realloc;
|
64
|
+
/** pointer to a function that can free memory allocated using
|
65
|
+
* reallocFunction or mallocFunction */
|
66
|
+
yajl_free_func free;
|
67
|
+
/** a context pointer that will be passed to above allocation routines */
|
68
|
+
void * ctx;
|
69
|
+
} yajl_alloc_funcs;
|
70
|
+
|
71
|
+
#ifdef __cplusplus
|
72
|
+
}
|
73
|
+
#endif
|
74
|
+
|
75
|
+
#endif
|