aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrik Nyblom <[email protected]>2010-04-30 11:52:38 +0200
committerBjörn Gustavsson <[email protected]>2010-05-17 15:51:50 +0200
commit8f21d4026e8f338245812d6edfd113c05282e321 (patch)
tree90c8151cdcba7ad8b9fda5a1d63ac64cd958aa2c
parent1dad48ee9f2e1aba6a0ec69d9cf688705d6f187c (diff)
downloadotp-8f21d4026e8f338245812d6edfd113c05282e321.tar.gz
otp-8f21d4026e8f338245812d6edfd113c05282e321.tar.bz2
otp-8f21d4026e8f338245812d6edfd113c05282e321.zip
Add referenced_byte_size/1
Add testcases for referenced_byte_size/1. Add failure tests for referenced_byte_size.
-rw-r--r--erts/emulator/beam/bif.tab2
-rw-r--r--erts/emulator/beam/erl_bif_binary.c23
-rw-r--r--lib/stdlib/test/binary_module_SUITE.erl36
3 files changed, 56 insertions, 5 deletions
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab
index bd908566ee..7978044fe5 100644
--- a/erts/emulator/beam/bif.tab
+++ b/erts/emulator/beam/bif.tab
@@ -778,7 +778,7 @@ bif binary:bin_to_list/3
bif binary:list_to_bin/1
bif binary:copy/1
bif binary:copy/2
-# bif binary:referenced_byte_size/1
+bif binary:referenced_byte_size/1
# bif binary:decode_unsigned/1
# bif binary:decode_unsigned/2
diff --git a/erts/emulator/beam/erl_bif_binary.c b/erts/emulator/beam/erl_bif_binary.c
index e2d3d00db2..b3ebc95cea 100644
--- a/erts/emulator/beam/erl_bif_binary.c
+++ b/erts/emulator/beam/erl_bif_binary.c
@@ -2418,6 +2418,29 @@ BIF_RETTYPE binary_copy_2(BIF_ALIST_2)
return do_binary_copy(BIF_P,BIF_ARG_1,BIF_ARG_2);
}
+BIF_RETTYPE binary_referenced_byte_size_1(BIF_ALIST_1)
+{
+ ErlSubBin *sb;
+ ProcBin *pb;
+ Eterm res;
+ Eterm bin = BIF_ARG_1;
+
+ if (is_not_binary(BIF_ARG_1)) {
+ BIF_ERROR(BIF_P,BADARG);
+ }
+ sb = (ErlSubBin *) binary_val(bin);
+ if (sb->thing_word == HEADER_SUB_BIN) {
+ bin = sb->orig;
+ }
+ pb = (ProcBin *) binary_val(bin);
+ if (pb->thing_word == HEADER_PROC_BIN) {
+ res = erts_make_integer((Uint) pb->val->orig_size, BIF_P); /* XXX:PaN Halfword? orig_size is a long */
+ } else { /* heap binary */
+ res = erts_make_integer((Uint) ((ErlHeapBin *) pb)->size, BIF_P);
+ }
+ BIF_RET(res);
+}
+
/*
* Hard debug functions (dump) for the search structures
*/
diff --git a/lib/stdlib/test/binary_module_SUITE.erl b/lib/stdlib/test/binary_module_SUITE.erl
index 1c386b049c..9126d25e48 100644
--- a/lib/stdlib/test/binary_module_SUITE.erl
+++ b/lib/stdlib/test/binary_module_SUITE.erl
@@ -1,9 +1,8 @@
-module(binary_module_SUITE).
-export([all/1, interesting/1,random_ref_comp/1,random_ref_sr_comp/1,
- random_ref_fla_comp/1,parts/1, bin_to_list/1, list_to_bin/1, copy/1]).
-
--export([random_copy/1]).
+ random_ref_fla_comp/1,parts/1, bin_to_list/1, list_to_bin/1,
+ copy/1, referenced/1]).
-define(STANDALONE,1).
@@ -28,7 +27,8 @@ run() ->
-endif.
all(suite) -> [interesting,random_ref_fla_comp,random_ref_sr_comp,
- random_ref_comp,parts,bin_to_list, list_to_bin, copy].
+ random_ref_comp,parts,bin_to_list, list_to_bin, copy,
+ referenced].
-define(MASK_ERROR(EXPR),mask_error((catch (EXPR)))).
@@ -292,6 +292,34 @@ do_interesting(Module) ->
?line [1,2,3] = ?MASK_ERROR(Module:bin_to_list(<<1,2,3>>,3,-3)),
ok.
+
+referenced(doc) ->
+ ["Test refernced_byte_size/1 bif."];
+referenced(Config) when is_list(Config) ->
+ ?line badarg = ?MASK_ERROR(binary:referenced_byte_size([])),
+ ?line badarg = ?MASK_ERROR(binary:referenced_byte_size(apa)),
+ ?line badarg = ?MASK_ERROR(binary:referenced_byte_size({})),
+ ?line badarg = ?MASK_ERROR(binary:referenced_byte_size(1)),
+ ?line A = <<1,2,3>>,
+ ?line B = binary:copy(A,1000),
+ ?line 3 = binary:referenced_byte_size(A),
+ ?line 3000 = binary:referenced_byte_size(B),
+ ?line <<_:8,C:2/binary>> = A,
+ ?line 3 = binary:referenced_byte_size(C),
+ ?line 2 = binary:referenced_byte_size(binary:copy(C)),
+ ?line <<_:7,D:2/binary,_:1>> = A,
+ ?line 2 = binary:referenced_byte_size(binary:copy(D)),
+ ?line 3 = binary:referenced_byte_size(D),
+ ?line <<_:8,E:2/binary,_/binary>> = B,
+ ?line 3000 = binary:referenced_byte_size(E),
+ ?line 2 = binary:referenced_byte_size(binary:copy(E)),
+ ?line <<_:7,F:2/binary,_:1,_/binary>> = B,
+ ?line 2 = binary:referenced_byte_size(binary:copy(F)),
+ ?line 3000 = binary:referenced_byte_size(F),
+ ok.
+
+
+
list_to_bin(doc) ->
["Test list_to_bin/1 bif"];
list_to_bin(Config) when is_list(Config) ->