Benoit Chesneau pirms 9 gadiem
vecāks
revīzija
85d644dad6
11 mainītis faili ar 173 papildinājumiem un 114 dzēšanām
  1. +21
    -6
      .gitignore
  2. +0
    -43
      Makefile
  3. +66
    -0
      c_src/Makefile
  4. +14
    -0
      c_src/decoder.c
  5. +10
    -0
      c_src/encoder.c
  6. Binārs
      rebar
  7. +13
    -33
      rebar.config
  8. +37
    -30
      rebar.config.script
  9. +1
    -0
      rebar.lock
  10. +5
    -1
      src/jiffy.app.src
  11. +6
    -1
      test/jiffy_10_short_double_tests.erl

+ 21
- 6
.gitignore Parādīt failu

@ -1,9 +1,24 @@
.jiffy.dev
*.app
*.beam
*.o
*.so
.eunit
deps
erln8.config
TEST-*.xml
.rebar3
_*
.eunit
*.o
*.so
*.beam
*.plt
*.swp
*.swo
.erlang.cookie
ebin
log
erl_crash.dump
.rebar
_rel
_deps
_plugins
_tdeps
logs
_build
c_src/env.mk

+ 0
- 43
Makefile Parādīt failu

@ -1,43 +0,0 @@
REBAR?=./rebar
all: build
clean:
$(REBAR) clean
rm -rf logs
rm -rf .eunit
rm -f test/*.beam
distclean: clean
git clean -fxd
devmarker:
@touch .jiffy.dev
depends: devmarker
@if test ! -d ./deps/proper; then \
$(REBAR) get-deps; \
fi
build: depends
$(REBAR) compile
eunit:
$(REBAR) eunit skip_deps=true
check: build eunit
%.beam: %.erl
erlc -o test/ $<
.PHONY: all clean distclean depends build etap eunit check

+ 66
- 0
c_src/Makefile Parādīt failu

@ -0,0 +1,66 @@
?ERL= erl
BASEDIR=$(CURDIR)
PRIVDIR=$(BASEDIR)/../priv
NIF_DIR=$(BASEDIR)
NIF_ENV=$(BASEDIR)/env.mk
NIF_SOURCES := $(shell find $(NIF_DIR) -type f \( -name "*.c" -o -name "*.cc" \))
NIF_OBJS=$(addsuffix .o, $(basename $(NIF_SOURCES)))
NIF_SO=$(PRIVDIR)/jiffy.so
UNAME_SYS := $(shell uname -s)
ifeq ($(UNAME_SYS), Darwin)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -arch x86_64 -I. -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -arch x86_64 -I. -Wall
LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
else ifeq ($(UNAME_SYS), FreeBSD)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -I. -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -I. -Wall
else ifeq ($(UNAME_SYS), Linux)
CC ?= g++
CFLAGS ?= -O3 -std=c99 -finline-functions -I. -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -I. -Wall
LDFLAGS ?= -lstdc++
endif
CFLAGS += -fPIC -I$(ERTS_INCLUDE_DIR) -I$(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -fPIC -I$(ERTS_INCLUDE_DIR) -I$(ERL_INTERFACE_INCLUDE_DIR)
LDLIBS += -L$(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei
LDFLAGS += -shared
all: $(NIF_ENV) $(NIF_SO)
clean:
@rm -rf $(NIF_SO) $(NIF_OBJS)
distclean: clean
@rm -rf $(NIF_ENV)
$(NIF_SO): $(NIF_OBJS)
@mkdir -p $(PRIVDIR)
$(CC) $(NIF_OBJS) $(LDFLAGS) $(LDLIBS) -o $(NIF_SO)
%.o: %.c
@$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o: %.cc
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
$(NIF_ENV):
@$(ERL) -eval "file:write_file(\"$(NIF_ENV)\", \
io_lib:format( \
\"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
\"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
\"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \
[code:root_dir(), erlang:system_info(version), \
code:lib_dir(erl_interface, include), \
code:lib_dir(erl_interface, lib)])), \
halt()."
-include $(NIF_ENV)

+ 14
- 0
c_src/decoder.c Parādīt failu

@ -65,6 +65,20 @@ typedef struct {
int st_top;
} Decoder;
Decoder* dec_new(ErlNifEnv* env);
void dec_init(Decoder* d, ErlNifEnv* env, ERL_NIF_TERM arg, ErlNifBinary* bin);
ERL_NIF_TERM dec_error(Decoder* d, const char* atom);
char dec_curr(Decoder* d);
int dec_top(Decoder* d);
void dec_push(Decoder* d, char val);
void dec_pop(Decoder* d, char val);
int dec_string(Decoder* d, ERL_NIF_TERM* value);
int dec_number(Decoder* d, ERL_NIF_TERM* value);
ERL_NIF_TERM make_empty_object(ErlNifEnv* env, int ret_map);
int make_object(ErlNifEnv* env, ERL_NIF_TERM pairs, ERL_NIF_TERM* out, int ret_map);
ERL_NIF_TERM make_array(ErlNifEnv* env, ERL_NIF_TERM list);
Decoder*
dec_new(ErlNifEnv* env)
{

+ 10
- 0
c_src/encoder.c Parādīt failu

@ -67,6 +67,16 @@ static char* shifts[NUM_SHIFTS] = {
};
Encoder* enc_new(ErlNifEnv* env);
int enc_init(Encoder* e, ErlNifEnv* env);
ERL_NIF_TERM enc_error(Encoder* e, const char* msg);
ERL_NIF_TERM enc_obj_error(Encoder* e, const char* msg, ERL_NIF_TERM obj);
int enc_result(Encoder* e, ERL_NIF_TERM* value);
int enc_done(Encoder* e, ERL_NIF_TERM* value);
#if MAP_TYPE_PRESENT
int enc_map_to_ejson(ErlNifEnv* env, ERL_NIF_TERM map, ERL_NIF_TERM* out);
#endif
Encoder*
enc_new(ErlNifEnv* env)
{

Binārs
rebar Parādīt failu


+ 13
- 33
rebar.config Parādīt failu

@ -1,33 +1,3 @@
{port_specs, [
{"priv/jiffy.so", [
"c_src/*.c",
"c_src/*.cc",
"c_src/double-conversion/*.cc"
]}
]}.
{port_env, [
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
"CFLAGS", "$CFLAGS -Ic_src/ -g -Wall -Werror -O3 -fno-strict-aliasing"},
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
"CXXFLAGS", "$CXXFLAGS -Ic_src/ -g -Wall -Werror -O3"},
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
"LDFLAGS", "$LDFLAGS -lstdc++"},
%% OS X Leopard flags for 64-bit
{"darwin9.*-64$", "CXXFLAGS", "-m64"},
{"darwin9.*-64$", "LDFLAGS", "-arch x86_64"},
%% OS X Snow Leopard flags for 32-bit
{"darwin10.*-32$", "CXXFLAGS", "-m32"},
{"darwin10.*-32$", "LDFLAGS", "-arch i386"},
%% This will merge into basho/rebar/rebar.config eventually
{"win32", "CFLAGS", "/Wall /DWIN32 /D_WINDOWS /D_WIN32 /DWINDOWS"},
{"win32", "CXXFLAGS", "-Ic_src/ -g -Wall -O3"}
]}.
{erl_opts, [
{platform_define, "R1(1|2|3|4|5|6)", 'JIFFY_NO_MAPS'}
]}.
@ -39,7 +9,17 @@
}}
]}.
{plugins, [
rebar_gdb_plugin
]}.
{eunit_tests, [{dir, "test"}]}.
{profiles, [{test,
[{deps, [
{proper,
{git, "git://github.com/manopapad/proper.git",
{branch, "master"}}}
]}]}]}.
{pre_hooks, [{"(linux|darwin|solaris)", compile, "make -C c_src"},
{"(freebsd|netbsd|openbsd)", compile, "gmake -C c_src"}]}.
{post_hooks, [{"(linux|darwin|solaris)", clean, "make -C c_src clean"},
{"(freebsd|netbsd|openbsd)", compile, "gmake -C c_src clean"}]}.

+ 37
- 30
rebar.config.script Parādīt failu

@ -1,37 +1,44 @@
% This file is part of Jiffy released under the MIT license.
% See the LICENSE file for more information.
IsRebar3 = case application:get_key(rebar, vsn) of
{ok, VSN} ->
[VSN1 | _] = string:tokens(VSN, "-"),
[Maj, Min, Patch] = string:tokens(VSN1, "."),
(list_to_integer(Maj) >= 3);
undefined ->
lists:keymember(mix, 1, application:loaded_applications())
end,
% Only include PropEr as a dependency when the JIFFY_DEV
% environment variable is defined. This allows downstream
% applications to avoid requiring PropEr.
%
% This script is based on the example provided with Rebar.
case IsRebar3 of
true ->
CONFIG;
false ->
io:format("la~n", []),
ErlOpts = [{d, 'JIFFY_DEV'}],
CONFIG1 = [{eunit_opts, [verbose]}, {plugins, [rebar_gdb_plugin]} | CONFIG],
Proper = [
{proper, ".*", {git, "git://github.com/manopapad/proper.git", "master"}}
],
ErlOpts = [{d, 'JIFFY_DEV'}],
Proper = [{proper, ".*", {git, "git://github.com/manopapad/proper.git", "master"}}],
ConfigPath = filename:dirname(SCRIPT),
DevMarker = filename:join([ConfigPath, ".jiffy.dev"]),
ConfigPath = filename:dirname(SCRIPT),
DevMarker = filename:join([ConfigPath, ".jiffy.dev"]),
case filelib:is_file(DevMarker) of
true ->
% Don't override existing dependencies
Config0 = case lists:keyfind(deps, 1, CONFIG) of
case filelib:is_file(DevMarker) of
true ->
% Don't override existing dependencies
CONFIG2 = case lists:keyfind(deps, 1, CONFIG1) of
false ->
CONFIG1 ++ [{deps, Proper}];
{deps, DepsList} ->
lists:keyreplace(deps, 1, CONFIG1, {deps, DepsList ++ Proper})
end,
case lists:keyfind(erl_opts, 1, CONFIG2) of
false ->
CONFIG2 ++ [{erl_opts, ErlOpts}];
{erl_opts, Opts} ->
NewOpts = {erl_opts, Opts ++ ErlOpts},
lists:keyreplace(erl_opts, 1, CONFIG2, NewOpts)
end;
false ->
CONFIG ++ [{deps, Proper}];
{deps, DepsList} ->
lists:keyreplace(deps, 1, CONFIG, {deps, DepsList ++ Proper})
end,
Config1 = case lists:keyfind(erl_opts, 1, Config0) of
false ->
Config0 ++ [{erl_opts, ErlOpts}];
{erl_opts, Opts} ->
NewOpts = {erl_opts, Opts ++ ErlOpts},
lists:keyreplace(erl_opts, 1, Config0, NewOpts)
end;
false ->
CONFIG
CONFIG1
end
end.

+ 1
- 0
rebar.lock Parādīt failu

@ -0,0 +1 @@
[].

+ 5
- 1
src/jiffy.app.src Parādīt failu

@ -2,5 +2,9 @@
{description, "JSON Decoder/Encoder."},
{vsn, git},
{registered, []},
{applications, [kernel, stdlib]}
{applications, [kernel, stdlib]},
{maintainers, ["Paul J. Davis"]},
{licenses, ["BSD"]},
{links, [{"Github", "https://github.com/davisp/jiffy"}]}
]}.

+ 6
- 1
test/jiffy_10_short_double_tests.erl Parādīt failu

@ -8,7 +8,12 @@
-include("jiffy_util.hrl").
filename() -> "../test/cases/short-doubles.txt".
filename() ->
FName = "test/cases/short-doubles.txt",
case filelib:is_file(FName) of
true -> FName;
false -> "../" ++ FName
end.
short_double_test_() ->

Notiek ielāde…
Atcelt
Saglabāt