diff options
211 files changed, 8247 insertions, 2960 deletions
diff --git a/bootstrap/bin/start.script b/bootstrap/bin/start.script index 61a0942632..98760d1e27 100644 --- a/bootstrap/bin/start.script +++ b/bootstrap/bin/start.script @@ -1,4 +1,4 @@ -%% script generated at {2009,12,14} {14,9,55} +%% script generated at {2010,2,10} {11,22,34} {script, {"OTP APN 181 01","R13B04"}, [{preLoaded, diff --git a/bootstrap/bin/start_clean.script b/bootstrap/bin/start_clean.script index 61a0942632..98760d1e27 100644 --- a/bootstrap/bin/start_clean.script +++ b/bootstrap/bin/start_clean.script @@ -1,4 +1,4 @@ -%% script generated at {2009,12,14} {14,9,55} +%% script generated at {2010,2,10} {11,22,34} {script, {"OTP APN 181 01","R13B04"}, [{preLoaded, diff --git a/bootstrap/lib/compiler/ebin/beam_asm.beam b/bootstrap/lib/compiler/ebin/beam_asm.beam Binary files differindex 1c2783cc14..6908d2c296 100644 --- a/bootstrap/lib/compiler/ebin/beam_asm.beam +++ b/bootstrap/lib/compiler/ebin/beam_asm.beam diff --git a/bootstrap/lib/compiler/ebin/beam_validator.beam b/bootstrap/lib/compiler/ebin/beam_validator.beam Binary files differindex 832e473761..2edf5f226e 100644 --- a/bootstrap/lib/compiler/ebin/beam_validator.beam +++ b/bootstrap/lib/compiler/ebin/beam_validator.beam diff --git a/bootstrap/lib/compiler/ebin/compile.beam b/bootstrap/lib/compiler/ebin/compile.beam Binary files differindex 1e711b2461..864d76b526 100644 --- a/bootstrap/lib/compiler/ebin/compile.beam +++ b/bootstrap/lib/compiler/ebin/compile.beam diff --git a/bootstrap/lib/compiler/ebin/compiler.app b/bootstrap/lib/compiler/ebin/compiler.app index d5e7956176..497d1873d8 100644 --- a/bootstrap/lib/compiler/ebin/compiler.app +++ b/bootstrap/lib/compiler/ebin/compiler.app @@ -1,24 +1,24 @@ % This is an -*- erlang -*- file. %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% {application, compiler, [{description, "ERTS CXC 138 10"}, - {vsn, "4.6.4"}, + {vsn, "4.6.5"}, {modules, [ beam_asm, beam_block, diff --git a/bootstrap/lib/compiler/ebin/compiler.appup b/bootstrap/lib/compiler/ebin/compiler.appup index 224c761cc2..99b234c847 100644 --- a/bootstrap/lib/compiler/ebin/compiler.appup +++ b/bootstrap/lib/compiler/ebin/compiler.appup @@ -1 +1 @@ -{"4.6.4",[],[]}. +{"4.6.5",[],[]}. diff --git a/bootstrap/lib/compiler/ebin/sys_pre_expand.beam b/bootstrap/lib/compiler/ebin/sys_pre_expand.beam Binary files differindex a5a0a3d6ac..a2766d3048 100644 --- a/bootstrap/lib/compiler/ebin/sys_pre_expand.beam +++ b/bootstrap/lib/compiler/ebin/sys_pre_expand.beam diff --git a/bootstrap/lib/compiler/ebin/v3_core.beam b/bootstrap/lib/compiler/ebin/v3_core.beam Binary files differindex 111753213e..2b5efad43f 100644 --- a/bootstrap/lib/compiler/ebin/v3_core.beam +++ b/bootstrap/lib/compiler/ebin/v3_core.beam diff --git a/bootstrap/lib/compiler/egen/core_parse.erl b/bootstrap/lib/compiler/egen/core_parse.erl index f20cda3d04..e93877a690 100644 --- a/bootstrap/lib/compiler/egen/core_parse.erl +++ b/bootstrap/lib/compiler/egen/core_parse.erl @@ -16,20 +16,20 @@ tok_line(T) -> element(2, T). -file("/usr/local/otp/releases/sles10_32_R13B03_patched/lib/parsetools-2.0.1/include/yeccpre.hrl", 0). %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% diff --git a/bootstrap/lib/kernel/ebin/code.beam b/bootstrap/lib/kernel/ebin/code.beam Binary files differindex 105de39d21..1392a018ab 100644 --- a/bootstrap/lib/kernel/ebin/code.beam +++ b/bootstrap/lib/kernel/ebin/code.beam diff --git a/bootstrap/lib/kernel/ebin/code_server.beam b/bootstrap/lib/kernel/ebin/code_server.beam Binary files differindex 9515ff81c1..e6ad873c82 100644 --- a/bootstrap/lib/kernel/ebin/code_server.beam +++ b/bootstrap/lib/kernel/ebin/code_server.beam diff --git a/bootstrap/lib/kernel/ebin/gen_sctp.beam b/bootstrap/lib/kernel/ebin/gen_sctp.beam Binary files differindex 18ecaff05f..f66b4635a2 100644 --- a/bootstrap/lib/kernel/ebin/gen_sctp.beam +++ b/bootstrap/lib/kernel/ebin/gen_sctp.beam diff --git a/bootstrap/lib/kernel/ebin/hipe_unified_loader.beam b/bootstrap/lib/kernel/ebin/hipe_unified_loader.beam Binary files differindex 21d21208f3..ffa0160f81 100644 --- a/bootstrap/lib/kernel/ebin/hipe_unified_loader.beam +++ b/bootstrap/lib/kernel/ebin/hipe_unified_loader.beam diff --git a/bootstrap/lib/kernel/ebin/inet.beam b/bootstrap/lib/kernel/ebin/inet.beam Binary files differindex d12f0a57a9..a8983e79c1 100644 --- a/bootstrap/lib/kernel/ebin/inet.beam +++ b/bootstrap/lib/kernel/ebin/inet.beam diff --git a/bootstrap/lib/kernel/ebin/inet_config.beam b/bootstrap/lib/kernel/ebin/inet_config.beam Binary files differindex 5b93d653f7..ad3f46010e 100644 --- a/bootstrap/lib/kernel/ebin/inet_config.beam +++ b/bootstrap/lib/kernel/ebin/inet_config.beam diff --git a/bootstrap/lib/kernel/ebin/inet_db.beam b/bootstrap/lib/kernel/ebin/inet_db.beam Binary files differindex 14e0e57729..ee4a8633d6 100644 --- a/bootstrap/lib/kernel/ebin/inet_db.beam +++ b/bootstrap/lib/kernel/ebin/inet_db.beam diff --git a/bootstrap/lib/kernel/ebin/inet_gethost_native.beam b/bootstrap/lib/kernel/ebin/inet_gethost_native.beam Binary files differindex aaaecc8577..1f9241a378 100644 --- a/bootstrap/lib/kernel/ebin/inet_gethost_native.beam +++ b/bootstrap/lib/kernel/ebin/inet_gethost_native.beam diff --git a/bootstrap/lib/kernel/ebin/inet_parse.beam b/bootstrap/lib/kernel/ebin/inet_parse.beam Binary files differindex 3315aab31f..926f21e99c 100644 --- a/bootstrap/lib/kernel/ebin/inet_parse.beam +++ b/bootstrap/lib/kernel/ebin/inet_parse.beam diff --git a/bootstrap/lib/kernel/ebin/inet_sctp.beam b/bootstrap/lib/kernel/ebin/inet_sctp.beam Binary files differindex 0372452973..a4d234911d 100644 --- a/bootstrap/lib/kernel/ebin/inet_sctp.beam +++ b/bootstrap/lib/kernel/ebin/inet_sctp.beam diff --git a/bootstrap/lib/kernel/ebin/kernel.app b/bootstrap/lib/kernel/ebin/kernel.app index c6abc267b1..83a01d75cb 100644 --- a/bootstrap/lib/kernel/ebin/kernel.app +++ b/bootstrap/lib/kernel/ebin/kernel.app @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% This is an -*- erlang -*- file. diff --git a/bootstrap/lib/kernel/ebin/pg2.beam b/bootstrap/lib/kernel/ebin/pg2.beam Binary files differindex efb224f375..38870b0f43 100644 --- a/bootstrap/lib/kernel/ebin/pg2.beam +++ b/bootstrap/lib/kernel/ebin/pg2.beam diff --git a/bootstrap/lib/kernel/include/file.hrl b/bootstrap/lib/kernel/include/file.hrl index b8ad6c8464..2273b0c5a6 100644 --- a/bootstrap/lib/kernel/include/file.hrl +++ b/bootstrap/lib/kernel/include/file.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% diff --git a/bootstrap/lib/kernel/include/inet.hrl b/bootstrap/lib/kernel/include/inet.hrl index a62c8b0878..94dd269f7e 100644 --- a/bootstrap/lib/kernel/include/inet.hrl +++ b/bootstrap/lib/kernel/include/inet.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% This record is returned by inet:gethostbyaddr/2 and inet:gethostbyname/2. diff --git a/bootstrap/lib/kernel/include/inet_sctp.hrl b/bootstrap/lib/kernel/include/inet_sctp.hrl index 34c46fee1e..83f95e05af 100644 --- a/bootstrap/lib/kernel/include/inet_sctp.hrl +++ b/bootstrap/lib/kernel/include/inet_sctp.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% SCTP protocol contribution by Leonid Timochouk and Serge Aleynikov. diff --git a/bootstrap/lib/orber/include/Makefile b/bootstrap/lib/orber/include/Makefile index cc02fbf5b3..08745e5727 100644 --- a/bootstrap/lib/orber/include/Makefile +++ b/bootstrap/lib/orber/include/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 2008-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 2008-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # # diff --git a/bootstrap/lib/orber/include/corba.hrl b/bootstrap/lib/orber/include/corba.hrl index 99fe498d2e..c5d2d50ea0 100644 --- a/bootstrap/lib/orber/include/corba.hrl +++ b/bootstrap/lib/orber/include/corba.hrl @@ -1,20 +1,20 @@ %%-------------------------------------------------------------------- %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% diff --git a/bootstrap/lib/orber/include/ifr_types.hrl b/bootstrap/lib/orber/include/ifr_types.hrl index 7e67da9781..035142d802 100644 --- a/bootstrap/lib/orber/include/ifr_types.hrl +++ b/bootstrap/lib/orber/include/ifr_types.hrl @@ -1,20 +1,20 @@ %%-------------------------------------------------------------------- %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% diff --git a/bootstrap/lib/orber/include/orber_pi.hrl b/bootstrap/lib/orber/include/orber_pi.hrl index d2fb33197e..2b846bc814 100644 --- a/bootstrap/lib/orber/include/orber_pi.hrl +++ b/bootstrap/lib/orber/include/orber_pi.hrl @@ -1,20 +1,20 @@ %%---------------------------------------------------------------------- %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% diff --git a/bootstrap/lib/stdlib/ebin/edlin.beam b/bootstrap/lib/stdlib/ebin/edlin.beam Binary files differindex 7a2b065674..fe51f7f417 100644 --- a/bootstrap/lib/stdlib/ebin/edlin.beam +++ b/bootstrap/lib/stdlib/ebin/edlin.beam diff --git a/bootstrap/lib/stdlib/ebin/edlin_expand.beam b/bootstrap/lib/stdlib/ebin/edlin_expand.beam Binary files differindex 1719b3bb45..0ca05e1bc3 100644 --- a/bootstrap/lib/stdlib/ebin/edlin_expand.beam +++ b/bootstrap/lib/stdlib/ebin/edlin_expand.beam diff --git a/bootstrap/lib/stdlib/ebin/epp.beam b/bootstrap/lib/stdlib/ebin/epp.beam Binary files differindex 4d072403ec..66a84e41df 100644 --- a/bootstrap/lib/stdlib/ebin/epp.beam +++ b/bootstrap/lib/stdlib/ebin/epp.beam diff --git a/bootstrap/lib/stdlib/ebin/erl_lint.beam b/bootstrap/lib/stdlib/ebin/erl_lint.beam Binary files differindex 08da4563a7..79ed469508 100644 --- a/bootstrap/lib/stdlib/ebin/erl_lint.beam +++ b/bootstrap/lib/stdlib/ebin/erl_lint.beam diff --git a/bootstrap/lib/stdlib/ebin/escript.beam b/bootstrap/lib/stdlib/ebin/escript.beam Binary files differindex 20e6a25f1d..a606d817b7 100644 --- a/bootstrap/lib/stdlib/ebin/escript.beam +++ b/bootstrap/lib/stdlib/ebin/escript.beam diff --git a/bootstrap/lib/stdlib/ebin/filelib.beam b/bootstrap/lib/stdlib/ebin/filelib.beam Binary files differindex f3065882ae..e03b753c09 100644 --- a/bootstrap/lib/stdlib/ebin/filelib.beam +++ b/bootstrap/lib/stdlib/ebin/filelib.beam diff --git a/bootstrap/lib/stdlib/ebin/otp_internal.beam b/bootstrap/lib/stdlib/ebin/otp_internal.beam Binary files differindex f9256f3f4c..974377cdd4 100644 --- a/bootstrap/lib/stdlib/ebin/otp_internal.beam +++ b/bootstrap/lib/stdlib/ebin/otp_internal.beam diff --git a/bootstrap/lib/stdlib/ebin/re.beam b/bootstrap/lib/stdlib/ebin/re.beam Binary files differindex ae7bf3a734..06c02fc10c 100644 --- a/bootstrap/lib/stdlib/ebin/re.beam +++ b/bootstrap/lib/stdlib/ebin/re.beam diff --git a/bootstrap/lib/stdlib/ebin/shell.beam b/bootstrap/lib/stdlib/ebin/shell.beam Binary files differindex fc3552621d..a537d0936e 100644 --- a/bootstrap/lib/stdlib/ebin/shell.beam +++ b/bootstrap/lib/stdlib/ebin/shell.beam diff --git a/bootstrap/lib/stdlib/ebin/shell_default.beam b/bootstrap/lib/stdlib/ebin/shell_default.beam Binary files differindex aa600600d0..57ac5f2046 100644 --- a/bootstrap/lib/stdlib/ebin/shell_default.beam +++ b/bootstrap/lib/stdlib/ebin/shell_default.beam diff --git a/bootstrap/lib/stdlib/ebin/stdlib.app b/bootstrap/lib/stdlib/ebin/stdlib.app index ff81f58bcc..8a6e9cf514 100644 --- a/bootstrap/lib/stdlib/ebin/stdlib.app +++ b/bootstrap/lib/stdlib/ebin/stdlib.app @@ -1,20 +1,20 @@ %% This is an -*- erlang -*- file. %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% {application, stdlib, diff --git a/bootstrap/lib/stdlib/egen/erl_parse.erl b/bootstrap/lib/stdlib/egen/erl_parse.erl index 684f65386f..d3e63c1aec 100644 --- a/bootstrap/lib/stdlib/egen/erl_parse.erl +++ b/bootstrap/lib/stdlib/egen/erl_parse.erl @@ -532,20 +532,20 @@ get_attributes(L) -> -file("/usr/local/otp/releases/sles10_32_R13B03_patched/lib/parsetools-2.0.1/include/yeccpre.hrl", 0). %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% diff --git a/bootstrap/lib/stdlib/include/erl_bits.hrl b/bootstrap/lib/stdlib/include/erl_bits.hrl index 3ca71af3a0..06bc1a75fc 100644 --- a/bootstrap/lib/stdlib/include/erl_bits.hrl +++ b/bootstrap/lib/stdlib/include/erl_bits.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% This is an -*- erlang -*- file. diff --git a/bootstrap/lib/stdlib/include/erl_compile.hrl b/bootstrap/lib/stdlib/include/erl_compile.hrl index 48aadbcc5e..b49b0c3970 100644 --- a/bootstrap/lib/stdlib/include/erl_compile.hrl +++ b/bootstrap/lib/stdlib/include/erl_compile.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% diff --git a/bootstrap/lib/stdlib/include/ms_transform.hrl b/bootstrap/lib/stdlib/include/ms_transform.hrl index fed832fa66..81a624b075 100644 --- a/bootstrap/lib/stdlib/include/ms_transform.hrl +++ b/bootstrap/lib/stdlib/include/ms_transform.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -compile({parse_transform,ms_transform}). diff --git a/bootstrap/lib/stdlib/include/qlc.hrl b/bootstrap/lib/stdlib/include/qlc.hrl index edb1e7ef57..54df6168e4 100644 --- a/bootstrap/lib/stdlib/include/qlc.hrl +++ b/bootstrap/lib/stdlib/include/qlc.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -compile({parse_transform,qlc}). diff --git a/bootstrap/lib/stdlib/include/zip.hrl b/bootstrap/lib/stdlib/include/zip.hrl index 7336b760cd..47b06a1cc3 100644 --- a/bootstrap/lib/stdlib/include/zip.hrl +++ b/bootstrap/lib/stdlib/include/zip.hrl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% diff --git a/configure.in b/configure.in index 19ef304a1a..2a9a2c50b2 100644 --- a/configure.in +++ b/configure.in @@ -272,6 +272,19 @@ AC_ARG_ENABLE(m64-build, esac ],enable_m64_build=no) +AC_ARG_ENABLE(m32-build, +[ --enable-m32-build build 32bit binaries using the -m32 flag to (g)cc], +[ case "$enableval" in + no) enable_m32_build=no ;; + *) + if test X${enable_darwin_64bit} = Xyes -o X${enable_m64_build} = Xyes; + then + AC_MSG_ERROR([(--enable-darwin-64bit or --enable-m64-build) and --enable-m32-build are mutually exclusive]) ; + fi ; + enable_m32_build=yes ;; + esac +],enable_m32_build=no) + dnl OK, we might have darwin switches off different kinds, lets dnl check it all before continuing. TMPSYS=`uname -s`-`uname -m` @@ -315,6 +328,13 @@ if test X${enable_m64_build} = Xyes; then LDFLAGS="-m64 $LDFLAGS" export LDFLAGS fi +if test X${enable_m32_build} = Xyes; then + enable_hipe=no + CFLAGS="-m32 $CFLAGS" + export CFLAGS + LDFLAGS="-m32 $LDFLAGS" + export LDFLAGS +fi export ERL_TOP AC_CONFIG_SUBDIRS(lib erts) diff --git a/erts/configure.in b/erts/configure.in index a3b6fe319f..5fa1245b13 100644 --- a/erts/configure.in +++ b/erts/configure.in @@ -226,6 +226,19 @@ AC_ARG_ENABLE(m64-build, esac ],enable_m64_build=no) +AC_ARG_ENABLE(m32-build, +[ --enable-m32-build build 32bit binaries using the -m32 flag to (g)cc], +[ case "$enableval" in + no) enable_m32_build=no ;; + *) + if test X${enable_darwin_64bit} = Xyes -o X${enable_m64_build} = Xyes; + then + AC_MSG_ERROR([(--enable-darwin-64bit or --enable-m64-build) and --enable-m32-build are mutually exclusive]) ; + fi ; + enable_m32_build=yes ;; + esac +],enable_m32_build=no) + AC_ARG_ENABLE(fixalloc, [ --disable-fixalloc disable the use of fix_alloc]) if test x${enable_fixalloc} = xno ; then @@ -335,6 +348,17 @@ else esac ;; *) + if test X${enable_m32_build} = Xyes; + then + enable_hipe=no; + case $CFLAGS in + *-m32*) + ;; + *) + CFLAGS="-m32 $CFLAGS" + ;; + esac ; + fi ;; esac fi @@ -432,6 +456,35 @@ CFLAGS="$CFLAGS $extra_flags" DEBUG_CFLAGS="-g $CPPFLAGS $extra_flags" DEBUG_FLAGS=-g +dnl +dnl Adjust DEBUG_CFLAGS to match CFLAGS in terms of -m +dnl + +case $CFLAGS in + *-m64*) + case $DEBUG_CFLAGS in + *-m64*) + ;; + *) + DEBUG_CFLAGS="-m64 $DEBUG_CFLAGS" + ;; + esac + ;; + *-m32*) + case $DEBUG_CFLAGS in + *-m32*) + ;; + *) + DEBUG_CFLAGS="-m32 $DEBUG_CFLAGS" + ;; + esac + ;; + *) + ;; +esac + + + CFLAG_RUNTIME_LIBRARY_PATH="-Wl,-R" case $host_os in darwin*) @@ -664,6 +717,16 @@ case $ARCH-$OPSYS in LDFLAGS="-m64 $LDFLAGS" ;; esac + fi; + if test X${enable_m32_build} = Xyes; then + AC_MSG_NOTICE([Adjusting LDFLAGS to use -m32]) ; + case $LDFLAGS in + *-m32*) + ;; + *) + LDFLAGS="-m32 $LDFLAGS" + ;; + esac ; fi ;; esac @@ -1378,7 +1441,7 @@ AC_CHECK_HEADER(sys/devpoll.h, have_kernel_poll=/dev/poll) dnl Check for kernel SCTP support AC_SUBST(LIBSCTP) -if test "x$enable_sctp" == "xyes" ; then +if test "x$enable_sctp" = "xyes" ; then AC_CHECK_HEADER(netinet/sctp.h, [LIBSCTP=libsctp.so.1 AC_DEFINE(HAVE_SCTP_H, [1], @@ -3220,6 +3283,9 @@ case $host_os in DED_LDFLAGS="-shared -Wl,-Bsymbolic" if test X${enable_m64_build} = Xyes; then DED_LDFLAGS="-m64 $DED_LDFLAGS" + fi; + if test X${enable_m32_build} = Xyes; then + DED_LDFLAGS="-m32 $DED_LDFLAGS" fi ;; freebsd*) @@ -3228,6 +3294,9 @@ case $host_os in DED_LDFLAGS="-shared" if test X${enable_m64_build} = Xyes; then DED_LDFLAGS="-m64 $DED_LDFLAGS" + fi; + if test X${enable_m32_build} = Xyes; then + DED_LDFLAGS="-m32 $DED_LDFLAGS" fi ;; osf*) diff --git a/erts/doc/src/alt_dist.xml b/erts/doc/src/alt_dist.xml index 9a68b3cf40..a929aec97f 100644 --- a/erts/doc/src/alt_dist.xml +++ b/erts/doc/src/alt_dist.xml @@ -4,7 +4,7 @@ <chapter> <header> <copyright> - <year>2000</year><year>2009</year> + <year>2000</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>How to implement an alternative carrier for the Erlang distribution</title> @@ -939,7 +939,7 @@ connection that is not functioning.</item> <item>'R': Get creation number of listen socket, which is used to dig out the number stored in the lock file to differentiate - between invocations of Erlang nodes with the same name.\011 </item> + between invocations of Erlang nodes with the same name.</item> </list> <p>The control interface gets a buffer to return its value in, but is free to allocate it's own buffer is the provided one is @@ -949,11 +949,11 @@ ( 2) char* buf, int count, char** res, int res_size) ( 3) { ( 4) /* Local macro to ensure large enough buffer. */ -( 5) #define ENSURE(N) \\ -( 6) do { \\ -( 7) if (res_size < N) { \\ -( 8) *res = ALLOC(N); \\ -( 9) } \\ +( 5) #define ENSURE(N) \ +( 6) do { \ +( 7) if (res_size < N) { \ +( 8) *res = ALLOC(N); \ +( 9) } \ (10) } while(0) (11) UdsData *ud = (UdsData *) handle; @@ -1075,7 +1075,7 @@ Eshell V5.0 (abort with ^G) (bing@hador)2></pre> <p>...</p> <pre> -$ <input>erl -pa $ERL_TOP/lib/kernel/examples/uds_dist/ebin -proto_dist uds \\ </input> +$ <input>erl -pa $ERL_TOP/lib/kernel/examples/uds_dist/ebin -proto_dist uds \ </input> <input> -no_epmd -sname bong</input> Erlang (BEAM) emulator version 5.0 @@ -1084,7 +1084,7 @@ Eshell V5.0 (abort with ^G) <p>One can utilize the ERL_FLAGS environment variable to store the complicated parameters in:</p> <pre> -$ <input>ERL_FLAGS=-pa $ERL_TOP/lib/kernel/examples/uds_dist/ebin \\ </input> +$ <input>ERL_FLAGS=-pa $ERL_TOP/lib/kernel/examples/uds_dist/ebin \ </input> <input> -proto_dist uds -no_epmd</input> $ <input>export ERL_FLAGS</input> $ <input>erl -sname bang</input> diff --git a/erts/doc/src/crash_dump.xml b/erts/doc/src/crash_dump.xml index 5182929358..b3c4671c3d 100644 --- a/erts/doc/src/crash_dump.xml +++ b/erts/doc/src/crash_dump.xml @@ -4,7 +4,7 @@ <chapter> <header> <copyright> - <year>1999</year><year>2009</year> + <year>1999</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>How to interpret the Erlang crash dumps</title> @@ -96,7 +96,7 @@ allocators see <seealso marker="erts_alloc">erts_alloc(3)</seealso>.</item> <item>"<em><A></em>: Cannot reallocate <em><N></em> - bytes of memory\011(of type "<em><T></em>")." - Same as + bytes of memory (of type "<em><T></em>")." - Same as above with the exception that memory was being reallocated instead of being allocated when the system ran out of memory.</item> <item>"Unexpected op code <em>N</em>" - Error in compiled diff --git a/erts/doc/src/driver.xml b/erts/doc/src/driver.xml index c396ee0b90..12c79aee90 100644 --- a/erts/doc/src/driver.xml +++ b/erts/doc/src/driver.xml @@ -4,7 +4,7 @@ <chapter> <header> <copyright> - <year>2001</year><year>2009</year> + <year>2001</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>How to implement a driver</title> @@ -510,11 +510,11 @@ static int do_select(const char* s, our_data_t* data) PGconn* conn = data->conn; /* if there's an error return it now */ if (PQsendQuery(conn, s) == 0) { -\011ei_x_buff x; -\011ei_x_new_with_version(&x); -\011encode_error(&x, conn); -\011driver_output(data->port, x.buff, x.index); -\011ei_x_free(&x); + ei_x_buff x; + ei_x_new_with_version(&x); + encode_error(&x, conn); + driver_output(data->port, x.buff, x.index); + ei_x_free(&x); } /* else wait for ready_output to get results */ return 0; @@ -532,31 +532,31 @@ static void ready_io(ErlDrvData drv_data, ErlDrvEvent event) ei_x_buff x; ei_x_new_with_version(&x); if (data->connecting) { -\011ConnStatusType status; -\011PQconnectPoll(conn); -\011status = PQstatus(conn); -\011if (status == CONNECTION_OK) -\011 encode_ok(&x); -\011else if (status == CONNECTION_BAD) -\011 encode_error(&x, conn); + ConnStatusType status; + PQconnectPoll(conn); + status = PQstatus(conn); + if (status == CONNECTION_OK) + encode_ok(&x); + else if (status == CONNECTION_BAD) + encode_error(&x, conn); } else { -\011PQconsumeInput(conn); -\011if (PQisBusy(conn)) -\011 return; -\011res = PQgetResult(conn); -\011encode_result(&x, res, conn); -\011PQclear(res); -\011for (;;) { -\011 res = PQgetResult(conn); -\011 if (res == NULL) -\011\011break; -\011 PQclear(res); -\011} + PQconsumeInput(conn); + if (PQisBusy(conn)) + return; + res = PQgetResult(conn); + encode_result(&x, res, conn); + PQclear(res); + for (;;) { + res = PQgetResult(conn); + if (res == NULL) + break; + PQclear(res); + } } if (x.index > 1) { -\011driver_output(data->port, x.buff, x.index); -\011if (data->connecting) -\011 driver_select(data->port, (ErlDrvEvent)data->socket, DO_WRITE, 0); + driver_output(data->port, x.buff, x.index); + if (data->connecting) + driver_select(data->port, (ErlDrvEvent)data->socket, DO_WRITE, 0); } ei_x_free(&x); } @@ -592,17 +592,17 @@ static void ready_io(ErlDrvData drv_data, ErlDrvEvent event) connect(ConnectStr) -> case erl_ddll:load_driver(".", "pg_async") of -\011ok -> ok; -\011{error, already_loaded} -> ok; -\011_ -> exit({error, could_not_load_driver}) + ok -> ok; + {error, already_loaded} -> ok; + _ -> exit({error, could_not_load_driver}) end, Port = open_port({spawn, ?MODULE}, [binary]), port_control(Port, ?DRV_CONNECT, ConnectStr), case return_port_data(Port) of -\011ok -> -\011 {ok, Port}; -\011Error -> -\011 Error + ok -> + {ok, Port}; + Error -> + Error end. disconnect(Port) -> @@ -617,8 +617,8 @@ select(Port, Query) -> return_port_data(Port) -> receive -\011{Port, {data, Data}} -> -\011 binary_to_term(Data) + {Port, {data, Data}} -> + binary_to_term(Data) end. ]]></code> <p>The Erlang code is slightly different, this is because we @@ -662,22 +662,22 @@ return_port_data(Port) -> call-back <c><![CDATA[ready_async]]></c>.</p> <code type="none"><![CDATA[ static ErlDrvEntry next_perm_driver_entry = { - NULL,\011\011\011/* init */ + NULL, /* init */ start, - NULL, \011\011\011/* stop */ - output,\011\011\011 - NULL,\011\011\011/* ready_input */ - NULL,\011\011\011/* ready_output */ - "next_perm", /* the name of the driver */ - NULL,\011\011\011/* finish */ - NULL,\011\011\011/* handle */ - NULL,\011\011\011/* control */ - NULL,\011\011\011/* timeout */ - NULL,\011\011\011/* outputv */ + NULL, /* stop */ + output, + NULL, /* ready_input */ + NULL, /* ready_output */ + "next_perm", /* the name of the driver */ + NULL, /* finish */ + NULL, /* handle */ + NULL, /* control */ + NULL, /* timeout */ + NULL, /* outputv */ ready_async, - NULL,\011\011\011/* flush */ - NULL,\011\011\011/* call */ - NULL\011\011\011/* event */ + NULL, /* flush */ + NULL, /* call */ + NULL /* event */ }; ]]></code> <p>The <c><![CDATA[output]]></c> function allocates the work-area of the @@ -699,7 +699,7 @@ struct our_async_data { }; our_async_data::our_async_data(ErlDrvPort p, int command, -\011\011\011 const char* buf, int len) + const char* buf, int len) : prev(command == 2), data((int*)buf, (int*)buf + len / sizeof(int)) { @@ -722,9 +722,9 @@ static void do_perm(void* async_data) { our_async_data* d = reinterpret_cast<our_async_data*>(async_data); if (d->prev) -\011prev_permutation(d->data.begin(), d->data.end()); + prev_permutation(d->data.begin(), d->data.end()); else -\011next_permutation(d->data.begin(), d->data.end()); + next_permutation(d->data.begin(), d->data.end()); } ]]></code> <p>In the <c><![CDATA[ready_async]]></c> function, the output is sent back to the @@ -742,9 +742,9 @@ static void ready_async(ErlDrvData drv_data, ErlDrvThreadData async_data) int n = d->data.size(), result_n = n*2 + 3; ErlDrvTermData* result = new ErlDrvTermData[result_n], * rp = result; for (vector<int>::iterator i = d->data.begin(); -\011 i != d->data.end(); ++i) { -\011*rp++ = ERL_DRV_INT; -\011*rp++ = *i; + i != d->data.end(); ++i) { + *rp++ = ERL_DRV_INT; + *rp++ = *i; } *rp++ = ERL_DRV_NIL; *rp++ = ERL_DRV_LIST; @@ -767,16 +767,16 @@ static void ready_async(ErlDrvData drv_data, ErlDrvThreadData async_data) load() -> case whereis(next_perm) of -\011undefined -> -\011 case erl_ddll:load_driver(".", "next_perm") of -\011\011ok -> ok; -\011\011{error, already_loaded} -> ok; -\011\011E -> exit(E) -\011 end, -\011 Port = open_port({spawn, "next_perm"}, []), -\011 register(next_perm, Port); -\011_ -> -\011 ok + undefined -> + case erl_ddll:load_driver(".", "next_perm") of + ok -> ok; + {error, already_loaded} -> ok; + E -> exit(E) + end, + Port = open_port({spawn, "next_perm"}, []), + register(next_perm, Port); + _ -> + ok end. list_to_integer_binaries(L) -> @@ -793,8 +793,8 @@ next_perm(L, Nxt) -> B = list_to_integer_binaries(L), port_control(next_perm, Nxt, B), receive -\011Result -> -\011 Result + Result -> + Result end. all_perm(L) -> diff --git a/erts/doc/src/driver_entry.xml b/erts/doc/src/driver_entry.xml index 6b7d2acf24..e71b48bd92 100644 --- a/erts/doc/src/driver_entry.xml +++ b/erts/doc/src/driver_entry.xml @@ -4,7 +4,7 @@ <cref> <header> <copyright> - <year>2001</year><year>2009</year> + <year>2001</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>driver_entry</title> @@ -188,7 +188,7 @@ typedef struct erl_drv_entry { <p>This is called when the port is closed, with <c>port_close/1</c> or <c>Port ! {self(), close}</c>. Note that terminating the port owner process also closes the - p\011 port.</p> + port.</p> </item> <tag><marker id="output"/>void (*output)(ErlDrvData drv_data, char *buf, int len)</tag> <item> diff --git a/erts/doc/src/erl_driver.xml b/erts/doc/src/erl_driver.xml index 5d7a11b70a..63108f41f0 100644 --- a/erts/doc/src/erl_driver.xml +++ b/erts/doc/src/erl_driver.xml @@ -299,6 +299,8 @@ typedef struct ErlDrvSysInfo { int smp_support; int async_threads; int scheduler_threads; + int nif_major_version; + int nif_minor_version; } ErlDrvSysInfo; </code> @@ -365,9 +367,14 @@ typedef struct ErlDrvSysInfo { (the same as returned by <seealso marker="erts:erlang#system_info_schedulers">erlang:system_info(schedulers)</seealso>). </item> + <tag><c>nif_major_version</c></tag> + <item>The value of <c>ERL_NIF_MAJOR_VERSION</c> when the runtime system was compiled. + </item> + <tag><c>nif_minor_version</c></tag> + <item>The value of <c>ERL_NIF_MINOR_VERSION</c> when the runtime system was compiled. + </item> </taglist> </item> - <tag><marker id="ErlDrvBinary"/>ErlDrvBinary</tag> <item> <p/> diff --git a/erts/doc/src/erl_nif.xml b/erts/doc/src/erl_nif.xml index 2902d70976..c013d96fc4 100644 --- a/erts/doc/src/erl_nif.xml +++ b/erts/doc/src/erl_nif.xml @@ -41,7 +41,9 @@ </p><p><em>R13B04</em>: The function prototypes of the NIFs have changed to expect <c>argc</c> and <c>argv</c> arguments. The arity of a NIF is by that no longer limited to - 3.</p></warning> + 3.</p> + <p>enif_get_data renamed as enif_priv_data.</p> + </warning> <p>A NIF library contains native implementation of some functions of an erlang module. The native implemented functions (NIFs) are @@ -113,16 +115,71 @@ ok dynamic library will mean that static data defined by the library will be shared as well. To avoid unintentionally shared static data, each Erlang module code can keep its own private data. This - global private data can be set when the NIF library is loaded and - then retrieved by calling <seealso marker="erl_nif#enif_get_data">enif_get_data()</seealso>.</p> - <p>There is currently no way to explicitly unload a NIF - library. A library will be automatically unloaded when the module - code that it belongs to is purged by the code server. A NIF - library will can also be unloaded by replacing it with another - version of the library by a second call to + private data can be set when the NIF library is loaded and + then retrieved by calling <seealso marker="erl_nif#enif_priv_data">enif_priv_data()</seealso>.</p> + <p>There is no way to explicitly unload a NIF library. A library will be + automatically unloaded when the module code that it belongs to is purged + by the code server. A NIF library will also be unloaded if it is replaced + by another version of the library by a second call to <c>erlang:load_nif/2</c> from the same module code.</p> </description> - + <section> + <title>FUNCTIONALITY</title> + <p>All functions that a NIF library needs to do with Erlang are + performed through the NIF API functions. There are functions + for the following functionality:</p> + <taglist> + <tag>Read and write Erlang terms</tag> + <item><p>Any Erlang terms can be passed to a NIF as function arguments and + be returned as function return value. The terms are of C-type <c>ERL_NIF_TERM</c> + and can only be read or written using API functions. Most functions to read + the content of a term are prefixed <c>enif_get_</c> and usually return + true (or false) if the term was of the expected type (or not). + The functions to write terms are all prefixed <c>enif_make_</c> and usually + return the created <c>ERL_NIF_TERM</c>. There are also some functions + to query terms, like <c>enif_is_atom</c>, <c>enif_is_identical</c> and + <c>enif_compare</c>.</p></item> + <tag>Resource objects</tag> + <item><p>Resource objects are a way to return pointers to native data + structures from a NIF in a safe way. A resource object is just a block + of memory allocated with <seealso marker="erl_nif#enif_alloc_resource">enif_alloc_resource()</seealso>. + A handle ("safe pointer") to this memory block can then be returned to Erlang by the use of + <seealso marker="erl_nif#enif_make_resource">enif_make_resource()</seealso>. + The term returned by <c>enif_make_resource</c> + is totally opaque in nature. It can be stored and passed between processses + on the same node, but the only real end usage is to pass it back as argument to a NIF. + The NIF can then do <seealso marker="erl_nif#enif_get_resource">enif_get_resource()</seealso> + and get back a pointer to the memory block that is guaranteed to still be + valid. A resource object will not be deallocated until the last handle term + has been garbage collected by the VM and the resource has been + released with <seealso marker="erl_nif#enif_release_resource">enif_release_resource()</seealso> + (not necessarily in that order).</p> + <p>All resource objects are created as instances of some <em>resource type</em>. + This makes resources from different modules or applications to be distinguishable. + A resource type is created by calling + <seealso marker="erl_nif#enif_open_resource_type">enif_open_resource_type()</seealso> + when a library is loaded. Objects of that resource type can then later be allocated + and <c>enif_get_resource</c> verifies that the resource is of the expected type. + A resource type can have a destructor function that is automatically + called when resources of that type are released (by either the garbage + collector or <c>enif_release_resource</c>). Resource types also support + upgrade in runtime by allowing a loaded NIF library to takeover an already + existing resource type and thereby "inherit" all existing objects of that type. + The destructor of the new library will thereafter be called for the inherited + objects and the library with the old destructor function can be safely + unloaded. Resource types are uniquely identified by a supplied name string. + </p> + </item> + <tag>Threads and concurrency</tag> + <item><p>A NIF is thread-safe without any explicit synchronization as + long as it acts as a pure function and only operates on the supplied + arguments. As soon as you access a shared state either through static + variables or <seealso marker="erl_nif#enif_priv_data">enif_priv_data</seealso> + you need to supply your own explicit synchronization.</p> + <p>The library initialization callbacks <c>load</c>, <c>reload</c> and + <c>upgrade</c> are all thread-safe even for shared state data.</p></item> + </taglist> + </section> <section> <title>INITIALIZATION</title> <taglist> @@ -146,7 +203,7 @@ ok and there is no previously loaded library for this module.</p> <p><c>*priv_data</c> can be set to point to some private data that the library needs in able to keep a state between NIF - calls. <c>enif_get_data()</c> will return this pointer.</p> + calls. <c>enif_priv_data()</c> will return this pointer.</p> <p><c>load_info</c> is the second argument to <seealso marker="erlang#load_nif-2">erlang:load_nif/2</seealso>.</p> <p>The library will fail to load if <c>load</c> returns @@ -168,13 +225,11 @@ ok <tag><marker id="upgrade"/>int (*upgrade)(ErlNifEnv* env, void** priv_data, void** old_priv_data, ERL_NIF_TERM load_info)</tag> <item><p><c>upgrade</c> is called when the NIF library is loaded and there is no previously loaded library for this module - code, BUT there is old code of this module with a - loaded NIF library.</p> + code, BUT there is old code of this module with a loaded NIF library.</p> <p>Works the same as <c>load</c>. The only difference is that <c>*old_priv_data</c> already contains the value set by the last call to <c>load</c> or <c>reload</c> for the old module - code. It is allowed to write to both *priv_data and - *old_priv_data.</p> + code. It is allowed to write to both *priv_data and *old_priv_data.</p> <p>The library will fail to load if <c>upgrade</c> returns anything other than 0 or if <c>upgrade</c> is NULL.</p> </item> @@ -185,7 +240,6 @@ ok of the same module may or may not exist.</p> </item> - </taglist> </section> @@ -193,6 +247,14 @@ ok <title>DATA TYPES</title> <taglist> + <tag><marker id="ERL_NIF_TERM"/>ERL_NIF_TERM</tag> + <item> + <p>Variables of type <c>ERL_NIF_TERM</c> can refer to any Erlang term. + This is an opaque type and values of it can only by used either as + arguments to API functions or as return values from NIFs. A variable of + type <c>ERL_NIF_TERM</c> is only valid until the NIF call, where it was + obtained, returns.</p> + </item> <tag><marker id="ErlNifEnv"/>ErlNifEnv</tag> <item> <p><c>ErlNifEnv</c> contains information about the context in @@ -236,15 +298,41 @@ typedef struct { inspected binary term. <c>data</c> is a pointer to a buffer of <c>size</c> bytes with the raw content of the binary.</p> </item> - <tag><marker id="ERL_NIF_TERM"/>ERL_NIF_TERM</tag> + <tag><marker id="ErlNifResourceType"/>ErlNifResourceType</tag> <item> - <p>Variables of type <c>ERL_NIF_TERM</c> can refere to any - Erlang term. This is an opaque type and values of it can only - by used either as arguments to API functions or as return - values from NIFs. A variable of type <c>ERL_NIF_TERM</c> is - only valid until the NIF call, where it was obtained, - returns.</p> - </item> + <p>Each instance of <c>ErlNifResourceType</c> represent a class of + memory managed resource objects that can be garbage collected. + Each resource type has a unique name and a destructor function that + is called when objects of its type are released.</p> + </item> + <tag><marker id="ErlNifResourceDtor"/>ErlNifResourceDtor</tag> + <item> + <p/> + <code type="none"> +typedef void ErlNifResourceDtor(ErlNifEnv* env, void* obj); +</code> + <p>The function prototype of a resource destructor function. + A destructor function is not allowed to call any term-making functions.</p> + </item> + <tag><marker id="ErlNifCharEncoding"/>ErlNifCharEncoding</tag> + <item> + <p/> + <code type="none"> +typedef enum { + ERL_NIF_LATIN1 +}ErlNifCharEncoding; +</code> + <p>The character encoding used in strings. The only supported + encoding is currently <c>ERL_NIF_LATIN1</c> for iso-latin-1 + (8-bit ascii).</p> + </item> + <tag><marker id="ErlNifSysInfo"/>ErlNifSysInfo</tag> + <item> + <p>Used by <seealso marker="erl_nif#enif_system_info">enif_system_info</seealso> + to return information about the runtime system. Contains currently + the exact same content as <seealso marker="erl_driver#ErlDrvSysInfo">ErlDrvSysInfo</seealso>.</p> + </item> + </taglist> </section> @@ -257,7 +345,18 @@ typedef struct { <fsummary>Create a new binary.</fsummary> <desc><p>Allocate a new binary of size of <c>size</c> bytes. Initialize the structure pointed to by <c>bin</c> to - refer to the allocated binary. Return false if allocation failed.</p></desc> + refer to the allocated binary. The binary must either be released by + <seealso marker="erl_nif#enif_release_binary">enif_release_binary()</seealso> + or ownership transferred to an erlang term with + <seealso marker="erl_nif#enif_make_binary">enif_make_binary()</seealso>. + An allocated (and owned) <c>ErlNifBinary</c> can be kept between NIF + calls.</p> + <p>Return false if allocation failed.</p> + </desc> + </func> + <func><name><ret>void*</ret><nametext>enif_alloc_resource(ErlNifEnv* env, ErlNifResourceType* type, unsigned size)</nametext></name> + <fsummary>Allocate a memory managed resource object</fsummary> + <desc><p>Allocate a memory managed resource object of type <c>type</c> and size <c>size</c> bytes.</p></desc> </func> <func><name><ret>int</ret><nametext>enif_compare(ErlNifEnv* env, ERL_NIF_TERM lhs, ERL_NIF_TERM rhs)</nametext></name> <fsummary>Compare two terms</fsummary> @@ -267,13 +366,50 @@ typedef struct { operators <c>==</c>, <c>/=</c>, <c>=<</c>, <c><</c>, <c>>=</c> and <c>></c> (but <em>not</em> <c>=:=</c> or <c>=/=</c>).</p></desc> </func> + <func><name><ret>void</ret><nametext>enif_cond_broadcast(ErlNifCond *cnd)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_broadcast">erl_drv_cond_broadcast()</seealso>. + </p></desc> + </func> + <func><name><ret>ErlNifCond*</ret><nametext>enif_cond_create(char *name)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_create">erl_drv_cond_create()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_cond_destroy(ErlNifCond *cnd)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_destroy">erl_drv_cond_destroy()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_cond_signal(ErlNifCond *cnd)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_signal">erl_drv_cond_signal()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_cond_wait(ErlNifCond *cnd, ErlNifMutex *mtx)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_wait">erl_drv_cond_wait()</seealso>. + </p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_equal_tids(ErlNifTid tid1, ErlNifTid tid2)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_equal_tids">erl_drv_equal_tids()</seealso>. + </p></desc> + </func> <func><name><ret>void</ret><nametext>enif_free(ErlNifEnv* env, void* ptr)</nametext></name> <fsummary>Free dynamic memory</fsummary> <desc><p>Free memory allocated by <c>enif_alloc</c>.</p></desc> </func> - <func><name><ret>void*</ret><nametext>enif_get_data(ErlNifEnv* env)</nametext></name> - <fsummary>Get the private data of a NIF library</fsummary> - <desc><p>Return the pointer to the private data that was set by <c>load</c>, <c>reload</c> or <c>upgrade</c>.</p></desc> + <func><name><ret>int</ret><nametext>enif_get_atom(ErlNifEnv* env, + ERL_NIF_TERM term, char* buf, unsigned size) + </nametext></name> + <fsummary>Get the text representation of an atom term</fsummary> + <desc><p>Write a null-terminated string, in the buffer pointed to by + <c>buf</c> of size <c>size</c>, consisting of the string + representation of the atom <c>term</c>. Return the number of bytes + written (including terminating null character) or 0 if + <c>term</c> is not an atom with maximum length of + <c>size-1</c>.</p></desc> </func> <func><name><ret>int</ret><nametext>enif_get_double(ErlNifEnv* env, ERL_NIF_TERM term, double* dp)</nametext></name> <fsummary>Read a floating-point number term.</fsummary> @@ -292,16 +428,49 @@ typedef struct { <c>list</c> or return false if <c>list</c> is not a non-empty list.</p></desc> </func> + <func><name><ret>int</ret><nametext>enif_get_long(ErlNifEnv* env, ERL_NIF_TERM term, long int* ip)</nametext></name> + <fsummary>Read an long integer term.</fsummary> + <desc><p>Set <c>*ip</c> to the long integer value of + <c>term</c> or return false if <c>term</c> is not an integer or is + outside the bounds of type <c>long int</c>.</p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_get_resource(ErlNifEnv* env, ERL_NIF_TERM term, ErlNifResourceType* type, void** objp)</nametext></name> + <fsummary>Get the pointer to a resource object</fsummary> + <desc><p>Set <c>*objp</c> to point to the resource object referred to by <c>term</c>. + Return false if <c>term</c> is not a handle to a resource object of type <c>type</c>.</p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_get_string(ErlNifEnv* env, + ERL_NIF_TERM list, char* buf, unsigned size, + ErlNifCharEncoding encode)</nametext></name> + <fsummary>Get a C-string from a list.</fsummary> + <desc><p>Write a null-terminated string, in the buffer pointed to by + <c>buf</c> with size <c>size</c>, consisting of the characters + in the string <c>list</c>. The characters are written using encoding + <c>encode</c>. Return the number of bytes written + (including terminating null character), or <c>-size</c> if the + string was truncated due to buffer space, or 0 if <c>list</c> + is not a string that can be encoded with <c>encode</c> or + if <c>size</c> was less than 1. + The written string is always null-terminated unless buffer + <c>size</c> is less than 1.</p></desc> + </func> <func><name><ret>int</ret><nametext>enif_get_tuple(ErlNifEnv* env, ERL_NIF_TERM term, int* arity, const ERL_NIF_TERM** array)</nametext></name> <fsummary>Inspect the elements of a tuple.</fsummary> <desc><p>If <c>term</c> is a tuple, set <c>*array</c> to point to an array containing the elements of the tuple and set <c>*arity</c> to the number of elements. Note that the array - is read-only an <c>(*array)[N-1]</c> will be the Nth element of + is read-only and <c>(*array)[N-1]</c> will be the Nth element of the tuple. <c>*array</c> is undefined if the arity of the tuple is zero.</p><p>Return false if <c>term</c> is not a tuple.</p></desc> </func> + <func><name><ret>int</ret><nametext>enif_get_uint(ErlNifEnv* env, ERL_NIF_TERM term, unsigned int* ip)</nametext></name> + <fsummary>Read an unsigned integer term.</fsummary> + <desc><p>Set <c>*ip</c> to the unsigned integer value of + <c>term</c> or return false if <c>term</c> is not an unsigned integer or is + outside the bounds of type <c>unsigned int</c></p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_get_ulong(ErlNifEnv* env, ERL_NIF_TERM term, unsigned long* ip)</nametext></name> <fsummary>Read an unsigned integer term.</fsummary> <desc><p>Set <c>*ip</c> to the unsigned long integer value of @@ -310,10 +479,21 @@ typedef struct { </func> <func><name><ret>int</ret><nametext>enif_inspect_binary(ErlNifEnv* env, ERL_NIF_TERM bin_term, ErlNifBinary* bin)</nametext></name> <fsummary>Inspect the content of a binary</fsummary> - <desc><p>Initialize the structure pointed to by <c>bin</c> with - transient information about the binary term + <desc><p>Initialize the structure pointed to by <c>bin</c> with + information about the binary term <c>bin_term</c>. Return false if <c>bin_term</c> is not a binary.</p></desc> </func> + <func><name><ret>int</ret><nametext>enif_inspect_iolist_as_binary(ErlNifEnv* + env, ERL_NIF_TERM term, ErlNifBinary* bin) + </nametext></name> + <fsummary>Inspect the content of an iolist</fsummary> + <desc><p>Initialize the structure pointed to by <c>bin</c> with one + continuous buffer with the same byte content as <c>iolist</c>. As with + inspect_binary, the data pointed to by <c>bin</c> is transient and does + not need to be released. Return false if <c>iolist</c> is not an + iolist.</p> + </desc> + </func> <func><name><ret>int</ret><nametext>enif_is_atom(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name> <fsummary>Determine if a term is an atom</fsummary> <desc><p>Return true if <c>term</c> is an atom.</p></desc> @@ -322,19 +502,36 @@ typedef struct { <fsummary>Determine if a term is a binary</fsummary> <desc><p>Return true if <c>term</c> is a binary</p></desc> </func> + <func><name><ret>int</ret><nametext>enif_is_empty_list(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name> + <fsummary>Determine if a term is an empty list</fsummary> + <desc><p>Return true if <c>term</c> is an empty list.</p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_is_fun(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name> + <fsummary>Determine if a term is a fun</fsummary> + <desc><p>Return true if <c>term</c> is a fun.</p></desc> + </func> <func><name><ret>int</ret><nametext>enif_is_identical(ErlNifEnv* env, ERL_NIF_TERM lhs, ERL_NIF_TERM rhs)</nametext></name> <fsummary>Erlang operator =:=</fsummary> - <desc><p>Return true if and only if the two terms are - identical. Corresponds to the Erlang operators <c>=:=</c> and + <desc><p>Return true if the two terms are identical. Corresponds to the + Erlang operators <c>=:=</c> and <c>=/=</c>.</p></desc> </func> + <func><name><ret>int</ret><nametext>enif_is_pid(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name> + <fsummary>Determine if a term is a pid</fsummary> + <desc><p>Return true if <c>term</c> is a pid.</p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_is_port(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name> + <fsummary>Determine if a term is a port</fsummary> + <desc><p>Return true if <c>term</c> is a port.</p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_is_ref(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name> <fsummary>Determine if a term is a reference</fsummary> <desc><p>Return true if <c>term</c> is a reference.</p></desc> </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_atom(ErlNifEnv* env, const char* name)</nametext></name> <fsummary>Create an atom term</fsummary> - <desc><p>Create an atom term from the C-string <c>name</c>. Atom + <desc><p>Create an atom term from the C-string <c>name</c>. Unlike other terms, atom terms may be saved and used between NIF calls.</p></desc> </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_badarg(ErlNifEnv* env)</nametext></name> @@ -343,8 +540,10 @@ typedef struct { </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_binary(ErlNifEnv* env, ErlNifBinary* bin)</nametext></name> <fsummary>Make a binary term.</fsummary> - <desc><p>Make a binary term from <c>bin</c>. Will also release - the binary.</p></desc> + <desc><p>Make a binary term from <c>bin</c>. Any ownership of + the binary data will be transferred to the created term and + <c>bin</c> should be considered read-only for the rest of the NIF + call and then as released.</p></desc> </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_double(ErlNifEnv* env, double d)</nametext></name> <fsummary>Create an floating-point term</fsummary> @@ -367,18 +566,62 @@ typedef struct { <c>cnt</c> number of arguments (after <c>cnt</c>) of type ERL_NIF_TERM as the elements of the list. An empty list is returned if <c>cnt</c> is 0.</p></desc> </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list1(ErlNifEnv* env, ERL_NIF_TERM e1)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list2(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list3(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2, ERL_NIF_TERM e3)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list4(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e4)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list5(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e5)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list6(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e6)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list7(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e7)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list8(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e8)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list9(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e9)</nametext></name> + <fsummary>Create a list term.</fsummary> + <desc><p>Create an ordinary list term with length indicated by the + function name. Prefere these functions (macros) over the variadic + <c>enif_make_list</c> to get compile time error if the number of + arguments does not match.</p></desc> + </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list_cell(ErlNifEnv* env, ERL_NIF_TERM head, ERL_NIF_TERM tail)</nametext></name> <fsummary>Create a list cell.</fsummary> <desc><p>Create a list cell <c>[head | tail]</c>.</p></desc> </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[], unsigned cnt)</nametext></name> + <fsummary>Create a list term from an array.</fsummary> + <desc><p>Create an ordinary list containing the elements of array <c>arr</c> + of length <c>cnt</c>. An empty list is returned if <c>cnt</c> is 0.</p></desc> + </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_long(ErlNifEnv* env, long int i)</nametext></name> + <fsummary>Create an integer term from a long int</fsummary> + <desc><p>Create an integer term from a <c>long int</c>.</p></desc> + </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_ref(ErlNifEnv* env)</nametext></name> <fsummary>Create a reference.</fsummary> <desc><p>Create a reference like <seealso marker="erlang#make_ref-0">erlang:make_ref/0</seealso>.</p></desc> </func> - <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_string(ErlNifEnv* env, const char* string)</nametext></name> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_resource(ErlNifEnv* env, void* obj)</nametext></name> + <fsummary>Create an opaque handle to a resource object</fsummary> + <desc><p>Create an opaque handle to a memory managed resource object + obtained by <seealso marker="erl_nif#enif_alloc_resource">enif_alloc_resource</seealso>. + No ownership transfer is done, the resource object still needs to be released by + <seealso marker="erl_nif#enif_release_resource">enif_release_resource</seealso>.</p> + <p>Note that the only defined behaviour when using of a resource term in + an Erlang program is to store it and send it between processes on the + same node. Other operations such as matching or <c>term_to_binary</c> + will have unpredictable (but harmless) results.</p></desc> + </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_string(ErlNifEnv* env, const char* string, ErlNifCharEncoding encoding)</nametext></name> <fsummary>Create a string.</fsummary> <desc><p>Create a list containing the characters of the - C-string <c>string</c>.</p></desc> + null-terminated string <c>string</c> with encoding <c>encoding</c>.</p></desc> + </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_sub_binary(ErlNifEnv* + env, ERL_NIF_TERM bin_term, unsigned pos, unsigned size)</nametext></name> + <fsummary>Make a subbinary term.</fsummary> + <desc><p>Make a subbinary of binary <c>bin_term</c>, starting at + zero-based position <c>pos</c> with a length of <c>size</c> bytes. + <c>bin_term</c> must be a binary or bitstring and + <c>pos+size</c> must be less or equal to the number of whole + bytes in <c>bin_term</c>.</p></desc> </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple(ErlNifEnv* env, unsigned cnt, ...)</nametext></name> <fsummary>Create a tuple term.</fsummary> @@ -386,13 +629,205 @@ typedef struct { <c>cnt</c> number of arguments (after <c>cnt</c>) of type ERL_NIF_TERM as the elements of the tuple.</p></desc> </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple1(ErlNifEnv* env, ERL_NIF_TERM e1)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple2(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple3(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2, ERL_NIF_TERM e3)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple4(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e4)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple5(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e5)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple6(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e6)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple7(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e7)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple8(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e8)</nametext></name> + <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple9(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e9)</nametext></name> + <fsummary>Create a tuple term.</fsummary> + <desc><p>Create a tuple term with length indicated by the + function name. Prefere these functions (macros) over the variadic + <c>enif_make_tuple</c> to get compile time error if the number of + arguments does not match.</p></desc> + </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[], unsigned cnt)</nametext></name> + <fsummary>Create a tuple term from an array.</fsummary> + <desc><p>Create a tuple containing the elements of array <c>arr</c> + of length <c>cnt</c>.</p></desc> + </func> + <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_uint(ErlNifEnv* env, unsigned int i)</nametext></name> + <fsummary>Create an unsigned integer term</fsummary> + <desc><p>Create an integer term from an <c>unsigned int</c>.</p></desc> + </func> <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_ulong(ErlNifEnv* env, unsigned long i)</nametext></name> <fsummary>Create an integer term from an unsigned long int</fsummary> <desc><p>Create an integer term from an <c>unsigned long int</c>.</p></desc> </func> + <func><name><ret>ErlNifMutex*</ret><nametext>enif_mutex_create(char *name)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_create">erl_drv_mutex_create()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_mutex_destroy(ErlNifMutex *mtx)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_destroy">erl_drv_mutex_destroy()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_mutex_lock(ErlNifMutex *mtx)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_lock">erl_drv_mutex_lock()</seealso>. + </p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_mutex_trylock(ErlNifMutex *mtx)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_trylock">erl_drv_mutex_trylock()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_mutex_unlock(ErlNifMutex *mtx)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_unlock">erl_drv_mutex_unlock()</seealso>. + </p></desc> + </func> + <func><name><ret>ErlNifResourceType*</ret><nametext>enif_open_resource_type(ErlNifEnv* env, const char* name, + ErlNifResourceDtor* dtor, ErlNifResourceFlags flags, ErlNifResourceFlags* tried)</nametext></name> + <fsummary>Create or takeover a resource type</fsummary> + <desc><p>Create or takeover a resource type identified by the string + <c>name</c> and give it the destructor function pointed to by <c>dtor</c>. + Argument <c>flags</c> can have the following values:</p> + <taglist> + <tag><c>ERL_NIF_RT_CREATE</c></tag> + <item>Create a new resource type that does not already exist.</item> + <tag><c>ERL_NIF_RT_TAKEOVER</c></tag> + <item>Open an existing resource type and take over ownership of all its instances. + The supplied destructor <c>dtor</c> will be called both for existing instances + as well as new instances not yet created by the calling NIF library.</item> + </taglist> + <p>The two flag values can be combined with bitwise-or. To avoid unintentionally + name clashes a good practice is to include the module name as part of the + type <c>name</c>. The <c>dtor</c> may be <c>NULL</c> in case no destructor + is needed.</p> + <p>On success, return a pointer to the resource type and <c>*tried</c> + will be set to either <c>ERL_NIF_RT_CREATE</c> or + <c>ERL_NIF_RT_TAKEOVER</c> to indicate what was actually done. + On failure, return <c>NULL</c> and set <c>*tried</c> to <c>flags</c>. + It is allowed to set <c>tried</c> to <c>NULL</c>.</p> + <p>Note that <c>enif_open_resource_type</c> is only allowed to be called in the three callbacks + <seealso marker="erl_nif#load">load</seealso>, <seealso marker="erl_nif#reload">reload</seealso> + and <seealso marker="erl_nif#upgrade">upgrade</seealso>.</p> + </desc> + </func> + <func><name><ret>void*</ret><nametext>enif_priv_data(ErlNifEnv* env)</nametext></name> + <fsummary>Get the private data of a NIF library</fsummary> + <desc><p>Return the pointer to the private data that was set by <c>load</c>, + <c>reload</c> or <c>upgrade</c>.</p> + <p>Was previously named <c>enif_get_data</c>.</p></desc> + </func> <func><name><ret>void</ret><nametext>enif_release_binary(ErlNifEnv* env, ErlNifBinary* bin)</nametext></name> <fsummary>Release a binary.</fsummary> - <desc><p>Release a binary obtained from <c>enif_alloc_binary</c> or <c>enif_inspect_binary</c>.</p></desc> + <desc><p>Release a binary obtained + from <c>enif_alloc_binary</c>.</p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_release_resource(ErlNifEnv* env, void* obj)</nametext></name> + <fsummary>Release a resource object.</fsummary> + <desc><p>Release a resource objects obtained from <c>enif_alloc_resource</c>. + The object may still be alive if it is referred to by Erlang terms. Each call to + <c>enif_release_resource</c> must correspond to a previous call to <c>enif_alloc_resource</c>. + References made by <c>enif_make_resource</c> can only be released by the garbage collector.</p></desc> + </func> + <func><name><ret>ErlNifRWLock*</ret><nametext>enif_rwlock_create(char *name)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_create">erl_drv_rwlock_create()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_rwlock_destroy(ErlNifRWLock *rwlck)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_destroy">erl_drv_rwlock_destroy()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_rwlock_rlock(ErlNifRWLock *rwlck)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_rlock">erl_drv_rwlock_rlock()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_rwlock_runlock(ErlNifRWLock *rwlck)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_runlock">erl_drv_rwlock_runlock()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_rwlock_rwlock(ErlNifRWLock *rwlck)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_rwlock">erl_drv_rwlock_rwlock()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_rwlock_rwunlock(ErlNifRWLock *rwlck)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_rwunlock">erl_drv_rwlock_rwunlock()</seealso>. + </p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_rwlock_tryrlock(ErlNifRWLock *rwlck)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_tryrlock">erl_drv_rwlock_tryrlock()</seealso>. + </p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_rwlock_tryrwlock(ErlNifRWLock *rwlck)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_tryrwlock">erl_drv_rwlock_tryrwlock()</seealso>. + </p></desc> + </func> + <func><name><ret>unsigned</ret><nametext>enif_sizeof_resource(ErlNifEnv* env, void* obj)</nametext></name> + <fsummary>Get the byte size of a resource object</fsummary> + <desc><p>Get the byte size of a resource object <c>obj</c> obtained by + <c>enif_alloc_resource</c>.</p></desc> + </func> + <func> + <name><ret>void</ret><nametext>enif_system_info(ErlNifSysInfo *sys_info_ptr, size_t size)</nametext></name> + <fsummary>Get information about the Erlang runtime system</fsummary> + <desc><p>Same as <seealso marker="erl_driver#driver_system_info">driver_system_info()</seealso>. + </p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_thread_create(char *name,ErlNifTid *tid,void * (*func)(void *),void *args,ErlNifThreadOpts *opts)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_create">erl_drv_thread_create()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_thread_exit(void *resp)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_exit">erl_drv_thread_exit()</seealso>. + </p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_thread_join(ErlNifTid, void **respp)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_join">erl_drv_thread_join ()</seealso>. + </p></desc> + </func> + <func><name><ret>ErlNifThreadOpts*</ret><nametext>enif_thread_opts_create(char *name)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_opts_create">erl_drv_thread_opts_create()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_thread_opts_destroy(ErlNifThreadOpts *opts)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_opts_destroy">erl_drv_thread_opts_destroy()</seealso>. + </p></desc> + </func> + <func><name><ret>ErlNifTid</ret><nametext>enif_thread_self(void)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_self">erl_drv_thread_self()</seealso>. + </p></desc> + </func> + <func><name><ret>int</ret><nametext>enif_tsd_key_create(char *name, ErlNifTSDKey *key)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_key_create">erl_drv_tsd_key_create()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_tsd_key_destroy(ErlNifTSDKey key)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_key_destroy">erl_drv_tsd_key_destroy()</seealso>. + </p></desc> + </func> + <func><name><ret>void*</ret><nametext>enif_tsd_get(ErlNifTSDKey key)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_get">erl_drv_tsd_get()</seealso>. + </p></desc> + </func> + <func><name><ret>void</ret><nametext>enif_tsd_set(ErlNifTSDKey key, void *data)</nametext></name> + <fsummary></fsummary> + <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_set">erl_drv_tsd_set()</seealso>. + </p></desc> </func> </funcs> <section> diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index 207aabca35..8e2c02e0ce 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -774,10 +774,10 @@ false</pre> erlang:demonitor(MonitorRef), receive -\011{_, MonitorRef, _, _, _} -> -\011 true + {_, MonitorRef, _, _, _} -> + true after 0 -> -\011 true + true end</code> </item> <tag><c>info</c></tag> @@ -2325,13 +2325,13 @@ os_prompt%</pre> other. Values beginning with an uppercase letter is not part of the result.</p> <code type="none"> -\011total = processes + system -\011processes = processes_used + ProcessesNotUsed -\011system = atom + binary + code + ets + OtherSystem -\011atom = atom_used + AtomNotUsed + total = processes + system + processes = processes_used + ProcessesNotUsed + system = atom + binary + code + ets + OtherSystem + atom = atom_used + AtomNotUsed -\011RealTotal = processes + RealSystem -\011RealSystem = system + MissedSystem</code> + RealTotal = processes + RealSystem + RealSystem = system + MissedSystem</code> <p>More tuples in the returned list may be added in the future.</p> <note> <p>The <c>total</c> value is supposed to be the total amount @@ -6965,10 +6965,10 @@ true</pre> unlink(Id), receive -\011{'EXIT', Id, _} -> -\011 true + {'EXIT', Id, _} -> + true after 0 -> -\011 true + true end</code> <note> <p>Prior to OTP release R11B (erts version 5.5) <c>unlink/1</c> diff --git a/erts/doc/src/erlsrv.xml b/erts/doc/src/erlsrv.xml index 93db56fc7c..0dfad2a112 100644 --- a/erts/doc/src/erlsrv.xml +++ b/erts/doc/src/erlsrv.xml @@ -4,7 +4,7 @@ <comref> <header> <copyright> - <year>1998</year><year>2009</year> + <year>1998</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>erlsrv</title> @@ -251,7 +251,7 @@ necessarily the same as the interactive users. The service runs as the local administrator. All arguments should be given together in one string, use double quotes (") to give an - argument string containing spaces and use quoted quotes (\\") + argument string containing spaces and use quoted quotes (\") to give an quote within the argument string if necessary.</item> <tag>-i[nternalservicename] [<internal name>]</tag> @@ -356,7 +356,7 @@ The environment of an Erlang machine started */ BOOL WINAPI service_aware_handler(DWORD ctrl){ if(ctrl == CTRL_LOGOFF_EVENT) -\011return TRUE; + return TRUE; return FALSE; } @@ -368,10 +368,10 @@ void initialize_handler(void){ */ if(GetEnvironmentVariable("ERLSRV_SERVICE_NAME",buffer, (DWORD) 2)){ -\011/* -\011** Actually set the control handler -\011*/ -\011SetConsoleCtrlHandler(&service_aware_handler, TRUE); + /* + ** Actually set the control handler + */ + SetConsoleCtrlHandler(&service_aware_handler, TRUE); } } ]]></code> </section> @@ -388,8 +388,8 @@ void initialize_handler(void){ the runtime system should not need to overwrite existing (and probably used) executables.</p> <p>To easily manipulate the Erlang services, put - the <c><![CDATA[<erlang_root>\\erts-<version>\\bin]]></c> directory in - the path instead of <c><![CDATA[<erlang_root>\\bin]]></c>. The erlsrv program + the <c><![CDATA[<erlang_root>\erts-<version>\bin]]></c> directory in + the path instead of <c><![CDATA[<erlang_root>\bin]]></c>. The erlsrv program can be found from inside Erlang by using the <c><![CDATA[os:find_executable/1]]></c> Erlang function.</p> <p>For release handling to work, use <c><![CDATA[start_erl]]></c> as the Erlang diff --git a/erts/doc/src/escript.xml b/erts/doc/src/escript.xml index 8df179b3e2..a89449df23 100644 --- a/erts/doc/src/escript.xml +++ b/erts/doc/src/escript.xml @@ -4,7 +4,7 @@ <comref> <header> <copyright> - <year>2007</year><year>2009</year> + <year>2007</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>escript</title> @@ -50,20 +50,18 @@ $ <input>cat factorial</input> %%! -smp enable -sname factorial -mnesia debug verbose main([String]) -> try -\011N = list_to_integer(String), -\011F = fac(N), -\011io:format("factorial ~w = ~w\ -", [N,F]) + N = list_to_integer(String), + F = fac(N), + io:format("factorial ~w = ~w\n", [N,F]) catch -\011_:_ -> -\011 usage() + _:_ -> + usage() end; main(_) -> usage(). usage() -> - io:format("usage: factorial integer\ -"), + io:format("usage: factorial integer\n"), halt(1). fac(0) -> 1; diff --git a/erts/doc/src/inet_cfg.xml b/erts/doc/src/inet_cfg.xml index 18cf65759a..2a033c037c 100644 --- a/erts/doc/src/inet_cfg.xml +++ b/erts/doc/src/inet_cfg.xml @@ -4,7 +4,7 @@ <chapter> <header> <copyright> - <year>2004</year><year>2009</year> + <year>2004</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>Inet configuration</title> @@ -230,6 +230,13 @@ (use the Erlang DNS client <seealso marker="kernel:inet_res">inet_res</seealso> for nameserver queries).</p> + <p>The lookup method <c><![CDATA[string]]></c> tries to + parse the hostname as a IPv4 or IPv6 string and return + the resulting IP address. It is automatically tried + first when <c><![CDATA[native]]></c> is <em>not</em> + in the <c><![CDATA[Methods]]></c> list. To skip it in this case + the pseudo lookup method <c><![CDATA[nostring]]></c> can be + inserted anywhere in the <c><![CDATA[Methods]]></c> list.</p> <p></p> </item> <tag><em><c><![CDATA[{cache_size, Size}.]]></c></em></tag> diff --git a/erts/doc/src/match_spec.xml b/erts/doc/src/match_spec.xml index 26480473d2..b9f955e4db 100644 --- a/erts/doc/src/match_spec.xml +++ b/erts/doc/src/match_spec.xml @@ -4,7 +4,7 @@ <chapter> <header> <copyright> - <year>1999</year><year>2009</year> + <year>1999</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>Match specifications in Erlang</title> @@ -360,52 +360,52 @@ </p> <table> <row> - <cell align="left" valign="middle">Expression\011\011</cell> - <cell align="left" valign="middle">Variable bindings\011\011</cell> - <cell align="left" valign="middle">Result\011</cell> + <cell align="left" valign="middle">Expression </cell> + <cell align="left" valign="middle">Variable bindings </cell> + <cell align="left" valign="middle">Result </cell> </row> <row> - <cell align="left" valign="middle">{{'$1','$2'}}\011\011</cell> + <cell align="left" valign="middle">{{'$1','$2'}} </cell> <cell align="left" valign="middle">'$1' = a, '$2' = b</cell> <cell align="left" valign="middle">{a,b}</cell> </row> <row> - <cell align="left" valign="middle">{const, {'$1', '$2'}}\011</cell> + <cell align="left" valign="middle">{const, {'$1', '$2'}} </cell> <cell align="left" valign="middle">doesn't matter</cell> <cell align="left" valign="middle">{'$1', '$2'}</cell> </row> <row> - <cell align="left" valign="middle">a\011\011\011</cell> - <cell align="left" valign="middle">doesn't matter\011\011\011</cell> + <cell align="left" valign="middle">a </cell> + <cell align="left" valign="middle">doesn't matter </cell> <cell align="left" valign="middle">a</cell> </row> <row> - <cell align="left" valign="middle">'$1'\011\011\011</cell> - <cell align="left" valign="middle">'$1' = []\011\011\011</cell> + <cell align="left" valign="middle">'$1' </cell> + <cell align="left" valign="middle">'$1' = [] </cell> <cell align="left" valign="middle">[]</cell> </row> <row> - <cell align="left" valign="middle">['$1']\011\011\011</cell> - <cell align="left" valign="middle">'$1' = []\011\011\011</cell> + <cell align="left" valign="middle">['$1'] </cell> + <cell align="left" valign="middle">'$1' = [] </cell> <cell align="left" valign="middle">[[]]</cell> </row> <row> - <cell align="left" valign="middle">[{{a}}]\011\011\011</cell> + <cell align="left" valign="middle">[{{a}}] </cell> <cell align="left" valign="middle">doesn't matter</cell> <cell align="left" valign="middle">[{a}]</cell> </row> <row> - <cell align="left" valign="middle">42\011\011\011</cell> + <cell align="left" valign="middle">42 </cell> <cell align="left" valign="middle">doesn't matter</cell> <cell align="left" valign="middle">42</cell> </row> <row> - <cell align="left" valign="middle">"hello"\011\011\011</cell> + <cell align="left" valign="middle">"hello" </cell> <cell align="left" valign="middle">doesn't matter</cell> <cell align="left" valign="middle">"hello"</cell> </row> <row> - <cell align="left" valign="middle">$1\011\011\011</cell> + <cell align="left" valign="middle">$1 </cell> <cell align="left" valign="middle">doesn't matter</cell> <cell align="left" valign="middle">49 (the ASCII value for the character '1')</cell> </row> @@ -507,8 +507,8 @@ a list which in turn begins with the second argument times two (i. e. [{[4,x],y},2] or [{[8], y, z},4])</p> <code type="none"><![CDATA[ -[{['$1', '$2'],\011[{'=:=', {'*', 2, '$2'}, {hd, {element, 1, '$1'}}}], - []}]\011 +[{['$1', '$2'],[{'=:=', {'*', 2, '$2'}, {hd, {element, 1, '$1'}}}], + []}] ]]></code> <p>Match three arguments. When all three are equal and are numbers, append the process dump to the trace message, else diff --git a/erts/doc/src/notes.xml b/erts/doc/src/notes.xml index 5fe414841e..70f2d95103 100644 --- a/erts/doc/src/notes.xml +++ b/erts/doc/src/notes.xml @@ -4371,16 +4371,16 @@ following code might hang:</p> <code type="none"><![CDATA[ Mon = erlang:monitor(process, Pid), -\011 %% ... -\011 exit(Pid, bang), + %% ... + exit(Pid, bang), erlang:demonitor(Mon), -\011 receive -\011 {'DOWN', Mon , process, Pid, _} -> ok -\011 %% We were previously guaranteed to get a down message -\011 %% (since we exited the process ourself), so we could -\011 %% in this case leave out: -\011 %% after 0 -> ok -\011 end, + receive + {'DOWN', Mon , process, Pid, _} -> ok + %% We were previously guaranteed to get a down message + %% (since we exited the process ourself), so we could + %% in this case leave out: + %% after 0 -> ok + end, ]]></code> <p>*** POTENTIAL INCOMPATIBILITY ***</p> <p>Own Id: OTP-5772</p> @@ -5342,7 +5342,7 @@ <list type="bulleted"> <item> <p>If Erlang/OTP was installed in a short directory name, - such as <c><![CDATA[C:\\Program\\erl5.4.2]]></c>, the emulator would not + such as <c><![CDATA[C:\Program\erl5.4.2]]></c>, the emulator would not start.</p> <p>Own Id: OTP-5254</p> </item> diff --git a/erts/doc/src/tty.xml b/erts/doc/src/tty.xml index 23694e5965..7d662a2849 100644 --- a/erts/doc/src/tty.xml +++ b/erts/doc/src/tty.xml @@ -4,7 +4,7 @@ <chapter> <header> <copyright> - <year>1996</year><year>2009</year> + <year>1996</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>tty - A command line interface</title> @@ -47,7 +47,7 @@ <section> <title>Normal Mode</title> <p>In normal mode keystrokes from the user are collected and interpreted by <c><![CDATA[tty]]></c>. Most of the <em>emacs</em> line editing commands are supported. The following is a complete list of the supported line editing commands.<br></br></p> - <p><em>Note:</em>\011The notation <c><![CDATA[C-a]]></c> means pressing the control key and the letter <c><![CDATA[a]]></c> simultaneously. <c><![CDATA[M-f]]></c> means pressing the <c><![CDATA[ESC]]></c> key followed by the letter <c><![CDATA[f]]></c>. + <p><em>Note:</em> The notation <c><![CDATA[C-a]]></c> means pressing the control key and the letter <c><![CDATA[a]]></c> simultaneously. <c><![CDATA[M-f]]></c> means pressing the <c><![CDATA[ESC]]></c> key followed by the letter <c><![CDATA[f]]></c>. </p> <table> <row> diff --git a/erts/doc/src/zlib.xml b/erts/doc/src/zlib.xml index 9f39ac657a..b1e768bce9 100644 --- a/erts/doc/src/zlib.xml +++ b/erts/doc/src/zlib.xml @@ -4,7 +4,7 @@ <erlref> <header> <copyright> - <year>2005</year><year>2009</year> + <year>2005</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>zlib</title> @@ -372,11 +372,11 @@ list_to_binary([B1,B2])</pre> <pre> unpack(Z, Compressed, Dict) -> case catch zlib:inflate(Z, Compressed) of -\011 {'EXIT',{{need_dictionary,DictID},_}} -> - \011 zlib:inflateSetDictionary(Z, Dict), -\011 Uncompressed = zlib:inflate(Z, []); -\011 Uncompressed -> -\011 Uncompressed + {'EXIT',{{need_dictionary,DictID},_}} -> + zlib:inflateSetDictionary(Z, Dict), + Uncompressed = zlib:inflate(Z, []); + Uncompressed -> + Uncompressed end.</pre> </desc> </func> @@ -466,8 +466,8 @@ unpack(Z, Compressed, Dict) -> the required initial value for the crc.</p> <pre> Crc = lists:foldl(fun(Bin,Crc0) -> -\011 zlib:crc32(Z, Crc0, Bin), -\011 end, zlib:crc32(Z,<< >>), Bins)</pre> + zlib:crc32(Z, Crc0, Bin), + end, zlib:crc32(Z,<< >>), Bins)</pre> </desc> </func> <func> @@ -517,8 +517,8 @@ Crc = lists:foldl(fun(Bin,Crc0) -> the required initial value for the checksum.</p> <pre> Crc = lists:foldl(fun(Bin,Crc0) -> -\011 zlib:adler32(Z, Crc0, Bin), -\011 end, zlib:adler32(Z,<< >>), Bins)</pre> + zlib:adler32(Z, Crc0, Bin), + end, zlib:adler32(Z,<< >>), Bins)</pre> </desc> </func> <func> diff --git a/erts/emulator/Makefile.in b/erts/emulator/Makefile.in index 2fe12be43e..a81ab28847 100644 --- a/erts/emulator/Makefile.in +++ b/erts/emulator/Makefile.in @@ -419,7 +419,7 @@ include $(ERL_TOP)/make/otp_release_targets.mk RELSYSDIR = $(RELEASE_PATH)/erts-$(VSN) -RELEASE_INCLUDES = beam/erl_driver.h sys/$(ERLANG_OSTYPE)/driver_int.h beam/erl_nif.h beam/erl_nif_api_funcs.h +RELEASE_INCLUDES = beam/erl_driver.h sys/$(ERLANG_OSTYPE)/driver_int.h beam/erl_nif.h beam/erl_nif_api_funcs.h beam/erl_drv_nif.h ifeq ($(TARGET),win32) RELEASE_INCLUDES += sys/$(ERLANG_OSTYPE)/erl_win_dyn_driver.h endif diff --git a/erts/emulator/beam/beam_bif_load.c b/erts/emulator/beam/beam_bif_load.c index d3a1ed4e7d..b1feec7074 100644 --- a/erts/emulator/beam/beam_bif_load.c +++ b/erts/emulator/beam/beam_bif_load.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1999-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1999-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -642,21 +642,9 @@ purge_module(int module) /* * Unload any NIF library */ - if (modp->old_nif.handle != NULL) { - if (modp->old_nif.entry->unload != NULL) { - ErlNifEnv env; - env.nif_data = modp->old_nif.data; - env.proc = NULL; /* BUGBUG: unlink can not access calling process */ - env.hp = NULL; - env.hp_end = NULL; - env.heap_frag_sz = 0; - env.fpe_was_unmasked = erts_block_fpe(); - modp->old_nif.entry->unload(NULL, modp->old_nif.data); - erts_unblock_fpe(env.fpe_was_unmasked); - } - erts_sys_ddll_close(modp->old_nif.handle); - modp->old_nif.handle = NULL; - modp->old_nif.entry = NULL; + if (modp->old_nif != NULL) { + erts_unload_nif(modp->old_nif); + modp->old_nif = NULL; } /* @@ -732,8 +720,7 @@ delete_code(Process *c_p, ErtsProcLocks c_p_locks, Module* modp) modp->code = NULL; modp->code_length = 0; modp->catches = BEAM_CATCHES_NIL; - modp->nif.handle = NULL; - modp->nif.entry = NULL; + modp->nif = NULL; } diff --git a/erts/emulator/beam/beam_emu.c b/erts/emulator/beam/beam_emu.c index 13757b7d1c..2f7f48193d 100644 --- a/erts/emulator/beam/beam_emu.c +++ b/erts/emulator/beam/beam_emu.c @@ -2973,7 +2973,7 @@ void process_main(void) * I[-1]: Arity * I[0]: &&call_nif * I[1]: Function pointer to NIF function - * I[2]: priv_data pointer + * I[2]: Pointer to erl_module_nif */ BifFunction vbf; @@ -2989,7 +2989,7 @@ void process_main(void) typedef Eterm NifF(struct enif_environment_t*, int argc, Eterm argv[]); NifF* fp = vbf = (NifF*) I[1]; struct enif_environment_t env; - erts_pre_nif(&env, c_p, (void*)I[2]); + erts_pre_nif(&env, c_p, (struct erl_module_nif*)I[2]); reg[0] = r(0); tmp_arg1 = (*fp)(&env, tmp_arg2, reg); erts_post_nif(&env); diff --git a/erts/emulator/beam/binary.c b/erts/emulator/beam/binary.c index 49bc0d6457..08c64610a2 100644 --- a/erts/emulator/beam/binary.c +++ b/erts/emulator/beam/binary.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1996-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -180,7 +180,7 @@ erts_realloc_binary(Eterm bin, size_t size) } byte* -erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr) +erts_get_aligned_binary_bytes_extra(Eterm bin, byte** base_ptr, unsigned extra) { byte* bytes; Eterm* real_bin; @@ -208,10 +208,10 @@ erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr) bytes = (byte *)(&(((ErlHeapBin *) real_bin)->data)) + offs; } if (bit_offs) { - byte* buf = (byte *) erts_alloc(ERTS_ALC_T_TMP, byte_size); - - erts_copy_bits(bytes, bit_offs, 1, buf, 0, 1, byte_size*8); + byte* buf = (byte *) erts_alloc(ERTS_ALC_T_TMP, byte_size + extra); *base_ptr = buf; + buf += extra; + erts_copy_bits(bytes, bit_offs, 1, buf, 0, 1, byte_size*8); bytes = buf; } return bytes; diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c index 5ff1f794df..a34d400ed8 100644 --- a/erts/emulator/beam/erl_bif_info.c +++ b/erts/emulator/beam/erl_bif_info.c @@ -3704,12 +3704,11 @@ static Eterm lcnt_build_lock_term(Eterm **hpp, Uint *szp, erts_lcnt_lock_t *lock ASSERT(ltype); type = am_atom_put(ltype, strlen(ltype)); - name = am_atom_put(lock->name, strlen(lock->name)); if (lock->flag & ERTS_LCNT_LT_ALLOC) { /* use allocator types names as id's for allocator locks */ - ltype = ERTS_ALC_A2AD(signed_val(lock->id)); + ltype = (char *) ERTS_ALC_A2AD(signed_val(lock->id)); id = am_atom_put(ltype, strlen(ltype)); } else if (lock->flag & ERTS_LCNT_LT_PROCLOCK) { /* use registered names as id's for process locks if available */ @@ -3778,17 +3777,28 @@ BIF_RETTYPE erts_debug_lock_counters_1(BIF_ALIST_1) { #ifdef ERTS_ENABLE_LOCK_COUNT Eterm res = NIL; - erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); - erts_smp_block_system(0); +#endif + + + if (BIF_ARG_1 == am_enabled) { +#ifdef ERTS_ENABLE_LOCK_COUNT + BIF_RET(am_true); +#else + BIF_RET(am_false); +#endif + } +#ifdef ERTS_ENABLE_LOCK_COUNT - if (BIF_ARG_1 == am_info) { + else if (BIF_ARG_1 == am_info) { erts_lcnt_data_t *data; Uint hsize = 0; Uint *szp; Eterm* hp; - erts_lcnt_set_rt_opt(ERTS_LCNT_OPT_SUSPEND); + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erts_smp_block_system(0); + erts_lcnt_set_rt_opt(ERTS_LCNT_OPT_SUSPEND); data = erts_lcnt_get_data(); /* calculate size */ @@ -3803,29 +3813,65 @@ BIF_RETTYPE erts_debug_lock_counters_1(BIF_ALIST_1) res = lcnt_build_result_term(&hp, NULL, data, res); erts_lcnt_clear_rt_opt(ERTS_LCNT_OPT_SUSPEND); + + erts_smp_release_system(); + erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); - goto done; + BIF_RET(res); } else if (BIF_ARG_1 == am_clear) { + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erts_smp_block_system(0); + erts_lcnt_clear_counters(); - res = am_ok; - goto done; + + erts_smp_release_system(); + erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); + + BIF_RET(am_ok); } else if (is_tuple(BIF_ARG_1)) { - Uint prev = 0; Eterm* tp = tuple_val(BIF_ARG_1); + switch (arityval(tp[0])) { case 2: - if (ERTS_IS_ATOM_STR("process_locks", tp[1])) { + if (ERTS_IS_ATOM_STR("copy_save", tp[1])) { + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erts_smp_block_system(0); if (tp[2] == am_true) { - prev = erts_lcnt_set_rt_opt(ERTS_LCNT_OPT_PROCLOCK); - if (prev) res = am_true; - else res = am_false; - goto done; + + res = erts_lcnt_set_rt_opt(ERTS_LCNT_OPT_COPYSAVE) ? am_true : am_false; + } else if (tp[2] == am_false) { - prev = erts_lcnt_clear_rt_opt(ERTS_LCNT_OPT_PROCLOCK); - if (prev) res = am_true; - else res = am_false; - goto done; + + res = erts_lcnt_clear_rt_opt(ERTS_LCNT_OPT_COPYSAVE) ? am_true : am_false; + + } else { + erts_smp_release_system(); + erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); + BIF_ERROR(BIF_P, BADARG); } + erts_smp_release_system(); + erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); + BIF_RET(res); + + } else if (ERTS_IS_ATOM_STR("process_locks", tp[1])) { + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erts_smp_block_system(0); + if (tp[2] == am_true) { + + res = erts_lcnt_set_rt_opt(ERTS_LCNT_OPT_PROCLOCK) ? am_true : am_false; + + } else if (tp[2] == am_false) { + + res = erts_lcnt_set_rt_opt(ERTS_LCNT_OPT_PROCLOCK) ? am_true : am_false; + + } else { + erts_smp_release_system(); + erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); + BIF_ERROR(BIF_P, BADARG); + } + erts_smp_release_system(); + erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); + BIF_RET(res); } break; @@ -3834,16 +3880,8 @@ BIF_RETTYPE erts_debug_lock_counters_1(BIF_ALIST_1) } } - erts_smp_release_system(); - erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); #endif BIF_ERROR(BIF_P, BADARG); -#ifdef ERTS_ENABLE_LOCK_COUNT -done: - erts_smp_release_system(); - erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); - BIF_RET(res); -#endif } void diff --git a/erts/emulator/beam/erl_binary.h b/erts/emulator/beam/erl_binary.h index f8ecdde997..21d4e3fdfd 100644 --- a/erts/emulator/beam/erl_binary.h +++ b/erts/emulator/beam/erl_binary.h @@ -150,7 +150,7 @@ do { \ void erts_init_binary(void); -byte* erts_get_aligned_binary_bytes(Eterm, byte**); +byte* erts_get_aligned_binary_bytes_extra(Eterm, byte**, unsigned extra); #if defined(__i386__) || !defined(__GNUC__) /* @@ -166,6 +166,7 @@ byte* erts_get_aligned_binary_bytes(Eterm, byte**); #define ERTS_CHK_BIN_ALIGNMENT(B) \ do { ASSERT(!(B) || (((Uint) &((Binary *)(B))->orig_bytes[0]) & ERTS_BIN_ALIGNMENT_MASK) == ((Uint) 0)) } while(0) +ERTS_GLB_INLINE byte* erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr); ERTS_GLB_INLINE void erts_free_aligned_binary_bytes(byte* buf); ERTS_GLB_INLINE Binary *erts_bin_drv_alloc_fnf(Uint size); ERTS_GLB_INLINE Binary *erts_bin_drv_alloc(Uint size); @@ -178,6 +179,14 @@ ERTS_GLB_INLINE Binary *erts_create_magic_binary(Uint size, #if ERTS_GLB_INLINE_INCL_FUNC_DEF +#include <stddef.h> /* offsetof */ + +ERTS_GLB_INLINE byte* +erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr) +{ + return erts_get_aligned_binary_bytes_extra(bin, base_ptr, 0); +} + ERTS_GLB_INLINE void erts_free_aligned_binary_bytes(byte* buf) { @@ -189,7 +198,7 @@ erts_free_aligned_binary_bytes(byte* buf) ERTS_GLB_INLINE Binary * erts_bin_drv_alloc_fnf(Uint size) { - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); void *res; res = erts_alloc_fnf(ERTS_ALC_T_DRV_BINARY, bsize); ERTS_CHK_BIN_ALIGNMENT(res); @@ -199,7 +208,7 @@ erts_bin_drv_alloc_fnf(Uint size) ERTS_GLB_INLINE Binary * erts_bin_drv_alloc(Uint size) { - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); void *res; res = erts_alloc(ERTS_ALC_T_DRV_BINARY, bsize); ERTS_CHK_BIN_ALIGNMENT(res); @@ -210,7 +219,7 @@ erts_bin_drv_alloc(Uint size) ERTS_GLB_INLINE Binary * erts_bin_nrml_alloc(Uint size) { - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); void *res; res = erts_alloc(ERTS_ALC_T_BINARY, bsize); ERTS_CHK_BIN_ALIGNMENT(res); @@ -221,7 +230,7 @@ ERTS_GLB_INLINE Binary * erts_bin_realloc_fnf(Binary *bp, Uint size) { Binary *nbp; - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); ASSERT((bp->flags & BIN_FLAG_MAGIC) == 0); if (bp->flags & BIN_FLAG_DRV) nbp = erts_realloc_fnf(ERTS_ALC_T_DRV_BINARY, (void *) bp, bsize); @@ -235,7 +244,7 @@ ERTS_GLB_INLINE Binary * erts_bin_realloc(Binary *bp, Uint size) { Binary *nbp; - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); ASSERT((bp->flags & BIN_FLAG_MAGIC) == 0); if (bp->flags & BIN_FLAG_DRV) nbp = erts_realloc_fnf(ERTS_ALC_T_DRV_BINARY, (void *) bp, bsize); diff --git a/erts/emulator/beam/erl_db.c b/erts/emulator/beam/erl_db.c index b02150008f..15b1c6bb56 100644 --- a/erts/emulator/beam/erl_db.c +++ b/erts/emulator/beam/erl_db.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1996-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -261,13 +261,8 @@ static ERTS_INLINE void db_init_lock(DbTable* tb, char *rwname, char* fixname) erts_refc_init(&tb->common.ref, 1); erts_refc_init(&tb->common.fixref, 0); #ifdef ERTS_SMP -# ifdef ERTS_ENABLE_LOCK_COUNT erts_smp_rwmtx_init_x(&tb->common.rwlock, rwname, tb->common.the_name); erts_smp_mtx_init_x(&tb->common.fixlock, fixname, tb->common.the_name); -# else - erts_smp_rwmtx_init(&tb->common.rwlock, rwname); - erts_smp_mtx_init(&tb->common.fixlock, fixname); -# endif tb->common.is_thread_safe = !(tb->common.status & DB_FINE_LOCKED); #endif } @@ -2597,19 +2592,11 @@ void init_db(void) #ifdef ERTS_SMP for (i=0; i<META_MAIN_TAB_LOCK_CNT; i++) { -#ifdef ERTS_ENABLE_LOCK_COUNT erts_smp_spinlock_init_x(&meta_main_tab_locks[i].lck, "meta_main_tab_slot", make_small(i)); -#else - erts_smp_spinlock_init(&meta_main_tab_locks[i].lck, "meta_main_tab_slot"); -#endif } erts_smp_spinlock_init(&meta_main_tab_main_lock, "meta_main_tab_main"); for (i=0; i<META_NAME_TAB_LOCK_CNT; i++) { -#ifdef ERTS_ENABLE_LOCK_COUNT erts_smp_rwmtx_init_x(&meta_name_tab_rwlocks[i].lck, "meta_name_tab", make_small(i)); -#else - erts_smp_rwmtx_init(&meta_name_tab_rwlocks[i].lck, "meta_name_tab"); -#endif } #endif diff --git a/erts/emulator/beam/erl_db_hash.c b/erts/emulator/beam/erl_db_hash.c index dea45053df..4141f9766b 100644 --- a/erts/emulator/beam/erl_db_hash.c +++ b/erts/emulator/beam/erl_db_hash.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1998-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -628,11 +628,7 @@ int db_create_hash(Process *p, DbTable *tbl) (DbTable *) tb, sizeof(DbTableHashFineLocks)); for (i=0; i<DB_HASH_LOCK_CNT; ++i) { - #ifdef ERTS_ENABLE_LOCK_COUNT - erts_rwmtx_init_x(&tb->locks->lck_vec[i].lck, "db_hash_slot", tb->common.the_name); - #else - erts_rwmtx_init(&tb->locks->lck_vec[i].lck, "db_hash_slot"); - #endif + erts_rwmtx_init_x(&tb->locks->lck_vec[i].lck, "db_hash_slot", make_small(i)); } /* This important property is needed to guarantee that the buckets * involved in a grow/shrink operation it protected by the same lock: diff --git a/erts/emulator/beam/erl_driver.h b/erts/emulator/beam/erl_driver.h index cdb584b282..489e74d960 100644 --- a/erts/emulator/beam/erl_driver.h +++ b/erts/emulator/beam/erl_driver.h @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1999-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1999-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -65,6 +65,8 @@ # error SIZEOF_LONG_LONG mismatch #endif +#include "erl_drv_nif.h" + #include <stdlib.h> #if defined(VXWORKS) @@ -116,7 +118,7 @@ typedef struct { #define ERL_DRV_EXTENDED_MARKER (0xfeeeeeed) #define ERL_DRV_EXTENDED_MAJOR_VERSION 1 -#define ERL_DRV_EXTENDED_MINOR_VERSION 4 +#define ERL_DRV_EXTENDED_MINOR_VERSION 5 /* * The emulator will refuse to load a driver with different major @@ -195,22 +197,6 @@ typedef struct { unsigned char data[sizeof(void *)*4]; } ErlDrvMonitor; - -/* - * System info - */ - -typedef struct { - int driver_major_version; - int driver_minor_version; - char *erts_version; - char *otp_release; - int thread_support; - int smp_support; - int async_threads; - int scheduler_threads; -} ErlDrvSysInfo; - typedef struct { unsigned long megasecs; unsigned long secs; @@ -255,9 +241,6 @@ typedef struct ErlDrvCond_ ErlDrvCond; typedef struct ErlDrvRWLock_ ErlDrvRWLock; typedef int ErlDrvTSDKey; -typedef struct { - int suggested_stack_size; -} ErlDrvThreadOpts; /* * diff --git a/erts/emulator/beam/erl_drv_nif.h b/erts/emulator/beam/erl_drv_nif.h new file mode 100644 index 0000000000..ea013a49a3 --- /dev/null +++ b/erts/emulator/beam/erl_drv_nif.h @@ -0,0 +1,48 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2010. All Rights Reserved. + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * %CopyrightEnd% + */ + +/* + * Common structures for both erl_driver.h and erl_nif.h + */ + +#ifndef __ERL_DRV_NIF_H__ +#define __ERL_DRV_NIF_H__ + +typedef struct { + int driver_major_version; + int driver_minor_version; + char *erts_version; + char *otp_release; + int thread_support; + int smp_support; + int async_threads; + int scheduler_threads; + int nif_major_version; + int nif_minor_version; +} ErlDrvSysInfo; + +typedef struct { + int suggested_stack_size; +} ErlDrvThreadOpts; + +#endif /* __ERL_DRV_NIF_H__ */ + + + + diff --git a/erts/emulator/beam/erl_init.c b/erts/emulator/beam/erl_init.c index 17cf3b9597..e97ab328cd 100644 --- a/erts/emulator/beam/erl_init.c +++ b/erts/emulator/beam/erl_init.c @@ -296,6 +296,7 @@ erl_init(void) erl_sys_init_final(); #endif packet_parser_init(); + erl_nif_init(); } static void diff --git a/erts/emulator/beam/erl_lock_count.c b/erts/emulator/beam/erl_lock_count.c index 6211983f4b..0d7e1335c1 100644 --- a/erts/emulator/beam/erl_lock_count.c +++ b/erts/emulator/beam/erl_lock_count.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 2008-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 2008-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -162,7 +162,6 @@ static void print_lock_x(erts_lcnt_lock_t *lock, Uint16 flag, char *action, char long int colls, tries, w_state, r_state; erts_lcnt_lock_stats_t *stats = NULL; - float rate; char *type; int i; @@ -170,8 +169,6 @@ static void print_lock_x(erts_lcnt_lock_t *lock, Uint16 flag, char *action, char ethr_atomic_read(&lock->r_state, &r_state); ethr_atomic_read(&lock->w_state, &w_state); - if (tries > 0) rate = (float)(colls/(float)tries)*100; - else rate = 0.0f; if (lock->flag & flag) { erts_printf("%20s [%30s] [r/w state %4ld/%4ld] id %T %s\r\n", @@ -181,26 +178,13 @@ static void print_lock_x(erts_lcnt_lock_t *lock, Uint16 flag, char *action, char w_state, lock->id, extra); - - for(i = 0; i < lock->n_stats; i++) { - stats = &(lock->stats[i]); - ethr_atomic_read(&stats->tries, &tries); - ethr_atomic_read(&stats->colls, &colls); - fprintf(stderr, "%69s:%5d [tries %9ld] [colls %9ld] [timer_n %8ld] [timer %4ld s %6ld us]\r\n", - stats->file, - stats->line, - tries, - colls, - stats->timer_n, - stats->timer.s, - (unsigned long)stats->timer.ns/1000); - } - fprintf(stderr, "\r\n"); } } static void print_lock(erts_lcnt_lock_t *lock, char *action) { - print_lock_x(lock, ERTS_LCNT_LT_ALL, action, ""); + if (strcmp(lock->name, "proc_main") == 0) { + print_lock_x(lock, ERTS_LCNT_LT_ALL, action, ""); + } } #endif @@ -230,8 +214,8 @@ static void lcnt_update_stats(erts_lcnt_lock_stats_t *stats, int lock_in_conflic ethr_atomic_inc(&stats->tries); - /* beware of trylock */ - if (lock_in_conflict) ethr_atomic_inc(&stats->colls); + if (lock_in_conflict) + ethr_atomic_inc(&stats->colls); if (time_wait) { lcnt_time_add(&(stats->timer), time_wait); @@ -366,6 +350,7 @@ void erts_lcnt_init_lock_x(erts_lcnt_lock_t *lock, char *name, Uint16 flag, Eter for (i = 0; i < ERTS_LCNT_MAX_LOCK_LOCATIONS; i++) { lcnt_clear_stats(&lock->stats[i]); } + erts_lcnt_list_insert(erts_lcnt_data->current_locks, lock); lcnt_unlock(); @@ -373,18 +358,20 @@ void erts_lcnt_init_lock_x(erts_lcnt_lock_t *lock, char *name, Uint16 flag, Eter void erts_lcnt_destroy_lock(erts_lcnt_lock_t *lock) { erts_lcnt_lock_t *deleted_lock; - - /* copy structure and insert the copy */ - deleted_lock = (erts_lcnt_lock_t*)malloc(sizeof(erts_lcnt_lock_t)); lcnt_lock(); - memcpy(deleted_lock, lock, sizeof(erts_lcnt_lock_t)); - deleted_lock->next = NULL; - deleted_lock->prev = NULL; + if (erts_lcnt_rt_options & ERTS_LCNT_OPT_COPYSAVE) { + /* copy structure and insert the copy */ - erts_lcnt_list_insert(erts_lcnt_data->deleted_locks, deleted_lock); + deleted_lock = (erts_lcnt_lock_t*)malloc(sizeof(erts_lcnt_lock_t)); + memcpy(deleted_lock, lock, sizeof(erts_lcnt_lock_t)); + deleted_lock->next = NULL; + deleted_lock->prev = NULL; + + erts_lcnt_list_insert(erts_lcnt_data->deleted_locks, deleted_lock); + } /* delete original */ erts_lcnt_list_delete(erts_lcnt_data->current_locks, lock); @@ -416,9 +403,10 @@ void erts_lcnt_lock_opt(erts_lcnt_lock_t *lock, Uint16 option) { /* we cannot acquire w_lock if either w or r are taken */ /* we cannot acquire r_lock if w_lock is taken */ - if ((w_state > 0) || (r_state > 0)){ + if ((w_state > 0) || (r_state > 0)) { eltd->lock_in_conflict = 1; - if (eltd->timer_set == 0) lcnt_time(&eltd->timer); + if (eltd->timer_set == 0) + lcnt_time(&eltd->timer); eltd->timer_set++; } else { eltd->lock_in_conflict = 0; @@ -445,7 +433,8 @@ void erts_lcnt_lock(erts_lcnt_lock_t *lock) { * 'atomicly'. All other locks will block the thread if w_state > 0 * i.e. locked. */ - if (eltd->timer_set == 0) lcnt_time(&eltd->timer); + if (eltd->timer_set == 0) + lcnt_time(&eltd->timer); eltd->timer_set++; } else { @@ -494,24 +483,23 @@ void erts_lcnt_lock_post_x(erts_lcnt_lock_t *lock, char *file, unsigned int line eltd = lcnt_get_thread_data(); ASSERT(eltd); - + /* if lock was in conflict, time it */ stats = lcnt_get_lock_stats(lock, file, line); if (eltd->timer_set) { lcnt_time(&timer); - - eltd->timer_set--; lcnt_time_diff(&time_wait, &timer, &(eltd->timer)); lcnt_update_stats(stats, eltd->lock_in_conflict, &time_wait); + eltd->timer_set--; ASSERT(eltd->timer_set >= 0); } else { lcnt_update_stats(stats, eltd->lock_in_conflict, NULL); } - + } /* unlock */ diff --git a/erts/emulator/beam/erl_lock_count.h b/erts/emulator/beam/erl_lock_count.h index 8564c36203..e3044c371f 100644 --- a/erts/emulator/beam/erl_lock_count.h +++ b/erts/emulator/beam/erl_lock_count.h @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 2008-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 2008-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -39,6 +39,20 @@ * Each instance of a lock is the unique lock, i.e. set and id in that set. * For each lock there is a set of statistics with where and what impact * the lock aqusition had. + * + * Runtime options + * - suspend, used when internal lock-counting can't be applied. For instance + * when allocating a term for the outside and halloc needs to be used. + * Default: off. + * - location, reserved and not used. + * - proclock, disable proclock counting. Used when performance might be an + * issue. Accessible from erts_debug:lock_counters({process_locks, bool()}). + * Default: off. + * - copysave, enable saving of destroyed locks (and thereby its statistics). + * If memory constraints is an issue this need to be disabled. + * Accessible from erts_debug:lock_counters({copy_save, bool()}). + * Default: off. + * */ #include "sys.h" @@ -74,6 +88,7 @@ #define ERTS_LCNT_OPT_SUSPEND (((Uint16) 1) << 0) #define ERTS_LCNT_OPT_LOCATION (((Uint16) 1) << 1) #define ERTS_LCNT_OPT_PROCLOCK (((Uint16) 1) << 2) +#define ERTS_LCNT_OPT_COPYSAVE (((Uint16) 1) << 3) typedef struct { unsigned long s; diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c index 2cb93112ae..585a6c1fdf 100644 --- a/erts/emulator/beam/erl_nif.c +++ b/erts/emulator/beam/erl_nif.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 2009-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ /* Erlang Native InterFace @@ -34,9 +34,26 @@ #include "beam_bp.h" #include <limits.h> +#include <stddef.h> /* offsetof */ + + +/* Information about a loaded nif library. + * Each successful call to erlang:load_nif will allocate an instance of + * erl_module_nif. Two calls opening the same library will thus have the same + * 'handle'. + */ +struct erl_module_nif { + void* priv_data; + void* handle; /* "dlopen" */ + struct enif_entry_t* entry; + erts_refc_t rt_cnt; /* number of resource types */ + erts_refc_t rt_dtor_cnt; /* number of resource types with destructors */ + int is_orphan; /* if erlang module has been purged */ +}; + #define MIN_HEAP_FRAG_SZ 200 -static Eterm* alloc_heap_heavy(ErlNifEnv* env, unsigned need); +static Eterm* alloc_heap_heavy(ErlNifEnv* env, unsigned need, Eterm* hp); static ERTS_INLINE Eterm* alloc_heap(ErlNifEnv* env, unsigned need) { @@ -45,43 +62,88 @@ static ERTS_INLINE Eterm* alloc_heap(ErlNifEnv* env, unsigned need) if (env->hp <= env->hp_end) { return hp; } - env->hp = hp; - return alloc_heap_heavy(env,need); + return alloc_heap_heavy(env, need, hp); } -static Eterm* alloc_heap_heavy(ErlNifEnv* env, unsigned need) -{ - Eterm* hp; - - if (env->heap_frag_sz == 0) { +static Eterm* alloc_heap_heavy(ErlNifEnv* env, unsigned need, Eterm* hp) +{ + unsigned frag_sz; + env->hp = hp; + if (env->heap_frag == NULL) { ASSERT(HEAP_LIMIT(env->proc) == env->hp_end); HEAP_TOP(env->proc) = env->hp; - env->heap_frag_sz = need + MIN_HEAP_FRAG_SZ; } else { HRelease(env->proc, env->hp_end, env->hp); - env->heap_frag_sz *= 2; } - hp = erts_heap_alloc(env->proc, env->heap_frag_sz); + frag_sz = need + MIN_HEAP_FRAG_SZ; + hp = erts_heap_alloc(env->proc, frag_sz); env->hp = hp + need; - env->hp_end = hp + env->heap_frag_sz; + env->hp_end = hp + frag_sz; + env->heap_frag = MBUF(env->proc); return hp; } -void erts_pre_nif(ErlNifEnv* env, Process* p, void* nif_data) +void erts_pre_nif(ErlNifEnv* env, Process* p, struct erl_module_nif* mod_nif) { - env->nif_data = nif_data; + env->mod_nif = mod_nif; env->proc = p; env->hp = HEAP_TOP(p); env->hp_end = HEAP_LIMIT(p); - env->heap_frag_sz = 0; + env->heap_frag = NULL; + env->fpe_was_unmasked = erts_block_fpe(); + env->tmp_obj_list = NULL; +} + +static void pre_nif_noproc(ErlNifEnv* env, struct erl_module_nif* mod_nif) +{ + env->mod_nif = mod_nif; + env->proc = NULL; + env->hp = NULL; + env->hp_end = NULL; + env->heap_frag = NULL; env->fpe_was_unmasked = erts_block_fpe(); + env->tmp_obj_list = NULL; +} + +static ERTS_INLINE void free_tmp_objs(ErlNifEnv* env) +{ + while (env->tmp_obj_list != NULL) { + struct enif_tmp_obj_t* free_me = env->tmp_obj_list; + env->tmp_obj_list = free_me->next; + free_me->dtor(free_me); + } } void erts_post_nif(ErlNifEnv* env) { erts_unblock_fpe(env->fpe_was_unmasked); - if (env->heap_frag_sz == 0) { + if (env->heap_frag == NULL) { + ASSERT(env->hp_end == HEAP_LIMIT(env->proc)); + ASSERT(env->hp >= HEAP_TOP(env->proc)); + ASSERT(env->hp <= HEAP_LIMIT(env->proc)); + HEAP_TOP(env->proc) = env->hp; + } + else { + ASSERT(env->hp_end != HEAP_LIMIT(env->proc)); + ASSERT(env->hp_end - env->hp <= env->heap_frag->size); + HRelease(env->proc, env->hp_end, env->hp); + } + free_tmp_objs(env); +} + +static void post_nif_noproc(ErlNifEnv* env) +{ + erts_unblock_fpe(env->fpe_was_unmasked); + free_tmp_objs(env); +} + + +/* Flush out our cached heap pointers to allow an ordinary HAlloc +*/ +static void enable_halloc(ErlNifEnv* env) +{ + if (env->heap_frag == NULL) { ASSERT(env->hp_end == HEAP_LIMIT(env->proc)); ASSERT(env->hp >= HEAP_TOP(env->proc)); ASSERT(env->hp <= HEAP_LIMIT(env->proc)); @@ -89,14 +151,35 @@ void erts_post_nif(ErlNifEnv* env) } else { ASSERT(env->hp_end != HEAP_LIMIT(env->proc)); - ASSERT(env->hp_end - env->hp <= env->heap_frag_sz); + ASSERT(env->hp_end - env->hp <= env->heap_frag->size); HRelease(env->proc, env->hp_end, env->hp); } } -void* enif_get_data(ErlNifEnv* env) +/* Restore cached heap pointers +*/ +static void disable_halloc(ErlNifEnv* env) { - return env->nif_data; + if (env->heap_frag == NULL) { + ASSERT(env->hp_end == HEAP_LIMIT(env->proc)); + ASSERT(env->hp <= HEAP_TOP(env->proc)); + ASSERT(env->hp <= HEAP_LIMIT(env->proc)); + env->hp = HEAP_TOP(env->proc); + } + else { + ASSERT(env->hp_end != HEAP_LIMIT(env->proc)); + ASSERT(env->hp_end - env->hp <= env->heap_frag->size); + env->heap_frag = MBUF(env->proc); + ASSERT(env->heap_frag != NULL); + env->hp = env->heap_frag->mem + env->heap_frag->used_size; + env->hp_end = env->heap_frag->mem + env->heap_frag->size; + } +} + + +void* enif_priv_data(ErlNifEnv* env) +{ + return env->mod_nif->priv_data; } void* enif_alloc(ErlNifEnv* env, size_t size) @@ -104,6 +187,11 @@ void* enif_alloc(ErlNifEnv* env, size_t size) return erts_alloc_fnf(ERTS_ALC_T_NIF, (Uint) size); } +void* enif_realloc(ErlNifEnv* env, void* ptr, size_t size) +{ + return erts_realloc_fnf(ERTS_ALC_T_NIF, ptr, size); +} + void enif_free(ErlNifEnv* env, void* ptr) { erts_free(ERTS_ALC_T_NIF, ptr); @@ -119,25 +207,94 @@ int enif_is_binary(ErlNifEnv* env, ERL_NIF_TERM term) return is_binary(term) && (binary_bitsize(term) % 8 == 0); } +int enif_is_empty_list(ErlNifEnv* env, ERL_NIF_TERM term) +{ + return is_nil(term); +} + +int enif_is_fun(ErlNifEnv* env, ERL_NIF_TERM term) +{ + return is_fun(term); +} + +int enif_is_pid(ErlNifEnv* env, ERL_NIF_TERM term) +{ + return is_pid(term); +} + +int enif_is_port(ErlNifEnv* env, ERL_NIF_TERM term) +{ + return is_port(term); +} + int enif_is_ref(ErlNifEnv* env, ERL_NIF_TERM term) { return is_ref(term); } +static void aligned_binary_dtor(struct enif_tmp_obj_t* obj) +{ + erts_free_aligned_binary_bytes((byte*)obj); +} int enif_inspect_binary(ErlNifEnv* env, Eterm bin_term, ErlNifBinary* bin) { - bin->tmp_alloc = NULL; - bin->data = erts_get_aligned_binary_bytes(bin_term, &bin->tmp_alloc); + union { + struct enif_tmp_obj_t* tmp; + byte* raw_ptr; + }u; + u.tmp = NULL; + bin->data = erts_get_aligned_binary_bytes_extra(bin_term, &u.raw_ptr, + sizeof(struct enif_tmp_obj_t)); if (bin->data == NULL) { return 0; } + if (u.tmp != NULL) { + u.tmp->next = env->tmp_obj_list; + u.tmp->dtor = &aligned_binary_dtor; + env->tmp_obj_list = u.tmp; + } bin->bin_term = bin_term; bin->size = binary_size(bin_term); bin->ref_bin = NULL; return 1; } +static void tmp_alloc_dtor(struct enif_tmp_obj_t* obj) +{ + erts_free(ERTS_ALC_T_TMP, obj); +} + +int enif_inspect_iolist_as_binary(ErlNifEnv* env, Eterm term, ErlNifBinary* bin) +{ + struct enif_tmp_obj_t* tobj; + int sz; + if (is_binary(term)) { + return enif_inspect_binary(env,term,bin); + } + if (is_nil(term)) { + bin->data = (unsigned char*) &bin->data; /* dummy non-NULL */ + bin->size = 0; + bin->bin_term = THE_NON_VALUE; + bin->ref_bin = NULL; + return 1; + } + if ((sz = io_list_len(term)) < 0) { + return 0; + } + + tobj = erts_alloc(ERTS_ALC_T_TMP, sz + sizeof(struct enif_tmp_obj_t)); + tobj->next = env->tmp_obj_list; + tobj->dtor = &tmp_alloc_dtor; + env->tmp_obj_list = tobj; + + bin->data = (unsigned char*) &tobj[1]; + bin->size = sz; + bin->bin_term = THE_NON_VALUE; + bin->ref_bin = NULL; + io_list_to_buf(term, (char*) bin->data, sz); + return 1; +} int enif_alloc_binary(ErlNifEnv* env, unsigned size, ErlNifBinary* bin) { @@ -154,46 +311,48 @@ int enif_alloc_binary(ErlNifEnv* env, unsigned size, ErlNifBinary* bin) bin->size = size; bin->data = (unsigned char*) refbin->orig_bytes; bin->bin_term = THE_NON_VALUE; - bin->tmp_alloc = NULL; bin->ref_bin = refbin; return 1; } int enif_realloc_binary(ErlNifEnv* env, ErlNifBinary* bin, unsigned size) { - Binary* oldbin; - Binary* newbin; - ASSERT(bin->ref_bin != NULL); - - oldbin = (Binary*) bin->ref_bin; - newbin = (Binary *) erts_bin_realloc_fnf(oldbin, size); - if (!newbin) { - return 0; - } - newbin->orig_size = size; - bin->ref_bin = newbin; - bin->data = (unsigned char*) newbin->orig_bytes; - bin->size = size; + if (bin->ref_bin != NULL) { + Binary* oldbin; + Binary* newbin; + + oldbin = (Binary*) bin->ref_bin; + newbin = (Binary *) erts_bin_realloc_fnf(oldbin, size); + if (!newbin) { + return 0; + } + newbin->orig_size = size; + bin->ref_bin = newbin; + bin->data = (unsigned char*) newbin->orig_bytes; + bin->size = size; + } + else { + unsigned char* old_data = bin->data; + unsigned cpy_sz = (size < bin->size ? size : bin->size); + enif_alloc_binary(env, size, bin); + sys_memcpy(bin->data, old_data, cpy_sz); + } return 1; } void enif_release_binary(ErlNifEnv* env, ErlNifBinary* bin) { - if (bin->ref_bin == NULL) { - erts_free_aligned_binary_bytes(bin->tmp_alloc); - } - else { + if (bin->ref_bin != NULL) { Binary* refbin = bin->ref_bin; - ASSERT(bin->tmp_alloc == NULL); ASSERT(bin->bin_term == THE_NON_VALUE); if (erts_refc_dectest(&refbin->refc, 0) == 0) { erts_bin_free(refbin); } } #ifdef DEBUG + bin->data = NULL; bin->bin_term = THE_NON_VALUE; - bin->tmp_alloc = NULL; bin->ref_bin = NULL; #endif } @@ -208,7 +367,7 @@ int enif_compare(ErlNifEnv* env, Eterm lhs, Eterm rhs) return cmp(lhs,rhs); } -int enif_get_tuple(ErlNifEnv* env, Eterm tpl, int* arity, Eterm** array) +int enif_get_tuple(ErlNifEnv* env, Eterm tpl, int* arity, const Eterm** array) { Eterm* ptr; if (is_not_tuple(tpl)) { @@ -220,16 +379,47 @@ int enif_get_tuple(ErlNifEnv* env, Eterm tpl, int* arity, Eterm** array) return 1; } +int enif_get_string(ErlNifEnv *env, ERL_NIF_TERM list, char* buf, unsigned len, + ErlNifCharEncoding encoding) +{ + Eterm* listptr; + int n = 0; + + ASSERT(encoding == ERL_NIF_LATIN1); + if (len < 1) { + return 0; + } + while (is_not_nil(list)) { + if (is_not_list(list)) { + buf[n] = '\0'; + return 0; + } + listptr = list_val(list); + + if (!is_byte(*listptr)) { + buf[n] = '\0'; + return 0; + } + buf[n++] = unsigned_val(*listptr); + if (n >= len) { + buf[n-1] = '\0'; /* truncate */ + return -len; + } + list = CDR(listptr); + } + buf[n] = '\0'; + return n + 1; +} + Eterm enif_make_binary(ErlNifEnv* env, ErlNifBinary* bin) { - if (bin->ref_bin == NULL) { - erts_free_aligned_binary_bytes(bin->tmp_alloc); + if (bin->bin_term != THE_NON_VALUE) { return bin->bin_term; } - else { + else if (bin->ref_bin != NULL) { Binary* bptr = bin->ref_bin; ProcBin* pb; - ASSERT(bin->tmp_alloc == NULL); + Eterm bin_term; /* !! Copy-paste from new_binary() !! */ pb = (ProcBin *) alloc_heap(env, PROC_BIN_SIZE); @@ -242,15 +432,67 @@ Eterm enif_make_binary(ErlNifEnv* env, ErlNifBinary* bin) pb->flags = 0; MSO(env->proc).overhead += pb->size / sizeof(Eterm); - return make_binary(pb); + bin_term = make_binary(pb); + if (erts_refc_read(&bptr->refc, 1) == 1) { + /* Total ownership transfer */ + bin->ref_bin = NULL; + bin->bin_term = bin_term; + } + return bin_term; + } + else { + enable_halloc(env); + bin->bin_term = new_binary(env->proc, bin->data, bin->size); + disable_halloc(env); + return bin->bin_term; } } +Eterm enif_make_sub_binary(ErlNifEnv* env, ERL_NIF_TERM bin_term, + unsigned pos, unsigned size) +{ + ErlSubBin* sb; + Eterm orig; + Uint offset, bit_offset, bit_size; + unsigned src_size; + + ASSERT(is_binary(bin_term)); + src_size = binary_size(bin_term); + ASSERT(pos <= src_size); + ASSERT(size <= src_size); + ASSERT(pos + size <= src_size); + sb = (ErlSubBin*) alloc_heap(env, ERL_SUB_BIN_SIZE); + ERTS_GET_REAL_BIN(bin_term, orig, offset, bit_offset, bit_size); + sb->thing_word = HEADER_SUB_BIN; + sb->size = size; + sb->offs = offset + pos; + sb->orig = orig; + sb->bitoffs = bit_offset; + sb->bitsize = 0; + sb->is_writable = 0; + return make_binary(sb); +} + + Eterm enif_make_badarg(ErlNifEnv* env) { BIF_ERROR(env->proc, BADARG); } +int enif_get_atom(ErlNifEnv* env, Eterm atom, char* buf, unsigned len) +{ + Atom* ap; + if (is_not_atom(atom)) { + return 0; + } + ap = atom_tab(atom_val(atom)); + if (ap->len+1 > len) { + return 0; + } + sys_memcpy(buf, ap->name, ap->len); + buf[ap->len] = '\0'; + return ap->len + 1; +} int enif_get_int(ErlNifEnv* env, Eterm term, int* ip) { @@ -268,6 +510,29 @@ int enif_get_int(ErlNifEnv* env, Eterm term, int* ip) #endif } +int enif_get_uint(ErlNifEnv* env, Eterm term, unsigned* ip) +{ +#if SIZEOF_INT == SIZEOF_VOID_P + return term_to_Uint(term, (Uint*)ip); +#elif SIZEOF_LONG == SIZEOF_VOID_P + Uint i; + if (!term_to_Uint(term, &i) || i > UINT_MAX) { + return 0; + } + *ip = (unsigned) i; + return 1; +#endif +} + +int enif_get_long(ErlNifEnv* env, Eterm term, long* ip) +{ +#if SIZEOF_LONG == SIZEOF_VOID_P + return term_to_Sint(term, ip); +#else +# error Unknown long word size +#endif +} + int enif_get_ulong(ErlNifEnv* env, Eterm term, unsigned long* ip) { #if SIZEOF_LONG == SIZEOF_VOID_P @@ -307,18 +572,26 @@ ERL_NIF_TERM enif_make_int(ErlNifEnv* env, int i) #endif } -ERL_NIF_TERM enif_make_ulong(ErlNifEnv* env, unsigned long i) +ERL_NIF_TERM enif_make_uint(ErlNifEnv* env, unsigned i) { -#if SIZEOF_LONG == SIZEOF_VOID_P - Eterm* hp; - Uint sz = 0; - erts_bld_uint(NULL, &sz, i); - hp = alloc_heap(env,sz); - return erts_bld_uint(&hp, NULL, i); -#else +#if SIZEOF_INT == SIZEOF_VOID_P + return IS_USMALL(0,i) ? make_small(i) : uint_to_big(i,alloc_heap(env,2)); +#elif SIZEOF_LONG == SIZEOF_VOID_P + return make_small(i); +#endif +} + +ERL_NIF_TERM enif_make_long(ErlNifEnv* env, long i) +{ +#if SIZEOF_LONG != SIZEOF_VOID_P # error Unknown long word size #endif + return IS_SSMALL(i) ? make_small(i) : small_to_big(i, alloc_heap(env,2)); +} +ERL_NIF_TERM enif_make_ulong(ErlNifEnv* env, unsigned long i) +{ + return IS_USMALL(0,i) ? make_small(i) : uint_to_big(i,alloc_heap(env,2)); } ERL_NIF_TERM enif_make_double(ErlNifEnv* env, double d) @@ -355,6 +628,19 @@ ERL_NIF_TERM enif_make_tuple(ErlNifEnv* env, unsigned cnt, ...) return ret; } +ERL_NIF_TERM enif_make_tuple_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[], unsigned cnt) +{ + Eterm* hp = alloc_heap(env,cnt+1); + Eterm ret = make_tuple(hp); + const Eterm* src = arr; + + *hp++ = make_arityval(cnt); + while (cnt--) { + *hp++ = *src++; + } + return ret; +} + ERL_NIF_TERM enif_make_list_cell(ErlNifEnv* env, Eterm car, Eterm cdr) { Eterm* hp = alloc_heap(env,2); @@ -384,10 +670,29 @@ ERL_NIF_TERM enif_make_list(ErlNifEnv* env, unsigned cnt, ...) return ret; } -ERL_NIF_TERM enif_make_string(ErlNifEnv* env, const char* string) +ERL_NIF_TERM enif_make_list_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[], unsigned cnt) +{ + Eterm* hp = alloc_heap(env,cnt*2); + Eterm ret = make_list(hp); + Eterm* last = &ret; + const Eterm* src = arr; + + while (cnt--) { + *last = make_list(hp); + *hp = *src++; + last = ++hp; + ++hp; + } + *last = NIL; + return ret; +} + +ERL_NIF_TERM enif_make_string(ErlNifEnv* env, const char* string, + ErlNifCharEncoding encoding) { Sint n = sys_strlen(string); Eterm* hp = alloc_heap(env,n*2); + ASSERT(encoding == ERL_NIF_LATIN1); return erts_bld_string_n(&hp,NULL,string,n); } @@ -397,32 +702,265 @@ ERL_NIF_TERM enif_make_ref(ErlNifEnv* env) return erts_make_ref_in_buffer(hp); } -#if 0 /* To be continued... */ -typedef struct enif_handle_type_t +void enif_system_info(ErlNifSysInfo *sip, size_t si_size) { - struct enif_handle_type_t* next; - struct enif_handle_type_t* prev; - const char* name; - void (*dtor)(void* obj); - erts_smp_atomic_t ref_cnt; /* num of handles of this type */ -}ErlNifHandleType; + driver_system_info(sip, si_size); +} -ErlNifHandleType* -enif_create_handle_type(ErlNifEnv* env, const char* type_name, - void (*dtor)(void *)) + +ErlNifMutex* enif_mutex_create(char *name) { return erl_drv_mutex_create(name); } +void enif_mutex_destroy(ErlNifMutex *mtx) { erl_drv_mutex_destroy(mtx); } +int enif_mutex_trylock(ErlNifMutex *mtx) { return erl_drv_mutex_trylock(mtx); } +void enif_mutex_lock(ErlNifMutex *mtx) { erl_drv_mutex_lock(mtx); } +void enif_mutex_unlock(ErlNifMutex *mtx) { erl_drv_mutex_unlock(mtx); } +ErlNifCond* enif_cond_create(char *name) { return erl_drv_cond_create(name); } +void enif_cond_destroy(ErlNifCond *cnd) { erl_drv_cond_destroy(cnd); } +void enif_cond_signal(ErlNifCond *cnd) { erl_drv_cond_signal(cnd); } +void enif_cond_broadcast(ErlNifCond *cnd) { erl_drv_cond_broadcast(cnd); } +void enif_cond_wait(ErlNifCond *cnd, ErlNifMutex *mtx) { erl_drv_cond_wait(cnd,mtx); } +ErlNifRWLock* enif_rwlock_create(char *name) { return erl_drv_rwlock_create(name); } +void enif_rwlock_destroy(ErlNifRWLock *rwlck) { erl_drv_rwlock_destroy(rwlck); } +int enif_rwlock_tryrlock(ErlNifRWLock *rwlck) { return erl_drv_rwlock_tryrlock(rwlck); } +void enif_rwlock_rlock(ErlNifRWLock *rwlck) { erl_drv_rwlock_rlock(rwlck); } +void enif_rwlock_runlock(ErlNifRWLock *rwlck) { erl_drv_rwlock_runlock(rwlck); } +int enif_rwlock_tryrwlock(ErlNifRWLock *rwlck) { return erl_drv_rwlock_tryrwlock(rwlck); } +void enif_rwlock_rwlock(ErlNifRWLock *rwlck) { erl_drv_rwlock_rwlock(rwlck); } +void enif_rwlock_rwunlock(ErlNifRWLock *rwlck) { erl_drv_rwlock_rwunlock(rwlck); } +int enif_tsd_key_create(char *name, ErlNifTSDKey *key) { return erl_drv_tsd_key_create(name,key); } +void enif_tsd_key_destroy(ErlNifTSDKey key) { erl_drv_tsd_key_destroy(key); } +void enif_tsd_set(ErlNifTSDKey key, void *data) { erl_drv_tsd_set(key,data); } +void* enif_tsd_get(ErlNifTSDKey key) { return erl_drv_tsd_get(key); } +ErlNifThreadOpts* enif_thread_opts_create(char *name) { return (ErlNifThreadOpts*) erl_drv_thread_opts_create(name); } +void enif_thread_opts_destroy(ErlNifThreadOpts *opts) { erl_drv_thread_opts_destroy((ErlDrvThreadOpts*)opts); } +int enif_thread_create(char *name, ErlNifTid *tid, void* (*func)(void *), + void *args, ErlNifThreadOpts *opts) { + return erl_drv_thread_create(name,tid,func,args,(ErlDrvThreadOpts*)opts); +} +ErlNifTid enif_thread_self(void) { return erl_drv_thread_self(); } +int enif_equal_tids(ErlNifTid tid1, ErlNifTid tid2) { return erl_drv_equal_tids(tid1,tid2); } +void enif_thread_exit(void *resp) { erl_drv_thread_exit(resp); } +int enif_thread_join(ErlNifTid tid, void **respp) { return erl_drv_thread_join(tid,respp); } + +int enif_fprintf(void* filep, const char* format, ...) +{ + int ret; + va_list arglist; + va_start(arglist, format); + ret = erts_vfprintf((FILE*)filep, format, arglist); + va_end(arglist); + return ret; +} + +/*********************************************************** + ** Memory managed (GC'ed) "resource" objects ** + ***********************************************************/ + + +struct enif_resource_type_t { + struct enif_resource_type_t* next; /* list of all resource types */ + struct enif_resource_type_t* prev; + struct erl_module_nif* owner; /* that created this type and thus implements the destructor*/ + ErlNifResourceDtor* dtor; /* user destructor function */ + erts_refc_t refc; /* num of resources of this type (HOTSPOT warning) + +1 for active erl_module_nif */ + char name[1]; +}; + +/* dummy node in circular list */ +struct enif_resource_type_t resource_type_list; + +typedef struct enif_resource_t +{ + struct enif_resource_type_t* type; +#ifdef DEBUG + erts_refc_t nif_refc; +#endif + char data[1]; +}ErlNifResource; + +#define SIZEOF_ErlNifResource(SIZE) (offsetof(ErlNifResource,data) + (SIZE)) +#define DATA_TO_RESOURCE(PTR) ((ErlNifResource*)((char*)(PTR) - offsetof(ErlNifResource,data))) +static ErlNifResourceType* find_resource_type(const char* name) +{ + ErlNifResourceType* type; + for (type = resource_type_list.next; + type != &resource_type_list; + type = type->next) { + + if (sys_strcmp(type->name, name) == 0) { + return type; + } + } + return NULL; +} + +#define in_area(ptr,start,nbytes) \ + ((unsigned long)((char*)(ptr) - (char*)(start)) < (nbytes)) + + +static void close_lib(struct erl_module_nif* lib) +{ + ASSERT(lib != NULL); + ASSERT(lib->handle != NULL); + ASSERT(erts_refc_read(&lib->rt_dtor_cnt,0) == 0); + + if (lib->entry != NULL && lib->entry->unload != NULL) { + ErlNifEnv env; + pre_nif_noproc(&env, lib); + lib->entry->unload(&env, lib->priv_data); + post_nif_noproc(&env); + } + erts_sys_ddll_close(lib->handle); + lib->handle = NULL; } -ERL_NIF_TERM enif_make_handle(ErlNifEnv* env, ErlNifHandleType* htype, void* obj) +static void steal_resource_type(ErlNifResourceType* type) { + struct erl_module_nif* lib = type->owner; + + if (type->dtor != NULL + && erts_refc_dectest(&lib->rt_dtor_cnt, 0) == 0 + && lib->is_orphan) { + /* last type with destructor gone, close orphan lib */ + close_lib(lib); + } + if (erts_refc_dectest(&lib->rt_cnt, 0) == 0 + && lib->is_orphan) { + erts_free(ERTS_ALC_T_NIF, lib); + } } -int enif_get_handle(ErlNifEnv* env, ERL_NIF_TERM term, void** objp) +ErlNifResourceType* +enif_open_resource_type(ErlNifEnv* env, const char* type_name, + ErlNifResourceDtor* dtor, + enum ErlNifResourceFlags flags, + enum ErlNifResourceFlags* tried) { + ErlNifResourceType* type = find_resource_type(type_name); + enum ErlNifResourceFlags op = flags; + ASSERT(erts_smp_is_system_blocked(0)); + if (type == NULL) { + if (flags & ERL_NIF_RT_CREATE) { + type = erts_alloc(ERTS_ALC_T_NIF, + sizeof(struct enif_resource_type_t) + + sys_strlen(type_name)); + type->dtor = dtor; + sys_strcpy(type->name, type_name); + erts_refc_init(&type->refc, 1); + type->owner = env->mod_nif; + type->prev = &resource_type_list; + type->next = resource_type_list.next; + type->next->prev = type; + type->prev->next = type; + op = ERL_NIF_RT_CREATE; + } + } + else { + if (flags & ERL_NIF_RT_TAKEOVER) { + steal_resource_type(type); + op = ERL_NIF_RT_TAKEOVER; + } + else { + type = NULL; + } + } + if (type != NULL) { + type->owner = env->mod_nif; + type->dtor = dtor; + if (type->dtor != NULL) { + erts_refc_inc(&type->owner->rt_dtor_cnt, 1); + } + erts_refc_inc(&type->owner->rt_cnt, 1); + } + if (tried != NULL) { + *tried = op; + } + return type; +} + +static void nif_resource_dtor(Binary* bin) +{ + ErlNifResource* resource = (ErlNifResource*) ERTS_MAGIC_BIN_DATA(bin); + ErlNifResourceType* type = resource->type; + ASSERT(ERTS_MAGIC_BIN_DESTRUCTOR(bin) == &nif_resource_dtor); + + if (type->dtor != NULL) { + ErlNifEnv env; + pre_nif_noproc(&env, type->owner); + type->dtor(&env,resource->data); + post_nif_noproc(&env); + } + if (erts_refc_dectest(&type->refc, 0) == 0) { + ASSERT(type->next == NULL); + ASSERT(type->owner != NULL); + ASSERT(type->owner->is_orphan); + steal_resource_type(type); + erts_free(ERTS_ALC_T_NIF, type); + } } + +void* enif_alloc_resource(ErlNifEnv* env, ErlNifResourceType* type, unsigned size) +{ + Binary* bin = erts_create_magic_binary(SIZEOF_ErlNifResource(size), &nif_resource_dtor); + ErlNifResource* resource = ERTS_MAGIC_BIN_DATA(bin); + resource->type = type; + erts_refc_inc(&bin->refc, 1); +#ifdef DEBUG + erts_refc_init(&resource->nif_refc, 1); +#endif + erts_refc_inc(&resource->type->refc, 2); + return resource->data; +} + +void enif_release_resource(ErlNifEnv* env, void* obj) +{ + ErlNifResource* resource = DATA_TO_RESOURCE(obj); + ErtsBinary* bin = ERTS_MAGIC_BIN_FROM_DATA(resource); + + ASSERT(ERTS_MAGIC_BIN_DESTRUCTOR(bin) == &nif_resource_dtor); +#ifdef DEBUG + erts_refc_dec(&resource->nif_refc, 0); #endif + if (erts_refc_dectest(&bin->binary.refc, 0) == 0) { + erts_bin_free(&bin->binary); + } +} + +ERL_NIF_TERM enif_make_resource(ErlNifEnv* env, void* obj) +{ + ErlNifResource* resource = DATA_TO_RESOURCE(obj); + ErtsBinary* bin = ERTS_MAGIC_BIN_FROM_DATA(resource); + Eterm* hp = alloc_heap(env,PROC_BIN_SIZE); + return erts_mk_magic_binary_term(&hp, &MSO(env->proc), &bin->binary); +} + +int enif_get_resource(ErlNifEnv* env, ERL_NIF_TERM term, ErlNifResourceType* type, + void** objp) +{ + Binary* mbin; + ErlNifResource* resource; + if (!ERTS_TERM_IS_MAGIC_BINARY(term)) { + return 0; + } + mbin = ((ProcBin*) binary_val(term))->val; + resource = (ErlNifResource*) ERTS_MAGIC_BIN_DATA(mbin); + if (ERTS_MAGIC_BIN_DESTRUCTOR(mbin) != &nif_resource_dtor + || resource->type != type) { + return 0; + } + *objp = resource->data; + return 1; +} + +unsigned enif_sizeof_resource(ErlNifEnv* env, void* obj) +{ + ErlNifResource* resource = DATA_TO_RESOURCE(obj); + Binary* bin = &ERTS_MAGIC_BIN_FROM_DATA(resource)->binary; + return ERTS_MAGIC_BIN_DATA_SIZE(bin) - offsetof(ErlNifResource,data); +} /*************************************************************************** ** load_nif/2 ** @@ -445,10 +983,7 @@ static Uint** get_func_pp(Eterm* mod_code, Eterm f_atom, unsigned arity) return NULL; } -#define in_area(ptr,start,nbytes) \ - ((unsigned long)((char*)(ptr) - (char*)(start)) < (nbytes)) - -static void refresh_cached_nif_data(Eterm* mod_code, +/*static void refresh_cached_nif_data(Eterm* mod_code, struct erl_module_nif* mod_nif) { int i; @@ -459,9 +994,9 @@ static void refresh_cached_nif_data(Eterm* mod_code, erts_atom_get(func->name, sys_strlen(func->name), &f_atom); code_ptr = *get_func_pp(mod_code, f_atom, func->arity); - code_ptr[5+2] = (Uint) mod_nif->data; + code_ptr[5+2] = (Uint) mod_nif->priv_data; } -} +}*/ static Eterm mkatom(const char *str) { @@ -567,6 +1102,7 @@ BIF_RETTYPE load_nif_2(BIF_ALIST_2) ErtsSysDdllError errdesc = ERTS_SYS_DDLL_ERROR_INIT; Eterm ret = am_ok; int veto; + struct erl_module_nif* lib = NULL; len = intlist_to_buf(BIF_ARG_1, lib_name, sizeof(lib_name)-1); if (len < 1) { @@ -652,16 +1188,27 @@ BIF_RETTYPE load_nif_2(BIF_ALIST_2) /* Call load, reload or upgrade: */ - if (mod->nif.handle != NULL) { /* Reload */ + + + lib = erts_alloc(ERTS_ALC_T_NIF, sizeof(struct erl_module_nif)); + lib->handle = handle; + lib->entry = entry; + erts_refc_init(&lib->rt_cnt, 0); + erts_refc_init(&lib->rt_dtor_cnt, 0); + lib->is_orphan = 0; + env.mod_nif = lib; + if (mod->nif != NULL) { /* Reload */ int k; - ASSERT(mod->nif.entry != NULL); + lib->priv_data = mod->nif->priv_data; + + ASSERT(mod->nif->entry != NULL); if (entry->reload == NULL) { ret = load_nif_error(BIF_P,reload,"Reload not supported by this NIF library."); goto error; } /* Check that no NIF is removed */ - for (k=0; k < mod->nif.entry->num_of_funcs; k++) { - ErlNifFunc* old_func = &mod->nif.entry->funcs[k]; + for (k=0; k < mod->nif->entry->num_of_funcs; k++) { + ErlNifFunc* old_func = &mod->nif->entry->funcs[k]; for (i=0; i < entry->num_of_funcs; i++) { if (old_func->arity == entry->funcs[i].arity && sys_strcmp(old_func->name, entry->funcs[i].name) == 0) { @@ -675,37 +1222,39 @@ BIF_RETTYPE load_nif_2(BIF_ALIST_2) goto error; } } - erts_pre_nif(&env, BIF_P, mod->nif.data); - veto = entry->reload(&env, &env.nif_data, BIF_ARG_2); + erts_pre_nif(&env, BIF_P, lib); + veto = entry->reload(&env, &lib->priv_data, BIF_ARG_2); erts_post_nif(&env); if (veto) { ret = load_nif_error(BIF_P, reload, "Library reload-call unsuccessful."); } else { - erts_sys_ddll_close(mod->nif.handle); + mod->nif->entry = NULL; /* to prevent 'unload' callback */ + erts_unload_nif(mod->nif); } } else { - if (mod->old_nif.handle != NULL) { /* Upgrade */ - void* prev_old_data = mod->old_nif.data; + lib->priv_data = NULL; + if (mod->old_nif != NULL) { /* Upgrade */ + void* prev_old_data = mod->old_nif->priv_data; if (entry->upgrade == NULL) { ret = load_nif_error(BIF_P, upgrade, "Upgrade not supported by this NIF library."); goto error; } - erts_pre_nif(&env, BIF_P, NULL); - veto = entry->upgrade(&env, &env.nif_data, &mod->old_nif.data, BIF_ARG_2); + erts_pre_nif(&env, BIF_P, lib); + veto = entry->upgrade(&env, &lib->priv_data, &mod->old_nif->priv_data, BIF_ARG_2); erts_post_nif(&env); if (veto) { - mod->old_nif.data = prev_old_data; + mod->old_nif->priv_data = prev_old_data; ret = load_nif_error(BIF_P, upgrade, "Library upgrade-call unsuccessful."); } - else if (mod->old_nif.data != prev_old_data) { - refresh_cached_nif_data(mod->old_code, &mod->old_nif); - } + /*else if (mod->old_nif->priv_data != prev_old_data) { + refresh_cached_nif_data(mod->old_code, mod->old_nif); + }*/ } else if (entry->load != NULL) { /* Initial load */ - erts_pre_nif(&env, BIF_P, NULL); - veto = entry->load(&env, &env.nif_data, BIF_ARG_2); + erts_pre_nif(&env, BIF_P, lib); + veto = entry->load(&env, &lib->priv_data, BIF_ARG_2); erts_post_nif(&env); if (veto) { ret = load_nif_error(BIF_P, "load", "Library load-call unsuccessful."); @@ -716,9 +1265,7 @@ BIF_RETTYPE load_nif_2(BIF_ALIST_2) /* ** Everything ok, patch the beam code with op_call_nif */ - mod->nif.data = env.nif_data; - mod->nif.handle = handle; - mod->nif.entry = entry; + mod->nif = lib; for (i=0; i < entry->num_of_funcs; i++) { Uint* code_ptr; @@ -727,17 +1274,21 @@ BIF_RETTYPE load_nif_2(BIF_ALIST_2) if (code_ptr[1] == 0) { code_ptr[5+0] = (Uint) BeamOp(op_call_nif); - } else { /* Function traced, patch the original instruction word */ + } + else { /* Function traced, patch the original instruction word */ BpData* bp = (BpData*) code_ptr[1]; bp->orig_instr = (Uint) BeamOp(op_call_nif); } code_ptr[5+1] = (Uint) entry->funcs[i].fptr; - code_ptr[5+2] = (Uint) mod->nif.data; + code_ptr[5+2] = (Uint) lib; } } else { error: ASSERT(ret != am_ok); + if (lib != NULL) { + erts_free(ERTS_ALC_T_NIF, lib); + } if (handle != NULL) { erts_sys_ddll_close(handle); } @@ -749,3 +1300,53 @@ BIF_RETTYPE load_nif_2(BIF_ALIST_2) BIF_RET(ret); } + +void +erts_unload_nif(struct erl_module_nif* lib) +{ + ErlNifResourceType* rt; + ErlNifResourceType* next; + ASSERT(erts_smp_is_system_blocked(0)); + ASSERT(lib != NULL); + ASSERT(!lib->is_orphan); + for (rt = resource_type_list.next; + rt != &resource_type_list; + rt = next) { + + next = rt->next; + if (rt->owner == lib) { + rt->next->prev = rt->prev; + rt->prev->next = rt->next; + rt->next = NULL; + rt->prev = NULL; + if (erts_refc_dectest(&rt->refc, 0) == 0) { + if (rt->dtor != NULL) { + erts_refc_dec(&lib->rt_dtor_cnt, 0); + } + erts_refc_dec(&lib->rt_cnt, 0); + erts_free(ERTS_ALC_T_NIF, rt); + } + } + } + if (erts_refc_read(&lib->rt_dtor_cnt, 0) == 0) { + close_lib(lib); + if (erts_refc_read(&lib->rt_cnt, 0) == 0) { + erts_free(ERTS_ALC_T_NIF, lib); + return; + } + } + else { + ASSERT(erts_refc_read(&lib->rt_cnt, 1) > 0); + } + lib->is_orphan = 1; +} + +void erl_nif_init() +{ + resource_type_list.next = &resource_type_list; + resource_type_list.prev = &resource_type_list; + resource_type_list.dtor = NULL; + resource_type_list.owner = NULL; + resource_type_list.name[0] = '\0'; +} + diff --git a/erts/emulator/beam/erl_nif.h b/erts/emulator/beam/erl_nif.h index e5e6d65c0e..1ccf00293e 100644 --- a/erts/emulator/beam/erl_nif.h +++ b/erts/emulator/beam/erl_nif.h @@ -1,25 +1,30 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 2009-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ /* Include file for writers of Native Implemented Functions. */ +#ifndef __ERL_NIF_H__ +#define __ERL_NIF_H__ + +#include "erl_drv_nif.h" + /* Version history: ** 0.1: R13B03 ** 1.0: R13B04 @@ -63,11 +68,32 @@ typedef struct /* Internals (avert your eyes) */ ERL_NIF_TERM bin_term; - unsigned char* tmp_alloc; void* ref_bin; - }ErlNifBinary; +typedef struct enif_resource_type_t ErlNifResourceType; +typedef void ErlNifResourceDtor(ErlNifEnv*, void*); +enum ErlNifResourceFlags +{ + ERL_NIF_RT_CREATE = 1, + ERL_NIF_RT_TAKEOVER = 2 +}; + +typedef enum +{ + ERL_NIF_LATIN1 = 1 +}ErlNifCharEncoding; + +typedef ErlDrvSysInfo ErlNifSysInfo; + +typedef struct ErlDrvTid_ *ErlNifTid; +typedef struct ErlDrvMutex_ ErlNifMutex; +typedef struct ErlDrvCond_ ErlNifCond; +typedef struct ErlDrvRWLock_ ErlNifRWLock; +typedef int ErlNifTSDKey; + +typedef ErlDrvThreadOpts ErlNifThreadOpts; + #if (defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_)) # define ERL_NIF_API_FUNC_DECL(RET_TYPE, NAME, ARGS) RET_TYPE (*NAME) ARGS typedef struct { @@ -124,3 +150,5 @@ ERL_NIF_INIT_DECL(NAME) \ return &entry; \ } +#endif /* __ERL_NIF_H__ */ + diff --git a/erts/emulator/beam/erl_nif_api_funcs.h b/erts/emulator/beam/erl_nif_api_funcs.h index 7556806ce4..ec07a976b2 100644 --- a/erts/emulator/beam/erl_nif_api_funcs.h +++ b/erts/emulator/beam/erl_nif_api_funcs.h @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 2009-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -22,7 +22,7 @@ #endif #ifdef ERL_NIF_API_FUNC_DECL -ERL_NIF_API_FUNC_DECL(void*,enif_get_data,(ErlNifEnv*)); +ERL_NIF_API_FUNC_DECL(void*,enif_priv_data,(ErlNifEnv*)); ERL_NIF_API_FUNC_DECL(void*,enif_alloc,(ErlNifEnv*, size_t size)); ERL_NIF_API_FUNC_DECL(void,enif_free,(ErlNifEnv*, void* ptr)); ERL_NIF_API_FUNC_DECL(int,enif_is_atom,(ErlNifEnv*, ERL_NIF_TERM term)); @@ -36,7 +36,7 @@ ERL_NIF_API_FUNC_DECL(int,enif_get_int,(ErlNifEnv*, ERL_NIF_TERM term, int* ip)) ERL_NIF_API_FUNC_DECL(int,enif_get_ulong,(ErlNifEnv*, ERL_NIF_TERM term, unsigned long* ip)); ERL_NIF_API_FUNC_DECL(int,enif_get_double,(ErlNifEnv*, ERL_NIF_TERM term, double* dp)); ERL_NIF_API_FUNC_DECL(int,enif_get_list_cell,(ErlNifEnv* env, ERL_NIF_TERM term, ERL_NIF_TERM* head, ERL_NIF_TERM* tail)); -ERL_NIF_API_FUNC_DECL(int,enif_get_tuple,(ErlNifEnv* env, ERL_NIF_TERM tpl, int* arity, ERL_NIF_TERM** array)); +ERL_NIF_API_FUNC_DECL(int,enif_get_tuple,(ErlNifEnv* env, ERL_NIF_TERM tpl, int* arity, const ERL_NIF_TERM** array)); ERL_NIF_API_FUNC_DECL(int,enif_is_identical,(ErlNifEnv* env, ERL_NIF_TERM lhs, ERL_NIF_TERM rhs)); ERL_NIF_API_FUNC_DECL(int,enif_compare,(ErlNifEnv* env, ERL_NIF_TERM lhs, ERL_NIF_TERM rhs)); ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_binary,(ErlNifEnv* env, ErlNifBinary* bin)); @@ -49,15 +49,69 @@ ERL_NIF_API_FUNC_DECL(int,enif_make_existing_atom,(ErlNifEnv* env, const char* n ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_tuple,(ErlNifEnv* env, unsigned cnt, ...)); ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_list,(ErlNifEnv* env, unsigned cnt, ...)); ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_list_cell,(ErlNifEnv* env, ERL_NIF_TERM car, ERL_NIF_TERM cdr)); -ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_string,(ErlNifEnv* env, const char* string)); +ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_string,(ErlNifEnv* env, const char* string, ErlNifCharEncoding)); ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_ref,(ErlNifEnv* env)); + +ERL_NIF_API_FUNC_DECL(ErlNifMutex*,enif_mutex_create,(char *name)); +ERL_NIF_API_FUNC_DECL(void,enif_mutex_destroy,(ErlNifMutex *mtx)); +ERL_NIF_API_FUNC_DECL(int,enif_mutex_trylock,(ErlNifMutex *mtx)); +ERL_NIF_API_FUNC_DECL(void,enif_mutex_lock,(ErlNifMutex *mtx)); +ERL_NIF_API_FUNC_DECL(void,enif_mutex_unlock,(ErlNifMutex *mtx)); +ERL_NIF_API_FUNC_DECL(ErlNifCond*,enif_cond_create,(char *name)); +ERL_NIF_API_FUNC_DECL(void,enif_cond_destroy,(ErlNifCond *cnd)); +ERL_NIF_API_FUNC_DECL(void,enif_cond_signal,(ErlNifCond *cnd)); +ERL_NIF_API_FUNC_DECL(void,enif_cond_broadcast,(ErlNifCond *cnd)); +ERL_NIF_API_FUNC_DECL(void,enif_cond_wait,(ErlNifCond *cnd, ErlNifMutex *mtx)); +ERL_NIF_API_FUNC_DECL(ErlNifRWLock*,enif_rwlock_create,(char *name)); +ERL_NIF_API_FUNC_DECL(void,enif_rwlock_destroy,(ErlNifRWLock *rwlck)); +ERL_NIF_API_FUNC_DECL(int,enif_rwlock_tryrlock,(ErlNifRWLock *rwlck)); +ERL_NIF_API_FUNC_DECL(void,enif_rwlock_rlock,(ErlNifRWLock *rwlck)); +ERL_NIF_API_FUNC_DECL(void,enif_rwlock_runlock,(ErlNifRWLock *rwlck)); +ERL_NIF_API_FUNC_DECL(int,enif_rwlock_tryrwlock,(ErlNifRWLock *rwlck)); +ERL_NIF_API_FUNC_DECL(void,enif_rwlock_rwlock,(ErlNifRWLock *rwlck)); +ERL_NIF_API_FUNC_DECL(void,enif_rwlock_rwunlock,(ErlNifRWLock *rwlck)); +ERL_NIF_API_FUNC_DECL(int,enif_tsd_key_create,(char *name, ErlNifTSDKey *key)); +ERL_NIF_API_FUNC_DECL(void,enif_tsd_key_destroy,(ErlNifTSDKey key)); +ERL_NIF_API_FUNC_DECL(void,enif_tsd_set,(ErlNifTSDKey key, void *data)); +ERL_NIF_API_FUNC_DECL(void*,enif_tsd_get,(ErlNifTSDKey key)); +ERL_NIF_API_FUNC_DECL(ErlNifThreadOpts*,enif_thread_opts_create,(char *name)); +ERL_NIF_API_FUNC_DECL(void,enif_thread_opts_destroy,(ErlNifThreadOpts *opts)); +ERL_NIF_API_FUNC_DECL(int,enif_thread_create,(char *name,ErlNifTid *tid,void * (*func)(void *),void *args,ErlNifThreadOpts *opts)); +ERL_NIF_API_FUNC_DECL(ErlNifTid,enif_thread_self,(void)); +ERL_NIF_API_FUNC_DECL(int,enif_equal_tids,(ErlNifTid tid1, ErlNifTid tid2)); +ERL_NIF_API_FUNC_DECL(void,enif_thread_exit,(void *resp)); +ERL_NIF_API_FUNC_DECL(int,enif_thread_join,(ErlNifTid, void **respp)); + +ERL_NIF_API_FUNC_DECL(void*,enif_realloc,(ErlNifEnv*, void* ptr, size_t size)); +ERL_NIF_API_FUNC_DECL(void,enif_system_info,(ErlNifSysInfo *sip, size_t si_size)); +ERL_NIF_API_FUNC_DECL(int,enif_fprintf,(void/* FILE* */ *filep, const char *format, ...)); +ERL_NIF_API_FUNC_DECL(int,enif_inspect_iolist_as_binary,(ErlNifEnv*, ERL_NIF_TERM term, ErlNifBinary* bin)); +ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_sub_binary,(ErlNifEnv*, ERL_NIF_TERM bin_term, unsigned pos, unsigned size)); +ERL_NIF_API_FUNC_DECL(int,enif_get_string,(ErlNifEnv*, ERL_NIF_TERM list, char* buf, unsigned len, ErlNifCharEncoding)); +ERL_NIF_API_FUNC_DECL(int,enif_get_atom,(ErlNifEnv*, ERL_NIF_TERM atom, char* buf, unsigned len)); +ERL_NIF_API_FUNC_DECL(int,enif_is_fun,(ErlNifEnv*, ERL_NIF_TERM term)); +ERL_NIF_API_FUNC_DECL(int,enif_is_pid,(ErlNifEnv*, ERL_NIF_TERM term)); +ERL_NIF_API_FUNC_DECL(int,enif_is_port,(ErlNifEnv*, ERL_NIF_TERM term)); +ERL_NIF_API_FUNC_DECL(int,enif_get_uint,(ErlNifEnv*, ERL_NIF_TERM term, unsigned* ip)); +ERL_NIF_API_FUNC_DECL(int,enif_get_long,(ErlNifEnv*, ERL_NIF_TERM term, long* ip)); +ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_uint,(ErlNifEnv*, unsigned i)); +ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_long,(ErlNifEnv*, long i)); +ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_tuple_from_array,(ErlNifEnv*, const ERL_NIF_TERM arr[], unsigned cnt)); +ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_list_from_array,(ErlNifEnv*, const ERL_NIF_TERM arr[], unsigned cnt)); +ERL_NIF_API_FUNC_DECL(int,enif_is_empty_list,(ErlNifEnv*, ERL_NIF_TERM term)); +ERL_NIF_API_FUNC_DECL(ErlNifResourceType*,enif_open_resource_type,(ErlNifEnv*, const char* type_name, void (*dtor)(ErlNifEnv*,void *), enum ErlNifResourceFlags flags, enum ErlNifResourceFlags* tried)); +ERL_NIF_API_FUNC_DECL(void*,enif_alloc_resource,(ErlNifEnv*, ErlNifResourceType* type, unsigned size)); +ERL_NIF_API_FUNC_DECL(void,enif_release_resource,(ErlNifEnv*, void* obj)); +ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_resource,(ErlNifEnv*, void* obj)); +ERL_NIF_API_FUNC_DECL(int,enif_get_resource,(ErlNifEnv*, ERL_NIF_TERM term, ErlNifResourceType* type, void** objp)); +ERL_NIF_API_FUNC_DECL(unsigned,enif_sizeof_resource,(ErlNifEnv*, void* obj)); /* ** Add last to keep compatibility on Windows!!! */ #endif #ifdef ERL_NIF_API_FUNC_MACRO -# define enif_get_data ERL_NIF_API_FUNC_MACRO(enif_get_data) +# define enif_priv_data ERL_NIF_API_FUNC_MACRO(enif_priv_data) # define enif_alloc ERL_NIF_API_FUNC_MACRO(enif_alloc) # define enif_free ERL_NIF_API_FUNC_MACRO(enif_free) # define enif_is_atom ERL_NIF_API_FUNC_MACRO(enif_is_atom) @@ -88,5 +142,84 @@ ERL_NIF_API_FUNC_DECL(ERL_NIF_TERM,enif_make_ref,(ErlNifEnv* env)); # define enif_make_string ERL_NIF_API_FUNC_MACRO(enif_make_string) # define enif_make_ref ERL_NIF_API_FUNC_MACRO(enif_make_ref) +# define enif_mutex_create ERL_NIF_API_FUNC_MACRO(enif_mutex_create) +# define enif_mutex_destroy ERL_NIF_API_FUNC_MACRO(enif_mutex_destroy) +# define enif_mutex_trylock ERL_NIF_API_FUNC_MACRO(enif_mutex_trylock) +# define enif_mutex_lock ERL_NIF_API_FUNC_MACRO(enif_mutex_lock) +# define enif_mutex_unlock ERL_NIF_API_FUNC_MACRO(enif_mutex_unlock) +# define enif_cond_create ERL_NIF_API_FUNC_MACRO(enif_cond_create) +# define enif_cond_destroy ERL_NIF_API_FUNC_MACRO(enif_cond_destroy) +# define enif_cond_signal ERL_NIF_API_FUNC_MACRO(enif_cond_signal) +# define enif_cond_broadcast ERL_NIF_API_FUNC_MACRO(enif_cond_broadcast) +# define enif_cond_wait ERL_NIF_API_FUNC_MACRO(enif_cond_wait) +# define enif_rwlock_create ERL_NIF_API_FUNC_MACRO(enif_rwlock_create) +# define enif_rwlock_destroy ERL_NIF_API_FUNC_MACRO(enif_rwlock_destroy) +# define enif_rwlock_tryrlock ERL_NIF_API_FUNC_MACRO(enif_rwlock_tryrlock) +# define enif_rwlock_rlock ERL_NIF_API_FUNC_MACRO(enif_rwlock_rlock) +# define enif_rwlock_runlock ERL_NIF_API_FUNC_MACRO(enif_rwlock_runlock) +# define enif_rwlock_tryrwlock ERL_NIF_API_FUNC_MACRO(enif_rwlock_tryrwlock) +# define enif_rwlock_rwlock ERL_NIF_API_FUNC_MACRO(enif_rwlock_rwlock) +# define enif_rwlock_rwunlock ERL_NIF_API_FUNC_MACRO(enif_rwlock_rwunlock) +# define enif_tsd_key_create ERL_NIF_API_FUNC_MACRO(enif_tsd_key_create) +# define enif_tsd_key_destroy ERL_NIF_API_FUNC_MACRO(enif_tsd_key_destroy) +# define enif_tsd_set ERL_NIF_API_FUNC_MACRO(enif_tsd_set) +# define enif_tsd_get ERL_NIF_API_FUNC_MACRO(enif_tsd_get) +# define enif_thread_opts_create ERL_NIF_API_FUNC_MACRO(enif_thread_opts_create) +# define enif_thread_opts_destroy ERL_NIF_API_FUNC_MACRO(enif_thread_opts_destroy) +# define enif_thread_create ERL_NIF_API_FUNC_MACRO(enif_thread_create) +# define enif_thread_self ERL_NIF_API_FUNC_MACRO(enif_thread_self) +# define enif_equal_tids ERL_NIF_API_FUNC_MACRO(enif_equal_tids) +# define enif_thread_exit ERL_NIF_API_FUNC_MACRO(enif_thread_exit) +# define enif_thread_join ERL_NIF_API_FUNC_MACRO(enif_thread_join) + +# define enif_realloc ERL_NIF_API_FUNC_MACRO(enif_realloc) +# define enif_system_info ERL_NIF_API_FUNC_MACRO(enif_system_info) +# define enif_fprintf ERL_NIF_API_FUNC_MACRO(enif_fprintf) +# define enif_inspect_iolist_as_binary ERL_NIF_API_FUNC_MACRO(enif_inspect_iolist_as_binary) +# define enif_make_sub_binary ERL_NIF_API_FUNC_MACRO(enif_make_sub_binary) +# define enif_get_string ERL_NIF_API_FUNC_MACRO(enif_get_string) +# define enif_get_atom ERL_NIF_API_FUNC_MACRO(enif_get_atom) +# define enif_is_fun ERL_NIF_API_FUNC_MACRO(enif_is_fun) +# define enif_is_pid ERL_NIF_API_FUNC_MACRO(enif_is_pid) +# define enif_is_port ERL_NIF_API_FUNC_MACRO(enif_is_port) +# define enif_get_uint ERL_NIF_API_FUNC_MACRO(enif_get_uint) +# define enif_get_long ERL_NIF_API_FUNC_MACRO(enif_get_long) +# define enif_make_uint ERL_NIF_API_FUNC_MACRO(enif_make_uint) +# define enif_make_long ERL_NIF_API_FUNC_MACRO(enif_make_long) +# define enif_make_tuple_from_array ERL_NIF_API_FUNC_MACRO(enif_make_tuple_from_array) +# define enif_make_list_from_array ERL_NIF_API_FUNC_MACRO(enif_make_list_from_array) +# define enif_is_empty_list ERL_NIF_API_FUNC_MACRO(enif_is_empty_list) +# define enif_open_resource_type ERL_NIF_API_FUNC_MACRO(enif_open_resource_type) +# define enif_alloc_resource ERL_NIF_API_FUNC_MACRO(enif_alloc_resource) +# define enif_release_resource ERL_NIF_API_FUNC_MACRO(enif_release_resource) +# define enif_make_resource ERL_NIF_API_FUNC_MACRO(enif_make_resource) +# define enif_get_resource ERL_NIF_API_FUNC_MACRO(enif_get_resource) +# define enif_sizeof_resource ERL_NIF_API_FUNC_MACRO(enif_sizeof_resource) + +#endif + +#ifndef enif_make_list1 +# define enif_make_list1(ENV,E1) enif_make_list(ENV,1,E1) +# define enif_make_list2(ENV,E1,E2) enif_make_list(ENV,2,E1,E2) +# define enif_make_list3(ENV,E1,E2,E3) enif_make_list(ENV,3,E1,E2,E3) +# define enif_make_list4(ENV,E1,E2,E3,E4) enif_make_list(ENV,4,E1,E2,E3,E4) +# define enif_make_list5(ENV,E1,E2,E3,E4,E5) enif_make_list(ENV,5,E1,E2,E3,E4,E5) +# define enif_make_list6(ENV,E1,E2,E3,E4,E5,E6) enif_make_list(ENV,6,E1,E2,E3,E4,E5,E6) +# define enif_make_list7(ENV,E1,E2,E3,E4,E5,E6,E7) enif_make_list(ENV,7,E1,E2,E3,E4,E5,E6,E7) +# define enif_make_list8(ENV,E1,E2,E3,E4,E5,E6,E7,E8) enif_make_list(ENV,8,E1,E2,E3,E4,E5,E6,E7,E8) +# define enif_make_list9(ENV,E1,E2,E3,E4,E5,E6,E7,E8,E9) enif_make_list(ENV,9,E1,E2,E3,E4,E5,E6,E7,E8,E9) +# define enif_make_tuple1(ENV,E1) enif_make_tuple(ENV,1,E1) +# define enif_make_tuple2(ENV,E1,E2) enif_make_tuple(ENV,2,E1,E2) +# define enif_make_tuple3(ENV,E1,E2,E3) enif_make_tuple(ENV,3,E1,E2,E3) +# define enif_make_tuple4(ENV,E1,E2,E3,E4) enif_make_tuple(ENV,4,E1,E2,E3,E4) +# define enif_make_tuple5(ENV,E1,E2,E3,E4,E5) enif_make_tuple(ENV,5,E1,E2,E3,E4,E5) +# define enif_make_tuple6(ENV,E1,E2,E3,E4,E5,E6) enif_make_tuple(ENV,6,E1,E2,E3,E4,E5,E6) +# define enif_make_tuple7(ENV,E1,E2,E3,E4,E5,E6,E7) enif_make_tuple(ENV,7,E1,E2,E3,E4,E5,E6,E7) +# define enif_make_tuple8(ENV,E1,E2,E3,E4,E5,E6,E7,E8) enif_make_tuple(ENV,8,E1,E2,E3,E4,E5,E6,E7,E8) +# define enif_make_tuple9(ENV,E1,E2,E3,E4,E5,E6,E7,E8,E9) enif_make_tuple(ENV,9,E1,E2,E3,E4,E5,E6,E7,E8,E9) +#endif + +#ifndef enif_get_data +# define enif_get_data enif_priv_data /* deprecated */ #endif diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c index 2789691c55..996806fc75 100644 --- a/erts/emulator/beam/erl_process.c +++ b/erts/emulator/beam/erl_process.c @@ -2095,7 +2095,11 @@ erts_init_scheduling(int mrq, int no_schedulers, int no_schedulers_online) rq->ix = ix; erts_smp_atomic_init(&rq->info_flags, ERTS_RUNQ_IFLG_NONEMPTY); - erts_smp_mtx_init(&rq->mtx, "run_queue"); + /* make sure that the "extra" id correponds to the schedulers + * id if the esdp->no <-> ix+1 mapping change. + */ + + erts_smp_mtx_init_x(&rq->mtx, "run_queue", make_small(ix + 1)); erts_smp_cnd_init(&rq->cnd); erts_smp_atomic_init(&rq->spin_waiter, 0); @@ -6282,7 +6286,9 @@ Process *schedule(Process *p, int calls) erts_check_my_tracer_proc(p); #endif - if ((FLAGS(p) & F_FORCE_GC) || (MSO(p).overhead > BIN_VHEAP_SZ(p))) { + if (!ERTS_PROC_IS_EXITING(p) + && ((FLAGS(p) & F_FORCE_GC) + || (MSO(p).overhead > BIN_VHEAP_SZ(p)))) { reds -= erts_garbage_collect(p, 0, p->arg_reg, p->arity); if (reds < 0) { reds = 1; diff --git a/erts/emulator/beam/external.c b/erts/emulator/beam/external.c index b011d4c0de..099eddd195 100644 --- a/erts/emulator/beam/external.c +++ b/erts/emulator/beam/external.c @@ -1027,11 +1027,12 @@ static uLongf binary2term_uncomp_size(byte* data, Sint size) err = inflateInit(&stream); if (err == Z_OK) { - while ((err = inflate(&stream, Z_NO_FLUSH)) == Z_OK) { - uncomp_size += chunk_size - stream.avail_out; + do { stream.next_out = tmp_buf; - stream.avail_out = chunk_size; - } + stream.avail_out = chunk_size; + err = inflate(&stream, Z_NO_FLUSH); + uncomp_size += chunk_size - stream.avail_out; + }while (err == Z_OK); inflateEnd(&stream); } erts_free(ERTS_ALC_T_TMP, tmp_buf); diff --git a/erts/emulator/beam/global.h b/erts/emulator/beam/global.h index 8def007c63..cab249a53f 100644 --- a/erts/emulator/beam/global.h +++ b/erts/emulator/beam/global.h @@ -76,19 +76,29 @@ typedef struct line_buf { /* Buffer used in line oriented I/O */ The rest is the overflow buffer. */ } LineBuf; +/* Temporary object header, auto-deallocated when NIF returns. */ +struct enif_tmp_obj_t { + struct enif_tmp_obj_t* next; + void (*dtor)(struct enif_tmp_obj_t*); + /*char data[];*/ +}; struct enif_environment_t /* ErlNifEnv */ { - void* nif_data; + struct erl_module_nif* mod_nif; Process* proc; Eterm* hp; Eterm* hp_end; - unsigned heap_frag_sz; + ErlHeapFragment* heap_frag; int fpe_was_unmasked; + struct enif_tmp_obj_t* tmp_obj_list; }; -extern void erts_pre_nif(struct enif_environment_t*, Process*, void* nif_data); +extern void erts_pre_nif(struct enif_environment_t*, Process*, + struct erl_module_nif*); extern void erts_post_nif(struct enif_environment_t* env); extern Eterm erts_nif_taints(Process* p); -extern void erts_print_nif_taints(int to, void* to_arg); +extern void erts_print_nif_taints(int to, void* to_arg); +void erts_unload_nif(struct erl_module_nif* nif); +extern void erl_nif_init(void); /* * Port Specific Data. @@ -403,6 +413,9 @@ typedef struct binary { char orig_bytes[1]; /* to be continued */ } Binary; +#define ERTS_SIZEOF_Binary(Sz) \ + (offsetof(Binary,orig_bytes) + (Sz)) + typedef struct { ERTS_INTERNAL_BINARY_FIELDS long orig_size; @@ -435,7 +448,9 @@ typedef union { #define ERTS_MAGIC_BIN_ORIG_SIZE(Sz) \ (sizeof(void (*)(Binary *)) + (Sz)) #define ERTS_MAGIC_BIN_SIZE(Sz) \ - (sizeof(ErtsMagicBinary) - 1 + (Sz)) + (offsetof(ErtsMagicBinary,magic_bin_data) + (Sz)) +#define ERTS_MAGIC_BIN_FROM_DATA(DATA) \ + ((ErtsBinary*)((char*)(DATA) - offsetof(ErtsMagicBinary,magic_bin_data))) #define Binary2ErlDrvBinary(B) (&((ErtsBinary *) (B))->driver.binary) #define ErlDrvBinary2Binary(D) ((Binary *) \ diff --git a/erts/emulator/beam/io.c b/erts/emulator/beam/io.c index 61985271e6..ad0b909b2a 100644 --- a/erts/emulator/beam/io.c +++ b/erts/emulator/beam/io.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1996-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -31,6 +31,7 @@ /* must be included BEFORE global.h (since it includes erl_driver.h) */ #include "erl_sys_driver.h" +#include "erl_nif.h" #include "erl_vm.h" #include "global.h" @@ -1078,7 +1079,7 @@ int erts_write_to_port(Eterm caller_id, Port *p, Eterm list) } cbin = driver_alloc_binary(csize); if (!cbin) - erts_alloc_enomem(ERTS_ALC_T_DRV_BINARY, sizeof(Binary) + csize); + erts_alloc_enomem(ERTS_ALC_T_DRV_BINARY, ERTS_SIZEOF_Binary(csize)); /* Element 0 is for driver usage to add header block */ ivp[0].iov_base = NULL; @@ -1227,7 +1228,7 @@ void init_io(void) erts_smp_atomic_init(&erts_port[i].refc, 0); erts_port[i].lock = NULL; erts_port[i].xports = NULL; - erts_smp_spinlock_init(&erts_port[i].state_lck, "port_state"); + erts_smp_spinlock_init_x(&erts_port[i].state_lck, "port_state", make_small(i)); #endif erts_port[i].tracer_proc = NIL; erts_port[i].trace_flags = 0; @@ -4473,7 +4474,14 @@ driver_system_info(ErlDrvSysInfo *sip, size_t si_size) sip->async_threads = erts_async_max_threads; sip->scheduler_threads = erts_no_schedulers; } - + /* + * 'nif_minor_version' is the last field in the third version + * (driver version 1.5, NIF version 1.0) + */ + if (si_size >= ERL_DRV_SYS_INFO_SIZE(nif_minor_version)) { + sip->nif_major_version = ERL_NIF_MAJOR_VERSION; + sip->nif_minor_version = ERL_NIF_MINOR_VERSION; + } } diff --git a/erts/emulator/beam/module.c b/erts/emulator/beam/module.c index 57a43c89f4..91e4ccce70 100644 --- a/erts/emulator/beam/module.c +++ b/erts/emulator/beam/module.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1996-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -66,12 +66,8 @@ static Module* module_alloc(Module* tmpl) obj->code_length = 0; obj->old_code_length = 0; obj->slot.index = -1; - obj->nif.handle = NULL; - obj->old_nif.handle = NULL; - obj->nif.entry = NULL; - obj->old_nif.entry = NULL; - obj->nif.data = NULL; - obj->old_nif.data = NULL; + obj->nif = NULL; + obj->old_nif = NULL; return obj; } diff --git a/erts/emulator/beam/module.h b/erts/emulator/beam/module.h index 314be8e2ee..87d13b3607 100644 --- a/erts/emulator/beam/module.h +++ b/erts/emulator/beam/module.h @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1996-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -24,11 +24,6 @@ #include "index.h" #endif -struct erl_module_nif { - void* handle; - struct enif_entry_t* entry; - void* data; -}; typedef struct erl_module { IndexSlot slot; /* Must be located at top of struct! */ @@ -39,8 +34,8 @@ typedef struct erl_module { int code_length; /* Length of loaded code in bytes. */ int old_code_length; /* Length of old loaded code in bytes */ unsigned catches, old_catches; - struct erl_module_nif nif; - struct erl_module_nif old_nif; + struct erl_module_nif* nif; + struct erl_module_nif* old_nif; } Module; Module* erts_get_module(Eterm mod); diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c index 687e6fa67b..31efddc0f2 100644 --- a/erts/emulator/beam/utils.c +++ b/erts/emulator/beam/utils.c @@ -124,26 +124,28 @@ erts_heap_alloc(Process* p, Uint need) #endif /* FORCE_HEAP_FRAGS */ n = need; + bp = MBUF(p); + if (bp != NULL && need <= (bp->size - bp->used_size)) { + Eterm* ret = bp->mem + bp->used_size; + bp->used_size += need; + return ret; + } #ifdef DEBUG n++; #endif bp = (ErlHeapFragment*) ERTS_HEAP_ALLOC(ERTS_ALC_T_HEAP_FRAG, ERTS_HEAP_FRAG_SIZE(n)); -#ifdef DEBUG - n--; -#endif - -#if defined(DEBUG) - for (i = 0; i <= n; i++) { - bp->mem[i] = ERTS_HOLE_MARKER; - } -#elif defined(CHECK_FOR_HOLES) +#if defined(DEBUG) || defined(CHECK_FOR_HOLES) for (i = 0; i < n; i++) { bp->mem[i] = ERTS_HOLE_MARKER; } #endif +#ifdef DEBUG + n--; +#endif + /* * When we have created a heap fragment, we are no longer allowed * to store anything more on the heap. diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c index 5291374e25..b0abfd2310 100644 --- a/erts/emulator/hipe/hipe_bif0.c +++ b/erts/emulator/hipe/hipe_bif0.c @@ -16,7 +16,7 @@ * * %CopyrightEnd% */ -/* $Id$ +/* * hipe_bif0.c * * Compiler and linker support. diff --git a/erts/emulator/test/nif_SUITE.erl b/erts/emulator/test/nif_SUITE.erl index e47161fcbc..522caec8f1 100644 --- a/erts/emulator/test/nif_SUITE.erl +++ b/erts/emulator/test/nif_SUITE.erl @@ -1,38 +1,50 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2009-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(nif_SUITE). %%-define(line_trace,true). +%%-define(CHECK(Exp,Got), ?line check(Exp,Got,?LINE)). +-define(CHECK(Exp,Got), ?line Exp = Got). -include("test_server.hrl"). -export([all/1, fin_per_testcase/2, basic/1, reload/1, upgrade/1, heap_frag/1, - types/1, many_args/1, neg/1]). + types/1, many_args/1, binaries/1, get_string/1, get_atom/1, api_macros/1, + from_array/1, iolist_as_binary/1, resource/1, resource_takeover/1, + threading/1, neg/1]). -export([many_args_100/100]). -define(nif_stub,nif_stub_error(?LINE)). all(suite) -> - [basic, reload, upgrade, heap_frag, types, many_args, neg]. + [basic, reload, upgrade, heap_frag, types, many_args, binaries, get_string, + get_atom, api_macros, from_array, iolist_as_binary, resource, + resource_takeover, threading, neg]. + +%%init_per_testcase(_Case, Config) -> +%% ?line Dog = ?t:timetrap(?t:seconds(60*60*24)), +%% [{watchdog, Dog}|Config]. fin_per_testcase(_Func, _Config) -> + %%Dog = ?config(watchdog, Config), + %%?t:timetrap_cancel(Dog), P1 = code:purge(nif_mod), Del = code:delete(nif_mod), P2 = code:purge(nif_mod), @@ -51,6 +63,7 @@ basic(Config) when is_list(Config) -> reload(doc) -> ["Test reload callback in nif lib"]; reload(suite) -> []; reload(Config) when is_list(Config) -> + TmpMem = tmpmem(), ensure_lib_loaded(Config), ?line Data = ?config(data_dir, Config), @@ -58,16 +71,16 @@ reload(Config) when is_list(Config) -> ?line {ok,nif_mod,Bin} = compile:file(File, [binary,return_errors]), ?line {module,nif_mod} = erlang:load_module(nif_mod,Bin), - ?line nif_mod:load_nif_lib(Config, 1), + ?line ok = nif_mod:load_nif_lib(Config, 1), ?line hold_nif_mod_priv_data(nif_mod:get_priv_data_ptr()), ?line [{load,1,1,101},{get_priv_data_ptr,1,2,102}] = nif_mod_call_history(), - ?line nif_mod:load_nif_lib(Config, 2), + ?line ok = nif_mod:load_nif_lib(Config, 2), ?line 2 = nif_mod:lib_version(), ?line [{reload,2,1,201},{lib_version,2,2,202}] = nif_mod_call_history(), - ?line nif_mod:load_nif_lib(Config, 1), + ?line ok = nif_mod:load_nif_lib(Config, 1), ?line 1 = nif_mod:lib_version(), ?line [{reload,1,1,101},{lib_version,1,2,102}] = nif_mod_call_history(), @@ -79,11 +92,13 @@ reload(Config) when is_list(Config) -> ?line [{unload,1,3,103}] = nif_mod_call_history(), ?line [?MODULE, nif_mod] = erlang:system_info(taints), + ?line verify_tmpmem(TmpMem), ok. upgrade(doc) -> ["Test upgrade callback in nif lib"]; upgrade(suite) -> []; upgrade(Config) when is_list(Config) -> + TmpMem = tmpmem(), ensure_lib_loaded(Config), ?line Data = ?config(data_dir, Config), @@ -91,7 +106,7 @@ upgrade(Config) when is_list(Config) -> ?line {ok,nif_mod,Bin} = compile:file(File, [binary,return_errors]), ?line {module,nif_mod} = erlang:load_module(nif_mod,Bin), - ?line nif_mod:load_nif_lib(Config, 1), + ?line ok = nif_mod:load_nif_lib(Config, 1), ?line {Pid,MRef} = nif_mod:start(), ?line 1 = call(Pid,lib_version), @@ -104,7 +119,7 @@ upgrade(Config) when is_list(Config) -> ?line 1 = call(Pid,lib_version), ?line [{lib_version,1,4,104}] = nif_mod_call_history(), - ?line nif_mod:load_nif_lib(Config, 1), + ?line ok = nif_mod:load_nif_lib(Config, 1), ?line 1 = nif_mod:lib_version(), ?line [{upgrade,1,5,105},{lib_version,1,6,106}] = nif_mod_call_history(), @@ -131,7 +146,7 @@ upgrade(Config) when is_list(Config) -> ?line {Pid2,MRef2} = nif_mod:start(), ?line undefined = call(Pid2,lib_version), - ?line nif_mod:load_nif_lib(Config, 1), + ?line ok = nif_mod:load_nif_lib(Config, 1), ?line hold_nif_mod_priv_data(nif_mod:get_priv_data_ptr()), ?line 1 = call(Pid2,lib_version), ?line [{load,1,1,101},{get_priv_data_ptr,1,2,102},{lib_version,1,3,103}] = nif_mod_call_history(), @@ -142,7 +157,7 @@ upgrade(Config) when is_list(Config) -> ?line 1 = call(Pid2,lib_version), ?line [{lib_version,1,4,104}] = nif_mod_call_history(), - ?line nif_mod:load_nif_lib(Config, 2), + ?line ok = nif_mod:load_nif_lib(Config, 2), ?line 2 = nif_mod:lib_version(), ?line [{upgrade,2,1,201},{lib_version,2,2,202}] = nif_mod_call_history(), @@ -167,14 +182,17 @@ upgrade(Config) when is_list(Config) -> ?line [{unload,2,4,204}] = nif_mod_call_history(), ?line [?MODULE, nif_mod] = erlang:system_info(taints), + ?line verify_tmpmem(TmpMem), ok. heap_frag(doc) -> ["Test NIF building heap fragments"]; heap_frag(suite) -> []; heap_frag(Config) when is_list(Config) -> + TmpMem = tmpmem(), ensure_lib_loaded(Config), heap_frag_do(1,1000000), + ?line verify_tmpmem(TmpMem), ok. heap_frag_do(N, Max) when N > Max -> @@ -188,6 +206,7 @@ heap_frag_do(N, Max) -> types(doc) -> ["Type tests"]; types(suite) -> []; types(Config) when is_list(Config) -> + TmpMem = tmpmem(), ensure_lib_loaded(Config), ?line ok = type_test(), lists:foreach(fun(Tpl) -> @@ -197,6 +216,7 @@ types(Config) when is_list(Config) -> [{},{ok},{{}},{[],{}},{1,2,3,4,5}]), Stuff = [[],{},0,0.0,(1 bsl 100),(fun()-> ok end),make_ref(),self()], [eq_cmp(A,clone(B)) || A<-Stuff, B<-Stuff], + ?line verify_tmpmem(TmpMem), ok. clone(X) -> @@ -227,17 +247,506 @@ eq_cmp_do(A,B) -> many_args(doc) -> ["Test NIF with many arguments"]; many_args(suite) -> []; many_args(Config) when is_list(Config) -> + TmpMem = tmpmem(), ?line ensure_lib_loaded(Config ,1), ?line ok = apply(?MODULE,many_args_100,lists:seq(1,100)), ?line ok = many_args_100(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100), + ?line verify_tmpmem(TmpMem), ok. - +binaries(doc) -> ["Test NIF binary handling."]; +binaries(suite) -> []; +binaries(Config) when is_list(Config) -> + TmpMem = tmpmem(), + ?line ensure_lib_loaded(Config, 1), + ?line RefcBin = list_to_binary(lists:seq(1,255)), + ?line RefcBin = clone_bin(RefcBin), + ?line HeapBin = list_to_binary(lists:seq(1,20)), + ?line HeapBin = clone_bin(HeapBin), + ?line <<_:8,Sub1:6/binary,_/binary>> = RefcBin, + ?line <<_:8,Sub2:6/binary,_/binary>> = HeapBin, + ?line Sub1 = Sub2, + ?line Sub1 = clone_bin(Sub1), + ?line Sub2 = clone_bin(Sub2), + ?line <<_:9,Sub3:6/binary,_/bitstring>> = RefcBin, + ?line <<_:9,Sub4:6/binary,_/bitstring>> = HeapBin, + ?line Sub3 = Sub4, + ?line Sub3 = clone_bin(Sub3), + ?line Sub4 = clone_bin(Sub4), + %% When NIFs get bitstring support + %%?line <<_:8,Sub5:27/bitstring,_/bitstring>> = RefcBin, + %%?line <<_:8,Sub6:27/bitstring,_/bitstring>> = HeapBin, + %%?line Sub5 = Sub6, + %%?line Sub5 = clone_bin(Sub5), + %%?line Sub6 = clone_bin(Sub6), + %%?line <<_:9,Sub7:27/bitstring,_/bitstring>> = RefcBin, + %%?line <<_:9,Sub8:27/bitstring,_/bitstring>> = HeapBin, + %%?line Sub7 = Sub8, + %%?line Sub7 = clone_bin(Sub7), + %%?line Sub8 = clone_bin(Sub8), + %%?line <<>> = clone_bin(<<>>), + + <<_:8,SubBinA:200/binary,_/binary>> = RefcBin, + <<_:9,SubBinB:200/binary,_/bitstring>> = RefcBin, + <<_:8,SubBinC:17/binary,_/binary>> = HeapBin, + <<_:9,SubBinD:17/binary,_/bitstring>> = HeapBin, + test_make_sub_bin(RefcBin), + test_make_sub_bin(HeapBin), + test_make_sub_bin(SubBinA), + test_make_sub_bin(SubBinB), + test_make_sub_bin(SubBinC), + test_make_sub_bin(SubBinD), + + ?line verify_tmpmem(TmpMem), + ok. + +test_make_sub_bin(Bin) -> + Size = byte_size(Bin), + Rest10 = Size - 10, + Rest1 = Size - 1, + ?line Bin = make_sub_bin(Bin, 0, Size), + <<_:10/binary,Sub0:Rest10/binary>> = Bin, + ?line Sub0 = make_sub_bin(Bin, 10, Rest10), + <<Sub1:10/binary,_/binary>> = Bin, + ?line Sub1 = make_sub_bin(Bin, 0, 10), + <<_:7/binary,Sub2:10/binary,_/binary>> = Bin, + ?line Sub2 = make_sub_bin(Bin, 7, 10), + ?line <<>> = make_sub_bin(Bin, 0, 0), + ?line <<>> = make_sub_bin(Bin, 10, 0), + ?line <<>> = make_sub_bin(Bin, Rest1, 0), + ?line <<>> = make_sub_bin(Bin, Size, 0), + ok. + +get_string(doc) -> ["Test enif_get_string"]; +get_string(suite) -> []; +get_string(Config) when is_list(Config) -> + ?line ensure_lib_loaded(Config, 1), + ?line {7, <<"hejsan",0,_:3/binary>>} = string_to_bin("hejsan",10), + ?line {7, <<"hejsan",0,_>>} = string_to_bin("hejsan",8), + ?line {7, <<"hejsan",0>>} = string_to_bin("hejsan",7), + ?line {-6, <<"hejsa",0>>} = string_to_bin("hejsan",6), + ?line {-5, <<"hejs",0>>} = string_to_bin("hejsan",5), + ?line {-1, <<0>>} = string_to_bin("hejsan",1), + ?line {0, <<>>} = string_to_bin("hejsan",0), + ?line {1, <<0>>} = string_to_bin("",1), + ?line {0, <<>>} = string_to_bin("",0), + ok. + +get_atom(doc) -> ["Test enif_get_atom"]; +get_atom(suite) -> []; +get_atom(Config) when is_list(Config) -> + ?line ensure_lib_loaded(Config, 1), + ?line {7, <<"hejsan",0,_:3/binary>>} = atom_to_bin(hejsan,10), + ?line {7, <<"hejsan",0,_>>} = atom_to_bin(hejsan,8), + ?line {7, <<"hejsan",0>>} = atom_to_bin(hejsan,7), + ?line {0, <<_:6/binary>>} = atom_to_bin(hejsan,6), + ?line {0, <<>>} = atom_to_bin(hejsan,0), + ?line {1, <<0>>} = atom_to_bin('',1), + ?line {0, <<>>} = atom_to_bin('',0), + ok. + +api_macros(doc) -> ["Test macros enif_make_list<N> and enif_make_tuple<N>"]; +api_macros(suite) -> []; +api_macros(Config) when is_list(Config) -> + ?line ensure_lib_loaded(Config, 1), + Expected = {[lists:seq(1,N) || N <- lists:seq(1,9)], + [list_to_tuple(lists:seq(1,N)) || N <- lists:seq(1,9)] + }, + ?line Expected = macros(list_to_tuple(lists:seq(1,9))), + ok. + +from_array(doc) -> ["enif_make_[tuple|list]_from_array"]; +from_array(suite) -> []; +from_array(Config) when is_list(Config) -> + ?line ensure_lib_loaded(Config, 1), + lists:foreach(fun(Tpl) -> + Lst = tuple_to_list(Tpl), + ?line {Lst,Tpl} = tuple_2_list_and_tuple(Tpl) + end, + [{}, {1,2,3}, {[4,5],[],{},{6,7}}, {{}}, {[]}]), + ok. + +iolist_as_binary(doc) -> ["enif_inspect_iolist_as_binary"]; +iolist_as_binary(suite) -> []; +iolist_as_binary(Config) when is_list(Config) -> + ?line ensure_lib_loaded(Config, 1), + TmpMem = tmpmem(), + List = [<<"hejsan">>, <<>>, [], [17], [<<>>], + [127,128,255,0], + [1, 2, 3, <<"abc">>, [<<"def">>,4], 5, <<"ghi">>], + [1, 2, 3, <<"abc">>, [<<"def">>,4], 5 | <<"ghi">>]], + + lists:foreach(fun(IoL) -> + B1 = erlang:iolist_to_binary(IoL), + ?line B2 = iolist_2_bin(IoL), + ?line B1 = B2 + end, + List), + ?line verify_tmpmem(TmpMem), + ok. + +resource(doc) -> ["Test memory managed objects, aka 'resources'"]; +resource(suite) -> []; +resource(Config) when is_list(Config) -> + ?line ensure_lib_loaded(Config, 1), + ?line Type = get_resource_type(0), + resource_hugo(Type), + resource_otto(Type), + resource_new(Type), + resource_neg(Type), + ok. + +resource_hugo(Type) -> + DtorCall = resource_hugo_do(Type), + erlang:garbage_collect(), + ?line DtorCall = last_resource_dtor_call(), + ok. + +resource_hugo_do(Type) -> + HugoBin = <<"Hugo Hacker">>, + ?line HugoPtr = alloc_resource(Type, HugoBin), + ?line Hugo = make_resource(HugoPtr), + ?line <<>> = Hugo, + release_resource(HugoPtr), + erlang:garbage_collect(), + ?line {HugoPtr,HugoBin} = get_resource(Type,Hugo), + Pid = spawn_link(fun() -> + receive {Pid, Type, Resource, Ptr, Bin} -> + Pid ! {self(), got_it}, + receive {Pid, check_it} -> + ?line {Ptr,Bin} = get_resource(Type,Resource), + Pid ! {self(), ok} + end + end + end), + Pid ! {self(), Type, Hugo, HugoPtr, HugoBin}, + ?line {Pid, got_it} = receive_any(), + erlang:garbage_collect(), % just to make our ProcBin move in memory + Pid ! {self(), check_it}, + ?line {Pid, ok} = receive_any(), + ?line [] = last_resource_dtor_call(), + ?line {HugoPtr,HugoBin} = get_resource(Type,Hugo), + {HugoPtr, HugoBin, 1}. + +resource_otto(Type) -> + {OttoPtr, OttoBin} = resource_otto_do(Type), + erlang:garbage_collect(), + ?line [] = last_resource_dtor_call(), + release_resource(OttoPtr), + ?line {OttoPtr,OttoBin,1} = last_resource_dtor_call(), + ok. + +resource_otto_do(Type) -> + OttoBin = <<"Otto Ordonnans">>, + ?line OttoPtr = alloc_resource(Type, OttoBin), + ?line Otto = make_resource(OttoPtr), + ?line <<>> = Otto, + %% forget resource term but keep referenced by NIF + {OttoPtr, OttoBin}. + +resource_new(Type) -> + ?line {PtrB,BinB} = resource_new_do1(Type), + erlang:garbage_collect(), + ?line {PtrB,BinB,1} = last_resource_dtor_call(), + ok. + +resource_new_do1(Type) -> + ?line {{PtrA,BinA}, {ResB,PtrB,BinB}} = resource_new_do2(Type), + erlang:garbage_collect(), + ?line {PtrA,BinA,1} = last_resource_dtor_call(), + ?line {PtrB,BinB} = get_resource(Type, ResB), + %% forget ResB and make it garbage + {PtrB,BinB}. + +resource_new_do2(Type) -> + BinA = <<"NewA">>, + BinB = <<"NewB">>, + ?line ResA = make_new_resource(Type, BinA), + ?line ResB = make_new_resource(Type, BinB), + ?line <<>> = ResA, + ?line <<>> = ResB, + ?line {PtrA,BinA} = get_resource(Type, ResA), + ?line {PtrB,BinB} = get_resource(Type, ResB), + ?line true = (PtrA =/= PtrB), + ?line [] = last_resource_dtor_call(), + %% forget ResA and make it garbage + {{PtrA,BinA}, {ResB,PtrB,BinB}}. + +resource_neg(TypeA) -> + TypeB = get_resource_type(1), + Aptr = alloc_resource(TypeA, <<"Arnold">>), + Bptr = alloc_resource(TypeB, <<"Bobo">>), + ?line {'EXIT',{badarg,_}} = (catch get_resource(TypeA, Bptr)), + ?line {'EXIT',{badarg,_}} = (catch get_resource(TypeB, Aptr)), + ok. +-define(RT_CREATE,1). +-define(RT_TAKEOVER,2). + +resource_takeover(doc) -> ["Test resource takeover by module reload and upgrade"]; +resource_takeover(suite) -> []; +resource_takeover(Config) when is_list(Config) -> + TmpMem = tmpmem(), + ensure_lib_loaded(Config), + + ?line Data = ?config(data_dir, Config), + ?line File = filename:join(Data, "nif_mod"), + ?line {ok,nif_mod,ModBin} = compile:file(File, [binary,return_errors]), + ?line {module,nif_mod} = erlang:load_module(nif_mod,ModBin), + + ?line ok = nif_mod:load_nif_lib(Config, 1, + [{resource_type, 0, ?RT_CREATE, "resource_type_A",resource_dtor_A, + ?RT_CREATE}, + {resource_type, 1, ?RT_CREATE, "resource_type_null_A",null, + ?RT_CREATE}, + {resource_type, 2, ?RT_CREATE bor ?RT_TAKEOVER, "resource_type_A_null",resource_dtor_A, + ?RT_CREATE}, + {resource_type, 3, ?RT_CREATE, "resource_type_B_goneX",resource_dtor_B, + ?RT_CREATE}, + {resource_type, 4, ?RT_CREATE, "resource_type_null_goneX",null, + ?RT_CREATE}, + {resource_type, null, ?RT_TAKEOVER, "Pink unicorn", resource_dtor_A, + ?RT_TAKEOVER} + ]), + + ?line hold_nif_mod_priv_data(nif_mod:get_priv_data_ptr()), + ?line [{load,1,1,101},{get_priv_data_ptr,1,2,102}] = nif_mod_call_history(), + + ?line {Holder, _MRef} = spawn_opt(fun resource_holder/0, [link, monitor]), + + {A1,BinA1} = make_resource(0,Holder,"A1"), + {A2,BinA2} = make_resource(0,Holder,"A2"), + {A3,BinA3} = make_resource(0,Holder,"A3"), + + {NA1,_BinNA1} = make_resource(1,Holder,"NA1"), + {NA2,BinNA2} = make_resource(1,Holder,"NA2"), + {NA3,_BinNA3} = make_resource(1,Holder,"NA3"), + + {AN1,BinAN1} = make_resource(2,Holder,"AN1"), + {AN2,_BinAN2} = make_resource(2,Holder,"AN2"), + {AN3,BinAN3} = make_resource(2,Holder,"AN3"), + + {BGX1,BinBGX1} = make_resource(3,Holder,"BGX1"), + {BGX2,BinBGX2} = make_resource(3,Holder,"BGX2"), + + {NGX1,_BinNGX1} = make_resource(4,Holder,"NGX1"), + {NGX2,_BinNGX2} = make_resource(4,Holder,"NGX2"), + + ?line [] = nif_mod_call_history(), + + ?line ok = forget_resource(A1), + ?line [{{resource_dtor_A_v1,BinA1},1,3,103}] = nif_mod_call_history(), + + ?line ok = forget_resource(NA1), + ?line [] = nif_mod_call_history(), % no dtor + + ?line ok = forget_resource(AN1), + ?CHECK([{{resource_dtor_A_v1,BinAN1},1,4,104}] , nif_mod_call_history()), + + ?line ok = forget_resource(BGX1), + ?CHECK([{{resource_dtor_B_v1,BinBGX1},1,5,105}], nif_mod_call_history()), + + ?line ok = forget_resource(NGX1), + ?CHECK([], nif_mod_call_history()), % no dtor + + ?line ok = nif_mod:load_nif_lib(Config, 2, + [{resource_type, 0, ?RT_TAKEOVER, "resource_type_A",resource_dtor_A, + ?RT_TAKEOVER}, + {resource_type, 1, ?RT_TAKEOVER bor ?RT_CREATE, "resource_type_null_A",resource_dtor_A, + ?RT_TAKEOVER}, + {resource_type, 2, ?RT_TAKEOVER, "resource_type_A_null",null, + ?RT_TAKEOVER}, + {resource_type, null, ?RT_TAKEOVER, "Pink unicorn", resource_dtor_A, + ?RT_TAKEOVER}, + {resource_type, null, ?RT_CREATE, "resource_type_B_goneX",resource_dtor_B, + ?RT_CREATE}, + {resource_type, null, ?RT_CREATE, "resource_type_null_goneX",null, + ?RT_CREATE}, + {resource_type, 3, ?RT_CREATE, "resource_type_B_goneY",resource_dtor_B, + ?RT_CREATE}, + {resource_type, 4, ?RT_CREATE, "resource_type_null_goneY",null, + ?RT_CREATE} + ]), + ?CHECK([{reload,2,1,201}], nif_mod_call_history()), + + ?line BinA2 = read_resource(0,A2), + ?line ok = forget_resource(A2), + ?CHECK([{{resource_dtor_A_v2,BinA2},2,2,202}], nif_mod_call_history()), + + ?line ok = forget_resource(NA2), + ?CHECK([{{resource_dtor_A_v2,BinNA2},2,3,203}], nif_mod_call_history()), + + ?line ok = forget_resource(AN2), + ?CHECK([], nif_mod_call_history()), % no dtor + + ?line ok = forget_resource(BGX2), % calling dtor in orphan library v1 still loaded + ?CHECK([{{resource_dtor_B_v1,BinBGX2},1,6,106}], nif_mod_call_history()), + % How to test that lib v1 is closed here? + + ?line ok = forget_resource(NGX2), + ?CHECK([], nif_mod_call_history()), % no dtor + + {BGY1,BinBGY1} = make_resource(3,Holder,"BGY1"), + {NGY1,_BinNGY1} = make_resource(4,Holder,"NGY1"), + + %% Module upgrade with same lib-version + ?line {module,nif_mod} = erlang:load_module(nif_mod,ModBin), + ?line undefined = nif_mod:lib_version(), + ?line ok = nif_mod:load_nif_lib(Config, 2, + [{resource_type, 2, ?RT_TAKEOVER, "resource_type_A",resource_dtor_B, + ?RT_TAKEOVER}, + {resource_type, 0, ?RT_TAKEOVER bor ?RT_CREATE, "resource_type_null_A",null, + ?RT_TAKEOVER}, + {resource_type, 1, ?RT_TAKEOVER, "resource_type_A_null",resource_dtor_A, + ?RT_TAKEOVER}, + {resource_type, null, ?RT_TAKEOVER, "Pink elephant", resource_dtor_A, + ?RT_TAKEOVER}, + {resource_type, 3, ?RT_CREATE, "resource_type_B_goneZ",resource_dtor_B, + ?RT_CREATE}, + {resource_type, 4, ?RT_CREATE, "resource_type_null_goneZ",null, + ?RT_CREATE} + ]), + + ?line 2 = nif_mod:lib_version(), + ?CHECK([{upgrade,2,4,204},{lib_version,2,5,205}], nif_mod_call_history()), + + ?line ok = forget_resource(A3), + ?CHECK([{{resource_dtor_B_v2,BinA3},2,6,206}], nif_mod_call_history()), + + ?line ok = forget_resource(NA3), + ?CHECK([], nif_mod_call_history()), + + ?line ok = forget_resource(AN3), + ?CHECK([{{resource_dtor_A_v2,BinAN3},2,7,207}], nif_mod_call_history()), + + {A4,BinA4} = make_resource(2,Holder, "A4"), + {NA4,BinNA4} = make_resource(0,Holder, "NA4"), + {AN4,_BinAN4} = make_resource(1,Holder, "AN4"), + + {BGZ1,BinBGZ1} = make_resource(3,Holder,"BGZ1"), + {NGZ1,_BinNGZ1} = make_resource(4,Holder,"NGZ1"), + + ?line false = code:purge(nif_mod), + ?line [] = nif_mod_call_history(), + + ?line ok = forget_resource(NGY1), + ?line [] = nif_mod_call_history(), + + ?line ok = forget_resource(BGY1), % calling dtor in orphan library v2 still loaded + ?line [{{resource_dtor_B_v2,BinBGY1},2,8,208},{unload,2,9,209}] = nif_mod_call_history(), + + %% Module upgrade with other lib-version + ?line {module,nif_mod} = erlang:load_module(nif_mod,ModBin), + ?line undefined = nif_mod:lib_version(), + ?line ok = nif_mod:load_nif_lib(Config, 1, + [{resource_type, 2, ?RT_TAKEOVER, "resource_type_A",resource_dtor_A, + ?RT_TAKEOVER}, + {resource_type, 0, ?RT_TAKEOVER bor ?RT_CREATE, "resource_type_null_A",resource_dtor_A, + ?RT_TAKEOVER}, + {resource_type, 1, ?RT_TAKEOVER, "resource_type_A_null",null, + ?RT_TAKEOVER}, + {resource_type, null, ?RT_TAKEOVER, "Mr Pink", resource_dtor_A, + ?RT_TAKEOVER} + ]), + + ?line 1 = nif_mod:lib_version(), + ?line [{upgrade,1,1,101},{lib_version,1,2,102}] = nif_mod_call_history(), + + %%?line false= check_process_code(Pid, nif_mod), + ?line false = code:purge(nif_mod), + %% no unload here as we still have instances with destructors + ?line [] = nif_mod_call_history(), + + ?line ok = forget_resource(BGZ1), % calling dtor in orphan library v2 still loaded + ?line [{{resource_dtor_B_v2,BinBGZ1},2,10,210},{unload,2,11,211}] = nif_mod_call_history(), + + ?line ok = forget_resource(NGZ1), + ?line [] = nif_mod_call_history(), + + ?line ok = forget_resource(A4), + ?line [{{resource_dtor_A_v1,BinA4},1,3,103}] = nif_mod_call_history(), + + ?line ok = forget_resource(NA4), + ?line [{{resource_dtor_A_v1,BinNA4},1,4,104}] = nif_mod_call_history(), + ?line ok = forget_resource(AN4), + ?line [] = nif_mod_call_history(), + + ?line [?MODULE, nif_mod] = erlang:system_info(taints), + ?line verify_tmpmem(TmpMem), + ok. + +make_resource(Type,Holder,Str) when is_list(Str) -> + Bin = list_to_binary(Str), + A1 = make_resource_do(Type,Holder,Bin), + ?line Bin = read_resource(Type,A1), + {A1,Bin}. + +make_resource_do(Type, Holder, Bin) -> + Holder ! {self(), make, Type, Bin}, + {Holder, make_ok, Id} = receive_any(), + {Holder,Id}. + +read_resource(Type, {Holder,Id}) -> + Holder ! {self(), get, Type, Id}, + {Holder, get_ok, Bin} = receive_any(), + Bin. + +forget_resource({Holder,Id}) -> + Holder ! {self(), forget, Id}, + {Holder, forget_ok, Id} = receive_any(), + ok. + + +resource_holder() -> + resource_holder([]). +resource_holder(List) -> + %%io:format("resource_holder waiting for msg\n", []), + Msg = receive_any(), + %%io:format("resource_holder got ~p with list = ~p\n", [Msg,List]), + case Msg of + {Pid, make, Type, Bin} -> + ?line Resource = nif_mod:make_new_resource(Type, Bin), + Id = {make_ref(),Bin}, + Pid ! {self(), make_ok, Id}, + resource_holder([{Id,Resource} | List]); + {Pid, get, Type, Id} -> + {Id,Resource} = lists:keyfind(Id, 1, List), + Pid ! {self(), get_ok, nif_mod:get_resource(Type, Resource)}, + resource_holder(List); + + {Pid, forget, Id} -> + NewList = lists:keydelete(Id, 1, List), + %%io:format("resource_holder forget: NewList = ~p\n", [NewList]), + resource_holder(Pid, {self(),forget_ok,Id}, NewList) + end. + +resource_holder(Pid,Reply,List) -> + erlang:garbage_collect(), + %%io:format("resource_holder GC'ed, now send ~p to ~p\n", [Reply,Pid]), + Pid ! Reply, + resource_holder(List). + + +threading(doc) -> ["Test the threading API functions (reuse tests from driver API)"]; +threading(Config) when is_list(Config) -> + ?line Data = ?config(data_dir, Config), + ?line File = filename:join(Data, "tester"), + ?line {ok,tester,ModBin} = compile:file(File, [binary,return_errors]), + ?line {module,tester} = erlang:load_module(tester,ModBin), + + ?line ok = tester:load_nif_lib(Config, "basic"), + ?line ok = tester:run(), + + ?line ok = tester:load_nif_lib(Config, "rwlock"), + ?line ok = tester:run(), + + ?line ok = tester:load_nif_lib(Config, "tsd"), + ?line ok = tester:run(). + neg(doc) -> ["Negative testing of load_nif"]; -neg(suite) -> []; neg(Config) when is_list(Config) -> + TmpMem = tmpmem(), ?line {'EXIT',{badarg,_}} = (catch erlang:load_nif(badarg, 0)), ?line {error,{load_failed,_}} = erlang:load_nif("pink_unicorn", 0), @@ -247,23 +756,61 @@ neg(Config) when is_list(Config) -> ?line {module,nif_mod} = erlang:load_module(nif_mod,Bin), ?line {error,{bad_lib,_}} = nif_mod:load_nif_lib(Config, no_init), + ?line verify_tmpmem(TmpMem), ?line ok. ensure_lib_loaded(Config) -> ensure_lib_loaded(Config, 1). - ensure_lib_loaded(Config, Ver) -> ?line case lib_version() of undefined -> ?line Path = ?config(data_dir, Config), ?line Lib = "nif_SUITE." ++ integer_to_list(Ver), - ?line ok = erlang:load_nif(filename:join(Path,Lib), 0); + ?line ok = erlang:load_nif(filename:join(Path,Lib), []); Ver when is_integer(Ver) -> ok end. +tmpmem() -> + case erlang:system_info({allocator,temp_alloc}) of + false -> undefined; + MemInfo -> + MSBCS = lists:foldl( + fun ({instance, _, L}, Acc) -> + {value,{_,MBCS}} = lists:keysearch(mbcs, 1, L), + {value,{_,SBCS}} = lists:keysearch(sbcs, 1, L), + [MBCS,SBCS | Acc] + end, + [], + MemInfo), + lists:foldl( + fun(L, {Bl0,BlSz0}) -> + {value,{_,Bl,_,_}} = lists:keysearch(blocks, 1, L), + {value,{_,BlSz,_,_}} = lists:keysearch(blocks_size, 1, L), + {Bl0+Bl,BlSz0+BlSz} + end, {0,0}, MSBCS) + end. + +verify_tmpmem(MemInfo) -> + %%wait_for_test_procs(), + case tmpmem() of + MemInfo -> + io:format("Tmp mem info: ~p", [MemInfo]), + case MemInfo of + {notsup,undefined} -> + %% Use 'erl +Mea max' to do more complete memory leak testing. + {comment,"Incomplete or no mem leak testing"}; + _ -> + ok + end; + Other -> + io:format("Expected: ~p", [MemInfo]), + io:format("Actual: ~p", [Other]), + ?t:fail() + end. + call(Pid,Cmd) -> %%io:format("~p calling ~p with ~p\n",[self(), Pid, Cmd]), Pid ! {self(), Cmd}, @@ -274,6 +821,15 @@ call(Pid,Cmd) -> receive_any() -> receive M -> M end. +%% check(Exp,Got,Line) -> +%% case Got of +%% Exp -> Exp; +%% _ -> +%% io:format("CHECK at ~p: Expected ~p but got ~p\n",[Line,Exp,Got]), +%% Got +%% end. + + %% The NIFs: lib_version() -> undefined. call_history() -> ?nif_stub. @@ -285,6 +841,20 @@ tuple_2_list(_) -> ?nif_stub. is_identical(_,_) -> ?nif_stub. compare(_,_) -> ?nif_stub. many_args_100(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_) -> ?nif_stub. - +clone_bin(_) -> ?nif_stub. +make_sub_bin(_,_,_) -> ?nif_stub. +string_to_bin(_,_) -> ?nif_stub. +atom_to_bin(_,_) -> ?nif_stub. +macros(_) -> ?nif_stub. +tuple_2_list_and_tuple(_) -> ?nif_stub. +iolist_2_bin(_) -> ?nif_stub. +get_resource_type(_) -> ?nif_stub. +alloc_resource(_,_) -> ?nif_stub. +make_resource(_) -> ?nif_stub. +get_resource(_,_) -> ?nif_stub. +release_resource(_) -> ?nif_stub. +last_resource_dtor_call() -> ?nif_stub. +make_new_resource(_,_) -> ?nif_stub. + nif_stub_error(Line) -> exit({nif_not_loaded,module,?MODULE,line,Line}). diff --git a/erts/emulator/test/nif_SUITE_data/Makefile.src b/erts/emulator/test/nif_SUITE_data/Makefile.src index 6a8b4f1245..ab4ff77add 100644 --- a/erts/emulator/test/nif_SUITE_data/Makefile.src +++ b/erts/emulator/test/nif_SUITE_data/Makefile.src @@ -4,11 +4,22 @@ NIF_LIBS = nif_SUITE.1@dll@ \ nif_mod.2@dll@ \ nif_mod.3@dll@ -all: $(NIF_LIBS) +all: $(NIF_LIBS) basic@dll@ rwlock@dll@ tsd@dll@ @SHLIB_RULES@ $(NIF_LIBS): nif_SUITE.c nif_mod.c nif_mod.h +basic@dll@: tester.c testcase_driver.h +rwlock@dll@: tester.c testcase_driver.h + +tsd@dll@: tester.c testcase_driver.h + +DRIVER_DIR = ../erl_drv_thread_SUITE_data + +basic.c rwlock.c tsd.c: $(DRIVER_DIR)/$@ + cat head.txt > $@ + cat $(DRIVER_DIR)/$@ | sed -e 's/erl_drv_/enif_/g' -e 's/driver_/enif_/g' -e 's/ErlDrv/ErlNif/g' >> $@ + cat tail.txt >> $@ diff --git a/erts/emulator/test/nif_SUITE_data/head.txt b/erts/emulator/test/nif_SUITE_data/head.txt new file mode 100644 index 0000000000..4b9b44276f --- /dev/null +++ b/erts/emulator/test/nif_SUITE_data/head.txt @@ -0,0 +1,5 @@ +/* Do NOT edit this file!!! +** +** This is a NIF'ified COPY of the original in ../erl_drv_thread_SUITE_data/ +*/ + diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c index 4532062dce..7d05a9a880 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c +++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c @@ -15,6 +15,7 @@ typedef struct int ref_cnt; CallInfo* call_history; NifModPrivData* nif_mod; + union { ErlNifResourceType* t; long l; } rt_arr[2]; }PrivData; void add_call(ErlNifEnv* env, PrivData* data, const char* func_name) @@ -26,12 +27,29 @@ void add_call(ErlNifEnv* env, PrivData* data, const char* func_name) call->static_cntA = ++static_cntA; call->static_cntB = ++static_cntB; data->call_history = call; + call->arg = NULL; + call->arg_sz = 0; } #define ADD_CALL(FUNC_NAME) add_call(env, enif_get_data(env),FUNC_NAME) +static void* resource_dtor_last = NULL; +static unsigned resource_dtor_last_sz = 0; +static char resource_dtor_last_data[20]; +static int resource_dtor_cnt = 0; + +static void resource_dtor(ErlNifEnv* env, void* obj) +{ + resource_dtor_last = obj; + resource_dtor_cnt++; + resource_dtor_last_sz = enif_sizeof_resource(env, obj); + assert(resource_dtor_last_sz <= sizeof(resource_dtor_last_data)); + memcpy(resource_dtor_last_data, obj, resource_dtor_last_sz); +} + static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) { + /*ERL_NIF_TERM head, tail;*/ PrivData* data = enif_alloc(env, sizeof(PrivData)); assert(data != NULL); data->ref_cnt = 1; @@ -39,7 +57,26 @@ static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) data->nif_mod = NULL; add_call(env, data, "load"); - + + /* + head = load_info; + data->rt_cnt = 0; + for (head=load_info; enif_get_list_cell(env,load_info,&head,&tail); + head=tail) { + char buf[20]; + int n = enif_get_string(env,head,buf,sizeof(buf)); + assert(n > 0); + assert(i < sizeof(data->rt_arr)/sizeof(*data->rt_arr)); + data->rt_arr[data->rt_cnt++].t = enif_create_resource_type(env,buf,resource_dtor, + ERL_NIF_RT_CREATE,NULL); + } + assert(enif_is_empty_list(env,head)); + */ + data->rt_arr[0].t = enif_open_resource_type(env,"Gold",resource_dtor, + ERL_NIF_RT_CREATE,NULL); + data->rt_arr[1].t = enif_open_resource_type(env,"Silver",resource_dtor, + ERL_NIF_RT_CREATE,NULL); + *priv_data = data; return 0; } @@ -80,11 +117,19 @@ static ERL_NIF_TERM make_call_history(ErlNifEnv* env, CallInfo** headp) while (*headp != NULL) { CallInfo* call = *headp; - ERL_NIF_TERM tpl = enif_make_tuple(env, 4, - enif_make_atom(env,call->func_name), - enif_make_int(env,call->lib_ver), - enif_make_int(env,call->static_cntA), - enif_make_int(env,call->static_cntB)); + ERL_NIF_TERM func_term = enif_make_atom(env,call->func_name); + ERL_NIF_TERM tpl; + if (call->arg != NULL) { + ErlNifBinary arg_bin; + enif_alloc_binary(env, call->arg_sz, &arg_bin); + memcpy(arg_bin.data, call->arg, call->arg_sz); + func_term = enif_make_tuple2(env, func_term, + enif_make_binary(env, &arg_bin)); + } + tpl = enif_make_tuple4(env, func_term, + enif_make_int(env,call->lib_ver), + enif_make_int(env,call->static_cntA), + enif_make_int(env,call->static_cntB)); list = enif_make_list_cell(env, tpl, list); *headp = call->next; enif_free(env,call); @@ -117,11 +162,14 @@ static ERL_NIF_TERM hold_nif_mod_priv_data(ErlNifEnv* env, int argc, const ERL_N static ERL_NIF_TERM nif_mod_call_history(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { PrivData* data = (PrivData*) enif_get_data(env); - + ERL_NIF_TERM ret; if (data->nif_mod == NULL) { - return enif_make_string(env,"nif_mod pointer is NULL"); + return enif_make_string(env,"nif_mod pointer is NULL", ERL_NIF_LATIN1); } - return make_call_history(env,&data->nif_mod->call_history); + enif_mutex_lock(data->nif_mod->mtx); + ret = make_call_history(env, &data->nif_mod->call_history); + enif_mutex_unlock(data->nif_mod->mtx); + return ret; } static ERL_NIF_TERM list_seq(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) @@ -150,12 +198,34 @@ static int test_int(ErlNifEnv* env, int i1) return 1; } +static int test_uint(ErlNifEnv* env, unsigned i1) +{ + unsigned i2 = 0; + ERL_NIF_TERM int_term = enif_make_uint(env, i1); + if (!enif_get_uint(env,int_term, &i2) || i1 != i2) { + fprintf(stderr, "test_uint(%u) ...FAILED i2=%u\r\n", i1, i2); + return 0; + } + return 1; +} + +static int test_long(ErlNifEnv* env, long i1) +{ + long i2 = 0; + ERL_NIF_TERM int_term = enif_make_long(env, i1); + if (!enif_get_long(env,int_term, &i2) || i1 != i2) { + fprintf(stderr, "test_long(%ld) ...FAILED i2=%ld\r\n", i1, i2); + return 0; + } + return 1; +} + static int test_ulong(ErlNifEnv* env, unsigned long i1) { unsigned long i2 = 0; ERL_NIF_TERM int_term = enif_make_ulong(env, i1); if (!enif_get_ulong(env,int_term, &i2) || i1 != i2) { - fprintf(stderr, "SVERK: test_ulong(%lu) ...FAILED i2=%lu\r\n", i1, i2); + fprintf(stderr, "test_ulong(%lu) ...FAILED i2=%lu\r\n", i1, i2); return 0; } return 1; @@ -166,7 +236,7 @@ static int test_double(ErlNifEnv* env, double d1) double d2 = 0; ERL_NIF_TERM term = enif_make_double(env, d1); if (!enif_get_double(env,term, &d2) || d1 != d2) { - fprintf(stderr, "SVERK: test_double(%e) ...FAILED i2=%e\r\n", d1, d2); + fprintf(stderr, "test_double(%e) ...FAILED i2=%e\r\n", d1, d2); return 0; } return 1; @@ -180,32 +250,59 @@ static int test_double(ErlNifEnv* env, double d1) static ERL_NIF_TERM type_test(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { int i; - unsigned long u; + int sint; + unsigned uint; + long slong; + unsigned long ulong; double d; ERL_NIF_TERM atom, ref1, ref2; - i = INT_MIN; + sint = INT_MIN; do { - if (!test_int(env,i)) { + if (!test_int(env,sint)) { goto error; } - i += ~i / 3 + 1; - } while (i < 0); - i = INT_MAX; + sint += ~sint / 3 + 1; + } while (sint < 0); + sint = INT_MAX; do { - if (!test_int(env,i)) { + if (!test_int(env,sint)) { goto error; } - i -= i / 3 + 1; - } while (i >= 0); + sint -= sint / 3 + 1; + } while (sint >= 0); - u = ULONG_MAX; + slong = LONG_MIN; + do { + if (!test_long(env,slong)) { + goto error; + } + slong += ~slong / 3 + 1; + } while (slong < 0); + slong = LONG_MAX; + do { + if (!test_long(env,slong)) { + goto error; + } + slong -= slong / 3 + 1; + } while (slong >= 0); + + + uint = UINT_MAX; for (;;) { - if (!test_ulong(env,u)) { + if (!test_uint(env,uint)) { } - if (u == 0) break; - u -= u / 3 + 1; + if (uint == 0) break; + uint -= uint / 3 + 1; + } + ulong = ULONG_MAX; + for (;;) { + if (!test_ulong(env,ulong)) { + + } + if (ulong == 0) break; + ulong -= ulong / 3 + 1; } if (MAX_SMALL < INT_MAX) { /* 32-bit */ @@ -219,11 +316,17 @@ static ERL_NIF_TERM type_test(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[ goto error; } } + for (i=-10 ; i <= 10; i++) { + if (!test_uint(env,MAX_SMALL+i)) { + goto error; + } + } } assert((MAX_SMALL < INT_MAX) == (MIN_SMALL > INT_MIN)); - for (u=0 ; u < 10; u++) { - if (!test_ulong(env,MAX_SMALL+u) || !test_ulong(env,MAX_SMALL-u)) { + for (i=-10 ; i < 10; i++) { + if (!test_long(env,MAX_SMALL+i) || !test_ulong(env,MAX_SMALL+i) || + !test_long(env,MIN_SMALL+i)) { goto error; } } @@ -236,12 +339,12 @@ static ERL_NIF_TERM type_test(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[ if (!enif_make_existing_atom(env,"nif_SUITE", &atom) || !enif_is_identical(env,atom,enif_make_atom(env,"nif_SUITE"))) { - fprintf(stderr, "SVERK: nif_SUITE not an atom?\r\n"); + fprintf(stderr, "nif_SUITE not an atom?\r\n"); goto error; } for (i=2; i; i--) { if (enif_make_existing_atom(env,"nif_SUITE_pink_unicorn", &atom)) { - fprintf(stderr, "SVERK: pink unicorn exist?\r\n"); + fprintf(stderr, "pink unicorn exist?\r\n"); goto error; } } @@ -249,7 +352,8 @@ static ERL_NIF_TERM type_test(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[ ref2 = enif_make_ref(env); if (!enif_is_ref(env,ref1) || !enif_is_ref(env,ref2) || enif_is_identical(env,ref1,ref2) || enif_compare(env,ref1,ref2)==0) { - fprintf(stderr, "SVERK: strange refs?\r\n"); + fprintf(stderr, "strange refs?\r\n"); + goto error; } return enif_make_atom(env,"ok"); @@ -260,7 +364,7 @@ error: static ERL_NIF_TERM tuple_2_list(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { int arity = -1; - ERL_NIF_TERM* ptr; + const ERL_NIF_TERM* ptr; ERL_NIF_TERM list = enif_make_list(env,0); if (argc!=1 || !enif_get_tuple(env,argv[0],&arity,&ptr)) { @@ -304,6 +408,213 @@ badarg: return enif_make_badarg(env); } +static ERL_NIF_TERM clone_bin(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary ibin; + if (enif_inspect_binary(env,argv[0],&ibin)) { + ErlNifBinary obin; + enif_alloc_binary(env,ibin.size,&obin); + memcpy(obin.data,ibin.data,ibin.size); + /*enif_release_binary(env,&ibin);*/ + return enif_make_binary(env,&obin); + } + else { + return enif_make_badarg(env); + } +} + +static ERL_NIF_TERM make_sub_bin(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + int pos, size; + if (!enif_get_int(env,argv[1],&pos) || !enif_get_int(env,argv[2],&size)) { + return enif_make_badarg(env); + } + return enif_make_sub_binary(env,argv[0],pos,size); +} + +static ERL_NIF_TERM string_to_bin(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary obin; + unsigned size; + int n; + if (!enif_get_int(env,argv[1],(int*)&size) + || !enif_alloc_binary(env,size,&obin)) { + return enif_make_badarg(env); + } + n = enif_get_string(env, argv[0], (char*)obin.data, size, ERL_NIF_LATIN1); + return enif_make_tuple(env, 2, enif_make_int(env,n), + enif_make_binary(env,&obin)); +} + +static ERL_NIF_TERM atom_to_bin(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary obin; + unsigned size; + int n; + if (!enif_get_int(env,argv[1],(int*)&size) + || !enif_alloc_binary(env,size,&obin)) { + return enif_make_badarg(env); + } + n = enif_get_atom(env, argv[0], (char*)obin.data, size); + return enif_make_tuple(env, 2, enif_make_int(env,n), + enif_make_binary(env,&obin)); +} + +static ERL_NIF_TERM macros(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + const ERL_NIF_TERM* a; + ERL_NIF_TERM lists, tuples; + int arity; + if (!enif_get_tuple(env, argv[0], &arity, &a) || arity != 9) { + return enif_make_badarg(env); + } + + lists = enif_make_list(env,9, + enif_make_list1(env,a[0]), + enif_make_list2(env,a[0],a[1]), + enif_make_list3(env,a[0],a[1],a[2]), + enif_make_list4(env,a[0],a[1],a[2],a[3]), + enif_make_list5(env,a[0],a[1],a[2],a[3],a[4]), + enif_make_list6(env,a[0],a[1],a[2],a[3],a[4],a[5]), + enif_make_list7(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6]), + enif_make_list8(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]), + enif_make_list9(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8])); + tuples = enif_make_list(env,9, + enif_make_tuple1(env,a[0]), + enif_make_tuple2(env,a[0],a[1]), + enif_make_tuple3(env,a[0],a[1],a[2]), + enif_make_tuple4(env,a[0],a[1],a[2],a[3]), + enif_make_tuple5(env,a[0],a[1],a[2],a[3],a[4]), + enif_make_tuple6(env,a[0],a[1],a[2],a[3],a[4],a[5]), + enif_make_tuple7(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6]), + enif_make_tuple8(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]), + enif_make_tuple9(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8])); + return enif_make_tuple2(env,lists,tuples); +} + +static ERL_NIF_TERM tuple_2_list_and_tuple(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + const ERL_NIF_TERM* arr; + int arity; + if (!enif_get_tuple(env,argv[0],&arity,&arr)) { + return enif_make_badarg(env); + } + return enif_make_tuple2(env, + enif_make_list_from_array(env, arr, arity), + enif_make_tuple_from_array(env, arr, arity)); +} + +static ERL_NIF_TERM iolist_2_bin(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary obin; + if (!enif_inspect_iolist_as_binary(env, argv[0], &obin)) { + return enif_make_badarg(env); + } + return enif_make_binary(env,&obin); +} + +static ERL_NIF_TERM last_resource_dtor_call(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary bin; + ERL_NIF_TERM ret; + if (resource_dtor_last != NULL) { + enif_alloc_binary(env, resource_dtor_last_sz, &bin); + memcpy(bin.data, resource_dtor_last_data, resource_dtor_last_sz); + ret = enif_make_tuple3(env, + enif_make_long(env, (long)resource_dtor_last), + enif_make_binary(env, &bin), + enif_make_int(env, resource_dtor_cnt)); + } + else { + ret = enif_make_list(env,0); + } + resource_dtor_last = NULL; + resource_dtor_last_sz = 0; + resource_dtor_cnt = 0; + return ret; +} + +static ERL_NIF_TERM get_resource_type(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + PrivData* data = (PrivData*) enif_get_data(env); + int ix; + + if (!enif_get_int(env, argv[0], &ix) || ix >= 2) { + return enif_make_badarg(env); + } + return enif_make_long(env, data->rt_arr[ix].l); +} + +static ERL_NIF_TERM alloc_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary data_bin; + union { ErlNifResourceType* t; long l;} type; + union { void* p; long l;} data; + if (!enif_get_long(env, argv[0], &type.l) + || !enif_inspect_binary(env, argv[1], &data_bin) + || (data.p = enif_alloc_resource(env, type.t, data_bin.size))==NULL) { + + return enif_make_badarg(env); + } + memcpy(data.p, data_bin.data, data_bin.size); + return enif_make_long(env, data.l); +} + +static ERL_NIF_TERM make_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + union { void* p; long l; } data; + if (!enif_get_long(env, argv[0], &data.l)) { + return enif_make_badarg(env); + } + return enif_make_resource(env, data.p); +} + +static ERL_NIF_TERM make_new_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary data_bin; + union { ErlNifResourceType* t; long l;} type; + void* data; + ERL_NIF_TERM ret; + if (!enif_get_long(env, argv[0], &type.l) + || !enif_inspect_binary(env, argv[1], &data_bin) + || (data = enif_alloc_resource(env, type.t, data_bin.size))==NULL) { + + return enif_make_badarg(env); + } + ret = enif_make_resource(env, data); + memcpy(data, data_bin.data, data_bin.size); + enif_release_resource(env, data); + return ret; +} + +static ERL_NIF_TERM get_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifBinary data_bin; + union { ErlNifResourceType* t; long l; } type; + union { void* p; long l; } data; + + if (!enif_get_long(env, argv[0], &type.l) + || !enif_get_resource(env, argv[1], type.t, &data.p)) { + return enif_make_badarg(env); + } + + enif_alloc_binary(env, enif_sizeof_resource(env,data.p), &data_bin); + memcpy(data_bin.data, data.p, data_bin.size); + return enif_make_tuple2(env, enif_make_long(env,data.l), + enif_make_binary(env, &data_bin)); +} + +static ERL_NIF_TERM release_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + union { void* p; long l; } data; + if (!enif_get_long(env, argv[0], &data.l)) { + return enif_make_badarg(env); + } + enif_release_resource(env, data.p); + return enif_make_atom(env,"ok"); +} + + static ErlNifFunc nif_funcs[] = { {"lib_version", 0, lib_version}, @@ -315,7 +626,22 @@ static ErlNifFunc nif_funcs[] = {"tuple_2_list", 1, tuple_2_list}, {"is_identical",2,is_identical}, {"compare",2,compare}, - {"many_args_100", 100, many_args_100} + {"many_args_100", 100, many_args_100}, + {"clone_bin", 1, clone_bin}, + {"make_sub_bin", 3, make_sub_bin}, + {"string_to_bin", 2, string_to_bin}, + {"atom_to_bin", 2, atom_to_bin}, + {"macros", 1, macros}, + {"tuple_2_list_and_tuple",1,tuple_2_list_and_tuple}, + {"iolist_2_bin", 1, iolist_2_bin}, + {"get_resource_type", 1, get_resource_type}, + {"alloc_resource", 2, alloc_resource}, + {"make_resource", 1, make_resource}, + {"get_resource", 2, get_resource}, + {"release_resource", 1, release_resource}, + {"last_resource_dtor_call", 0, last_resource_dtor_call}, + {"make_new_resource", 2, make_new_resource} + }; ERL_NIF_INIT(nif_SUITE,nif_funcs,load,reload,upgrade,unload) diff --git a/erts/emulator/test/nif_SUITE_data/nif_mod.c b/erts/emulator/test/nif_SUITE_data/nif_mod.c index 2f2267cf78..c075b74c57 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_mod.c +++ b/erts/emulator/test/nif_SUITE_data/nif_mod.c @@ -1,51 +1,182 @@ #include "erl_nif.h" #include <string.h> -#include <assert.h> +#include <stdio.h> #include "nif_mod.h" +#define CHECK(X) ((void)((X) || (check_abort(__LINE__),1))) +#ifdef __GNUC__ +static void check_abort(unsigned line) __attribute__((noreturn)); +#endif +static void check_abort(unsigned line) +{ + enif_fprintf(stderr, "Test CHECK failed at %s:%u\r\n", + __FILE__, line); + abort(); +} static int static_cntA; /* zero by default */ static int static_cntB = NIF_LIB_VER * 100; -static void add_call(ErlNifEnv* env, NifModPrivData* data, const char* func_name) +static ERL_NIF_TERM am_true; +static ERL_NIF_TERM am_null; +static ERL_NIF_TERM am_resource_type; +static ERL_NIF_TERM am_resource_dtor_A; +static ERL_NIF_TERM am_resource_dtor_B; + +static void init(ErlNifEnv* env) +{ + am_true = enif_make_atom(env, "true"); + am_null = enif_make_atom(env, "null"); + am_resource_type = enif_make_atom(env, "resource_type"); + am_resource_dtor_A = enif_make_atom(env, "resource_dtor_A"); + am_resource_dtor_B = enif_make_atom(env, "resource_dtor_B"); +} + +static void add_call_with_arg(ErlNifEnv* env, NifModPrivData* data, const char* func_name, + const char* arg, int arg_sz) { - CallInfo* call = enif_alloc(env, sizeof(CallInfo)+strlen(func_name)); + CallInfo* call = enif_alloc(env, sizeof(CallInfo)+strlen(func_name) + arg_sz); strcpy(call->func_name, func_name); call->lib_ver = NIF_LIB_VER; call->static_cntA = ++static_cntA; call->static_cntB = ++static_cntB; + call->arg_sz = arg_sz; + if (arg != NULL) { + call->arg = call->func_name + strlen(func_name) + 1; + memcpy(call->arg, arg, arg_sz); + } + else { + call->arg = NULL; + } + enif_mutex_lock(data->mtx); call->next = data->call_history; data->call_history = call; + enif_mutex_unlock(data->mtx); +} + +static void add_call(ErlNifEnv* env, NifModPrivData* data,const char* func_name) +{ + add_call_with_arg(env, data, func_name, NULL, 0); +} + +#define ADD_CALL(FUNC_NAME) add_call(env, enif_priv_data(env),FUNC_NAME) + +#define STRINGIFY_(X) #X +#define STRINGIFY(X) STRINGIFY_(X) + +static void resource_dtor_A(ErlNifEnv* env, void* a) +{ + const char dtor_name[] = "resource_dtor_A_v" STRINGIFY(NIF_LIB_VER); + + add_call_with_arg(env, enif_priv_data(env), dtor_name, + a, enif_sizeof_resource(env, a)); +} + +static void resource_dtor_B(ErlNifEnv* env, void* a) +{ + const char dtor_name[] = "resource_dtor_B_v" STRINGIFY(NIF_LIB_VER); + + add_call_with_arg(env, enif_priv_data(env), dtor_name, + a, enif_sizeof_resource(env, a)); +} + +/* {resource_type, Ix|null, ErlNifResourceFlags in, "TypeName", dtor(A|B|null), ErlNifResourceFlags out}*/ +static void open_resource_type(ErlNifEnv* env, ERL_NIF_TERM op_tpl) +{ + NifModPrivData* data = enif_priv_data(env); + const ERL_NIF_TERM* arr; + int arity; + char rt_name[30]; + union { enum ErlNifResourceFlags e; int i; } flags, exp_res, got_res; + unsigned ix; + ErlNifResourceDtor* dtor; + ErlNifResourceType* got_ptr; + + CHECK(enif_get_tuple(env, op_tpl, &arity, &arr)); + CHECK(arity == 6); + CHECK(enif_is_identical(env, arr[0], am_resource_type)); + CHECK(enif_get_int(env, arr[2], &flags.i)); + CHECK(enif_get_string(env, arr[3], rt_name, sizeof(rt_name), ERL_NIF_LATIN1) > 0); + CHECK(enif_get_int(env, arr[5], &exp_res.i)); + + if (enif_is_identical(env, arr[4], am_null)) { + dtor = NULL; + } + else if (enif_is_identical(env, arr[4], am_resource_dtor_A)) { + dtor = resource_dtor_A; + } + else { + CHECK(enif_is_identical(env, arr[4], am_resource_dtor_B)); + dtor = resource_dtor_B; + } + + got_ptr = enif_open_resource_type(env, rt_name, dtor, + flags.e, &got_res.e); + + if (enif_get_uint(env, arr[1], &ix) && ix < RT_MAX && got_ptr != NULL) { + data->rt_arr[ix] = got_ptr; + } + else { + CHECK(enif_is_identical(env, arr[1], am_null)); + CHECK(got_ptr == NULL); + } + CHECK(got_res.e == exp_res.e); } -#define ADD_CALL(FUNC_NAME) add_call(env, enif_get_data(env),FUNC_NAME) +static void do_load_info(ErlNifEnv* env, ERL_NIF_TERM load_info) +{ + NifModPrivData* data = enif_priv_data(env); + ERL_NIF_TERM head, tail; + unsigned ix; + for (ix=0; ix<RT_MAX; ix++) { + data->rt_arr[ix] = NULL; + } + for (head = load_info; enif_get_list_cell(env, head, &head, &tail); + head = tail) { + + open_resource_type(env, head); + } + CHECK(enif_is_empty_list(env, head)); +} static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) { - NifModPrivData* data = enif_alloc(env, sizeof(NifModPrivData)); - assert(data != NULL); + NifModPrivData* data; + + init(env); + data = enif_alloc(env, sizeof(NifModPrivData)); + CHECK(data != NULL); + *priv_data = data; + data->mtx = enif_mutex_create("nif_mod_priv_data"); data->ref_cnt = 1; data->call_history = NULL; add_call(env, data, "load"); - data->calls = 0; - *priv_data = data; + do_load_info(env, load_info); + data->calls = 0; return 0; } static int reload(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) { + init(env); add_call(env, *priv_data, "reload"); + + do_load_info(env, load_info); return 0; } static int upgrade(ErlNifEnv* env, void** priv_data, void** old_priv_data, ERL_NIF_TERM load_info) { NifModPrivData* data = *old_priv_data; + init(env); add_call(env, data, "upgrade"); data->ref_cnt++; + *priv_data = *old_priv_data; + do_load_info(env, load_info); + return 0; } @@ -53,9 +184,13 @@ static void unload(ErlNifEnv* env, void* priv_data) { NifModPrivData* data = priv_data; add_call(env, data, "unload"); + enif_mutex_lock(data->mtx); if (--data->ref_cnt == 0) { + enif_mutex_unlock(data->mtx); + enif_mutex_destroy(data->mtx); enif_free(env, data); } + enif_mutex_unlock(data->mtx); } static ERL_NIF_TERM lib_version(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) @@ -64,35 +199,51 @@ static ERL_NIF_TERM lib_version(ErlNifEnv* env, int argc, const ERL_NIF_TERM arg return enif_make_int(env, NIF_LIB_VER); } -static ERL_NIF_TERM call_history(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +static ERL_NIF_TERM get_priv_data_ptr(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { - NifModPrivData* data = (NifModPrivData*) enif_get_data(env); - ERL_NIF_TERM list = enif_make_list(env, 0); /* NIL */ + ADD_CALL("get_priv_data_ptr"); + return enif_make_ulong(env, (unsigned long)enif_priv_data(env)); +} - while (data->call_history != NULL) { - CallInfo* call = data->call_history; - ERL_NIF_TERM tpl = enif_make_tuple(env, 2, - enif_make_atom(env,call->func_name), - enif_make_int(env,call->lib_ver)); - list = enif_make_list_cell(env, tpl, list); - data->call_history = call->next; - enif_free(env,call); +static ERL_NIF_TERM make_new_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + NifModPrivData* data = (NifModPrivData*) enif_priv_data(env); + ErlNifBinary ibin; + char* a; + ERL_NIF_TERM ret; + unsigned ix; + if (!enif_get_uint(env, argv[0], &ix) || ix >= RT_MAX + || !enif_inspect_binary(env, argv[1], &ibin)) { + return enif_make_badarg(env); } - return list; + a = enif_alloc_resource(env, data->rt_arr[ix], ibin.size); + memcpy(a, ibin.data, ibin.size); + ret = enif_make_resource(env, a); + enif_release_resource(env, a); + return ret; } -static ERL_NIF_TERM get_priv_data_ptr(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +static ERL_NIF_TERM get_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { - ADD_CALL("get_priv_data_ptr"); - return enif_make_ulong(env, (unsigned long)enif_get_data(env)); + NifModPrivData* data = (NifModPrivData*) enif_priv_data(env); + ErlNifBinary obin; + unsigned ix; + void* a; + if (!enif_get_uint(env, argv[0], &ix) || ix >= RT_MAX + || !enif_get_resource(env, argv[1], data->rt_arr[ix], &a) + || !enif_alloc_binary(env, enif_sizeof_resource(env, a), &obin)) { + return enif_make_badarg(env); + } + memcpy(obin.data, a, obin.size); + return enif_make_binary(env, &obin); } - static ErlNifFunc nif_funcs[] = { {"lib_version", 0, lib_version}, - {"call_history", 0, call_history}, - {"get_priv_data_ptr", 0, get_priv_data_ptr} + {"get_priv_data_ptr", 0, get_priv_data_ptr}, + {"make_new_resource", 2, make_new_resource}, + {"get_resource", 2, get_resource} }; #if NIF_LIB_VER != 3 diff --git a/erts/emulator/test/nif_SUITE_data/nif_mod.erl b/erts/emulator/test/nif_SUITE_data/nif_mod.erl index 93da6590a0..7888a589e7 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_mod.erl +++ b/erts/emulator/test/nif_SUITE_data/nif_mod.erl @@ -21,15 +21,19 @@ -include("test_server.hrl"). --export([load_nif_lib/2, start/0, lib_version/0, call_history/0, get_priv_data_ptr/0]). +-export([load_nif_lib/2, load_nif_lib/3, start/0, lib_version/0, call_history/0, + get_priv_data_ptr/0, make_new_resource/2, get_resource/2]). -export([loop/0, upgrade/1]). -define(nif_stub,nif_stub_error(?LINE)). load_nif_lib(Config, Ver) -> + load_nif_lib(Config, Ver, []). + +load_nif_lib(Config, Ver, LoadInfo) -> ?line Path = ?config(data_dir, Config), - erlang:load_nif(filename:join(Path,libname(Ver)), 0). + erlang:load_nif(filename:join(Path,libname(Ver)), LoadInfo). libname(no_init) -> libname(3); libname(Ver) when is_integer(Ver) -> @@ -59,6 +63,8 @@ lib_version() -> % NIF call_history() -> ?nif_stub. get_priv_data_ptr() -> ?nif_stub. +make_new_resource(_,_) -> ?nif_stub. +get_resource(_,_) -> ?nif_stub. nif_stub_error(Line) -> exit({nif_not_loaded,module,?MODULE,line,Line}). diff --git a/erts/emulator/test/nif_SUITE_data/nif_mod.h b/erts/emulator/test/nif_SUITE_data/nif_mod.h index 2dfdc75176..0eaf91d6e1 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_mod.h +++ b/erts/emulator/test/nif_SUITE_data/nif_mod.h @@ -4,14 +4,19 @@ typedef struct call_info_t unsigned lib_ver; int static_cntA; int static_cntB; + char* arg; + int arg_sz; char func_name[1]; /* must be last */ }CallInfo; +#define RT_MAX 5 typedef struct { + ErlNifMutex* mtx; int calls; int ref_cnt; CallInfo* call_history; + ErlNifResourceType* rt_arr[RT_MAX]; }NifModPrivData; diff --git a/erts/emulator/test/nif_SUITE_data/tail.txt b/erts/emulator/test/nif_SUITE_data/tail.txt new file mode 100644 index 0000000000..7f06c118c1 --- /dev/null +++ b/erts/emulator/test/nif_SUITE_data/tail.txt @@ -0,0 +1,5 @@ + + +#include "tester.c" /* poor mans linker */ + + diff --git a/erts/emulator/test/nif_SUITE_data/testcase_driver.h b/erts/emulator/test/nif_SUITE_data/testcase_driver.h new file mode 100644 index 0000000000..98339e4746 --- /dev/null +++ b/erts/emulator/test/nif_SUITE_data/testcase_driver.h @@ -0,0 +1,59 @@ +/* ``The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved via the world wide web at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Ericsson Utvecklings AB. + * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings + * AB. All Rights Reserved.'' + * + * $Id$ + */ + +#ifndef TESTCASE_DRIVER_H__ +#define TESTCASE_DRIVER_H__ + +#include "erl_nif.h" +#include <stdlib.h> +#include <stdio.h> + +typedef struct { + char *testcase_name; + char *command; + int command_len; + void *extra; +} TestCaseState_t; + +#define ASSERT_CLNUP(TCS, B, CLN) \ +do { \ + if (!(B)) { \ + CLN; \ + testcase_assertion_failed((TCS), __FILE__, __LINE__, #B); \ + } \ +} while (0) + +#define ASSERT(TCS, B) ASSERT_CLNUP(TCS, B, (void) 0) + + +void testcase_printf(TestCaseState_t *tcs, char *frmt, ...); +void testcase_succeeded(TestCaseState_t *tcs, char *frmt, ...); +void testcase_skipped(TestCaseState_t *tcs, char *frmt, ...); +void testcase_failed(TestCaseState_t *tcs, char *frmt, ...); +int testcase_assertion_failed(TestCaseState_t *tcs, char *file, int line, + char *assertion); +void *testcase_alloc(size_t size); +void *testcase_realloc(void *ptr, size_t size); +void testcase_free(void *ptr); + + +char *testcase_name(void); +void testcase_run(TestCaseState_t *tcs); +void testcase_cleanup(TestCaseState_t *tcs); + +#endif diff --git a/erts/emulator/test/nif_SUITE_data/tester.c b/erts/emulator/test/nif_SUITE_data/tester.c new file mode 100644 index 0000000000..08466d0f18 --- /dev/null +++ b/erts/emulator/test/nif_SUITE_data/tester.c @@ -0,0 +1,73 @@ +#include "erl_nif.h" + +#include <stdio.h> +#include <stdarg.h> + +void testcase_printf(TestCaseState_t *tcs, char *frmt, ...) +{ + va_list va; + va_start(va, frmt); + vfprintf(stderr, frmt, va); + va_end(va); + fprintf(stderr, "\r"); +} + +void testcase_succeeded(TestCaseState_t *tcs, char *frmt, ...) +{ +} + +void testcase_skipped(TestCaseState_t *tcs, char *frmt, ...) +{ +} + +void testcase_failed(TestCaseState_t *tcs, char *frmt, ...) +{ + va_list va; + va_start(va, frmt); + vfprintf(stderr, frmt, va); + va_end(va); + abort(); +} + +int testcase_assertion_failed(TestCaseState_t *tcs, char *file, int line, + char *assertion) +{ + testcase_failed(tcs, "ASSERTION '%s' FAILED at %s:%d\r\n", + assertion, file, line); + abort(); + return 0; /*?*/ +} + +void *testcase_alloc(size_t size) +{ + return malloc(size); +} +void *testcase_realloc(void *ptr, size_t size) +{ + return realloc(ptr, size); +} +void testcase_free(void *ptr) +{ + free(ptr); +} + +void testcase_run(TestCaseState_t *tcs); + +static int reload(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) +{ + return 0; +} + +static ERL_NIF_TERM run(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + testcase_run(NULL); + return enif_make_atom(env, "ok"); +} + +static ErlNifFunc nif_funcs[] = +{ + {"run", 0, run} +}; + +ERL_NIF_INIT(tester,nif_funcs,NULL,reload,NULL,NULL) + diff --git a/erts/emulator/test/nif_SUITE_data/tester.erl b/erts/emulator/test/nif_SUITE_data/tester.erl new file mode 100644 index 0000000000..9df2158200 --- /dev/null +++ b/erts/emulator/test/nif_SUITE_data/tester.erl @@ -0,0 +1,13 @@ +-module(tester). + +-include("test_server.hrl"). + +-export([load_nif_lib/2, run/0]). + + +load_nif_lib(Config, LibName) -> + ?line Path = ?config(data_dir, Config), + erlang:load_nif(filename:join(Path,LibName), []). + +run() -> + exit({nif_not_loaded,?MODULE,?LINE}). diff --git a/erts/etc/unix/Install.src b/erts/etc/unix/Install.src index 22357b057f..83f9690782 100644 --- a/erts/etc/unix/Install.src +++ b/erts/etc/unix/Install.src @@ -149,4 +149,4 @@ then ./misc/format_man_pages $ERL_ROOT fi - +exit 0 diff --git a/erts/preloaded/ebin/erl_prim_loader.beam b/erts/preloaded/ebin/erl_prim_loader.beam Binary files differindex e966f727c4..304ac41dce 100644 --- a/erts/preloaded/ebin/erl_prim_loader.beam +++ b/erts/preloaded/ebin/erl_prim_loader.beam diff --git a/erts/preloaded/ebin/erlang.beam b/erts/preloaded/ebin/erlang.beam Binary files differindex 620ee733bd..21e5525b2f 100644 --- a/erts/preloaded/ebin/erlang.beam +++ b/erts/preloaded/ebin/erlang.beam diff --git a/erts/preloaded/ebin/init.beam b/erts/preloaded/ebin/init.beam Binary files differindex aa9bd13dd0..8ccc553c13 100644 --- a/erts/preloaded/ebin/init.beam +++ b/erts/preloaded/ebin/init.beam diff --git a/erts/preloaded/ebin/otp_ring0.beam b/erts/preloaded/ebin/otp_ring0.beam Binary files differindex f060ac73b7..8ae73ea9a7 100644 --- a/erts/preloaded/ebin/otp_ring0.beam +++ b/erts/preloaded/ebin/otp_ring0.beam diff --git a/erts/preloaded/ebin/prim_file.beam b/erts/preloaded/ebin/prim_file.beam Binary files differindex 34f9565fe3..3acda843fd 100644 --- a/erts/preloaded/ebin/prim_file.beam +++ b/erts/preloaded/ebin/prim_file.beam diff --git a/erts/preloaded/ebin/prim_inet.beam b/erts/preloaded/ebin/prim_inet.beam Binary files differindex 0ec3130d44..9457b6d360 100644 --- a/erts/preloaded/ebin/prim_inet.beam +++ b/erts/preloaded/ebin/prim_inet.beam diff --git a/erts/preloaded/ebin/prim_zip.beam b/erts/preloaded/ebin/prim_zip.beam Binary files differindex b7897dd798..6837cb4661 100644 --- a/erts/preloaded/ebin/prim_zip.beam +++ b/erts/preloaded/ebin/prim_zip.beam diff --git a/erts/preloaded/ebin/zlib.beam b/erts/preloaded/ebin/zlib.beam Binary files differindex c9be5d2aa0..4e4f85d312 100644 --- a/erts/preloaded/ebin/zlib.beam +++ b/erts/preloaded/ebin/zlib.beam diff --git a/erts/preloaded/src/erl_prim_loader.erl b/erts/preloaded/src/erl_prim_loader.erl index c0785083de..a13292d5ab 100644 --- a/erts/preloaded/src/erl_prim_loader.erl +++ b/erts/preloaded/src/erl_prim_loader.erl @@ -51,22 +51,25 @@ %% Used by escript and code -export([set_primary_archive/3, release_archives/0]). -%% Internal function. Exported to avoid dialyzer warnings --export([concat/1]). - -include_lib("kernel/include/file.hrl"). -type host() :: atom(). +-record(prim_state, {debug :: boolean(), + cache, + primary_archive}). +-type prim_state() :: #prim_state{}. + -record(state, - {loader :: 'efile' | 'inet', - hosts = [] :: [host()], % hosts list (to boot from) + {loader :: 'efile' | 'inet', + hosts = [] :: [host()], % hosts list (to boot from) id, % not used any more? - data, % data port etc - timeout, % idle timeout - n_timeouts, % Number of timeouts before archives are released - multi_get = false :: boolean(), - prim_state}). % state for efile code loader + data :: 'noport' | port(), % data port etc + timeout :: timeout(), % idle timeout + %% Number of timeouts before archives are released + n_timeouts :: non_neg_integer(), + multi_get = false :: boolean(), + prim_state :: prim_state()}). % state for efile code loader -define(IDLE_TIMEOUT, 60000). %% tear inet connection after 1 minutes -define(N_TIMEOUTS, 6). %% release efile archive after 6 minutes @@ -89,8 +92,6 @@ end end()). --record(prim_state, {debug, cache, primary_archive}). - debug(#prim_state{debug = Deb}, Term) -> case Deb of false -> ok; @@ -124,7 +125,7 @@ start(Id, Pgm0, Hosts) -> start_it("ose_inet"=Cmd, Id, Pid, Hosts) -> %% Setup reserved port for ose_inet driver (only OSE) - case catch erlang:open_port({spawn,Cmd},[binary]) of + case catch erlang:open_port({spawn,Cmd}, [binary]) of {'EXIT',Why} -> ?dbg(ose_inet_port_open_fail, Why), Why; @@ -317,7 +318,7 @@ loop(State, Parent, Paths) -> {Res,State1} = handle_get_cwd(State, Args), {Res,State1,Paths}; {set_primary_archive,File,Bin,FileInfo} -> - {Res,State1} = handle_set_primary_archive(State, File, Bin,FileInfo), + {Res,State1} = handle_set_primary_archive(State, File, Bin, FileInfo), {Res,State1,Paths}; release_archives -> {Res,State1} = handle_release_archives(State), @@ -326,7 +327,7 @@ loop(State, Parent, Paths) -> {ignore,State,Paths} end, if Resp =:= ignore -> ok; - true -> Pid ! {self(),Resp} + true -> Pid ! {self(),Resp}, ok end, if is_record(State2, state) -> @@ -335,7 +336,7 @@ loop(State, Parent, Paths) -> exit({bad_state, Req, State2}) end; {'EXIT',Parent,W} -> - handle_stop(State), + _State1 = handle_stop(State), exit(W); {'EXIT',P,W} -> State1 = handle_exit(State, P, W), @@ -605,7 +606,6 @@ find_collect(U,Retry,AL,Delay,Acc) -> _Garbage -> ?dbg(collect_garbage, _Garbage), find_collect(U, Retry, AL, Delay, Acc) - after Delay -> ?dbg(collected, Acc), case keymember(0, 1, Acc) of %% got high priority server? @@ -619,7 +619,7 @@ sleep(Time) -> receive after Time -> ok end. inet_exit_port(State, Port, _Reason) when State#state.data =:= Port -> - State#state { data = noport, timeout = infinity }; + State#state{data = noport, timeout = infinity}; inet_exit_port(State, _, _) -> State. @@ -629,7 +629,7 @@ inet_timeout_handler(State, _Parent) -> if is_port(Tcp) -> ll_close(Tcp); true -> ok end, - State#state { timeout = infinity, data = noport }. + State#state{timeout = infinity, data = noport}. %% -> {{ok,BinFile,Tag},State} | {{error,Reason},State} inet_get_file_from_port(State, File, Paths) -> @@ -659,9 +659,9 @@ inet_get_file_from_port1(_File, [], State) -> inet_send_and_rcv(Msg, Tag, State) when State#state.data =:= noport -> {ok,Tcp} = find_master(State#state.hosts), %% reconnect - inet_send_and_rcv(Msg, Tag, State#state { data = Tcp, - timeout = ?IDLE_TIMEOUT }); -inet_send_and_rcv(Msg, Tag, #state{data=Tcp,timeout=Timeout}=State) -> + inet_send_and_rcv(Msg, Tag, State#state{data = Tcp, + timeout = ?IDLE_TIMEOUT}); +inet_send_and_rcv(Msg, Tag, #state{data = Tcp, timeout = Timeout} = State) -> prim_inet:send(Tcp, term_to_binary(Msg)), receive {tcp,Tcp,BinMsg} -> @@ -679,13 +679,13 @@ inet_send_and_rcv(Msg, Tag, #state{data=Tcp,timeout=Timeout}=State) -> end; {tcp_closed,Tcp} -> %% Ok we must reconnect - inet_send_and_rcv(Msg, Tag, State#state { data = noport }); + inet_send_and_rcv(Msg, Tag, State#state{data = noport}); {tcp_error,Tcp,_Reason} -> %% Ok we must reconnect inet_send_and_rcv(Msg, Tag, inet_stop_port(State)); {'EXIT', Tcp, _} -> %% Ok we must reconnect - inet_send_and_rcv(Msg, Tag, State#state { data = noport }) + inet_send_and_rcv(Msg, Tag, State#state{data = noport}) after Timeout -> %% Ok we must reconnect inet_send_and_rcv(Msg, Tag, inet_stop_port(State)) @@ -772,6 +772,7 @@ port_error(S, Error) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec prim_init() -> prim_state(). prim_init() -> Deb = case init:get_argument(loader_debug) of @@ -779,10 +780,10 @@ prim_init() -> error -> false end, cache_new(#prim_state{debug = Deb}). - + prim_release_archives(PS) -> debug(PS, release_archives), - {Res, PS2}= prim_do_release_archives(PS, get(), []), + {Res, PS2} = prim_do_release_archives(PS, get(), []), debug(PS2, {return, Res}), {Res, PS2}. @@ -822,8 +823,8 @@ prim_set_primary_archive(PS, undefined, undefined, undefined) -> debug(PS2, {return, Res}), {Res, PS2} end; -prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, FileInfo) - when is_list(ArchiveFile), is_binary(ArchiveBin), is_record(FileInfo, file_info) -> +prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, #file_info{} = FileInfo) + when is_list(ArchiveFile), is_binary(ArchiveBin) -> %% Try the archive file debug(PS, {set_primary_archive, ArchiveFile, byte_size(ArchiveBin)}), {Res3, PS3} = @@ -861,6 +862,7 @@ prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, FileInfo) debug(PS3, {return, Res3}), {Res3, PS3}. +-spec prim_get_file(prim_state(), file:filename()) -> {_, prim_state()}. prim_get_file(PS, File) -> debug(PS, {get_file, File}), {Res2, PS2} = @@ -885,7 +887,9 @@ prim_get_file(PS, File) -> debug(PS, {return, Res2}), {Res2, PS2}. -%% -> {{ok,List},State} | {{error,Reason},State} +-spec prim_list_dir(prim_state(), file:filename()) -> + {{'ok', [file:filename()]}, prim_state()} + | {{'error', term()}, prim_state()}. prim_list_dir(PS, Dir) -> debug(PS, {list_dir, Dir}), {Res2, PS3} = @@ -936,7 +940,9 @@ prim_list_dir(PS, Dir) -> debug(PS, {return, Res2}), {Res2, PS3}. -%% -> {{ok,Info},State} | {{error,Reason},State} +-spec prim_read_file_info(prim_state(), file:filename()) -> + {{'ok', #file_info{}}, prim_state()} + | {{'error', term()}, prim_state()}. prim_read_file_info(PS, File) -> debug(PS, {read_file_info, File}), {Res2, PS2} = @@ -976,6 +982,8 @@ prim_read_file_info(PS, File) -> debug(PS2, {return, Res2}), {Res2, PS2}. +-spec prim_get_cwd(prim_state(), [file:filename()]) -> + {{'error', term()} | {'ok', _}, prim_state()}. prim_get_cwd(PS, []) -> debug(PS, {get_cwd, []}), Res = prim_file:get_cwd(), @@ -1029,7 +1037,7 @@ apply_archive(PS, Fun, Acc, Archive) -> {Acc2, PS}; Error -> debug(PS, {cache, {clear, Error}}), - clear_cache(Archive, Cache), + ok = clear_cache(Archive, Cache), debug(PS, {cache, Error}), erase(Archive), %% put(Archive, {Error, FI}), @@ -1041,7 +1049,7 @@ apply_archive(PS, Fun, Acc, Archive) -> end; Error -> debug(PS, {cache, {clear, Error}}), - clear_cache(Archive, Cache), + ok = clear_cache(Archive, Cache), apply_archive(PS, Fun, Acc, Archive) end end. @@ -1143,8 +1151,8 @@ send_all(U, [IP | AL], Cmd) -> send_all(U, AL, Cmd); send_all(_U, [], _) -> ok. -concat([A|T]) when is_atom(A) -> %Atom - atom_to_list(A) ++ concat(T); +%%concat([A|T]) when is_atom(A) -> %Atom +%% atom_to_list(A) ++ concat(T); concat([C|T]) when C >= 0, C =< 255 -> [C|concat(T)]; concat([S|T]) -> %String diff --git a/erts/preloaded/src/erlang.erl b/erts/preloaded/src/erlang.erl index 552121d485..1edb5e72db 100644 --- a/erts/preloaded/src/erlang.erl +++ b/erts/preloaded/src/erlang.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% +%% %% Copyright Ericsson AB 1996-2010. All Rights Reserved. -%% +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(erlang). @@ -29,25 +29,16 @@ -export([send_nosuspend/2, send_nosuspend/3]). -export([localtime_to_universaltime/1]). -export([suspend_process/1]). --export([min/2,max/2]). - +-export([min/2, max/2]). -export([dlink/1, dunlink/1, dsend/2, dsend/3, dgroup_leader/2, dexit/2, dmonitor_node/3, dmonitor_p/2]). - -export([delay_trap/2]). - -export([set_cookie/2, get_cookie/0]). - -export([nodes/0]). - -export([concat_binary/1]). - -export([list_to_integer/2,integer_to_list/2]). - -export([flush_monitor_message/2]). - -export([set_cpu_topology/1, format_cpu_topology/1]). - -export([await_proc_exit/3]). -deprecated([hash/2]). @@ -55,14 +46,22 @@ -compile(nowarn_bif_clash). +%%-------------------------------------------------------------------------- + +-type date() :: {pos_integer(), pos_integer(), pos_integer()}. +-type time() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}. +-type date_time() :: {date(), time()}. + +%%-------------------------------------------------------------------------- + apply(Fun, Args) -> apply(Fun, Args). apply(Mod, Name, Args) -> apply(Mod, Name, Args). +%% Spawns with a fun -% Spawns with a fun spawn(F) when is_function(F) -> spawn(erlang, apply, [F, []]); spawn({M,F}=MF) when is_atom(M), is_atom(F) -> @@ -125,7 +124,7 @@ spawn_opt(N, {M,F}=MF, O) when is_atom(M), is_atom(F) -> spawn_opt(N, F, O) -> erlang:error(badarg, [N, F, O]). -% Spawns with MFA +%% Spawns with MFA spawn(N,M,F,A) when N =:= node(), is_atom(M), is_atom(F), is_list(A) -> spawn(M,F,A); @@ -254,12 +253,17 @@ crasher(Node,Mod,Fun,Args,Opts,Reason) -> [Mod,Fun,Args,Opts,Node]), exit(Reason). +-spec yield() -> 'true'. yield() -> erlang:yield(). -nodes() -> erlang:nodes(visible). +-spec nodes() -> [node()]. +nodes() -> + erlang:nodes(visible). -disconnect_node(Node) -> net_kernel:disconnect(Node). +-spec disconnect_node(node()) -> boolean(). +disconnect_node(Node) -> + net_kernel:disconnect(Node). fun_info(Fun) when is_function(Fun) -> Keys = [type,env,arity,name,uniq,index,new_uniq,new_index,module,pid], @@ -285,9 +289,11 @@ send_nosuspend(Pid, Msg, Opts) -> _ -> false end. +-spec localtime_to_universaltime(date_time()) -> date_time(). localtime_to_universaltime(Localtime) -> erlang:localtime_to_universaltime(Localtime, undefined). +-spec suspend_process(pid()) -> 'true'. suspend_process(P) -> case catch erlang:suspend_process(P, []) of {'EXIT', {Reason, _}} -> erlang:error(Reason, [P]); @@ -298,10 +304,11 @@ suspend_process(P) -> %% %% If the emulator wants to perform a distributed command and %% a connection is not established to the actual node the following -%% functions is called in order to set up the connection and then +%% functions are called in order to set up the connection and then %% reactivate the command. %% +-spec dlink(pid() | port()) -> 'true'. dlink(Pid) -> case net_kernel:connect(node(Pid)) of true -> link(Pid); @@ -309,6 +316,7 @@ dlink(Pid) -> end. %% Can this ever happen? +-spec dunlink(identifier()) -> 'true'. dunlink(Pid) -> case net_kernel:connect(node(Pid)) of true -> unlink(Pid); @@ -322,7 +330,7 @@ dmonitor_node(Node, Flag, []) -> end; dmonitor_node(Node, Flag, Opts) -> - case lists:member(allow_passive_connect,Opts) of + case lists:member(allow_passive_connect, Opts) of true -> case net_kernel:passive_cnct(Node) of true -> erlang:monitor_node(Node, Flag, Opts); @@ -378,11 +386,11 @@ dsend({Name, Node}, Msg, Opts) -> ignored -> ok % Not distributed. end. +-spec dmonitor_p('process', pid() | {atom(),atom()}) -> reference(). dmonitor_p(process, ProcSpec) -> %% ProcSpec = pid() | {atom(),atom()} %% ProcSpec CANNOT be an atom because a locally registered process %% is never handled here. - Node = case ProcSpec of {S,N} when is_atom(S), is_atom(N), N =/= node() -> N; _ when is_pid(ProcSpec) -> node(ProcSpec) @@ -400,6 +408,7 @@ dmonitor_p(process, ProcSpec) -> %% Trap function used when modified timing has been enabled. %% +-spec delay_trap(Result, timeout()) -> Result. delay_trap(Result, 0) -> erlang:yield(), Result; delay_trap(Result, Timeout) -> receive after Timeout -> Result end. @@ -423,13 +432,15 @@ set_cookie(Node, C) when Node =/= nonode@nohost, is_atom(Node) -> error -> exit(badarg); Other -> Other end. - + +-spec get_cookie() -> atom(). get_cookie() -> auth:get_cookie(). concat_binary(List) -> list_to_binary(List). +-spec integer_to_list(integer(), 1..255) -> string(). integer_to_list(I, 10) -> erlang:integer_to_list(I); integer_to_list(I, Base) @@ -457,7 +468,6 @@ integer_to_list(I0, Base, R0) -> end. - list_to_integer(L, 10) -> erlang:list_to_integer(L); list_to_integer(L, Base) @@ -662,6 +672,7 @@ rvrs([X|Xs],Ys) -> rvrs(Xs, [X|Ys]). %% functions in bif.c. Do not make %% any changes to it without reading %% the comment about them in bif.c! +-spec await_proc_exit(dst(), 'apply' | 'data' | 'reason', term()) -> term(). await_proc_exit(Proc, Op, Data) -> Mon = erlang:monitor(process, Proc), receive @@ -677,8 +688,10 @@ await_proc_exit(Proc, Op, Data) -> end end. +-spec min(term(), term()) -> term(). min(A, B) when A > B -> B; min(A, _) -> A. +-spec max(term(), term()) -> term(). max(A, B) when A < B -> B; max(A, _) -> A. diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl index c0b3d286e8..3b98b9cddc 100644 --- a/erts/preloaded/src/init.erl +++ b/erts/preloaded/src/init.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% @@ -51,7 +51,7 @@ get_status/0,boot/1,get_arguments/0,get_plain_arguments/0, get_argument/1,script_id/0]). -% internal exports +%% internal exports -export([fetch_loaded/0,ensure_loaded/1,make_permanent/2, notify_when_started/1,wait_until_started/0, objfile_extension/0, archive_extension/0,code_path_choice/0]). @@ -115,6 +115,8 @@ fetch_loaded() -> ensure_loaded(Module) -> request({ensure_loaded, Module}). +-spec make_permanent(file:filename(), 'false' | file:filename()) -> + 'ok' | {'error', term()}. make_permanent(Boot,Config) -> request({make_permanent,Boot,Config}). diff --git a/erts/preloaded/src/otp_ring0.erl b/erts/preloaded/src/otp_ring0.erl index 3b0d562d1f..2ccf142f30 100644 --- a/erts/preloaded/src/otp_ring0.erl +++ b/erts/preloaded/src/otp_ring0.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2000-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2000-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(otp_ring0). @@ -22,6 +22,7 @@ -export([start/2]). +-spec start(_, term()) -> term(). start(_Env, Argv) -> run(init, boot, Argv). diff --git a/erts/preloaded/src/zlib.erl b/erts/preloaded/src/zlib.erl index 21971a75cf..51d6cd0a0b 100644 --- a/erts/preloaded/src/zlib.erl +++ b/erts/preloaded/src/zlib.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2003-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2003-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -115,7 +115,6 @@ %%------------------------------------------------------------------------ %% Main data types of the file --type(iodata() :: iolist() | binary()). %XXX To be removed in R13B. -type zstream() :: port(). %% Auxiliary data types of the file diff --git a/erts/test/install_SUITE.erl b/erts/test/install_SUITE.erl index b11f65480d..e14790bc1b 100644 --- a/erts/test/install_SUITE.erl +++ b/erts/test/install_SUITE.erl @@ -50,7 +50,7 @@ -define(DEFAULT_TIMEOUT, ?t:minutes(1)). -define(JOIN(A,B,C), filename:join(A, B, C)). --include("test_server.hrl"). +-include_lib("test_server/include/test_server.hrl"). -record(inst, {mkdirs = true, symlinks = true, diff --git a/lib/appmon/vsn.mk b/lib/appmon/vsn.mk index cbf0a88737..78b95e5688 100644 --- a/lib/appmon/vsn.mk +++ b/lib/appmon/vsn.mk @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1997-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1997-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% -APPMON_VSN = 2.1.10.2 +APPMON_VSN = 2.1.11 diff --git a/lib/common_test/info b/lib/common_test/info index 1819ca2aad..6b2778f3e6 100644 --- a/lib/common_test/info +++ b/lib/common_test/info @@ -1,2 +1,2 @@ -group: tools +group: test short: A portable framework for automatic testing diff --git a/lib/compiler/src/Makefile b/lib/compiler/src/Makefile index fde2b1a655..70ddd54145 100644 --- a/lib/compiler/src/Makefile +++ b/lib/compiler/src/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1996-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1996-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # @@ -45,46 +45,46 @@ RELSYSDIR = $(RELEASE_PATH)/lib/compiler-$(VSN) # Target Specs # ---------------------------------------------------- MODULES = \ - compile \ - sys_pre_attributes \ - sys_pre_expand \ - sys_expand_pmod \ - v3_core \ - sys_core_fold \ - sys_core_inline \ - sys_core_dsetel \ - core_lib \ - core_scan \ - core_parse \ - core_lint \ - core_pp \ - v3_kernel \ - v3_kernel_pp \ - v3_life \ - v3_codegen \ + beam_asm \ beam_block \ beam_bool \ - beam_dead \ - beam_jump \ - beam_type \ - beam_clean \ - beam_peep \ beam_bsm \ - beam_trim \ + beam_clean \ + beam_dead \ + beam_dict \ + beam_disasm \ beam_flatten \ + beam_jump \ beam_listing \ - beam_asm \ - beam_dict \ beam_opcodes \ - beam_disasm \ + beam_peep \ + beam_trim \ + beam_type \ beam_utils \ beam_validator \ - erl_bifs \ cerl \ cerl_clauses \ cerl_inline \ cerl_trees \ - rec_env + compile \ + core_lib \ + core_lint \ + core_parse \ + core_pp \ + core_scan \ + erl_bifs \ + rec_env \ + sys_core_dsetel \ + sys_core_fold \ + sys_core_inline \ + sys_expand_pmod \ + sys_pre_attributes \ + sys_pre_expand \ + v3_codegen \ + v3_core \ + v3_kernel \ + v3_kernel_pp \ + v3_life BEAM_H = $(wildcard ../priv/beam_h/*.h) @@ -114,6 +114,9 @@ APPUP_TARGET= $(EBIN)/$(APPUP_FILE) # FLAGS # ---------------------------------------------------- +ifeq ($(NATIVE_LIBS_ENABLED),yes) +ERL_COMPILE_FLAGS += +native +endif ERL_COMPILE_FLAGS += +inline +warn_unused_import -I../../stdlib/include -I$(EGEN) -W # ---------------------------------------------------- diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index d73c9cd762..b853800d73 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -1055,7 +1055,7 @@ test_native(#compile{options=Opts}) -> is_native_enabled([native|_]) -> true; is_native_enabled([no_native|_]) -> false; -is_native_enabled([H|T]) -> is_native_enabled(T); +is_native_enabled([_|Opts]) -> is_native_enabled(Opts); is_native_enabled([]) -> false. native_compile(#compile{code=none}=St) -> {ok,St}; diff --git a/lib/compiler/src/sys_pre_expand.erl b/lib/compiler/src/sys_pre_expand.erl index 78dd73e0a2..f80d03dfac 100644 --- a/lib/compiler/src/sys_pre_expand.erl +++ b/lib/compiler/src/sys_pre_expand.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% Purpose : Expand some source Erlang constructions. This is part of the @@ -114,7 +114,7 @@ expand_pmod(Fs0, St0) -> St1 = St0#expand{exports=Xs, defined=Ds}, {Fs2,St2} = add_instance(Ps, Fs1, St1), {Fs3,St3} = ensure_new(Base, Ps0, Fs2, St2), - {Fs3,St3#expand{attributes = [{abstract, [true]} + {Fs3,St3#expand{attributes = [{abstract, 0, [true]} | St3#expand.attributes]}} end. @@ -173,7 +173,7 @@ define_functions(Forms, #expand{defined=Predef}=St) -> St#expand{defined=ordsets:from_list(Fs)}. module_attrs(St) -> - {[{attribute,0,Name,Val} || {Name,Val} <- St#expand.attributes],St}. + {[{attribute,Line,Name,Val} || {Name,Line,Val} <- St#expand.attributes],St}. module_predef_funcs(St) -> PreDef = [{module_info,0},{module_info,1}], @@ -197,8 +197,8 @@ module_predef_funcs(St) -> forms([{attribute,_,file,_File}=F|Fs0], St0) -> {Fs,St1} = forms(Fs0, St0), {[F|Fs],St1}; -forms([{attribute,_,Name,Val}|Fs0], St0) -> - St1 = attribute(Name, Val, St0), +forms([{attribute,Line,Name,Val}|Fs0], St0) -> + St1 = attribute(Name, Val, Line, St0), forms(Fs0, St1); forms([{function,L,N,A,Cs}|Fs0], St0) -> {Ff,St1} = function(L, N, A, Cs, St0), @@ -207,30 +207,30 @@ forms([{function,L,N,A,Cs}|Fs0], St0) -> forms([_|Fs], St) -> forms(Fs, St); forms([], St) -> {[],St}. -%% attribute(Attribute, Value, State) -> State'. +%% attribute(Attribute, Value, Line, State) -> State'. %% Process an attribute, this just affects the state. -attribute(module, {Module, As}, St) -> +attribute(module, {Module, As}, _L, St) -> M = package_to_string(Module), St#expand{module=list_to_atom(M), - package = packages:strip_last(M), + package=packages:strip_last(M), parameters=As}; -attribute(module, Module, St) -> +attribute(module, Module, _L, St) -> M = package_to_string(Module), St#expand{module=list_to_atom(M), - package = packages:strip_last(M)}; -attribute(export, Es, St) -> + package=packages:strip_last(M)}; +attribute(export, Es, _L, St) -> St#expand{exports=union(from_list(Es), St#expand.exports)}; -attribute(import, Is, St) -> +attribute(import, Is, _L, St) -> import(Is, St); -attribute(compile, C, St) when is_list(C) -> +attribute(compile, C, _L, St) when is_list(C) -> St#expand{compile=St#expand.compile ++ C}; -attribute(compile, C, St) -> +attribute(compile, C, _L, St) -> St#expand{compile=St#expand.compile ++ [C]}; -attribute(Name, Val, St) when is_list(Val) -> - St#expand{attributes=St#expand.attributes ++ [{Name,Val}]}; -attribute(Name, Val, St) -> - St#expand{attributes=St#expand.attributes ++ [{Name,[Val]}]}. +attribute(Name, Val, Line, St) when is_list(Val) -> + St#expand{attributes=St#expand.attributes ++ [{Name,Line,Val}]}; +attribute(Name, Val, Line, St) -> + St#expand{attributes=St#expand.attributes ++ [{Name,Line,[Val]}]}. function(L, N, A, Cs0, St0) -> {Cs,St} = clauses(Cs0, St0#expand{func=N,arity=A,fcount=0}), @@ -299,10 +299,10 @@ pattern({match,Line,Pat1, Pat2}, St0) -> {TT,St2} = pattern(Pat1, St1), {{match,Line,TT,TH},St2}; %% Compile-time pattern expressions, including unary operators. -pattern({op,Line,Op,A}, St) -> - {erl_eval:partial_eval({op,Line,Op,A}),St}; -pattern({op,Line,Op,L,R}, St) -> - {erl_eval:partial_eval({op,Line,Op,L,R}),St}. +pattern({op,_Line,_Op,_A}=Op, St) -> + {erl_eval:partial_eval(Op),St}; +pattern({op,_Line,_Op,_L,_R}=Op, St) -> + {erl_eval:partial_eval(Op),St}. pattern_list([P0|Ps0], St0) -> {P,St1} = pattern(P0, St0), @@ -400,18 +400,18 @@ expr({'receive',Line,Cs0,To0,ToEs0}, St0) -> {{'receive',Line,Cs,To,ToEs},St3}; expr({'fun',Line,Body}, St) -> fun_tq(Line, Body, St); -expr({call,Line,{atom,La,N},As0}, St0) -> +expr({call,Line,{atom,La,N}=Atom,As0}, St0) -> {As,St1} = expr_list(As0, St0), Ar = length(As), case erl_internal:bif(N, Ar) of true -> - {{call,Line,{remote,La,{atom,La,erlang},{atom,La,N}},As},St1}; + {{call,Line,{remote,La,{atom,La,erlang},Atom},As},St1}; false -> case imported(N, Ar, St1) of {yes,Mod} -> - {{call,Line,{remote,La,{atom,La,Mod},{atom,La,N}},As},St1}; + {{call,Line,{remote,La,{atom,La,Mod},Atom},As},St1}; no -> - {{call,Line,{atom,La,N},As},St1} + {{call,Line,Atom,As},St1} end end; expr({call,Line,{record_field,_,_,_}=M,As0}, St0) -> diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl index a39a3c538f..dfe15de4ff 100644 --- a/lib/compiler/src/v3_core.erl +++ b/lib/compiler/src/v3_core.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1999-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1999-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% Purpose : Transform normal Erlang to Core Erlang @@ -164,8 +164,8 @@ form({attribute,_,file,{File,_Line}}, {Fs,As,Es,Ws,_}, _Opts) -> form({attribute,_,_,_}=F, {Fs,As,Es,Ws,File}, _Opts) -> {Fs,[attribute(F)|As],Es,Ws,File}. -attribute({attribute,_,Name,Val}) -> - {#c_literal{val=Name},#c_literal{val=Val}}. +attribute({attribute,Line,Name,Val}) -> + {#c_literal{val=Name, anno=[Line]}, #c_literal{val=Val, anno=[Line]}}. function({function,_,Name,Arity,Cs0}, Es0, Ws0, File, Opts) -> %%ok = io:fwrite("~p - ", [{Name,Arity}]), diff --git a/lib/docbuilder/info b/lib/docbuilder/info index 33ce19fb4b..60daa212c8 100644 --- a/lib/docbuilder/info +++ b/lib/docbuilder/info @@ -1,2 +1,2 @@ -group: tools +group: doc short: Tool for generating HTML documentation for applications. diff --git a/lib/edoc/info b/lib/edoc/info index cb25c1e519..bc52caa78b 100644 --- a/lib/edoc/info +++ b/lib/edoc/info @@ -1,3 +1,3 @@ -group: tools +group: doc Documentation Applications short: A utility used to generate documentation out of tags in source files. diff --git a/lib/edoc/vsn.mk b/lib/edoc/vsn.mk index 7c7ba58cc9..2de2641b4a 100644 --- a/lib/edoc/vsn.mk +++ b/lib/edoc/vsn.mk @@ -1 +1 @@ -EDOC_VSN = 0.7.6.5 +EDOC_VSN = 0.7.6.6 diff --git a/lib/erl_docgen/priv/xsl/db_man.xsl b/lib/erl_docgen/priv/xsl/db_man.xsl index a9a2781a8a..a2b1e755e2 100644 --- a/lib/erl_docgen/priv/xsl/db_man.xsl +++ b/lib/erl_docgen/priv/xsl/db_man.xsl @@ -176,10 +176,12 @@ <xsl:template match="/erlref"> <xsl:variable name="companyname"> <xsl:choose> - <xsl:when test="$company = ''"><xsl:value-of select="header/holder"/></xsl:when> - <xsl:otherwise><xsl:value-of select="$company"/></xsl:otherwise> + <!-- Workaround until all of OTP's .../holder contents are correct. --> + <xsl:when test="starts-with(header/copyright/holder,'Ericsson AB')"><xsl:text>Ericsson AB</xsl:text></xsl:when> + <xsl:otherwise><xsl:value-of select="header/copyright/holder"/></xsl:otherwise> </xsl:choose> </xsl:variable> + <xsl:text>.TH </xsl:text><xsl:value-of select="module"/><xsl:text> 3 "</xsl:text><xsl:value-of select="$appname"/><xsl:text> </xsl:text><xsl:value-of select="$appver"/><xsl:text>" "</xsl:text><xsl:value-of select="$companyname"/><xsl:text>" "Erlang Module Definition" </xsl:text> <xsl:text>.SH NAME </xsl:text> <xsl:value-of select="module"/><xsl:text> \- </xsl:text><xsl:value-of select="modulesummary"/><xsl:text> </xsl:text> @@ -190,11 +192,12 @@ <xsl:template match="/comref"> <xsl:variable name="companyname"> <xsl:choose> - <xsl:when test="$company = ''"><xsl:value-of select="header/holder"/></xsl:when> - <xsl:otherwise><xsl:value-of select="$company"/></xsl:otherwise> + <!-- Workaround until all of OTP's .../holder contents are correct. --> + <xsl:when test="starts-with(header/copyright/holder,'Ericsson AB')"><xsl:text>Ericsson AB</xsl:text></xsl:when> + <xsl:otherwise><xsl:value-of select="header/copyright/holder"/></xsl:otherwise> </xsl:choose> </xsl:variable> - <xsl:text>.TH </xsl:text><xsl:value-of select="com"/><xsl:text> 1 "</xsl:text><xsl:value-of select="$appname"/><xsl:text> </xsl:text><xsl:value-of select="$appver"/><xsl:text>" "</xsl:text><xsl:value-of select="$companyname"/><xsl:text>" "User Commands" </xsl:text> + <xsl:text>.TH </xsl:text><xsl:value-of select="com"/><xsl:text> 1 "</xsl:text><xsl:value-of select="$appname"/><xsl:text> </xsl:text><xsl:value-of select="$appver"/><xsl:text>" "</xsl:text><xsl:value-of select="$companyname"/><xsl:text>" "User Commands" </xsl:text> <xsl:text>.SH NAME </xsl:text> <xsl:value-of select="com"/><xsl:text> \- </xsl:text><xsl:value-of select="comsummary"/><xsl:text> </xsl:text> <xsl:apply-templates/> @@ -204,8 +207,9 @@ <xsl:template match="/cref"> <xsl:variable name="companyname"> <xsl:choose> - <xsl:when test="$company = ''"><xsl:value-of select="header/holder"/></xsl:when> - <xsl:otherwise><xsl:value-of select="$company"/></xsl:otherwise> + <!-- Workaround until all of OTP's .../holder contents are correct. --> + <xsl:when test="starts-with(header/copyright/holder,'Ericsson AB')"><xsl:text>Ericsson AB</xsl:text></xsl:when> + <xsl:otherwise><xsl:value-of select="header/copyright/holder"/></xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:text>.TH </xsl:text><xsl:value-of select="lib"/><xsl:text> 3 "</xsl:text><xsl:value-of select="$appname"/><xsl:text> </xsl:text><xsl:value-of select="$appver"/><xsl:text>" "</xsl:text><xsl:value-of select="$companyname"/><xsl:text>" "C Library Functions" </xsl:text> @@ -218,8 +222,9 @@ <xsl:template match="/fileref"> <xsl:variable name="companyname"> <xsl:choose> - <xsl:when test="$company = ''"><xsl:value-of select="header/holder"/></xsl:when> - <xsl:otherwise><xsl:value-of select="$company"/></xsl:otherwise> + <!-- Workaround until all of OTP's .../holder contents are correct. --> + <xsl:when test="starts-with(header/copyright/holder,'Ericsson AB')"><xsl:text>Ericsson AB</xsl:text></xsl:when> + <xsl:otherwise><xsl:value-of select="header/copyright/holder"/></xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:text>.TH </xsl:text><xsl:value-of select="file"/><xsl:text> 5 "</xsl:text><xsl:value-of select="$appname"/><xsl:text> </xsl:text><xsl:value-of select="$appver"/><xsl:text>" "</xsl:text><xsl:value-of select="$companyname"/><xsl:text>" "Files" </xsl:text> @@ -232,8 +237,9 @@ <xsl:template match="/appref"> <xsl:variable name="companyname"> <xsl:choose> - <xsl:when test="$company = ''"><xsl:value-of select="header/holder"/></xsl:when> - <xsl:otherwise><xsl:value-of select="$company"/></xsl:otherwise> + <!-- Workaround until all of OTP's .../holder contents are correct. --> + <xsl:when test="starts-with(header/copyright/holder,'Ericsson AB')"><xsl:text>Ericsson AB</xsl:text></xsl:when> + <xsl:otherwise><xsl:value-of select="header/copyright/holder"/></xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:text>.TH </xsl:text><xsl:value-of select="app"/><xsl:text> 7 "</xsl:text><xsl:value-of select="$appname"/><xsl:text> </xsl:text><xsl:value-of select="$appver"/><xsl:text>" "</xsl:text><xsl:value-of select="$companyname"/><xsl:text>" "Erlang Application Definition" </xsl:text> diff --git a/lib/et/doc/src/fascicules.xml b/lib/et/doc/src/fascicules.xml deleted file mode 100644 index 0678195e07..0000000000 --- a/lib/et/doc/src/fascicules.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="latin1" ?> -<!DOCTYPE fascicules SYSTEM "fascicules.dtd"> - -<fascicules> - <fascicule file="part" href="part_frame.html" entry="no"> - User's Guide - </fascicule> - <fascicule file="ref_man" href="ref_man_frame.html" entry="yes"> - Reference Manual - </fascicule> - <fascicule file="part_notes" href="part_notes_frame.html" entry="no"> - Release Notes - </fascicule> - <fascicule file="" href="../../../../doc/print.html" entry="no"> - Off-Print - </fascicule> -</fascicules> - diff --git a/lib/et/doc/src/files.mk b/lib/et/doc/src/files.mk index 41964de892..41fffb83f1 100644 --- a/lib/et/doc/src/files.mk +++ b/lib/et/doc/src/files.mk @@ -26,8 +26,7 @@ XML_REF3_FILES = \ et_viewer.xml XML_PART_FILES = \ - part.xml \ - part_notes.xml + part.xml XML_CHAPTER_FILES = \ et_intro.xml \ diff --git a/lib/eunit/info b/lib/eunit/info index 138f4dc040..e7e6265940 100644 --- a/lib/eunit/info +++ b/lib/eunit/info @@ -1,2 +1,2 @@ -group: tools +group: test short: Support for unit testing. diff --git a/lib/eunit/vsn.mk b/lib/eunit/vsn.mk index 002703b1b3..3bfa9c8000 100644 --- a/lib/eunit/vsn.mk +++ b/lib/eunit/vsn.mk @@ -1 +1 @@ -EUNIT_VSN = 2.1.4 +EUNIT_VSN = 2.1.5 diff --git a/lib/hipe/Makefile b/lib/hipe/Makefile index 10bf82b2d7..54efd7fcaf 100644 --- a/lib/hipe/Makefile +++ b/lib/hipe/Makefile @@ -27,7 +27,7 @@ else HIPE_SUBDIRS = endif -ALWAYS_SUBDIRS = misc main cerl icode flow util +ALWAYS_SUBDIRS = misc main cerl icode flow util doc/src ifdef HIPE_ENABLED # "rtl" below must be the first directory so that file rtl/hipe_literals.hrl diff --git a/lib/hipe/doc/Makefile b/lib/hipe/doc/Makefile index 340f909aa6..cdf9c9c798 100644 --- a/lib/hipe/doc/Makefile +++ b/lib/hipe/doc/Makefile @@ -1,21 +1,28 @@ -# ``The contents of this file are subject to the Erlang Public License, +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2006-2010. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be -# retrieved via the world wide web at http://www.erlang.org/. -# +# retrieved online at http://www.erlang.org/. +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# +# %CopyrightEnd% +# SHELL=/bin/sh include $(ERL_TOP)/make/target.mk include $(ERL_TOP)/make/$(TARGET)/otp.mk clean: - -rm -f *.html edoc-info stylesheet.css + -rm -f *.html edoc-info stylesheet.css erlang.png # ---------------------------------------------------- # Special Build Targets diff --git a/lib/hipe/doc/src/Makefile b/lib/hipe/doc/src/Makefile index 3b63e57549..d440178e4c 100644 --- a/lib/hipe/doc/src/Makefile +++ b/lib/hipe/doc/src/Makefile @@ -1,19 +1,20 @@ -# ``The contents of this file are subject to the Erlang Public License, +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2006-2010. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be -# retrieved via the world wide web at http://www.erlang.org/. -# +# retrieved online at http://www.erlang.org/. +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# -# The Initial Developer of the Original Code is Ericsson Utvecklings AB. -# Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings -# AB. All Rights Reserved.'' -# -# $Id$ +# +# %CopyrightEnd% # include $(ERL_TOP)/make/target.mk include $(ERL_TOP)/make/$(TARGET)/otp.mk @@ -33,7 +34,7 @@ RELSYSDIR = $(RELEASE_PATH)/lib/$(APPLICATION)-$(VSN) # ---------------------------------------------------- # Target Specs # ---------------------------------------------------- -XML_APPLICATION_FILES = +XML_APPLICATION_FILES = ref_man.xml XML_REF3_FILES = XML_PART_FILES = part_notes.xml diff --git a/lib/hipe/doc/src/book.xml b/lib/hipe/doc/src/book.xml index 236dfc69a1..9c95e3a827 100644 --- a/lib/hipe/doc/src/book.xml +++ b/lib/hipe/doc/src/book.xml @@ -4,7 +4,7 @@ <book xmlns:xi="http://www.w3.org/2001/XInclude"> <header titlestyle="normal"> <copyright> - <year>2006</year><year>2009</year> + <year>2006</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>HiPE</title> @@ -31,6 +31,9 @@ <preamble> </preamble> <pagetext>HiPE</pagetext> + <applications> + <xi:include href="ref_man.xml"/> + </applications> <releasenotes> <xi:include href="notes.xml"/> </releasenotes> diff --git a/lib/hipe/doc/src/hipe_app.xml b/lib/hipe/doc/src/hipe_app.xml new file mode 100644 index 0000000000..56729d4cc4 --- /dev/null +++ b/lib/hipe/doc/src/hipe_app.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="latin1" ?> +<!DOCTYPE appref SYSTEM "appref.dtd"> + +<appref> + <header> + <copyright> + <year>1997</year><year>2010</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + </legalnotice> + + <title>snmp</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev></rev> + <file>hipe.xml</file> + </header> + <app>HiPE</app> + <appsummary>The HiPE Application</appsummary> + <description> + <p> + The normal way to native-compile an Erlang module using HiPE is to include the atom native + in the Erlang compiler options, as in: + <code> + 1> <input>c(my_module, [native]).</input></code> + Options to the HiPE compiler are then passed as follows: + <code> + 1> <input>c(my_module, [native,{hipe,Options}]).</input></code> + For on-line help in the Erlang shell, call <c>hipe:help()</c>. + Details on HiPE compiler options are given by <c>hipe:help_options()</c>. + </p> + </description> + <section> + <title>SEE ALSO</title> + <p> + <seealso marker="stdlib:c">c(3)</seealso>, + <seealso marker="compiler:compile">compile(3)</seealso> + </p> + </section> + +</appref> + diff --git a/lib/et/doc/src/part_notes.xml b/lib/hipe/doc/src/ref_man.xml index 00b3d9df23..09d10147ee 100644 --- a/lib/et/doc/src/part_notes.xml +++ b/lib/hipe/doc/src/ref_man.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="latin1" ?> -<!DOCTYPE part SYSTEM "part.dtd"> +<!DOCTYPE application SYSTEM "application.dtd"> -<part xmlns:xi="http://www.w3.org/2001/XInclude"> +<application xmlns:xi="http://www.w3.org/2001/XInclude"> <header> <copyright> - <year>2002</year><year>2009</year> + <year>1996</year><year>2009</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -21,16 +21,15 @@ </legalnotice> - <title>Event Tracer (ET) Release Notes</title> - <prepared>Håkan Mattsson</prepared> + <title>HiPE</title> + <prepared></prepared> <docno></docno> - <date></date> - <rev>%VSN%</rev> + <date>1997-06-04</date> + <rev>1.3.1</rev> + <file>ref_man.xml</file> </header> <description> - <p>The Event Tracer (ET) uses the built-in trace mechanism in Erlang - and provides tools for collection and graphical viewing of trace data.</p> </description> - <xi:include href="notes.xml"/> -</part> + <xi:include href="hipe_app.xml"/> +</application> diff --git a/lib/hipe/info b/lib/hipe/info index 51b5dfb979..fe08fc8990 100644 --- a/lib/hipe/info +++ b/lib/hipe/info @@ -1,2 +1,2 @@ -group: basic +group: misc Miscellaneous Applications short: High Performance Erlang
\ No newline at end of file diff --git a/lib/jinterface/vsn.mk b/lib/jinterface/vsn.mk index 243547cf1f..6b5719d7c5 100644 --- a/lib/jinterface/vsn.mk +++ b/lib/jinterface/vsn.mk @@ -1,19 +1,19 @@ ## ## %CopyrightBegin% -## -## Copyright Ericsson AB 2000-2009. All Rights Reserved. -## +## +## Copyright Ericsson AB 2000-2010. All Rights Reserved. +## ## The contents of this file are subject to the Erlang Public License, ## Version 1.1, (the "License"); you may not use this file except in ## compliance with the License. You should have received a copy of the ## Erlang Public License along with this software. If not, it can be ## retrieved online at http://www.erlang.org/. -## +## ## Software distributed under the License is distributed on an "AS IS" ## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See ## the License for the specific language governing rights and limitations ## under the License. -## +## ## %CopyrightEnd% -JINTERFACE_VSN = 1.5.2 +JINTERFACE_VSN = 1.5.3 diff --git a/lib/kernel/src/Makefile b/lib/kernel/src/Makefile index cd011f09fe..9db6014a7d 100644 --- a/lib/kernel/src/Makefile +++ b/lib/kernel/src/Makefile @@ -143,6 +143,9 @@ APPUP_TARGET= $(EBIN)/$(APPUP_FILE) # FLAGS # ---------------------------------------------------- +ifeq ($(NATIVE_LIBS_ENABLED),yes) +ERL_COMPILE_FLAGS += +native +endif ERL_COMPILE_FLAGS += -I../include # ---------------------------------------------------- diff --git a/lib/kernel/src/hipe_unified_loader.erl b/lib/kernel/src/hipe_unified_loader.erl index 42eab67478..f289b8110d 100644 --- a/lib/kernel/src/hipe_unified_loader.erl +++ b/lib/kernel/src/hipe_unified_loader.erl @@ -96,14 +96,6 @@ load_hipe_modules() -> %% code:load_file/1) and the atom `no_native' on failure. load_native_code(Mod, Bin) when is_atom(Mod), is_binary(Bin) -> - erlang:system_flag(multi_scheduling, block), - try - load_native_code_nosmp(Mod, Bin) - after - erlang:system_flag(multi_scheduling, unblock) - end. - -load_native_code_nosmp(Mod, Bin) -> Architecture = erlang:system_info(hipe_architecture), try chunk_name(Architecture) of ChunkTag -> @@ -111,10 +103,15 @@ load_native_code_nosmp(Mod, Bin) -> case code:get_chunk(Bin, ChunkTag) of undefined -> no_native; NativeCode when is_binary(NativeCode) -> - OldReferencesToPatch = patch_to_emu_step1(Mod), - case load_module(Mod, NativeCode, Bin, OldReferencesToPatch) of - bad_crc -> no_native; - Result -> Result + erlang:system_flag(multi_scheduling, block), + try + OldReferencesToPatch = patch_to_emu_step1(Mod), + case load_module(Mod, NativeCode, Bin, OldReferencesToPatch) of + bad_crc -> no_native; + Result -> Result + end + after + erlang:system_flag(multi_scheduling, unblock) end end catch @@ -128,17 +125,18 @@ load_native_code_nosmp(Mod, Bin) -> -spec post_beam_load(atom()) -> 'ok'. post_beam_load(Mod) when is_atom(Mod) -> - erlang:system_flag(multi_scheduling, block), - try - post_beam_load_nosmp(Mod) - after - erlang:system_flag(multi_scheduling, unblock) - end. - -post_beam_load_nosmp(Mod) -> Architecture = erlang:system_info(hipe_architecture), - try chunk_name(Architecture) of _ChunkTag -> patch_to_emu(Mod) - catch _:_ -> ok + try chunk_name(Architecture) of + _ChunkTag -> + erlang:system_flag(multi_scheduling, block), + try + patch_to_emu(Mod) + after + erlang:system_flag(multi_scheduling, unblock) + end + catch + _:_ -> + ok end. %%======================================================================== diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl index b86aa1839e..eb503235d8 100644 --- a/lib/kernel/src/inet.erl +++ b/lib/kernel/src/inet.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet). @@ -45,6 +45,7 @@ %% resolve -export([gethostbyname/1, gethostbyname/2, gethostbyname/3, gethostbyname_tm/3]). +-export([gethostbyname_string/2, gethostbyname_self/2]). -export([gethostbyaddr/1, gethostbyaddr/2, gethostbyaddr_tm/2]). @@ -411,7 +412,17 @@ gethostbyname(Name,Family,Timeout) -> Res. gethostbyname_tm(Name,Family,Timer) -> - gethostbyname_tm(Name,Family,Timer,inet_db:res_option(lookup)). + Opts0 = inet_db:res_option(lookup), + Opts = + case (lists:member(native, Opts0) orelse + lists:member(string, Opts0) orelse + lists:member(nostring, Opts0)) of + true -> + Opts0; + false -> + [string|Opts0] + end, + gethostbyname_tm(Name, Family, Timer, Opts). -spec gethostbyaddr(Address :: string() | ip_address()) -> @@ -850,75 +861,61 @@ getaddrs_tm(Address, Family, Timer) -> %% %% gethostbyname with option search %% -gethostbyname_tm(Name, Type, Timer, [dns | Opts]) -> - Res = inet_res:gethostbyname_tm(Name, Type, Timer), - case Res of - {ok,_} -> Res; - {error,timeout} -> Res; - {error,formerr} -> {error,einval}; - {error,_} -> gethostbyname_tm(Name,Type,Timer,Opts) - end; -gethostbyname_tm(Name, Type, Timer, [file | Opts]) -> - case inet_hosts:gethostbyname(Name, Type) of - {error,formerr} -> {error,einval}; - {error,_} -> gethostbyname_tm(Name,Type,Timer,Opts); - Result -> Result - end; -gethostbyname_tm(Name, Type, Timer, [yp | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [string|_]=Opts) -> + Result = gethostbyname_string(Name, Type), + gethostbyname_tm(Name, Type, Timer, Opts, Result); +gethostbyname_tm(Name, Type, Timer, [dns|_]=Opts) -> + Result = inet_res:gethostbyname_tm(Name, Type, Timer), + gethostbyname_tm(Name, Type, Timer, Opts, Result); +gethostbyname_tm(Name, Type, Timer, [file|_]=Opts) -> + Result = inet_hosts:gethostbyname(Name, Type), + gethostbyname_tm(Name, Type, Timer, Opts, Result); +gethostbyname_tm(Name, Type, Timer, [yp|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [nis | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [nis|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [nisplus | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [nisplus|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [wins | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [wins|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(Name, Type, Timer, [native | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [native|_]=Opts) -> gethostbyname_tm_native(Name, Type, Timer, Opts); -gethostbyname_tm(_, _, _, [no_default|_]) -> - %% If the native resolver has failed, we should not bother - %% to try to be smarter and parse the IP address here. - {error,nxdomain}; -gethostbyname_tm(Name, Type, Timer, [_ | Opts]) -> +gethostbyname_tm(Name, Type, Timer, [_|_]=Opts) -> gethostbyname_tm(Name, Type, Timer, Opts); -%% Last resort - parse the hostname as address -gethostbyname_tm(Name, inet, _Timer, []) -> - case inet_parse:ipv4_address(Name) of - {ok,IP4} -> - {ok,make_hostent(Name, [IP4], [], inet)}; - _ -> - gethostbyname_self(Name) - end; -gethostbyname_tm(Name, inet6, _Timer, []) -> - case inet_parse:ipv6_address(Name) of - {ok,IP6} -> - {ok,make_hostent(Name, [IP6], [], inet6)}; - _ -> - %% Even if Name is a valid IPv4 address, we can't - %% assume it's correct to return it on a IPv6 - %% format ( {0,0,0,0,0,16#ffff,?u16(A,B),?u16(C,D)} ). - %% This host might not support IPv6. - gethostbyname_self(Name) +%% Make sure we always can look up our own hostname. +gethostbyname_tm(Name, Type, Timer, []) -> + Result = gethostbyname_self(Name, Type), + gethostbyname_tm(Name, Type, Timer, [], Result). + +gethostbyname_tm(Name, Type, Timer, Opts, Result) -> + case Result of + {ok,_} -> + Result; + {error,formerr} -> + {error,einval}; + {error,_} when Opts =:= [] -> + {error,nxdomain}; + {error,_} -> + gethostbyname_tm(Name, Type, Timer, tl(Opts)) end. gethostbyname_tm_native(Name, Type, Timer, Opts) -> %% Fixme: add (global) timeout to gethost_native - case inet_gethost_native:gethostbyname(Name, Type) of - {error,formerr} -> {error,einval}; - {error,timeout} -> {error,timeout}; - {error,_} -> gethostbyname_tm(Name, Type, Timer, Opts++[no_default]); - Result -> Result - end. + Result = inet_gethost_native:gethostbyname(Name, Type), + gethostbyname_tm(Name, Type, Timer, Opts, Result). -%% Make sure we always can look up our own hostname. -gethostbyname_self(Name) -> - Type = case inet_db:res_option(inet6) of - true -> inet6; - false -> inet - end, + + +gethostbyname_self(Name, Type) when is_atom(Name) -> + gethostbyname_self(atom_to_list(Name), Type); +gethostbyname_self(Name, Type) + when is_list(Name), Type =:= inet; + is_list(Name), Type =:= inet6 -> case inet_db:gethostname() of Name -> - {ok,make_hostent(Name, [translate_ip(loopback, Type)], - [], Type)}; + {ok,make_hostent(Name, + [translate_ip(loopback, Type)], + [], Type)}; Self -> case inet_db:res_option(domain) of "" -> {error,nxdomain}; @@ -931,7 +928,31 @@ gethostbyname_self(Name) -> _ -> {error,nxdomain} end end - end. + end; +gethostbyname_self(_, _) -> + {error,formerr}. + +gethostbyname_string(Name, Type) when is_atom(Name) -> + gethostbyname_string(atom_to_list(Name), Type); +gethostbyname_string(Name, Type) + when is_list(Name), Type =:= inet; + is_list(Name), Type =:= inet6 -> + case + case Type of + inet -> + inet_parse:ipv4_address(Name); + inet6 -> + %% XXX should we really translate IPv4 addresses here + %% even if we do not know if this host can do IPv6? + inet_parse:ipv6_address(Name) + end of + {ok,IP} -> + {ok,make_hostent(Name, [IP], [], Type)}; + {error,einval} -> + {error,nxdomain} + end; +gethostbyname_string(_, _) -> + {error,formerr}. make_hostent(Name, Addrs, Aliases, Type) -> #hostent{h_name = Name, diff --git a/lib/kernel/src/inet_config.erl b/lib/kernel/src/inet_config.erl index b5317f72f5..311e6bc9f9 100644 --- a/lib/kernel/src/inet_config.erl +++ b/lib/kernel/src/inet_config.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_config). @@ -130,21 +130,25 @@ init() -> {unix,_} -> %% The Etc variable enables us to run tests with other %% configuration files than the normal ones - Etc = case os:getenv("ERL_INET_ETC_DIR") of - false -> ?DEFAULT_ETC; - _EtcDir -> - _EtcDir - end, + Etc = + case os:getenv("ERL_INET_ETC_DIR") of + false -> + ?DEFAULT_ETC; + _EtcDir -> + _EtcDir + end, case inet_db:res_option(resolv_conf) of undefined -> - inet_db:set_resolv_conf(filename:join(Etc, - ?DEFAULT_RESOLV)); + inet_db:res_option( + resolv_conf_name, + filename:join(Etc, ?DEFAULT_RESOLV)); _ -> ok end, case inet_db:res_option(hosts_file) of undefined -> - inet_db:set_hosts_file(filename:join(Etc, - ?DEFAULT_HOSTS)); + inet_db:res_option( + hosts_file_name, + filename:join(Etc, ?DEFAULT_HOSTS)); _ -> ok end; _ -> ok diff --git a/lib/kernel/src/inet_db.erl b/lib/kernel/src/inet_db.erl index 211847014f..a05b380855 100644 --- a/lib/kernel/src/inet_db.erl +++ b/lib/kernel/src/inet_db.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -425,7 +425,9 @@ res_optname(usevc) -> res_usevc; res_optname(edns) -> res_edns; res_optname(udp_payload_size) -> res_udp_payload_size; res_optname(resolv_conf) -> res_resolv_conf; +res_optname(resolv_conf_name) -> res_resolv_conf; res_optname(hosts_file) -> res_hosts_file; +res_optname(hosts_file_name) -> res_hosts_file; res_optname(_) -> undefined. res_check_option(nameserver, NSs) -> %% Legacy @@ -458,9 +460,15 @@ res_check_option(udp_payload_size, S) when is_integer(S), S >= 512 -> true; res_check_option(resolv_conf, "") -> true; res_check_option(resolv_conf, F) -> res_check_option_absfile(F); +res_check_option(resolv_conf_name, "") -> true; +res_check_option(resolv_conf_name, F) -> + res_check_option_absfile(F); res_check_option(hosts_file, "") -> true; res_check_option(hosts_file, F) -> res_check_option_absfile(F); +res_check_option(hosts_file_name, "") -> true; +res_check_option(hosts_file_name, F) -> + res_check_option_absfile(F); res_check_option(_, _) -> false. res_check_option_absfile(F) -> @@ -503,7 +511,7 @@ res_update_hosts() -> res_update(res_hosts_file, res_hosts_file_tm, res_hosts_file_info, set_hosts_file_tm, fun set_hosts_file/1). -res_update(Tag, TagTm, TagInfo, CallTag, SetFun) -> +res_update(Tag, TagTm, TagInfo, TagSetTm, SetFun) -> case db_get(TagTm) of undefined -> ok; TM -> @@ -522,12 +530,12 @@ res_update(Tag, TagTm, TagInfo, CallTag, SetFun) -> atime = undefined}, case db_get(TagInfo) of Finfo -> - call({CallTag, Now}); + call({TagSetTm, Now}); _ -> SetFun(File) end; _ -> - call({CallTag, Now}), + call({TagSetTm, Now}), error end end; @@ -974,37 +982,55 @@ handle_call(Request, From, #state{db=Db}=State) -> {reply, error, State} end; + {res_set, hosts_file_name=Option, Fname} -> + handle_set_file( + Option, Fname, res_hosts_file_tm, res_hosts_file_info, + undefined, From, State); + {res_set, resolv_conf_name=Option, Fname} -> + handle_set_file( + Option, Fname, res_resolv_conf_tm, res_resolv_conf_info, + undefined, From, State); + {res_set, hosts_file=Option, Fname} -> - handle_set_file(Option, Fname, - res_hosts_file_tm, res_hosts_file_info, - fun (Bin) -> - case inet_parse:hosts(Fname, - {chars,Bin}) of - {ok,Opts} -> - [{load_hosts_file,Opts}]; - _ -> error - end - end, - From, State); + handle_set_file( + Option, Fname, res_hosts_file_tm, res_hosts_file_info, + fun (Bin) -> + case inet_parse:hosts( + Fname, {chars,Bin}) of + {ok,Opts} -> + [{load_hosts_file,Opts}]; + _ -> error + end + end, + From, State); %% {res_set, resolv_conf=Option, Fname} -> - handle_set_file(Option, Fname, - res_resolv_conf_tm, res_resolv_conf_info, - fun (Bin) -> - case inet_parse:resolv(Fname, - {chars,Bin}) of - {ok,Opts} -> - [del_ns, - clear_search, - clear_cache - |[Opt || - {T,_}=Opt <- Opts, - (T =:= nameserver orelse - T =:= search)]]; - _ -> error - end - end, - From, State); + handle_set_file( + Option, Fname, res_resolv_conf_tm, res_resolv_conf_info, + fun (Bin) -> + case inet_parse:resolv( + Fname, {chars,Bin}) of + {ok,Opts} -> + Search = + lists:foldl( + fun ({search,L}, _) -> + L; + ({domain,""}, S) -> + S; + ({domain,D}, _) -> + [D]; + (_, S) -> + S + end, [], Opts), + [del_ns, + clear_search, + clear_cache, + {search,Search} + |[Opt || {nameserver,_}=Opt <- Opts]]; + _ -> error + end + end, + From, State); %% {res_set, Opt, Value} -> case res_optname(Opt) of @@ -1156,6 +1182,12 @@ handle_set_file(Option, Fname, TagTm, TagInfo, ParseFun, From, ets:delete(Db, TagInfo), ets:delete(Db, TagTm), handle_set_file(ParseFun, <<>>, From, State); + true when ParseFun =:= undefined -> + File = filename:flatten(Fname), + ets:insert(Db, {res_optname(Option), File}), + ets:insert(Db, {TagInfo, undefined}), + ets:insert(Db, {TagTm, 0}), + {reply,ok,State}; true -> File = filename:flatten(Fname), ets:insert(Db, {res_optname(Option), File}), @@ -1178,7 +1210,8 @@ handle_set_file(Option, Fname, TagTm, TagInfo, ParseFun, From, handle_set_file(ParseFun, Bin, From, State) -> case ParseFun(Bin) of - error -> {reply,error,State}; + error -> + {reply,error,State}; Opts -> handle_rc_list(Opts, From, State) end. diff --git a/lib/kernel/src/inet_gethost_native.erl b/lib/kernel/src/inet_gethost_native.erl index abdbe2b8cf..fabe9bf8b3 100644 --- a/lib/kernel/src/inet_gethost_native.erl +++ b/lib/kernel/src/inet_gethost_native.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_gethost_native). @@ -443,19 +443,23 @@ gethostbyname(Name) -> gethostbyname(Name, inet). gethostbyname(Name, inet) when is_list(Name) -> - getit(?OP_GETHOSTBYNAME, ?PROTO_IPV4, Name); + getit(?OP_GETHOSTBYNAME, ?PROTO_IPV4, Name, Name); gethostbyname(Name, inet6) when is_list(Name) -> - getit(?OP_GETHOSTBYNAME, ?PROTO_IPV6, Name); + getit(?OP_GETHOSTBYNAME, ?PROTO_IPV6, Name, Name); gethostbyname(Name, Type) when is_atom(Name) -> gethostbyname(atom_to_list(Name), Type); gethostbyname(_, _) -> {error, formerr}. -gethostbyaddr({A,B,C,D}) when ?VALID_V4(A), ?VALID_V4(B), ?VALID_V4(C), ?VALID_V4(D) -> - getit(?OP_GETHOSTBYADDR, ?PROTO_IPV4, <<A,B,C,D>>); -gethostbyaddr({A,B,C,D,E,F,G,H}) when ?VALID_V6(A), ?VALID_V6(B), ?VALID_V6(C), ?VALID_V6(D), - ?VALID_V6(E), ?VALID_V6(F), ?VALID_V6(G), ?VALID_V6(H) -> - getit(?OP_GETHOSTBYADDR, ?PROTO_IPV6, <<A:16,B:16,C:16,D:16,E:16,F:16,G:16,H:16>>); +gethostbyaddr({A,B,C,D}=Addr) + when ?VALID_V4(A), ?VALID_V4(B), ?VALID_V4(C), ?VALID_V4(D) -> + getit(?OP_GETHOSTBYADDR, ?PROTO_IPV4, <<A,B,C,D>>, Addr); +gethostbyaddr({A,B,C,D,E,F,G,H}=Addr) + when ?VALID_V6(A), ?VALID_V6(B), ?VALID_V6(C), ?VALID_V6(D), + ?VALID_V6(E), ?VALID_V6(F), ?VALID_V6(G), ?VALID_V6(H) -> + getit + (?OP_GETHOSTBYADDR, ?PROTO_IPV6, + <<A:16,B:16,C:16,D:16,E:16,F:16,G:16,H:16>>, Addr); gethostbyaddr(Addr) when is_list(Addr) -> case inet_parse:address(Addr) of {ok, IP} -> gethostbyaddr(IP); @@ -466,30 +470,30 @@ gethostbyaddr(Addr) when is_atom(Addr) -> gethostbyaddr(_) -> {error, formerr}. control({debug_level, Level}) when is_integer(Level) -> - getit(?OP_CONTROL, ?SETOPT_DEBUG_LEVEL, <<Level:32>>); + getit(?OP_CONTROL, ?SETOPT_DEBUG_LEVEL, <<Level:32>>, undefined); control(soft_restart) -> - getit(restart_port); + getit(restart_port, undefined); control(_) -> {error, formerr}. -getit(Op, Proto, Data) -> - getit({Op, Proto, Data}). +getit(Op, Proto, Data, DefaultName) -> + getit({Op, Proto, Data}, DefaultName). -getit(Req) -> +getit(Req, DefaultName) -> Pid = ensure_started(), Ref = make_ref(), Pid ! {{self(),Ref}, Req}, receive {Ref, {ok,BinHostent}} -> - parse_address(BinHostent); - {Ref, Error} -> - Error + parse_address(BinHostent, DefaultName); + {Ref, Result} -> + Result after 5000 -> Ref2 = erlang:monitor(process,Pid), Res2 = receive {Ref, {ok,BinHostent}} -> - parse_address(BinHostent); - {Ref, Error} -> - Error; + parse_address(BinHostent, DefaultName); + {Ref, Result} -> + Result; {'DOWN', Ref2, process, Pid, Reason} -> {error, Reason} @@ -546,21 +550,23 @@ ensure_started() -> Pid end. -parse_address(BinHostent) -> +parse_address(BinHostent, DefaultName) -> case catch begin case BinHostent of <<?UNIT_ERROR, Errstring/binary>> -> {error, list_to_atom(listify(Errstring))}; <<?UNIT_IPV4, Naddr:32, T0/binary>> -> - {T1,Addresses} = pick_addresses_v4(Naddr, T0), - [Name | Names] = pick_names(T1), + {T1, Addresses} = pick_addresses_v4(Naddr, T0), + {Name, Names} = + expand_default_name(pick_names(T1), DefaultName), {ok, #hostent{h_addr_list = Addresses, h_addrtype = inet, h_aliases = Names, h_length = ?UNIT_IPV4, h_name = Name}}; <<?UNIT_IPV6, Naddr:32, T0/binary>> -> - {T1,Addresses} = pick_addresses_v6(Naddr, T0), - [Name | Names] = pick_names(T1), + {T1, Addresses} = pick_addresses_v6(Naddr, T0), + {Name, Names} = + expand_default_name(pick_names(T1), DefaultName), {ok, #hostent{h_addr_list = Addresses, h_addrtype = inet6, h_aliases = Names, h_length = ?UNIT_IPV6, h_name = Name}}; @@ -573,7 +579,15 @@ parse_address(BinHostent) -> Normal -> Normal end. - + +expand_default_name([], DefaultName) when is_list(DefaultName) -> + {DefaultName, []}; +expand_default_name([], DefaultName) when is_tuple(DefaultName) -> + {inet_parse:ntoa(DefaultName), []}; +expand_default_name([Name|Names], DefaultName) + when is_list(DefaultName); is_tuple(DefaultName) -> + {Name, Names}. + listify(Bin) -> N = byte_size(Bin) - 1, <<Bin2:N/binary, Ch>> = Bin, diff --git a/lib/kernel/src/inet_parse.erl b/lib/kernel/src/inet_parse.erl index 62d44fb723..3bd5fa0958 100644 --- a/lib/kernel/src/inet_parse.erl +++ b/lib/kernel/src/inet_parse.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_parse). @@ -34,6 +34,7 @@ -export([nsswitch_conf/1, nsswitch_conf/2]). -export([ipv4_address/1, ipv6_address/1]). +-export([ipv4strict_address/1, ipv6strict_address/1]). -export([address/1]). -export([visible_string/1, domain/1]). -export([ntoa/1, dots/1]). @@ -456,17 +457,15 @@ is_dom2(_) -> %% -%% Test ipv4 address or ipv6 address +%% Parse ipv4 address or ipv6 address %% Return {ok, Address} | {error, Reason} %% address(Cs) when is_list(Cs) -> case ipv4_address(Cs) of - {ok,IP} -> {ok,IP}; + {ok,IP} -> + {ok,IP}; _ -> - case ipv6_address(Cs) of - {ok, IP} -> {ok, IP}; - Error -> Error - end + ipv6strict_address(Cs) end; address(_) -> {error, einval}. @@ -477,49 +476,145 @@ address(_) -> %% d1.d2.d4 %% d1.d4 %% d4 +%% Any d may be octal, hexadecimal or decimal by C language standards. +%% d4 fills all LSB bytes. This is legacy behaviour from Solaris +%% and FreeBSD. And partly Linux that behave the same except +%% it does not accept hexadecimal. %% %% Return {ok, IP} | {error, einval} %% ipv4_address(Cs) -> - case catch ipv4_addr(Cs) of - {'EXIT',_} -> {error,einval}; - Addr -> {ok,Addr} + try ipv4_addr(Cs) of + Addr -> + {ok,Addr} + catch + error:badarg -> + {error,einval} end. -ipv4_addr(Cs) -> - ipv4_addr(d3(Cs), []). +ipv4_addr(Cs) -> + case ipv4_addr(Cs, []) of + [D] when D < (1 bsl 32) -> + <<D1,D2,D3,D4>> = <<D:32>>, + {D1,D2,D3,D4}; + [D,D1] when D < (1 bsl 24), D1 < 256 -> + <<D2,D3,D4>> = <<D:24>>, + {D1,D2,D3,D4}; + [D,D2,D1] when D < (1 bsl 16), (D2 bor D1) < 256 -> + <<D3,D4>> = <<D:16>>, + {D1,D2,D3,D4}; + [D4,D3,D2,D1] when (D4 bor D3 bor D2 bor D1) < 256 -> + {D1,D2,D3,D4}; + _ -> + erlang:error(badarg) + end. -ipv4_addr({Cs0,[]}, A) when length(A) =< 3 -> - case [tod(Cs0)|A] of - [D4,D3,D2,D1] -> +ipv4_addr([_|_], [_,_,_,_]) -> + %% Early bailout for extra characters + erlang:error(badarg); +ipv4_addr("0x"++Cs, Ds) -> + ipv4_addr(strip0(Cs), Ds, [], 16, 8); +ipv4_addr("0X"++Cs, Ds) -> + ipv4_addr(strip0(Cs), Ds, [], 16, 8); +ipv4_addr("0"++Cs, Ds) -> + ipv4_addr(strip0(Cs), Ds, [$0], 8, 11); +ipv4_addr(Cs, Ds) when is_list(Cs) -> + ipv4_addr(Cs, Ds, [], 10, 10). + +ipv4_addr(Cs0, Ds, Rs, Base, N) -> + case ipv4_field(Cs0, N, Rs, Base) of + {D,""} -> + [D|Ds]; + {D,[$.|[_|_]=Cs]} -> + ipv4_addr(Cs, [D|Ds]); + {_,_} -> + erlang:error(badarg) + end. + +strip0("0"++Cs) -> + strip0(Cs); +strip0(Cs) when is_list(Cs) -> + Cs. + + +%% +%% Parse IPv4 strict dotted decimal address, no leading zeros: +%% d1.d2.d3.d4 +%% +%% Return {ok, IP} | {error, einval} +%% +ipv4strict_address(Cs) -> + try ipv4strict_addr(Cs) of + Addr -> + {ok,Addr} + catch + error:badarg -> + {error,einval} + end. + +ipv4strict_addr(Cs) -> + case ipv4strict_addr(Cs, []) of + [D4,D3,D2,D1] when (D4 bor D3 bor D2 bor D1) < 256 -> {D1,D2,D3,D4}; - [D4,D2,D1] -> - {D1,D2,0,D4}; - [D4,D1] -> - {D1,0,0,D4}; - [D4] -> - {0,0,0,D4} - end; -ipv4_addr({Cs0,"."++Cs1}, A) when length(A) =< 2 -> - ipv4_addr(d3(Cs1), [tod(Cs0)|A]). + _ -> + erlang:error(badarg) + end. + +ipv4strict_addr([_|_], [_,_,_,_]) -> + %% Early bailout for extra characters + erlang:error(badarg); +ipv4strict_addr("0", Ds) -> + [0|Ds]; +ipv4strict_addr("0."++Cs, Ds) -> + ipv4strict_addr(Cs, [0|Ds]); +ipv4strict_addr(Cs0, Ds) when is_list(Cs0) -> + case ipv4_field(Cs0, 3, [], 10) of + {D,""} -> + [D|Ds]; + {D,[$.|[_|_]=Cs]} -> + ipv4strict_addr(Cs, [D|Ds]); + {_,_} -> + erlang:error(badarg) + end. + -d3(Cs) -> d3(Cs, []). -d3([C|Cs], R) when C >= $0, C =< $9, length(R) =< 2 -> - d3(Cs, [C|R]); -d3(Cs, [_|_]=R) -> - {lists:reverse(R),Cs}. +ipv4_field("", _, Rs, Base) -> + {ipv4_field(Rs, Base),""}; +ipv4_field("."++_=Cs, _, Rs, Base) -> + {ipv4_field(Rs, Base),Cs}; +ipv4_field("0"++_, _, [], _) -> + erlang:error(badarg); +ipv4_field([C|Cs], N, Rs, Base) when N > 0 -> + ipv4_field(Cs, N-1, [C|Rs], Base); +ipv4_field(Cs, _, _, _) when is_list(Cs) -> + erlang:error(badarg). + +ipv4_field(Rs, Base) -> + V = erlang:list_to_integer(lists:reverse(Rs), Base), + if V < 0 -> + erlang:error(badarg); + true -> + V + end. -tod(Cs) -> - case erlang:list_to_integer(Cs) of - D when D >= 0, D =< 255 -> - D; + + +%% +%% Forgiving IPv6 address +%% +%% Accepts IPv4 address and returns it as a IPv4 compatible IPv6 address +%% +ipv6_address(Cs) -> + case ipv4_address(Cs) of + {ok,{D1,D2,D3,D4}} -> + {ok,{0,0,0,0,0,16#ffff,(D1 bsl 8) bor D2,(D3 bsl 8) bor D4}}; _ -> - erlang:error(badarg, [Cs]) + ipv6strict_address(Cs) end. %% -%% Parse IPv6 address: +%% Parse IPv6 address according to RFC 4291: %% x1:x2:x3:x4:x5:x6:x7:x8 %% x1:x2::x7:x8 %% ::x7:x8 @@ -530,77 +625,89 @@ tod(Cs) -> %% ::x5:x6:d7a.d7b.d8a.d8b %% x1:x2::d7a.d7b.d8a.d8b %% ::d7a.d7b.d8a.d8b +%% etc %% %% Return {ok, IP} | {error, einval} %% -ipv6_address(Cs) -> - case catch ipv6_addr(Cs) of - {'EXIT',_} -> {error,einval}; - Addr -> {ok,Addr} +ipv6strict_address(Cs) -> + try ipv6_addr(Cs) of + Addr -> + {ok,Addr} + catch + error:badarg -> + {error,einval} end. ipv6_addr("::") -> - ipv6_addr_done([], []); + ipv6_addr_done([], [], 0); ipv6_addr("::"++Cs) -> - ipv6_addr(x4(Cs), [], []); + ipv6_addr(hex(Cs), [], [], 0); ipv6_addr(Cs) -> - ipv6_addr(x4(Cs), []). + ipv6_addr(hex(Cs), [], 0). %% Before "::" -ipv6_addr({Cs0,[]}, A) when length(A) =:= 7 -> - ipv6_addr_done([tox(Cs0)|A]); -ipv6_addr({Cs0,"::"}, A) when length(A) =< 6 -> - ipv6_addr_done([tox(Cs0)|A], []); -ipv6_addr({Cs0,"::"++Cs1}, A) when length(A) =< 5 -> - ipv6_addr(x4(Cs1), [tox(Cs0)|A], []); -ipv6_addr({Cs0,":"++Cs1}, A) when length(A) =< 6 -> - ipv6_addr(x4(Cs1), [tox(Cs0)|A]); -ipv6_addr({Cs0,"."++Cs1}, A) when length(A) =:= 6 -> - ipv6_addr(d3(Cs1), A, [], [tod(Cs0)]). +ipv6_addr({Cs0,[]}, A, N) when N == 7 -> + ipv6_addr_done([hex_to_int(Cs0)|A]); +ipv6_addr({Cs0,"::"}, A, N) when N =< 6 -> + ipv6_addr_done([hex_to_int(Cs0)|A], [], N+1); +ipv6_addr({Cs0,"::"++Cs1}, A, N) when N =< 5 -> + ipv6_addr(hex(Cs1), [hex_to_int(Cs0)|A], [], N+1); +ipv6_addr({Cs0,":"++Cs1}, A, N) when N =< 6 -> + ipv6_addr(hex(Cs1), [hex_to_int(Cs0)|A], N+1); +ipv6_addr({Cs0,"."++_=Cs1}, A, N) when N == 6 -> + ipv6_addr_done(A, [], N, ipv4strict_addr(Cs0++Cs1)); +ipv6_addr(_, _, _) -> + erlang:error(badarg). %% After "::" -ipv6_addr({Cs0,[]}, A, B) when length(A)+length(B) =< 6 -> - ipv6_addr_done(A, [tox(Cs0)|B]); -ipv6_addr({Cs0,":"++Cs1}, A, B) when length(A)+length(B) =< 5 -> - ipv6_addr(x4(Cs1), A, [tox(Cs0)|B]); -ipv6_addr({Cs0,"."++Cs1}, A, B) when length(A)+length(B) =< 5 -> - ipv6_addr(x4(Cs1), A, B, [tod(Cs0)]). +ipv6_addr({Cs0,[]}, A, B, N) when N =< 6 -> + ipv6_addr_done(A, [hex_to_int(Cs0)|B], N+1); +ipv6_addr({Cs0,":"++Cs1}, A, B, N) when N =< 5 -> + ipv6_addr(hex(Cs1), A, [hex_to_int(Cs0)|B], N+1); +ipv6_addr({Cs0,"."++_=Cs1}, A, B, N) when N =< 5 -> + ipv6_addr_done(A, B, N, ipv4strict_addr(Cs0++Cs1)); +ipv6_addr(_, _, _, _) -> + erlang:error(badarg). -%% After "." -ipv6_addr({Cs0,[]}, A, B, C) when length(C) =:= 3 -> - ipv6_addr_done(A, B, [tod(Cs0)|C]); -ipv6_addr({Cs0,"."++Cs1}, A, B, C) when length(C) =< 2 -> - ipv6_addr(d3(Cs1), A, B, [tod(Cs0)|C]). +ipv6_addr_done(Ar, Br, N, {D1,D2,D3,D4}) -> + ipv6_addr_done(Ar, [((D3 bsl 8) bor D4),((D1 bsl 8) bor D2)|Br], N+2). -ipv6_addr_done(Ar, Br, [D4,D3,D2,D1]) -> - ipv6_addr_done(Ar, [((D3 bsl 8) bor D4),((D1 bsl 8) bor D2)|Br]). - -ipv6_addr_done(Ar, Br) -> - ipv6_addr_done(Br++dup(8-length(Ar)-length(Br), 0, Ar)). +ipv6_addr_done(Ar, Br, N) -> + ipv6_addr_done(Br++dup(8-N, 0, Ar)). ipv6_addr_done(Ar) -> list_to_tuple(lists:reverse(Ar)). -x4(Cs) -> x4(Cs, []). - -x4([C|Cs], R) when C >= $0, C =< $9, length(R) =< 3 -> - x4(Cs, [C|R]); -x4([C|Cs], R) when C >= $a, C =< $f, length(R) =< 3 -> - x4(Cs, [C|R]); -x4([C|Cs], R) when C >= $A, C =< $F, length(R) =< 3 -> - x4(Cs, [C|R]); -x4(Cs, [_|_]=R) -> - {lists:reverse(R),Cs}. - -tox(Cs) -> - erlang:list_to_integer(Cs, 16). +%% Collect Hex digits +hex(Cs) -> hex(Cs, []). +%% +hex([C|Cs], R) when C >= $0, C =< $9 -> + hex(Cs, [C|R]); +hex([C|Cs], R) when C >= $a, C =< $f -> + hex(Cs, [C|R]); +hex([C|Cs], R) when C >= $A, C =< $F -> + hex(Cs, [C|R]); +hex(Cs, [_|_]=R) when is_list(Cs) -> + {lists:reverse(R),Cs}; +hex(_, _) -> + erlang:error(badarg). + +%% Hex string to integer +hex_to_int(Cs0) -> + case strip0(Cs0) of + Cs when length(Cs) =< 4 -> + erlang:list_to_integer("0"++Cs, 16); + _ -> + erlang:error(badarg) + end. +%% Dup onto head of existing list dup(0, _, L) -> L; dup(N, E, L) when is_integer(N), N >= 1 -> - dup(N-1, E, [E|L]); -dup(N, E, L) -> - erlang:error(badarg, [N,E,L]). + dup(N-1, E, [E|L]). + + %% Convert IPv4 adress to ascii %% Convert IPv6 / IPV4 adress to ascii (plain format) @@ -674,7 +781,7 @@ separate(_E, [H], R) -> lists:reverse(R, [H]). %% convert to A.B decimal form -dig_to_dec(0) -> [$0,$.,$0]; +dig_to_dec(0) -> "0.0"; dig_to_dec(X) -> integer_to_list((X bsr 8) band 16#ff) ++ "." ++ integer_to_list(X band 16#ff). diff --git a/lib/kernel/src/user.erl b/lib/kernel/src/user.erl index edf650ec59..17dc5a56a2 100644 --- a/lib/kernel/src/user.erl +++ b/lib/kernel/src/user.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(user). @@ -698,7 +698,11 @@ get_chars_more(State, M, F, Xa, Port, Q, Fmt) -> prompt(_Port, '') -> ok; prompt(Port, Prompt) -> - put_port(io_lib:format_prompt(Prompt), Port). + put_port(wrap_characters_to_binary(io_lib:format_prompt(Prompt),unicode, + case get(unicode) of + true -> unicode; + _ -> latin1 + end), Port). %% Convert error code to make it look as before err_func(io_lib, get_until, {_,F,_}) -> diff --git a/lib/kernel/test/inet_SUITE.erl b/lib/kernel/test/inet_SUITE.erl index cf33e8b27f..eb8f918491 100644 --- a/lib/kernel/test/inet_SUITE.erl +++ b/lib/kernel/test/inet_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_SUITE). @@ -28,7 +28,7 @@ gethostnative_parallell/1, cname_loop/1, gethostnative_soft_restart/1,gethostnative_debug_level/1,getif/1]). --export([get_hosts/1, get_ipv6_hosts/1, parse_hosts/1, +-export([get_hosts/1, get_ipv6_hosts/1, parse_hosts/1, parse_address/1, kill_gethost/0, parallell_gethost/0]). -export([init_per_testcase/2, end_per_testcase/2]). @@ -249,14 +249,16 @@ t_getaddr_v6(Config) when is_list(Config) -> ?line {ok,IP46} = inet:getaddr(IP46, inet6), ?line {ok,IP46} = inet:getaddr(Name, inet6), ?line {ok,IP46} = inet:getaddr(FullName, inet6), - ?line IP4toIP6 = inet:getaddr(IPStr, inet6), - ?line case IP4toIP6 of - {ok,IP46} -> % only native can do this - ?line true = lists:member(native, - inet_db:res_option(lookup)); - {error,nxdomain} -> - ok - end, + ?line {ok,IP46} = inet:getaddr(IPStr, inet6), +%% ?line IP4toIP6 = inet:getaddr(IPStr, inet6), +%% ?line case IP4toIP6 of +%% {ok,IP46} -> +%% ?line ok; +%% {error,nxdomain} -> +%% ?line false = +%% lists:member(native, +%% inet_db:res_option(lookup)) +%% end, ?line {Name6, FullName6, IPStr6, IP6, _} = ?config(test_host_ipv6_only, Config), ?line {ok,_} = inet:getaddr(list_to_atom(Name6), inet6), @@ -301,7 +303,6 @@ ipv4_to_ipv6(Config) when is_list(Config) -> end, ?line case {IP4to6Res,inet:gethostbyname(IPStr, inet6)} of {true,{ok,HEnt}} -> - ?line true = lists:member(native, inet_db:res_option(lookup)), ?line HEnt_ = HEnt#hostent{h_addrtype = inet6, h_length = 16, h_addr_list = [IP_46]}, @@ -374,9 +375,10 @@ get_hosts([C|Rest], Cur, Ip, Result) -> get_hosts([], _, _, Result) -> Result. -parse(suite) -> [parse_hosts]; +parse(suite) -> [parse_hosts, parse_address]; parse(doc) -> ["Test that parsing of the hosts file or equivalent works,", "and that erroneous lines are skipped"]. + parse_hosts(Config) when is_list(Config) -> ?line DataDir = ?config(data_dir,Config), ?line HostFile = filename:join(DataDir, "hosts"), @@ -388,6 +390,170 @@ parse_hosts(Config) when is_list(Config) -> ?line ResolvErr1 = filename:join(DataDir,"resolv.conf.err1"), ?line inet_parse:resolv(ResolvErr1). +parse_address(Config) when is_list(Config) -> + V4Strict = + [{{0,0,0,0},"0.0.0.0"}, + {{1,2,3,4},"1.2.3.4"}, + {{253,252,251,250},"253.252.251.250"}, + {{1,2,255,254},"1.2.255.254"}], + V6Strict = + [{{0,0,0,0,0,0,0,0},"::"}, + {{15,0,0,0,0,0,0,2},"f::2"}, + {{15,16#f11,0,0,0,0,256,2},"f:f11::0100:2"}, + {{0,0,0,0,0,0,0,16#17},"::17"}, + {{16#700,0,0,0,0,0,0,0},"0700::"}, + {{0,0,0,0,0,0,2,1},"::2:1"}, + {{0,0,0,0,0,3,2,1},"::3:2:1"}, + {{0,0,0,0,4,3,2,1},"::4:3:2:1"}, + {{0,0,0,5,4,3,2,1},"::5:4:3:2:1"}, + {{0,0,6,5,4,3,2,1},"::6:5:4:3:2:1"}, + {{0,7,6,5,4,3,2,1},"::7:6:5:4:3:2:1"}, + {{7,0,0,0,0,0,0,0},"7::"}, + {{7,6,0,0,0,0,0,0},"7:6::"}, + {{7,6,5,0,0,0,0,0},"7:6:5::"}, + {{7,6,5,4,0,0,0,0},"7:6:5:4::"}, + {{7,6,5,4,3,0,0,0},"7:6:5:4:3::"}, + {{7,6,5,4,3,2,0,0},"7:6:5:4:3:2::"}, + {{7,6,5,4,3,2,1,0},"7:6:5:4:3:2:1::"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22:5c33:c440:55c0:c66c:77:0088"}, + {{16#c11,0,16#5c33,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11::5c33:c440:55c0:c66c:77:0088"}, + {{16#c11,16#c22,0,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22::c440:55c0:c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,0,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22:5c33::55c0:c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,0,16#c66c,16#77,16#88}, + "c11:0c22:5c33:c440::c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,0,16#77,16#88}, + "c11:0c22:5c33:c440:55c0::77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,16#c66c,0,16#88}, + "c11:0c22:5c33:c440:55c0:c66c::0088"}, + {{16#c11,0,0,16#c440,16#55c0,16#c66c,16#77,16#88}, + "c11::c440:55c0:c66c:77:0088"}, + {{16#c11,16#c22,0,0,16#55c0,16#c66c,16#77,16#88}, + "c11:0c22::55c0:c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,0,0,16#c66c,16#77,16#88}, + "c11:0c22:5c33::c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,0,0,16#77,16#88}, + "c11:0c22:5c33:c440::77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,16#55c0,0,0,16#88}, + "c11:0c22:5c33:c440:55c0::0088"}, + {{16#c11,0,0,0,16#55c0,16#c66c,16#77,16#88}, + "c11::55c0:c66c:77:0088"}, + {{16#c11,16#c22,0,0,0,16#c66c,16#77,16#88}, + "c11:0c22::c66c:77:0088"}, + {{16#c11,16#c22,16#5c33,0,0,0,16#77,16#88}, + "c11:0c22:5c33::77:0088"}, + {{16#c11,16#c22,16#5c33,16#c440,0,0,0,16#88}, + "c11:0c22:5c33:c440::0088"}, + {{16#c11,0,0,0,0,16#c66c,16#77,16#88}, + "c11::c66c:77:0088"}, + {{16#c11,16#c22,0,0,0,0,16#77,16#88}, + "c11:0c22::77:0088"}, + {{16#c11,16#c22,16#5c33,0,0,0,0,16#88}, + "c11:0c22:5c33::0088"}, + {{16#c11,0,0,0,0,0,16#77,16#88}, + "c11::77:0088"}, + {{16#c11,16#c22,0,0,0,0,0,16#88}, + "c11:0c22::0088"}, + {{0,0,0,0,0,65535,258,65534},"::FFFF:1.2.255.254"}, + {{16#ffff,16#ffff,16#ffff,16#ffff,16#ffff,16#ffff,16#ffff,16#ffff}, + "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"} + |[{{D2,0,0,0,0,P,(D1 bsl 8) bor D2,(D3 bsl 8) bor D4}, + erlang:integer_to_list(D2, 16)++"::"++Q++S} + || {{D1,D2,D3,D4},S} <- V4Strict, + {P,Q} <- [{0,""},{16#17,"17:"},{16#ff0,"0ff0:"}]]], + V4Sloppy = + [{{10,1,16#98,16#76},"10.0x019876"}, + {{8#12,1,8#130,8#321},"012.01.054321"}, + {{255,255,255,255},"255.255.255.0377"}, + {{255,255,255,255},"0Xff.000000000377.0x0000ff.255"}, + {{255,255,255,255},"255.255.65535"}, + {{255,255,255,255},"255.0xFF.0177777"}, + {{255,255,255,255},"255.16777215"}, + {{255,255,255,255},"00377.0XFFFFFF"}, + {{255,255,255,255},"4294967295"}, + {{255,255,255,255},"0xffffffff"}, + {{255,255,255,255},"00000000000037777777777"}, + {{16#12,16#34,16#56,16#78},"0x12345678"}, + {{16#12,16#34,16#56,16#78},"0x12.0x345678"}, + {{16#12,16#34,16#56,16#78},"0x12.0X34.0x5678"}, + {{16#12,16#34,16#56,16#78},"0x12.0X34.0x56.0X78"}, + {{0,0,0,0},"0"}, + {{0,0,0,0},"00"}, + {{0,0,0,0},"0.0"}, + {{0,0,0,0},"00.00.00"}, + {{0,0,0,0},"0.00.0.0"}, + {{0,0,0,0},"0.0.000000000000.0"}], + V6Sloppy = + [{{0,0,0,0,0,65535,(D1 bsl 8) bor D2,(D3 bsl 8) bor D4},S} + || {{D1,D2,D3,D4},S} <- V4Strict++V4Sloppy], + V4Err = + ["0.256.0.1", + "1.2.3.4.5", + "256.255.65535", + "4294967296", + "0x100000000", + "040000000000", + "1.2.3.-4", + "1.2.-3.4", + "1.-2.3.4", + "-1.2.3.4", + "10.", + "172.16.", + "198.168.0.", + "127.0.0.1."], + V6Err = + [":::", + "f:::2", + "::-1", + "::g", + "f:f11::10100:2", + "::17000", + "10000::", + "::8:7:6:5:4:3:2:1", + "8:7:6:5:4:3:2:1::", + "8:7:6:5:4::3:2:1", + "::1.2.3.4.5", + "::1.2.3.04", + "::1.256.3.4", + "::-5.4.3.2", + "::5.-4.3.2", + "::5.4.-3.2", + "::5.4.3.-2", + "::FFFF:1.2.3.4.5", + "::10.", + "::FFFF:172.16.", + "fe80::198.168.0.", + "fec0::fFfF:127.0.0.1."], + t_parse_address + (ipv6_address, + V6Strict++V6Sloppy++V6Err++V4Err), + t_parse_address + (ipv6strict_address, + V6Strict++V6Err++V4Err++[S || {_,S} <- V6Sloppy]), + t_parse_address + (ipv4_address, + V4Strict++V4Sloppy++V4Err++V6Err++[S || {_,S} <- V6Strict]), + t_parse_address + (ipv4strict_address, + V4Strict++V4Err++V6Err++[S || {_,S} <- V4Sloppy++V6Strict]). + +t_parse_address(Func, []) -> + io:format("~p done.~n", [Func]), + ok; +t_parse_address(Func, [{Addr,String}|L]) -> + io:format("~p = ~p.~n", [Addr,String]), + {ok,Addr} = inet_parse:Func(String), + t_parse_address(Func, L); +t_parse_address(Func, [String|L]) -> + io:format("~p.~n", [String]), + {error,einval} = inet_parse:Func(String), + t_parse_address(Func, L). + + + t_gethostnative(suite) ->[]; t_gethostnative(doc) ->[]; t_gethostnative(Config) when is_list(Config) -> diff --git a/lib/kernel/test/inet_res_SUITE.erl b/lib/kernel/test/inet_res_SUITE.erl index 659cfc5988..cc32d1f8f9 100644 --- a/lib/kernel/test/inet_res_SUITE.erl +++ b/lib/kernel/test/inet_res_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2009-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(inet_res_SUITE). @@ -239,16 +239,37 @@ resolve(_Opts, []) -> ok; resolve(Opts, [{Class,Type,Name,Answers,Authority}=Q|Qs]) -> io:format("Query: ~p~nOptions: ~p~n", [Q,Opts]), {ok,Msg} = inet_res:resolve(Name, Class, Type, Opts), - if Answers =/= undefined -> - AnList = lists:sort(Answers), - AnList = lists:sort([inet_dns:rr(RR, data) || - RR <- inet_dns:msg(Msg, anlist)]); - true -> ok end, - if Authority =/= undefined -> - NsList = lists:sort(Authority), - NsList = lists:sort([inet_dns:rr(RR, data) || - RR <- inet_dns:msg(Msg, nslist)]); - true -> ok end, + AnList = + if + Answers =/= undefined -> + lists:sort(Answers); + true -> + undefined + end, + NsList = + if + Authority =/= undefined -> + lists:sort(Authority); + true -> + undefined + end, + case {lists:sort + ([inet_dns:rr(RR, data) || RR <- inet_dns:msg(Msg, anlist)]), + lists:sort + ([inet_dns:rr(RR, data) || RR <- inet_dns:msg(Msg, nslist)])} of + {AnList,NsList} -> + ok; + {NsList,AnList} when Type =:= ns -> + %% This whole case statement is kind of inside out just + %% to accept this case when some legacy DNS resolvers + %% return the answer to a NS query in the answer section + %% instead of in the authority section. + ok; + {AnList,_} when NsList =:= undefined -> + ok; + {_,NsList} when AnList =:= undefined -> + ok + end, Buf = inet_dns:encode(Msg), {ok,Msg} = inet_dns:decode(Buf), resolve(Opts, Qs). @@ -292,10 +313,23 @@ edns0(Config) when is_list(Config) -> MXs = lists:sort(inet_res_filter(inet_dns:msg(Msg2, anlist), in, mx)), Buf2 = inet_dns:encode(Msg2), {ok,Msg2} = inet_dns:decode(Buf2), - [OptRR] = [RR || RR <- inet_dns:msg(Msg2, arlist), - inet_dns:rr(RR, type) =:= opt], - io:format("~p~n", [inet_dns:rr(OptRR)]), - ok. + case [RR || RR <- inet_dns:msg(Msg2, arlist), + inet_dns:rr(RR, type) =:= opt] of + [OptRR] -> + io:format("~p~n", [inet_dns:rr(OptRR)]), + ok; + [] -> + case os:type() of + {unix,sunos} -> + case os:version() of + {M,V,_} when M < 5; M == 5, V =< 8 -> + %% In our test park only known platform + %% with an DNS resolver that can not do + %% EDNS0. + {comment,"No EDNS0"} + end + end + end. inet_res_filter(Anlist, Class, Type) -> [inet_dns:rr(RR, data) || RR <- Anlist, @@ -331,11 +365,13 @@ files_monitor(suite) -> files_monitor(doc) -> ["Tests monitoring of /etc/hosts and /etc/resolv.conf, but not them"]; files_monitor(Config) when is_list(Config) -> + Search = inet_db:res_option(search), HostsFile = inet_db:res_option(hosts_file), ResolvConf = inet_db:res_option(resolv_conf), Inet6 = inet_db:res_option(inet6), try do_files_monitor(Config) after + inet_db:res_option(search, Search), inet_db:res_option(resolv_conf, ResolvConf), inet_db:res_option(hosts_file, HostsFile), inet_db:res_option(inet6, Inet6) @@ -344,7 +380,13 @@ files_monitor(Config) when is_list(Config) -> do_files_monitor(Config) -> Dir = ?config(priv_dir, Config), {ok,Hostname} = inet:gethostname(), - FQDN = Hostname++"."++inet_db:res_option(domain), + FQDN = + case inet_db:res_option(domain) of + "" -> + Hostname; + _ -> + Hostname++"."++inet_db:res_option(domain) + end, HostsFile = filename:join(Dir, "files_monitor_hosts"), ResolvConf = filename:join(Dir, "files_monitor_resolv.conf"), ok = inet_db:res_option(resolv_conf, ResolvConf), @@ -362,20 +404,20 @@ do_files_monitor(Config) -> {error,nxdomain} = inet_res:gethostbyname(FQDN), {ok,{127,0,0,10}} = inet:getaddr("mx.otptest", inet), {ok,{0,0,0,0,0,0,32512,28}} = inet:getaddr("resolve.otptest", inet6), - ok = inet_db:res_option(inet6, true), {ok,#hostent{h_name = Hostname, h_addrtype = inet6, h_length = 16, h_addr_list = [{0,0,0,0,0,0,0,1}]}} = - inet:gethostbyname(Hostname), + inet:gethostbyname(Hostname, inet6), {ok,#hostent{h_name = FQDN, h_addrtype = inet6, h_length = 16, h_addr_list = [{0,0,0,0,0,0,0,1}]}} = - inet:gethostbyname(FQDN), + inet:gethostbyname(FQDN, inet6), {error,nxdomain} = inet_res:gethostbyname("resolve"), %% XXX inet does not honour res_option inet6, might be a problem? %% therefore inet_res is called here + ok = inet_db:res_option(inet6, true), {ok,#hostent{h_name = "resolve.otptest", h_addrtype = inet6, h_length = 16, diff --git a/lib/parsetools/vsn.mk b/lib/parsetools/vsn.mk index e3db40c193..b1354e89d8 100644 --- a/lib/parsetools/vsn.mk +++ b/lib/parsetools/vsn.mk @@ -1 +1 @@ -PARSETOOLS_VSN = 2.0.1 +PARSETOOLS_VSN = 2.0.2 diff --git a/lib/percept/src/egd_render.erl b/lib/percept/src/egd_render.erl index cea9d2d926..4a0247dd33 100644 --- a/lib/percept/src/egd_render.erl +++ b/lib/percept/src/egd_render.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2008-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2008-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -179,7 +179,7 @@ color(Trans,Layers,Type,OldC) -> color([],_) -> {0.0,0.0,0.0,0.0}; color([{_,C}|_],opaque) -> C; -color(Layers,alpha) -> color1({0,0,0,0},Layers). +color(Layers,alpha) -> color1({0.0,0.0,0.0,0.0},Layers). color1(Color,[]) -> Color; color1(Color,[{_,C}|Layers]) -> color1(alpha_blend(Color,C),Layers). diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index a2595400dd..fde02b47d5 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2007-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2007-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -143,6 +143,8 @@ image_shape(Config) when is_list(Config) -> ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), + ?line <<_/binary>> = egd:render(Im, raw_bitmap, [{render_engine, alpha}]), + ?line ok = egd:destroy(Im), erase(image_size), ok. @@ -177,6 +179,8 @@ image_primitives(Config) when is_list(Config) -> ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), + ?line <<_/binary>> = egd_render:binary(Im2, alpha), + erase(image_size), ok. diff --git a/lib/percept/vsn.mk b/lib/percept/vsn.mk index ef5a20f028..443d25c78f 100644 --- a/lib/percept/vsn.mk +++ b/lib/percept/vsn.mk @@ -1 +1 @@ -PERCEPT_VSN = 0.8.3 +PERCEPT_VSN = 0.8.4 diff --git a/lib/reltool/doc/src/Makefile b/lib/reltool/doc/src/Makefile index 2c634bdf6c..8bc1488f77 100644 --- a/lib/reltool/doc/src/Makefile +++ b/lib/reltool/doc/src/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 2009-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% include $(ERL_TOP)/make/target.mk @@ -39,6 +39,10 @@ include files.mk # ---------------------------------------------------- +XML_FILES = \ + $(BOOK_FILES) $(XML_APPLICATION_FILES) $(XML_REF3_FILES) \ + $(XML_PART_FILES) $(XML_CHAPTER_FILES) + HTML_FILES = $(XML_APPLICATION_FILES:%.xml=$(HTMLDIR)/%.html) \ $(XML_PART_FILES:%.xml=$(HTMLDIR)/%.html) @@ -46,10 +50,6 @@ INFO_FILE = ../../info MAN3_FILES = $(XML_REF3_FILES:%.xml=$(MAN3DIR)/%.3) -XML_FILES = \ - $(BOOK_FILES) $(XML_CHAPTER_FILES) \ - $(XML_PART_FILES) $(XML_REF3_FILES) $(XML_APPLICATION_FILES) - HTML_REF_MAN_FILE = $(HTMLDIR)/index.html TOP_PDF_FILE = $(PDFDIR)/$(APPLICATION)-$(VSN).pdf @@ -72,15 +72,20 @@ $(TOP_PDF_FILE): $(XML_FILES) pdf: $(TOP_PDF_FILE) -html: gifs $(HTML_REF_MAN_FILE) +html:images $(HTML_REF_MAN_FILE) man: $(MAN3_FILES) -gifs: $(GIF_FILES:%=$(HTMLDIR)/%) +images: $(IMAGE_FILES:%=$(HTMLDIR)/%) debug opt: clean clean_docs: + for file in $(XML_FILES); do \ + if [ -f $$file\src ]; then \ + rm -f $$file; \ + fi \ + done rm -rf $(HTMLDIR)/* rm -f $(MAN3DIR)/* rm -f $(TOP_PDF_FILE) $(TOP_PDF_FILE:%.pdf=%.fo) @@ -95,8 +100,7 @@ release_docs_spec: docs $(INSTALL_DIR) $(RELSYSDIR)/doc/pdf $(INSTALL_DATA) $(TOP_PDF_FILE) $(RELSYSDIR)/doc/pdf $(INSTALL_DIR) $(RELSYSDIR)/doc/html - $(INSTALL_DATA) $(HTMLDIR)/* \ - $(RELSYSDIR)/doc/html + $(INSTALL_DATA) $(HTMLDIR)/* $(RELSYSDIR)/doc/html $(INSTALL_DATA) $(INFO_FILE) $(RELSYSDIR) $(INSTALL_DIR) $(RELEASE_PATH)/man/man3 $(INSTALL_DATA) $(MAN3DIR)/* $(RELEASE_PATH)/man/man3 diff --git a/lib/reltool/doc/src/book.gif b/lib/reltool/doc/src/book.gif Binary files differdeleted file mode 100644 index 94b3868792..0000000000 --- a/lib/reltool/doc/src/book.gif +++ /dev/null diff --git a/lib/reltool/doc/src/fascicules.xml b/lib/reltool/doc/src/fascicules.xml deleted file mode 100644 index a57808974e..0000000000 --- a/lib/reltool/doc/src/fascicules.xml +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="latin1" ?> -<!DOCTYPE fascicules SYSTEM "fascicules.dtd"> - -<fascicules> - <fascicule file="part" href="part_frame.html" entry="no"> - User's Guide - </fascicule> - <fascicule file="ref_man" href="ref_man_frame.html" entry="yes"> - Reference Manual - </fascicule> - <fascicule file="part_notes" href="part_notes_frame.html" entry="no"> - Release Notes - </fascicule> - <fascicule file="" href="../../../../doc/print.html" entry="no"> - Off-Print - </fascicule> -</fascicules> diff --git a/lib/reltool/doc/src/files.mk b/lib/reltool/doc/src/files.mk index b2dc06411d..07b52f4934 100644 --- a/lib/reltool/doc/src/files.mk +++ b/lib/reltool/doc/src/files.mk @@ -1,20 +1,20 @@ #-*-makefile-*- ; force emacs to enter makefile-mode # # %CopyrightBegin% -# -# Copyright Ericsson AB 2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 2009-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% XML_APPLICATION_FILES = \ @@ -24,8 +24,7 @@ XML_REF3_FILES = \ reltool.xml XML_PART_FILES = \ - part.xml \ - part_notes.xml + part.xml XML_CHAPTER_FILES = \ reltool_intro.xml \ @@ -35,11 +34,5 @@ XML_CHAPTER_FILES = \ BOOK_FILES = book.xml -GIF_FILES = \ - book.gif \ - note.gif \ - notes.gif \ - ref_man.gif \ - user_guide.gif \ - warning.gif +IMAGE_FILES = diff --git a/lib/reltool/doc/src/note.gif b/lib/reltool/doc/src/note.gif Binary files differdeleted file mode 100644 index 6fffe30419..0000000000 --- a/lib/reltool/doc/src/note.gif +++ /dev/null diff --git a/lib/reltool/doc/src/notes.gif b/lib/reltool/doc/src/notes.gif Binary files differdeleted file mode 100644 index e000cca26a..0000000000 --- a/lib/reltool/doc/src/notes.gif +++ /dev/null diff --git a/lib/reltool/doc/src/part_notes.xml b/lib/reltool/doc/src/part_notes.xml deleted file mode 100644 index 5a2aeecce6..0000000000 --- a/lib/reltool/doc/src/part_notes.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="latin1" ?> -<!DOCTYPE part SYSTEM "part.dtd"> - -<part xmlns:xi="http://www.w3.org/2001/XInclude"> - <header> - <copyright> - <year>2009</year> - <year>2009</year> - <holder>Ericsson AB, All Rights Reserved</holder> - </copyright> - <legalnotice> - The contents of this file are subject to the Erlang Public License, - Version 1.1, (the "License"); you may not use this file except in - compliance with the License. You should have received a copy of the - Erlang Public License along with this software. If not, it can be - retrieved online at http://www.erlang.org/. - - Software distributed under the License is distributed on an "AS IS" - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - the License for the specific language governing rights and limitations - under the License. - - The Initial Developer of the Original Code is Ericsson AB. - </legalnotice> - - <title>Reltool Release Notes</title> - <prepared>Håkan Mattsson</prepared> - <docno></docno> - <date></date> - <rev>%VSN%</rev> - </header> - <description> - <p><c>Reltool</c> is a release management tool. It analyses a given - Erlang/OTP installation and determines various dependencies - between applications. The <c>graphical</c> frontend depicts the - dependencies and enables interactive customization of a - target system. The backend provides a <c>batch</c> interface - for generation of customized target systems.</p> - </description> - <xi:include href="notes.xml"/> -</part> diff --git a/lib/reltool/doc/src/ref_man.gif b/lib/reltool/doc/src/ref_man.gif Binary files differdeleted file mode 100644 index b13c4efd53..0000000000 --- a/lib/reltool/doc/src/ref_man.gif +++ /dev/null diff --git a/lib/reltool/doc/src/reltool_examples.xml b/lib/reltool/doc/src/reltool_examples.xml index 3d087862e6..d6db246f6c 100644 --- a/lib/reltool/doc/src/reltool_examples.xml +++ b/lib/reltool/doc/src/reltool_examples.xml @@ -45,7 +45,8 @@ its server can be obtained with <c>reltool:get_server/1</c></p> <pre> -Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false] +Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:4:4] [rq:4] + [async-threads:0] [kernel-poll:false] Eshell V5.7.3 (abort with ^G) 1> {ok, Win} = reltool:start([]). @@ -72,10 +73,13 @@ ok <title>Inspecting the configuration</title> <pre> -Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false] +Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:4:4] [rq:4] + [async-threads:0] [kernel-poll:false] Eshell V5.7.3 (abort with ^G) -1> Config = {sys, [{escript, "examples/display_args", [{incl_cond, include}]}, +1> Config = {sys, [{escript, + "examples/display_args", + [{incl_cond, include}]}, {app, inets, [{incl_cond, include}]}, {app, mnesia, [{incl_cond, exclude}]}, {app, ssl, [{incl_cond, exclude}]}, @@ -244,7 +248,8 @@ Eshell V5.7.3 (abort with ^G) <title>Generate release and script files</title> <pre> 5> {ok, Server} = reltool:start_server([{config, {sys, [{boot_rel, "NAME"}, - {rel, "NAME", "VSN", [kernel, stdlib, sasl]}]}}]). + {rel, "NAME", "VSN", + [kernel, stdlib, sasl]}]}}]). {ok,<0.1288.0>} 6> reltool:get_config(Server). {ok,{sys,[{boot_rel,"NAME"}, @@ -297,10 +302,13 @@ ok <section> <title>Create a target system</title> <pre> -Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false] +Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:4:4] [rq:4] + [async-threads:0] [kernel-poll:false] Eshell V5.7.3 (abort with ^G) -1> Config = {sys, [{escript, "examples/display_args", [{incl_cond, include}]}, +1> Config = {sys, [{escript, + "examples/display_args", + [{incl_cond, include}]}, {app, inets, [{incl_cond, include}]}, {app, mnesia, [{incl_cond, exclude}]}, {app, ssl, [{incl_cond, exclude}]}, @@ -320,11 +328,11 @@ Eshell V5.7.3 (abort with ^G) [{write_file,"start_erl.data","5.7.3 1.0"}, {create_dir,"1.0", [{write_file,"start_clean.rel", - [37,37,32,114,101,108,32,103,101,110,101,114,97,116|...]}, + [37,37,32,114,101,108,32,103,101,110,101|...]}, {write_file,"start_clean.script", - [37,37,32,115,99,114,105,112,116,32,103,101,110|...]}, + [37,37,32,115,99,114,105,112,116,32|...]}, {write_file,"start_clean.boot", - <<131,104,3,100,0,6,115,99,114,105,112,116,...>>}, + <<131,104,3,100,0,6,115,99,114,...>>}, {write_file,"start_sasl.rel", [37,37,32,114,101,108,32,103,101,110,101|...]}, {write_file,"start_sasl.script", @@ -409,11 +417,13 @@ Eshell V5.7.3 (abort with ^G) {copy_file,...}, {...}|...]}, {create_dir,"src", - [{copy_file,[...]},{copy_file,...},{...}|...]}]}]}, + [{copy_file,[...]}, + {copy_file,...},{...}|...]}]}]}, {archive,"crypto-1.6.1.ez",[], [{create_dir,"crypto-1.6.1", [{create_dir,"ebin", - [{copy_file,[...]},{copy_file,...},{...}|...]}, + [{copy_file,[...]}, + {copy_file,...},{...}|...]}, {create_dir,"src",[{copy_file,...},{...}|...]}]}]}, {create_dir,"crypto-1.6.1", [{create_dir,"priv", diff --git a/lib/reltool/doc/src/user_guide.gif b/lib/reltool/doc/src/user_guide.gif Binary files differdeleted file mode 100644 index e6275a803d..0000000000 --- a/lib/reltool/doc/src/user_guide.gif +++ /dev/null diff --git a/lib/reltool/doc/src/warning.gif b/lib/reltool/doc/src/warning.gif Binary files differdeleted file mode 100644 index 96af52360e..0000000000 --- a/lib/reltool/doc/src/warning.gif +++ /dev/null diff --git a/lib/reltool/src/reltool_target.erl b/lib/reltool/src/reltool_target.erl index 895fc6702b..6d85a98d9f 100644 --- a/lib/reltool/src/reltool_target.erl +++ b/lib/reltool/src/reltool_target.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2009-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% -module(reltool_target). @@ -966,9 +966,9 @@ do_eval_spec({create_dir, Dir, Files}, OrigSourceDir, SourceDir, TargetDir) -> TargetDir2 = filename:join([TargetDir, Dir]), reltool_utils:create_dir(TargetDir2), do_eval_spec(Files, OrigSourceDir, SourceDir2, TargetDir2); -do_eval_spec({create_dir, NewDir, OldDir, Files}, OrigSourceDir, _SourceDir, TargetDir) -> +do_eval_spec({create_dir, Dir, OldDir, Files}, OrigSourceDir, _SourceDir, TargetDir) -> SourceDir2 = filename:join([OrigSourceDir, OldDir]), - TargetDir2 = filename:join([TargetDir, NewDir]), + TargetDir2 = filename:join([TargetDir, Dir]), reltool_utils:create_dir(TargetDir2), do_eval_spec(Files, SourceDir2, SourceDir2, TargetDir2); do_eval_spec({archive, Archive, Options, Files}, OrigSourceDir, SourceDir, TargetDir) -> @@ -992,9 +992,9 @@ do_eval_spec({copy_file, File}, _OrigSourceDir, SourceDir, TargetDir) -> SourceFile = filename:join([SourceDir, File]), TargetFile = filename:join([TargetDir, File]), reltool_utils:copy_file(SourceFile, TargetFile); -do_eval_spec({copy_file, NewFile, OldFile}, OrigSourceDir, _SourceDir, TargetDir) -> +do_eval_spec({copy_file, File, OldFile}, OrigSourceDir, _SourceDir, TargetDir) -> SourceFile = filename:join([OrigSourceDir, OldFile]), - TargetFile = filename:join([TargetDir, NewFile]), + TargetFile = filename:join([TargetDir, File]), reltool_utils:copy_file(SourceFile, TargetFile); do_eval_spec({write_file, File, IoList}, _OrigSourceDir, _SourceDir, TargetDir) -> TargetFile = filename:join([TargetDir, File]), @@ -1014,8 +1014,8 @@ cleanup_spec({create_dir, Dir, Files}, TargetDir) -> TargetDir2 = filename:join([TargetDir, Dir]), cleanup_spec(Files, TargetDir2), file:del_dir(TargetDir2); -cleanup_spec({create_dir, NewDir, _OldDir, Files}, TargetDir) -> - TargetDir2 = filename:join([TargetDir, NewDir]), +cleanup_spec({create_dir, Dir, _OldDir, Files}, TargetDir) -> + TargetDir2 = filename:join([TargetDir, Dir]), cleanup_spec(Files, TargetDir2), file:del_dir(TargetDir2); cleanup_spec({archive, Archive, _Options, Files}, TargetDir) -> @@ -1125,6 +1125,8 @@ match(String, [#regexp{source = _, compiled = MP} | Regexps]) -> end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Old style installation +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% install(RelName, TargetDir) -> try @@ -1220,7 +1222,6 @@ subst_var([C| Rest], Vars, Result, VarAcc) -> subst_var(Rest, Vars, Result, [C| VarAcc]); subst_var([], Vars, Result, VarAcc) -> subst([], Vars, [VarAcc ++ [$% | Result]]). - start_scripts() -> ["erl", "start", "start_erl"]. diff --git a/lib/runtime_tools/vsn.mk b/lib/runtime_tools/vsn.mk index 591f3e1ac4..4bbdef19de 100644 --- a/lib/runtime_tools/vsn.mk +++ b/lib/runtime_tools/vsn.mk @@ -1 +1 @@ -RUNTIME_TOOLS_VSN = 1.8.2 +RUNTIME_TOOLS_VSN = 1.8.3 diff --git a/lib/snmp/doc/src/notes.xml b/lib/snmp/doc/src/notes.xml index 7984f2a536..dc2d879672 100644 --- a/lib/snmp/doc/src/notes.xml +++ b/lib/snmp/doc/src/notes.xml @@ -64,17 +64,22 @@ <section> <title>Reported Fixed Bugs and Malfunctions</title> + <!-- <p>-</p> + --> - <!-- <list type="bulleted"> <item> - <p>TBD. </p> - <p>Own Id: OTP-8384</p> + <p>The config utility + (<seealso marker="snmp#config">snmp:config/0</seealso>) + generated a default notify.conf + with a bad name for the starndard trap entry (was "stadard trap", + but should have been "standard trap"). This has been corrected. </p> + <p>Kenji Rikitake</p> + <p>Own Id: OTP-8433</p> </item> </list> - --> </section> diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl index bc0777a7dd..3a91cf4033 100644 --- a/lib/snmp/src/agent/snmpa_net_if.erl +++ b/lib/snmp/src/agent/snmpa_net_if.erl @@ -945,6 +945,12 @@ system_terminate(Reason, _Parent, _Dbg, #state{log = Log}) -> do_close_log(Log), exit(Reason). +system_code_change(OldState, _Module, _OldVsn, downgrade_to_pre_4_16) -> + {OldLog, Type} = OldState#state.log, + NewLog = snmp_log:downgrade(OldLog), + NewState = OldState#state{log = {NewLog, Type}}, + {ok, NewState}; + system_code_change(OldState, _Module, _OldVsn, upgrade_from_pre_4_16) -> Initial = ?ATL_SEQNO_INITIAL, Max = ?ATL_SEQNO_MAX, @@ -952,12 +958,11 @@ system_code_change(OldState, _Module, _OldVsn, upgrade_from_pre_4_16) -> Function = increment_counter, Args = [atl_seqno, Initial, Max], SeqNoGen = {Module, Function, Args}, - NewLog = snmp_log:upgrade(OldState#state.log, SeqNoGen), - NewState = OldState#state{log = NewLog}, - {ok, NewState}; -system_code_change(OldState, _Module, _OldVsn, downgrade_to_pre_4_16) -> - NewState = OldState#state{log = snmp_log:downgrade(OldState#state.log)}, + {OldLog, Type} = OldState#state.log, + NewLog = snmp_log:upgrade(OldLog, SeqNoGen), + NewState = OldState#state{log = {NewLog, Type}}, {ok, NewState}; + system_code_change(S, _Module, _OldVsn, _Extra) -> {ok, S}. diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index 74747b2e59..05aa3d0d48 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -25,6 +25,7 @@ {"4.15", [ {load_module, snmpa, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmp_log, soft_purge, soft_purge, []}, {update, snmpa_net_if, {advanced, upgrade_from_pre_4_16}, soft_purge, soft_purge, [snmpa_agent, snmp_log]}, @@ -34,6 +35,7 @@ {"4.14", [ {load_module, snmpa, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmp_log, soft_purge, soft_purge, []}, {update, snmpa_net_if, {advanced, upgrade_from_pre_4_16}, soft_purge, soft_purge, [snmpa_agent, snmp_log]}, @@ -49,6 +51,7 @@ [ {load_module, snmpa_mib_data, soft_purge, soft_purge, []}, {load_module, snmpa, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmp_log, soft_purge, soft_purge, []}, {update, snmpa_net_if, {advanced, upgrade_from_pre_4_16}, soft_purge, soft_purge, [snmpa_agent, snmp_log]}, @@ -70,6 +73,7 @@ {"4.15", [ {load_module, snmpa, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmp_log, soft_purge, soft_purge, []}, {update, snmpa_net_if, {advanced, downgrade_to_pre_4_16}, soft_purge, soft_purge, [snmpa_agent, snmp_log]}, @@ -79,6 +83,7 @@ {"4.14", [ {load_module, snmpa, soft_purge, soft_purge, [snmp_log]}, + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmp_log, soft_purge, soft_purge, []}, {update, snmpa_net_if, {advanced, downgrade_to_pre_4_16}, soft_purge, soft_purge, [snmpa_agent, snmp_log]}, @@ -92,6 +97,7 @@ {"4.13.5", [ {load_module, snmpa_mib_data, soft_purge, soft_purge, []}, + {load_module, snmp_config, soft_purge, soft_purge, []}, {load_module, snmpa, soft_purge, soft_purge, [snmp_log]}, {load_module, snmp_log, soft_purge, soft_purge, []}, {update, snmpa_net_if, {advanced, downgrade_to_pre_4_16}, diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl index 4ec24af7f3..ad39157721 100644 --- a/lib/snmp/src/manager/snmpm_net_if.erl +++ b/lib/snmp/src/manager/snmpm_net_if.erl @@ -464,13 +464,17 @@ do_close_log(_) -> code_change({down, _Vsn}, OldState, downgrade_to_pre_4_16) -> ?d("code_change(down) -> entry", []), - State = OldState#state{log = snmp_log:downgrade(OldState#state.log)}, + {OldLog, Type} = OldState#state.log, + NewLog = snmp_log:downgrade(OldLog), + State = OldState#state{log = {NewLog, Type}}, {ok, State}; % upgrade code_change(_Vsn, OldState, upgrade_from_pre_4_16) -> ?d("code_change(up) -> entry", []), - State = OldState#state{log = snmp_log:upgrade(OldState#state.log)}, + {OldLog, Type} = OldState#state.log, + NewLog = snmp_log:upgrade(OldLog), + State = OldState#state{log = {NewLog, Type}}, {ok, State}; code_change(_Vsn, State, _Extra) -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 0ee373a4d4..c066680160 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -1806,7 +1806,7 @@ write_agent_snmp_notify_conf(Dir, NotifyType) -> "%% {\"standard inform\", \"std_inform\", inform}.\n" "%%\n\n", Hdr = header() ++ Comment, - Conf = [{"stadard_trap", "std_trap", NotifyType}], + Conf = [{"standard trap", "std_trap", NotifyType}], write_agent_notify_config(Dir, Hdr, Conf). write_agent_notify_config(Dir, Hdr, Conf) -> diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl index 9f4fdf97ca..f9aa911817 100644 --- a/lib/snmp/src/misc/snmp_log.erl +++ b/lib/snmp/src/misc/snmp_log.erl @@ -115,6 +115,11 @@ create(Name, File, SeqNoGen, Size, Repair, Notify) -> close(#snmp_log{id = Log}) -> ?vtrace("close -> entry with" "~n Log: ~p", [Log]), + do_close(Log); +close(Log) -> + do_close(Log). + +do_close(Log) -> disk_log:close(Log). @@ -345,6 +350,11 @@ next_seqno(_) -> %% -- change_size --- change_size(#snmp_log{id = Log}, NewSize) -> + do_change_size(Log, NewSize); +change_size(Log, NewSize) -> + do_change_size(Log, NewSize). + +do_change_size(Log, NewSize) -> ?vtrace("change_size -> entry with" "~n Log: ~p" "~n NewSize: ~p", [Log, NewSize]), diff --git a/lib/snmp/vsn.mk b/lib/snmp/vsn.mk index d78a2cec7a..a151f332ae 100644 --- a/lib/snmp/vsn.mk +++ b/lib/snmp/vsn.mk @@ -18,10 +18,12 @@ # %CopyrightEnd% SNMP_VSN = 4.16 -PRE_VSN =-p01 +PRE_VSN =-p03 APP_VSN = "snmp-$(SNMP_VSN)$(PRE_VSN)" -TICKETS = OTP-8395 +TICKETS = \ + OTP-8395 \ + OTP-8433 TICKETS_4_15 = OTP-8229 OTP-8249 diff --git a/lib/stdlib/doc/src/shell.xml b/lib/stdlib/doc/src/shell.xml index 2a7c5b8c69..73cc1b33bd 100644 --- a/lib/stdlib/doc/src/shell.xml +++ b/lib/stdlib/doc/src/shell.xml @@ -755,10 +755,11 @@ loop(N) -> created by the shell. Currently there is only one pair: <c>{history, N}</c>, where N is the current command number. The function should return a list of characters or an atom. This - constraint is due to the Erlang I/O-protocol. Note that in - restricted mode the call <c>Mod:Func(L)</c> must be allowed or - the default shell prompt function will be called.</p> - </section> + constraint is due to the Erlang I/O-protocol. Unicode characters + beyond codepoint 255 are allowed in the list. Note + that in restricted mode the call <c>Mod:Func(L)</c> must be + allowed or the default shell prompt function will be called.</p> + </section> <funcs> <func> diff --git a/lib/stdlib/src/Makefile b/lib/stdlib/src/Makefile index 37c836a254..237818c08b 100644 --- a/lib/stdlib/src/Makefile +++ b/lib/stdlib/src/Makefile @@ -146,6 +146,9 @@ APPUP_TARGET= $(EBIN)/$(APPUP_FILE) # FLAGS # ---------------------------------------------------- +ifeq ($(NATIVE_LIBS_ENABLED),yes) +ERL_COMPILE_FLAGS += +native +endif ERL_COMPILE_FLAGS += -I../include -I../../kernel/include # ---------------------------------------------------- diff --git a/lib/stdlib/src/dets_v8.erl b/lib/stdlib/src/dets_v8.erl index ec3bad45bc..1f9f84cd27 100644 --- a/lib/stdlib/src/dets_v8.erl +++ b/lib/stdlib/src/dets_v8.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2001-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2001-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(dets_v8). diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl index 156d68554e..91f7641af7 100644 --- a/lib/stdlib/src/erl_lint.erl +++ b/lib/stdlib/src/erl_lint.erl @@ -1,20 +1,20 @@ %% -*- erlang-indent-level: 4 -*- %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% %% Do necessary checking of Erlang code. @@ -78,7 +78,7 @@ value_option(Flag, Default, On, OnVal, Off, OffVal, Opts) -> calls = dict:new(), %Who calls who imported = [], %Actually imported functions used_records=sets:new() :: set(), %Used record definitions - used_types = sets:new() :: set() %Used type definitions + used_types = dict:new() :: dict() %Used type definitions }). %% Define the lint state record. @@ -277,6 +277,8 @@ format_error({conflicting_behaviours,{Name,Arity},B,FirstL,FirstB}) -> format_error({undefined_behaviour_func, {Func,Arity}, Behaviour}) -> io_lib:format("undefined callback function ~w/~w (behaviour '~w')", [Func,Arity,Behaviour]); +format_error({undefined_behaviour_func, {Func,Arity,_Spec}, Behaviour}) -> + format_error({undefined_behaviour_func, {Func,Arity}, Behaviour}); format_error({undefined_behaviour,Behaviour}) -> io_lib:format("behaviour ~w undefined", [Behaviour]); format_error({undefined_behaviour_callbacks,Behaviour}) -> @@ -288,7 +290,7 @@ format_error({ill_defined_behaviour_callbacks,Behaviour}) -> %% --- types and specs --- format_error({singleton_typevar, Name}) -> io_lib:format("type variable ~w is only used once (is unbound)", [Name]); -format_error({type_ref, {TypeName, Arity}}) -> +format_error({undefined_type, {TypeName, Arity}}) -> io_lib:format("type ~w~s undefined", [TypeName, gen_type_paren(Arity)]); format_error({unused_type, {TypeName, Arity}}) -> io_lib:format("type ~w~s is unused", [TypeName, gen_type_paren(Arity)]); @@ -757,10 +759,11 @@ post_traversal_check(Forms, St0) -> St7 = check_bif_clashes(Forms, St6), St8 = check_specs_without_function(St7), St9 = check_functions_without_spec(Forms, St8), - StA = check_unused_types(Forms, St9), - StB = check_untyped_records(Forms, StA), - StC = check_on_load(StB), - check_unused_records(Forms, StC). + StA = check_undefined_types(St9), + StB = check_unused_types(Forms, StA), + StC = check_untyped_records(Forms, StB), + StD = check_on_load(StC), + check_unused_records(Forms, StD). %% check_behaviour(State0) -> State %% Check that the behaviour attribute is valid. @@ -786,13 +789,20 @@ behaviour_callbacks(Line, B, St0) -> Funcs when is_list(Funcs) -> All = all(fun({FuncName, Arity}) -> is_atom(FuncName) andalso is_integer(Arity); + ({FuncName, Arity, Spec}) -> + is_atom(FuncName) andalso is_integer(Arity) + andalso is_list(Spec); (_Other) -> false end, Funcs), + MaybeRemoveSpec = fun({_F,_A}=FA) -> FA; + ({F,A,_S}) -> {F,A}; + (Other) -> Other + end, if All =:= true -> - {Funcs, St0}; + {[MaybeRemoveSpec(F) || F <- Funcs], St0}; true -> St1 = add_warning(Line, {ill_defined_behaviour_callbacks,B}, @@ -970,6 +980,16 @@ check_undefined_functions(#lint{called=Called0,defined=Def0}=St0) -> add_error(L, {undefined_function,NA}, St) end, St0, Undef). +%% check_undefined_types(State0) -> State + +check_undefined_types(#lint{usage=Usage,types=Def}=St0) -> + Used = Usage#usage.used_types, + UTAs = dict:fetch_keys(Used), + Undef = [{TA,dict:fetch(TA, Used)} || TA <- UTAs, not dict:is_key(TA, Def)], + foldl(fun ({TA,L}, St) -> + add_error(L, {undefined_type,TA}, St) + end, St0, Undef). + %% check_bif_clashes(Forms, State0) -> State check_bif_clashes(Forms, St0) -> @@ -1427,20 +1447,11 @@ is_pattern_expr_1({tuple,_Line,Es}) -> all(fun is_pattern_expr/1, Es); is_pattern_expr_1({nil,_Line}) -> true; is_pattern_expr_1({cons,_Line,H,T}) -> - case is_pattern_expr_1(H) of - true -> is_pattern_expr_1(T); - false -> false - end; + is_pattern_expr_1(H) andalso is_pattern_expr_1(T); is_pattern_expr_1({op,_Line,Op,A}) -> - case erl_internal:arith_op(Op, 1) of - true -> is_pattern_expr_1(A); - false -> false - end; + erl_internal:arith_op(Op, 1) andalso is_pattern_expr_1(A); is_pattern_expr_1({op,_Line,Op,A1,A2}) -> - case erl_internal:arith_op(Op, 2) of - true -> all(fun is_pattern_expr/1, [A1,A2]); - false -> false - end; + erl_internal:arith_op(Op, 2) andalso all(fun is_pattern_expr/1, [A1,A2]); is_pattern_expr_1(_Other) -> false. %% pattern_bin([Element], VarTable, Old, BinVarTable, State) -> @@ -1817,28 +1828,17 @@ is_gexpr({bin,_L,Fs}, RDs) -> end, Fs); is_gexpr({call,_L,{atom,_Lf,F},As}, RDs) -> A = length(As), - case erl_internal:guard_bif(F, A) of - true -> is_gexpr_list(As, RDs); - false -> false - end; + erl_internal:guard_bif(F, A) andalso is_gexpr_list(As, RDs); is_gexpr({call,_L,{remote,_Lr,{atom,_Lm,erlang},{atom,_Lf,F}},As}, RDs) -> A = length(As), - case erl_internal:guard_bif(F, A) orelse is_gexpr_op(F, A) of - true -> is_gexpr_list(As, RDs); - false -> false - end; + (erl_internal:guard_bif(F, A) orelse is_gexpr_op(F, A)) + andalso is_gexpr_list(As, RDs); is_gexpr({call,L,{tuple,Lt,[{atom,Lm,erlang},{atom,Lf,F}]},As}, RDs) -> is_gexpr({call,L,{remote,Lt,{atom,Lm,erlang},{atom,Lf,F}},As}, RDs); is_gexpr({op,_L,Op,A}, RDs) -> - case is_gexpr_op(Op, 1) of - true -> is_gexpr(A, RDs); - false -> false - end; + is_gexpr_op(Op, 1) andalso is_gexpr(A, RDs); is_gexpr({op,_L,Op,A1,A2}, RDs) -> - case is_gexpr_op(Op, 2) of - true -> is_gexpr_list([A1,A2], RDs); - false -> false - end; + is_gexpr_op(Op, 2) andalso is_gexpr_list([A1,A2], RDs); is_gexpr(_Other, _RDs) -> false. is_gexpr_op('andalso', 2) -> true; @@ -2388,7 +2388,7 @@ check_type(Types, St) -> {SeenVars, St1} = check_type(Types, dict:new(), St), dict:fold(fun(Var, {seen_once, Line}, AccSt) -> case atom_to_list(Var) of - [$_|_] -> AccSt; + "_"++_ -> AccSt; _ -> add_error(Line, {singleton_typevar, Var}, AccSt) end; (_Var, seen_multiple, AccSt) -> @@ -2400,7 +2400,7 @@ check_type({ann_type, _L, [_Var, Type]}, SeenVars, St) -> check_type({paren_type, _L, [Type]}, SeenVars, St) -> check_type(Type, SeenVars, St); check_type({remote_type, L, [{atom, _, Mod}, {atom, _, Name}, Args]}, - SeenVars, St = #lint{module=CurrentMod}) -> + SeenVars, #lint{module=CurrentMod} = St) -> St1 = case (dict:is_key({Name, length(Args)}, default_types()) orelse is_var_arity_type(Name)) of @@ -2463,21 +2463,15 @@ check_type({type, _L, product, Args}, SeenVars, St) -> lists:foldl(fun(T, {AccSeenVars, AccSt}) -> check_type(T, AccSeenVars, AccSt) end, {SeenVars, St}, Args); -check_type({type, La, TypeName, Args}, SeenVars, - St = #lint{types=Defs, usage=Usage}) -> +check_type({type, La, TypeName, Args}, SeenVars, #lint{usage=Usage} = St) -> Arity = length(Args), - St1 = - case dict:is_key({TypeName, Arity}, Defs) of - true -> - UsedTypes1 = Usage#usage.used_types, - UsedTypes2 = sets:add_element({TypeName, Arity}, UsedTypes1), - St#lint{usage=Usage#usage{used_types=UsedTypes2}}; - false -> - case is_var_arity_type(TypeName) of - true -> St; - false -> add_error(La, {type_ref, {TypeName, Arity}}, St) - end - end, + St1 = case is_var_arity_type(TypeName) of + true -> St; + false -> + OldUsed = Usage#usage.used_types, + UsedTypes = dict:store({TypeName, Arity}, La, OldUsed), + St#lint{usage=Usage#usage{used_types=UsedTypes}} + end, check_type({type, -1, product, Args}, SeenVars, St1). check_record_types(Line, Name, Fields, SeenVars, St) -> @@ -2636,7 +2630,7 @@ check_specs([FunType|Left], Arity, St0) -> check_specs([], _Arity, St) -> St. -check_specs_without_function(St = #lint{module=Mod, defined=Funcs}) -> +check_specs_without_function(#lint{module=Mod,defined=Funcs,specs=Specs}=St) -> Fun = fun({M, F, A} = MFA, Line, AccSt) when M =:= Mod -> case gb_sets:is_element({F, A}, Funcs) of true -> AccSt; @@ -2644,7 +2638,7 @@ check_specs_without_function(St = #lint{module=Mod, defined=Funcs}) -> end; ({_M, _F, _A}, _Line, AccSt) -> AccSt end, - dict:fold(Fun, St, St#lint.specs). + dict:fold(Fun, St, Specs). %% This generates warnings for functions without specs; if the user has %% specified both options, we do not generate the same warnings twice. @@ -2688,7 +2682,7 @@ check_unused_types(Forms, St = #lint{usage=Usage, types=Types}) -> (Type, FileLine, AccSt) -> case loc(FileLine) of {FirstFile, _} -> - case sets:is_element(Type, UsedTypes) of + case dict:is_key(Type, UsedTypes) of true -> AccSt; false -> add_warning(FileLine, @@ -3009,7 +3003,7 @@ check_old_unused_vars(Vt, Vt0, St0) -> unused_vars(Vt, Vt0, _St0) -> U0 = orddict:filter(fun (V, {_State,unused,_Ls}) -> case atom_to_list(V) of - [$_|_] -> false; + "_"++_ -> false; _ -> true end; (_V, _How) -> false diff --git a/lib/stdlib/src/escript.erl b/lib/stdlib/src/escript.erl index c0f71fb3f5..b2562c6169 100644 --- a/lib/stdlib/src/escript.erl +++ b/lib/stdlib/src/escript.erl @@ -139,7 +139,8 @@ start(EscriptOptions) -> parse_and_run(File, Args, Options) -> CheckOnly = lists:member("s", Options), - {Source, Module, FormsOrBin, Mode} = parse_file(File, CheckOnly), + {Source, Module, FormsOrBin, HasRecs, Mode} = + parse_file(File, CheckOnly), Mode2 = case lists:member("d", Options) of true -> @@ -159,7 +160,7 @@ parse_and_run(File, Args, Options) -> is_list(FormsOrBin) -> case Mode2 of interpret -> - interpret(FormsOrBin, File, Args); + interpret(FormsOrBin, HasRecs, File, Args); compile -> case compile:forms(FormsOrBin, [report]) of {ok, Module, BeamBin} -> @@ -246,7 +247,8 @@ parse_file(File, CheckOnly) -> #state{mode = Mode, source = Source, module = Module, - forms_or_bin = FormsOrBin} = + forms_or_bin = FormsOrBin, + has_records = HasRecs} = case ScriptType of archive -> %% Archive file @@ -260,7 +262,7 @@ parse_file(File, CheckOnly) -> %% Source code parse_source(S, File, Fd, StartLine, HeaderSz, CheckOnly) end, - {Source, Module, FormsOrBin, Mode}. + {Source, Module, FormsOrBin, HasRecs, Mode}. %% Skip header and make a heuristic guess about the script type skip_header(P, LineNo) -> @@ -421,8 +423,7 @@ check_source(S, CheckOnly) -> case S of #state{n_errors = Nerrs} when Nerrs =/= 0 -> fatal("There were compilation errors."); - #state{exports_main = ExpMain, - has_records = HasRecs, + #state{exports_main = ExpMain, forms_or_bin = [FileForm2, ModForm2 | Forms]} -> %% Optionally add export of main/1 Forms2 = @@ -433,36 +434,15 @@ check_source(S, CheckOnly) -> Forms3 = [FileForm2, ModForm2 | Forms2], case CheckOnly of true -> - %% Optionally expand records - Forms4 = - case HasRecs of - false -> Forms3; - true -> erl_expand_records:module(Forms3, []) - end, %% Strong validation and halt - case compile:forms(Forms4, [report,strong_validation]) of + case compile:forms(Forms3, [report,strong_validation]) of {ok,_} -> my_halt(0); _Other -> fatal("There were compilation errors.") end; false -> - %% Basic validation before execution - case erl_lint:module(Forms3) of - {ok,Ws} -> - report_warnings(Ws); - {error,Es,Ws} -> - report_errors(Es), - report_warnings(Ws), - fatal("There were compilation errors.") - end, - %% Optionally expand records - Forms4 = - case HasRecs of - false -> Forms3; - true -> erl_expand_records:module(Forms3, []) - end, - S#state{forms_or_bin = Forms4} + S#state{forms_or_bin = Forms3} end end. @@ -495,17 +475,9 @@ epp_parse_file2(Epp, S, Forms, Parsed) -> case Parsed of {ok, Form} -> case Form of - {attribute,Ln,record,{Record,Fields}} -> - S2 = S#state{has_records = true}, - case epp:normalize_typed_record_fields(Fields) of - {typed, NewFields} -> - epp_parse_file(Epp, S2, - [{attribute, Ln, record, {Record, NewFields}}, - {attribute, Ln, type, - {{record, Record}, Fields, []}} | Forms]); - not_typed -> - epp_parse_file(Epp, S2, [Form | Forms]) - end; + {attribute,_,record, _} -> + S2 = S#state{has_records = true}, + epp_parse_file(Epp, S2, [Form | Forms]); {attribute,Ln,mode,NewMode} -> S2 = S#state{mode = NewMode}, if @@ -564,8 +536,23 @@ run(Module, Args) -> fatal(format_exception(Class, Reason)) end. -interpret(Forms, File, Args) -> - Dict = parse_to_dict(Forms), +interpret(Forms, HasRecs, File, Args) -> + %% Basic validation before execution + case erl_lint:module(Forms) of + {ok,Ws} -> + report_warnings(Ws); + {error,Es,Ws} -> + report_errors(Es), + report_warnings(Ws), + fatal("There were compilation errors.") + end, + %% Optionally expand records + Forms2 = + case HasRecs of + false -> Forms; + true -> erl_expand_records:module(Forms, []) + end, + Dict = parse_to_dict(Forms2), ArgsA = erl_parse:abstract(Args, 0), Call = {call,0,{atom,0,main},[ArgsA]}, try diff --git a/lib/stdlib/src/file_sorter.erl b/lib/stdlib/src/file_sorter.erl index f253791f80..e21a0c88f3 100644 --- a/lib/stdlib/src/file_sorter.erl +++ b/lib/stdlib/src/file_sorter.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2001-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2001-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(file_sorter). diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl index 2d3c86e4ea..26f6ec8931 100644 --- a/lib/stdlib/src/io_lib.erl +++ b/lib/stdlib/src/io_lib.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -139,9 +139,9 @@ format_prompt({format,Format,Args}) -> format_prompt(Format,Args); format_prompt(Prompt) when is_list(Prompt); is_atom(Prompt); is_binary(Prompt) -> - format_prompt("~s", [Prompt]); + format_prompt("~ts", [Prompt]); format_prompt(Prompt) -> - format_prompt("~p", [Prompt]). + format_prompt("~tp", [Prompt]). format_prompt(Format, Args) -> case catch io_lib:format(Format, Args) of diff --git a/lib/stdlib/src/qlc.erl b/lib/stdlib/src/qlc.erl index bbeeb503e5..6e48d95973 100644 --- a/lib/stdlib/src/qlc.erl +++ b/lib/stdlib/src/qlc.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(qlc). diff --git a/lib/stdlib/src/qlc_pt.erl b/lib/stdlib/src/qlc_pt.erl index a72fe8639e..24378a0698 100644 --- a/lib/stdlib/src/qlc_pt.erl +++ b/lib/stdlib/src/qlc_pt.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(qlc_pt). diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl index bfbd7b3dc1..8581b496aa 100644 --- a/lib/stdlib/test/erl_lint_SUITE.erl +++ b/lib/stdlib/test/erl_lint_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1999-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1999-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(erl_lint_SUITE). @@ -2597,7 +2597,7 @@ otp_8051(Config) when is_list(Config) -> <<"-opaque foo() :: bar(). ">>, [], - {error,[{1,erl_lint,{type_ref,{bar,0}}}], + {error,[{1,erl_lint,{undefined_type,{bar,0}}}], [{1,erl_lint,{unused_type,{foo,0}}}]}}], ?line [] = run(Config, Ts), ok. diff --git a/lib/stdlib/test/io_proto_SUITE.erl b/lib/stdlib/test/io_proto_SUITE.erl index 59aa175c73..93159fbd5b 100644 --- a/lib/stdlib/test/io_proto_SUITE.erl +++ b/lib/stdlib/test/io_proto_SUITE.erl @@ -23,7 +23,7 @@ -export([init_per_testcase/2, fin_per_testcase/2]). -export([setopts_getopts/1,unicode_options/1,unicode_options_gen/1, binary_options/1, bc_with_r12/1, - bc_with_r12_gl/1, read_modes_gl/1,bc_with_r12_ogl/1, read_modes_ogl/1, broken_unicode/1,eof_on_pipe/1]). + bc_with_r12_gl/1, read_modes_gl/1,bc_with_r12_ogl/1, read_modes_ogl/1, broken_unicode/1,eof_on_pipe/1,unicode_prompt/1]). -export([io_server_proxy/1,start_io_server_proxy/0, proxy_getall/1, proxy_setnext/2, proxy_quit/1]). @@ -31,6 +31,8 @@ -export([toerl_server/3,hold_the_line/3,answering_machine1/3, answering_machine2/3]). +-export([uprompt/1]). + %-define(without_test_server, true). -ifdef(without_test_server). @@ -43,7 +45,7 @@ -define(privdir(Conf), ?config(priv_dir, Conf)). -endif. -%-define(debug, true). +-define(debug, true). -ifdef(debug). -define(format(S, A), io:format(S, A)). @@ -82,7 +84,7 @@ all(doc) -> all(suite) -> [setopts_getopts, unicode_options, unicode_options_gen, binary_options, bc_with_r12, bc_with_r12_gl,bc_with_r12_ogl, read_modes_gl, read_modes_ogl, - broken_unicode,eof_on_pipe]. + broken_unicode,eof_on_pipe,unicode_prompt]. -record(state, { @@ -91,6 +93,48 @@ all(suite) -> mode = list }). +uprompt(_L) -> + [1050,1072,1082,1074,1086,32,1077,32,85,110,105,99,111,100,101,32,63]. + +unicode_prompt(suite) -> + []; +unicode_prompt(doc) -> + ["Test that an Unicode prompt does not crash the shell"]; +unicode_prompt(Config) when is_list(Config) -> + ?line PA = filename:dirname(code:which(?MODULE)), + ?line rtnode([{putline,""}, + {putline, "2."}, + {getline, "2"}, + {putline, "shell:prompt_func({io_proto_SUITE,uprompt})."}, + {getline, "default"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "\"hej\\n\""}, + {putline, "io:setopts([{binary,true}])."}, + {getline, "ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "<<\"hej\\n\">>"} + ],[],[],"-pa "++ PA), + %% And one with oldshell + ?line rtnode([{putline,""}, + {putline, "2."}, + {getline_re, ".*2."}, + {getline, "2"}, + {putline, "shell:prompt_func({io_proto_SUITE,uprompt})."}, + {getline_re, ".*default"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*\"hej\\\\n\""}, + {putline, "io:setopts([{binary,true}])."}, + {getline_re, ".*ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*<<\"hej\\\\n\">>"} + ],[],[],"-oldshell -pa "++PA), + ok. + + setopts_getopts(suite) -> []; setopts_getopts(doc) -> diff --git a/lib/stdlib/test/shell_SUITE.erl b/lib/stdlib/test/shell_SUITE.erl index da73046c2a..588342d46a 100644 --- a/lib/stdlib/test/shell_SUITE.erl +++ b/lib/stdlib/test/shell_SUITE.erl @@ -34,7 +34,8 @@ start_restricted_on_command_line/1,restricted_local/1]). %% Internal export. --export([otp_5435_2/0, prompt1/1, prompt2/1, prompt3/1, prompt4/1]). +-export([otp_5435_2/0, prompt1/1, prompt2/1, prompt3/1, prompt4/1, + prompt5/1]). %% %% Define to run outside of test server @@ -2618,6 +2619,16 @@ otp_8393(Config) when is_list(Config) -> ?line "default\nl.\n" = t(<<"shell:prompt_func({shell_SUITE,prompt3}). l.">>), + %% + %% Although this tests that you can set a unicode prompt function + %% it does not really test that it does work with the io-servers. + %% That is instead tested in the io_proto_SUITE, which has + %% the right infrastructure in place for such tests. /PaN + %% + ?line _ = shell:prompt_func(default), + ?line "default\nl.\n" = + t(<<"shell:prompt_func({shell_SUITE,prompt5}). l.">>), + %% Restricted shell. Contents = <<"-module(test_restricted_shell). -export([local_allowed/3, non_local_allowed/3]). @@ -2672,6 +2683,9 @@ prompt3(L) -> prompt4(_L) -> erlang:apply({erlang,'/'}, [1,0]). +prompt5(_L) -> + [1050,1072,1082,1074,1086,32,1077,32,85,110,105,99,111,100,101,32,63]. + -ifdef(not_used). exit_term(B) -> "** exception exit:" ++ Reply = t(B), diff --git a/lib/syntax_tools/vsn.mk b/lib/syntax_tools/vsn.mk index 53c13440f3..2ba5eac582 100644 --- a/lib/syntax_tools/vsn.mk +++ b/lib/syntax_tools/vsn.mk @@ -1 +1 @@ -SYNTAX_TOOLS_VSN = 1.6.4 +SYNTAX_TOOLS_VSN = 1.6.5 diff --git a/lib/test_server/info b/lib/test_server/info index 79ccc202d7..7a9ed6c700 100644 --- a/lib/test_server/info +++ b/lib/test_server/info @@ -1,2 +1,2 @@ -group: tools +group: test Test Applications short: The OTP Test Server diff --git a/lib/tools/doc/src/Makefile b/lib/tools/doc/src/Makefile index bab607c4bd..433f123ae5 100644 --- a/lib/tools/doc/src/Makefile +++ b/lib/tools/doc/src/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1997-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1997-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # include $(ERL_TOP)/make/target.mk @@ -41,6 +41,7 @@ XML_REF3_FILES = \ eprof.xml \ fprof.xml \ cprof.xml \ + lcnt.xml \ instrument.xml \ make.xml \ tags.xml \ @@ -53,6 +54,7 @@ XML_CHAPTER_FILES = \ cover_chapter.xml \ fprof_chapter.xml \ cprof_chapter.xml \ + lcnt_chapter.xml \ erlang_mode_chapter.xml \ xref_chapter.xml \ notes.xml \ diff --git a/lib/tools/doc/src/lcnt.xml b/lib/tools/doc/src/lcnt.xml new file mode 100644 index 0000000000..3c55e4e422 --- /dev/null +++ b/lib/tools/doc/src/lcnt.xml @@ -0,0 +1,465 @@ +<?xml version="1.0" encoding="latin1" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2009</year> + <year>2010</year> + <holder>Ericsson AB, All Rights Reserved</holder> + </copyright> + <legalnotice> + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + The Initial Developer of the Original Code is Ericsson AB. + </legalnotice> + + <title>lcnt</title> + <prepared>Björn-Egil Dahlberg</prepared> + <responsible>nobody</responsible> + <docno></docno> + <approved>nobody</approved> + <checked></checked> + <date>2009-11-26</date> + <rev>PA1</rev> + <file>lcnt.xml</file> + </header> + <module>lcnt</module> + <modulesummary>A runtime system Lock Profiling tool.</modulesummary> + <description> + <p>The <c>lcnt</c> module is used to profile the internal ethread locks in the + Erlang Runtime System. With <c>lcnt</c> enabled, Internal counters in the + runtime system are updated each time a lock is taken. The counters stores + information about the number of acquisition tries and the number of collisions + that has occurred during the acquisition tries. The counters also record the + waiting time a lock has caused for a blocked thread when a collision has occurred. + </p> + <p> + The data produced by the lock counters will give an estimate on how well + the runtime system will behave from a parallelizable view point for the + scenarios tested. This tool was mainly developed to help erlang runtime + developers iron out potential and generic bottlenecks. + </p> + <p>Locks in the emulator are named after what type of resource they protect and where + in the emulator they are initialized, those are lock 'classes'. Most of those + locks are also instantiated several times, and given unique identifiers, to increase + locking granularity. Typically an instantiated lock protects a disjunct set of + the resource, i.e ets-tables, processes or ports. In other cases it protects a + specific range of a resource, e.g. <c>pix_lock</c> which protects index to process + mappings, and is given a unique number within the class. A unique lock in <c>lcnt</c> + is referenced by a name (class) and an identifier, <c>{Name, Id}</c>. + </p> + <p>Some locks in the system are static and protects global resources, for example + <c>bif_timers</c> and the <c>run_queue</c> locks. Other locks are dynamic and not + necessarily long lived, for example process locks and ets-table locks. The + statistics data from short lived locks can be stored separately when the locks + are deleted. This behavior is by default turned off to save memory but can be + turned on via <c>lcnt:rt_opt({copy_save, true})</c>. The <c>lcnt:apply/1,2,3</c> + functions enables this behavior during profiling. + </p> + </description> + <funcs> + + <func> + <name>start() -> {ok, Pid} | {error, {already_started, Pid}} </name> + <fsummary>Starts the lock profiler server.</fsummary> + <type> + <v>Pid = pid()</v> + </type> + <desc> + <p>Starts the lock profiler server. The server only act as a medium for the + user and performs filtering and printing of data collected by <c>lcnt:collect/1</c>. + </p> + </desc> + </func> + + <func> + <name>stop() -> ok</name> + <fsummary>Stops the lock profiler server.</fsummary> + <desc> + <p>Stops the lock profiler server.</p> + </desc> + </func> + + <func> + <name>collect() -> ok</name> + <fsummary>Same as <c>collect(node())</c>.</fsummary> + <desc><p>Same as <c>collect(node())</c>.</p></desc> + </func> + + <func> + <name>collect(Node) -> ok</name> + <fsummary>Collects lock statistics from the runtime system.</fsummary> + <type> + <v>Node = node()</v> + </type> + <desc> + <p>Collects lock statistics from the runtime system. The function starts a + server if it is not already started. It then populates the server with lock + statistics. If the server held any lock statistics data before the collect then + that data is lost. + </p> + <note> + <p> + When collection occurs the runtime system transitions to a single thread, + blocking all other threads. No other tasks will be scheduled during this + operation. Depending on the size of the data this might take a long time + (several seconds) and cause timeouts in the system. + </p> + </note> + </desc> + </func> + + <func> + <name>clear() -> ok</name> + <fsummary>Same as <c>clear(node())</c>.</fsummary> + <desc><p>Same as <c>clear(node())</c>.</p></desc> + </func> + + <func> + <name>clear(Node) -> ok</name> + <fsummary>Clears the internal lock statistics from runtime system.</fsummary> + <type> + <v>Node = node()</v> + </type> + <desc> + <p>Clears the internal lock statistics from the runtime system. This does not clear the + data on the server only on runtime system. All counters for static locks are zeroed, + all dynamic locks currently alive are zeroed and all saved locks now destroyed are removed. + It also resets the duration timer. + </p> + </desc> + </func> + <func> + <name>conflicts() -> ok</name> + <fsummary>Same as <c>conflicts([])</c>.</fsummary> + <desc><p>Same as <c>conflicts([])</c>.</p></desc> + </func> + <func> + <name>conflicts([Option]) -> ok</name> + <fsummary>Prints a list of internal lock counters.</fsummary> + <type> + <v>Option = {sort, Sort} | {reverse, bool()} | {thresholds, [Thresholds]} | {print, [Print | {Print, integer()}]} | {max_locks, MaxLocks} | {combine, bool()}</v> + <v>Sort = name | id | type | tries | colls | ratio | time | entry</v> + <v>Thresholds = {tries, integer()} | {colls, integer()} | {time, integer()}</v> + <v>Print = name | id | type | entry | tries | colls | ratio | time | duration</v> + <v>MaxLocks = integer() | none</v> + </type> + <desc> + <p>Prints a list of internal locks and its statistics.</p> + <p>For option description, see <seealso marker="#inspect/2">lcnt:inspect/2</seealso>.</p> + </desc> + </func> + + <func> + <name>locations() -> ok</name> + <fsummary>Same as <c>locations([])</c>.</fsummary> + <desc> + <p>Same as <c>locations([])</c>.</p> + </desc> + </func> + <func> + <name>locations([Option]) -> ok</name> + <fsummary>Prints a list of internal lock counters by source code locations.</fsummary> + <type> + <v>Option = {sort, Sort} | {thresholds, [Thresholds]} | {print, [Print | {Print, integer()}]} | {max_locks, MaxLocks} | {combine, bool()}</v> + <v>Sort = name | id | type | tries | colls | ratio | time | entry</v> + <v>Thresholds = {tries, integer()} | {colls, integer()} | {time, integer()}</v> + <v>Print = name | id | type | entry | tries | colls | ratio | time | duration</v> + <v>MaxLocks = integer() | none</v> + </type> + <desc> + <p>Prints a list of internal lock counters by source code locations.</p> + <p>For option description, see <seealso marker="#inspect/2">lcnt:inspect/2</seealso>.</p> + </desc> + </func> + + <func> + <name>inspect(Lock) -> ok</name> + <fsummary>Same as <c>inspect(Lock, [])</c>.</fsummary> + <desc><p>Same as <c>inspect(Lock, [])</c>.</p></desc> + </func> + <func> + <name>inspect(Lock, [Option]) -> ok</name> + <fsummary>Prints a list of internal lock counters for a specific lock.</fsummary> + <type> + <v>Lock = Name | {Name, Id | [Id]}</v> + <v>Name = atom() | pid() | port()</v> + <v>Id = atom() | integer() | pid() | port()</v> + <v>Option = {sort, Sort} | {thresholds, [Thresholds]} | {print, [Print | {Print, integer()}]} | {max_locks, MaxLocks} | {combine, bool()} | {locations, bool()}</v> + <v>Sort = name | id | type | tries | colls | ratio | time</v> + <v>Thresholds = {tries, integer()} | {colls, integer()} | {time, integer()}</v> + <v>Print = name | id | type | entry | tries | colls | ratio | time | duration</v> + <v>MaxLocks = integer() | none</v> + </type> + <desc> + <p>Prints a list of internal lock counters for a specific lock.</p> + <p>Lock <c>Name</c> and <c>Id</c> for ports and processes are interchangeable with the use of <c>lcnt:swap_pid_keys/0</c> and is the reason why <c>pid()</c> and <c>port()</c> options can be used in both <c>Name</c> and <c>Id</c> space. Both pids and ports are special identifiers with stripped creation and can be recreated with <seealso marker="#pid/3">lcnt:pid/2,3</seealso> and <seealso marker="#port/2">lcnt:port/1,2</seealso>. </p> + <p>Option description:</p> + <taglist> + <tag><c>{combine, bool()}</c></tag> + <item>Combine the statistics from different instances of a lock class. + <br/>Default: <c>true</c> + </item> + + <tag><c>{locations, bool()}</c></tag> + <item>Print the statistics by source file and line numbers. + <br/>Default: <c>false</c> + </item> + + <tag><c>{max_locks, MaxLocks}</c></tag> + <item>Maximum number of locks printed or no limit with <c>none</c>. + <br/>Default: <c>20</c> + </item> + + <tag><c>{print, PrintOptions}</c></tag> + <item>Printing options: + <taglist> + <tag><c>name</c></tag> + <item>Named lock or named set of locks (classes). The same name used for initializing the lock in the VM.</item> + + <tag><c>id</c></tag> + <item>Internal id for set of locks, not always unique. This could be table name for ets tables (db_tab), port id for ports, integer identifiers for allocators, etc.</item> + + <tag><c>type</c></tag> + <item>Type of lock: <c>rw_mutex</c>, <c>mutex</c>, <c>spinlock</c>, <c>rw_spinlock</c> or <c>proclock</c>.</item> + + <tag><c>entry</c></tag> + <item>In combination with <c>{locations, true}</c> this option prints the lock operations source file and line number entry-points along with statistics for each entry. </item> + + <tag><c>tries</c></tag> + <item>Number of acquisitions of this lock.</item> + + <tag><c>colls</c></tag> + <item>Number of collisions when a thread tried to acquire this lock. This is when a trylock is EBUSY, a write try on read held rw_lock, a try read on write held rw_lock, a thread tries to lock an already locked lock. (Internal states supervises this).</item> + + <tag><c>ratio</c></tag> + <item>The ratio between the number of collisions and the number of tries (acquisitions) in percentage.</item> + + <tag><c>time</c></tag> + <item>Accumulated waiting time for this lock. This could be greater than actual wall clock time, it is accumulated for all threads. Trylock conflicts does not accumulate time.</item> + + <tag><c>duration</c></tag> + <item>Percentage of accumulated waiting time of wall clock time. This percentage can be higher than 100% since accumulated time is from all threads.</item> + </taglist> + <br/>Default: <c>[name,id,tries,colls,ratio,time,duration]</c> + </item> + + <tag><c>{reverse, bool()}</c></tag> + <item>Reverses the order of sorting. + <br/>Default: <c>false</c> + </item> + + <tag><c>{sort, Sort}</c></tag> + <item>Column sorting orders. + <br/>Default: <c>time</c> + </item> + + <tag><c>{thresholds, Thresholds}</c></tag> + <item>Filtering thresholds. Anything values above the threshold value are passed through. + <br/>Default: <c>[{tries, 0}, {colls, 0}, {time, 0}]</c> + </item> + + </taglist> + + </desc> + </func> + + <func> + <name>information() -> ok</name> + <fsummary>Prints lcnt server state and generic information about collected lock statistics.</fsummary> + <desc> + <p>Prints lcnt server state and generic information about collected lock statistics.</p> + </desc> + </func> + + <func> + <name>swap_pid_keys() -> ok</name> + <fsummary>Swaps places on <c>Name</c> and <c>Id</c> space for ports and processes.</fsummary> + <desc> + <p>Swaps places on <c>Name</c> and <c>Id</c> space for ports and processes.</p> + </desc> + </func> + + <func> + <name>load(Filename) -> ok</name> + <fsummary>Restores previously saved data to the server.</fsummary> + <type> + <v>Filename = filename()</v> + </type> + <desc> + <p>Restores previously saved data to the server.</p> + </desc> + </func> + + <func> + <name>save(Filename) -> ok</name> + <fsummary>Saves the collected data to file.</fsummary> + <type> + <v>Filename = filename()</v> + </type> + <desc> + <p>Saves the collected data to file.</p> + </desc> + </func> + </funcs> + + <section> + <title>Convenience functions</title> + <p>The following functions are used for convenience.</p> + </section> + <funcs> + <func> + <name>apply(Fun) -> term()</name> + <fsummary>Same as <c>apply(Fun, [])</c>.</fsummary> + <desc> + <p>Same as <c>apply(Fun, [])</c>.</p> + </desc> + </func> + <func> + <name>apply(Fun, Args) -> term()</name> + <fsummary>Clears counters, applies function and collects the profiling results.</fsummary> + <type> + <v>Fun = fun()</v> + <v>Args = [term()]</v> + </type> + <desc> + <p> Clears the lock counters and then setups the instrumentation to save all destroyed locks. + After setup the fun is called, passing the elements in <c>Args</c> as arguments. + When the fun returns the statistics are immediately collected to the server. After the + collection the instrumentation is returned to its previous behavior. + The result of the applied fun is returned. + </p> + </desc> + </func> + <func> + <name>apply(Module, Function, Args) -> term()</name> + <fsummary>Clears counters, applies function and collects the profiling results.</fsummary> + <type> + <v>Module = atom()</v> + <v>Function = atom()</v> + <v>Args = [term()]</v> + </type> + <desc> + <p> Clears the lock counters and then setups the instrumentation to save all destroyed locks. + After setup the function is called, passing the elements in <c>Args</c> as arguments. + When the function returns the statistics are immediately collected to the server. After the + collection the instrumentation is returned to its previous behavior. + The result of the applied function is returned. + </p> + </desc> + </func> + + <func> + <name>pid(Id, Serial) -> pid()</name> + <fsummary>Same as <c>pid(node(), Id, Serial)</c>.</fsummary> + <desc><p>Same as <c>pid(node(), Id, Serial)</c>.</p></desc> + </func> + <func> + <name>pid(Node, Id, Serial) -> pid()</name> + <fsummary>Creates a process id with creation 0.</fsummary> + <type> + <v>Node = node()</v> + <v>Id = integer()</v> + <v>Serial = integer()</v> + </type> + <desc> + <p>Creates a process id with creation 0. Example:</p> + </desc> + </func> + + <func> + <name>port(Id) -> port()</name> + <fsummary>Same as <c>port(node(), Id)</c>.</fsummary> + <desc><p>Same as <c>port(node(), Id)</c>.</p></desc> + </func> + <func> + <name>port(Node, Id) -> port()</name> + <fsummary>Creates a port id with creation 0.</fsummary> + <type> + <v>Node = node()</v> + <v>Id = integer()</v> + </type> + <desc><p>Creates a port id with creation 0.</p></desc> + </func> + + </funcs> + + <section> + <title>Internal runtime lock counter controllers</title> + <p> The following functions control the behavior of the internal counters. </p> + </section> + + <funcs> + <func> + <name>rt_collect() -> [lock_counter_data()]</name> + <fsummary>Same as <c>rt_collect(node())</c>.</fsummary> + <desc> <p>Same as <c>rt_collect(node())</c>.</p> </desc> + </func> + <func> + <name>rt_collect(Node) -> [lock_counter_data()]</name> + <fsummary>Returns a list of raw lock counter data.</fsummary> + <type> + <v>Node = node()</v> + </type> + <desc> <p>Returns a list of raw lock counter data.</p> </desc> + </func> + + <func> + <name>rt_clear() -> ok</name> + <fsummary>Same as <c>rt_clear(node())</c>.</fsummary> + <desc> <p>Same as <c>rt_clear(node())</c>.</p> </desc> + </func> + <func> + <name>rt_clear(Node) -> ok</name> + <fsummary>Clears the internal counters.</fsummary> + <type> + <v>Node = node()</v> + </type> + <desc> <p>Clear the internal counters. Same as <c>lcnt:clear(Node)</c>.</p></desc> + </func> + + <func> + <name>rt_opt({Type, bool()}) -> bool()</name> + <fsummary>Same as <c>rt_opt(node(), {Type, Opt})</c>.</fsummary> + <desc> <p>Same as <c>rt_opt(node(), {Type, Opt})</c>.</p> </desc> + </func> + <func> + <name>rt_opt(Node, {Type, bool()}) -> bool()</name> + <fsummary>Changes the lock counter behavior and returns the previous behaviour.</fsummary> + <type> + <v>Node = node()</v> + <v>Type = copy_save | process_locks</v> + </type> + <desc> + <p>Changes the lock counter behavior and returns the previous behaviour.</p> + <p>Option description:</p> + <taglist> + <tag><c>{copy_save, bool()}</c></tag> + <item>Enable statistics saving from destroyed locks by copying. This might consume a lot of memory. + <br/>Default: <c>false</c> + </item> + + <tag><c>{process_locks, bool()}</c></tag> + <item>Profile process locks. + <br/>Default: <c>true</c> + </item> + </taglist> + </desc> + </func> + </funcs> + + <section> + <title>See Also</title> + <p> <seealso marker="lcnt_chapter">LCNT User's Guide</seealso></p> + </section> +</erlref> diff --git a/lib/tools/doc/src/lcnt_chapter.xml b/lib/tools/doc/src/lcnt_chapter.xml new file mode 100644 index 0000000000..8f44b23f59 --- /dev/null +++ b/lib/tools/doc/src/lcnt_chapter.xml @@ -0,0 +1,301 @@ +<?xml version="1.0" encoding="latin1" ?> +<!DOCTYPE chapter SYSTEM "chapter.dtd"> + +<chapter> + <header> + <copyright> + <year>2009</year><year>2010</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + </legalnotice> + + <title>lcnt - The Lock Profiler</title> + <prepared>Björn-Egil Dahlberg</prepared> + <responsible>nobody</responsible> + <docno></docno> + <approved>nobody</approved> + <checked>no</checked> + <date>2009-11-26</date> + <rev>PA1</rev> + <file>lcnt_chapter.xml</file> + </header> + <p> + Internally in the Erlang runtime system locks are used to protect resources from being updated from multiple threads in a fatal way. Locks are necessary + to ensure that the runtime system works properly but it also introduces a couple of limitations. Lock contention and locking overhead. + </p> + <p> + With lock contention we mean when one thread locks a resource and another thread, or threads, tries to acquire the same resource at the same time. The lock will deny + the other thread access to the resource and the thread will be blocked from continuing its execution. The second thread has to wait until the first thread has + completed its access to the resource and unlocked it. The <c>lcnt</c> tool measures these lock conflicts. + </p> + <p> + Locks has an inherent cost in execution time and memory space. It takes time initialize, destroy, aquiring or releasing locks. To decrease lock contention it + some times necessary to use finer grained locking strategies. This will usually also increase the locking overhead and hence there is a tradeoff + between lock contention and overhead. In general, lock contention increases with the number of threads running concurrently. The <c>lcnt</c> tool does not measure locking overhead. + </p> + <section> + <title> Enabling lock-counting </title> + <p>For investigation of locks in the emulator we use an internal tool called <c>lcnt</c> (short for lock-count). The VM needs to be compiled with this option enabled. To enable this, use:</p> + + <pre> +cd $ERL_TOP +./configure --enable-lock-counter + </pre> + + <p> + Another way to enable this alongside a normal VM is to compile it at emulator directory level, much like a debug build. To compile it this way do the following, + </p> + <pre> +cd $ERL_TOP/erts/emulator +make lcnt FLAVOR=smp + </pre> + <p> and then starting Erlang with,</p> + <pre> +$ERL_TOP/bin/cerl -lcnt + </pre> + <p>To verify that you lock-counting enabled check that <c>[lock-counting]</c> appears in the status text when the VM is started.</p> + <pre> +Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:8:8] [rq:8] [async-threads:0] [hipe] + [kernel-poll:false] [lock-counting] + </pre> + </section> + <section> + <title>Getting started</title> + <p>Once you have a lock counting enabled VM the module <c>lcnt</c> can be used. The module is intended to be used from the current running nodes shell. To access remote nodes use <c>lcnt:clear(Node)</c> and <c>lcnt:collect(Node)</c>. </p> + + <p>All locks are continuously monitored and its statistics updated. Use <c>lcnt:clear/0</c> to initially clear all counters before running any specific tests. This command will also reset the duration timer internally.</p> + <p>To retrieve lock statistics information use, <c>lcnt:collect/0,1</c>. The collect operation will start a <c>lcnt</c> server if it not already started. All collected data will be built into an erlang term and uploaded to the server and a duration time will also be uploaded. This duration is the time between <c>lcnt:clear/0,1</c> and <c>lcnt:collect/0,1</c>.</p> + + <p>Once the data is collected to the server it can be filtered, sorted and printed in many different ways.</p> + <p>See the <seealso marker="lcnt">reference manual</seealso> for a description of each function.</p> + </section> + <section> + <title> Example of usage </title> + <p>From the Erlang shell:</p> + <pre> +Erlang R13B03 (erts-5.7.4) [source] [smp:8:8] [rq:8] [async-threads:0] [hipe] + [kernel-poll:false] [lock-counting] +1> lcnt:rt_opt({copy_save, true}). +false +2> lcnt:clear(), big:bang(1000), lcnt:collect(). +ok +3> lcnt:conflicts(). + lock id #tries #collisions collisions [%] time [us] duration [%] + ----- --- ------- ------------ --------------- ---------- ------------- + alcu_allocator 50 4113692 158921 3.8632 215464 4.4962 + pix_lock 256 4007140 4882 0.1218 12221 0.2550 + run_queue 8 2287246 6949 0.3038 9825 0.2050 + proc_main 1029 3115778 25755 0.8266 1199 0.0250 + proc_msgq 1029 2467022 1910 0.0774 1048 0.0219 + proc_status 1029 5708439 2435 0.0427 706 0.0147 + message_pre_alloc_lock 8 2008569 134 0.0067 90 0.0019 + timeofday 1 54065 8 0.0148 22 0.0005 + gc_info 1 7071 7 0.0990 5 0.0001 +ok +</pre> +<p> + Another way to to profile a specific function is to use <c>lcnt:apply/3</c> or <c>lcnt:apply/1</c> which does <c>lcnt:clear/0</c> before the function and <c>lcnt:collect/0</c> after its invocation. + It also sets <c>copy_save</c> to <c>true</c> for the duration of the function call +</p> +<pre> +Erlang R13B03 (erts-5.7.4) [source] [smp:8:8] [rq:8] [async-threads:0] [hipe] + [kernel-poll:false] [lock-counting] +1> lcnt:apply(fun() -> big:bang(1000) end). +4384.338 +2> lcnt:conflicts(). + lock id #tries #collisions collisions [%] time [us] duration [%] + ----- --- ------- ------------ --------------- ---------- ------------- + alcu_allocator 50 4117913 183091 4.4462 234232 5.1490 + run_queue 8 2050398 3801 0.1854 6700 0.1473 + pix_lock 256 4007080 4943 0.1234 2847 0.0626 + proc_main 1028 3000178 28247 0.9415 1022 0.0225 + proc_msgq 1028 2293677 1352 0.0589 545 0.0120 + proc_status 1028 5258029 1744 0.0332 442 0.0097 + message_pre_alloc_lock 8 2009322 147 0.0073 82 0.0018 + timeofday 1 48616 9 0.0185 13 0.0003 + gc_info 1 7455 12 0.1610 9 0.0002 +ok +</pre> +<p> The process locks are sorted after its class like all other locks. It is convenient to look at specific processes and ports as classes. We can do this by swapping class and class identifiers with <c>lcnt:swap_pid_keys/0</c>. </p> +<pre> +3> lcnt:swap_pid_keys(). +ok +4> lcnt:conflicts([{print, [name, tries, ratio, time]}]). + lock #tries collisions [%] time [us] + ----- ------- --------------- ---------- + alcu_allocator 4117913 4.4462 234232 + run_queue 2050398 0.1854 6700 + pix_lock 4007080 0.1234 2847 + message_pre_alloc_lock 2009322 0.0073 82 + <[email protected]> 13493 1.4452 41 + <[email protected]> 13504 1.1404 36 + <[email protected]> 13181 1.6235 35 + <[email protected]> 13534 0.8202 22 + <[email protected]> 8744 5.8326 22 + <[email protected]> 13335 1.1174 19 + <[email protected]> 13452 1.3678 19 + <[email protected]> 13497 1.8745 18 + <[email protected]> 11009 2.5343 18 + <[email protected]> 13131 1.2566 16 + <[email protected]> 13216 1.7327 15 + <[email protected]> 13156 1.1098 15 + <[email protected]> 13420 0.7303 14 + <[email protected]> 13141 1.6437 14 + <[email protected]> 13346 1.2064 13 + <[email protected]> 13076 1.1701 13 +ok +</pre> + </section> + <section> + <title> Example with Mnesia Transaction Benchmark </title> + <p>From the Erlang shell:</p> +<pre> +Erlang R13B03 (erts-5.7.4) [source] [smp:8:8] [rq:8] [async-threads:0] [hipe] + [kernel-poll:false] [lock-counting] + +Eshell V5.7.4 (abort with ^G) +1> Conf=[{db_nodes, [node()]}, {driver_nodes, [node()]}, {replica_nodes, [node()]}, + {n_drivers_per_node, 10}, {n_branches, 1000}, {n_accounts_per_branch, 10}, + {replica_type, ram_copies}, {stop_after, 60000}, {reuse_history_id, true}]. +[{db_nodes,[nonode@nohost]}, + {driver_nodes,[nonode@nohost]}, + {replica_nodes,[nonode@nohost]}, + {n_drivers_per_node,10}, + {n_branches,1000}, + {n_accounts_per_branch,10}, + {replica_type,ram_copies}, + {stop_after,60000}, + {reuse_history_id,true}] +2> mnesia_tpcb:init([{use_running_mnesia, false}|Conf]). +ignore +</pre> +<p>Initial configuring of the benchmark is done. It is time to profile the actual benchmark and Mnesia</p> +<pre> +3> lcnt:apply(fun() -> {ok,{time, Tps,_,_,_,_}} = mnesia_tpcb:run([{use_running_mnesia, + true}|Conf]), Tps/60 end). +12037.483333333334 +ok +4> lcnt:swap_pid_keys(). +ok +</pre> +<p>The <c>id</c> header represents the number of unique identifiers under a class when the option <c>{combine, true}</c> is used (which is on by default). It will otherwise show the specific identifier. +The <c>db_tab</c> listing shows 722287 unique locks, it is one for each ets-table created and Mnesia creates one for each transaction. +</p> +<pre> +5> lcnt:conflicts(). + lock id #tries #collisions collisions [%] time [us] duration [%] + ----- --- ------- ------------ --------------- ---------- ------------- + alcu_allocator 50 56355118 732662 1.3001 2934747 4.8862 + db_tab 722287 94513441 63203 0.0669 1958797 3.2613 + timeofday 1 2701048 175854 6.5106 1746079 2.9071 + pix_lock 256 24306168 163214 0.6715 918309 1.5289 + run_queue 8 11813811 152637 1.2920 357040 0.5945 + message_pre_alloc_lock 8 17671449 57203 0.3237 263043 0.4380 + mnesia_locker 4 17477633 1618548 9.2607 97092 0.1617 + mnesia_tm 4 9891408 463788 4.6888 86353 0.1438 + gc_info 1 823460 628 0.0763 24826 0.0413 + meta_main_tab_slot 16 41393400 7193 0.0174 11393 0.0190 + <[email protected]> 4 4331412 333 0.0077 7148 0.0119 + timer_wheel 1 203185 30 0.0148 3108 0.0052 + <[email protected]> 4 4291098 210 0.0049 885 0.0015 + <[email protected]> 4 4294702 288 0.0067 442 0.0007 + <[email protected]> 4 4346066 235 0.0054 390 0.0006 + <[email protected]> 4 4348159 287 0.0066 379 0.0006 + <[email protected]> 4 4279309 290 0.0068 325 0.0005 + <[email protected]> 4 4292190 302 0.0070 315 0.0005 + <[email protected]> 4 4208858 265 0.0063 276 0.0005 + <[email protected]> 4 4377502 267 0.0061 276 0.0005 +ok +</pre> +<p>The listing shows <c>mnesia_locker</c>, a process, has highly contended locks.</p> +<pre> +6> lcnt:inspect(mnesia_locker). + lock id #tries #collisions collisions [%] time [us] duration [%] + ----- --- ------- ------------ --------------- ---------- ------------- + mnesia_locker proc_msgq 5449930 59374 1.0894 69781 0.1162 + mnesia_locker proc_main 4462782 1487374 33.3284 14398 0.0240 + mnesia_locker proc_status 7564921 71800 0.9491 12913 0.0215 + mnesia_locker proc_link 0 0 0.0000 0 0.0000 +ok +</pre> +<p>Listing without class combiner.</p> + +<pre> +7> lcnt:conflicts([{combine, false}, {print, [name, id, tries, ratio, time]}]). + lock id #tries collisions [%] time [us] + ----- --- ------- --------------- ---------- + db_tab mnesia_transient_decision 722250 3.9463 1856852 + timeofday undefined 2701048 6.5106 1746079 + alcu_allocator ets_alloc 7490696 2.2737 692655 + alcu_allocator ets_alloc 7081771 2.3294 664522 + alcu_allocator ets_alloc 7047750 2.2520 658495 + alcu_allocator ets_alloc 5883537 2.3177 610869 + pix_lock 58 11011355 1.1924 564808 + pix_lock 60 4426484 0.7120 262490 + alcu_allocator ets_alloc 1897004 2.4248 219543 + message_pre_alloc_lock undefined 4211267 0.3242 128299 + run_queue 3 2801555 1.3003 116792 + run_queue 2 2799988 1.2700 100091 + run_queue 1 2966183 1.2712 78834 + mnesia_locker proc_msgq 5449930 1.0894 69781 + message_pre_alloc_lock undefined 3495672 0.3262 65773 + message_pre_alloc_lock undefined 4189752 0.3174 58607 + mnesia_tm proc_msgq 2094144 1.7184 56361 + run_queue 4 2343585 1.3115 44300 + db_tab branch 1446529 0.5229 38244 + gc_info undefined 823460 0.0763 24826 +ok +</pre> +<p> +In this scenario the lock that protects ets-table <c>mnesia_transient_decision</c> has spent most of its waiting for. That is 1.8 seconds in a test that run for 60 seconds. The time is also spread on eight different scheduler threads. +</p> +<pre> +8> lcnt:inspect(db_tab, [{print, [name, id, tries, colls, ratio, duration]}]). + lock id #tries #collisions collisions [%] duration [%] + ----- --- ------- ------------ --------------- ------------- + db_tab mnesia_transient_decision 722250 28502 3.9463 3.0916 + db_tab branch 1446529 7564 0.5229 0.0637 + db_tab account 1464500 8203 0.5601 0.0357 + db_tab teller 1464529 8110 0.5538 0.0291 + db_tab history 722250 3767 0.5216 0.0232 + db_tab mnesia_stats 750332 7057 0.9405 0.0180 + db_tab mnesia_trans_store 61 0 0.0000 0.0000 + db_tab mnesia_trans_store 61 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 + db_tab mnesia_trans_store 53 0 0.0000 0.0000 +ok +</pre> + + </section> + <section> + <title> Deciphering the output </title> + <p> Typically high <c>time</c> values are bad and this is often the thing to look for. However, one should also look for high lock acquisition frequencies (#tries) since locks generate overhead and because high frequency could become problematic if they begin to have conflicts even if it is not shown in a particular test. </p> + </section> + + <section> + <title>See Also</title> + <p> <seealso marker="lcnt">LCNT Reference Manual</seealso></p> + </section> +</chapter> diff --git a/lib/tools/doc/src/part.xml b/lib/tools/doc/src/part.xml index 3e02086b80..bf9e1ebbec 100644 --- a/lib/tools/doc/src/part.xml +++ b/lib/tools/doc/src/part.xml @@ -4,7 +4,7 @@ <part xmlns:xi="http://www.w3.org/2001/XInclude"> <header> <copyright> - <year>1996</year><year>2009</year> + <year>1996</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>Tools User's Guide</title> @@ -55,6 +55,8 @@ <tag><em>instrument</em></tag> <item>Utility functions for obtaining and analysing resource usage in an instrumented Erlang runtime system.</item> + <tag><em>lcnt</em></tag> + <item>A lock profiling tool for the Erlang runtime system.</item> <tag><em>make</em></tag> <item>A make utility for Erlang similar to UNIX make.</item> <tag><em>tags</em></tag> @@ -69,6 +71,7 @@ <xi:include href="cprof_chapter.xml"/> <xi:include href="erlang_mode_chapter.xml"/> <xi:include href="fprof_chapter.xml"/> + <xi:include href="lcnt_chapter.xml"/> <xi:include href="xref_chapter.xml"/> </part> diff --git a/lib/tools/doc/src/ref_man.xml b/lib/tools/doc/src/ref_man.xml index aea74e3746..d4861af9f3 100644 --- a/lib/tools/doc/src/ref_man.xml +++ b/lib/tools/doc/src/ref_man.xml @@ -4,7 +4,7 @@ <application xmlns:xi="http://www.w3.org/2001/XInclude"> <header> <copyright> - <year>1996</year><year>2009</year> + <year>1996</year><year>2010</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -13,12 +13,12 @@ compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. - + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. - + </legalnotice> <title>Tools Reference Manual</title> @@ -51,9 +51,14 @@ Erlang programs. Uses trace to file to minimize runtime performance impact, and displays time for calling and called functions.</item> + <tag><em>instrument</em></tag> <item>Utility functions for obtaining and analysing resource usage in an instrumented Erlang runtime system.</item> + + <tag><em>lcnt</em></tag> + <item>A lock profiling tool for the Erlang runtime system.</item> + <tag><em>make</em></tag> <item>A make utility for Erlang similar to UNIX make.</item> <tag><em>tags</em></tag> @@ -70,6 +75,7 @@ <xi:include href="erlang_mode.xml"/> <xi:include href="fprof.xml"/> <xi:include href="instrument.xml"/> + <xi:include href="lcnt.xml"/> <xi:include href="make.xml"/> <xi:include href="tags.xml"/> <xi:include href="xref.xml"/> diff --git a/lib/tools/src/Makefile b/lib/tools/src/Makefile index 81933cda14..360f4f8f29 100644 --- a/lib/tools/src/Makefile +++ b/lib/tools/src/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1996-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1996-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # include $(ERL_TOP)/make/target.mk @@ -34,11 +34,13 @@ RELSYSDIR = $(RELEASE_PATH)/lib/tools-$(VSN) # Common Macros # ---------------------------------------------------- -MODULES= cover \ +MODULES= \ + cover \ cover_web \ eprof \ fprof \ cprof \ + lcnt \ instrument \ make \ tags \ diff --git a/lib/tools/src/lcnt.erl b/lib/tools/src/lcnt.erl new file mode 100644 index 0000000000..989a661b75 --- /dev/null +++ b/lib/tools/src/lcnt.erl @@ -0,0 +1,840 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(lcnt). +-behaviour(gen_server). +-author("Björn-Egil Dahlberg"). + +%% gen_server callbacks +-export([ + init/1, + handle_call/3, + handle_cast/2, + handle_info/2, + terminate/2, + code_change/3 + ]). + +%% start/stop +-export([ + start/0, + stop/0 + ]). + +%% erts_debug:lock_counters api +-export([ + rt_collect/0, + rt_collect/1, + rt_clear/0, + rt_clear/1, + rt_opt/1, + rt_opt/2 + ]). + + +%% gen_server call api +-export([ + raw/0, + collect/0, + collect/1, + clear/0, + clear/1, + conflicts/0, + conflicts/1, + locations/0, + locations/1, + inspect/1, + inspect/2, + information/0, + swap_pid_keys/0, + % set options + set/1, + set/2, + + load/1, + save/1 + ]). + +%% convenience +-export([ + apply/3, + apply/2, + apply/1, + all_conflicts/0, + all_conflicts/1, + pid/2, pid/3, + port/1, port/2 + ]). + +-define(version, "1.0"). + +-record(state, { + locks = [], + duration = 0 + }). + + +-record(stats, { + file, + line, + tries, + colls, + time, % us + nt % #timings collected + }). + +-record(lock, { + name, + id, + type, + stats = [] + }). + +-record(print, { + name, + id, + type, + entry, + tries, + colls, + cr, % collision ratio + time, + dtr % time duration ratio + }). + + + +%% -------------------------------------------------------------------- %% +%% +%% start/stop/init +%% +%% -------------------------------------------------------------------- %% + +start() -> gen_server:start({local, ?MODULE}, ?MODULE, [], []). +stop() -> gen_server:cast(?MODULE, stop). +init([]) -> {ok, #state{ locks = [], duration = 0 } }. + +%% -------------------------------------------------------------------- %% +%% +%% API erts_debug:lock_counters +%% +%% -------------------------------------------------------------------- %% + +rt_collect() -> + erts_debug:lock_counters(info). + +rt_collect(Node) -> + rpc:call(Node, erts_debug, lock_counters, [info]). + +rt_clear() -> + erts_debug:lock_counters(clear). + +rt_clear(Node) -> + rpc:call(Node, erts_debug, lock_counters, [clear]). + +rt_opt({Type, Opt}) -> + erts_debug:lock_counters({Type, Opt}). + +rt_opt(Node, {Type, Opt}) -> + rpc:call(Node, erts_debug, lock_counters, [{Type, Opt}]). + +%% -------------------------------------------------------------------- %% +%% +%% API implementation +%% +%% -------------------------------------------------------------------- %% + +clear() -> rt_clear(). +clear(Node) -> rt_clear(Node). +collect() -> call({collect, rt_collect()}). +collect(Node) -> call({collect, rt_collect(Node)}). + +locations() -> call({locations,[]}). +locations(Opts) -> call({locations, Opts}). +conflicts() -> call({conflicts, []}). +conflicts(Opts) -> call({conflicts, Opts}). +inspect(Lock) -> call({inspect, Lock, []}). +inspect(Lock, Opts) -> call({inspect, Lock, Opts}). +information() -> call(information). +swap_pid_keys() -> call(swap_pid_keys). +raw() -> call(raw). +set(Option, Value) -> call({set, Option, Value}). +set({Option, Value}) -> call({set, Option, Value}). +save(Filename) -> call({save, Filename}). +load(Filename) -> start(), call({load, Filename}). + +call(Msg) -> gen_server:call(?MODULE, Msg, infinity). + +%% -------------------------------------------------------------------- %% +%% +%% convenience implementation +%% +%% -------------------------------------------------------------------- %% + +apply(M,F,As) when is_atom(M), is_atom(F), is_list(As) -> + lcnt:start(), + Opt = lcnt:rt_opt({copy_save, true}), + lcnt:clear(), + Res = erlang:apply(M,F,As), + lcnt:collect(), + lcnt:rt_opt({copy_save, Opt}), + Res. + +apply(Fun) when is_function(Fun) -> + lcnt:apply(Fun, []). + +apply(Fun, As) when is_function(Fun) -> + lcnt:start(), + Opt = lcnt:rt_opt({copy_save, true}), + lcnt:clear(), + Res = erlang:apply(Fun, As), + lcnt:collect(), + lcnt:rt_opt({copy_save, Opt}), + Res. + +all_conflicts() -> all_conflicts(time). +all_conflicts(Sort) -> + conflicts([{max_locks, none}, {thresholds, []},{combine,false}, {sort, Sort}, {reverse, true}]). + +pid(Id, Serial) -> pid(node(), Id, Serial). +pid(Node, Id, Serial) when is_atom(Node) -> + Header = <<131,103,100>>, + String = atom_to_list(Node), + L = length(String), + binary_to_term(list_to_binary([Header, bytes16(L), String, bytes32(Id), bytes32(Serial),0])). + +port(Id) -> port(node(), Id). +port(Node, Id ) when is_atom(Node) -> + Header = <<131,102,100>>, + String = atom_to_list(Node), + L = length(String), + binary_to_term(list_to_binary([Header, bytes16(L), String, bytes32(Id), 0])). + +%% -------------------------------------------------------------------- %% +%% +%% handle_call +%% +%% -------------------------------------------------------------------- %% + +% printing + +handle_call({conflicts, InOpts}, _From, #state{ locks = Locks } = State) when is_list(InOpts) -> + Default = [ + {sort, time}, + {reverse, false}, + {print, [name,id,tries,colls,ratio,time,duration]}, + {max_locks, 20}, + {combine, true}, + {thresholds, [{tries, 0}, {colls, 0}, {time, 0}] }, + {locations, false}], + + Opts = options(InOpts, Default), + Flocks = filter_locks_type(Locks, proplists:get_value(type, Opts)), + Combos = combine_classes(Flocks, proplists:get_value(combine, Opts)), + Printables = locks2print(Combos, State#state.duration), + Filtered = filter_print(Printables, Opts), + + print_lock_information(Filtered, proplists:get_value(print, Opts)), + + {reply, ok, State}; + +handle_call(information, _From, State) -> + print_state_information(State), + {reply, ok, State}; + +handle_call({locations, InOpts}, _From, #state{ locks = Locks } = State) when is_list(InOpts) -> + Default = [ + {sort, time}, + {reverse, false}, + {print, [name,entry,tries,colls,ratio,time,duration]}, + {max_locks, 20}, + {combine, true}, + {thresholds, [{tries, 0}, {colls, 0}, {time, 0}] }, + {locations, true}], + + Opts = options(InOpts, Default), + Printables = filter_print([#print{ + name = string_names(Names), + entry = term2string("~p:~p", [Stats#stats.file, Stats#stats.line]), + colls = Stats#stats.colls, + tries = Stats#stats.tries, + cr = percent(Stats#stats.colls, Stats#stats.tries), + time = Stats#stats.time, + dtr = percent(Stats#stats.time, State#state.duration) + } || {Stats, Names} <- combine_locations(Locks) ], Opts), + + print_lock_information(Printables, proplists:get_value(print, Opts)), + + {reply, ok, State}; + +handle_call({inspect, Lockname, InOpts}, _From, #state{ duration = Duration, locks = Locks } = State) when is_list(InOpts) -> + Default = [ + {sort, time}, + {reverse, false}, + {print, [name,id,tries,colls,ratio,time,duration]}, + {max_locks, 20}, + {combine, false}, + {thresholds, [] }, + {locations, false}], + + Opts = options(InOpts, Default), + Filtered = filter_locks(Locks, Lockname), + IDs = case {proplists:get_value(full_id, Opts), proplists:get_value(combine, Opts)} of + {true, true} -> locks_ids(Filtered); + _ -> [] + end, + Combos = combine_classes(Filtered, proplists:get_value(combine, Opts)), + case proplists:get_value(locations, Opts) of + true -> + lists:foreach(fun + (#lock{ name = Name, id = Id, type = Type, stats = Stats }) -> + IdString = case proplists:get_value(full_id, Opts) of + true -> term2string(proplists:get_value(Name, IDs, Id)); + _ -> term2string(Id) + end, + Combined = [CStats || {CStats,_} <- combine_locations(Stats)], + case Combined of + [] -> + ok; + _ -> + %io:format("Combined ~p~n", [Combined]), + print("lock: " ++ term2string(Name)), + print("id: " ++ IdString), + print("type: " ++ term2string(Type)), + Ps = stats2print(Combined, Duration), + Opts1 = options([{print, [entry, tries,colls,ratio,time,duration]}, + {thresholds, [{tries, -1}, {colls, -1}, {time, -1}]}], Opts), + print_lock_information(filter_print(Ps, Opts1), proplists:get_value(print, Opts1)) + end + % (#lock{ name = Name, id = Id}) -> + % io:format("Empty lock ~p ~p~n", [Name, Id]) + end, Combos); + _ -> + Print1 = locks2print(Combos, Duration), + Print2 = filter_print(Print1, Opts), + print_lock_information(Print2, proplists:get_value(print, Opts)) + end, + {reply, ok, State}; + +handle_call(raw, _From, #state{ locks = Locks} = State)-> + {reply, Locks, State}; + +% collecting +handle_call({collect, Data}, _From, State)-> + {reply, ok, data2state(Data, State)}; + +% manipulate +handle_call(swap_pid_keys, _From, #state{ locks = Locks } = State)-> + SwappedLocks = lists:map(fun + (L) when L#lock.name =:= port_lock; L#lock.type =:= proclock -> + L#lock{ id = L#lock.name, name = L#lock.id }; + (L) -> + L + end, Locks), + + {reply, ok, State#state{ locks = SwappedLocks}}; + +% settings +handle_call({set, data, Data}, _From, State)-> + {reply, ok, data2state(Data, State)}; + +handle_call({set, duration, Duration}, _From, State)-> + {reply, ok, State#state{ duration = Duration}}; + +% file operations +handle_call({load, Filename}, _From, State) -> + case file:read_file(Filename) of + {ok, Binary} -> + case binary_to_term(Binary) of + {?version, Statelist} -> + {reply, ok, list2state(Statelist)}; + {Version, _} -> + {reply, {error, {mismatch, Version, ?version}}, State} + end; + Error -> + {reply, {error, Error}, State} + end; + +handle_call({save, Filename}, _From, State) -> + Binary = term_to_binary({?version, state2list(State)}), + case file:write_file(Filename, Binary) of + ok -> + {reply, ok, State}; + Error -> + {reply, {error, Error}, State} + end; + + +handle_call(Command, _From, State) -> + {reply, {error, {undefined, Command}}, State}. + +%% -------------------------------------------------------------------- %% +%% +%% handle_cast +%% +%% -------------------------------------------------------------------- %% + +handle_cast(stop, State) -> + {stop, normal, State}; +handle_cast(_, State) -> + {noreply, State}. + +%% -------------------------------------------------------------------- %% +%% +%% handle_info +%% +%% -------------------------------------------------------------------- %% + +handle_info(_Info, State) -> + {noreply, State}. + +%% -------------------------------------------------------------------- %% +%% +%% termination +%% +%% -------------------------------------------------------------------- %% + +terminate(_Reason, _State) -> + ok. + +%% -------------------------------------------------------------------- %% +%% +%% code_change +%% +%% -------------------------------------------------------------------- %% + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +%% -------------------------------------------------------------------- %% +%% +%% AUX +%% +%% -------------------------------------------------------------------- %% + +% summate + +summate_locks(Locks) -> summate_locks(Locks, #stats{ tries = 0, colls = 0, time = 0, nt = 0}). +summate_locks([], Stats) -> Stats; +summate_locks([L|Ls], #stats{ tries = Tries, colls = Colls, time = Time, nt = Nt}) -> + S = summate_stats(L#lock.stats), + summate_locks(Ls, #stats{ tries = Tries + S#stats.tries, colls = Colls + S#stats.colls, time = Time + S#stats.time, nt = Nt + S#stats.nt}). + +summate_stats(Stats) -> summate_stats(Stats, #stats{ tries = 0, colls = 0, time = 0, nt = 0}). +summate_stats([], Stats) -> Stats; +summate_stats([S|Ss], #stats{ tries = Tries, colls = Colls, time = Time, nt = Nt}) -> + summate_stats(Ss, #stats{ tries = Tries + S#stats.tries, colls = Colls + S#stats.colls, time = Time + S#stats.time, nt = Nt + S#stats.nt}). + + +%% manipulators +filter_locks_type(Locks, undefined) -> Locks; +filter_locks_type(Locks, all) -> Locks; +filter_locks_type(Locks, Types) when is_list(Types) -> + [ L || L <- Locks, lists:member(L#lock.type, Types)]; +filter_locks_type(Locks, Type) -> + [ L || L <- Locks, L#lock.type =:= Type]. + +filter_locks(Locks, {Lockname, Ids}) when is_list(Ids) -> + [ L || L <- Locks, L#lock.name =:= Lockname, lists:member(L#lock.id, Ids)]; +filter_locks(Locks, {Lockname, Id}) -> + [ L || L <- Locks, L#lock.name =:= Lockname, L#lock.id =:= Id ]; +filter_locks(Locks, Lockname) -> + [ L || L <- Locks, L#lock.name =:= Lockname ]. +% order of processing +% 2. cut thresholds +% 3. sort locks +% 4. max length of locks + +filter_print(PLs, Opts) -> + TLs = threshold_locks(PLs, proplists:get_value(thresholds, Opts, [])), + SLs = sort_locks(TLs, proplists:get_value(sort, Opts, time)), + CLs = cut_locks(SLs, proplists:get_value(max_locks, Opts, none)), + reverse_locks(CLs, proplists:get_value(reverse, Opts, false)). + +sort_locks(Locks, Type) -> lists:reverse(sort_locks0(Locks, Type)). +sort_locks0(Locks, name) -> lists:keysort(#print.name, Locks); +sort_locks0(Locks, id) -> lists:keysort(#print.id, Locks); +sort_locks0(Locks, type) -> lists:keysort(#print.type, Locks); +sort_locks0(Locks, tries) -> lists:keysort(#print.tries, Locks); +sort_locks0(Locks, colls) -> lists:keysort(#print.colls, Locks); +sort_locks0(Locks, ratio) -> lists:keysort(#print.cr, Locks); +sort_locks0(Locks, time) -> lists:keysort(#print.time, Locks); +sort_locks0(Locks, _) -> sort_locks0(Locks, time). + +% cut locks not above certain thresholds +threshold_locks(Locks, Thresholds) -> + Tries = proplists:get_value(tries, Thresholds, -1), + Colls = proplists:get_value(colls, Thresholds, -1), + Time = proplists:get_value(time, Thresholds, -1), + [ L || L <- Locks, L#print.tries > Tries, L#print.colls > Colls, L#print.time > Time]. + +cut_locks(Locks, N) when is_integer(N), N > 0 -> lists:sublist(Locks, N); +cut_locks(Locks, _) -> Locks. + +%% reversal +reverse_locks(Locks, true) -> lists:reverse(Locks); +reverse_locks(Locks, _) -> Locks. + + +%% +string_names([]) -> ""; +string_names(Names) -> string_names(Names, []). +string_names([Name], Strings) -> strings(lists:reverse([term2string(Name) | Strings])); +string_names([Name|Names],Strings) -> string_names(Names, [term2string(Name) ++ ","|Strings]). + +%% combine_locations +%% In: +%% Locations :: [#lock{}] | [#stats{}] +%% Out: +%% [{{File,Line}, #stats{}, [Lockname]}] + + +combine_locations(Locations) -> gb_trees:values(combine_locations(Locations, gb_trees:empty())). +combine_locations([], Tree) -> Tree; +combine_locations([S|_] = Stats, Tree) when is_record(S, stats) -> + combine_locations(Stats, undefined, Tree); +combine_locations([#lock{ stats = Stats, name = Name}|Ls], Tree) -> + combine_locations(Ls, combine_locations(Stats, Name, Tree)). + +combine_locations([], _, Tree) -> Tree; +combine_locations([S|Ss], Name, Tree) when is_record(S, stats)-> + Key = {S#stats.file, S#stats.line}, + Tree1 = case gb_trees:lookup(Key, Tree) of + none -> + gb_trees:insert(Key, {S, [Name]}, Tree); + {value, {C, Names}} -> + NewNames = case lists:member(Name, Names) of + true -> Names; + _ -> [Name | Names] + end, + gb_trees:update(Key, { + C#stats{ + tries = C#stats.tries + S#stats.tries, + colls = C#stats.colls + S#stats.colls, + time = C#stats.time + S#stats.time, + nt = C#stats.nt + S#stats.nt + }, NewNames}, Tree) + end, + combine_locations(Ss, Name, Tree1). + +%% combines all statistics for a class (name) lock +%% id's are translated to #id's. + +combine_classes(Locks, true) -> combine_classes1(Locks, gb_trees:empty()); +combine_classes(Locks, _) -> Locks. + +combine_classes1([], Tree) -> gb_trees:values(Tree); +combine_classes1([L|Ls], Tree) -> + Key = L#lock.name, + case gb_trees:lookup(Key, Tree) of + none -> + combine_classes1(Ls, gb_trees:insert(Key, L#lock{ id = 1 }, Tree)); + {value, C} -> + combine_classes1(Ls, gb_trees:update(Key, C#lock{ + id = C#lock.id + 1, + stats = L#lock.stats ++ C#lock.stats + }, Tree)) + end. + +locks_ids(Locks) -> locks_ids(Locks, []). +locks_ids([], Out) -> Out; +locks_ids([#lock{ name = Key } = L|Ls], Out) -> + case proplists:get_value(Key, Out) of + undefined -> + locks_ids(Ls, [{Key, [L#lock.id] } | Out]); + Ids -> + locks_ids(Ls, [{Key, [L#lock.id | Ids] } | proplists:delete(Key,Out)]) + end. + +stats2print(Stats, Duration) -> + lists:map(fun + (S) -> + #print{ + entry = term2string("~p:~p", [S#stats.file, S#stats.line]), + colls = S#stats.colls, + tries = S#stats.tries, + cr = percent(S#stats.colls, S#stats.tries), + time = S#stats.time, + dtr = percent(S#stats.time, Duration) + } + end, Stats). + +locks2print(Locks, Duration) -> + lists:map( fun + (L) -> + Tries = lists:sum([T || #stats{ tries = T} <- L#lock.stats]), + Colls = lists:sum([C || #stats{ colls = C} <- L#lock.stats]), + Time = lists:sum([T || #stats{ time = T} <- L#lock.stats]), + Cr = percent(Colls, Tries), + Dtr = percent(Time, Duration), + #print{ + name = L#lock.name, + id = L#lock.id, + type = L#lock.type, + tries = Tries, + colls = Colls, + cr = Cr, + time = Time, + dtr = Dtr + } + end, Locks). + +%% state making + +data2state(Data, State) -> + Duration = time2us(proplists:get_value(duration, Data)), + Rawlocks = proplists:get_value(locks, Data), + Locks = locks2records(Rawlocks), + State#state{ + duration = Duration, + locks = Locks + }. + +locks2records(Locks) -> locks2records(Locks, []). +locks2records([], Out) -> Out; +locks2records([{Name, Id, Type, Stats}|Locks], Out) -> + Lock = #lock{ + name = Name, + id = clean_id_creation(Id), + type = Type, + stats = [ #stats{ + file = File, + line = Line, + tries = Tries, + colls = Colls, + time = time2us({S, Ns}), + nt = N + } || {{File, Line}, {Tries, Colls, {S, Ns, N}}} <- Stats] }, + locks2records(Locks, [Lock|Out]). + +clean_id_creation(Id) when is_pid(Id) -> + Bin = term_to_binary(Id), + <<H:3/binary, L:16, Node:L/binary, Ids:8/binary, _Creation/binary>> = Bin, + Bin2 = list_to_binary([H, bytes16(L), Node, Ids, 0]), + binary_to_term(Bin2); +clean_id_creation(Id) when is_port(Id) -> + Bin = term_to_binary(Id), + <<H:3/binary, L:16, Node:L/binary, Ids:4/binary, _Creation/binary>> = Bin, + Bin2 = list_to_binary([H, bytes16(L), Node, Ids, 0]), + binary_to_term(Bin2); +clean_id_creation(Id) -> + Id. + +%% serializer + +state_default(Field) -> proplists:get_value(Field, state2list(#state{})). + +state2list(State) -> + [_|Values] = tuple_to_list(State), + lists:zipwith(fun + (locks, Locks) -> {locks, [lock2list(Lock) || Lock <- Locks]}; + (X, Y) -> {X,Y} + end, record_info(fields, state), Values). + +list2state(List) -> list2state(record_info(fields, state), List, [state]). +list2state([], _, Out) -> list_to_tuple(lists:reverse(Out)); +list2state([locks|Fs], List, Out) -> + Locks = [ list2lock(Lock) || Lock <- proplists:get_value(locks, List, [])], + list2state(Fs, List, [Locks|Out]); +list2state([F|Fs], List, Out) -> list2state(Fs, List, [proplists:get_value(F, List, state_default(F))|Out]). + +lock_default(Field) -> proplists:get_value(Field, lock2list(#lock{})). + +lock2list(Lock) -> + [_|Values] = tuple_to_list(Lock), + lists:zip(record_info(fields, lock), Values). + +list2lock(List) -> list2lock(record_info(fields, lock), List, [lock]). +list2lock([], _, Out) -> list_to_tuple(lists:reverse(Out)); +list2lock([F|Fs], List, Out) -> list2lock(Fs, List, [proplists:get_value(F, List, lock_default(F))|Out]). + +%% printing + +%% print_lock_information +%% In: +%% Locks :: [#lock{}] +%% Print :: [Type | {Type, integer()}] +%% +%% Out: +%% ok + +auto_print_width(Locks, Print) -> + % iterate all lock entries to save all max length values + % these are records, so we do a little tuple <-> list smashing + R = lists:foldl(fun + (L, Max) -> + list_to_tuple(lists:reverse(lists:foldl(fun + ({print,print}, Out) -> [print|Out]; + ({Str, Len}, Out) -> [erlang:min(erlang:max(length(s(Str))+1,Len),80)|Out] + end, [], lists:zip(tuple_to_list(L), tuple_to_list(Max))))) + end, #print{ id = 4, type = 5, entry = 5, name = 6, tries = 8, colls = 13, cr = 16, time = 11, dtr = 14 }, + Locks), + % Setup the offsets for later pruning + Offsets = [ + {id, R#print.id}, + {name, R#print.name}, + {type, R#print.type}, + {entry, R#print.entry}, + {tries, R#print.tries}, + {colls, R#print.colls}, + {ratio, R#print.cr}, + {time, R#print.time}, + {duration, R#print.dtr}], + % Prune offsets to only allow specified print options + lists:foldr(fun + ({Type, W}, Out) -> [{Type, W}|Out]; + (Type, Out) -> [proplists:lookup(Type, Offsets)|Out] + end, [], Print). + +print_lock_information(Locks, Print) -> + % remake Print to autosize entries + AutoPrint = auto_print_width(Locks, Print), + + print_header(AutoPrint), + + lists:foreach(fun + (L) -> + print_lock(L, AutoPrint) + end, Locks), + ok. + +print_header(Opts) -> + Header = #print{ + name = "lock", + id = "id", + type = "type", + entry = "location", + tries = "#tries", + colls = "#collisions", + cr = "collisions [%]", + time = "time [us]", + dtr = "duration [%]" + }, + Divider = #print{ + name = lists:duplicate(1 + length(Header#print.name), 45), + id = lists:duplicate(1 + length(Header#print.id), 45), + type = lists:duplicate(1 + length(Header#print.type), 45), + entry = lists:duplicate(1 + length(Header#print.entry), 45), + tries = lists:duplicate(1 + length(Header#print.tries), 45), + colls = lists:duplicate(1 + length(Header#print.colls), 45), + cr = lists:duplicate(1 + length(Header#print.cr), 45), + time = lists:duplicate(1 + length(Header#print.time), 45), + dtr = lists:duplicate(1 + length(Header#print.dtr), 45) + }, + print_lock(Header, Opts), + print_lock(Divider, Opts), + ok. + + +print_lock(L, Opts) -> print_lock(L, Opts, []). +print_lock(_, [], Formats) -> print(strings(lists:reverse(Formats))); +print_lock(L, [Opt|Opts], Formats) -> + case Opt of + id -> print_lock(L, Opts, [{space, 25, s(L#print.id) } | Formats]); + {id, W} -> print_lock(L, Opts, [{space, W, s(L#print.id) } | Formats]); + type -> print_lock(L, Opts, [{space, 18, s(L#print.type) } | Formats]); + {type, W} -> print_lock(L, Opts, [{space, W, s(L#print.type) } | Formats]); + entry -> print_lock(L, Opts, [{space, 30, s(L#print.entry)} | Formats]); + {entry, W} -> print_lock(L, Opts, [{space, W, s(L#print.entry)} | Formats]); + name -> print_lock(L, Opts, [{space, 22, s(L#print.name) } | Formats]); + {name, W} -> print_lock(L, Opts, [{space, W, s(L#print.name) } | Formats]); + tries -> print_lock(L, Opts, [{space, 12, s(L#print.tries)} | Formats]); + {tries, W} -> print_lock(L, Opts, [{space, W, s(L#print.tries)} | Formats]); + colls -> print_lock(L, Opts, [{space, 14, s(L#print.colls)} | Formats]); + {colls, W} -> print_lock(L, Opts, [{space, W, s(L#print.colls)} | Formats]); + ratio -> print_lock(L, Opts, [{space, 20, s(L#print.cr) } | Formats]); + {ratio, W} -> print_lock(L, Opts, [{space, W, s(L#print.cr) } | Formats]); + time -> print_lock(L, Opts, [{space, 15, s(L#print.time) } | Formats]); + {time, W} -> print_lock(L, Opts, [{space, W, s(L#print.time) } | Formats]); + duration -> print_lock(L, Opts, [{space, 20, s(L#print.dtr) } | Formats]); + {duration, W} -> print_lock(L, Opts, [{space, W, s(L#print.dtr) } | Formats]); + _ -> print_lock(L, Opts, Formats) + end. + +print_state_information(#state{ locks = Locks} = State) -> + Stats = summate_locks(Locks), + print("information:"), + print(kv("#locks", s(length(Locks)))), + print(kv("duration", s(State#state.duration) ++ " us" ++ " (" ++ s(State#state.duration/1000000) ++ " s)")), + print("\nsummated stats:"), + print(kv("#tries", s(Stats#stats.tries))), + print(kv("#colls", s(Stats#stats.colls))), + print(kv("wait time", s(Stats#stats.time) ++ " us" ++ " ( " ++ s(Stats#stats.time/1000000) ++ " s)")), + print(kv("percent of duration", s(Stats#stats.time/State#state.duration*100) ++ " %")), + ok. + +%% AUX + +time2us({S, Ns}) -> round(S*1000000 + Ns/1000). + +percent(_,0) -> 0.0; +percent(T,N) -> T/N*100. + +options(Opts, Default) when is_list(Default) -> + options1(proplists:unfold(Opts), Default). +options1([], Defaults) -> Defaults; +options1([{Key, Value}|Opts], Defaults) -> + case proplists:get_value(Key, Defaults) of + undefined -> options1(Opts, [{Key, Value} | Defaults]); + _ -> options1(Opts, [{Key, Value} | proplists:delete(Key, Defaults)]) + end. + +%%% AUX STRING FORMATTING + +print(String) -> io:format("~s~n", [String]). + +kv(Key, Value) -> kv(Key, Value, 20). +kv(Key, Value, Offset) -> term2string(term2string("~~~ps : ~~s", [Offset]),[Key, Value]). + +s(T) when is_float(T) -> term2string("~.4f", [T]); +s(T) when is_list(T) -> term2string("~s", [T]); +s(T) -> term2string(T). + +strings(Strings) -> strings(Strings, []). +strings([], Out) -> Out; +strings([{space, N, S} | Ss], Out) -> strings(Ss, Out ++ term2string(term2string("~~~ps", [N]), [S])); +strings([{format, Format, S} | Ss], Out) -> strings(Ss, Out ++ term2string(Format, [S])); +strings([S|Ss], Out) -> strings(Ss, Out ++ term2string("~s", [S])). + + +term2string({M,F,A}) when is_atom(M), is_atom(F), is_integer(A) -> term2string("~p:~p/~p", [M,F,A]); +term2string(Term) when is_port(Term) -> + % ex #Port<6442.816> + <<_:3/binary, L:16, Node:L/binary, Ids:32, _/binary>> = term_to_binary(Term), + term2string("#Port<~s.~w>", [Node, Ids]); +term2string(Term) when is_pid(Term) -> + % ex <0.80.0> + <<_:3/binary, L:16, Node:L/binary, Ids:32, Serial:32, _/binary>> = term_to_binary(Term), + term2string("<~s.~w.~w>", [Node, Ids, Serial]); +term2string(Term) -> term2string("~w", [Term]). +term2string(Format, Terms) -> lists:flatten(io_lib:format(Format, Terms)). + +%%% AUD id binary + +bytes16(Value) -> + B0 = Value band 255, + B1 = (Value bsr 8) band 255, + <<B1, B0>>. + +bytes32(Value) -> + B0 = Value band 255, + B1 = (Value bsr 8) band 255, + B2 = (Value bsr 16) band 255, + B3 = (Value bsr 24) band 255, + <<B3, B2, B1, B0>>. diff --git a/lib/tools/src/xref_utils.erl b/lib/tools/src/xref_utils.erl index aeb7bf9f1c..680b7e8aac 100644 --- a/lib/tools/src/xref_utils.erl +++ b/lib/tools/src/xref_utils.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2000-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2000-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(xref_utils). @@ -453,7 +453,8 @@ find_beam(Module) when is_atom(Module) -> non_existing -> error({no_such_module, Module}); preloaded -> - {_M, _Bin, File} = code:get_object_code(Module), + {Module, {_M, _Bin, File}} = + {Module, code:get_object_code(Module)}, {ok, File}; cover_compiled -> error({cover_compiled, Module}); diff --git a/lib/tools/test/Makefile b/lib/tools/test/Makefile index a846a3a6f4..3a59be758a 100644 --- a/lib/tools/test/Makefile +++ b/lib/tools/test/Makefile @@ -26,6 +26,7 @@ MODULES = \ fprof_SUITE \ cprof_SUITE \ instrument_SUITE \ + lcnt_SUITE \ make_SUITE \ tools_SUITE \ xref_SUITE \ @@ -49,7 +50,8 @@ RELSYSDIR = $(RELEASE_PATH)/tools_test # FLAGS # ---------------------------------------------------- ERL_MAKE_FLAGS += -ERL_COMPILE_FLAGS += -I$(ERL_TOP)/lib/test_server/include +ERL_COMPILE_FLAGS += -I$(ERL_TOP)/lib/test_server/include \ + -I$(ERL_TOP)/lib/percept/include EBIN = . @@ -68,10 +70,11 @@ tests debug opt: make_emakefile clean: rm -f $(EMAKEFILE) rm -f $(TARGET_FILES) - rm -f core + rm -f core *~ docs: + # ---------------------------------------------------- # Release Target # ---------------------------------------------------- diff --git a/lib/tools/test/lcnt_SUITE.erl b/lib/tools/test/lcnt_SUITE.erl new file mode 100644 index 0000000000..e6866f721d --- /dev/null +++ b/lib/tools/test/lcnt_SUITE.erl @@ -0,0 +1,154 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(lcnt_SUITE). +-include("test_server.hrl"). + +%% Test server specific exports +-export([all/1]). +-export([init_per_suite/1, end_per_suite/1]). +-export([init_per_testcase/2, end_per_testcase/2]). + +%% Test cases +-export([ + load_v1/1, + conflicts/1, + locations/1, + swap_keys/1 + ]). + +%% Default timetrap timeout (set in init_per_testcase) +-define(default_timeout, ?t:minutes(2)). + +init_per_suite(Config) when is_list(Config) -> + Config. + +end_per_suite(Config) when is_list(Config) -> + Config. + +init_per_testcase(_Case, Config) -> + Dog = ?t:timetrap(?default_timeout), + [{watchdog,Dog} | Config]. + +end_per_testcase(_Case, Config) -> + Dog = ?config(watchdog, Config), + ?t:timetrap_cancel(Dog), + ok. + +all(suite) -> + % Test cases + [load_v1, conflicts, locations, swap_keys]. + +%%---------------------------------------------------------------------- +%% Tests +%%---------------------------------------------------------------------- + +load_v1(suite) -> + []; +load_v1(doc) -> + ["Load data from file."]; +load_v1(Config) when is_list(Config) -> + ?line {ok, _} = lcnt:start(), + ?line Path = ?config(data_dir, Config), + ?line File = filename:join([Path,"big_bang_40.lcnt"]), + ?line ok = lcnt:load(File), + ?line ok = lcnt:stop(), + ok. + +conflicts(suite) -> + []; +conflicts(doc) -> + ["API: conflicts"]; +conflicts(Config) when is_list(Config) -> + ?line {ok, _} = lcnt:start(), + ?line Path = ?config(data_dir, Config), + ?line File = filename:join([Path,"big_bang_40.lcnt"]), + ?line ok = lcnt:load(File), + ?line ok = lcnt:conflicts(), + THs = [-1, 0, 100, 1000], + Print = [name , id , type , entry , tries , colls , ratio , time , duration], + Opts = [ + [{sort, Sort}, {reverse, Rev}, {max_locks, ML}, {combine, Combine}, {thresholds, [TH]}, {print, [Print]}] || + Sort <- [name , id , type , tries , colls , ratio , time , entry], + ML <- [none, 1 , 32, 4096], + Combine <- [true, false], + TH <- [{tries, Tries} || Tries <- THs] ++ [{colls, Colls} || Colls <- THs] ++ [{time, Time} || Time <- THs], + Rev <- [true, false] + ], + ?line ok = test_conflicts_opts(Opts), + ?line ok = lcnt:stop(), + ok. + +test_conflicts_opts([]) -> ok; +test_conflicts_opts([Opt|Opts]) -> + ?line ok = lcnt:conflicts(Opt), + test_conflicts_opts(Opts). + +locations(suite) -> + []; +locations(doc) -> + ["API: locations"]; +locations(Config) when is_list(Config) -> + ?line {ok, _} = lcnt:start(), + ?line Path = ?config(data_dir, Config), + ?line File = filename:join([Path,"big_bang_40.lcnt"]), + ?line ok = lcnt:load(File), + ?line ok = lcnt:locations(), + THs = [-1, 0, 100, 1000], + Print = [name , id , type , entry , tries , colls , ratio , time , duration], + Opts = [ + [{full_id, Id}, {sort, Sort}, {max_locks, ML}, {combine, Combine}, {thresholds, [TH]}, {print, Print}] || + Sort <- [name , id , type , tries , colls , ratio , time , entry], + ML <- [none, 1 , 64], + Combine <- [true, false], + TH <- [{tries, Tries} || Tries <- THs] ++ [{colls, Colls} || Colls <- THs] ++ [{time, Time} || Time <- THs], + Id <- [true, false] + ], + ?line ok = test_locations_opts(Opts), + ?line ok = lcnt:stop(), + ok. + +test_locations_opts([]) -> ok; +test_locations_opts([Opt|Opts]) -> + ?line ok = lcnt:locations(Opt), + test_locations_opts(Opts). + +swap_keys(suite) -> + []; +swap_keys(doc) -> + ["Test interchanging port/process id with class"]; +swap_keys(Config) when is_list(Config) -> + ?line {ok, _} = lcnt:start(), + ?line Path = ?config(data_dir, Config), + ?line File = filename:join([Path,"big_bang_40.lcnt"]), + ?line ok = lcnt:load(File), + ?line ok = lcnt:conflicts(), + ?line ok = lcnt:swap_pid_keys(), + ?line ok = lcnt:conflicts(), + ?line ok = lcnt:stop(), + ok. + + +%%---------------------------------------------------------------------- +%% Auxiliary tests +%%---------------------------------------------------------------------- + +%%---------------------------------------------------------------------- +%% Auxiliary +%%---------------------------------------------------------------------- diff --git a/lib/tools/test/lcnt_SUITE_data/big_bang_40.lcnt b/lib/tools/test/lcnt_SUITE_data/big_bang_40.lcnt Binary files differnew file mode 100644 index 0000000000..6087f6f37e --- /dev/null +++ b/lib/tools/test/lcnt_SUITE_data/big_bang_40.lcnt diff --git a/lib/tools/test/xref_SUITE.erl b/lib/tools/test/xref_SUITE.erl index 0bbb3ba0f1..b4684140ca 100644 --- a/lib/tools/test/xref_SUITE.erl +++ b/lib/tools/test/xref_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2000-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2000-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% -module(xref_SUITE). @@ -1067,9 +1067,7 @@ read_expected(Version) -> {POS13+3,{FF,{'$M_EXPR','$F_EXPR',-1}}}, {POS14+8,{{read,bi,0},{'$M_EXPR','$F_EXPR',1}}}], - O1 = [{0,{FF,{modul,'$F_EXPR',179}}}, - {0,{FF,{read,'$F_EXPR',178}}}, - {20,{{read,lc,0},{ets,new,0}}}, + O1 = [{20,{{read,lc,0},{ets,new,0}}}, {21,{{read,lc,0},{ets,tab2list,1}}}, {POS1+1,{FF,{erlang,spawn,1}}}, {POS1+1,{FF,{mod17,fun17,0}}}, @@ -1168,13 +1166,19 @@ read_expected(Version) -> [{POS8+3, {FF,{erlang,apply,3}}}, {POS10+1, {FF,{erlang,apply,3}}}, {POS10+6, {FF,{erlang,apply,3}}}] - ++ O1; + ++ + [{0,{FF,{read,'$F_EXPR',178}}}, + {0,{FF,{modul,'$F_EXPR',179}}}] + ++ O1; _ -> % [{POS15+2,{{read,bi,0},{foo,t,0}}}, % {POS15+3,{{read,bi,0},{bar,t,0}}}, % {POS15+6,{{read,bi,0},{read,local,0}}}, % {POS15+8,{{read,bi,0},{foo,t,0}}}, % {POS15+10,{{read,bi,0},{bar,t,0}}}] ++ + [{16,{FF,{read,'$F_EXPR',178}}}, + {17,{FF,{modul,'$F_EXPR',179}}}] + ++ O1 end, @@ -1649,7 +1653,7 @@ abstract_modules(Conf) when is_list(Conf) -> %% The compiler will no longer allow us to have a mismatch between %% the module name and the output file, so we must use a trick. ?line {ok, param, BeamCode} = compile:file(File, [binary,debug_info]), - ?line ok = file:write_file(filename:join(Dir, Beam), BeamCode), + ?line ok = file:write_file(Beam, BeamCode), ?line {ok, _} = xref:start(s), ?line {ok, param} = xref:add_module(s, MFile, {warnings,false}), @@ -40,7 +40,7 @@ bootstrap_apps="erts lib/asn1 lib/compiler lib/hipe lib/ic lib/kernel lib/parset # We will quote a bit more than needed, but the important thing is that # all that needs quoting will be quoted... -DONT_QUOTE="A-Za-z0-9/=_+-" +DONT_QUOTE="A-Za-z0-9~/=_+-" # Utility functions usage () @@ -433,7 +433,11 @@ try_cross_configure () --build=*) build_value=`echo $x | sed "s|^--build=\(.*\)|\1|"`;; --xcomp-conf=*) - xcomp_conf=`echo "X$arg" | sed "s|^X--xcomp-conf=\(.*\)\$|\1|g"` + # tilde expansion is not handled by the `configure' script, + # but we do it for this argument. This argument is however not + # a `configure' argument. + xcomp_conf=`echo "X$arg" | sed "s|^X--xcomp-conf=\(.*\)\$|\1|g;s|\([^$DONT_QUOTE]\)|\\\\\\\\\1|g"` + eval "xcomp_conf=$xcomp_conf" test "X$xcomp_conf" != "X" || { echo "$0: Missing xcomp-conf file name" exit 1 @@ -444,7 +448,7 @@ try_cross_configure () } . "$xcomp_conf" test $? -eq 0 || { - echo "$0: Failed to read xcomp-conf file: $conf" + echo "$0: Failed to read xcomp-conf file: $xcomp_conf" exit 1 } test "X$erl_xcomp_build" = "X" || build_value="$erl_xcomp_build" diff --git a/system/doc/installation_guide/Makefile b/system/doc/installation_guide/Makefile index c51f0ee5f3..ec60105ae0 100644 --- a/system/doc/installation_guide/Makefile +++ b/system/doc/installation_guide/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1996-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1996-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # # @@ -54,6 +54,12 @@ XML_FILES = \ $(XML_PART_FILES) # ---------------------------------------------------- +# Readme for X-compiling +# ---------------------------------------------------- +XCOMP_README_FILE = $(ERL_TOP)/xcomp/README.md +README_FILE = $(ERL_TOP)/README + +# ---------------------------------------------------- HTML_FILES = \ $(XML_PART_FILES:%.xml=%.html) @@ -92,8 +98,10 @@ include $(ERL_TOP)/make/otp_release_targets.mk release_docs_spec: docs $(INSTALL_DIR) $(RELSYSDIR) - $(INSTALL_DATA) $(GIF_FILES) $(HTMLDIR)/*.html \ + $(INSTALL_DATA) $(README_FILE) $(GIF_FILES) $(HTMLDIR)/*.html \ $(RELSYSDIR) + $(INSTALL_DIR) $(RELSYSDIR)/xcomp + $(INSTALL_DATA) $(XCOMP_README_FILE) $(RELSYSDIR)/xcomp release_spec: diff --git a/system/doc/top/Makefile b/system/doc/top/Makefile index 08fe265336..154deb006b 100644 --- a/system/doc/top/Makefile +++ b/system/doc/top/Makefile @@ -1,19 +1,19 @@ # # %CopyrightBegin% -# -# Copyright Ericsson AB 1999-2009. All Rights Reserved. -# +# +# Copyright Ericsson AB 1999-2010. All Rights Reserved. +# # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in # compliance with the License. You should have received a copy of the # Erlang Public License along with this software. If not, it can be # retrieved online at http://www.erlang.org/. -# +# # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See # the License for the specific language governing rights and limitations # under the License. -# +# # %CopyrightEnd% # # @@ -103,7 +103,8 @@ JAVASCRIPT = $(HTMLDIR)/js/erlresolvelinks.js JAVASCRIPT_BUILD_SCRIPT = $(EBIN)/erlresolvelinks.$(EMULATOR) JAVASCRIPT_BUILD_SCRIPT_SRC = src/erlresolvelinks.erl -MAN_INDEX_SCRIPT = $(ERL_TOP)/system/doc/top/bin/otp_man_index +MAN_INDEX_SCRIPT = $(EBIN)/otp_man_index.$(EMULATOR) +MAN_INDEX_SRC = src/otp_man_index.erl MAN_INDEX = $(HTMLDIR)/man_index.html GLOSSARY = $(HTMLDIR)/glossary.html @@ -116,14 +117,11 @@ $(INDEX_SCRIPT): $(INDEX_SRC) $(ERLC) -o$(EBIN) +warn_unused_vars $< # We don't list toc_*.html as targets because we don't know -$(HTMLDIR)/index.html: $(INDEX_SCRIPT) -ifneq ($(INSTALLROOT),) +$(HTMLDIR)/index.html + $(HTMLDIR)/applications.html: $(INDEX_SCRIPT) echo "Generating index $@" - $(ERL) -noshell -pa $(EBIN) -s erl_html_tools top_index $(INSTALLROOT) \ + $(ERL) -noshell -pa $(EBIN) -s erl_html_tools top_index $(ERL_TOP) \ $(HTMLDIR) $(SYSTEM_VSN) -s erlang halt -else - @echo "INSTALLROOT unset, no indexes built." -endif + #-------------------------------------------------------------------------- @@ -131,25 +129,19 @@ $(JAVASCRIPT_BUILD_SCRIPT): $(JAVASCRIPT_BUILD_SCRIPT_SRC) $(ERLC) -o$(EBIN) +warn_unused_vars $< $(JAVASCRIPT): $(JAVASCRIPT_BUILD_SCRIPT) -ifneq ($(INSTALLROOT),) - echo "Generating javascript for resolving HTML links" - erl -noshell -pa $(EBIN) -s erlresolvelinks make $(INSTALLROOT) \ - . -s erlang halt - mkdir $(HTMLDIR)/js - mv erlresolvelinks.js $(JAVASCRIPT) # not portable !!! -else - @echo "INSTALLROOT unset, no javascript generated." -endif + erl -noshell -pa $(EBIN) -s erlresolvelinks make -s erlang halt + $(INSTALL_DIR) $(HTMLDIR)/js + $(INSTALL_DATA) erlresolvelinks.js $(JAVASCRIPT) #-------------------------------------------------------------------------- +$(MAN_INDEX_SCRIPT): $(MAN_INDEX_SRC) + $(ERLC) -o$(EBIN) +warn_unused_vars $< + $(MAN_INDEX): $(MAN_INDEX_SCRIPT) -ifneq ($(INSTALLROOT),) - echo "Generating index $@" - (cd $(INSTALLROOT); perl $< ) > $@ -else - @echo "INSTALLROOT unset, no manual index built." -endif + $(ERL) -noshell -pa $(EBIN) -s otp_man_index gen $(ERL_TOP) $@ \ + -s erlang halt + #-------------------------------------------------------------------------- $(HTMLDIR)/highlights.html: highlights.xml @@ -230,13 +222,11 @@ release_docs_spec: docs $(INSTALL_DIR) $(RELSYSDIR)/pdf $(INSTALL_DATA) \ $(TOP_PDF_FILE) $(RELSYSDIR)/pdf -#$(TOP_HTML_FILES) -ifneq ($(INSTALLROOT),) - $(INSTALL_DATA) $(INDEX_FILES) $(MAN_INDEX) $(TOP_HTML_FILES) $(RELSYSDIR) + $(INSTALL_DATA) $(TOP_HTML_FILES) $(RELSYSDIR) $(INSTALL_DIR) $(RELSYSDIR)/js $(INSTALL_DATA) \ $(JAVASCRIPT) $(RELSYSDIR)/js -endif + $(INSTALL_DATA) $(INDEX_FILES) $(MAN_INDEX) $(TOP_HTML_FILES) $(RELSYSDIR) release_spec: diff --git a/system/doc/top/bin/.gitignore b/system/doc/top/bin/.gitignore new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/system/doc/top/bin/.gitignore diff --git a/system/doc/top/bin/otp_man_index b/system/doc/top/bin/otp_man_index deleted file mode 100755 index 57a0f12d32..0000000000 --- a/system/doc/top/bin/otp_man_index +++ /dev/null @@ -1,106 +0,0 @@ -#!/opt/local/bin/perl - -use File::Find; -use strict; - -######################################### -# Usage: -# $ cd $ERLANG_RELEASE -# otp_man_index > doc/man_index.html -######################################### - -my (@list,$info); - -find(\&wanted,'.'); - -header(); - -foreach $info (sort {lc($a->[0]) cmp lc($b->[0])} @list) { - my ($module,$application,$dir,$path) = @$info; - - my $idx = -f "$dir/index.html" ? "$dir/index.html" : "$dir/../index.html"; - # Remove .html extension from module name, if there is one - if ($module =~ /(\w+).html$/) { - $module = "$1"; - } - print " <TR>\n"; - print " <TD><A HREF=\"../$path\">$module</A></TD>\n"; - print " <TD><A HREF=\"../$idx\">$application</A></TD>\n"; - print " </TR>\n"; -} - -footer(); - -########################################################################### - -sub wanted { - return unless /\.html$/ and -f $_; - - open(FILE,$_) or die "ERROR: Can't open $File::Find::name: $!\n"; - my $line; - - while (defined ($line = <FILE>)) { - if ($line =~ /<!-- refpage -->/) { - close FILE; - my $path = $File::Find::name; - $path =~ s/\.\///; # Remove './' prefix - my $dir = $File::Find::dir; - $dir =~ s/\.\///; # Remove './' prefix - $dir =~ m&([^/]+)/doc/html$&; - my $application = $1; - push(@list, [$_,$application,$dir,$path]); - return; - } - } - close FILE; -} - - -sub header { - print <<EOS; -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<!-- This file was generated by the otp_man_index script --> -<HTML> -<HEAD> - <link rel="stylesheet" href="otp_doc.css" type="text/css"/> - <TITLE>Erlang/OTP Manual Page Index</TITLE> -</HEAD> -<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF" - ALINK="#FF0000"> -<CENTER> -<!-- A HREF="http://www.erlang.org/"> -<img alt="Erlang logo" src="erlang-logo.png"/ > -</A><BR --> -<SMALL> -[<A HREF="index.html">Up</A> | -<A HREF="http://www.erlang.org/">Erlang</A>] -</SMALL><BR> -<P><FONT SIZE="+4">Manual Page Index</FONT><BR> -</CENTER> -<CENTER> -<P> -<TABLE BORDER=1> -<TR> - <TH>Manual Page</TH><TH>Application</TH> -</TR> -EOS -} - -sub footer { - my $year = (localtime)[5] + 1900; - print <<EOS; -</TABLE> -</CENTER> -<P> -<CENTER> -<HR> -<SMALL> -Copyright © 1991-$year -<a href="http://www.ericsson.com/technology/opensource/erlang/"> -Ericsson AB</a> -</SMALL> -</CENTER> -</BODY> -</HTML> -EOS -} diff --git a/system/doc/top/src/erl_html_tools.erl b/system/doc/top/src/erl_html_tools.erl index d93516768e..8a5c744128 100644 --- a/system/doc/top/src/erl_html_tools.erl +++ b/system/doc/top/src/erl_html_tools.erl @@ -1,130 +1,66 @@ -%% ``The contents of this file are subject to the Erlang Public License, +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be -%% retrieved via the world wide web at http://www.erlang.org/. -%% +%% retrieved online at http://www.erlang.org/. +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% -%% The Initial Developer of the Original Code is Ericsson Utvecklings AB. -%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings -%% AB. All Rights Reserved.'' -%% --module(erl_html_tools). - -%% This file contains tools for updating HTML files in an installed system -%% depending on the installed applications. Currently the only use is -%% to update the top index file. - - -%% ------ VERY IMPORTANT ------ %% -%% Original location for this file: -%% /clearcase/otp/internal_tools/integration/scripts/make_index/ -%% When updating this file, copy the source to -%% /home/otp/patch/share/program/ -%% and place .beam files (compiled with correct release) in all -%% /home/otp/patch/share/program/<release> -%% for releases >= R9C +%% %CopyrightEnd% %% -%% ---------------------------- - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% This program generate the top index files for the OTP documentation. -% Part of the HTML code is in templates, like "index.html.src" and -% part is written out from this module. So the program and the templates -% has to match. -% -% The templates are searched from the current directory, a directory -% "templates" relative to the current directory or at RootDir. -% -% RootDir is given as an argument or assumed to be code:root_dir(), -% i.e. the root of the system running this program. -% -% The output is put into DestDir or RootDir if not given. -% -% The functions to call are -% -% top_index() -% top_index([RootDir]) -% top_index([RootDir,DestDir,OtpRel]) -% top_index(RootDir) -% top_index(RootDir, DestDir, OtpRel) -% -% where RootDir can be a string or an atom. -% -% -% USING THIS SCRIPT FROM THE UNIX COMMAND LINE -% -------------------------------------------- -% If the Erlang started is the same as the Erlang to create index.html -% for the use -% -% % erl -noshell -s erl_html_tools top_index -% -% If you want to create an index for another Erlang installation or -% documentation located separate from the object code, then use -% -% % erl -noshell -s erl_html_tools top_index /path/to/erlang/root -% -% -% COLLECTING INFORMATION -% ---------------------- -% This script assumes that all applications have an "info" file -% in their top directory. This file should have some keywords with -% values defined. The keys are 'group' and 'short' (for "short -% description). See the OTP applications for examples. -% -% Some HTML code is generated by this program, others are taken from -% the file "index.html.src" that may be located in the patch directory -% or in the "$ERLANG_ROOT/doc/" directory. -% -% The code for creating the top index page assumes all applications -% have a file "info" with some fields filled in -% -% short: Text Short text describing the application -% group: tag [Heading] Group tag optionally followed by a description. -% Only one app need to describe the group but -% more than one can. -% -% FIXME: Check that there is documentation for the application, not just -% an info file. -% FIXME: Use records, it is now unreadable :-( -% FIXME: Use a separate URL and URLIndexFile -% FIXME: Pass the OTP release name as an argument instead of in -% process dictionary (for elegance). +%%----------------------------------------------------------------- +%% File: erl_html_tools.erl +%% +%% Description: +%% This file generates the top index of the documentation. +%% +%%----------------------------------------------------------------- +-module(erl_html_tools). -export([top_index/0,top_index/1,top_index/3,top_index_silent/3]). -% This is the order groups are inserted into the file. Groups -% not in this list is inserted in undefined order. +-include_lib("kernel/include/file.hrl"). group_order() -> [ - basic, - dat, - oam, - orb, - comm, - tools + {basic, "Basic"}, + {dat, "Database"}, + {oam, "Operation & Maintenance"}, + {comm, "Interface and Communication"}, + {tools, "Tools"}, + {test, "Test"}, + {doc, "Documentation"}, + {orb, "Object Request Broker & IDL"}, + {misc, "Miscellaneous"} ]. top_index() -> - top_index(code:root_dir()). + case os:getenv("ERL_TOP") of + false -> + io:format("Variable ERL_TOP is required\n",[]); + Value -> + {_,RelName} = init:script_id(), + top_index(Value, filename:join(Value, "doc"), RelName) + end. -top_index([RootDir]) when atom(RootDir) -> - top_index(atom_to_list(RootDir)); -top_index([RootDir,DestDir,OtpRel]) +top_index([RootDir, DestDir, OtpRel]) when is_atom(RootDir), is_atom(DestDir), is_atom(OtpRel) -> top_index(atom_to_list(RootDir), atom_to_list(DestDir), atom_to_list(OtpRel)); -top_index(RootDir) -> +top_index(RootDir) when is_atom(RootDir) -> {_,RelName} = init:script_id(), top_index(RootDir, filename:join(RootDir, "doc"), RelName). + + top_index(RootDir, DestDir, OtpRel) -> report("****\nRootDir: ~p", [RootDir]), report("****\nDestDir: ~p", [DestDir]), @@ -145,7 +81,9 @@ top_index_silent(RootDir, DestDir, OtpRel) -> Result = top_index(RootDir, DestDir, OtpRel), erase(silent), Result. - + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Main loop - process templates @@ -173,7 +111,7 @@ process_multi_template(BaseName0, Template, DestDir, Info) -> BaseName1 = filename:basename(BaseName0, Ext), [_|BaseName2] = lists:reverse(BaseName1), BaseName = lists:reverse(BaseName2), - Groups0 = [{[$_|atom_to_list(G)],G} || G <- group_order()], + Groups0 = [{[$_|atom_to_list(G)],G} || {G, _} <- group_order()], Groups = [{"",basic}|Groups0], process_multi_template_1(Groups, BaseName, Ext, Template, DestDir, Info). @@ -240,34 +178,47 @@ find_information(Bases) -> find_application_paths([]) -> []; -find_application_paths([{URL,Dir} | Paths]) -> +find_application_paths([{URL, Dir} | Paths]) -> Sub1 = "doc/html/index.html", %% Sub2 = "doc/index.html", - case file:list_dir(Dir) of - {ok, Dirs} -> - AppDirs = - lists:filter( - fun(E) -> - is_match(E, "^[A-Za-z0-9_]+-[0-9\\.]+") - end, Dirs), - AppPaths = - lists:map( - fun(AppDir) -> - {ok,[App,Ver]} = regexp:split(AppDir, "-"), - DirPath = filename:join(Dir,AppDir), - AppURL = URL ++ AppDir, - {App,Ver,DirPath,AppURL ++ "/" ++ Sub1} -%% case file:read_file_info( -%% filename:join(DirPath, Sub1)) of -%% {ok, _} -> -%% {App,Ver,DirPath,AppURL ++ "/" ++ Sub1}; -%% _ -> -%% {App,Ver,DirPath,AppURL ++ "/" ++ Sub2} -%% end - end, AppDirs), - AppPaths ++ find_application_paths(Paths) - end. + AppDirs = get_app_dirs(Dir), + + AppPaths = + lists:map( + fun({App, AppPath}) -> + VsnFile = filename:join(AppPath, "vsn.mk"), + VsnStr = + case file:read_file(VsnFile) of + {ok, Bin} -> + case re:run(Bin, ".*VSN\s*=\s*([0-9\.]+).*",[{capture,[1],list}]) of + {match, [V]} -> + V; + nomatch -> + exit(io_lib:format("No VSN variable found in ~s\n", + [VsnFile])) + end; + {error, Reason} -> + exit(io_lib:format("~p : ~s\n", [Reason, VsnFile])) + end, + AppURL = URL ++ App ++ "-" ++ VsnStr, + {App, VsnStr, AppPath, AppURL ++ "/" ++ Sub1} + end, AppDirs), + AppPaths ++ find_application_paths(Paths). + +get_app_dirs(Dir) -> + {ok, Files} = file:list_dir(Dir), + AFiles = + lists:map(fun(File) -> {File, filename:join([Dir, File])} end, Files), + lists:zf(fun is_app_with_doc/1, AFiles). + +is_app_with_doc({ADir, APath}) -> + case file:read_file_info(filename:join([APath, "info"])) of + {ok, _FileInfo} -> + {true, {ADir, APath}}; + _ -> + false + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Find info for one application. @@ -281,20 +232,20 @@ find_application_paths([{URL,Dir} | Paths]) -> find_application_infos([]) -> []; -find_application_infos([{App,Ver,AppPath,IndexURL} | Paths]) -> +find_application_infos([{App, Vsn, AppPath, IndexURL} | Paths]) -> case read_info(filename:join(AppPath,"info")) of {error,_Reason} -> warning("No info for app ~p", [AppPath]), find_application_infos(Paths); Db -> - {Group,Heading} = + {Group,_Heading} = case lists:keysearch("group", 1, Db) of {value, {_, G0}} -> % This value may be in two parts, % tag and desciption - case string:str(G0," ") of + case string:str(G0, " ") of 0 -> - {list_to_atom(G0),""}; + {list_to_atom(G0), ""}; N -> {list_to_atom(string:substr(G0,1,N-1)), string:substr(G0,N+1)} @@ -309,7 +260,8 @@ find_application_infos([{App,Ver,AppPath,IndexURL} | Paths]) -> false -> "" end, - [{Group,Heading,{App,{Ver,AppPath,IndexURL,Text}}} +%% [{Group, Heading, {App, {Vsn, AppPath, IndexURL, Text}}} + [{Group, "", {App, {Vsn, AppPath, IndexURL, Text}}} | find_application_infos(Paths)] end. @@ -439,17 +391,17 @@ search_appname(App, [{_Group,_,Apps} | Groups]) -> search_appname(App, Groups) end; search_appname(_App, []) -> - {error,noapp}. + {error, noapp}. subst_applinks(Info, Group) -> subst_applinks_1(group_order(), Info, Group). -subst_applinks_1([G|Gs], Info0, Group) -> +subst_applinks_1([{G, Heading}|Gs], Info0, Group) -> case lists:keysearch(G, 1, Info0) of - {value,{G,Heading,Apps}} -> + {value,{G,_Heading,Apps}} -> Info = lists:keydelete(G, 1, Info0), - ["\n<li>",Heading,"\n<ul>\n", - html_applinks(Apps),"\n</ul></li>\n"| + ["\n<li>",Heading, "\n<ul>\n", + html_applinks(Apps), "\n</ul></li>\n"| subst_applinks_1(Gs, Info, Group)]; false -> warning("No applications in group ~w\n", [G]), @@ -457,7 +409,7 @@ subst_applinks_1([G|Gs], Info0, Group) -> end; subst_applinks_1([], [], _) -> []; subst_applinks_1([], Info, _) -> - error("Info left:\n", [Info]), + error("Info left: ~p\n", [Info]), []. html_applinks([{Name,[{_,_,URL,_}|_]}|AppNames]) -> @@ -482,9 +434,9 @@ subst_groups(Info0) -> subst_known_groups([], Info, Text) -> {Text,Info}; -subst_known_groups([Group | Groups], Info0, Text0) -> +subst_known_groups([{Group, Heading} | Groups], Info0, Text0) -> case lists:keysearch(Group, 1, Info0) of - {value,{_,Heading,Apps}} -> + {value,{_,_Heading,Apps}} -> Text = group_table(Heading,Apps), Info = lists:keydelete(Group, 1, Info0), subst_known_groups(Groups, Info, Text0 ++ Text); @@ -634,34 +586,36 @@ combine_key_value([]) -> lines_to_key_value([]) -> []; lines_to_key_value([Line | Lines]) -> - case regexp:first_match(Line, "^[a-zA-Z_\\-]+:") of + case re:run(Line, "^[a-zA-Z_\\-]+:") of nomatch -> - case regexp:first_match(Line, "[\041-\377]") of + case re:run(Line, "[\041-\377]") of nomatch -> lines_to_key_value(Lines); _ -> warning("skipping line \"~s\"",[Line]), lines_to_key_value(Lines) end; - {match, _, Length} -> + {match, [{0, Length} |_]} -> Value0 = lists:sublist(Line, Length+1, length(Line) - Length), - {ok, Value1, _} = regexp:sub(Value0, "^[ \t]*", ""), - {ok, Value, _} = regexp:sub(Value1, "[ \t]*$", ""), + Value1 = re:replace(Value0, "^[ \t]*", "", + [{return, list}]), + Value = re:replace(Value1, "[ \t]*$", "", + [{return, list}]), Key = lists:sublist(Line, Length-1), - [{Key,Value} | lines_to_key_value(Lines)] + [{Key, Value} | lines_to_key_value(Lines)] end. - + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Extensions to the 'regexp' module. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -is_match(Ex, Re) -> - case regexp:first_match(Ex, Re) of - {match, _, _} -> - true; - nomatch -> - false - end. +%% is_match(Ex, Re) -> +%% case regexp:first_match(Ex, Re) of +%% {match, _, _} -> +%% true; +%% nomatch -> +%% false +%% end. %% -type gsub(String, RegExp, Fun, Acc) -> subres(). %% Substitute every match of the regular expression RegExp with the @@ -669,25 +623,27 @@ is_match(Ex, Re) -> %% regular expressions. Acc is an argument to the Fun. The Fun should return %% a tuple {Replacement, NewAcc}. -gsub(String, RegExp, Fun, Acc) when list(RegExp) -> - case regexp:parse(RegExp) of - {ok,RE} -> gsub(String, RE, Fun, Acc); - {error,E} -> {error,E} +gsub(String, RegExp, Fun, Acc) when is_list(RegExp) -> + case re:compile(RegExp) of + {ok, RE} -> + gsub(String, RE, Fun, Acc); + {error, E} -> + {error, E} end; gsub(String, RE, Fun, Acc) -> - {match,Ss} = regexp:matches(String, RE), - {NewString, NewAcc} = sub_repl(Ss, Fun, Acc, String, 1), - {ok,NewString,NewAcc}. + {match, Ss} = re:run(String, RE, [global]), + {NewString, NewAcc} = sub_repl(Ss, Fun, Acc, String, 0), + {ok, NewString, NewAcc}. % New code that uses fun for finding the replacement. Also uses accumulator % to pass argument between the calls to the fun. -sub_repl([{St,L}|Ss], Fun, Acc0, S, Pos) -> - Match = string:substr(S, St, L), +sub_repl([[{St, L}] |Ss], Fun, Acc0, S, Pos) -> + Match = string:substr(S, St+1, L), {Rep, Acc} = Fun(Match, Acc0), {Rs, NewAcc} = sub_repl(Ss, Fun, Acc, S, St+L), - {string:substr(S, Pos, St-Pos) ++ Rep ++ Rs, NewAcc}; -sub_repl([], _Fun, Acc, S, Pos) -> {string:substr(S, Pos), Acc}. + {string:substr(S, Pos+1, St-Pos) ++ Rep ++ Rs, NewAcc}; +sub_repl([], _Fun, Acc, S, Pos) -> {string:substr(S, Pos+1), Acc}. @@ -725,3 +681,4 @@ uc([H | T], Acc) when is_integer(H), [97] =< H, H =< $z -> uc(T, [H - 32 | Acc]); uc([H | T], Acc) -> uc(T, [H | Acc]). + diff --git a/system/doc/top/src/erlresolvelinks.erl b/system/doc/top/src/erlresolvelinks.erl index a891b67421..004d0d8626 100644 --- a/system/doc/top/src/erlresolvelinks.erl +++ b/system/doc/top/src/erlresolvelinks.erl @@ -1,42 +1,60 @@ --module(erlresolvelinks). - -%% ------ VERY IMPORTANT ------ +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009-2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. %% -%% Original location for this file: -%% /clearcase/otp/internal_tools/integration/scripts/resolve_links/ -%% When updating this file, copy the source to -%% /usr/local/otp/patch/share/program/ -%% and place .beam files (compiled with correct release) in all -%% /usr/local/otp/patch/share/program/<release> -%% for releases >= R10B +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. %% -%% ---------------------------- +%% %CopyrightEnd% +%% +%%----------------------------------------------------------------- +%% File: erlresolvelinks.erl +%% +%% Description: +%% This file generates the javascript that resolves documentation links. +%% +%%----------------------------------------------------------------- +-module(erlresolvelinks). --export([make/1, do_make/1, do_make/2, do_make/3]). +-export([make/0, make/1]). -include_lib("kernel/include/file.hrl"). -define(JAVASCRIPT_NAME, "erlresolvelinks.js"). -make([RootDir]) -> - do_make(RootDir); +make() -> + case os:getenv("ERL_TOP") of + false -> + io:format("Variable ERL_TOP is required\n",[]); + Value -> + make_from_src(Value, ".") + end. + make([RootDir, DestDir]) -> do_make(RootDir, DestDir); -make([RootDir, DestDir, Name]) -> - do_make(RootDir, DestDir, Name). - -do_make(RootDir) -> +make(RootDir) when is_atom(RootDir) -> DestDir = filename:join(RootDir, "doc"), do_make(RootDir, DestDir). -do_make(RootDir, DestDir) -> - do_make(RootDir, DestDir, ?JAVASCRIPT_NAME). +do_make(_RootDir, _DestDir) -> + ok. -do_make(RootDir, DestDir, Name) -> +make_from_src(RootDir, DestDir) -> %% doc/Dir %% erts-Vsn %% lib/App-Vsn - DocDirs0 = get_dirs(filename:join([RootDir, "doc"])), - DocDirs = lists:map(fun(Dir) -> + Name = ?JAVASCRIPT_NAME, + DocDirs0 = get_dirs(filename:join([RootDir, "system/doc"])), + DocDirs = lists:map(fun({Dir, _DirPath}) -> D = filename:join(["doc", Dir]), {D, D} end, DocDirs0), @@ -68,7 +86,10 @@ do_make(RootDir, DestDir, Name) -> io:fwrite(Fd, "}\n", []), file:close(Fd), ok. - + + + + get_dirs(Dir) -> {ok, Files} = file:list_dir(Dir), AFiles = @@ -79,7 +100,7 @@ is_dir({File, AFile}) -> {ok, FileInfo} = file:read_file_info(AFile), case FileInfo#file_info.type of directory -> - {true, File}; + {true, {File, AFile}}; _ -> false end. @@ -88,47 +109,66 @@ latest_app_dirs(RootDir, Dir) -> ADir = filename:join(RootDir, Dir), RDirs0 = get_dirs(ADir), RDirs1 = lists:filter(fun is_app_dir/1, RDirs0), - %% Build a list of {{App, VsnNumList}, AppVsn} + SDirs0 = - lists:map(fun(AppVsn) -> - [App, VsnStr] = string:tokens(AppVsn, "-"), - VsnNumList = vsnstr_to_numlist(VsnStr), - {{App, VsnNumList}, AppVsn} end, + lists:map(fun({App, Dir1}) -> + File = filename:join(Dir1, "vsn.mk"), + case file:read_file(File) of + {ok, Bin} -> + case re:run(Bin, ".*VSN\s*=\s*([0-9\.]+).*",[{capture,[1],list}]) of + {match, [VsnStr]} -> + VsnNumList = vsnstr_to_numlist(VsnStr), + {{App, VsnNumList}, App++"-"++VsnStr}; + nomatch -> + io:format("No VSN variable found in ~s\n", [File]), + error + end; + {error, Reason} -> + io:format("~p : ~s\n", [Reason, File]), + error + end + end, RDirs1), - SDirs1 = lists:keysort(1, SDirs0), - App2Dirs = lists:foldr(fun({{App, _VsnNumList}, AppVsn}, Acc) -> - case lists:keymember(App, 1, Acc) of - true -> - Acc; - false -> - [{App, AppVsn}| Acc] - end - end, [], SDirs1), + SDirs1 = lists:keysort(1, SDirs0), + App2Dirs = lists:foldr(fun({{App, _VsnNumList}, AppVsn}, Acc) -> + case lists:keymember(App, 1, Acc) of + true -> + Acc; + false -> + [{App, AppVsn}| Acc] + end + end, [], SDirs1), lists:map(fun({App, AppVsn}) -> {App, filename:join([Dir, AppVsn])} end, - App2Dirs). - -is_app_dir(Dir) -> - case string:tokens(Dir, "-") of - [_Name, Rest] -> - is_vsnstr(Rest); - _ -> + App2Dirs). + +is_app_dir({_Dir, DirPath}) -> + case file:read_file_info(filename:join(DirPath, "vsn.mk")) of + {ok, FileInfo} -> + case FileInfo#file_info.type of + regular -> + true; + _ -> + false + end; + {error, _Reason} -> false end. -is_vsnstr(Str) -> - case string:tokens(Str, ".") of - [_] -> - false; - Toks -> - lists:all(fun is_numstr/1, Toks) - end. -is_numstr(Cs) -> - lists:all(fun(C) when $0 =< C, C =< $9 -> - true; - (_) -> - false - end, Cs). +%% is_vsnstr(Str) -> +%% case string:tokens(Str, ".") of +%% [_] -> +%% false; +%% Toks -> +%% lists:all(fun is_numstr/1, Toks) +%% end. + +%% is_numstr(Cs) -> +%% lists:all(fun(C) when $0 =< C, C =< $9 -> +%% true; +%% (_) -> +%% false +%% end, Cs). %% We know: diff --git a/system/doc/top/src/otp_man_index.erl b/system/doc/top/src/otp_man_index.erl new file mode 100644 index 0000000000..78ecd8b954 --- /dev/null +++ b/system/doc/top/src/otp_man_index.erl @@ -0,0 +1,197 @@ +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2010. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%%----------------------------------------------------------------- +%% File: otp_man_index.erl +%% +%% Description: +%% This file generates the module overview in the documentation. +%% +%%----------------------------------------------------------------- + +-module(otp_man_index). + +-export([gen/1]). +-include_lib("kernel/include/file.hrl"). + + +gen([RootDir, OutFile]) when is_atom(RootDir), is_atom(OutFile)-> + Bases = [{"../lib/", filename:join(RootDir, "lib")}, + {"../", RootDir}], + Apps = find_application_paths(Bases), + RefPages = find_ref_files(Apps), + gen_html(RefPages, atom_to_list(OutFile)). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Find Reference files +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +find_ref_files(Apps) -> + find_ref_files(Apps, []). + +find_ref_files([], Acc) -> + Acc; +find_ref_files([{App, Vsn, AppPath, RelPath} |Apps], Acc) -> + case filelib:wildcard(filename:join(AppPath, "*.html")) of + [] -> + find_ref_files(Apps, Acc); + Result -> + + Refs1 = lists:filter(fun(Ref) -> + case file:read_file(Ref) of + {ok, Bin} -> + case re:run(Bin, ".*<!-- refpage -->.*",[]) of + {match, _} -> + true; + nomatch -> + false + end; + {error, Reason} -> + exit(io_lib:format("~p : ~s\n", [Reason, Ref])) + end + end, + Result), + + Refs2 = lists:map(fun(Ref) -> + Module = filename:basename(Ref, ".html"), + {string:to_lower(Module), + Module, + App ++ "-" ++ Vsn, + RelPath, + filename:join(RelPath, filename:basename(Ref))} + end, + Refs1), + find_ref_files(Apps, Refs2 ++ Acc) + end. + +find_application_paths([]) -> + []; +find_application_paths([{URL, Dir} | Paths]) -> + Sub1 = "doc/html", + + AppDirs = get_app_dirs(Dir), + + AppPaths = + lists:map( + fun({App, AppPath}) -> + VsnFile = filename:join(AppPath, "vsn.mk"), + VsnStr = + case file:read_file(VsnFile) of + {ok, Bin} -> + case re:run(Bin, ".*VSN\s*=\s*([0-9\.]+).*",[{capture,[1],list}]) of + {match, [V]} -> + V; + nomatch -> + exit(io_lib:format("No VSN variable found in ~s\n", + [VsnFile])) + end; + {error, Reason} -> + exit(io_lib:format("~p : ~s\n", [Reason, VsnFile])) + end, + AppURL = URL ++ App ++ "-" ++ VsnStr, + {App, VsnStr, AppPath ++ "/" ++ Sub1, AppURL ++ "/" ++ Sub1} + end, AppDirs), + AppPaths ++ find_application_paths(Paths). + + +get_app_dirs(Dir) -> + {ok, Files} = file:list_dir(Dir), + AFiles = + lists:map(fun(File) -> {File, filename:join([Dir, File])} end, Files), + lists:zf(fun is_app_with_doc/1, AFiles). + +is_app_with_doc({ADir, APath}) -> + case file:read_file_info(filename:join([APath, "info"])) of + {ok, _FileInfo} -> + {true, {ADir, APath}}; + _ -> + false + end. + + + + +gen_html(RefPages, OutFile)-> + case file:open(OutFile, [write]) of + {ok, Out} -> + io:fwrite(Out, "~s\n", [html_header()]), + + SortedPages = lists:sort(RefPages), + + lists:foreach(fun({_,Module, App, AppDocDir, RefPagePath}) -> + io:fwrite(Out, " <TR>\n",[]), + io:fwrite(Out, " <TD><A HREF=\"~s\">~s</A></TD>\n", + [RefPagePath, Module]), + io:fwrite(Out, " <TD><A HREF=\"~s\">~s</A></TD>\n", + [filename:join(AppDocDir, "index.html"), + App]), + io:fwrite(Out, " </TR>\n",[]) + end, + SortedPages), + + {Year, _, _} = date(), + io:fwrite(Out, "~s\n", [html_footer(integer_to_list(Year))]); + {error, Reason} -> + exit("~p: ~s\n",[Reason, OutFile]) + end. + + + +html_header() -> + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" + "<!-- This file was generated by the otp_man_index -->\n" + "<HTML>\n" + "<HEAD>\n" + " <link rel=\"stylesheet\" href=\"otp_doc.css\" type=\"text/css\"/>\n" + " <TITLE>Erlang/OTP Manual Page Index</TITLE>\n" + "</HEAD>\n" + "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#0000FF\" VLINK=\"#FF00FF\" ALINK=\"#FF0000\">\n" + "<CENTER>\n" + "<!-- A HREF=\"http://www.erlang.org/\">\n" + "<img alt=\"Erlang logo\" src=\"erlang-logo.png\"/>\n" + "</A><BR -->\n" + "<SMALL>\n" + "[<A HREF=\"index.html\">Up</A> | <A HREF=\"http://www.erlang.org/\">Erlang</A>]\n" + "</SMALL><BR>\n" + "<P/><FONT SIZE=\"+4\">OTP Reference Page Index</FONT><BR>\n" + "</CENTER>\n" + "<CENTER>\n" + "<P/>\n" + "<TABLE BORDER=1>\n" + "<TR>\n" + " <TH>Manual Page</TH><TH>Application</TH>\n" + "</TR>\n". + + + +html_footer(Year) -> + "</TABLE>\n" + "</CENTER>\n" + "<P/>\n" + "<CENTER>\n" + "<HR/>\n" + "<SMALL>\n" + "Copyright © 1991-" ++ Year ++ "\n" + "<a href=\"http://www.ericsson.com/technology/opensource/erlang/\">\n" + "Ericsson AB</a>\n" + "</SMALL>\n" + "</CENTER>\n" + "</BODY>\n" + "</HTML>\n". diff --git a/system/doc/top/templates/applications.html.src b/system/doc/top/templates/applications.html.src index 0251d39b28..285bbced71 100644 --- a/system/doc/top/templates/applications.html.src +++ b/system/doc/top/templates/applications.html.src @@ -1,7 +1,26 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<!-- +%CopyrightBegin% + +Copyright Ericsson AB 2009-2010. All Rights Reserved. + +The contents of this file are subject to the Erlang Public License, +Version 1.1, (the "License"); you may not use this file except in +compliance with the License. You should have received a copy of the +Erlang Public License along with this software. If not, it can be +retrieved online at http://www.erlang.org/. + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +the License for the specific language governing rights and limitations +under the License. + +%CopyrightEnd% +--> + <html> <head> - <title>Erlang/OTP #version#</title> + <title>Erlang/OTP #version# Applications</title> <style type="text/css"> <!-- BODY { background: white } diff --git a/system/doc/top/templates/index.html.src b/system/doc/top/templates/index.html.src index 257a656316..88d425ac1d 100644 --- a/system/doc/top/templates/index.html.src +++ b/system/doc/top/templates/index.html.src @@ -39,8 +39,8 @@ under the License. <small><a href="applications.html">Applications</a><br> <a href="man_index.html">Modules</a></small> <p/> -<small><a href="highlights.html">Release highlights</a><br> -<a href="incompatible.html">Potential incompatibilities</a><br> +<small><a href="highlights.html">Release highlights</a><br/> +<a href="incompatible.html">Potential incompatibilities</a><br/> </small> <br> <a href="javascript:openAllFlips()">Expand All</a><br> @@ -48,7 +48,7 @@ under the License. <p/> <ul class="flipMenu"> -<li>Erlang/OTP System Documentation +<li>System Documentation <ul> <li><a href="installation_guide/users_guide.html">Installation Guide</a></li> <li><a href="system_principles/users_guide.html">System Principles</a></li> @@ -62,7 +62,11 @@ under the License. <li><a href="oam/users_guide.html">OAM Principles</a></li> </ul> </li> +</ul> +<b>Application Groups</b> +<br/> +<ul class="flipMenu"> #applinks# </ul> diff --git a/xcomp/README b/xcomp/README deleted file mode 100644 index f4285cd16f..0000000000 --- a/xcomp/README +++ /dev/null @@ -1,449 +0,0 @@ -=============================================================================== - Cross Compiling Erlang/OTP -=============================================================================== - -%CopyrightBegin% - -Copyright Ericsson AB 2009-2010. All Rights Reserved. - -The contents of this file are subject to the Erlang Public License, -Version 1.1, (the "License"); you may not use this file except in -compliance with the License. You should have received a copy of the -Erlang Public License along with this software. If not, it can be -retrieved online at http://www.erlang.org/. - -Software distributed under the License is distributed on an "AS IS" -basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -the License for the specific language governing rights and limitations -under the License. - -%CopyrightEnd% - -=============================================================================== - -This document describes how to cross compile Erlang/OTP. Note that the support -for cross compiling Erlang/OTP is in its early stage of development, and -should be considered as experimental. You are encouraged to read the whole -document before attempting to cross compile Erlang/OTP. - -Building Erlang/OTP can be done either by using the `$ERL_TOP/otp_build' -script, or by invoking `configure' and `make' directly. The -`erl-xcomp.conf.template' file contains all available configuration variables -and can be used as a template when creating a configuration. See -`erl-xcomp-TileraMDE2.0-tilepro.conf` and `erl-xcomp-x86_64-saf-linux-gnu.conf' -for examples of working configurations. - -The configuration files can be passed to `$ERL_TOP/otp_build configure' using -the `--xcomp-conf' command line argument. Note that `configure' doesn't accept -this command line argument. When using the `configure' script directly, pass -the configuration variables as arguments to `configure' (or exported in the -environment). If the default behavior of a variable is satisfactory, the -variable doesn't need to be set. However, the `configure' script will issue a -warning when a default value is used. When a variable has been set, no warning -will be issued. - -All Erlang/OTP applications except the `wx' application can be cross compiled. -The build of the `wx' driver will currently be automatically disabled when -cross compiling. - -Note, that `$ERL_TOP/otp_build configure' will produce a default configuration -that differs from what `$ERL_TOP/configure' will produce by default. For -example, currently `--disable-dynamic-ssl-lib' is added to the -`$ERL_TOP/configure' command line arguments unless `--enable-dynamic-ssl-lib' -has been explicitly passed. The defaults used by `$ERL_TOP/otp_build configure' -may change at any time without prior notice. - -The build system, including cross compilation configuration variables used, -may be subject to non backward compatible changes without prior notice. -Current cross build system has been tested when cross compiling some Linux/GNU -systems, but has only been partly tested for more esoteric platforms. The -VxWorks example file is highly dependent on our environment and is here more -or less only for internal use. - -Please submit any patches for cross compiling in a way consistent with this -system. All input is welcome as we have a very limited set of cross compiling -environments to test with. If a new configuration variable is needed, add it -to `$ERL_TOP/xcomp/erl-xcomp.conf.template', and use it in `configure.in'. -Other files that might need to be updated are: -- `$ERL_TOP/xcomp/erl-xcomp-vars.sh' -- `$ERL_TOP/erl-build-tool-vars.sh' -- `$ERL_TOP/erts/aclocal.m4' -- `$ERL_TOP/xcomp/README' -- `$ERL_TOP/xcomp/erl-xcomp-*.conf' -Note that this might be an incomplete list of files that need to be updated. - -General information on how to submit patches can be found at: - http://wiki.github.com/erlang/otp/submitting-patches - -======= Build and Install ===================================================== - - [1] - -Change directory into the top directory of the Erlang/OTP source tree. - - $ cd $ERL_TOP - -------- Build ----------------------------------------------------------------- - -In order to compile Erlang code, a small Erlang bootstrap system has to be -built, or an Erlang/OTP system of the same release as the one being built -has to be provided in the `$PATH'. The Erlang/OTP for the target system will -be built using this Erlang system, together with the cross compilation tools -provided. - -If you want to build using a compatible Erlang/OTP system in the `$PATH', -jump to [3]. - --- Building a bootstrap system -- - - [2] - - $ ./configure --enable-bootstrap-only - $ make - -The `--enable-bootstrap-only' argument to `configure' isn't strictly necessary, -but will speed things up. It will only run `configure' in applications -necessary for the bootstrap, and will disable a lot of things not needed by -the bootstrap system. If you run `configure' without `--enable-boostrap-only' -you also have to run make as `make bootstrap'; otherwise, the whole system will -be built. - --- Cross building the system -- - - [3] - - $ ./configure --build=<BUILD> --host=<HOST> [Other Configure Args] - $ make - -<BUILD> should equal the CPU-VENDOR-OS triplet of the system that you build -on. If you execute `$ERL_TOP/erts/autoconf/config.guess', it will in most -cases print the triplet you want to use for this. - -<HOST> is the system that you build for. It does not have to be a full -CPU-VENDOR-OS triplet, but can be. The full CPU-VENDOR-OS triplet will be -created by executing `$ERL_TOP/erts/autoconf/config.sub <HOST>'. If -`config.sub' fails, you need to be more specific. - -Pass the cross compilation variables as command line arguments to `configure' -using a `<VAR>=<VALUE>' syntax (or export them in the environment). Note that -you can *not* pass a configuration file using `--xcomp-conf=<FILE>' when you -invoke `configure' directly. The `--xcomp-conf=<FILE>' argument can only -be passed to `$ERL_TOP/otp_build configure'. - -`make' will verify that the Erlang/OTP system used when building is of the -same release as the system being built, and will fail if this is not the case. -It is possible, however not recommended, to force the cross compilation even -though the wrong Erlang/OTP system is used. This by invoking `make' like this: -`make ERL_XCOMP_FORCE_DIFFERENT_OTP=yes'. Note that this build might fail, -silently produce suboptimal code, or silently produce erroneous code. - --- Installing -- - -You can either install using the installation paths determined by `configure' -[4], or install manually using [5]. - - [4] - - $ make install DESTDIR=<TEMPORARY_PREFIX> - -`make install' will install at a location specified when doing `configure'. -`configure' arguments specifying where the installation should reside are for -example: `--prefix', `--exec-prefix', `--libdir', `--bindir', etc. By default -it will install under `/usr/local'. You typically do not want to install your -cross build under `/usr/local' on your build machine. Using `DESTDIR' will -cause the installation paths to be prefixed by `$DESTDIR'. This makes it -possible to install and package the installation on the build machine without -having to place the installation in the same directory on the build machine as -it should be executed from on the target machine. - -When `make install' has finished, change directory into `$DESTDIR', package -the system, move it to the target machine, and unpack it. Note that the -installation will only be working on the target machine at the location -determined by `configure'. - -Installing manually: - - [5] - - $ make release RELEASE_ROOT=<RELEASE_DIR> - -`make release' will copy what you have built for the target machine to -`<RELEASE_DIR>'. The `Install' script will not be run. The content of -`<RELEASE_DIR>' is what by default ends up in `/usr/local/lib/erlang'. - -The `Install' script used when installing Erlang/OTP requires common Unix -tools such as `sed' to be present in your `$PATH'. If your target system -does not have such tools, you need to run the `Install' script on your -build machine before packaging Erlang/OTP. The `Install' script should -currently be invoked as follows in the directory where it resides -(the top directory): - `./Install [-cross] [-minimal|-sasl] <ERL_ROOT>' - where: - -minimal - Creates an installation that starts up a minimal amount - of applications, i.e., only `kernel' and `stdlib' are - started. The minimal system is normally enough. - -sasl - Creates an installation that also starts up the `sasl' - application. - -cross - For cross compilation. Informs the install script that it - is run on the build machine. - <ERL_ROOT> - The absolute path to the Erlang installation to use at run - time. This is often the same as the current working - directory, but does not have to be. It can follow any other - path through the file system to the same directory. -If neither `-minimal', nor `-sasl' is passed as argument you will be -prompted. - -You can now either: - - [6] - -* Decide where the installation should be located on the target machine, run - the `Install' script on the build machine, and package the installed - installation. The installation just need to be unpacked at the right - location on the target machine: - - $ cd <RELEASE_DIR> - $ ./Install -cross [-minimal|-sasl] <ABSOLUTE_INSTALL_DIR_ON_TARGET> - - [7] - -* Package the installation in <RELEASE_DIR>, place it wherever you want on - your target machine, and run the `Install' script on your target machine: - - $ cd <ABSOLUTE_INSTALL_DIR_ON_TARGET> - $ ./Install [-minimal|-sasl] <ABSOLUTE_INSTALL_DIR_ON_TARGET> - --- Building with the `otp_build' script -- - - [8] - - $ cd $ERL_TOP - - [9] - - $ ./otp_build configure [--build=<BUILD>] [--host=<HOST>] \ - [--with-xcomp-conf=<FILE>] [Other Configure Args] - -If you have your cross compilation configuration in a file, pass it using the -`--xcomp-conf=<FILE>' command line argument. If not, pass the configuration -variables on the command line using a `<VAR>=<VALUE>' syntax (or in the -environment). - -`--build=<BUILD>', and `--host=<HOST>' are the same as described at [3]. -The `--xcomp-conf=<FILE>' argument causes `otp_build' to read the cross -compilation configuration from `<FILE>'. All of these arguments are in this -case optional, but `<BUILD>', and `<HOST>' must be given either by passing -`--build=<BUILD>' and `--host=<HOST>' on the command line, or by setting -`erl_xcomp_build=<HOST>', and `erl_xcomp_host=<HOST>' in `<FILE>' and -passing the `--xcomp-conf=<FILE>' argument. - -`otp_build configure' will configure both for the boostrap system on the -build machine and the cross host system. - - [10] - - $ ./otp_build boot -a - -`otp_build boot -a' will first build a bootstrap system for the build machine -and then do the cross build of the system. - - [11] - - $ ./otp_build release -a <RELEASE_DIR> - -`otp_build release -a' will do the same as [5], and you will after this have -to do a manual install either by doing [6], or [7]. - -======== Currently used configuration variables =============================== - -Note that you cannot define arbitrary variables in a cross compilation -configuration file. Only the ones listed below will be guaranteed to be -visible throughout the whole execution of all `configure' scripts. Other -variables needs to be defined as arguments to `configure' or exported in -the environment. - --------- `otp_build' only variables ------------------------------------------- - -Variables in this section are only used, when configuring Erlang/OTP for -cross compilation using `$ERL_TOP/otp_build configure'. - -NOTE! These variables currently have *no* effect if you configure using the -`configure' script directly. - -* erl_xcomp_build - Build system. - This value will be passed as `--build=$erl_xcomp_build' argument to the - `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, - but can be. The full CPU-VENDOR-OS triplet will be created by: - `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build' - If `erl_xcomp_build=guess', the build system will be guessed using: - `$ERL_TOP/erts/autoconf/config.guess'. - -* erl_xcomp_host - Cross host system. - This value will be passed as `--host=$erl_xcomp_host' argument to the - `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, - but can be. The full CPU-VENDOR-OS triplet will be created by: - `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host' - -* erl_xcomp_configure_flags - Extra configure flags. - Extra flags to pass to the `configure' script. - --------- Cross compiler and other tools to use -------------------------------- - -If the cross compilation tools are prefixed by `<HOST>-' you probably do -not need to set these variables (where `<HOST>' is what has been passed as -`--host=<HOST>' argument to `configure'). - -* CC - C compiler. - -* CFLAGS - C compiler flags. - -* STATIC_CFLAGS - Static C compiler flags. - -* CFLAG_RUNTIME_LIBRARY_PATH - C compiler runtime library path flag. - This flag should set a specific runtime library path for the shared - library at link time. Note that this is actually a linker flag, but it - needs to be passed via the compiler. - -* CPP - C pre-processor. - -* CPPFLAGS - C pre-processor flags. - -* CXX - C++ compiler. - -* CXXFLAGS - C++ compiler flags. - -* LD - Linker. - -* LDFLAGS - Linker flags. - -* LIBS - Libraries. - --- Dynamic Erlang Driver linker flags -- - -NOTE! Either set all or non of the DED_LD* variables. - -* DED_LD - Linker. - -* DED_LDFLAGS - Linker flags. - -* DED_LD_FLAG_RUNTIME_LIBRARY_PATH - Linker runtime library path flag. - This flag should set a specific runtime library path for the shared - library at link time. - --- Large file support -- - -NOTE! Either set all or non of the LFS_* variables. - -* LFS_CFLAGS - Large file support C compiler flags. - -* LFS_LDFLAGS - Large file support linker flags. - -* LFS_LIBS - Large file support libraries. - --- Other tools -- - -* RANLIB - `ranlib' archive index tool. - -* AR - `ar' archiving tool. - -* GETCONF - `getconf' system configuration inspection tool. - --------- Cross System Root Locations ------------------------------------------ - -* erl_xcomp_sysroot - Absolute cross system root path. - The absolute path to the system root of the cross compilation - environment. Currently, the `crypto', `odbc', `ssh' and `ssl' - applications need the system root. These applications will be skipped - if the system root has not been set. The system root might be needed - for other things too. If this is the case and the system root has not - been set, `configure' will fail and request you to set it. - -* erl_xcomp_isysroot - Absolute cross include system root path. - The absolute path to the system root for includes of the cross - compilation environment. If not set, this value defaults to - `$erl_xcomp_sysroot', i.e., only set this value if the include system - root path is not the same as the system root path. - --------- Optional feature, or bug tests --------------------------------------- - -These tests cannot (always) be done automatically when cross compiling. You -usually does not need to set these variables. Only set these if you really -know what you are doing. - -Note that some of these values will override results of tests performed -by `configure', and some will not be used until `configure' is sure that -it cannot figure the result out. - -The `configure' script will issue a warning when a default value is used. -When a variable has been set, no warning will be issued. - -* erl_xcomp_bigendian - yes|no - If `yes', the target system must be big endian. If `no', little endian. - This can often be automatically detected, but not always. If not - automatically detected, `configure' will fail unless this variable is - set. No default value is used, i.e., `configure' will try to figure - this out automatically. - -* erl_xcomp_linux_clock_gettime_correction - yes|no (defaults to `yes' on - Linux; otherwise, `no') - If `yes', `clock_gettime(CLOCK_MONOTONIC, _)' on the target system must - work. This variable is recommended to be set to `no' on Linux systems - with kernel versions less than 2.6. - -* erl_xcomp_linux_nptl - yes|no (defaults to `yes' on Linux; otherwise, `no') - If `yes', the target system must have NPTL (Native POSIX Thread Library). - Older Linux systems have LinuxThreads instead of NPTL (Linux kernel - versions typically less than 2.6). - -* erl_xcomp_linux_usable_sigusrx - yes|no (defaults to `yes') - If `yes', the `SIGUSR1' and `SIGUSR2' signals must be usable by the ERTS. - Old LinuxThreads thread libraries (Linux kernel versions less than 2.2) - used these signals and made them unusable by the ERTS. - -* erl_xcomp_linux_usable_sigaltstack - yes|no (defaults to `yes' on Linux; - otherwise, `no') - If `yes', `sigaltstack()' must be usable on the target system. - `sigaltstack()' on Linux kernel versions less than 2.4 are broken. - -* erl_xcomp_poll - yes|no (defaults to `no' on Darwin/MacOSX; otherwise, `yes') - If `yes', the target system must have a working `poll()' implementation - that also can handle devices. If `no', `select()' will be used instead of - `poll()'. - -* erl_xcomp_kqueue - yes|no (defaults to `no') - If `yes', the target system must have a working `kqueue()' implementation - that returns a file descriptor which can be used by `poll()' and/or - `select()'. If `no' and the target system has not got `epoll()' or - `/dev/poll', the kernel-poll feature will be disabled. - -* erl_xcomp_putenv_copy - yes|no (defaults to `no') - If `yes', the target system must have a `putenv()' implementation that - stores a copy of the key/value pair. - -* erl_xcomp_reliable_fpe - yes|no (defaults to `no') - If `yes', the target system must have reliable floating point exceptions. - -* erl_xcomp_getaddrinfo - yes|no (defaults to `no') - If `yes', the target system must have a working `getaddrinfo()' - implementation that can handle both IPv4 and IPv6. - -* erl_xcomp_gethrvtime_procfs_ioctl - yes|no (defaults to `no') - If `yes', the target system must have a working `gethrvtime()' - implementation and is used with procfs `ioctl()'. - -* erl_xcomp_clock_gettime_cpu_time - yes|no (defaults to `no') - If `yes', the target system must have a working `clock_gettime()' - implementation that can be used for retrieving process CPU time. - -* erl_xcomp_after_morecore_hook - yes|no (defaults to `no') - If `yes', the target system must have a working `__after_morecore_hook' - that can be used for tracking used `malloc()' implementations core memory - usage. - -* erl_xcomp_dlsym_brk_wrappers - yes|no (defaults to `no') - If `yes', the target system must have a working `dlsym(RTLD_NEXT, <S>)' - implementation that can be used on `brk' and `sbrk' symbols used by the - `malloc()' implementation in use, and by this track the `malloc()' - implementations core memory usage. - -=============================================================================== diff --git a/xcomp/README.md b/xcomp/README.md new file mode 100644 index 0000000000..e97b26e605 --- /dev/null +++ b/xcomp/README.md @@ -0,0 +1,485 @@ +Cross Compiling Erlang/OTP +========================== + +This document describes how to cross compile Erlang/OTP. Note that the support +for cross compiling Erlang/OTP is in its early stage of development, and +should be considered as experimental. You are encouraged to read the whole +document before attempting to cross compile Erlang/OTP. + +Building Erlang/OTP can be done either by using the `$ERL_TOP/otp_build` +script, or by invoking `$ERL_TOP/configure` and `make` directly (where +`$ERL_TOP` is the top directory in the source tree). Building using `otp_build` +is easier since it involves fewer steps, but the `otp_build` build procedure +is not as flexible as the `configure`/`make` build procedure. The binary +releases that we deliver are built using `otp_build`. Also note that +`otp_build configure` will produce a default configuration that differs from +what `configure` will produce by default. For example, currently +`--disable-dynamic-ssl-lib` is added to the `configure` command line arguments +unless `--enable-dynamic-ssl-lib` has been explicitly passed. The defaults +used by `otp_build configure` may change at any time without prior notice. + +The `$ERL_TOP/xcomp/erl-xcomp.conf.template` file contains all available cross +configuration variables and can be used as a template when creating a cross +compilation configuration. For examples of working cross configurations see +the `$ERL_TOP/xcomp/erl-xcomp-TileraMDE2.0-tilepro.conf` file and the +`$ERL_TOP/xcomp/erl-xcomp-x86_64-saf-linux-gnu.conf` file. If the default +behavior of a variable is satisfactory, the variable does not need to be set. +However, the `configure` script will issue a warning when a default value is +used. When a variable has been set, no warning will be issued. + +A cross configuration file can be passed to `otp_build configure` using the +`--xcomp-conf` command line argument. Note that `configure` does not accept +this command line argument. When using the `configure` script directly, pass +the configuration variables as arguments to `configure` using a +`<VARIABLE>=<VALUE>` syntax. Variables can also be passed as environment +variables to `configure`. However, if you pass the configuration in the +environment, make sure to unset all of these environment variables before +invoking `make`; otherwise, the environment variables might set make variables +in some applications, or parts of some applications, and you may end up with +an erroneously configured build. + +All Erlang/OTP applications except the `wx` application can be cross compiled. +The build of the `wx` driver will currently be automatically disabled when +cross compiling. + +The build system, including cross compilation configuration variables used, +may be subject to non backward compatible changes without prior notice. +Current cross build system has been tested when cross compiling some Linux/GNU +systems, but has only been partly tested for more esoteric platforms. The +VxWorks example file is highly dependent on our environment and is here more +or less only for internal use. + +Please submit any patches for cross compiling in a way consistent with this +system. All input is welcome as we have a very limited set of cross compiling +environments to test with. If a new configuration variable is needed, add it +to `$ERL_TOP/xcomp/erl-xcomp.conf.template`, and use it in `configure.in`. +Other files that might need to be updated are: + +- `$ERL_TOP/xcomp/erl-xcomp-vars.sh` +- `$ERL_TOP/erl-build-tool-vars.sh` +- `$ERL_TOP/erts/aclocal.m4` +- `$ERL_TOP/xcomp/README` +- `$ERL_TOP/xcomp/erl-xcomp-*.conf` + +Note that this might be an incomplete list of files that need to be updated. + +General information on how to submit patches can be found at: + <http://wiki.github.com/erlang/otp/submitting-patches> + +If you are building in a `git` working directory, the `configure` scripts need +to be generated before you can start building. This is done by invoking +`./otp_build autoconf` in the `$ERL_TOP` directory. The `configure` scripts +also have to be regenerated when a `configure.in` or `aclocal.m4` file is +modified. Note that this is *not* needed when building an unmodified version +of the released source. + +Build and Install +----------------- + + [1] + +Change directory into the top directory of the Erlang/OTP source tree. + + $ cd $ERL_TOP + +### Build ### + +In order to compile Erlang code, a small Erlang bootstrap system has to be +built, or an Erlang/OTP system of the same release as the one being built +has to be provided in the `$PATH`. The Erlang/OTP for the target system will +be built using this Erlang system, together with the cross compilation tools +provided. + +If you want to build using a compatible Erlang/OTP system in the `$PATH`, +jump to [3]. + +#### Building a Bootstrap System #### + + [2] + + $ ./configure --enable-bootstrap-only + $ make + +The `--enable-bootstrap-only` argument to `configure` isn't strictly necessary, +but will speed things up. It will only run `configure` in applications +necessary for the bootstrap, and will disable a lot of things not needed by +the bootstrap system. If you run `configure` without `--enable-boostrap-only` +you also have to run make as `make bootstrap`; otherwise, the whole system will +be built. + +#### Cross Building the System #### + + [3] + + $ ./configure --host=<HOST> --build=<BUILD> [Other Config Args] + $ make + +`<HOST>` is the host/target system that you build for. It does not have to be +a full `CPU-VENDOR-OS` triplet, but can be. The full `CPU-VENDOR-OS` triplet +will be created by executing `$ERL_TOP/erts/autoconf/config.sub <HOST>`. If +`config.sub` fails, you need to be more specific. + +`<BUILD>` should equal the `CPU-VENDOR-OS` triplet of the system that you +build on. If you execute `$ERL_TOP/erts/autoconf/config.guess`, it will in +most cases print the triplet you want to use for this. + +Pass the cross compilation variables as command line arguments to `configure` +using a `<VARIABLE>=<VALUE>` syntax. Note that you can *not* pass a +configuration file using `--xcomp-conf=<FILE>` when you invoke `configure` +directly. The `--xcomp-conf=<FILE>` argument can only be passed to +`otp_build configure`. + +`make` will verify that the Erlang/OTP system used when building is of the +same release as the system being built, and will fail if this is not the case. +It is possible, however not recommended, to force the cross compilation even +though the wrong Erlang/OTP system is used. This by invoking `make` like this: +`make ERL_XCOMP_FORCE_DIFFERENT_OTP=yes`. Note that this build might fail, +silently produce suboptimal code, or silently produce erroneous code. + +#### Installing #### + +You can either install using the installation paths determined by `configure` +[4], or install manually using [5]. + + [4] + + $ make install DESTDIR=<TEMPORARY_PREFIX> + +`make install` will install at a location specified when doing `configure`. +`configure` arguments specifying where the installation should reside are for +example: `--prefix`, `--exec-prefix`, `--libdir`, `--bindir`, etc. By default +it will install under `/usr/local`. You typically do not want to install your +cross build under `/usr/local` on your build machine. Using `DESTDIR` will +cause the installation paths to be prefixed by `$DESTDIR`. This makes it +possible to install and package the installation on the build machine without +having to place the installation in the same directory on the build machine as +it should be executed from on the target machine. + +When `make install` has finished, change directory into `$DESTDIR`, package +the system, move it to the target machine, and unpack it. Note that the +installation will only be working on the target machine at the location +determined by `configure`. + +Installing manually: + + [5] + + $ make release RELEASE_ROOT=<RELEASE_DIR> + +`make release` will copy what you have built for the target machine to +`<RELEASE_DIR>`. The `Install` script will not be run. The content of +`<RELEASE_DIR>` is what by default ends up in `/usr/local/lib/erlang`. + +The `Install` script used when installing Erlang/OTP requires common Unix +tools such as `sed` to be present in your `$PATH`. If your target system +does not have such tools, you need to run the `Install` script on your +build machine before packaging Erlang/OTP. The `Install` script should +currently be invoked as follows in the directory where it resides +(the top directory): + + $ ./Install [-cross] [-minimal|-sasl] <ERL_ROOT> + +where: + + * `-minimal` - Creates an installation that starts up a minimal + amount of applications, i.e., only `kernel` and + `stdlib` are started. The minimal system is normally + enough, and is what `make install` uses. + * `-sasl` - Creates an installation that also starts up the + `sasl` application. + * `-cross` - For cross compilation. Informs the install script + that it is run on the build machine. + * `<ERL_ROOT>` - The absolute path to the Erlang installation to use + at run time. This is often the same as the current + working directory, but does not have to be. It can + follow any other path through the file system to the + same directory. + +If neither `-minimal`, nor `-sasl` is passed as argument you will be +prompted. + +You can now either do [6] or [7]: + + [6] + +Decide where the installation should be located on the target machine, run +the `Install` script on the build machine, and package the installed +installation. The installation just need to be unpacked at the right location +on the target machine: + + $ cd <RELEASE_DIR> + $ ./Install -cross [-minimal|-sasl] <ABSOLUTE_INSTALL_DIR_ON_TARGET> + + [7] + +Package the installation in <RELEASE_DIR>, place it wherever you want on your +target machine, and run the `Install` script on your target machine: + + $ cd <ABSOLUTE_INSTALL_DIR_ON_TARGET> + $ ./Install [-minimal|-sasl] <ABSOLUTE_INSTALL_DIR_ON_TARGET> + +#### Building With the `otp_build` Script #### + + [8] + + $ cd $ERL_TOP + + [9] + + $ ./otp_build configure --xcomp-conf=<FILE> [Other Config Args] + +alternatively: + + $ ./otp_build configure --host=<HOST> --build=<BUILD> [Other Config Args] + +If you have your cross compilation configuration in a file, pass it using the +`--xcomp-conf=<FILE>` command line argument. If not, pass `--host=<HOST>`, +`--build=<BUILD>`, and the configuration variables using a `<VARIABLE>=<VALUE>` +syntax on the command line (same as in [3]). Note that `<HOST>` and `<BUILD>` +have to be passed one way or the other; either by using `erl_xcomp_host=<HOST>` +and `erl_xcomp_build=<BUILD>` in the configuration file, or by using the +`--host=<HOST>`, and `--build=<BUILD>` command line arguments. + +`otp_build configure` will configure both for the boostrap system on the +build machine and the cross host system. + + [10] + + $ ./otp_build boot -a + +`otp_build boot -a` will first build a bootstrap system for the build machine +and then do the cross build of the system. + + [11] + + $ ./otp_build release -a <RELEASE_DIR> + +`otp_build release -a` will do the same as [5], and you will after this have +to do a manual install either by doing [6], or [7]. + +Currently Used Configuration Variables +-------------------------------------- + +Note that you cannot define arbitrary variables in a cross compilation +configuration file. Only the ones listed below will be guaranteed to be +visible throughout the whole execution of all `configure` scripts. Other +variables needs to be defined as arguments to `configure` or exported in +the environment. + +### Variables for `otp_build` Only ### + +Variables in this section are only used, when configuring Erlang/OTP for +cross compilation using `$ERL_TOP/otp_build configure`. + +*NOTE*! These variables currently have *no* effect if you configure using +the `configure` script directly. + +* `erl_xcomp_build` - The build system used. This value will be passed as + `--build=$erl_xcomp_build` argument to the `configure` script. It does + not have to be a full `CPU-VENDOR-OS` triplet, but can be. The full + `CPU-VENDOR-OS` triplet will be created by + `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build`. + If set to `guess`, the build system will be guessed using + `$ERL_TOP/erts/autoconf/config.guess`. + +* `erl_xcomp_host` - Cross host/target system to build for. This value will + be passed as `--host=$erl_xcomp_host` argument to the `configure` script. + It does not have to be a full `CPU-VENDOR-OS` triplet, but can be. The + full `CPU-VENDOR-OS` triplet will be created by: + `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host` + +* `erl_xcomp_configure_flags` - Extra configure flags to pass to the + `configure` script. + +### Cross Compiler and Other Tools ### + +If the cross compilation tools are prefixed by `<HOST>-` you probably do +not need to set these variables (where `<HOST>` is what has been passed as +`--host=<HOST>` argument to `configure`). + +All variables in this section can also be used when native compiling. + +* `CC` - C compiler. + +* `CFLAGS` - C compiler flags. + +* `STATIC_CFLAGS` - Static C compiler flags. + +* `CFLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library + search path for the shared libraries. Note that this actually is a + linker flag, but it needs to be passed via the compiler. + +* `CPP` - C pre-processor. + +* `CPPFLAGS` - C pre-processor flags. + +* `CXX` - C++ compiler. + +* `CXXFLAGS` - C++ compiler flags. + +* `LD` - Linker. + +* `LDFLAGS` - Linker flags. + +* `LIBS` - Libraries. + +#### *D*ynamic *E*rlang *D*river Linking #### + +*NOTE*! Either set all or none of the `DED_LD*` variables. + +* `DED_LD` - Linker for Dynamically loaded Erlang Drivers. + +* `DED_LDFLAGS` - Linker flags to use with `DED_LD`. + +* `DED_LD_FLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library + search path for shared libraries when linking with `DED_LD`. + +#### Large File Support #### + +*NOTE*! Either set all or none of the `LFS_*` variables. + +* `LFS_CFLAGS` - Large file support C compiler flags. + +* `LFS_LDFLAGS` - Large file support linker flags. + +* `LFS_LIBS` - Large file support libraries. + +#### Other Tools #### + +* `RANLIB` - `ranlib` archive index tool. + +* `AR` - `ar` archiving tool. + +* `GETCONF` - `getconf` system configuration inspection tool. `getconf` is + currently used for finding out large file support flags to use, and + on Linux systems for finding out if we have an NPTL thread library or + not. + +### Cross System Root Locations ### + +* `erl_xcomp_sysroot` - The absolute path to the system root of the cross + compilation environment. Currently, the `crypto`, `odbc`, `ssh` and + `ssl` applications need the system root. These applications will be + skipped if the system root has not been set. The system root might be + needed for other things too. If this is the case and the system root + has not been set, `configure` will fail and request you to set it. + +* `erl_xcomp_isysroot` - The absolute path to the system root for includes + of the cross compilation environment. If not set, this value defaults + to `$erl_xcomp_sysroot`, i.e., only set this value if the include system + root path is not the same as the system root path. + +### Optional Feature, and Bug Tests ### + +These tests cannot (always) be done automatically when cross compiling. You +usually do not need to set these variables. Only set these if you really +know what you are doing. + +Note that some of these values will override results of tests performed +by `configure`, and some will not be used until `configure` is sure that +it cannot figure the result out. + +The `configure` script will issue a warning when a default value is used. +When a variable has been set, no warning will be issued. + +* `erl_xcomp_after_morecore_hook` - `yes|no`. Defaults to `no`. If `yes`, the + target system must have a working `__after_morecore_hook` that can be + used for tracking used `malloc()` implementations core memory usage. + This is currently only used by unsupported features. + +* `erl_xcomp_bigendian` - `yes|no`. No default. If `yes`, the target system + must be big endian. If `no`, little endian. This can often be + automatically detected, but not always. If not automatically detected, + `configure` will fail unless this variable is set. Since no default + value is used, `configure` will try to figure this out automatically. + +* `erl_xcomp_clock_gettime_cpu_time` - `yes|no`. Defaults to `no`. If `yes`, + the target system must have a working `clock_gettime()` implementation + that can be used for retrieving process CPU time. + +* `erl_xcomp_getaddrinfo` - `yes|no`. Defaults to `no`. If `yes`, the target + system must have a working `getaddrinfo()` implementation that can + handle both IPv4 and IPv6. + +* `erl_xcomp_gethrvtime_procfs_ioctl` - `yes|no`. Defaults to `no`. If `yes`, + the target system must have a working `gethrvtime()` implementation and + is used with procfs `ioctl()`. + +* `erl_xcomp_dlsym_brk_wrappers` - `yes|no`. Defaults to `no`. If `yes`, the + target system must have a working `dlsym(RTLD_NEXT, <S>)` implementation + that can be used on `brk` and `sbrk` symbols used by the `malloc()` + implementation in use, and by this track the `malloc()` implementations + core memory usage. This is currently only used by unsupported features. + +* `erl_xcomp_kqueue` - `yes|no`. Defaults to `no`. If `yes`, the target system + must have a working `kqueue()` implementation that returns a file + descriptor which can be used by `poll()` and/or `select()`. If `no` and + the target system has not got `epoll()` or `/dev/poll`, the kernel-poll + feature will be disabled. + +* `erl_xcomp_linux_clock_gettime_correction` - `yes|no`. Defaults to `yes` on + Linux; otherwise, `no`. If `yes`, `clock_gettime(CLOCK_MONOTONIC, _)` on + the target system must work. This variable is recommended to be set to + `no` on Linux systems with kernel versions less than 2.6. + +* `erl_xcomp_linux_nptl` - `yes|no`. Defaults to `yes` on Linux; otherwise, + `no`. If `yes`, the target system must have NPTL (Native POSIX Thread + Library). Older Linux systems have LinuxThreads instead of NPTL (Linux + kernel versions typically less than 2.6). + +* `erl_xcomp_linux_usable_sigaltstack` - `yes|no`. Defaults to `yes` on Linux; + otherwise, `no`. If `yes`, `sigaltstack()` must be usable on the target + system. `sigaltstack()` on Linux kernel versions less than 2.4 are + broken. + +* `erl_xcomp_linux_usable_sigusrx` - `yes|no`. Defaults to `yes`. If `yes`, + the `SIGUSR1` and `SIGUSR2` signals must be usable by the ERTS. Old + LinuxThreads thread libraries (Linux kernel versions typically less than + 2.2) used these signals and made them unusable by the ERTS. + +* `erl_xcomp_poll` - `yes|no`. Defaults to `no` on Darwin/MacOSX; otherwise, + `yes`. If `yes`, the target system must have a working `poll()` + implementation that also can handle devices. If `no`, `select()` will be + used instead of `poll()`. + +* `erl_xcomp_putenv_copy` - `yes|no`. Defaults to `no`. If `yes`, the target + system must have a `putenv()` implementation that stores a copy of the + key/value pair. + +* `erl_xcomp_reliable_fpe` - `yes|no`. Defaults to `no`. If `yes`, the target + system must have reliable floating point exceptions. + +Copyright and License +--------------------- + +> %CopyrightBegin% +> +> Copyright Ericsson AB 2009-2010. All Rights Reserved. +> +> The contents of this file are subject to the Erlang Public License, +> Version 1.1, (the "License"); you may not use this file except in +> compliance with the License. You should have received a copy of the +> Erlang Public License along with this software. If not, it can be +> retrieved online at http://www.erlang.org/. +> +> Software distributed under the License is distributed on an "AS IS" +> basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +> the License for the specific language governing rights and limitations +> under the License. +> +> %CopyrightEnd% + + +<!-- + +Modifying This Document +----------------------- + +This document has been written using Markdown notation. This makes it possible +to easily generate a nice looking HTML version of this file. When modifying +this file, make sure that the modifications are made using valid Markdown +notation. For more information on Markdown see: + <http://daringfireball.net/projects/markdown/>. + +--> + diff --git a/xcomp/erl-xcomp-TileraMDE2.0-tilepro.conf b/xcomp/erl-xcomp-TileraMDE2.0-tilepro.conf index 5ceb4ec145..9379739744 100644 --- a/xcomp/erl-xcomp-TileraMDE2.0-tilepro.conf +++ b/xcomp/erl-xcomp-TileraMDE2.0-tilepro.conf @@ -21,239 +21,238 @@ #### Author: Rickard Green #### #### -------------------------------------------------------------------------- -#### When cross compiling Erlang/OTP using `otp_build', copy this file and set +#### When cross compiling Erlang/OTP using `otp_build`, copy this file and set #### the variables needed below. Then pass the path to the copy of this file as -#### an argument to `otp_build' in the configure stage: -#### `otp_build configure --xcomp-conf=<FILE>' +#### an argument to `otp_build` in the configure stage: +#### `otp_build configure --xcomp-conf=<FILE>` #### -------------------------------------------------------------------------- ### Note that you cannot define arbitrary variables in a cross compilation ### configuration file. Only the ones listed below will be guaranteed to be -### visible throughout the whole execution of all `configure' scripts. Other -### variables needs to be defined as arguments to `configure' or exported in +### visible throughout the whole execution of all `configure` scripts. Other +### variables needs to be defined as arguments to `configure` or exported in ### the environment. -### ---- `otp_build' only variables ------------------------------------------- +### ### Variables for `otp_build` Only ### ### Variables in this section are only used, when configuring Erlang/OTP for -### cross compilation using `$ERL_TOP/otp_build configure'. - -### NOTE! These variables currently have *no* effect if you configure using the -### `configure' script directly. - -## erl_xcomp_build - Build system. -## This value will be passed as `--build=$erl_xcomp_build' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build' -## If `erl_xcomp_build=guess', the build system will be guessed using: -## `$ERL_TOP/erts/autoconf/config.guess'. +### cross compilation using `$ERL_TOP/otp_build configure`. + +### *NOTE*! These variables currently have *no* effect if you configure using +### the `configure` script directly. + +## `erl_xcomp_build` - The build system used. This value will be passed as +## `--build=$erl_xcomp_build` argument to the `configure` script. It does +## not have to be a full `CPU-VENDOR-OS` triplet, but can be. The full +## `CPU-VENDOR-OS` triplet will be created by +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build`. +## If set to `guess`, the build system will be guessed using +## `$ERL_TOP/erts/autoconf/config.guess`. erl_xcomp_build=guess -## erl_xcomp_host - Cross host system. -## This value will be passed as `--host=$erl_xcomp_host' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host' +## `erl_xcomp_host` - Cross host/target system to build for. This value will +## be passed as `--host=$erl_xcomp_host` argument to the `configure` script. +## It does not have to be a full `CPU-VENDOR-OS` triplet, but can be. The +## full `CPU-VENDOR-OS` triplet will be created by: +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host` erl_xcomp_host=tile -## erl_xcomp_configure_flags - Extra configure flags. -## Extra flags to pass to the `configure' script. +## `erl_xcomp_configure_flags` - Extra configure flags to pass to the +## `configure` script. erl_xcomp_configure_flags="--without-termcap" -### ---- Cross compiler and other tools to use -------------------------------- +### ### Cross Compiler and Other Tools ### -### If the cross compilation tools are prefixed by `<HOST>-' you probably do -### not need to set these variables (where `<HOST>' is what has been passed as -### `--host=<HOST>' argument to `configure'). +### If the cross compilation tools are prefixed by `<HOST>-` you probably do +### not need to set these variables (where `<HOST>` is what has been passed as +### `--host=<HOST>` argument to `configure`). -## CC - C compiler. +### All variables in this section can also be used when native compiling. + +## `CC` - C compiler. #CC= -## CFLAGS - C compiler flags. +## `CFLAGS` - C compiler flags. #CFLAGS= -## STATIC_CFLAGS - Static C compiler flags. +## `STATIC_CFLAGS` - Static C compiler flags. #STATIC_CFLAGS= -## CFLAG_RUNTIME_LIBRARY_PATH - C compiler runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. Note that this is actually a linker flag, but it -## needs to be passed via the compiler. +## `CFLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for the shared libraries. Note that this actually is a +## linker flag, but it needs to be passed via the compiler. #CFLAG_RUNTIME_LIBRARY_PATH= -## CPP - C pre-processor. +## `CPP` - C pre-processor. #CPP= -## CPPFLAGS - C pre-processor flags. +## `CPPFLAGS` - C pre-processor flags. #CPPFLAGS= -## CXX - C++ compiler. +## `CXX` - C++ compiler. #CXX= -## CXXFLAGS - C++ compiler flags. +## `CXXFLAGS` - C++ compiler flags. #CXXFLAGS= -## LD - Linker. +## `LD` - Linker. #LD= -## LDFLAGS - Linker flags. +## `LDFLAGS` - Linker flags. #LDFLAGS= -## LIBS - Libraries. +## `LIBS` - Libraries. #LIBS= -### -- Dynamic Erlang Driver linker flags -- +### #### *D*ynamic *E*rlang *D*river Linking #### -### NOTE! Either set all or non of the DED_LD* variables. +### *NOTE*! Either set all or none of the `DED_LD*` variables. -## DED_LD - Linker. +## `DED_LD` - Linker for Dynamically loaded Erlang Drivers. #DED_LD= -## DED_LDFLAGS - Linker flags. +## `DED_LDFLAGS` - Linker flags to use with `DED_LD`. #DED_LDFLAGS= -## DED_LD_FLAG_RUNTIME_LIBRARY_PATH - Linker runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. +## `DED_LD_FLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for shared libraries when linking with `DED_LD`. #DED_LD_FLAG_RUNTIME_LIBRARY_PATH= -### -- Large file support -- +### #### Large File Support #### -### NOTE! Either set all or non of the LFS_* variables. +### *NOTE*! Either set all or none of the `LFS_*` variables. -## LFS_CFLAGS - Large file support C compiler flags. +## `LFS_CFLAGS` - Large file support C compiler flags. #LFS_CFLAGS= -## LFS_LDFLAGS - Large file support linker flags. +## `LFS_LDFLAGS` - Large file support linker flags. #LFS_LDFLAGS= -## LFS_LIBS - Large file support libraries. +## `LFS_LIBS` - Large file support libraries. #LFS_LIBS= -### -- Other tools -- +### #### Other Tools #### -## RANLIB - `ranlib' archive index tool. +## `RANLIB` - `ranlib` archive index tool. #RANLIB= -## AR - `ar' archiving tool. +## `AR` - `ar` archiving tool. #AR= -## GETCONF - `getconf' system configuration inspection tool. +## `GETCONF` - `getconf` system configuration inspection tool. `getconf` is +## currently used for finding out large file support flags to use, and +## on Linux systems for finding out if we have an NPTL thread library or +## not. #GETCONF= -### ---- Cross System Root Locations ------------------------------------------ +### ### Cross System Root Locations ### -## erl_xcomp_sysroot - Absolute cross system root path. -## The absolute path to the system root of the cross compilation -## environment. Currently, the `crypto', `odbc', `ssh' and `ssl' -## applications need the system root. These applications will be skipped -## if the system root has not been set. The system root might be needed -## for other things too. If this is the case and the system root has not -## been set, `configure' will fail and request you to set it. +## `erl_xcomp_sysroot` - The absolute path to the system root of the cross +## compilation environment. Currently, the `crypto`, `odbc`, `ssh` and +## `ssl` applications need the system root. These applications will be +## skipped if the system root has not been set. The system root might be +## needed for other things too. If this is the case and the system root +## has not been set, `configure` will fail and request you to set it. erl_xcomp_sysroot="$TILERA_ROOT/tile" -## erl_xcomp_isysroot - Absolute cross include system root path. -## The absolute path to the system root for includes of the cross -## compilation environment. If not set, this value defaults to -## `$erl_xcomp_sysroot', i.e., only set this value if the include system +## `erl_xcomp_isysroot` - The absolute path to the system root for includes +## of the cross compilation environment. If not set, this value defaults +## to `$erl_xcomp_sysroot`, i.e., only set this value if the include system ## root path is not the same as the system root path. #erl_xcomp_isysroot= -### ---- Optional feature, or bug tests --------------------------------------- +### ### Optional Feature, and Bug Tests ### ### These tests cannot (always) be done automatically when cross compiling. You -### usually does not need to set these variables. Only set these if you really +### usually do not need to set these variables. Only set these if you really ### know what you are doing. ### Note that some of these values will override results of tests performed -### by `configure', and some will not be used until `configure' is sure that +### by `configure`, and some will not be used until `configure` is sure that ### it cannot figure the result out. -### The `configure' script will issue a warning when a default value is used. +### The `configure` script will issue a warning when a default value is used. ### When a variable has been set, no warning will be issued. -## erl_xcomp_bigendian - yes|no -## If `yes', the target system must be big endian. If `no', little endian. -## This can often be automatically detected, but not always. If not -## automatically detected, `configure' will fail unless this variable is -## set. No default value is used, i.e., `configure' will try to figure -## this out automatically. -#erl_xcomp_bigendian= +## `erl_xcomp_after_morecore_hook` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `__after_morecore_hook` that can be +## used for tracking used `malloc()` implementations core memory usage. +## This is currently only used by unsupported features. +#erl_xcomp_after_morecore_hook= -## erl_xcomp_linux_clock_gettime_correction - yes|no (defaults to `yes' on -## Linux; otherwise, `no') -## If `yes', `clock_gettime(CLOCK_MONOTONIC, _)' on the target system must -## work. This variable is recommended to be set to `no' on Linux systems -## with kernel versions less than 2.6. -#erl_xcomp_linux_clock_gettime_correction= +## `erl_xcomp_bigendian` - `yes|no`. No default. If `yes`, the target system +## must be big endian. If `no`, little endian. This can often be +## automatically detected, but not always. If not automatically detected, +## `configure` will fail unless this variable is set. Since no default +## value is used, `configure` will try to figure this out automatically. +#erl_xcomp_bigendian= -## erl_xcomp_linux_nptl - yes|no (defaults to `yes' on Linux; otherwise, `no') -## If `yes', the target system must have NPTL (Native POSIX Thread Library). -## Older Linux systems have LinuxThreads instead of NPTL (Linux kernel -## versions typically less than 2.6). -#erl_xcomp_linux_nptl= +## `erl_xcomp_clock_gettime_cpu_time` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `clock_gettime()` implementation +## that can be used for retrieving process CPU time. +#erl_xcomp_clock_gettime_cpu_time= -## erl_xcomp_linux_usable_sigusrx - yes|no (defaults to `yes') -## If `yes', the `SIGUSR1' and `SIGUSR2' signals must be usable by the ERTS. -## Old LinuxThreads thread libraries (Linux kernel versions less than 2.2) -## used these signals and made them unusable by the ERTS. -#erl_xcomp_linux_usable_sigusrx= +## `erl_xcomp_getaddrinfo` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a working `getaddrinfo()` implementation that can +## handle both IPv4 and IPv6. +erl_xcomp_getaddrinfo=yes -## erl_xcomp_linux_usable_sigaltstack - yes|no (defaults to `yes' on Linux; -## otherwise, `no') -## If `yes', `sigaltstack()' must be usable on the target system. -## `sigaltstack()' on Linux kernel versions less than 2.4 are broken. -#erl_xcomp_linux_usable_sigaltstack= +## `erl_xcomp_gethrvtime_procfs_ioctl` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `gethrvtime()` implementation and +## is used with procfs `ioctl()`. +#erl_xcomp_gethrvtime_procfs_ioctl= -## erl_xcomp_poll - yes|no (defaults to `no' on Darwin/MacOSX; otherwise, `yes') -## If `yes', the target system must have a working `poll()' implementation -## that also can handle devices. If `no', `select()' will be used instead of -## `poll()'. -#erl_xcomp_poll= +## `erl_xcomp_dlsym_brk_wrappers` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `dlsym(RTLD_NEXT, <S>)` implementation +## that can be used on `brk` and `sbrk` symbols used by the `malloc()` +## implementation in use, and by this track the `malloc()` implementations +## core memory usage. This is currently only used by unsupported features. +#erl_xcomp_dlsym_brk_wrappers= -## erl_xcomp_kqueue - yes|no (defaults to `no') -## If `yes', the target system must have a working `kqueue()' implementation -## that returns a file descriptor which can be used by `poll()' and/or -## `select()'. If `no' and the target system has not got `epoll()' or -## `/dev/poll', the kernel-poll feature will be disabled. +## `erl_xcomp_kqueue` - `yes|no`. Defaults to `no`. If `yes`, the target system +## must have a working `kqueue()` implementation that returns a file +## descriptor which can be used by `poll()` and/or `select()`. If `no` and +## the target system has not got `epoll()` or `/dev/poll`, the kernel-poll +## feature will be disabled. #erl_xcomp_kqueue= -## erl_xcomp_putenv_copy - yes|no (defaults to `no') -## If `yes', the target system must have a `putenv()' implementation that -## stores a copy of the key/value pair. -#erl_xcomp_putenv_copy= +## `erl_xcomp_linux_clock_gettime_correction` - `yes|no`. Defaults to `yes` on +## Linux; otherwise, `no`. If `yes`, `clock_gettime(CLOCK_MONOTONIC, _)` on +## the target system must work. This variable is recommended to be set to +## `no` on Linux systems with kernel versions less than 2.6. +#erl_xcomp_linux_clock_gettime_correction= -## erl_xcomp_reliable_fpe - yes|no (defaults to `no') -## If `yes', the target system must have reliable floating point exceptions. -#erl_xcomp_reliable_fpe= +## `erl_xcomp_linux_nptl` - `yes|no`. Defaults to `yes` on Linux; otherwise, +## `no`. If `yes`, the target system must have NPTL (Native POSIX Thread +## Library). Older Linux systems have LinuxThreads instead of NPTL (Linux +## kernel versions typically less than 2.6). +#erl_xcomp_linux_nptl= -## erl_xcomp_getaddrinfo - yes|no (defaults to `no') -## If `yes', the target system must have a working `getaddrinfo()' -## implementation that can handle both IPv4 and IPv6. -erl_xcomp_getaddrinfo=yes +## `erl_xcomp_linux_usable_sigaltstack` - `yes|no`. Defaults to `yes` on Linux; +## otherwise, `no`. If `yes`, `sigaltstack()` must be usable on the target +## system. `sigaltstack()` on Linux kernel versions less than 2.4 are +## broken. +#erl_xcomp_linux_usable_sigaltstack= -## erl_xcomp_gethrvtime_procfs_ioctl - yes|no (defaults to `no') -## If `yes', the target system must have a working `gethrvtime()' -## implementation and is used with procfs `ioctl()'. -#erl_xcomp_gethrvtime_procfs_ioctl= +## `erl_xcomp_linux_usable_sigusrx` - `yes|no`. Defaults to `yes`. If `yes`, +## the `SIGUSR1` and `SIGUSR2` signals must be usable by the ERTS. Old +## LinuxThreads thread libraries (Linux kernel versions typically less than +## 2.2) used these signals and made them unusable by the ERTS. +#erl_xcomp_linux_usable_sigusrx= -## erl_xcomp_clock_gettime_cpu_time - yes|no (defaults to `no') -## If `yes', the target system must have a working `clock_gettime()' -## implementation that can be used for retrieving process CPU time. -#erl_xcomp_clock_gettime_cpu_time= +## `erl_xcomp_poll` - `yes|no`. Defaults to `no` on Darwin/MacOSX; otherwise, +## `yes`. If `yes`, the target system must have a working `poll()` +## implementation that also can handle devices. If `no`, `select()` will be +## used instead of `poll()`. +#erl_xcomp_poll= -## erl_xcomp_after_morecore_hook - yes|no (defaults to `no') -## If `yes', the target system must have a working `__after_morecore_hook' -## that can be used for tracking used `malloc()' implementations core memory -## usage. -#erl_xcomp_after_morecore_hook= +## `erl_xcomp_putenv_copy` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a `putenv()` implementation that stores a copy of the +## key/value pair. +#erl_xcomp_putenv_copy= -## erl_xcomp_dlsym_brk_wrappers - yes|no (defaults to `no') -## If `yes', the target system must have a working `dlsym(RTLD_NEXT, <S>)' -## implementation that can be used on `brk' and `sbrk' symbols used by the -## `malloc()' implementation in use, and by this track the `malloc()' -## implementations core memory usage. -#erl_xcomp_dlsym_brk_wrappers= +## `erl_xcomp_reliable_fpe` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have reliable floating point exceptions. +#erl_xcomp_reliable_fpe= -#### -------------------------------------------------------------------------- +#### diff --git a/xcomp/erl-xcomp-avr32-atmel-linux-gnu.conf b/xcomp/erl-xcomp-avr32-atmel-linux-gnu.conf new file mode 100644 index 0000000000..11ffce2085 --- /dev/null +++ b/xcomp/erl-xcomp-avr32-atmel-linux-gnu.conf @@ -0,0 +1,262 @@ +#### -*-shell-script-*- +#### +#### %CopyrightBegin% +#### +#### Copyright Ericsson AB 2010. All Rights Reserved. +#### +#### The contents of this file are subject to the Erlang Public License, +#### Version 1.1, (the "License"); you may not use this file except in +#### compliance with the License. You should have received a copy of the +#### Erlang Public License along with this software. If not, it can be +#### retrieved online at http://www.erlang.org/. +#### +#### Software distributed under the License is distributed on an "AS IS" +#### basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +#### the License for the specific language governing rights and limitations +#### under the License. +#### +#### %CopyrightEnd% +#### +#### File: erl-xcomp-avr32-atmel-linux-gnu.conf +#### Author: Winston Smith <[email protected]> +#### +#### -------------------------------------------------------------------------- +#### When cross compiling Erlang/OTP using `otp_build', copy this file and set +#### the variables needed below. Then pass the path to the copy of this file as +#### an argument to `otp_build' in the configure stage: +#### `otp_build configure --xcomp-conf=<FILE>' +#### -------------------------------------------------------------------------- + +### Note that you cannot define arbitrary variables in a cross compilation +### configuration file. Only the ones listed below will be guaranteed to be +### visible throughout the whole execution of all `configure' scripts. Other +### variables needs to be defined as arguments to `configure' or exported in +### the environment. + +### ---- `otp_build' only variables ------------------------------------------- + +### Variables in this section are only used, when configuring Erlang/OTP for +### cross compilation using `$ERL_TOP/otp_build configure'. + +### NOTE! These variables currently have *no* effect if you configure using the +### `configure' script directly. + +## erl_xcomp_build - Build system. +## This value will be passed as `--build=$erl_xcomp_build' argument to the +## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, +## but can be. The full CPU-VENDOR-OS triplet will be created by: +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build' +## If `erl_xcomp_build=guess', the build system will be guessed using: +## `$ERL_TOP/erts/autoconf/config.guess'. +erl_xcomp_build=guess + +## erl_xcomp_host - Cross host system. +## This value will be passed as `--host=$erl_xcomp_host' argument to the +## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, +## but can be. The full CPU-VENDOR-OS triplet will be created by: +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host' +erl_xcomp_host=avr32-atmel-linux-gnu + +## erl_xcomp_configure_flags - Extra configure flags. +## Extra flags to pass to the `configure' script. +#erl_xcomp_configure_flags= + +### ---- Cross compiler and other tools to use -------------------------------- + +### If the cross compilation tools are prefixed by `<HOST>-' you probably do +### not need to set these variables (where `<HOST>' is what has been passed as +### `--host=<HOST>' argument to `configure'). + +## CC - C compiler. +CC=avr32-linux-gcc + +## CFLAGS - C compiler flags. +#CFLAGS= + +## STATIC_CFLAGS - Static C compiler flags. +#STATIC_CFLAGS= + +## CFLAG_RUNTIME_LIBRARY_PATH - C compiler runtime library path flag. +## This flag should set a specific runtime library path for the shared +## library at link time. Note that this is actually a linker flag, but it +## needs to be passed via the compiler. +#CFLAG_RUNTIME_LIBRARY_PATH= + +## CPP - C pre-processor. +#CPP= + +## CPPFLAGS - C pre-processor flags. +#CPPFLAGS= + +## CXX - C++ compiler. +CXX=avr32-linux-g++ + +## CXXFLAGS - C++ compiler flags. +#CXXFLAGS= + +## LD - Linker. +LD=avr32-linux-ld + +## LDFLAGS - Linker flags. +#LDFLAGS= + +## LIBS - Libraries. +#LIBS= + +### -- Dynamic Erlang Driver linker flags -- + +### NOTE! Either set all or non of the DED_LD* variables. + +## DED_LD - Linker. +#DED_LD= + +## DED_LDFLAGS - Linker flags. +#DED_LDFLAGS= + +## DED_LD_FLAG_RUNTIME_LIBRARY_PATH - Linker runtime library path flag. +## This flag should set a specific runtime library path for the shared +## library at link time. +#DED_LD_FLAG_RUNTIME_LIBRARY_PATH= + +### -- Large file support -- + +### NOTE! Either set all or non of the LFS_* variables. + +## LFS_CFLAGS - Large file support C compiler flags. +#LFS_CFLAGS= + +## LFS_LDFLAGS - Large file support linker flags. +#LFS_LDFLAGS= + +## LFS_LIBS - Large file support libraries. +#LFS_LIBS= + +### -- Other tools -- + +## RANLIB - `ranlib' archive index tool. +RANLIB=avr32-linux-ranlib + +## AR - `ar' archiving tool. +AR=avr32-linux-ar + +## GETCONF - `getconf' system configuration inspection tool. +#GETCONF= + +### ---- Cross System Root Locations ------------------------------------------ + +## erl_xcomp_sysroot - Absolute cross system root path. +## The absolute path to the system root of the cross compilation +## environment. Currently, the `crypto', `odbc', `ssh' and `ssl' +## applications need the system root. These applications will be skipped +## if the system root has not been set. The system root might be needed +## for other things too. If this is the case and the system root has not +## been set, `configure' will fail and request you to set it. +## +## NOTE: For AVR32, this should be set to the build_avr32/staging_dir +## subdirectory within the buildroot tree. +erl_xcomp_sysroot="$ATMEL_SYSROOT_AVR32" + +## erl_xcomp_isysroot - Absolute cross include system root path. +## The absolute path to the system root for includes of the cross +## compilation environment. If not set, this value defaults to +## `$erl_xcomp_sysroot', i.e., only set this value if the include system +## root path is not the same as the system root path. +#erl_xcomp_isysroot= + +### ---- Optional feature, or bug tests --------------------------------------- + +### These tests cannot (always) be done automatically when cross compiling. You +### usually does not need to set these variables. Only set these if you really +### know what you are doing. + +### Note that some of these values will override results of tests performed +### by `configure', and some will not be used until `configure' is sure that +### it cannot figure the result out. + +### The `configure' script will issue a warning when a default value is used. +### When a variable has been set, no warning will be issued. + +## erl_xcomp_bigendian - yes|no +## If `yes', the target system must be big endian. If `no', little endian. +## This can often be automatically detected, but not always. If not +## automatically detected, `configure' will fail unless this variable is +## set. No default value is used, i.e., `configure' will try to figure +## this out automatically. +#erl_xcomp_bigendian= + +## erl_xcomp_linux_clock_gettime_correction - yes|no (defaults to `yes' on +## Linux; otherwise, `no') +## If `yes', `clock_gettime(CLOCK_MONOTONIC, _)' on the target system must +## work. This variable is recommended to be set to `no' on Linux systems +## with kernel versions less than 2.6. +#erl_xcomp_linux_clock_gettime_correction= + +## erl_xcomp_linux_nptl - yes|no (defaults to `yes' on Linux; otherwise, `no') +## If `yes', the target system must have NPTL (Native POSIX Thread Library). +## Older Linux systems have LinuxThreads instead of NPTL (Linux kernel +## versions typically less than 2.6). +#erl_xcomp_linux_nptl= + +## erl_xcomp_linux_usable_sigusrx - yes|no (defaults to `yes') +## If `yes', the `SIGUSR1' and `SIGUSR2' signals must be usable by the ERTS. +## Old LinuxThreads thread libraries (Linux kernel versions less than 2.2) +## used these signals and made them unusable by the ERTS. +#erl_xcomp_linux_usable_sigusrx= + +## erl_xcomp_linux_usable_sigaltstack - yes|no (defaults to `yes' on Linux; +## otherwise, `no') +## If `yes', `sigaltstack()' must be usable on the target system. +## `sigaltstack()' on Linux kernel versions less than 2.4 are broken. +#erl_xcomp_linux_usable_sigaltstack= + +## erl_xcomp_poll - yes|no (defaults to `no' on Darwin/MacOSX; otherwise, `yes') +## If `yes', the target system must have a working `poll()' implementation +## that also can handle devices. If `no', `select()' will be used instead of +## `poll()'. +#erl_xcomp_poll= + +## erl_xcomp_kqueue - yes|no (defaults to `no') +## If `yes', the target system must have a working `kqueue()' implementation +## that returns a file descriptor which can be used by `poll()' and/or +## `select()'. If `no' and the target system has not got `epoll()' or +## `/dev/poll', the kernel-poll feature will be disabled. +#erl_xcomp_kqueue= + +## erl_xcomp_putenv_copy - yes|no (defaults to `no') +## If `yes', the target system must have a `putenv()' implementation that +## stores a copy of the key/value pair. +#erl_xcomp_putenv_copy= + +## erl_xcomp_reliable_fpe - yes|no (defaults to `no') +## If `yes', the target system must have reliable floating point exceptions. +#erl_xcomp_reliable_fpe= + +## erl_xcomp_getaddrinfo - yes|no (defaults to `no') +## If `yes', the target system must have a working `getaddrinfo()' +## implementation that can handle both IPv4 and IPv6. +erl_xcomp_getaddrinfo=yes + +## erl_xcomp_gethrvtime_procfs_ioctl - yes|no (defaults to `no') +## If `yes', the target system must have a working `gethrvtime()' +## implementation and is used with procfs `ioctl()'. +#erl_xcomp_gethrvtime_procfs_ioctl= + +## erl_xcomp_clock_gettime_cpu_time - yes|no (defaults to `no') +## If `yes', the target system must have a working `clock_gettime()' +## implementation that can be used for retrieving process CPU time. +erl_xcomp_clock_gettime_cpu_time=yes + +## erl_xcomp_after_morecore_hook - yes|no (defaults to `no') +## If `yes', the target system must have a working `__after_morecore_hook' +## that can be used for tracking used `malloc()' implementations core memory +## usage. +#erl_xcomp_after_morecore_hook= + +## erl_xcomp_dlsym_brk_wrappers - yes|no (defaults to `no') +## If `yes', the target system must have a working `dlsym(RTLD_NEXT, <S>)' +## implementation that can be used on `brk' and `sbrk' symbols used by the +## `malloc()' implementation in use, and by this track the `malloc()' +## implementations core memory usage. +erl_xcomp_dlsym_brk_wrappers=yes + +#### -------------------------------------------------------------------------- diff --git a/xcomp/erl-xcomp-vxworks_ppc32.conf b/xcomp/erl-xcomp-vxworks_ppc32.conf index aa7c652d80..b75c7444bb 100644 --- a/xcomp/erl-xcomp-vxworks_ppc32.conf +++ b/xcomp/erl-xcomp-vxworks_ppc32.conf @@ -21,239 +21,238 @@ #### Author: Rickard Green/Patrik Nyblom #### #### -------------------------------------------------------------------------- -#### When cross compiling Erlang/OTP using `otp_build', copy this file and set +#### When cross compiling Erlang/OTP using `otp_build`, copy this file and set #### the variables needed below. Then pass the path to the copy of this file as -#### an argument to `otp_build' in the configure stage: -#### `otp_build configure --xcomp-conf=<FILE>' +#### an argument to `otp_build` in the configure stage: +#### `otp_build configure --xcomp-conf=<FILE>` #### -------------------------------------------------------------------------- ### Note that you cannot define arbitrary variables in a cross compilation ### configuration file. Only the ones listed below will be guaranteed to be -### visible throughout the whole execution of all `configure' scripts. Other -### variables needs to be defined as arguments to `configure' or exported in +### visible throughout the whole execution of all `configure` scripts. Other +### variables needs to be defined as arguments to `configure` or exported in ### the environment. -### ---- `otp_build' only variables ------------------------------------------- +### ### Variables for `otp_build` Only ### ### Variables in this section are only used, when configuring Erlang/OTP for -### cross compilation using `$ERL_TOP/otp_build configure'. - -### NOTE! These variables currently have *no* effect if you configure using the -### `configure' script directly. - -## erl_xcomp_build - Build system. -## This value will be passed as `--build=$erl_xcomp_build' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build' -## If `erl_xcomp_build=guess', the build system will be guessed using: -## `$ERL_TOP/erts/autoconf/config.guess'. +### cross compilation using `$ERL_TOP/otp_build configure`. + +### *NOTE*! These variables currently have *no* effect if you configure using +### the `configure` script directly. + +## `erl_xcomp_build` - The build system used. This value will be passed as +## `--build=$erl_xcomp_build` argument to the `configure` script. It does +## not have to be a full `CPU-VENDOR-OS` triplet, but can be. The full +## `CPU-VENDOR-OS` triplet will be created by +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build`. +## If set to `guess`, the build system will be guessed using +## `$ERL_TOP/erts/autoconf/config.guess`. erl_xcomp_build=guess -## erl_xcomp_host - Cross host system. -## This value will be passed as `--host=$erl_xcomp_host' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host' +## `erl_xcomp_host` - Cross host/target system to build for. This value will +## be passed as `--host=$erl_xcomp_host` argument to the `configure` script. +## It does not have to be a full `CPU-VENDOR-OS` triplet, but can be. The +## full `CPU-VENDOR-OS` triplet will be created by: +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host` erl_xcomp_host=powerpc-wrs-vxworks -## erl_xcomp_configure_flags - Extra configure flags. -## Extra flags to pass to the `configure' script. +## `erl_xcomp_configure_flags` - Extra configure flags to pass to the +## `configure` script. erl_xcomp_configure_flags="--disable-threads --without-termcap" -### ---- Cross compiler and other tools to use -------------------------------- +### ### Cross Compiler and Other Tools ### -### If the cross compilation tools are prefixed by `<HOST>-' you probably do -### not need to set these variables (where `<HOST>' is what has been passed as -### `--host=<HOST>' argument to `configure'). +### If the cross compilation tools are prefixed by `<HOST>-` you probably do +### not need to set these variables (where `<HOST>` is what has been passed as +### `--host=<HOST>` argument to `configure`). -## CC - C compiler. +### All variables in this section can also be used when native compiling. + +## `CC` - C compiler. CC="$WIND_BASE/gnu/3.4.4-vxworks-6.3/$WIND_HOST_TYPE/bin/ccppc" -## CFLAGS - C compiler flags. +## `CFLAGS` - C compiler flags. CFLAGS="-DCPU=PPC32 -DTOOL_FAMILY=gnu -DTOOL=gnu -DWANT_NONBLOCKING -DHAVE_SENS -DHAVE_MEMMOVE -DVXWORKS -I$WIND_BASE/vxworks-6.3/target/h -I$WIND_BASE/gnu/3.4.4-vxworks-6.3/$WIND_HOST_TYPE/lib/gcc/powerpc-wrs-vxworks/3.4.4/include -I$WIND_BASE/vxworks-6.3/target/h/wrn/coreip -I$WIND_BASE/vxworks-6.3/target/h -mstrict-align -fvolatile -fno-builtin -mlongcall" -## STATIC_CFLAGS - Static C compiler flags. +## `STATIC_CFLAGS` - Static C compiler flags. #STATIC_CFLAGS= -## CFLAG_RUNTIME_LIBRARY_PATH - C compiler runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. Note that this is actually a linker flag, but it -## needs to be passed via the compiler. +## `CFLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for the shared libraries. Note that this actually is a +## linker flag, but it needs to be passed via the compiler. #CFLAG_RUNTIME_LIBRARY_PATH= -## CPP - C pre-processor. +## `CPP` - C pre-processor. CPP="$CC $CFLAGS -E" -## CPPFLAGS - C pre-processor flags. +## `CPPFLAGS` - C pre-processor flags. #CPPFLAGS= -## CXX - C++ compiler. +## `CXX` - C++ compiler. #CXX= -## CXXFLAGS - C++ compiler flags. +## `CXXFLAGS` - C++ compiler flags. #CXXFLAGS= -## LD - Linker. +## `LD` - Linker. LD="$WIND_BASE/gnu/3.4.4-vxworks-6.3/$WIND_HOST_TYPE/bin/ldppc" -## LDFLAGS - Linker flags. +## `LDFLAGS` - Linker flags. LDFLAGS="-mlongcall" -## LIBS - Libraries. +## `LIBS` - Libraries. #LIBS= -### -- Dynamic Erlang Driver linker flags -- +### #### *D*ynamic *E*rlang *D*river Linking #### -### NOTE! Either set all or non of the DED_LD* variables. +### *NOTE*! Either set all or none of the `DED_LD*` variables. -## DED_LD - Linker. +## `DED_LD` - Linker for Dynamically loaded Erlang Drivers. #DED_LD= -## DED_LDFLAGS - Linker flags. +## `DED_LDFLAGS` - Linker flags to use with `DED_LD`. #DED_LDFLAGS= -## DED_LD_FLAG_RUNTIME_LIBRARY_PATH - Linker runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. +## `DED_LD_FLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for shared libraries when linking with `DED_LD`. #DED_LD_FLAG_RUNTIME_LIBRARY_PATH= -### -- Large file support -- +### #### Large File Support #### -### NOTE! Either set all or non of the LFS_* variables. +### *NOTE*! Either set all or none of the `LFS_*` variables. -## LFS_CFLAGS - Large file support C compiler flags. +## `LFS_CFLAGS` - Large file support C compiler flags. #LFS_CFLAGS= -## LFS_LDFLAGS - Large file support linker flags. +## `LFS_LDFLAGS` - Large file support linker flags. #LFS_LDFLAGS= -## LFS_LIBS - Large file support libraries. +## `LFS_LIBS` - Large file support libraries. #LFS_LIBS= -### -- Other tools -- +### #### Other Tools #### -## RANLIB - `ranlib' archive index tool. +## `RANLIB` - `ranlib` archive index tool. RANLIB="$WIND_BASE/gnu/3.4.4-vxworks-6.3/$WIND_HOST_TYPE/bin/ranlibppc" -## AR - `ar' archiving tool. +## `AR` - `ar` archiving tool. AR="$WIND_BASE/gnu/3.4.4-vxworks-6.3/$WIND_HOST_TYPE/bin/arppc" -## GETCONF - `getconf' system configuration inspection tool. +## `GETCONF` - `getconf` system configuration inspection tool. `getconf` is +## currently used for finding out large file support flags to use, and +## on Linux systems for finding out if we have an NPTL thread library or +## not. #GETCONF= -### ---- Cross System Root Locations ------------------------------------------ +### ### Cross System Root Locations ### -## erl_xcomp_sysroot - Absolute cross system root path. -## The absolute path to the system root of the cross compilation -## environment. Currently, the `crypto', `odbc', `ssh' and `ssl' -## applications need the system root. These applications will be skipped -## if the system root has not been set. The system root might be needed -## for other things too. If this is the case and the system root has not -## been set, `configure' will fail and request you to set it. +## `erl_xcomp_sysroot` - The absolute path to the system root of the cross +## compilation environment. Currently, the `crypto`, `odbc`, `ssh` and +## `ssl` applications need the system root. These applications will be +## skipped if the system root has not been set. The system root might be +## needed for other things too. If this is the case and the system root +## has not been set, `configure` will fail and request you to set it. #erl_xcomp_sysroot= -## erl_xcomp_isysroot - Absolute cross include system root path. -## The absolute path to the system root for includes of the cross -## compilation environment. If not set, this value defaults to -## `$erl_xcomp_sysroot', i.e., only set this value if the include system +## `erl_xcomp_isysroot` - The absolute path to the system root for includes +## of the cross compilation environment. If not set, this value defaults +## to `$erl_xcomp_sysroot`, i.e., only set this value if the include system ## root path is not the same as the system root path. #erl_xcomp_isysroot= -### ---- Optional feature, or bug tests --------------------------------------- +### ### Optional Feature, and Bug Tests ### ### These tests cannot (always) be done automatically when cross compiling. You -### usually does not need to set these variables. Only set these if you really +### usually do not need to set these variables. Only set these if you really ### know what you are doing. ### Note that some of these values will override results of tests performed -### by `configure', and some will not be used until `configure' is sure that +### by `configure`, and some will not be used until `configure` is sure that ### it cannot figure the result out. -### The `configure' script will issue a warning when a default value is used. +### The `configure` script will issue a warning when a default value is used. ### When a variable has been set, no warning will be issued. -## erl_xcomp_bigendian - yes|no -## If `yes', the target system must be big endian. If `no', little endian. -## This can often be automatically detected, but not always. If not -## automatically detected, `configure' will fail unless this variable is -## set. No default value is used, i.e., `configure' will try to figure -## this out automatically. -erl_xcomp_bigendian=yes +## `erl_xcomp_after_morecore_hook` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `__after_morecore_hook` that can be +## used for tracking used `malloc()` implementations core memory usage. +## This is currently only used by unsupported features. +#erl_xcomp_after_morecore_hook= -## erl_xcomp_linux_clock_gettime_correction - yes|no (defaults to `yes' on -## Linux; otherwise, `no') -## If `yes', `clock_gettime(CLOCK_MONOTONIC, _)' on the target system must -## work. This variable is recommended to be set to `no' on Linux systems -## with kernel versions less than 2.6. -#erl_xcomp_linux_clock_gettime_correction= +## `erl_xcomp_bigendian` - `yes|no`. No default. If `yes`, the target system +## must be big endian. If `no`, little endian. This can often be +## automatically detected, but not always. If not automatically detected, +## `configure` will fail unless this variable is set. Since no default +## value is used, `configure` will try to figure this out automatically. +erl_xcomp_bigendian=yes -## erl_xcomp_linux_nptl - yes|no (defaults to `yes' on Linux; otherwise, `no') -## If `yes', the target system must have NPTL (Native POSIX Thread Library). -## Older Linux systems have LinuxThreads instead of NPTL (Linux kernel -## versions typically less than 2.6). -#erl_xcomp_linux_nptl= +## `erl_xcomp_clock_gettime_cpu_time` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `clock_gettime()` implementation +## that can be used for retrieving process CPU time. +#erl_xcomp_clock_gettime_cpu_time= -## erl_xcomp_linux_usable_sigusrx - yes|no (defaults to `yes') -## If `yes', the `SIGUSR1' and `SIGUSR2' signals must be usable by the ERTS. -## Old LinuxThreads thread libraries (Linux kernel versions less than 2.2) -## used these signals and made them unusable by the ERTS. -#erl_xcomp_linux_usable_sigusrx= +## `erl_xcomp_getaddrinfo` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a working `getaddrinfo()` implementation that can +## handle both IPv4 and IPv6. +#erl_xcomp_getaddrinfo= -## erl_xcomp_linux_usable_sigaltstack - yes|no (defaults to `yes' on Linux; -## otherwise, `no') -## If `yes', `sigaltstack()' must be usable on the target system. -## `sigaltstack()' on Linux kernel versions less than 2.4 are broken. -#erl_xcomp_linux_usable_sigaltstack= +## `erl_xcomp_gethrvtime_procfs_ioctl` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `gethrvtime()` implementation and +## is used with procfs `ioctl()`. +#erl_xcomp_gethrvtime_procfs_ioctl= -## erl_xcomp_poll - yes|no (defaults to `no' on Darwin/MacOSX; otherwise, `yes') -## If `yes', the target system must have a working `poll()' implementation -## that also can handle devices. If `no', `select()' will be used instead of -## `poll()'. -#erl_xcomp_poll= +## `erl_xcomp_dlsym_brk_wrappers` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `dlsym(RTLD_NEXT, <S>)` implementation +## that can be used on `brk` and `sbrk` symbols used by the `malloc()` +## implementation in use, and by this track the `malloc()` implementations +## core memory usage. This is currently only used by unsupported features. +#erl_xcomp_dlsym_brk_wrappers= -## erl_xcomp_kqueue - yes|no (defaults to `no') -## If `yes', the target system must have a working `kqueue()' implementation -## that returns a file descriptor which can be used by `poll()' and/or -## `select()'. If `no' and the target system has not got `epoll()' or -## `/dev/poll', the kernel-poll feature will be disabled. +## `erl_xcomp_kqueue` - `yes|no`. Defaults to `no`. If `yes`, the target system +## must have a working `kqueue()` implementation that returns a file +## descriptor which can be used by `poll()` and/or `select()`. If `no` and +## the target system has not got `epoll()` or `/dev/poll`, the kernel-poll +## feature will be disabled. #erl_xcomp_kqueue= -## erl_xcomp_putenv_copy - yes|no (defaults to `no') -## If `yes', the target system must have a `putenv()' implementation that -## stores a copy of the key/value pair. -#erl_xcomp_putenv_copy= +## `erl_xcomp_linux_clock_gettime_correction` - `yes|no`. Defaults to `yes` on +## Linux; otherwise, `no`. If `yes`, `clock_gettime(CLOCK_MONOTONIC, _)` on +## the target system must work. This variable is recommended to be set to +## `no` on Linux systems with kernel versions less than 2.6. +#erl_xcomp_linux_clock_gettime_correction= -## erl_xcomp_reliable_fpe - yes|no (defaults to `no') -## If `yes', the target system must have reliable floating point exceptions. -#erl_xcomp_reliable_fpe= +## `erl_xcomp_linux_nptl` - `yes|no`. Defaults to `yes` on Linux; otherwise, +## `no`. If `yes`, the target system must have NPTL (Native POSIX Thread +## Library). Older Linux systems have LinuxThreads instead of NPTL (Linux +## kernel versions typically less than 2.6). +#erl_xcomp_linux_nptl= -## erl_xcomp_getaddrinfo - yes|no (defaults to `no') -## If `yes', the target system must have a working `getaddrinfo()' -## implementation that can handle both IPv4 and IPv6. -#erl_xcomp_getaddrinfo= +## `erl_xcomp_linux_usable_sigaltstack` - `yes|no`. Defaults to `yes` on Linux; +## otherwise, `no`. If `yes`, `sigaltstack()` must be usable on the target +## system. `sigaltstack()` on Linux kernel versions less than 2.4 are +## broken. +#erl_xcomp_linux_usable_sigaltstack= -## erl_xcomp_gethrvtime_procfs_ioctl - yes|no (defaults to `no') -## If `yes', the target system must have a working `gethrvtime()' -## implementation and is used with procfs `ioctl()'. -#erl_xcomp_gethrvtime_procfs_ioctl= +## `erl_xcomp_linux_usable_sigusrx` - `yes|no`. Defaults to `yes`. If `yes`, +## the `SIGUSR1` and `SIGUSR2` signals must be usable by the ERTS. Old +## LinuxThreads thread libraries (Linux kernel versions typically less than +## 2.2) used these signals and made them unusable by the ERTS. +#erl_xcomp_linux_usable_sigusrx= -## erl_xcomp_clock_gettime_cpu_time - yes|no (defaults to `no') -## If `yes', the target system must have a working `clock_gettime()' -## implementation that can be used for retrieving process CPU time. -#erl_xcomp_clock_gettime_cpu_time= +## `erl_xcomp_poll` - `yes|no`. Defaults to `no` on Darwin/MacOSX; otherwise, +## `yes`. If `yes`, the target system must have a working `poll()` +## implementation that also can handle devices. If `no`, `select()` will be +## used instead of `poll()`. +#erl_xcomp_poll= -## erl_xcomp_after_morecore_hook - yes|no (defaults to `no') -## If `yes', the target system must have a working `__after_morecore_hook' -## that can be used for tracking used `malloc()' implementations core memory -## usage. -#erl_xcomp_after_morecore_hook= +## `erl_xcomp_putenv_copy` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a `putenv()` implementation that stores a copy of the +## key/value pair. +#erl_xcomp_putenv_copy= -## erl_xcomp_dlsym_brk_wrappers - yes|no (defaults to `no') -## If `yes', the target system must have a working `dlsym(RTLD_NEXT, <S>)' -## implementation that can be used on `brk' and `sbrk' symbols used by the -## `malloc()' implementation in use, and by this track the `malloc()' -## implementations core memory usage. -#erl_xcomp_dlsym_brk_wrappers= +## `erl_xcomp_reliable_fpe` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have reliable floating point exceptions. +#erl_xcomp_reliable_fpe= -#### -------------------------------------------------------------------------- +#### diff --git a/xcomp/erl-xcomp-x86_64-saf-linux-gnu.conf b/xcomp/erl-xcomp-x86_64-saf-linux-gnu.conf index 1d57876172..a0dd7c9115 100644 --- a/xcomp/erl-xcomp-x86_64-saf-linux-gnu.conf +++ b/xcomp/erl-xcomp-x86_64-saf-linux-gnu.conf @@ -21,239 +21,238 @@ #### Author: Rickard Green #### #### -------------------------------------------------------------------------- -#### When cross compiling Erlang/OTP using `otp_build', copy this file and set +#### When cross compiling Erlang/OTP using `otp_build`, copy this file and set #### the variables needed below. Then pass the path to the copy of this file as -#### an argument to `otp_build' in the configure stage: -#### `otp_build configure --xcomp-conf=<FILE>' +#### an argument to `otp_build` in the configure stage: +#### `otp_build configure --xcomp-conf=<FILE>` #### -------------------------------------------------------------------------- ### Note that you cannot define arbitrary variables in a cross compilation ### configuration file. Only the ones listed below will be guaranteed to be -### visible throughout the whole execution of all `configure' scripts. Other -### variables needs to be defined as arguments to `configure' or exported in +### visible throughout the whole execution of all `configure` scripts. Other +### variables needs to be defined as arguments to `configure` or exported in ### the environment. -### ---- `otp_build' only variables ------------------------------------------- +### ### Variables for `otp_build` Only ### ### Variables in this section are only used, when configuring Erlang/OTP for -### cross compilation using `$ERL_TOP/otp_build configure'. - -### NOTE! These variables currently have *no* effect if you configure using the -### `configure' script directly. - -## erl_xcomp_build - Build system. -## This value will be passed as `--build=$erl_xcomp_build' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build' -## If `erl_xcomp_build=guess', the build system will be guessed using: -## `$ERL_TOP/erts/autoconf/config.guess'. +### cross compilation using `$ERL_TOP/otp_build configure`. + +### *NOTE*! These variables currently have *no* effect if you configure using +### the `configure` script directly. + +## `erl_xcomp_build` - The build system used. This value will be passed as +## `--build=$erl_xcomp_build` argument to the `configure` script. It does +## not have to be a full `CPU-VENDOR-OS` triplet, but can be. The full +## `CPU-VENDOR-OS` triplet will be created by +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build`. +## If set to `guess`, the build system will be guessed using +## `$ERL_TOP/erts/autoconf/config.guess`. erl_xcomp_build=guess -## erl_xcomp_host - Cross host system. -## This value will be passed as `--host=$erl_xcomp_host' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host' +## `erl_xcomp_host` - Cross host/target system to build for. This value will +## be passed as `--host=$erl_xcomp_host` argument to the `configure` script. +## It does not have to be a full `CPU-VENDOR-OS` triplet, but can be. The +## full `CPU-VENDOR-OS` triplet will be created by: +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host` erl_xcomp_host=x86_64-saf-linux-gnu -## erl_xcomp_configure_flags - Extra configure flags. -## Extra flags to pass to the `configure' script. +## `erl_xcomp_configure_flags` - Extra configure flags to pass to the +## `configure` script. #erl_xcomp_configure_flags= -### ---- Cross compiler and other tools to use -------------------------------- +### ### Cross Compiler and Other Tools ### -### If the cross compilation tools are prefixed by `<HOST>-' you probably do -### not need to set these variables (where `<HOST>' is what has been passed as -### `--host=<HOST>' argument to `configure'). +### If the cross compilation tools are prefixed by `<HOST>-` you probably do +### not need to set these variables (where `<HOST>` is what has been passed as +### `--host=<HOST>` argument to `configure`). -## CC - C compiler. +### All variables in this section can also be used when native compiling. + +## `CC` - C compiler. CC=x86_64-saf-gcc -## CFLAGS - C compiler flags. +## `CFLAGS` - C compiler flags. #CFLAGS= -## STATIC_CFLAGS - Static C compiler flags. +## `STATIC_CFLAGS` - Static C compiler flags. #STATIC_CFLAGS= -## CFLAG_RUNTIME_LIBRARY_PATH - C compiler runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. Note that this is actually a linker flag, but it -## needs to be passed via the compiler. +## `CFLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for the shared libraries. Note that this actually is a +## linker flag, but it needs to be passed via the compiler. #CFLAG_RUNTIME_LIBRARY_PATH= -## CPP - C pre-processor. +## `CPP` - C pre-processor. #CPP= -## CPPFLAGS - C pre-processor flags. +## `CPPFLAGS` - C pre-processor flags. #CPPFLAGS= -## CXX - C++ compiler. +## `CXX` - C++ compiler. CXX=x86_64-saf-g++ -## CXXFLAGS - C++ compiler flags. +## `CXXFLAGS` - C++ compiler flags. #CXXFLAGS= -## LD - Linker. +## `LD` - Linker. LD=x86_64-saf-ld -## LDFLAGS - Linker flags. +## `LDFLAGS` - Linker flags. #LDFLAGS= -## LIBS - Libraries. +## `LIBS` - Libraries. #LIBS= -### -- Dynamic Erlang Driver linker flags -- +### #### *D*ynamic *E*rlang *D*river Linking #### -### NOTE! Either set all or non of the DED_LD* variables. +### *NOTE*! Either set all or none of the `DED_LD*` variables. -## DED_LD - Linker. +## `DED_LD` - Linker for Dynamically loaded Erlang Drivers. #DED_LD= -## DED_LDFLAGS - Linker flags. +## `DED_LDFLAGS` - Linker flags to use with `DED_LD`. #DED_LDFLAGS= -## DED_LD_FLAG_RUNTIME_LIBRARY_PATH - Linker runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. +## `DED_LD_FLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for shared libraries when linking with `DED_LD`. #DED_LD_FLAG_RUNTIME_LIBRARY_PATH= -### -- Large file support -- +### #### Large File Support #### -### NOTE! Either set all or non of the LFS_* variables. +### *NOTE*! Either set all or none of the `LFS_*` variables. -## LFS_CFLAGS - Large file support C compiler flags. +## `LFS_CFLAGS` - Large file support C compiler flags. #LFS_CFLAGS= -## LFS_LDFLAGS - Large file support linker flags. +## `LFS_LDFLAGS` - Large file support linker flags. #LFS_LDFLAGS= -## LFS_LIBS - Large file support libraries. +## `LFS_LIBS` - Large file support libraries. #LFS_LIBS= -### -- Other tools -- +### #### Other Tools #### -## RANLIB - `ranlib' archive index tool. +## `RANLIB` - `ranlib` archive index tool. RANLIB=x86_64-saf-ranlib -## AR - `ar' archiving tool. +## `AR` - `ar` archiving tool. AR=x86_64-saf-ar -## GETCONF - `getconf' system configuration inspection tool. +## `GETCONF` - `getconf` system configuration inspection tool. `getconf` is +## currently used for finding out large file support flags to use, and +## on Linux systems for finding out if we have an NPTL thread library or +## not. #GETCONF= -### ---- Cross System Root Locations ------------------------------------------ +### ### Cross System Root Locations ### -## erl_xcomp_sysroot - Absolute cross system root path. -## The absolute path to the system root of the cross compilation -## environment. Currently, the `crypto', `odbc', `ssh' and `ssl' -## applications need the system root. These applications will be skipped -## if the system root has not been set. The system root might be needed -## for other things too. If this is the case and the system root has not -## been set, `configure' will fail and request you to set it. +## `erl_xcomp_sysroot` - The absolute path to the system root of the cross +## compilation environment. Currently, the `crypto`, `odbc`, `ssh` and +## `ssl` applications need the system root. These applications will be +## skipped if the system root has not been set. The system root might be +## needed for other things too. If this is the case and the system root +## has not been set, `configure` will fail and request you to set it. erl_xcomp_sysroot="$SAF_SYSROOT_X86_64" -## erl_xcomp_isysroot - Absolute cross include system root path. -## The absolute path to the system root for includes of the cross -## compilation environment. If not set, this value defaults to -## `$erl_xcomp_sysroot', i.e., only set this value if the include system +## `erl_xcomp_isysroot` - The absolute path to the system root for includes +## of the cross compilation environment. If not set, this value defaults +## to `$erl_xcomp_sysroot`, i.e., only set this value if the include system ## root path is not the same as the system root path. #erl_xcomp_isysroot= -### ---- Optional feature, or bug tests --------------------------------------- +### ### Optional Feature, and Bug Tests ### ### These tests cannot (always) be done automatically when cross compiling. You -### usually does not need to set these variables. Only set these if you really +### usually do not need to set these variables. Only set these if you really ### know what you are doing. ### Note that some of these values will override results of tests performed -### by `configure', and some will not be used until `configure' is sure that +### by `configure`, and some will not be used until `configure` is sure that ### it cannot figure the result out. -### The `configure' script will issue a warning when a default value is used. +### The `configure` script will issue a warning when a default value is used. ### When a variable has been set, no warning will be issued. -## erl_xcomp_bigendian - yes|no -## If `yes', the target system must be big endian. If `no', little endian. -## This can often be automatically detected, but not always. If not -## automatically detected, `configure' will fail unless this variable is -## set. No default value is used, i.e., `configure' will try to figure -## this out automatically. -#erl_xcomp_bigendian= +## `erl_xcomp_after_morecore_hook` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `__after_morecore_hook` that can be +## used for tracking used `malloc()` implementations core memory usage. +## This is currently only used by unsupported features. +erl_xcomp_after_morecore_hook=yes -## erl_xcomp_linux_clock_gettime_correction - yes|no (defaults to `yes' on -## Linux; otherwise, `no') -## If `yes', `clock_gettime(CLOCK_MONOTONIC, _)' on the target system must -## work. This variable is recommended to be set to `no' on Linux systems -## with kernel versions less than 2.6. -#erl_xcomp_linux_clock_gettime_correction= +## `erl_xcomp_bigendian` - `yes|no`. No default. If `yes`, the target system +## must be big endian. If `no`, little endian. This can often be +## automatically detected, but not always. If not automatically detected, +## `configure` will fail unless this variable is set. Since no default +## value is used, `configure` will try to figure this out automatically. +#erl_xcomp_bigendian= -## erl_xcomp_linux_nptl - yes|no (defaults to `yes' on Linux; otherwise, `no') -## If `yes', the target system must have NPTL (Native POSIX Thread Library). -## Older Linux systems have LinuxThreads instead of NPTL (Linux kernel -## versions typically less than 2.6). -#erl_xcomp_linux_nptl= +## `erl_xcomp_clock_gettime_cpu_time` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `clock_gettime()` implementation +## that can be used for retrieving process CPU time. +#erl_xcomp_clock_gettime_cpu_time= -## erl_xcomp_linux_usable_sigusrx - yes|no (defaults to `yes') -## If `yes', the `SIGUSR1' and `SIGUSR2' signals must be usable by the ERTS. -## Old LinuxThreads thread libraries (Linux kernel versions less than 2.2) -## used these signals and made them unusable by the ERTS. -#erl_xcomp_linux_usable_sigusrx= +## `erl_xcomp_getaddrinfo` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a working `getaddrinfo()` implementation that can +## handle both IPv4 and IPv6. +erl_xcomp_getaddrinfo=yes -## erl_xcomp_linux_usable_sigaltstack - yes|no (defaults to `yes' on Linux; -## otherwise, `no') -## If `yes', `sigaltstack()' must be usable on the target system. -## `sigaltstack()' on Linux kernel versions less than 2.4 are broken. -#erl_xcomp_linux_usable_sigaltstack= +## `erl_xcomp_gethrvtime_procfs_ioctl` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `gethrvtime()` implementation and +## is used with procfs `ioctl()`. +#erl_xcomp_gethrvtime_procfs_ioctl= -## erl_xcomp_poll - yes|no (defaults to `no' on Darwin/MacOSX; otherwise, `yes') -## If `yes', the target system must have a working `poll()' implementation -## that also can handle devices. If `no', `select()' will be used instead of -## `poll()'. -#erl_xcomp_poll= +## `erl_xcomp_dlsym_brk_wrappers` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `dlsym(RTLD_NEXT, <S>)` implementation +## that can be used on `brk` and `sbrk` symbols used by the `malloc()` +## implementation in use, and by this track the `malloc()` implementations +## core memory usage. This is currently only used by unsupported features. +#erl_xcomp_dlsym_brk_wrappers= -## erl_xcomp_kqueue - yes|no (defaults to `no') -## If `yes', the target system must have a working `kqueue()' implementation -## that returns a file descriptor which can be used by `poll()' and/or -## `select()'. If `no' and the target system has not got `epoll()' or -## `/dev/poll', the kernel-poll feature will be disabled. +## `erl_xcomp_kqueue` - `yes|no`. Defaults to `no`. If `yes`, the target system +## must have a working `kqueue()` implementation that returns a file +## descriptor which can be used by `poll()` and/or `select()`. If `no` and +## the target system has not got `epoll()` or `/dev/poll`, the kernel-poll +## feature will be disabled. #erl_xcomp_kqueue= -## erl_xcomp_putenv_copy - yes|no (defaults to `no') -## If `yes', the target system must have a `putenv()' implementation that -## stores a copy of the key/value pair. -#erl_xcomp_putenv_copy= +## `erl_xcomp_linux_clock_gettime_correction` - `yes|no`. Defaults to `yes` on +## Linux; otherwise, `no`. If `yes`, `clock_gettime(CLOCK_MONOTONIC, _)` on +## the target system must work. This variable is recommended to be set to +## `no` on Linux systems with kernel versions less than 2.6. +#erl_xcomp_linux_clock_gettime_correction= -## erl_xcomp_reliable_fpe - yes|no (defaults to `no') -## If `yes', the target system must have reliable floating point exceptions. -#erl_xcomp_reliable_fpe= +## `erl_xcomp_linux_nptl` - `yes|no`. Defaults to `yes` on Linux; otherwise, +## `no`. If `yes`, the target system must have NPTL (Native POSIX Thread +## Library). Older Linux systems have LinuxThreads instead of NPTL (Linux +## kernel versions typically less than 2.6). +#erl_xcomp_linux_nptl= -## erl_xcomp_getaddrinfo - yes|no (defaults to `no') -## If `yes', the target system must have a working `getaddrinfo()' -## implementation that can handle both IPv4 and IPv6. -erl_xcomp_getaddrinfo=yes +## `erl_xcomp_linux_usable_sigaltstack` - `yes|no`. Defaults to `yes` on Linux; +## otherwise, `no`. If `yes`, `sigaltstack()` must be usable on the target +## system. `sigaltstack()` on Linux kernel versions less than 2.4 are +## broken. +#erl_xcomp_linux_usable_sigaltstack= -## erl_xcomp_gethrvtime_procfs_ioctl - yes|no (defaults to `no') -## If `yes', the target system must have a working `gethrvtime()' -## implementation and is used with procfs `ioctl()'. -#erl_xcomp_gethrvtime_procfs_ioctl= +## `erl_xcomp_linux_usable_sigusrx` - `yes|no`. Defaults to `yes`. If `yes`, +## the `SIGUSR1` and `SIGUSR2` signals must be usable by the ERTS. Old +## LinuxThreads thread libraries (Linux kernel versions typically less than +## 2.2) used these signals and made them unusable by the ERTS. +#erl_xcomp_linux_usable_sigusrx= -## erl_xcomp_clock_gettime_cpu_time - yes|no (defaults to `no') -## If `yes', the target system must have a working `clock_gettime()' -## implementation that can be used for retrieving process CPU time. -#erl_xcomp_clock_gettime_cpu_time= +## `erl_xcomp_poll` - `yes|no`. Defaults to `no` on Darwin/MacOSX; otherwise, +## `yes`. If `yes`, the target system must have a working `poll()` +## implementation that also can handle devices. If `no`, `select()` will be +## used instead of `poll()`. +#erl_xcomp_poll= -## erl_xcomp_after_morecore_hook - yes|no (defaults to `no') -## If `yes', the target system must have a working `__after_morecore_hook' -## that can be used for tracking used `malloc()' implementations core memory -## usage. -erl_xcomp_after_morecore_hook=yes +## `erl_xcomp_putenv_copy` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a `putenv()` implementation that stores a copy of the +## key/value pair. +#erl_xcomp_putenv_copy= -## erl_xcomp_dlsym_brk_wrappers - yes|no (defaults to `no') -## If `yes', the target system must have a working `dlsym(RTLD_NEXT, <S>)' -## implementation that can be used on `brk' and `sbrk' symbols used by the -## `malloc()' implementation in use, and by this track the `malloc()' -## implementations core memory usage. -#erl_xcomp_dlsym_brk_wrappers= +## `erl_xcomp_reliable_fpe` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have reliable floating point exceptions. +#erl_xcomp_reliable_fpe= -#### -------------------------------------------------------------------------- +#### diff --git a/xcomp/erl-xcomp.conf.template b/xcomp/erl-xcomp.conf.template index afbef66af1..090f92c15f 100644 --- a/xcomp/erl-xcomp.conf.template +++ b/xcomp/erl-xcomp.conf.template @@ -21,239 +21,238 @@ #### Author: Rickard Green #### #### -------------------------------------------------------------------------- -#### When cross compiling Erlang/OTP using `otp_build', copy this file and set +#### When cross compiling Erlang/OTP using `otp_build`, copy this file and set #### the variables needed below. Then pass the path to the copy of this file as -#### an argument to `otp_build' in the configure stage: -#### `otp_build configure --xcomp-conf=<FILE>' +#### an argument to `otp_build` in the configure stage: +#### `otp_build configure --xcomp-conf=<FILE>` #### -------------------------------------------------------------------------- ### Note that you cannot define arbitrary variables in a cross compilation ### configuration file. Only the ones listed below will be guaranteed to be -### visible throughout the whole execution of all `configure' scripts. Other -### variables needs to be defined as arguments to `configure' or exported in +### visible throughout the whole execution of all `configure` scripts. Other +### variables needs to be defined as arguments to `configure` or exported in ### the environment. -### ---- `otp_build' only variables ------------------------------------------- +### ### Variables for `otp_build` Only ### ### Variables in this section are only used, when configuring Erlang/OTP for -### cross compilation using `$ERL_TOP/otp_build configure'. - -### NOTE! These variables currently have *no* effect if you configure using the -### `configure' script directly. - -## erl_xcomp_build - Build system. -## This value will be passed as `--build=$erl_xcomp_build' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build' -## If `erl_xcomp_build=guess', the build system will be guessed using: -## `$ERL_TOP/erts/autoconf/config.guess'. +### cross compilation using `$ERL_TOP/otp_build configure`. + +### *NOTE*! These variables currently have *no* effect if you configure using +### the `configure` script directly. + +## `erl_xcomp_build` - The build system used. This value will be passed as +## `--build=$erl_xcomp_build` argument to the `configure` script. It does +## not have to be a full `CPU-VENDOR-OS` triplet, but can be. The full +## `CPU-VENDOR-OS` triplet will be created by +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_build`. +## If set to `guess`, the build system will be guessed using +## `$ERL_TOP/erts/autoconf/config.guess`. #erl_xcomp_build= -## erl_xcomp_host - Cross host system. -## This value will be passed as `--host=$erl_xcomp_host' argument to the -## `configure' script. It does not have to be a full CPU-VENDOR-OS triplet, -## but can be. The full CPU-VENDOR-OS triplet will be created by: -## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host' +## `erl_xcomp_host` - Cross host/target system to build for. This value will +## be passed as `--host=$erl_xcomp_host` argument to the `configure` script. +## It does not have to be a full `CPU-VENDOR-OS` triplet, but can be. The +## full `CPU-VENDOR-OS` triplet will be created by: +## `$ERL_TOP/erts/autoconf/config.sub $erl_xcomp_host` #erl_xcomp_host= -## erl_xcomp_configure_flags - Extra configure flags. -## Extra flags to pass to the `configure' script. +## `erl_xcomp_configure_flags` - Extra configure flags to pass to the +## `configure` script. #erl_xcomp_configure_flags= -### ---- Cross compiler and other tools to use -------------------------------- +### ### Cross Compiler and Other Tools ### -### If the cross compilation tools are prefixed by `<HOST>-' you probably do -### not need to set these variables (where `<HOST>' is what has been passed as -### `--host=<HOST>' argument to `configure'). +### If the cross compilation tools are prefixed by `<HOST>-` you probably do +### not need to set these variables (where `<HOST>` is what has been passed as +### `--host=<HOST>` argument to `configure`). -## CC - C compiler. +### All variables in this section can also be used when native compiling. + +## `CC` - C compiler. #CC= -## CFLAGS - C compiler flags. +## `CFLAGS` - C compiler flags. #CFLAGS= -## STATIC_CFLAGS - Static C compiler flags. +## `STATIC_CFLAGS` - Static C compiler flags. #STATIC_CFLAGS= -## CFLAG_RUNTIME_LIBRARY_PATH - C compiler runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. Note that this is actually a linker flag, but it -## needs to be passed via the compiler. +## `CFLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for the shared libraries. Note that this actually is a +## linker flag, but it needs to be passed via the compiler. #CFLAG_RUNTIME_LIBRARY_PATH= -## CPP - C pre-processor. +## `CPP` - C pre-processor. #CPP= -## CPPFLAGS - C pre-processor flags. +## `CPPFLAGS` - C pre-processor flags. #CPPFLAGS= -## CXX - C++ compiler. +## `CXX` - C++ compiler. #CXX= -## CXXFLAGS - C++ compiler flags. +## `CXXFLAGS` - C++ compiler flags. #CXXFLAGS= -## LD - Linker. +## `LD` - Linker. #LD= -## LDFLAGS - Linker flags. +## `LDFLAGS` - Linker flags. #LDFLAGS= -## LIBS - Libraries. +## `LIBS` - Libraries. #LIBS= -### -- Dynamic Erlang Driver linker flags -- +### #### *D*ynamic *E*rlang *D*river Linking #### -### NOTE! Either set all or non of the DED_LD* variables. +### *NOTE*! Either set all or none of the `DED_LD*` variables. -## DED_LD - Linker. +## `DED_LD` - Linker for Dynamically loaded Erlang Drivers. #DED_LD= -## DED_LDFLAGS - Linker flags. +## `DED_LDFLAGS` - Linker flags to use with `DED_LD`. #DED_LDFLAGS= -## DED_LD_FLAG_RUNTIME_LIBRARY_PATH - Linker runtime library path flag. -## This flag should set a specific runtime library path for the shared -## library at link time. +## `DED_LD_FLAG_RUNTIME_LIBRARY_PATH` - This flag should set runtime library +## search path for shared libraries when linking with `DED_LD`. #DED_LD_FLAG_RUNTIME_LIBRARY_PATH= -### -- Large file support -- +### #### Large File Support #### -### NOTE! Either set all or non of the LFS_* variables. +### *NOTE*! Either set all or none of the `LFS_*` variables. -## LFS_CFLAGS - Large file support C compiler flags. +## `LFS_CFLAGS` - Large file support C compiler flags. #LFS_CFLAGS= -## LFS_LDFLAGS - Large file support linker flags. +## `LFS_LDFLAGS` - Large file support linker flags. #LFS_LDFLAGS= -## LFS_LIBS - Large file support libraries. +## `LFS_LIBS` - Large file support libraries. #LFS_LIBS= -### -- Other tools -- +### #### Other Tools #### -## RANLIB - `ranlib' archive index tool. +## `RANLIB` - `ranlib` archive index tool. #RANLIB= -## AR - `ar' archiving tool. +## `AR` - `ar` archiving tool. #AR= -## GETCONF - `getconf' system configuration inspection tool. +## `GETCONF` - `getconf` system configuration inspection tool. `getconf` is +## currently used for finding out large file support flags to use, and +## on Linux systems for finding out if we have an NPTL thread library or +## not. #GETCONF= -### ---- Cross System Root Locations ------------------------------------------ +### ### Cross System Root Locations ### -## erl_xcomp_sysroot - Absolute cross system root path. -## The absolute path to the system root of the cross compilation -## environment. Currently, the `crypto', `odbc', `ssh' and `ssl' -## applications need the system root. These applications will be skipped -## if the system root has not been set. The system root might be needed -## for other things too. If this is the case and the system root has not -## been set, `configure' will fail and request you to set it. +## `erl_xcomp_sysroot` - The absolute path to the system root of the cross +## compilation environment. Currently, the `crypto`, `odbc`, `ssh` and +## `ssl` applications need the system root. These applications will be +## skipped if the system root has not been set. The system root might be +## needed for other things too. If this is the case and the system root +## has not been set, `configure` will fail and request you to set it. #erl_xcomp_sysroot= -## erl_xcomp_isysroot - Absolute cross include system root path. -## The absolute path to the system root for includes of the cross -## compilation environment. If not set, this value defaults to -## `$erl_xcomp_sysroot', i.e., only set this value if the include system +## `erl_xcomp_isysroot` - The absolute path to the system root for includes +## of the cross compilation environment. If not set, this value defaults +## to `$erl_xcomp_sysroot`, i.e., only set this value if the include system ## root path is not the same as the system root path. #erl_xcomp_isysroot= -### ---- Optional feature, or bug tests --------------------------------------- +### ### Optional Feature, and Bug Tests ### ### These tests cannot (always) be done automatically when cross compiling. You -### usually does not need to set these variables. Only set these if you really +### usually do not need to set these variables. Only set these if you really ### know what you are doing. ### Note that some of these values will override results of tests performed -### by `configure', and some will not be used until `configure' is sure that +### by `configure`, and some will not be used until `configure` is sure that ### it cannot figure the result out. -### The `configure' script will issue a warning when a default value is used. +### The `configure` script will issue a warning when a default value is used. ### When a variable has been set, no warning will be issued. -## erl_xcomp_bigendian - yes|no -## If `yes', the target system must be big endian. If `no', little endian. -## This can often be automatically detected, but not always. If not -## automatically detected, `configure' will fail unless this variable is -## set. No default value is used, i.e., `configure' will try to figure -## this out automatically. -#erl_xcomp_bigendian= +## `erl_xcomp_after_morecore_hook` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `__after_morecore_hook` that can be +## used for tracking used `malloc()` implementations core memory usage. +## This is currently only used by unsupported features. +#erl_xcomp_after_morecore_hook= -## erl_xcomp_linux_clock_gettime_correction - yes|no (defaults to `yes' on -## Linux; otherwise, `no') -## If `yes', `clock_gettime(CLOCK_MONOTONIC, _)' on the target system must -## work. This variable is recommended to be set to `no' on Linux systems -## with kernel versions less than 2.6. -#erl_xcomp_linux_clock_gettime_correction= +## `erl_xcomp_bigendian` - `yes|no`. No default. If `yes`, the target system +## must be big endian. If `no`, little endian. This can often be +## automatically detected, but not always. If not automatically detected, +## `configure` will fail unless this variable is set. Since no default +## value is used, `configure` will try to figure this out automatically. +#erl_xcomp_bigendian= -## erl_xcomp_linux_nptl - yes|no (defaults to `yes' on Linux; otherwise, `no') -## If `yes', the target system must have NPTL (Native POSIX Thread Library). -## Older Linux systems have LinuxThreads instead of NPTL (Linux kernel -## versions typically less than 2.6). -#erl_xcomp_linux_nptl= +## `erl_xcomp_clock_gettime_cpu_time` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `clock_gettime()` implementation +## that can be used for retrieving process CPU time. +#erl_xcomp_clock_gettime_cpu_time= -## erl_xcomp_linux_usable_sigusrx - yes|no (defaults to `yes') -## If `yes', the `SIGUSR1' and `SIGUSR2' signals must be usable by the ERTS. -## Old LinuxThreads thread libraries (Linux kernel versions less than 2.2) -## used these signals and made them unusable by the ERTS. -#erl_xcomp_linux_usable_sigusrx= +## `erl_xcomp_getaddrinfo` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a working `getaddrinfo()` implementation that can +## handle both IPv4 and IPv6. +#erl_xcomp_getaddrinfo= -## erl_xcomp_linux_usable_sigaltstack - yes|no (defaults to `yes' on Linux; -## otherwise, `no') -## If `yes', `sigaltstack()' must be usable on the target system. -## `sigaltstack()' on Linux kernel versions less than 2.4 are broken. -#erl_xcomp_linux_usable_sigaltstack= +## `erl_xcomp_gethrvtime_procfs_ioctl` - `yes|no`. Defaults to `no`. If `yes`, +## the target system must have a working `gethrvtime()` implementation and +## is used with procfs `ioctl()`. +#erl_xcomp_gethrvtime_procfs_ioctl= -## erl_xcomp_poll - yes|no (defaults to `no' on Darwin/MacOSX; otherwise, `yes') -## If `yes', the target system must have a working `poll()' implementation -## that also can handle devices. If `no', `select()' will be used instead of -## `poll()'. -#erl_xcomp_poll= +## `erl_xcomp_dlsym_brk_wrappers` - `yes|no`. Defaults to `no`. If `yes`, the +## target system must have a working `dlsym(RTLD_NEXT, <S>)` implementation +## that can be used on `brk` and `sbrk` symbols used by the `malloc()` +## implementation in use, and by this track the `malloc()` implementations +## core memory usage. This is currently only used by unsupported features. +#erl_xcomp_dlsym_brk_wrappers= -## erl_xcomp_kqueue - yes|no (defaults to `no') -## If `yes', the target system must have a working `kqueue()' implementation -## that returns a file descriptor which can be used by `poll()' and/or -## `select()'. If `no' and the target system has not got `epoll()' or -## `/dev/poll', the kernel-poll feature will be disabled. +## `erl_xcomp_kqueue` - `yes|no`. Defaults to `no`. If `yes`, the target system +## must have a working `kqueue()` implementation that returns a file +## descriptor which can be used by `poll()` and/or `select()`. If `no` and +## the target system has not got `epoll()` or `/dev/poll`, the kernel-poll +## feature will be disabled. #erl_xcomp_kqueue= -## erl_xcomp_putenv_copy - yes|no (defaults to `no') -## If `yes', the target system must have a `putenv()' implementation that -## stores a copy of the key/value pair. -#erl_xcomp_putenv_copy= +## `erl_xcomp_linux_clock_gettime_correction` - `yes|no`. Defaults to `yes` on +## Linux; otherwise, `no`. If `yes`, `clock_gettime(CLOCK_MONOTONIC, _)` on +## the target system must work. This variable is recommended to be set to +## `no` on Linux systems with kernel versions less than 2.6. +#erl_xcomp_linux_clock_gettime_correction= -## erl_xcomp_reliable_fpe - yes|no (defaults to `no') -## If `yes', the target system must have reliable floating point exceptions. -#erl_xcomp_reliable_fpe= +## `erl_xcomp_linux_nptl` - `yes|no`. Defaults to `yes` on Linux; otherwise, +## `no`. If `yes`, the target system must have NPTL (Native POSIX Thread +## Library). Older Linux systems have LinuxThreads instead of NPTL (Linux +## kernel versions typically less than 2.6). +#erl_xcomp_linux_nptl= -## erl_xcomp_getaddrinfo - yes|no (defaults to `no') -## If `yes', the target system must have a working `getaddrinfo()' -## implementation that can handle both IPv4 and IPv6. -#erl_xcomp_getaddrinfo= +## `erl_xcomp_linux_usable_sigaltstack` - `yes|no`. Defaults to `yes` on Linux; +## otherwise, `no`. If `yes`, `sigaltstack()` must be usable on the target +## system. `sigaltstack()` on Linux kernel versions less than 2.4 are +## broken. +#erl_xcomp_linux_usable_sigaltstack= -## erl_xcomp_gethrvtime_procfs_ioctl - yes|no (defaults to `no') -## If `yes', the target system must have a working `gethrvtime()' -## implementation and is used with procfs `ioctl()'. -#erl_xcomp_gethrvtime_procfs_ioctl= +## `erl_xcomp_linux_usable_sigusrx` - `yes|no`. Defaults to `yes`. If `yes`, +## the `SIGUSR1` and `SIGUSR2` signals must be usable by the ERTS. Old +## LinuxThreads thread libraries (Linux kernel versions typically less than +## 2.2) used these signals and made them unusable by the ERTS. +#erl_xcomp_linux_usable_sigusrx= -## erl_xcomp_clock_gettime_cpu_time - yes|no (defaults to `no') -## If `yes', the target system must have a working `clock_gettime()' -## implementation that can be used for retrieving process CPU time. -#erl_xcomp_clock_gettime_cpu_time= +## `erl_xcomp_poll` - `yes|no`. Defaults to `no` on Darwin/MacOSX; otherwise, +## `yes`. If `yes`, the target system must have a working `poll()` +## implementation that also can handle devices. If `no`, `select()` will be +## used instead of `poll()`. +#erl_xcomp_poll= -## erl_xcomp_after_morecore_hook - yes|no (defaults to `no') -## If `yes', the target system must have a working `__after_morecore_hook' -## that can be used for tracking used `malloc()' implementations core memory -## usage. -#erl_xcomp_after_morecore_hook= +## `erl_xcomp_putenv_copy` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have a `putenv()` implementation that stores a copy of the +## key/value pair. +#erl_xcomp_putenv_copy= -## erl_xcomp_dlsym_brk_wrappers - yes|no (defaults to `no') -## If `yes', the target system must have a working `dlsym(RTLD_NEXT, <S>)' -## implementation that can be used on `brk' and `sbrk' symbols used by the -## `malloc()' implementation in use, and by this track the `malloc()' -## implementations core memory usage. -#erl_xcomp_dlsym_brk_wrappers= +## `erl_xcomp_reliable_fpe` - `yes|no`. Defaults to `no`. If `yes`, the target +## system must have reliable floating point exceptions. +#erl_xcomp_reliable_fpe= -#### -------------------------------------------------------------------------- +#### |