diff options
Diffstat (limited to 'lib/stdlib')
83 files changed, 3420 insertions, 1329 deletions
diff --git a/lib/stdlib/doc/src/beam_lib.xml b/lib/stdlib/doc/src/beam_lib.xml index f2a9c2a671..b9286f1402 100644 --- a/lib/stdlib/doc/src/beam_lib.xml +++ b/lib/stdlib/doc/src/beam_lib.xml @@ -4,7 +4,7 @@ <erlref> <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>beam_lib</title> @@ -70,82 +70,88 @@ using <seealso marker="#strip/1">strip/1</seealso>, <seealso marker="#strip_files/1">strip_files/1</seealso> and/or <seealso marker="#strip_release/1">strip_release/1</seealso>.</p> - <p><em>Reconstructing source code</em></p> - <p>Here is an example of how to reconstruct source code from - the debug information in a BEAM file <c>Beam</c>:</p> - <code type="none"> + <section> + <title>Reconstructing source code</title> + <p>Here is an example of how to reconstruct source code from + the debug information in a BEAM file <c>Beam</c>:</p> + <code type="none"> {ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam,[abstract_code]). io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).</code> - <p><em>Encrypted debug information</em></p> - <p>The debug information can be encrypted in order to keep - the source code secret, but still being able to use tools such as - Xref or Debugger. </p> - <p>To use encrypted debug information, a key must be provided to - the compiler and <c>beam_lib</c>. The key is given as a string and - it is recommended that it contains at least 32 characters and - that both upper and lower case letters as well as digits and - special characters are used.</p> - <p></p> - <p>The default type -- and currently the only type -- of crypto - algorithm is <c>des3_cbc</c>, three rounds of DES. The key string - will be scrambled using <c>erlang:md5/1</c> to generate - the actual keys used for <c>des3_cbc</c>.</p> - <note> - <p>As far as we know by the time of writing, it is - infeasible to break <c>des3_cbc</c> encryption without any - knowledge of the key. Therefore, as long as the key is kept - safe and is unguessable, the encrypted debug information - <em>should</em> be safe from intruders.</p> - </note> - <p>There are two ways to provide the key:</p> - <list type="ordered"> - <item> - <p>Use the compiler option <c>{debug_info,Key}</c>, see - <seealso marker="compiler:compile#debug_info_key">compile(3)</seealso>, - and the function - <seealso marker="#crypto_key_fun/1">crypto_key_fun/1</seealso> - to register a fun which returns the key whenever - <c>beam_lib</c> needs to decrypt the debug information.</p> - <p>If no such fun is registered, <c>beam_lib</c> will instead - search for a <c>.erlang.crypt</c> file, see below.</p> - </item> - <item> - <p>Store the key in a text file named <c>.erlang.crypt</c>.</p> - <p>In this case, the compiler option <c>encrypt_debug_info</c> - can be used, see - <seealso marker="compiler:compile#encrypt_debug_info">compile(3)</seealso>.</p> - </item> - </list> - <p><em>.erlang.crypt</em></p> - <p><c>beam_lib</c> searches for <c>.erlang.crypt</c> in the current - directory and then the home directory for the current user. If - the file is found and contains a key, <c>beam_lib</c> will - implicitly create a crypto key fun and register it.</p> - <p>The <c>.erlang.crypt</c> file should contain a single list of - tuples:</p> - <code type="none"> + </section> + <section> + <title>Encrypted debug information</title> + <p>The debug information can be encrypted in order to keep + the source code secret, but still being able to use tools such as + Xref or Debugger. </p> + <p>To use encrypted debug information, a key must be provided to + the compiler and <c>beam_lib</c>. The key is given as a string and + it is recommended that it contains at least 32 characters and + that both upper and lower case letters as well as digits and + special characters are used.</p> + <p></p> + <p>The default type -- and currently the only type -- of crypto + algorithm is <c>des3_cbc</c>, three rounds of DES. The key string + will be scrambled using <c>erlang:md5/1</c> to generate + the actual keys used for <c>des3_cbc</c>.</p> + <note> + <p>As far as we know by the time of writing, it is + infeasible to break <c>des3_cbc</c> encryption without any + knowledge of the key. Therefore, as long as the key is kept + safe and is unguessable, the encrypted debug information + <em>should</em> be safe from intruders.</p> + </note> + <p>There are two ways to provide the key:</p> + <list type="ordered"> + <item> + <p>Use the compiler option <c>{debug_info,Key}</c>, see + <seealso marker="compiler:compile#debug_info_key">compile(3)</seealso>, + and the function + <seealso marker="#crypto_key_fun/1">crypto_key_fun/1</seealso> + to register a fun which returns the key whenever + <c>beam_lib</c> needs to decrypt the debug information.</p> + <p>If no such fun is registered, <c>beam_lib</c> will instead + search for a <c>.erlang.crypt</c> file, see below.</p> + </item> + <item> + <p>Store the key in a text file named <c>.erlang.crypt</c>.</p> + <p>In this case, the compiler option <c>encrypt_debug_info</c> + can be used, see + <seealso marker="compiler:compile#encrypt_debug_info">compile(3)</seealso>.</p> + </item> + </list> + </section> + <section> + <title>.erlang.crypt</title> + <p><c>beam_lib</c> searches for <c>.erlang.crypt</c> in the current + directory and then the home directory for the current user. If + the file is found and contains a key, <c>beam_lib</c> will + implicitly create a crypto key fun and register it.</p> + <p>The <c>.erlang.crypt</c> file should contain a single list of + tuples:</p> + <code type="none"> {debug_info, Mode, Module, Key}</code> - <p><c>Mode</c> is the type of crypto algorithm; currently, the only - allowed value thus is <c>des3_cbc</c>. <c>Module</c> is either an - atom, in which case <c>Key</c> will only be used for the module - <c>Module</c>, or <c>[]</c>, in which case <c>Key</c> will be - used for all modules. <c>Key</c> is the non-empty key string.</p> - <p>The <c>Key</c> in the first tuple where both <c>Mode</c> and - <c>Module</c> matches will be used.</p> - <p>Here is an example of an <c>.erlang.crypt</c> file that returns - the same key for all modules:</p> - <code type="none"><![CDATA[ + <p><c>Mode</c> is the type of crypto algorithm; currently, the only + allowed value thus is <c>des3_cbc</c>. <c>Module</c> is either an + atom, in which case <c>Key</c> will only be used for the module + <c>Module</c>, or <c>[]</c>, in which case <c>Key</c> will be + used for all modules. <c>Key</c> is the non-empty key string.</p> + <p>The <c>Key</c> in the first tuple where both <c>Mode</c> and + <c>Module</c> matches will be used.</p> + <p>Here is an example of an <c>.erlang.crypt</c> file that returns + the same key for all modules:</p> + <code type="none"><![CDATA[ [{debug_info, des3_cbc, [], "%>7}|pc/DM6Cga*68$Mw]L#&_Gejr]G^"}].]]></code> - <p>And here is a slightly more complicated example of an - <c>.erlang.crypt</c> which provides one key for the module - <c>t</c>, and another key for all other modules:</p> - <code type="none"><![CDATA[ + <p>And here is a slightly more complicated example of an + <c>.erlang.crypt</c> which provides one key for the module + <c>t</c>, and another key for all other modules:</p> + <code type="none"><![CDATA[ [{debug_info, des3_cbc, t, "My KEY"}, {debug_info, des3_cbc, [], "%>7}|pc/DM6Cga*68$Mw]L#&_Gejr]G^"}].]]></code> - <note> - <p>Do not use any of the keys in these examples. Use your own - keys.</p> - </note> + <note> + <p>Do not use any of the keys in these examples. Use your own + keys.</p> + </note> + </section> </section> <section> diff --git a/lib/stdlib/doc/src/epp.xml b/lib/stdlib/doc/src/epp.xml index 455d9dc124..e6b48b270a 100644 --- a/lib/stdlib/doc/src/epp.xml +++ b/lib/stdlib/doc/src/epp.xml @@ -4,23 +4,21 @@ <erlref> <header> <copyright> - <year>1996</year> - <year>2007</year> - <holder>Ericsson AB, All Rights Reserved</holder> + <year>1996</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/. + 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. + 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>epp</title> @@ -112,7 +110,7 @@ <p>A string which describes the error is obtained with the following call: </p> <code type="none"> -apply(Module, format_error, ErrorDescriptor) </code> + Module:format_error(ErrorDescriptor) </code> </section> <section> diff --git a/lib/stdlib/doc/src/erl_lint.xml b/lib/stdlib/doc/src/erl_lint.xml index e339f484cc..6a7d37765c 100644 --- a/lib/stdlib/doc/src/erl_lint.xml +++ b/lib/stdlib/doc/src/erl_lint.xml @@ -4,7 +4,7 @@ <erlref> <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>erl_lint</title> @@ -147,7 +147,7 @@ <p>A string which describes the error is obtained with the following call: </p> <code type="none"> -apply(Module, format_error, ErrorDescriptor) </code> + Module:format_error(ErrorDescriptor) </code> </section> <section> diff --git a/lib/stdlib/doc/src/erl_parse.xml b/lib/stdlib/doc/src/erl_parse.xml index 739fde7a40..ae8a8afd5c 100644 --- a/lib/stdlib/doc/src/erl_parse.xml +++ b/lib/stdlib/doc/src/erl_parse.xml @@ -4,23 +4,21 @@ <erlref> <header> <copyright> - <year>1996</year> - <year>2007</year> - <holder>Ericsson AB, All Rights Reserved</holder> + <year>1996</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/. + 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. + 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>erl_parse</title> @@ -188,7 +186,7 @@ <p>A string which describes the error is obtained with the following call: </p> <code type="none"> -apply(Module, format_error, ErrorDescriptor) </code> + Module:format_error(ErrorDescriptor) </code> </section> <section> diff --git a/lib/stdlib/doc/src/file_sorter.xml b/lib/stdlib/doc/src/file_sorter.xml index b3f4da294c..ccb32659a0 100644 --- a/lib/stdlib/doc/src/file_sorter.xml +++ b/lib/stdlib/doc/src/file_sorter.xml @@ -4,7 +4,7 @@ <erlref> <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>file_sorter</title> @@ -83,13 +83,15 @@ An ordering function is antisymmetric, transitive and total. <c>Fun(A, B)</c> should return <c>true</c> if <c>A</c> comes before <c>B</c> in the ordering, <c>false</c> otherwise. + An example of a typical ordering function is less than or equal + to, <c>=</2</c>. Using an ordering function will slow down the sort considerably. The <c>keysort</c>, <c>keymerge</c> and <c>keycheck</c> functions do not accept ordering functions. </item> <item><c>{unique, bool()}</c>. When sorting or merging files, - only the first of a sequence of terms that compare equal is - output if this option is set to <c>true</c>. The default + only the first of a sequence of terms that compare equal (<c>==</c>) + is output if this option is set to <c>true</c>. The default value is <c>false</c> which implies that all terms that compare equal are output. When checking files for sortedness, a check that no pair of consecutive terms @@ -301,7 +303,7 @@ Value = Term</pre> <desc> <p>Sorts tuples on files. The sort is performed on the element(s) mentioned in <c>KeyPos</c>. If two tuples - compare equal on one element, next element according to + compare equal (<c>==</c>) on one element, next element according to <c>KeyPos</c> is compared. The sort is stable. </p> <p><c>keysort(N, FileName)</c> is equivalent to diff --git a/lib/stdlib/doc/src/filename.xml b/lib/stdlib/doc/src/filename.xml index 3a6c5e0b60..0cf82fa48b 100644 --- a/lib/stdlib/doc/src/filename.xml +++ b/lib/stdlib/doc/src/filename.xml @@ -37,7 +37,7 @@ is meant all strings that can be used to denote a file. They can be short relative names like <c>foo.erl</c>, very long absolute name which include a drive designator and directory names like - <c>D:\\usr/local\\bin\\erl/lib\\tools\\foo.erl</c>, or any variations + <c>D:\usr/local\bin\erl/lib\tools\foo.erl</c>, or any variations in between.</p> <p>In Windows, all functions return file names with forward slashes only, even if the arguments contain back slashes. Use @@ -173,7 +173,7 @@ name() = string() | atom() | DeepList 14> <input>filename:dirname("kalle.erl").</input> "." -5> <input>filename:dirname("\\\\usr\\\\src/kalle.erl").</input> % Windows +5> <input>filename:dirname("\\usr\\src/kalle.erl").</input> % Windows "/usr/src"</pre> </desc> </func> @@ -228,7 +228,7 @@ name() = string() | atom() | DeepList 18> <input>filename:join(["a/b///c/"]).</input> "a/b/c" -6> <input>filename:join(["B:a\\\\b///c/"]).</input> % Windows +6> <input>filename:join(["B:a\\b///c/"]).</input> % Windows "b:a/b/c"</pre> </desc> </func> @@ -259,7 +259,7 @@ name() = string() | atom() | DeepList "/usr/local/bin" 7> <input>filename:nativename("/usr/local/bin/").</input> % Windows -"\\\\usr\\\\local\\\\bin"</pre> +"\\usr\\local\\bin"</pre> </desc> </func> <func> @@ -329,7 +329,7 @@ name() = string() | atom() | DeepList ["/","usr","local","bin"] 25> <input>filename:split("foo/bar").</input> ["foo","bar"] -26> <input>filename:split("a:\\\\msdev\\\\include").</input> +26> <input>filename:split("a:\\msdev\\include").</input> ["a:/","msdev","include"]</pre> </desc> </func> diff --git a/lib/stdlib/doc/src/gb_sets.xml b/lib/stdlib/doc/src/gb_sets.xml index accec623b9..60d8bcbfa3 100644 --- a/lib/stdlib/doc/src/gb_sets.xml +++ b/lib/stdlib/doc/src/gb_sets.xml @@ -4,7 +4,7 @@ <erlref> <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>gb_sets</title> @@ -34,6 +34,8 @@ General Balanced Trees. This can be much more efficient than using ordered lists, for larger sets, but depends on the application.</p> + <p>This module considers two elements as different if and only if + they do not compare equal (<c>==</c>).</p> </description> <section> diff --git a/lib/stdlib/doc/src/gb_trees.xml b/lib/stdlib/doc/src/gb_trees.xml index 2bf18138c0..94f40c28bd 100644 --- a/lib/stdlib/doc/src/gb_trees.xml +++ b/lib/stdlib/doc/src/gb_trees.xml @@ -4,7 +4,7 @@ <erlref> <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>gb_trees</title> @@ -34,6 +34,8 @@ Balanced Trees. These have no storage overhead compared to unbalanced binary trees, and their performance is in general better than AVL trees.</p> + <p>This module considers two keys as different if and only if + they do not compare equal (<c>==</c>).</p> </description> <section> diff --git a/lib/stdlib/doc/src/gen_fsm.xml b/lib/stdlib/doc/src/gen_fsm.xml index f5d8b9bb48..739cd0bffd 100644 --- a/lib/stdlib/doc/src/gen_fsm.xml +++ b/lib/stdlib/doc/src/gen_fsm.xml @@ -729,6 +729,36 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4 updated internal data.</p> </desc> </func> + <func> + <name>Module:format_status(normal, [PDict, StateData]) -> Status</name> + <fsummary>Optional function for providing a term describing the + current gen_fsm status.</fsummary> + <type> + <v>PDict = [{Key, Value}]</v> + <v>StateData = term()</v> + <v>Status = [term()]</v> + </type> + <desc> + <p><em>This callback is optional, so callback modules need not + export it. The gen_fsm module provides a default + implementation of this function that returns the callback + module state data.</em></p> + <p>This function is called by a gen_fsm process when one + of <seealso marker="sys#get_status/1">sys:get_status/1,2</seealso> + is invoked to get the gen_fsm status. A callback module + wishing to customise the <c>sys:get_status/1,2</c> return + value exports an instance of <c>format_status/2</c> that + returns a term describing the current status of the + gen_fsm.</p> + <p><c>PDict</c> is the current value of the gen_fsm's + process dictionary.</p> + <p><c>StateData</c> is the internal state data of the + gen_fsm.</p> + <p>The function should return <c>Status</c>, a list of one or + more terms that customise the details of the current state + and status of the gen_fsm.</p> + </desc> + </func> </funcs> <section> diff --git a/lib/stdlib/doc/src/gen_server.xml b/lib/stdlib/doc/src/gen_server.xml index 8496802259..30c04d1d52 100644 --- a/lib/stdlib/doc/src/gen_server.xml +++ b/lib/stdlib/doc/src/gen_server.xml @@ -598,6 +598,35 @@ gen_server:abcast -----> Module:handle_cast/2 <p>The function should return the updated internal state.</p> </desc> </func> + <func> + <name>Module:format_status(normal, [PDict, State]) -> Status</name> + <fsummary>Optional function for providing a term describing the + current gen_server status.</fsummary> + <type> + <v>PDict = [{Key, Value}]</v> + <v>State = term()</v> + <v>Status = [term()]</v> + </type> + <desc> + <p><em>This callback is optional, so callback modules need not + export it. The gen_server module provides a default + implementation of this function that returns the callback + module state.</em></p> + <p>This function is called by a gen_server process when one + of <seealso marker="sys#get_status/1">sys:get_status/1,2</seealso> + is invoked to get the gen_server status. A callback module + wishing to customise the <c>sys:get_status/1,2</c> return + value exports an instance of <c>format_status/2</c> that + returns a term describing the current status of the + gen_server.</p> + <p><c>PDict</c> is the current value of the gen_server's + process dictionary.</p> + <p><c>State</c> is the internal state of the gen_server.</p> + <p>The function should return <c>Status</c>, a list of one or + more terms that customise the details of the current state + and status of the gen_server.</p> + </desc> + </func> </funcs> <section> diff --git a/lib/stdlib/doc/src/io.xml b/lib/stdlib/doc/src/io.xml index c075f11792..efbb1fc078 100644 --- a/lib/stdlib/doc/src/io.xml +++ b/lib/stdlib/doc/src/io.xml @@ -4,7 +4,7 @@ <erlref> <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>io</title> @@ -1003,7 +1003,8 @@ enter><input>bar.</input> <title>Standard Error</title> <p>In certain situations, especially when the standard output is redirected, access to an io_server() specific for error messages might be convenient. The io_device 'standard_error' can be used to direct output to whatever the current operating system considers a suitable device for error output. Example on a Unix-like operating system:</p> <pre> -$ <input>erl -noshell -noinput -eval 'io:format(standard_error,"Error: ~s~n",["error 11"]),init:stop().' > /dev/null</input> +$ <input>erl -noshell -noinput -eval 'io:format(standard_error,"Error: ~s~n",["error 11"]),'\</input> +<input>'init:stop().' > /dev/null</input> Error: error 11</pre> @@ -1020,7 +1021,7 @@ Error: error 11</pre> <p>A string which describes the error is obtained with the following call:</p> <code type="none"> -apply(Module, format_error, ErrorDescriptor)</code> +Module:format_error(ErrorDescriptor)</code> </section> </erlref> diff --git a/lib/stdlib/doc/src/io_protocol.xml b/lib/stdlib/doc/src/io_protocol.xml index 1b75114031..201787f7b5 100644 --- a/lib/stdlib/doc/src/io_protocol.xml +++ b/lib/stdlib/doc/src/io_protocol.xml @@ -546,7 +546,7 @@ request({get_chars, Encoding, _Prompt, N}, State) -> get_until(Encoding, ?MODULE, until_enough, [N], State); request({get_line, Encoding, _Prompt}, State) -> %% To simplify the code, get_line is implemented using get_until - get_until(Encoding, ?MODULE, until_newline, [$\\n], State); + get_until(Encoding, ?MODULE, until_newline, [$\n], State); </code> <p>Here we have cheated a little by more or less only implementing diff --git a/lib/stdlib/doc/src/lists.xml b/lib/stdlib/doc/src/lists.xml index 39fc05420d..855a7e0244 100644 --- a/lib/stdlib/doc/src/lists.xml +++ b/lib/stdlib/doc/src/lists.xml @@ -4,7 +4,7 @@ <erlref> <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>lists</title> @@ -30,15 +30,16 @@ <module>lists</module> <modulesummary>List Processing Functions</modulesummary> <description> - <p>This module contains functions for list processing. The functions - are organized in two groups: those in the first group perform a - particular operation on one or more lists, whereas those in the - second group are higher-order functions, using a fun as argument - to perform an operation on one list.</p> + <p>This module contains functions for list processing.</p> + <p>Unless otherwise stated, all functions assume that position numbering starts at 1. That is, the first element of a list is at position 1.</p> + <p>Two terms <c>T1</c> and <c>T2</c> compare equal if + <c>T1 == T2</c> evaluates to <c>true</c>. They match + if <c>T1 =:= T2</c> evaluates to <c>true</c>.</p> + <p>Whenever an <marker id="ordering_function"></marker><em>ordering function</em> <c>F</c> is expected as argument, it is assumed that the diff --git a/lib/stdlib/doc/src/proplists.xml b/lib/stdlib/doc/src/proplists.xml index a218dcf1fe..9f1c5b24ad 100644 --- a/lib/stdlib/doc/src/proplists.xml +++ b/lib/stdlib/doc/src/proplists.xml @@ -4,7 +4,7 @@ <erlref> <header> <copyright> - <year>2002</year><year>2009</year> + <year>2002</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>proplists</title> @@ -44,6 +44,9 @@ such as options passed to a function where a user may specify options overriding the default settings, object properties, annotations, etc.</p> + <p>Two keys are considered equal if they match (<c>=:=</c>). In other + words, numbers are compared literally rather than by value, so that, + for instance, <c>1</c> and <c>1.0</c> are different keys.</p> </description> <funcs> <func> diff --git a/lib/stdlib/doc/src/re.xml b/lib/stdlib/doc/src/re.xml index 6c6f67811a..4d2a0e0995 100644 --- a/lib/stdlib/doc/src/re.xml +++ b/lib/stdlib/doc/src/re.xml @@ -56,10 +56,10 @@ <note> <p>The Erlang literal syntax for strings give special - meaning to the "\\" (backslash) character. To literally write + meaning to the "\" (backslash) character. To literally write a regular expression or a replacement string containing a backslash in your code or in the shell, two backslashes have to be written: - "\\\\".</p> + "\\".</p> </note> @@ -163,9 +163,9 @@ This option makes it possible to include comments inside complicated patterns. N </taglist> </item> <tag><c>bsr_anycrlf</c></tag> - <item>Specifies specifically that \\R is to match only the cr, lf or crlf sequences, not the Unicode specific newline characters.</item> + <item>Specifies specifically that \R is to match only the cr, lf or crlf sequences, not the Unicode specific newline characters.</item> <tag><c>bsr_unicode</c></tag> - <item>Specifies specifically that \\R is to match all the Unicode newline characters (including crlf etc, the default).</item> + <item>Specifies specifically that \R is to match all the Unicode newline characters (including crlf etc, the default).</item> </taglist> </desc> </func> @@ -384,9 +384,9 @@ This option makes it possible to include comments inside complicated patterns. N </taglist> </item> <tag><c>bsr_anycrlf</c></tag> - <item>Specifies specifically that \\R is to match only the cr, lf or crlf sequences, not the Unicode specific newline characters.(overrides compilation option)</item> + <item>Specifies specifically that \R is to match only the cr, lf or crlf sequences, not the Unicode specific newline characters.(overrides compilation option)</item> <tag><c>bsr_unicode</c></tag> - <item>Specifies specifically that \\R is to match all the Unicode newline characters (including crlf etc, the default).(overrides compilation option)</item> + <item>Specifies specifically that \R is to match all the Unicode newline characters (including crlf etc, the default).(overrides compilation option)</item> <tag><c>{capture, ValueSpec}</c>/<c>{capture, ValueSpec, Type}</c></tag> <item> @@ -471,9 +471,9 @@ This option makes it possible to include comments inside complicated patterns. N <tag><c>index</c></tag> <item>Return captured substrings as pairs of byte indexes into the subject string and length of the matching string in the subject (as if the subject string was flattened with <c>iolist_to_binary/1</c> or <c>unicode:characters_to_binary/2</c> prior to matching). Note that the <c>unicode</c> option results in <em>byte-oriented</em> indexes in a (possibly imagined) <em>UTF-8 encoded</em> binary. A byte index tuple <c>{0,2}</c> might therefore represent one or two characters when <c>unicode</c> is in effect. This might seem contra-intuitive, but has been deemed the most effective and useful way to way to do it. To return lists instead might result in simpler code if that is desired. This return type is the default.</item> <tag><c>list</c></tag> - <item>Return matching substrings as lists of characters (Erlang <c>string()</c>'s). It the <c>unicode</c> option is used in combination with the \\C sequence in the regular expression, a captured subpattern can contain bytes that has is not valid UTF-8 (\\C matches bytes regardless of character encoding). In that case the <c>list</c> capturing may result in the same types of tuples that <c>unicode:characters_to_list/2</c> can return, namely three-tuples with the tag <c>incomplete</c> or <c>error</c>, the successfully converted characters and the invalid UTF-8 tail of the conversion as a binary. The best strategy is to avoid using the\\C sequence when capturing lists.</item> + <item>Return matching substrings as lists of characters (Erlang <c>string()</c>'s). It the <c>unicode</c> option is used in combination with the \C sequence in the regular expression, a captured subpattern can contain bytes that has is not valid UTF-8 (\C matches bytes regardless of character encoding). In that case the <c>list</c> capturing may result in the same types of tuples that <c>unicode:characters_to_list/2</c> can return, namely three-tuples with the tag <c>incomplete</c> or <c>error</c>, the successfully converted characters and the invalid UTF-8 tail of the conversion as a binary. The best strategy is to avoid using the \C sequence when capturing lists.</item> <tag><c>binary</c></tag> - <item>Return matching substrings as binaries. If the <c>unicode</c> option is used, these binaries is in UTF-8. If the \\C sequence is used together with <c>unicode</c> the binaries may be invalid UTF-8.</item> + <item>Return matching substrings as binaries. If the <c>unicode</c> option is used, these binaries is in UTF-8. If the \C sequence is used together with <c>unicode</c> the binaries may be invalid UTF-8.</item> </taglist> </item> </taglist> @@ -544,20 +544,20 @@ This option makes it possible to include comments inside complicated patterns. N <p>The replacement string can contain the special character <c>&</c>, which inserts the whole matching expression in the - result, and the special sequence <c>\\</c>N (where N is an + result, and the special sequence <c>\</c>N (where N is an integer > 0), resulting in the subexpression number N will be inserted in the result. If no subexpression with that number is generated by the regular expression, nothing is inserted.</p> - <p>To insert an <c>&</c> or <c>\\</c> in the result, precede it - with a <c>\\</c>. Note that Erlang already gives a special - meaning to <c>\\</c> in literal strings, why a single <c>\\</c> - has to be written as <c>"\\\\"</c> and therefore a double <c>\\</c> - as <c>"\\\\\\\\"</c>. Example:</p> + <p>To insert an <c>&</c> or <c>\</c> in the result, precede it + with a <c>\</c>. Note that Erlang already gives a special + meaning to <c>\</c> in literal strings, why a single <c>\</c> + has to be written as <c>"\\"</c> and therefore a double <c>\</c> + as <c>"\\\\"</c>. Example:</p> <code> re:replace("abcd","c","[&]",[{return,list}]).</code> <p>gives</p> <code> "ab[c]d"</code> <p>while</p> - <code> re:replace("abcd","c","[\\\&]",[{return,list}]).</code> + <code> re:replace("abcd","c","[\\&]",[{return,list}]).</code> <p>gives</p> <code> "ab[&]d"</code> <p>As with <c>re:run/3</c>, compilation errors raise the <c>badarg</c> @@ -852,19 +852,19 @@ example, the pattern:</p> <p> (*CR)a.b</p> </quote> -<p>changes the convention to CR. That pattern matches "a\\nb" because LF is no +<p>changes the convention to CR. That pattern matches "a\nb" because LF is no longer a newline. Note that these special settings, which are not Perl-compatible, are recognized only at the very start of a pattern, and that they must be in upper case. If more than one of them is present, the last one is used.</p> -<p>The newline convention does not affect what the \\R escape sequence matches. By +<p>The newline convention does not affect what the \R escape sequence matches. By default, this is any Unicode newline sequence, for Perl compatibility. However, -this can be changed; see the description of \\R in the section entitled +this can be changed; see the description of \R in the section entitled "Newline sequences" -below. A change of \\R setting can be combined with a change of newline +below. A change of \R setting can be combined with a change of newline convention.</p> </section> @@ -897,7 +897,7 @@ recognized within square brackets. Outside square brackets, the metacharacters are as follows:</p> <taglist> - <tag>\\</tag> <item>general escape character with several uses</item> + <tag>\</tag> <item>general escape character with several uses</item> <tag>^</tag> <item>assert start of string (or line, in multiline mode)</item> <tag>$</tag> <item>assert end of string (or line, in multiline mode)</item> <tag>.</tag> <item>match any character except newline (by default)</item> @@ -918,7 +918,7 @@ are as follows:</p> a character class the only metacharacters are:</p> <taglist> - <tag>\\</tag> <item>general escape character</item> + <tag>\</tag> <item>general escape character</item> <tag>^</tag> <item>negate the class, but only if the first character</item> <tag>-</tag> <item>indicates character range</item> <tag>[</tag> <item>POSIX character class (only if followed by POSIX @@ -939,11 +939,11 @@ non-alphanumeric character, it takes away any special meaning that character may have. This use of backslash as an escape character applies both inside and outside character classes.</p> -<p>For example, if you want to match a * character, you write \\* in the pattern. +<p>For example, if you want to match a * character, you write \* in the pattern. This escaping action applies whether or not the following character would otherwise be interpreted as a metacharacter, so it is always safe to precede a non-alphanumeric with backslash to specify that it stands for itself. In -particular, if you want to match a backslash, you write \\\\.</p> +particular, if you want to match a backslash, you write \\.</p> <p>If a pattern is compiled with the <c>extended</c> option, whitespace in the pattern (other than in a character class) and characters between a # outside @@ -951,18 +951,18 @@ a character class and the next newline are ignored. An escaping backslash can be used to include a whitespace or # character as part of the pattern.</p> <p>If you want to remove the special meaning from a sequence of characters, you -can do so by putting them between \\Q and \\E. This is different from Perl in -that $ and @ are handled as literals in \\Q...\\E sequences in PCRE, whereas in +can do so by putting them between \Q and \E. This is different from Perl in +that $ and @ are handled as literals in \Q...\E sequences in PCRE, whereas in Perl, $ and @ cause variable interpolation. Note the following examples:</p> <code type="none"> Pattern PCRE matches Perl matches - \\Qabc$xyz\\E abc$xyz abc followed by the contents of $xyz - \\Qabc\\$xyz\\E abc\\$xyz abc\\$xyz - \\Qabc\\E\\$\\Qxyz\\E abc$xyz abc$xyz</code> + \Qabc$xyz\E abc$xyz abc followed by the contents of $xyz + \Qabc\$xyz\E abc\$xyz abc\$xyz + \Qabc\E\$\Qxyz\E abc$xyz abc$xyz</code> -<p>The \\Q...\\E sequence is recognized both inside and outside character classes.</p> +<p>The \Q...\E sequence is recognized both inside and outside character classes.</p> <p><em>Non-printing characters</em></p> @@ -975,41 +975,41 @@ use one of the following escape sequences than the binary character it represents:</p> <taglist> - <tag>\\a</tag> <item>alarm, that is, the BEL character (hex 07)</item> - <tag>\\cx</tag> <item>"control-x", where x is any character</item> - <tag>\\e </tag> <item>escape (hex 1B)</item> - <tag>\\f</tag> <item>formfeed (hex 0C)</item> - <tag>\\n</tag> <item>linefeed (hex 0A)</item> - <tag>\\r</tag> <item>carriage return (hex 0D)</item> - <tag>\\t </tag> <item>tab (hex 09)</item> - <tag>\\ddd</tag> <item>character with octal code ddd, or backreference</item> - <tag>\\xhh </tag> <item>character with hex code hh</item> - <tag>\\x{hhh..}</tag> <item>character with hex code hhh..</item> + <tag>\a</tag> <item>alarm, that is, the BEL character (hex 07)</item> + <tag>\cx</tag> <item>"control-x", where x is any character</item> + <tag>\e </tag> <item>escape (hex 1B)</item> + <tag>\f</tag> <item>formfeed (hex 0C)</item> + <tag>\n</tag> <item>linefeed (hex 0A)</item> + <tag>\r</tag> <item>carriage return (hex 0D)</item> + <tag>\t </tag> <item>tab (hex 09)</item> + <tag>\ddd</tag> <item>character with octal code ddd, or backreference</item> + <tag>\xhh </tag> <item>character with hex code hh</item> + <tag>\x{hhh..}</tag> <item>character with hex code hhh..</item> </taglist> -<p>The precise effect of \\cx is as follows: if x is a lower case letter, it +<p>The precise effect of \cx is as follows: if x is a lower case letter, it is converted to upper case. Then bit 6 of the character (hex 40) is inverted. -Thus \\cz becomes hex 1A, but \\c{ becomes hex 3B, while \\c; becomes hex +Thus \cz becomes hex 1A, but \c{ becomes hex 3B, while \c; becomes hex 7B.</p> -<p>After \\x, from zero to two hexadecimal digits are read (letters can be in -upper or lower case). Any number of hexadecimal digits may appear between \\x{ +<p>After \x, from zero to two hexadecimal digits are read (letters can be in +upper or lower case). Any number of hexadecimal digits may appear between \x{ and }, but the value of the character code must be less than 256 in non-UTF-8 mode, and less than 2**31 in UTF-8 mode. That is, the maximum value in hexadecimal is 7FFFFFFF. Note that this is bigger than the largest Unicode code point, which is 10FFFF.</p> -<p>If characters other than hexadecimal digits appear between \\x{ and }, or if +<p>If characters other than hexadecimal digits appear between \x{ and }, or if there is no terminating }, this form of escape is not recognized. Instead, the -initial \\x will be interpreted as a basic hexadecimal escape, with no +initial \x will be interpreted as a basic hexadecimal escape, with no following digits, giving a character whose value is zero.</p> <p>Characters whose value is less than 256 can be defined by either of the two -syntaxes for \\x. There is no difference in the way they are handled. For -example, \\xdc is exactly the same as \\x{dc}.</p> +syntaxes for \x. There is no difference in the way they are handled. For +example, \xdc is exactly the same as \x{dc}.</p> -<p>After \\0 up to two further octal digits are read. If there are fewer than two -digits, just those that are present are used. Thus the sequence \\0\\x\\07 +<p>After \0 up to two further octal digits are read. If there are fewer than two +digits, just those that are present are used. Thus the sequence \0\x\07 specifies two binary zeros followed by a BEL character (code value 7). Make sure you supply two digits after the initial zero if the pattern character that follows is itself an octal digit.</p> @@ -1027,32 +1027,32 @@ have not been that many capturing subpatterns, PCRE re-reads up to three octal digits following the backslash, and uses them to generate a data character. Any subsequent digits stand for themselves. The value of a -character specified in octal must be less than \\400. +character specified in octal must be less than \400. In non-UTF-8 mode, the value of a -character specified in octal must be less than \\400. In UTF-8 mode, values up -to \\777 are permitted. +character specified in octal must be less than \400. In UTF-8 mode, values up +to \777 are permitted. For example:</p> <taglist> - <tag>\\040</tag> <item>is another way of writing a space</item> + <tag>\040</tag> <item>is another way of writing a space</item> - <tag>\\40</tag> <item>is the same, provided there are fewer than 40 + <tag>\40</tag> <item>is the same, provided there are fewer than 40 previous capturing subpatterns</item> - <tag>\\7</tag> <item>is always a back reference</item> + <tag>\7</tag> <item>is always a back reference</item> - <tag>\\11</tag> <item> might be a back reference, or another way of + <tag>\11</tag> <item> might be a back reference, or another way of writing a tab</item> - <tag>\\011</tag> <item>is always a tab</item> - <tag>\\0113</tag> <item>is a tab followed by the character "3"</item> + <tag>\011</tag> <item>is always a tab</item> + <tag>\0113</tag> <item>is a tab followed by the character "3"</item> - <tag>\\113</tag> <item>might be a back reference, otherwise the + <tag>\113</tag> <item>might be a back reference, otherwise the character with octal code 113</item> - <tag>\\377</tag> <item>might be a back reference, otherwise + <tag>\377</tag> <item>might be a back reference, otherwise the byte consisting entirely of 1 bits</item> - <tag>\\81</tag> <item>is either a back reference, or a binary zero + <tag>\81</tag> <item>is either a back reference, or a binary zero followed by the two characters "8" and "1"</item> </taglist> @@ -1062,16 +1062,16 @@ read.</p> <p>All the sequences that define a single character value can be used both inside and outside character classes. In addition, inside a -character class, the sequence \\b is interpreted as the backspace -character (hex 08), and the sequences \\R and \\X are interpreted as +character class, the sequence \b is interpreted as the backspace +character (hex 08), and the sequences \R and \X are interpreted as the characters "R" and "X", respectively. Outside a character class, these sequences have different meanings (see below).</p> <p><em>Absolute and relative back references</em></p> -<p>The sequence \\g followed by an unsigned or a negative number, +<p>The sequence \g followed by an unsigned or a negative number, optionally enclosed in braces, is an absolute or relative back -reference. A named back reference can be coded as \\g{name}. Back +reference. A named back reference can be coded as \g{name}. Back references are discussed later, following the discussion of parenthesized subpatterns.</p> @@ -1081,16 +1081,16 @@ parenthesized subpatterns.</p> following are always recognized:</p> <taglist> - <tag>\\d</tag> <item>any decimal digit</item> - <tag>\\D</tag> <item>any character that is not a decimal digit</item> - <tag>\\h</tag> <item>any horizontal whitespace character</item> - <tag>\\H</tag> <item>any character that is not a horizontal whitespace character</item> - <tag>\\s</tag> <item>any whitespace character</item> - <tag>\\S</tag> <item>any character that is not a whitespace character</item> - <tag>\\v</tag> <item>any vertical whitespace character</item> - <tag>\\V</tag> <item>any character that is not a vertical whitespace character</item> - <tag>\\w</tag> <item>any "word" character</item> - <tag>\\W</tag> <item>any "non-word" character</item> + <tag>\d</tag> <item>any decimal digit</item> + <tag>\D</tag> <item>any character that is not a decimal digit</item> + <tag>\h</tag> <item>any horizontal whitespace character</item> + <tag>\H</tag> <item>any character that is not a horizontal whitespace character</item> + <tag>\s</tag> <item>any whitespace character</item> + <tag>\S</tag> <item>any character that is not a whitespace character</item> + <tag>\v</tag> <item>any vertical whitespace character</item> + <tag>\V</tag> <item>any character that is not a vertical whitespace character</item> + <tag>\w</tag> <item>any "word" character</item> + <tag>\W</tag> <item>any "non-word" character</item> </taglist> <p>Each pair of escape sequences partitions the complete set of characters into @@ -1101,19 +1101,19 @@ classes. They each match one character of the appropriate type. If the current matching point is at the end of the subject string, all of them fail, since there is no character to match.</p> -<p>For compatibility with Perl, \\s does not match the VT character (code 11). -This makes it different from the POSIX "space" class. The \\s characters +<p>For compatibility with Perl, \s does not match the VT character (code 11). +This makes it different from the POSIX "space" class. The \s characters are HT (9), LF (10), FF (12), CR (13), and space (32). If "use locale;" is -included in a Perl script, \\s may match the VT character. In PCRE, it never +included in a Perl script, \s may match the VT character. In PCRE, it never does.</p> -<p>In UTF-8 mode, characters with values greater than 128 never match \\d, \\s, or -\\w, and always match \\D, \\S, and \\W. This is true even when Unicode +<p>In UTF-8 mode, characters with values greater than 128 never match \d, \s, or +\w, and always match \D, \S, and \W. This is true even when Unicode character property support is available. These sequences retain their original meanings from before UTF-8 support was available, mainly for efficiency reasons.</p> -<p>The sequences \\h, \\H, \\v, and \\V are Perl 5.10 features. In contrast to the +<p>The sequences \h, \H, \v, and \V are Perl 5.10 features. In contrast to the other sequences, these do match certain high-valued codepoints in UTF-8 mode. The horizontal space characters are:</p> @@ -1157,11 +1157,11 @@ low-valued character tables, which are always ISO-8859-1.</p> <p><em>Newline sequences</em></p> -<p>Outside a character class, by default, the escape sequence \\R matches any -Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8 mode \\R is +<p>Outside a character class, by default, the escape sequence \R matches any +Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8 mode \R is equivalent to the following:</p> -<quote><p> (?>\\r\\n|\\n|\\x0b|\\f|\\r|\\x85)</p></quote> +<quote><p> (?>\r\n|\n|\x0b|\f|\r|\x85)</p></quote> <p>This is an example of an "atomic group", details of which are given below.</p> @@ -1177,7 +1177,7 @@ Unicode character property support is not needed for these characters to be recognized.</p> -<p>It is possible to restrict \\R to match only CR, LF, or CRLF (instead of the +<p>It is possible to restrict \R to match only CR, LF, or CRLF (instead of the complete set of Unicode line endings) by setting the option <c>bsr_anycrlf</c> either at compile time or when the pattern is matched. (BSR is an abbreviation for "backslash R".) This can be made the default when PCRE is built; if this is @@ -1197,7 +1197,7 @@ newline convention, for example, a pattern can start with:</p> <p> (*ANY)(*BSR_ANYCRLF)</p> -<p>Inside a character class, \\R matches the letter "R".</p> +<p>Inside a character class, \R matches the letter "R".</p> <p><em>Unicode character properties</em></p> @@ -1208,22 +1208,22 @@ When not in UTF-8 mode, these sequences are of course limited to testing characters whose codepoints are less than 256, but they do work in this mode. The extra escape sequences are:</p> -<p> \\p{<em>xx</em>} a character with the <em>xx</em> property - \\P{<em>xx</em>} a character without the <em>xx</em> property - \\X an extended Unicode sequence</p> +<p> \p{<em>xx</em>} a character with the <em>xx</em> property + \P{<em>xx</em>} a character without the <em>xx</em> property + \X an extended Unicode sequence</p> <p>The property names represented by <em>xx</em> above are limited to the Unicode script names, the general category properties, and "Any", which matches any character (including newline). Other properties such as "InMusicalSymbols" are -not currently supported by PCRE. Note that \\P{Any} does not match any +not currently supported by PCRE. Note that \P{Any} does not match any characters, so always causes a match failure.</p> <p>Sets of Unicode characters are defined as belonging to certain scripts. A character from one of these sets can be matched using a script name. For example:</p> -<p> \\p{Greek} - \\P{Han}</p> +<p> \p{Greek} + \P{Han}</p> <p>Those that are not part of an identified script are lumped together as "Common". The current list of scripts is:</p> @@ -1300,15 +1300,15 @@ example:</p> <p>Each character has exactly one general category property, specified by a two-letter abbreviation. For compatibility with Perl, negation can be specified by including a circumflex between the opening brace and the property name. For -example, \\p{^Lu} is the same as \\P{Lu}.</p> +example, \p{^Lu} is the same as \P{Lu}.</p> -<p>If only one letter is specified with \\p or \\P, it includes all the general +<p>If only one letter is specified with \p or \P, it includes all the general category properties that start with that letter. In this case, in the absence of negation, the curly brackets in the escape sequence are optional; these two examples have the same effect:</p> -<list><item>\\p{L}</item> - <item>\\pL</item></list> +<list><item>\p{L}</item> + <item>\pL</item></list> <p>The following general category property codes are supported:</p> @@ -1382,7 +1382,7 @@ cannot be tested by PCRE, unless UTF-8 validity checking has been turned off <em>pcreapi</em> page).</p> -<p>The long synonyms for these properties that Perl supports (such as \\p{Letter}) +<p>The long synonyms for these properties that Perl supports (such as \p{Letter}) are not supported by PCRE, nor is it permitted to prefix any of these properties with "Is".</p> @@ -1391,12 +1391,12 @@ Instead, this property is assumed for any code point that is not in the Unicode table.</p> <p>Specifying caseless matching does not affect these escape sequences. For -example, \\p{Lu} always matches only upper case letters.</p> +example, \p{Lu} always matches only upper case letters.</p> -<p>The \\X escape matches any number of Unicode characters that form an extended -Unicode sequence. \\X is equivalent to</p> +<p>The \X escape matches any number of Unicode characters that form an extended +Unicode sequence. \X is equivalent to</p> -<quote><p> (?>\\PM\\pM*)</p></quote> +<quote><p> (?>\PM\pM*)</p></quote> <p>That is, it matches a character without the "mark" property, followed by zero or more characters with the "mark" property, and treats the sequence as an @@ -1404,20 +1404,20 @@ atomic group (see below). Characters with the "mark" property are typically accents that affect the preceding character. None of them have codepoints less than 256, so in -non-UTF-8 mode \\X matches any one character.</p> +non-UTF-8 mode \X matches any one character.</p> <p>Matching characters by Unicode property is not fast, because PCRE has to search a structure that contains data for over fifteen thousand characters. That is -why the traditional escape sequences such as \\d and \\w do not use Unicode +why the traditional escape sequences such as \d and \w do not use Unicode properties in PCRE.</p> <p><em>Resetting the match start</em></p> -<p>The escape sequence \\K, which is a Perl 5.10 feature, causes any previously +<p>The escape sequence \K, which is a Perl 5.10 feature, causes any previously matched characters not to be included in the final matched sequence. For example, the pattern:</p> -<quote><p> foo\\Kbar</p></quote> +<quote><p> foo\Kbar</p></quote> <p>matches "foobar", but reports that it has matched "bar". This feature is similar to a lookbehind assertion @@ -1426,12 +1426,12 @@ similar to a lookbehind assertion (described below). However, in this case, the part of the subject before the real match does not -have to be of fixed length, as lookbehind assertions do. The use of \\K does +have to be of fixed length, as lookbehind assertions do. The use of \K does not interfere with the setting of captured substrings. For example, when the pattern</p> -<quote><p> (foo)\\Kbar</p></quote> +<quote><p> (foo)\Kbar</p></quote> <p>matches "foobar", the first substring is still set to "foo".</p> @@ -1444,50 +1444,50 @@ string. The use of subpatterns for more complicated assertions is described below. The backslashed assertions are:</p> <taglist> - <tag>\\b</tag> <item>matches at a word boundary</item> - <tag>\\B</tag> <item>matches when not at a word boundary</item> - <tag>\\A</tag> <item>matches at the start of the subject</item> - <tag>\\Z</tag> <item>matches at the end of the subject + <tag>\b</tag> <item>matches at a word boundary</item> + <tag>\B</tag> <item>matches when not at a word boundary</item> + <tag>\A</tag> <item>matches at the start of the subject</item> + <tag>\Z</tag> <item>matches at the end of the subject also matches before a newline at the end of the subject</item> - <tag>\\z</tag> <item>matches only at the end of the subject</item> - <tag>\\G</tag> <item>matches at the first matching position in the + <tag>\z</tag> <item>matches only at the end of the subject</item> + <tag>\G</tag> <item>matches at the first matching position in the subject</item> </taglist> -<p>These assertions may not appear in character classes (but note that \\b has a +<p>These assertions may not appear in character classes (but note that \b has a different meaning, namely the backspace character, inside a character class).</p> <p>A word boundary is a position in the subject string where the current character -and the previous character do not both match \\w or \\W (i.e. one matches -\\w and the other matches \\W), or the start or end of the string if the -first or last character matches \\w, respectively.</p> +and the previous character do not both match \w or \W (i.e. one matches +\w and the other matches \W), or the start or end of the string if the +first or last character matches \w, respectively.</p> -<p>The \\A, \\Z, and \\z assertions differ from the traditional circumflex and +<p>The \A, \Z, and \z assertions differ from the traditional circumflex and dollar (described in the next section) in that they only ever match at the very start and end of the subject string, whatever options are set. Thus, they are independent of multiline mode. These three assertions are not affected by the <c>notbol</c> or <c>noteol</c> options, which affect only the behaviour of the circumflex and dollar metacharacters. However, if the <em>startoffset</em> argument of <c>re:run/3</c> is non-zero, indicating that matching is to start -at a point other than the beginning of the subject, \\A can never match. The -difference between \\Z and \\z is that \\Z matches before a newline at the end -of the string as well as at the very end, whereas \\z matches only at the end.</p> +at a point other than the beginning of the subject, \A can never match. The +difference between \Z and \z is that \Z matches before a newline at the end +of the string as well as at the very end, whereas \z matches only at the end.</p> -<p>The \\G assertion is true only when the current matching position is at the +<p>The \G assertion is true only when the current matching position is at the start point of the match, as specified by the <em>startoffset</em> argument of -<c>re:run/3</c>. It differs from \\A when the value of <em>startoffset</em> is +<c>re:run/3</c>. It differs from \A when the value of <em>startoffset</em> is non-zero. By calling <c>re:run/3</c> multiple times with appropriate arguments, you can mimic Perl's /g option, and it is in this kind of -implementation where \\G can be useful.</p> +implementation where \G can be useful.</p> -<p>Note, however, that PCRE's interpretation of \\G, as the start of the current +<p>Note, however, that PCRE's interpretation of \G, as the start of the current match, is subtly different from Perl's, which defines it as the end of the previous match. In Perl, these can be different when the previously matched string was empty. Because PCRE does just one match at a time, it cannot reproduce this behaviour.</p> -<p>If all the alternatives of a pattern begin with \\G, the expression is anchored +<p>If all the alternatives of a pattern begin with \G, the expression is anchored to the starting match position, and the "anchored" flag is set in the compiled regular expression.</p> @@ -1519,7 +1519,7 @@ character class.</p> <p>The meaning of dollar can be changed so that it matches only at the very end of the string, by setting the <c>dollar_endonly</c> option at -compile time. This does not affect the \\Z assertion.</p> +compile time. This does not affect the \Z assertion.</p> <p>The meanings of the circumflex and dollar characters are changed if the <c>multiline</c> option is set. When this is the case, a circumflex matches @@ -1530,16 +1530,16 @@ matches before any newlines in the string, as well as at the very end, when sequence CRLF, isolated CR and LF characters do not indicate newlines.</p> <p>For example, the pattern /^abc$/ matches the subject string -"def\\nabc" (where \\n represents a newline) in multiline mode, but +"def\nabc" (where \n represents a newline) in multiline mode, but not otherwise. Consequently, patterns that are anchored in single line mode because all branches start with ^ are not anchored in multiline mode, and a match for circumflex is possible when the <em>startoffset</em> argument of <c>re:run/3</c> is non-zero. The <c>dollar_endonly</c> option is ignored if <c>multiline</c> is set.</p> -<p>Note that the sequences \\A, \\Z, and \\z can be used to match the start and +<p>Note that the sequences \A, \Z, and \z can be used to match the start and end of the subject in both modes, and if all branches of a pattern start with -\\A it is always anchored, whether or not <c>multiline</c> is set.</p> +\A it is always anchored, whether or not <c>multiline</c> is set.</p> </section> @@ -1574,14 +1574,14 @@ involve newlines. Dot has no special meaning in a character class.</p> <section><marker id="sect6"></marker><title>Matching a single byte</title> -<p>Outside a character class, the escape sequence \\C matches any one byte, both +<p>Outside a character class, the escape sequence \C matches any one byte, both in and out of UTF-8 mode. Unlike a dot, it always matches any line-ending characters. The feature is provided in Perl in order to match individual bytes in UTF-8 mode. Because it breaks up UTF-8 characters into individual bytes, what remains in the string may be a malformed UTF-8 string. For this reason, -the \\C escape sequence is best avoided.</p> +the \C escape sequence is best avoided.</p> -<p>PCRE does not allow \\C to appear in lookbehind assertions (described below), +<p>PCRE does not allow \C to appear in lookbehind assertions (described below), because in UTF-8 mode this would make it impossible to calculate the length of the lookbehind.</p> @@ -1615,7 +1615,7 @@ string, and therefore it fails if the current pointer is at the end of the string.</p> <p>In UTF-8 mode, characters with values greater than 255 can be included in a -class as a literal string of bytes, or by using the \\x{ escaping mechanism.</p> +class as a literal string of bytes, or by using the \x{ escaping mechanism.</p> <p>When caseless matching is set, any letters in a class represent both their upper case and lower case versions, so for example, a caseless [aeiou] matches @@ -1648,32 +1648,32 @@ character of a range. A pattern such as [W-]46] is interpreted as a class of two characters ("W" and "-") followed by a literal string "46]", so it would match "W46]" or "-46]". However, if the "]" is escaped with a backslash it is interpreted as the end of range, so -[W-\\]46] is interpreted as a class containing a range followed by two +[W-\]46] is interpreted as a class containing a range followed by two other characters. The octal or hexadecimal representation of "]" can also be used to end a range.</p> <p>Ranges operate in the collating sequence of character values. They can also be -used for characters specified numerically, for example [\\000-\\037]. +used for characters specified numerically, for example [\000-\037]. In UTF-8 mode, ranges can include characters whose values are greater than 255, for -example [\\x{100}-\\x{2ff}]. +example [\x{100}-\x{2ff}]. </p> <p>If a range that includes letters is used when caseless matching is set, it matches the letters in either case. For example, [W-c] is equivalent to -[][\\\\^_`wxyzabc], matched caselessly +[][\\^_`wxyzabc], matched caselessly , and in non-UTF-8 mode, if character -tables for a French locale are in use, [\\xc8-\\xcb] matches accented E +tables for a French locale are in use, [\xc8-\xcb] matches accented E characters in both cases. In UTF-8 mode, PCRE supports the concept of case for characters with values greater than 128 only when it is compiled with Unicode property support.</p> -<p>The character types \\d, \\D, \\p, \\P, \\s, \\S, \\w, and \\W may +<p>The character types \d, \D, \p, \P, \s, \S, \w, and \W may also appear in a character class, and add the characters that they -match to the class. For example, [\\dABCDEF] matches any hexadecimal +match to the class. For example, [\dABCDEF] matches any hexadecimal digit. A circumflex can conveniently be used with the upper case character types to specify a more restricted set of characters than -the matching lower case type. For example, the class [^\\W_] matches +the matching lower case type. For example, the class [^\W_] matches any letter or digit, but not underscore.</p> <p>The only metacharacters that are recognized in character classes @@ -1702,20 +1702,20 @@ are</p> <tag>ascii</tag> <item>character codes 0 - 127</item> <tag>blank</tag> <item>space or tab only</item> <tag>cntrl</tag> <item>control characters</item> - <tag>digit</tag> <item>decimal digits (same as \\d)</item> + <tag>digit</tag> <item>decimal digits (same as \d)</item> <tag>graph</tag> <item>printing characters, excluding space</item> <tag>lower</tag> <item>lower case letters</item> <tag>print</tag> <item>printing characters, including space</item> <tag>punct</tag> <item>printing characters, excluding letters and digits</item> - <tag>space</tag> <item>whitespace (not quite the same as \\s)</item> + <tag>space</tag> <item>whitespace (not quite the same as \s)</item> <tag>upper</tag> <item>upper case letters</item> - <tag>word</tag> <item>"word" characters (same as \\w)</item> + <tag>word</tag> <item>"word" characters (same as \w)</item> <tag>xdigit</tag> <item>hexadecimal digits</item> </taglist> <p>The "space" characters are HT (9), LF (10), VT (11), FF (12), CR (13), and space (32). Notice that this list includes the VT character (code 11). This -makes "space" different to \\s, which does not include VT (for Perl +makes "space" different to \s, which does not include VT (for Perl compatibility).</p> <p>The name "word" is a Perl extension, and "blank" is a GNU extension @@ -1936,7 +1936,7 @@ match. Suppose you want to match the name of a weekday, either as a 3-letter abbreviation or as the full name, and in both cases you want to extract the abbreviation. This pattern (ignoring the line breaks) does the job:</p> -<code type="none"> +<code type="none"> (?<DN>Mon|Fri|Sun)(?:day)?| (?<DN>Tue)(?:sday)?| (?<DN>Wed)(?:nesday)?| @@ -1972,12 +1972,12 @@ following items:</p> <list> <item>a literal data character</item> <item>the dot metacharacter</item> - <item>the \\C escape sequence</item> - <item>the \\X escape sequence + <item>the \C escape sequence</item> + <item>the \X escape sequence (in UTF-8 mode with Unicode properties) </item> - <item>the \\R escape sequence</item> - <item>an escape such as \\d that matches a single character</item> + <item>the \R escape sequence</item> + <item>an escape such as \d that matches a single character</item> <item>a character class</item> <item>a back reference (see next section)</item> <item>a parenthesized subpattern (unless it is an assertion)</item> @@ -1999,7 +1999,7 @@ quantifier specifies an exact number of required matches. Thus</p> <p>matches at least 3 successive vowels, but may match many more, while</p> -<quote><p> \\d{8}</p></quote> +<quote><p> \d{8}</p></quote> <p>matches exactly 8 digits. An opening curly bracket that appears in a position where a quantifier is not allowed, or one that does not match the syntax of a @@ -2007,9 +2007,9 @@ quantifier, is taken as a literal character. For example, {,6} is not a quantifier, but a literal string of four characters.</p> <p>In UTF-8 mode, quantifiers apply to UTF-8 characters rather than to individual -bytes. Thus, for example, \\x{100}{2} matches two UTF-8 characters, each of +bytes. Thus, for example, \x{100}{2} matches two UTF-8 characters, each of which is represented by a two-byte sequence. Similarly, when Unicode property -support is available, \\X{3} matches three Unicode extended sequences, each of +support is available, \X{3} matches three Unicode extended sequences, each of which may be several bytes long (and they may be of different lengths).</p> <p>The quantifier {0} is permitted, causing the expression to behave as if the @@ -2042,7 +2042,7 @@ is in trying to match comments in C programs. These appear between /* and */ and within the comment, individual * and / characters may appear. An attempt to match C comments by applying the pattern</p> -<quote><p> /\\*.*\\*/</p></quote> +<quote><p> /\*.*\*/</p></quote> <p>to the string</p> @@ -2055,14 +2055,14 @@ item.</p> greedy, and instead matches the minimum number of times possible, so the pattern</p> -<quote><p> /\\*.*?\\*/</p></quote> +<quote><p> /\*.*?\*/</p></quote> <p>does the right thing with the C comments. The meaning of the various quantifiers is not otherwise changed, just the preferred number of matches. Do not confuse this use of question mark with its use as a quantifier in its own right. Because it has two uses, it can sometimes appear doubled, as in</p> -<quote><p> \\d??\\d</p></quote> +<quote><p> \d??\d</p></quote> <p>which matches one digit by preference, but can match two if that is the only way the rest of the pattern matches.</p> @@ -2081,7 +2081,7 @@ to Perl's /s) is set, thus allowing the dot to match newlines, the pattern is implicitly anchored, because whatever follows will be tried against every character position in the subject string, so there is no point in retrying the overall match at any position after the first. PCRE normally treats such a -pattern as though it were preceded by \\A.</p> +pattern as though it were preceded by \A.</p> <p>In cases where it is known that the subject string contains no newlines, it is worth setting <c>dotall</c> in order to obtain this optimization, or @@ -2092,7 +2092,7 @@ is inside capturing parentheses that are the subject of a backreference elsewhere in the pattern, a match at the start may fail where a later one succeeds. Consider, for example:</p> -<quote><p> (.*)abc\\1</p></quote> +<quote><p> (.*)abc\1</p></quote> <p>If the subject is "xyz123abc123" the match point is the fourth character. For this reason, such a pattern is not implicitly anchored.</p> @@ -2100,7 +2100,7 @@ this reason, such a pattern is not implicitly anchored.</p> <p>When a capturing subpattern is repeated, the value captured is the substring that matched the final iteration. For example, after</p> -<quote><p> (tweedle[dume]{3}\\s*)+</p></quote> +<quote><p> (tweedle[dume]{3}\s*)+</p></quote> <p>has matched "tweedledum tweedledee" the value of the captured substring is "tweedledee". However, if there are nested capturing subpatterns, the @@ -2123,12 +2123,12 @@ pattern to match. Sometimes it is useful to prevent this, either to change the nature of the match, or to cause it fail earlier than it otherwise might, when the author of the pattern knows there is no point in carrying on.</p> -<p>Consider, for example, the pattern \\d+foo when applied to the subject line</p> +<p>Consider, for example, the pattern \d+foo when applied to the subject line</p> <quote><p> 123456bar</p></quote> <p>After matching all 6 digits and then failing to match "foo", the normal -action of the matcher is to try again with only 5 digits matching the \\d+ +action of the matcher is to try again with only 5 digits matching the \d+ item, and then with 4, and so on, before ultimately failing. "Atomic grouping" (a term taken from Jeffrey Friedl's book) provides the means for specifying that once a subpattern has matched, it is not to be re-evaluated in this way.</p> @@ -2137,7 +2137,7 @@ that once a subpattern has matched, it is not to be re-evaluated in this way.</p immediately on failing to match "foo" the first time. The notation is a kind of special parenthesis, starting with (?> as in this example:</p> -<quote><p> (?>\\d+)foo</p></quote> +<quote><p> (?>\d+)foo</p></quote> <p>This kind of parenthesis "locks up" the part of the pattern it contains once it has matched, and a failure further into the pattern is prevented from @@ -2150,9 +2150,9 @@ the current point in the subject string.</p> <p>Atomic grouping subpatterns are not capturing subpatterns. Simple cases such as the above example can be thought of as a maximizing repeat that must swallow -everything it can. So, while both \\d+ and \\d+? are prepared to adjust the +everything it can. So, while both \d+ and \d+? are prepared to adjust the number of digits they match in order to make the rest of the pattern match, -(?>\\d+) can only match an entire sequence of digits.</p> +(?>\d+) can only match an entire sequence of digits.</p> <p>Atomic groups in general can of course contain arbitrarily complicated subpatterns, and can be nested. However, when the subpattern for an atomic @@ -2161,7 +2161,7 @@ notation, called a "possessive quantifier" can be used. This consists of an additional + character following a quantifier. Using this notation, the previous example can be rewritten as</p> -<quote><p> \\d++foo</p></quote> +<quote><p> \d++foo</p></quote> <p>Note that a possessive quantifier can be used with an entire group, for example:</p> @@ -2189,7 +2189,7 @@ be repeated an unlimited number of times, the use of an atomic group is the only way to avoid some failing matches taking a very long time indeed. The pattern</p> -<quote><p> (\\D+|<\\d+>)*[!?]</p></quote> +<quote><p> (\D+|<\d+>)*[!?]</p></quote> <p>matches an unlimited number of substrings that either consist of non-digits, or digits enclosed in <>, followed by either ! or ?. When it matches, it runs @@ -2198,7 +2198,7 @@ quickly. However, if it is applied to</p> <quote><p> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></quote> <p>it takes a long time before reporting failure. This is because the string can -be divided between the internal \\D+ repeat and the external * repeat in a +be divided between the internal \D+ repeat and the external * repeat in a large number of ways, and all have to be tried. (The example uses [!?] rather than a single character at the end, because both PCRE and Perl have an optimization that allows for fast failure when a single character is used. They @@ -2206,7 +2206,7 @@ remember the last single character that is required for a match, and fail early if it is not present in the string.) If the pattern is changed so that it uses an atomic group, like this:</p> -<quote><p> ((?>\\D+)|<\\d+>)*[!?]</p></quote> +<quote><p> ((?>\D+)|<\d+>)*[!?]</p></quote> <p>sequences of non-digits cannot be broken, and failure happens quickly.</p> @@ -2229,22 +2229,22 @@ in an earlier iteration.</p> <p>It is not possible to have a numerical "forward back reference" to a subpattern whose number is 10 or more using this syntax because a -sequence such as \\50 is interpreted as a character defined in +sequence such as \50 is interpreted as a character defined in octal. See the subsection entitled "Non-printing characters" above for further details of the handling of digits following a backslash. There is no such problem when named parentheses are used. A back reference to any subpattern is possible using named parentheses (see below).</p> <p>Another way of avoiding the ambiguity inherent in the use of digits -following a backslash is to use the \\g escape sequence, which is a +following a backslash is to use the \g escape sequence, which is a feature introduced in Perl 5.10. This escape must be followed by an unsigned number or a negative number, optionally enclosed in braces. These examples are all identical:</p> <list> - <item>(ring), \\1</item> - <item>(ring), \\g1</item> - <item>(ring), \\g{1}</item> + <item>(ring), \1</item> + <item>(ring), \g1</item> + <item>(ring), \g{1}</item> </list> <p>An unsigned number specifies an absolute reference without the @@ -2252,11 +2252,11 @@ ambiguity that is present in the older syntax. It is also useful when literal digits follow the reference. A negative number is a relative reference. Consider this example:</p> -<quote><p> (abc(def)ghi)\\g{-1}</p></quote> +<quote><p> (abc(def)ghi)\g{-1}</p></quote> -<p>The sequence \\g{-1} is a reference to the most recently started capturing -subpattern before \\g, that is, is it equivalent to \\2. Similarly, \\g{-2} -would be equivalent to \\1. The use of relative references can be helpful in +<p>The sequence \g{-1} is a reference to the most recently started capturing +subpattern before \g, that is, is it equivalent to \2. Similarly, \g{-2} +would be equivalent to \1. The use of relative references can be helpful in long patterns, and also in patterns that are created by joining together fragments that contain references within themselves.</p> @@ -2265,29 +2265,29 @@ subpattern in the current subject string, rather than anything matching the subpattern itself (see "Subpatterns as subroutines" below for a way of doing that). So the pattern</p> -<quote><p> (sens|respons)e and \\1ibility</p></quote> +<quote><p> (sens|respons)e and \1ibility</p></quote> <p>matches "sense and sensibility" and "response and responsibility", but not "sense and responsibility". If caseful matching is in force at the time of the back reference, the case of letters is relevant. For example,</p> -<quote><p> ((?i)rah)\\s+\\1</p></quote> +<quote><p> ((?i)rah)\s+\1</p></quote> <p>matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capturing subpattern is matched caselessly.</p> <p>There are several different ways of writing back references to named -subpatterns. The .NET syntax \\k{name} and the Perl syntax \\k<name> or -\\k'name' are supported, as is the Python syntax (?P=name). Perl 5.10's unified -back reference syntax, in which \\g can be used for both numeric and named +subpatterns. The .NET syntax \k{name} and the Perl syntax \k<name> or +\k'name' are supported, as is the Python syntax (?P=name). Perl 5.10's unified +back reference syntax, in which \g can be used for both numeric and named references, is also supported. We could rewrite the above example in any of the following ways:</p> <list> - <item>(?<p1>(?i)rah)\\s+\\k<p1></item> - <item>(?'p1'(?i)rah)\\s+\\k{p1}</item> - <item>(?P<p1>(?i)rah)\\s+(?P=p1)</item> - <item>(?<p1>(?i)rah)\\s+\\g{p1}</item> + <item>(?<p1>(?i)rah)\s+\k<p1></item> + <item>(?'p1'(?i)rah)\s+\k{p1}</item> + <item>(?P<p1>(?i)rah)\s+(?P=p1)</item> + <item>(?<p1>(?i)rah)\s+\g{p1}</item> </list> <p>A subpattern that is referenced by name may appear in the pattern before or @@ -2297,7 +2297,7 @@ after the reference.</p> subpattern has not actually been used in a particular match, any back references to it always fail. For example, the pattern</p> -<quote><p> (a|(bc))\\2</p></quote> +<quote><p> (a|(bc))\2</p></quote> <p>always fails if it starts to match "a" rather than "bc". Because there may be many capturing parentheses in a pattern, all digits @@ -2308,11 +2308,11 @@ some delimiter must be used to terminate the back reference. If the empty comment (see "Comments" below) can be used.</p> <p>A back reference that occurs inside the parentheses to which it refers fails -when the subpattern is first used, so, for example, (a\\1) never matches. +when the subpattern is first used, so, for example, (a\1) never matches. However, such references can be useful inside repeated subpatterns. For example, the pattern</p> -<quote><p> (a|b\\1)+</p></quote> +<quote><p> (a|b\1)+</p></quote> <p>matches any number of "a"s and also "aba", "ababbaa" etc. At each iteration of the subpattern, the back reference matches the character string corresponding @@ -2327,7 +2327,7 @@ minimum of zero.</p> <p>An assertion is a test on the characters following or preceding the current matching point that does not actually consume any characters. The simple -assertions coded as \\b, \\B, \\A, \\G, \\Z, \\z, ^ and $ are described +assertions coded as \b, \B, \A, \G, \Z, \z, ^ and $ are described above.</p> @@ -2348,7 +2348,7 @@ because it does not make sense for negative assertions.</p> <p>Lookahead assertions start with (?= for positive assertions and (?! for negative assertions. For example,</p> -<quote><p> \\w+(?=;)</p></quote> +<quote><p> \w+(?=;)</p></quote> <p>matches a word followed by a semicolon, but does not include the semicolon in the match, and</p> @@ -2400,7 +2400,7 @@ lengths, but it is acceptable if rewritten to use two top-level branches:</p> <quote><p> (?<=abc|abde)</p></quote> -<p>In some cases, the Perl 5.10 escape sequence \\K (see above) can be +<p>In some cases, the Perl 5.10 escape sequence \K (see above) can be used instead of a lookbehind assertion; this is not restricted to a fixed-length.</p> @@ -2409,9 +2409,9 @@ temporarily move the current position back by the fixed length and then try to match. If there are insufficient characters before the current position, the assertion fails.</p> -<p>PCRE does not allow the \\C escape (which matches a single byte in UTF-8 mode) +<p>PCRE does not allow the \C escape (which matches a single byte in UTF-8 mode) to appear in lookbehind assertions, because it makes it impossible to calculate -the length of the lookbehind. The \\X and \\R escapes, which can match +the length of the lookbehind. The \X and \R escapes, which can match different numbers of bytes, are also not permitted.</p> <p>Possessive quantifiers can be used in conjunction with lookbehind assertions to @@ -2443,7 +2443,7 @@ approach makes a significant difference to the processing time.</p> <p>Several assertions (of any sort) may occur in succession. For example,</p> -<quote><p> (?<=\\d{3})(?<!999)foo</p></quote> +<quote><p> (?<=\d{3})(?<!999)foo</p></quote> <p>matches "foo" preceded by three digits that are not "999". Notice that each of the assertions is applied independently at the same point @@ -2454,7 +2454,7 @@ three characters are not "999". This pattern does <em>not</em> match the last three of which are not "999". For example, it doesn't match "123abcfoo". A pattern to do that is</p> -<quote><p> (?<=\\d{3}...)(?<!999)foo</p></quote> +<quote><p> (?<=\d{3}...)(?<!999)foo</p></quote> <p>This time the first assertion looks at the preceding six characters, checking that the first three are digits, and then the @@ -2468,7 +2468,7 @@ second assertion checks that the preceding three characters are not <p>matches an occurrence of "baz" that is preceded by "bar" which in turn is not preceded by "foo", while</p> -<quote><p> (?<=\\d{3}(?!999)...)foo</p></quote> +<quote><p> (?<=\d{3}(?!999)...)foo</p></quote> <p>is another pattern that matches "foo" preceded by three digits and any three characters that are not "999".</p> @@ -2510,7 +2510,7 @@ refer to subsequent groups with constructs such as (?(+2).</p> whitespace to make it more readable (assume the <c>extended</c> option) and to divide it into three parts for ease of discussion:</p> -<quote><p> ( \\( )? [^()]+ (?(1) \\) )</p></quote> +<quote><p> ( \( )? [^()]+ (?(1) \) )</p></quote> <p>The first part matches an optional opening parenthesis, and if that character is present, sets it as the first captured substring. The second part @@ -2525,7 +2525,7 @@ non-parentheses, optionally enclosed in parentheses.</p> <p>If you were embedding this pattern in a larger one, you could use a relative reference:</p> -<quote><p> ...other stuff... ( \\( )? [^()]+ (?(-1) \\) ) ...</p></quote> +<quote><p> ...other stuff... ( \( )? [^()]+ (?(-1) \) ) ...</p></quote> <p>This makes the fragment independent of the parentheses in the larger pattern.</p> @@ -2543,7 +2543,7 @@ consist entirely of digits is not recommended.</p> <p>Rewriting the above example to use a named subpattern gives this:</p> -<quote><p> (?<OPEN> \\( )? [^()]+ (?(<OPEN>) \\) )</p></quote> +<quote><p> (?<OPEN> \( )? [^()]+ (?(<OPEN>) \) )</p></quote> <p><em>Checking for pattern recursion</em></p> @@ -2571,8 +2571,8 @@ point in the pattern; the idea of DEFINE is that it can be used to define is described below.) For example, a pattern to match an IPv4 address could be written like this (ignore whitespace and line breaks):</p> -<quote><p> (?(DEFINE) (?<byte> 2[0-4]\\d | 25[0-5] | 1\\d\\d | [1-9]?\\d) ) - \\b (?&byte) (\\.(?&byte)){3} \\b</p></quote> +<quote><p> (?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) ) + \b (?&byte) (\.(?&byte)){3} \b</p></quote> <p>The first part of the pattern is a DEFINE group inside which a another group named "byte" is defined. This matches an individual component of an IPv4 @@ -2590,9 +2590,9 @@ assertion. This may be a positive or negative lookahead or lookbehind assertion. Consider this pattern, again containing non-significant whitespace, and with the two alternatives on the second line:</p> -<code type="none"> +<code type="none"> (?(?=[^a-z]*[a-z]) - \\d{2}-[a-z]{3}-\\d{2} | \\d{2}-\\d{2}-\\d{2} )</code> + \d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} )</code> <p>The condition is a positive lookahead assertion that matches an optional sequence of non-letters followed by a letter. In other words, it tests for the @@ -2631,7 +2631,7 @@ can refer to the expression itself. A Perl pattern using code interpolation to solve the parentheses problem can be created like this:</p> -<quote><p> $re = qr{\\( (?: (?>[^()]+) | (?p{$re}) )* \\)}x;</p></quote> +<quote><p> $re = qr{\( (?: (?>[^()]+) | (?p{$re}) )* \)}x;</p></quote> <p>The (?p{...}) item interpolates Perl code at run time, and in this case refers recursively to the pattern in which it appears.</p> @@ -2657,7 +2657,7 @@ failure.</p> <p>This PCRE pattern solves the nested parentheses problem (assume the <c>extended</c> option is set so that whitespace is ignored):</p> -<quote><p> \\( ( (?>[^()]+) | (?R) )* \\)</p></quote> +<quote><p> \( ( (?>[^()]+) | (?R) )* \)</p></quote> <p>First it matches an opening parenthesis. Then it matches any number of substrings which can either be a sequence of non-parentheses, or a @@ -2667,7 +2667,7 @@ parenthesized substring). Finally there is a closing parenthesis.</p> <p>If this were part of a larger pattern, you would not want to recurse the entire pattern, so instead you could use this:</p> -<quote><p> ( \\( ( (?>[^()]+) | (?1) )* \\) )</p></quote> +<quote><p> ( \( ( (?>[^()]+) | (?1) )* \) )</p></quote> <p>We have put the pattern into parentheses, and caused the recursion to refer to them instead of the whole pattern.</p> @@ -2691,7 +2691,7 @@ Perl syntax for this is (?&name); PCRE's earlier syntax (?P>name) is also supported. We could rewrite the above example as follows:</p> -<quote><p> (?<pn> \\( ( (?>[^()]+) | (?&pn) )* \\) )</p></quote> +<quote><p> (?<pn> \( ( (?>[^()]+) | (?&pn) )* \) )</p></quote> <p>If there is more than one subpattern with the same name, the earliest one is used.</p> @@ -2727,7 +2727,7 @@ If the pattern above is matched against</p> on at the top level. If additional parentheses are added, giving</p> <code type="none"> - \\( ( ( (?>[^()]+) | (?R) )* ) \\) + \( ( ( (?>[^()]+) | (?R) )* ) \) ^ ^ ^ ^</code> @@ -2747,7 +2747,7 @@ brackets, allowing for arbitrary nesting. Only digits are allowed in nested brackets (that is, when recursing), whereas any characters are permitted at the outer level.</p> -<quote><p> < (?: (?(R) \\d++ | [^<>]*+) | (?R)) * ></p></quote> +<quote><p> < (?: (?(R) \d++ | [^<>]*+) | (?R)) * ></p></quote> <p>In this pattern, (?(R) is the start of a conditional subpattern, with two different alternatives for the recursive and non-recursive @@ -2771,7 +2771,7 @@ relative, as in these examples:</p> <p>An earlier example pointed out that the pattern</p> -<quote><p> (sens|respons)e and \\1ibility</p></quote> +<quote><p> (sens|respons)e and \1ibility</p></quote> <p>matches "sense and sensibility" and "response and responsibility", but not "sense and responsibility". If instead the pattern</p> diff --git a/lib/stdlib/doc/src/regexp.xml b/lib/stdlib/doc/src/regexp.xml index 8da636e4ad..8c4191c88f 100644 --- a/lib/stdlib/doc/src/regexp.xml +++ b/lib/stdlib/doc/src/regexp.xml @@ -132,7 +132,7 @@ <v>RepCount = integer()</v> </type> <desc> - <p>Substitutes the first occurrence of a substring matching <c>RegExp</c> in <c>String</c> with the string <c>New</c>. A <c><![CDATA[&]]></c> in the string <c>New</c> is replaced by the matched substring of <c>String</c>. <c><![CDATA[\\&]]></c> puts a literal <c><![CDATA[&]]></c> into the replacement string. It returns as follows:</p> + <p>Substitutes the first occurrence of a substring matching <c>RegExp</c> in <c>String</c> with the string <c>New</c>. A <c><![CDATA[&]]></c> in the string <c>New</c> is replaced by the matched substring of <c>String</c>. <c><![CDATA[\&]]></c> puts a literal <c><![CDATA[&]]></c> into the replacement string. It returns as follows:</p> <taglist> <tag><c>{ok,NewString,RepCount}</c></tag> <item> @@ -286,7 +286,7 @@ <item> <p>matches the non-metacharacter <c>c</c>.</p> </item> - <tag>\\c</tag> + <tag>\c</tag> <item> <p>matches the escape sequence or literal character <c>c</c>.</p> </item> @@ -341,74 +341,74 @@ <p>The escape sequences allowed are the same as for Erlang strings:</p> <taglist> - <tag><c>\\b</c></tag> + <tag><c>\b</c></tag> <item> <p>backspace</p> </item> - <tag><c>\\f</c></tag> + <tag><c>\f</c></tag> <item> <p>form feed </p> </item> - <tag><c>\</c></tag> + <tag><c>\n</c></tag> <item> <p>newline (line feed) </p> </item> - <tag><c>\\r</c></tag> + <tag><c>\r</c></tag> <item> <p>carriage return </p> </item> - <tag><c>\\t</c></tag> + <tag><c>\t</c></tag> <item> <p>tab </p> </item> - <tag><c>\\e</c></tag> + <tag><c>\e</c></tag> <item> <p>escape </p> </item> - <tag><c>\\v</c></tag> + <tag><c>\v</c></tag> <item> <p>vertical tab </p> </item> - <tag><c>\\s</c></tag> + <tag><c>\s</c></tag> <item> <p>space </p> </item> - <tag><c>\\d</c></tag> + <tag><c>\d</c></tag> <item> <p>delete </p> </item> - <tag><c>\\ddd</c></tag> + <tag><c>\ddd</c></tag> <item> <p>the octal value ddd </p> </item> - <tag><c>\\xhh</c></tag> + <tag><c>\xhh</c></tag> <item> <p>The hexadecimal value <c>hh</c>.</p> </item> - <tag><c>\\x{h...}</c></tag> + <tag><c>\x{h...}</c></tag> <item> <p>The hexadecimal value <c>h...</c>.</p> </item> - <tag><c>\\c</c></tag> + <tag><c>\c</c></tag> <item> - <p>any other character literally, for example <c>\\\\</c> for backslash, - <c>\\"</c> for ")</p> + <p>any other character literally, for example <c>\\</c> for backslash, + <c>\"</c> for ")</p> </item> </taglist> <p>To make these functions easier to use, in combination with the function <c>io:get_line</c> which terminates the input line with a new line, the <c>$</c> characters also matches a string ending - with <c>"...\ "</c>. The following examples + with <c>"...\n"</c>. The following examples define Erlang data types:</p> <pre> Atoms [a-z][0-9a-zA-Z_]* Variables [A-Z_][0-9a-zA-Z_]* -Floats (\\+|-)?[0-9]+\\.[0-9]+((E|e)(\\+|-)?[0-9]+)?</pre> - <p>Regular expressions are written as Erlang strings when used with the functions in this module. This means that any <c>\\</c> or <c>"</c> characters in a regular expression - string must be written with <c>\\</c> as they are also escape characters for the string. For example, the regular expression string for Erlang floats is: - <c>"(\\\\+|-)?[0-9]+\\\\.[0-9]+((E|e)(\\\\+|-)?[0-9]+)?"</c>.</p> +Floats (\+|-)?[0-9]+\.[0-9]+((E|e)(\+|-)?[0-9]+)?</pre> + <p>Regular expressions are written as Erlang strings when used with the functions in this module. This means that any <c>\</c> or <c>"</c> characters in a regular expression + string must be written with <c>\</c> as they are also escape characters for the string. For example, the regular expression string for Erlang floats is: + <c>"(\\+|-)?[0-9]+\\.[0-9]+((E|e)(\\+|-)?[0-9]+)?"</c>.</p> <p>It is not really necessary to have the escape sequences as part of the regular expression syntax as they can always be generated directly in the string. They are included for completeness and can they can also be useful when generating regular expressions, or when they are entered other than with Erlang strings.</p> </section> </erlref> diff --git a/lib/stdlib/doc/src/shell.xml b/lib/stdlib/doc/src/shell.xml index 24b845fee9..73cc1b33bd 100644 --- a/lib/stdlib/doc/src/shell.xml +++ b/lib/stdlib/doc/src/shell.xml @@ -4,7 +4,7 @@ <erlref> <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>shell</title> @@ -333,10 +333,12 @@ undefined <0.57.0> 27> <input>get(aa).</input> hello -28> <input>io:format("hello hello\ ").</input> -hello hello ok +28> <input>io:format("hello hello\n").</input> +hello hello +ok 29> <input>e(28).</input> -hello hello ok +hello hello +ok 30> <input>v(28).</input> ok 31> <input>c(ex).</input> @@ -737,6 +739,28 @@ loop(N) -> returns <c>{error,Reason}</c>.</item> </list> </section> + + <section> + <title>Prompting</title> + <p>The default shell prompt function displays the name of the node + (if the node can be part of a distributed system) and the + current command number. The user can customize the prompt + function by calling + <c>shell:prompt_func/1</c> or by setting the application + configuration parameter <c>shell_prompt_func</c> for the + application STDLIB.</p> + <p>A customized prompt function is stated as a tuple + <c>{Mod, Func}</c>. The function is called as + <c>Mod:Func(L)</c>, where <c>L</c> is a list of key-value pairs + 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. 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> <name>history(N) -> integer()</name> @@ -780,6 +804,19 @@ loop(N) -> </desc> </func> <func> + <name>prompt_func(PromptFunc) -> prompt_func()</name> + <fsummary>Sets the shell prompt</fsummary> + <type> + <v>PromptFunc = prompt_func()</v> + <v>prompt_func() = default | {Mod, Func}</v> + <v>Mod = Func = atom()</v> + </type> + <desc> + <p>Sets the shell prompt function to <c>PromptFunc</c>. The + previous prompt function is returned.</p> + </desc> + </func> + <func> <name>start_restricted(Module) -> ok | {error, Reason}</name> <fsummary>Exits a normal shell and starts a restricted shell.</fsummary> <type> diff --git a/lib/stdlib/doc/src/sofs.xml b/lib/stdlib/doc/src/sofs.xml index ac434ec5b7..8c8ae51262 100644 --- a/lib/stdlib/doc/src/sofs.xml +++ b/lib/stdlib/doc/src/sofs.xml @@ -4,7 +4,7 @@ <erlref> <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>sofs</title> @@ -311,7 +311,7 @@ applying Fun to the type of the given set), and that Fun does nothing but selecting, duplicating or rearranging parts of the elements. Specifying a SetFun as an integer I is equivalent to - specifying <c>{external, fun(X) -> element(I, X)}</c>, + specifying <c>{external, fun(X) -> element(I, X) end}</c>, but is to be preferred since it makes it possible to handle this case even more efficiently. Examples of SetFuns:</p> <pre> @@ -336,6 +336,7 @@ fun(S) -> sofs:partition(1, S) end <c>badarg</c>, <c>bad_function</c>, or <c>type_mismatch</c> message when given badly formed arguments or sets the types of which are not compatible.</p> + <p>When comparing external sets the operator <c>==/2</c> is used.</p> <p><em>Types</em></p> <pre> anyset() = - an unordered, ordered or atomic set - @@ -1108,7 +1109,13 @@ type() = - a type - </pre> <desc> <p>Returns <c>true</c> if the AnySet1 and AnySet2 are <seealso marker="#equal">equal</seealso>, <c>false</c> - otherwise.</p> + otherwise. This example shows that <c>==/2</c> is used when + comparing sets for equality:</p> + <pre> +1> <input>S1 = sofs:set([1.0]),</input> +<input>S2 = sofs:set([1]),</input> +<input>sofs:is_equal(S1, S2).</input> +true</pre> </desc> </func> <func> diff --git a/lib/stdlib/doc/src/stdlib_app.xml b/lib/stdlib/doc/src/stdlib_app.xml index da046b8a8d..a615c1bf88 100644 --- a/lib/stdlib/doc/src/stdlib_app.xml +++ b/lib/stdlib/doc/src/stdlib_app.xml @@ -4,23 +4,21 @@ <appref> <header> <copyright> - <year>2005</year> - <year>2007</year> - <holder>Ericsson AB, All Rights Reserved</holder> + <year>2005</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/. + 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. + 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>STDLIB</title> @@ -63,6 +61,16 @@ <p>This parameter can be used to determine how many commands are saved by the Erlang shell.</p> </item> + <tag><c>shell_prompt_func = {Mod, Func} | default</c></tag> + <item> + <p>where</p> + <list type="bulleted"> + <item><c>Mod = atom()</c></item> + <item><c>Func = atom()</c></item> + </list> + <p>This parameter can be used to set a customized + Erlang shell prompt function.</p> + </item> <tag><c>shell_saved_results = integer() >= 0</c></tag> <item> <p>This parameter can be used to determine how many diff --git a/lib/stdlib/doc/src/string.xml b/lib/stdlib/doc/src/string.xml index 7ee38e496d..de1b99a2d5 100644 --- a/lib/stdlib/doc/src/string.xml +++ b/lib/stdlib/doc/src/string.xml @@ -117,9 +117,9 @@ from) Chars.</p> <p>For example:</p> <code type="none"> -> string:span("\\t abcdef", " \\t"). +> string:span("\t abcdef", " \t"). 5 -> string:cspan("\\t abcdef", " \\t"). +> string:cspan("\t abcdef", " \t"). 0 </code> </desc> </func> diff --git a/lib/stdlib/doc/src/supervisor.xml b/lib/stdlib/doc/src/supervisor.xml index adf9d24eae..c696434d49 100644 --- a/lib/stdlib/doc/src/supervisor.xml +++ b/lib/stdlib/doc/src/supervisor.xml @@ -4,7 +4,7 @@ <erlref> <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>supervisor</title> @@ -402,9 +402,12 @@ child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules} <v> Module = atom()</v> </type> <desc> - <p>Returns a list with information about all child + <p>Returns a newly created list with information about all child specifications and child processes belonging to the supervisor <c>SupRef</c>.</p> + <p>Note that calling this function when supervising a large + number of children under low memory conditions can cause an + out of memory exception.</p> <p>See <c>start_child/2</c> for a description of <c>SupRef</c>.</p> <p>The information given for each child specification/process is:</p> @@ -428,6 +431,39 @@ child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules} </desc> </func> <func> + <name>count_children(SupRef) -> PropListOfCounts</name> + <fsummary>Return counts for the number of childspecs, active children, supervisors and workers.</fsummary> + <type> + <v>SupRef = Name | {Name,Node} | {global,Name} | pid()</v> + <v> Name = Node = atom()</v> + <v>PropListOfCounts = [{specs, ChildSpecCount}, {active, ActiveProcessCount}, {supervisors, ChildSupervisorCount}, {workers, ChildWorkerCount}]</v> + </type> + <desc> + <p>Returns a property list (see <c>proplists</c>) containing the + counts for each of the following elements of the supervisor's + child specifications and managed processes:</p> + <list type="bulleted"> + <item> + <p><c>specs</c> - the total count of children, dead or alive.</p> + </item> + <item> + <p><c>active</c> - the count of all actively running child processes + managed by this supervisor.</p> + </item> + <item> + <p><c>supervisors</c> - the count of all children marked as + child_type = supervisor in the spec list, whether or not the + child process is still alive.</p> + </item> + <item> + <p><c>workers</c> - the count of all children marked as + child_type = worker in the spec list, whether or not the child + process is still alive.</p> + </item> + </list> + </desc> + </func> + <func> <name>check_childspecs([ChildSpec]) -> Result</name> <fsummary>Check if children specifications are syntactically correct.</fsummary> <type> diff --git a/lib/stdlib/doc/src/sys.xml b/lib/stdlib/doc/src/sys.xml index a395a8a415..10ead62073 100644 --- a/lib/stdlib/doc/src/sys.xml +++ b/lib/stdlib/doc/src/sys.xml @@ -4,23 +4,21 @@ <erlref> <header> <copyright> - <year>1996</year> - <year>2007</year> - <holder>Ericsson AB, All Rights Reserved</holder> + <year>1996</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. + 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>sys</title> @@ -237,6 +235,17 @@ </type> <desc> <p>Gets the status of the process.</p> + <p>The value of <c>Misc</c> varies for different types of + processes. For example, a <c>gen_server</c> process returns + the callback module's state, and a <c>gen_fsm</c> process + returns information such as its current state name. Callback + modules for <c>gen_server</c> and <c>gen_fsm</c> can also + customise the value of <c>Misc</c> by exporting + a <c>format_status/2</c> function that contributes + module-specific information; + see <seealso marker="gen_server#format_status/2">gen_server:format_status/2</seealso> + and <seealso marker="gen_fsm#format_status/2">gen_fsm:format_status/2</seealso> + for more details.</p> </desc> </func> <func> diff --git a/lib/stdlib/doc/src/unicode.xml b/lib/stdlib/doc/src/unicode.xml index b3aad51591..60edd8ade9 100644 --- a/lib/stdlib/doc/src/unicode.xml +++ b/lib/stdlib/doc/src/unicode.xml @@ -51,7 +51,9 @@ charlist() = [unicode_char() | unicode_binary() | charlist()] a unicode_binary is allowed as the tail of the list</code> <code type="none"> -external_unicode_binary() = binary() with characters coded in a user specified Unicode encoding other than UTF-8 (UTF-16 or UTF-32) +external_unicode_binary() = binary() + with characters coded in a user specified Unicode encoding other + than UTF-8 (UTF-16 or UTF-32) external_chardata() = external_charlist() | external_unicode_binary() diff --git a/lib/stdlib/doc/src/unicode_usage.xml b/lib/stdlib/doc/src/unicode_usage.xml index 06347b3aae..c5bf10b63d 100644 --- a/lib/stdlib/doc/src/unicode_usage.xml +++ b/lib/stdlib/doc/src/unicode_usage.xml @@ -76,7 +76,8 @@ charlist() = [unicode_char() | unicode_binary() | charlist()] a unicode_binary is allowed as the tail of the list</code> <p>The module <c>unicode</c> in stdlib even supports similar mixes with binaries containing other encodings than UTF-8, but that is a special case to allow for conversions to and from external data:</p> <code type="none"> -external_unicode_binary() = binary() with characters coded in a user specified Unicode encoding other than UTF-8 (UTF-16 or UTF-32) +external_unicode_binary() = binary() with characters coded in a user specified Unicode + encoding other than UTF-8 (UTF-16 or UTF-32) external_chardata() = external_charlist() | external_unicode_binary() @@ -93,7 +94,8 @@ external_charlist() = [unicode_char() | external_unicode_binary() | external_cha <code> <<Ch/utf8,_/binary>> = Bin1, <<Ch/utf16-little,_/binary>> = Bin2, -Bin3 = <<$H/utf32-little, $e/utf32-little, $l/utf32-little, $l/utf32-little, $o/utf32-little>>,</code> +Bin3 = <<$H/utf32-little, $e/utf32-little, $l/utf32-little, $l/utf32-little, + $o/utf32-little>>,</code> <p>For convenience, literal strings can be encoded with a Unicode encoding in binaries using the following (or similar) syntax:</p> <code> Bin4 = <<"Hello"/utf16>>,</code> diff --git a/lib/stdlib/doc/src/win32reg.xml b/lib/stdlib/doc/src/win32reg.xml index d8055047b0..28960cd098 100644 --- a/lib/stdlib/doc/src/win32reg.xml +++ b/lib/stdlib/doc/src/win32reg.xml @@ -48,7 +48,7 @@ <p>Paths to keys are left to right, with sub-keys to the right and backslash between keys. (Remember that backslashes must be doubled in Erlang strings.) Case is preserved but not significant. - Example: <c>"\\\\hkey_local_machine\\\\software\\\\Ericsson\\\\Erlang\\\\5.0"</c> is the key + Example: <c>"\\hkey_local_machine\\software\\Ericsson\\Erlang\\5.0"</c> is the key for the installation data for the latest Erlang release.</p> <p>There are six entry points in the Windows registry, top level keys. They can be abbreviated in the <c>win32reg</c> module as:</p> @@ -66,7 +66,7 @@ current_config HKEY_CURRENT_CONFIG hkcc HKEY_CURRENT_CONFIG dyn_data HKEY_DYN_DATA hkdd HKEY_DYN_DATA</pre> - <p>The key above could be written as <c>"\\\\hklm\\\\software\\\\ericsson\\\\erlang\\\\5.0"</c>.</p> + <p>The key above could be written as <c>"\\hklm\\software\\ericsson\\erlang\\5.0"</c>.</p> <p>The <c>win32reg</c> module uses a current key. It works much like the current directory. From the current key, values can be fetched, sub-keys can be listed, and so on.</p> @@ -96,7 +96,7 @@ hkdd HKEY_DYN_DATA</pre> <desc> <p>Changes the current key to another key. Works like cd. The key can be specified as a relative path or as an - absolute path, starting with \\.</p> + absolute path, starting with \.</p> </desc> </func> <func> diff --git a/lib/stdlib/src/Makefile b/lib/stdlib/src/Makefile index 68708d6b02..237818c08b 100644 --- a/lib/stdlib/src/Makefile +++ b/lib/stdlib/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% # @@ -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 # ---------------------------------------------------- @@ -173,8 +176,8 @@ $(BOOTSTRAP_COMPILER)/ebin/erl_parse.beam: erl_parse.yrl $(ERLC) -o $(BOOTSTRAP_COMPILER)/egen erl_parse.yrl $(ERLC) -o $(BOOTSTRAP_COMPILER)/ebin $(BOOTSTRAP_COMPILER)/egen/erl_parse.erl -#$(BOOTSTRAP_COMPILER)/ebin/erl_lint.beam: erl_lint.erl -# $(ERLC) -o $(BOOTSTRAP_COMPILER)/ebin erl_lint.erl +$(BOOTSTRAP_TOP)/lib/stdlib/egen/erl_parse.erl: erl_parse.yrl + $(ERLC) $(YRL_FLAGS) -o$(BOOTSTRAP_TOP)/lib/stdlib/egen erl_parse.yrl $(BOOTSTRAP_COMPILER)/ebin/%.beam: %.erl $(ERLC) -o $(BOOTSTRAP_COMPILER)/ebin $< diff --git a/lib/stdlib/src/array.erl b/lib/stdlib/src/array.erl index 295eeac221..83576c9fd3 100644 --- a/lib/stdlib/src/array.erl +++ b/lib/stdlib/src/array.erl @@ -741,11 +741,17 @@ set_get_test_() -> ?_assert(array:get(0, set(0, 42, set(0, 17, new()))) =:= 42), - ?_assert(array:get(0, reset(0, new())) =:= undefined), - ?_assert(array:get(0, reset(0, set(0, 17, new()))) =:= undefined), - ?_assert(array:get(0, reset(0, new({default,42}))) =:= 42), - ?_assert(array:get(0, reset(0, set(0, 17, new({default,42})))) - =:= 42) + ?_assertError(badarg, array:get(0, reset(11, new([{size,10}])))), + ?_assertError(badarg, array:get(0, reset(-1, new([{size,10}])))), + ?_assert(array:get(0, reset(0, new())) =:= undefined), + ?_assert(array:get(0, reset(0, set(0, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(9, set(9, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(11, set(11, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(11, set(12, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(1, set(12, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(11, new())) =:= undefined), + ?_assert(array:get(0, reset(0, set(0, 17, new({default,42})))) =:= 42), + ?_assert(array:get(0, reset(0, new({default,42}))) =:= 42) ]. -endif. diff --git a/lib/stdlib/src/c.erl b/lib/stdlib/src/c.erl index 9e4cec5db2..433833e233 100644 --- a/lib/stdlib/src/c.erl +++ b/lib/stdlib/src/c.erl @@ -197,7 +197,9 @@ nc(File, Opts0) when is_list(Opts0) -> Opts = Opts0 ++ [report_errors, report_warnings], case compile:file(File, Opts) of {ok,Mod} -> - Fname = concat([File, code:objfile_extension()]), + Dir = outdir(Opts), + Obj = filename:basename(File, ".erl") ++ code:objfile_extension(), + Fname = filename:join(Dir, Obj), case file:read_file(Fname) of {ok,Bin} -> rpc:eval_everywhere(code,load_binary,[Mod,Fname,Bin]), diff --git a/lib/stdlib/src/dets_v8.erl b/lib/stdlib/src/dets_v8.erl index b24df02882..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). @@ -1053,14 +1053,14 @@ wl([{_Seq, {insert, Object}} | Cs], Type, _Del, Lookup, _I, _Objs) wl(Cs, Type, delete, Lookup, 1, [{Object,-1}]); wl([{_Seq, {insert, Object}} | Cs], Type, Del, Lookup, _I, Objs) -> NObjs = - case lists:keysearch(Object, 1, Objs) of - {value, {_, 0}} -> + case lists:keyfind(Object, 1, Objs) of + {_, 0} -> lists:keyreplace(Object, 1, Objs, {Object,-1}); - {value, {_, _C}} when Type =:= bag -> % C =:= 1; C =:= -1 + {_, _C} when Type =:= bag -> % C =:= 1; C =:= -1 Objs; - {value, {_, C}} when C < 0 -> % when Type =:= duplicate_bag + {_, C} when C < 0 -> % when Type =:= duplicate_bag lists:keyreplace(Object, 1, Objs, {Object,C-1}); - {value, {_, C}} -> % when C > 0, Type =:= duplicate_bag + {_, C} -> % when C > 0, Type =:= duplicate_bag lists:keyreplace(Object, 1, Objs, {Object,C+1}); false when Del =:= delete -> [{Object, -1} | Objs]; @@ -1258,8 +1258,8 @@ eval_slot(Head, TrySize, Pos, WLs, L, LU) -> find_key(Head, Pos, NextPos, Size, Term, Key, WLs, L, LU). find_key(Head, Pos, NextPos, Size, Term, Key, WLs, L, LU) -> - case lists:keysearch(Key, 1, WLs) of - {value, {_, {Delete, LookUp, Objects}} = WL} -> + case lists:keyfind(Key, 1, WLs) of + {_, {Delete, LookUp, Objects}} = WL -> NWLs = lists:delete(WL, WLs), {NewObjects, NL, LUK} = eval_object(Size, Term, Delete, LookUp, Objects, Head, Pos, L, []), @@ -1297,30 +1297,30 @@ eval_key(Key, Delete, LookUp, Objects, Head, Pos, WLs, L, LU, LUK) -> %% All objects in Objects have the key Key. eval_object(Size, Term, Delete, LookUp, Objects, Head, Pos, L, LU) -> Type = Head#head.type, - case lists:keysearch(Term, 1, Objects) of - {value, {_Object, N}} when N =:= 0 -> + case lists:keyfind(Term, 1, Objects) of + {_Object, N} when N =:= 0 -> L1 = [{delete,Pos,Size} | L], {Objects, L1, LU}; - {value, {_Object, N}} when N < 0, Type =:= set -> + {_Object, N} when N < 0, Type =:= set -> L1 = [{old,Pos} | L], wl_lookup(LookUp, Objects, Term, L1, LU); - {value, {Object, _N}} when Type =:= bag -> % when N =:= 1; N =:= -1 + {Object, _N} when Type =:= bag -> % when N =:= 1; N =:= -1 L1 = [{old,Pos} | L], Objects1 = lists:keydelete(Object, 1, Objects), wl_lookup(LookUp, Objects1, Term, L1, LU); - {value, {Object, N}} when N < 0, Type =:= duplicate_bag -> + {Object, N} when N < 0, Type =:= duplicate_bag -> L1 = [{old,Pos} | L], Objects1 = lists:keyreplace(Object, 1, Objects, {Object,N+1}), wl_lookup(LookUp, Objects1, Term, L1, LU); - {value, {_Object, N}} when N > 0, Type =:= duplicate_bag -> + {_Object, N} when N > 0, Type =:= duplicate_bag -> L1 = [{old,Pos} | L], wl_lookup(LookUp, Objects, Term, L1, LU); false when Type =:= set, Delete =:= delete -> - case lists:keysearch(-1, 2, Objects) of + case lists:keyfind(-1, 2, Objects) of false -> % no inserted object, perhaps deleted objects L1 = [{delete,Pos,Size} | L], {[], L1, LU}; - {value, {Term2,-1}} -> + {Term2, -1} -> Bin2 = term_to_binary(Term2), NSize = byte_size(Bin2), Overwrite = diff --git a/lib/stdlib/src/edlin.erl b/lib/stdlib/src/edlin.erl index 31a653bda0..6cb441dbed 100644 --- a/lib/stdlib/src/edlin.erl +++ b/lib/stdlib/src/edlin.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(edlin). @@ -30,8 +30,6 @@ -import(lists, [reverse/1, reverse/2]). -%-import([nthtail/2, keysearch/3, prefix/2]). - -export([over_word/3]). @@ -281,12 +279,32 @@ do_op(_, Bef, Aft, Rs) -> %% Step over word/non-word characters pushing the stepped over ones on %% the stack. -over_word([C|Cs], Stack, N) -> + +over_word(Cs, Stack, N) -> + L = length([1 || $\' <- Cs]), + case L rem 2 of + 0 -> + over_word1(Cs, Stack, N); + 1 -> + until_quote(Cs, Stack, N) + end. + +until_quote([$\'|Cs], Stack, N) -> + {Cs, [$\'|Stack], N+1}; +until_quote([C|Cs], Stack, N) -> + until_quote(Cs, [C|Stack], N+1). + +over_word1([$\'=C|Cs], Stack, N) -> + until_quote(Cs, [C|Stack], N+1); +over_word1(Cs, Stack, N) -> + over_word2(Cs, Stack, N). + +over_word2([C|Cs], Stack, N) -> case word_char(C) of - true -> over_word(Cs, [C|Stack], N+1); + true -> over_word2(Cs, [C|Stack], N+1); false -> {[C|Cs],Stack,N} end; -over_word([], Stack, N) when is_integer(N) -> +over_word2([], Stack, N) when is_integer(N) -> {[],Stack,N}. over_non_word([C|Cs], Stack, N) -> @@ -456,8 +474,8 @@ prompt({line,Pbs,_,_}) -> %% case erlang:module_loaded(Mod) of %% true -> %% L = apply(Mod, module_info, []), -%% case keysearch(exports, 1, L) of -%% {value, {_, Exports}} -> +%% case lists:keyfind(exports, 1, L) of +%% {_, Exports} -> %% match(FuncPrefix, Exports, "("); %% _ -> %% no @@ -473,7 +491,7 @@ prompt({line,Pbs,_,_}) -> %% print_matches(Matches), %% no; %% {partial, Str} -> -%% case nthtail(length(Prefix), Str) of +%% case lists:nthtail(length(Prefix), Str) of %% [] -> %% print_matches(Matches), %% {yes, []}; @@ -481,7 +499,7 @@ prompt({line,Pbs,_,_}) -> %% {yes, Remain} %% end; %% {complete, Str} -> -%% {yes, nthtail(length(Prefix), Str) ++ Extra}; +%% {yes, lists:nthtail(length(Prefix), Str) ++ Extra}; %% no -> %% no %% end. diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl index 7ed76a6b09..516c0aa30b 100644 --- a/lib/stdlib/src/edlin_expand.erl +++ b/lib/stdlib/src/edlin_expand.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2005-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(edlin_expand). @@ -46,23 +46,38 @@ expand_module_name(Prefix) -> match(Prefix, code:all_loaded(), ":"). expand_function_name(ModStr, FuncPrefix) -> - Mod = list_to_atom(ModStr), - case erlang:module_loaded(Mod) of - true -> - L = Mod:module_info(), - case lists:keyfind(exports, 1, L) of - {_, Exports} -> - match(FuncPrefix, Exports, "("); - _ -> - {no, [], []} - end; - false -> + case to_atom(ModStr) of + {ok, Mod} -> + case erlang:module_loaded(Mod) of + true -> + L = Mod:module_info(), + case lists:keyfind(exports, 1, L) of + {_, Exports} -> + match(FuncPrefix, Exports, "("); + _ -> + {no, [], []} + end; + false -> + {no, [], []} + end; + error -> {no, [], []} end. +%% if it's a quoted atom, atom_to_list/1 will do the wrong thing. +to_atom(Str) -> + case erl_scan:string(Str) of + {ok, [{atom,_,A}], _} -> + {ok, A}; + _ -> + error + end. + match(Prefix, Alts, Extra) -> Len = length(Prefix), - Matches = [{S, A} || {H, A} <- Alts, prefix(Prefix, S=atom_to_list(H))], + Matches = lists:sort( + [{S, A} || {H, A} <- Alts, + prefix(Prefix, S=hd(io_lib:fwrite("~w",[H])))]), case longest_common_head([N || {N, _} <- Matches]) of {partial, []} -> {no, [], Matches}; % format_matches(Matches)}; diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl index 8b702c005b..424aed3d2e 100644 --- a/lib/stdlib/src/epp.erl +++ b/lib/stdlib/src/epp.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(epp). @@ -111,18 +111,24 @@ format_error({bad,W}) -> io_lib:format("badly formed '~s'", [W]); format_error({call,What}) -> io_lib:format("illegal macro call '~s'",[What]); -format_error({undefined,M}) -> - io_lib:format("undefined macro '~w'", [M]); +format_error({undefined,M,none}) -> + io_lib:format("undefined macro '~s'", [M]); +format_error({undefined,M,A}) -> + io_lib:format("undefined macro '~s/~p'", [M,A]); format_error({depth,What}) -> io_lib:format("~s too deep",[What]); format_error({mismatch,M}) -> - io_lib:format("argument mismatch for macro '~w'", [M]); + io_lib:format("argument mismatch for macro '~s'", [M]); format_error({arg_error,M}) -> - io_lib:format("badly formed argument for macro '~w'", [M]); + io_lib:format("badly formed argument for macro '~s'", [M]); format_error({redefine,M}) -> - io_lib:format("redefining macro '~w'", [M]); -format_error({circular,M}) -> - io_lib:format("circular macro '~w'", [M]); + io_lib:format("redefining macro '~s'", [M]); +format_error({redefine_predef,M}) -> + io_lib:format("redefining predefined macro '~s'", [M]); +format_error({circular,M,none}) -> + io_lib:format("circular macro '~s'", [M]); +format_error({circular,M,A}) -> + io_lib:format("circular macro '~s/~p'", [M,A]); format_error({include,W,F}) -> io_lib:format("can't find include ~s \"~s\"", [W,F]); format_error({illegal,How,What}) -> @@ -258,18 +264,23 @@ user_predef([{M,Val,redefine}|Pdm], Ms) when is_atom(M) -> user_predef(Pdm, dict:store({atom,M}, {none,Exp}, Ms)); user_predef([{M,Val}|Pdm], Ms) when is_atom(M) -> case dict:find({atom,M}, Ms) of - {ok,_Def} -> + {ok,_Defs} when is_list(_Defs) -> %% User defined macros {error,{redefine,M}}; + {ok,_Def} -> %% Predefined macros + {error,{redefine_predef,M}}; error -> Exp = erl_parse:tokens(erl_parse:abstract(Val)), - user_predef(Pdm, dict:store({atom,M}, {none,Exp}, Ms)) + user_predef(Pdm, dict:store({atom,M}, [{none, {none,Exp}}], Ms)) end; user_predef([M|Pdm], Ms) when is_atom(M) -> case dict:find({atom,M}, Ms) of - {ok,_Def} -> + {ok,_Defs} when is_list(_Defs) -> %% User defined macros {error,{redefine,M}}; + {ok,_Def} -> %% Predefined macros + {error,{redefine_predef,M}}; error -> - user_predef(Pdm, dict:store({atom,M}, {none,[{atom,1,true}]}, Ms)) + user_predef(Pdm, + dict:store({atom,M}, [{none, {none,[{atom,1,true}]}}], Ms)) end; user_predef([Md|_Pdm], _Ms) -> {error,{bad,Md}}; user_predef([], Ms) -> {ok,Ms}. @@ -476,57 +487,56 @@ scan_extends(_Ts, _As, Ms) -> Ms. %% scan_define(Tokens, DefineToken, From, EppState) -scan_define([{'(',_Lp},{atom,_Lm,M}=Mac,{',',_Lc}|Toks], _Def, From, St) -> +scan_define([{'(',_Lp},{Type,_Lm,M}=Mac,{',',_Lc}|Toks], _Def, From, St) + when Type =:= atom; Type =:= var -> case dict:find({atom,M}, St#epp.macs) of - {ok,_OldDef} -> - epp_reply(From, {error,{loc(Mac),epp,{redefine,M}}}), - wait_req_scan(St); - error -> - scan_define_cont(From, St, - {atom, M}, - {none,macro_expansion(Toks)}) - end; -scan_define([{'(',_Lp},{atom,_Lm,M}=Mac,{'(',_Lc}|Toks], Def, From, St) -> - case dict:find({atom,M}, St#epp.macs) of - {ok,_Def} -> - epp_reply(From, {error,{loc(Mac),epp,{redefine,M}}}), - wait_req_scan(St); - error -> - case catch macro_pars(Toks, []) of - {ok, {As, Me}} -> - scan_define_cont(From, St, - {atom, M}, - {As, Me}); - _ -> - epp_reply(From, {error,{loc(Def),epp,{bad,define}}}), - wait_req_scan(St) - end - end; -scan_define([{'(',_Lp},{var,_Lm,M}=Mac,{',',_Lc}|Toks], _Def, From, St) -> - case dict:find({atom,M}, St#epp.macs) of - {ok,_OldDef} -> - epp_reply(From, {error,{loc(Mac),epp,{redefine,M}}}), - wait_req_scan(St); - error -> - scan_define_cont(From, St, - {atom, M}, - {none,macro_expansion(Toks)}) + {ok, Defs} when is_list(Defs) -> + %% User defined macros: can be overloaded + case proplists:is_defined(none, Defs) of + true -> + epp_reply(From, {error,{loc(Mac),epp,{redefine,M}}}), + wait_req_scan(St); + false -> + scan_define_cont(From, St, + {atom, M}, + {none, {none,macro_expansion(Toks)}}) + end; + {ok, _PreDef} -> + %% Predefined macros: cannot be overloaded + epp_reply(From, {error,{loc(Mac),epp,{redefine_predef,M}}}), + wait_req_scan(St); + error -> + scan_define_cont(From, St, + {atom, M}, + {none, {none,macro_expansion(Toks)}}) end; -scan_define([{'(',_Lp},{var,_Lm,M}=Mac,{'(',_Lc}|Toks], Def, From, St) -> - case dict:find({atom,M}, St#epp.macs) of - {ok,_Def} -> - epp_reply(From, {error,{loc(Mac),epp,{redefine,M}}}), - wait_req_scan(St); - error -> - case catch macro_pars(Toks, []) of - {ok, {As, Me}} -> - scan_define_cont(From, St, - {atom, M}, - {As, Me}); - _ -> - epp_reply(From, {error,{loc(Def),epp,{bad,define}}}), - wait_req_scan(St) - end +scan_define([{'(',_Lp},{Type,_Lm,M}=Mac,{'(',_Lc}|Toks], Def, From, St) + when Type =:= atom; Type =:= var -> + case catch macro_pars(Toks, []) of + {ok, {As,Me}} -> + Len = length(As), + case dict:find({atom,M}, St#epp.macs) of + {ok, Defs} when is_list(Defs) -> + %% User defined macros: can be overloaded + case proplists:is_defined(Len, Defs) of + true -> + epp_reply(From,{error,{loc(Mac),epp,{redefine,M}}}), + wait_req_scan(St); + false -> + scan_define_cont(From, St, {atom, M}, + {Len, {As, Me}}) + end; + {ok, _PreDef} -> + %% Predefined macros: cannot be overloaded + %% (There are currently no predefined F(...) macros.) + epp_reply(From, {error,{loc(Mac),epp,{redefine_predef,M}}}), + wait_req_scan(St); + error -> + scan_define_cont(From, St, {atom, M}, {Len, {As, Me}}) + end; + _ -> + epp_reply(From, {error,{loc(Def),epp,{bad,define}}}), + wait_req_scan(St) end; scan_define(_Toks, Def, From, St) -> epp_reply(From, {error,{loc(Def),epp,{bad,define}}}), @@ -541,13 +551,17 @@ scan_define(_Toks, Def, From, St) -> %%% the information from St#epp.uses is traversed, and if a circularity %%% is detected, an error message is thrown. -scan_define_cont(F, St, M, Def) -> - Ms = dict:store(M, Def, St#epp.macs), - U = dict:store(M, macro_uses(Def), St#epp.uses), - scan_toks(F, St#epp{uses=U, macs=Ms}). +scan_define_cont(F, St, M, {Arity, Def}) -> + Ms = dict:append_list(M, [{Arity, Def}], St#epp.macs), + try dict:append_list(M, [{Arity, macro_uses(Def)}], St#epp.uses) of + U -> + scan_toks(F, St#epp{uses=U, macs=Ms}) + catch + {error, Line, Reason} -> + epp_reply(F, {error,{Line,epp,Reason}}), + wait_req_scan(St) + end. -macro_uses(undefined) -> - undefined; macro_uses({_Args, Tokens}) -> Uses0 = macro_ref(Tokens), lists:usort(Uses0). @@ -556,31 +570,25 @@ macro_ref([]) -> []; macro_ref([{'?', _}, {'?', _} | Rest]) -> macro_ref(Rest); -macro_ref([{'?', _}, {atom, _, A} | Rest]) -> - [{atom, A} | macro_ref(Rest)]; -macro_ref([{'?', _}, {var, _, A} | Rest]) -> - [{atom, A} | macro_ref(Rest)]; +macro_ref([{'?', _}, {atom, Lm, A} | Rest]) -> + Arity = count_args(Rest, Lm, A), + [{{atom, A}, Arity} | macro_ref(Rest)]; +macro_ref([{'?', _}, {var, Lm, A} | Rest]) -> + Arity = count_args(Rest, Lm, A), + [{{atom, A}, Arity} | macro_ref(Rest)]; macro_ref([_Token | Rest]) -> macro_ref(Rest). -all_macro_uses(D0) -> - L = dict:to_list(D0), - D = dict:new(), - add_macro_uses(L, D). - -add_macro_uses([], D) -> - D; -add_macro_uses([{Key, Def} | Rest], D0) -> - add_macro_uses(Rest, dict:store(Key, macro_uses(Def), D0)). - %% scan_undef(Tokens, UndefToken, From, EppState) scan_undef([{'(',_Llp},{atom,_Lm,M},{')',_Lrp},{dot,_Ld}], _Undef, From, St) -> - scan_toks(From, St#epp{macs=dict:erase({atom,M}, St#epp.macs), - uses=all_macro_uses(St#epp.macs)}); + Macs = dict:erase({atom,M}, St#epp.macs), + Uses = dict:erase({atom,M}, St#epp.uses), + scan_toks(From, St#epp{macs=Macs, uses=Uses}); scan_undef([{'(',_Llp},{var,_Lm,M},{')',_Lrp},{dot,_Ld}], _Undef, From,St) -> - scan_toks(From, St#epp{macs=dict:erase({atom,M}, St#epp.macs), - uses=all_macro_uses(St#epp.macs)}); + Macs = dict:erase({atom,M}, St#epp.macs), + Uses = dict:erase({atom,M}, St#epp.uses), + scan_toks(From, St#epp{macs=Macs, uses=Uses}); scan_undef(_Toks, Undef, From, St) -> epp_reply(From, {error,{loc(Undef),epp,{bad,undef}}}), wait_req_scan(St). @@ -819,42 +827,57 @@ expand_macros(Type, MacT, M, Toks, Ms0) -> %% (Type will always be 'atom') {Ms, U} = Ms0, Lm = loc(MacT), - check_uses([{Type,M}], [], U, Lm), Tinfo = element(2, MacT), - case dict:find({Type,M}, Ms) of + case expand_macro1(Type, Lm, M, Toks, Ms) of {ok,{none,Exp}} -> - expand_macros(expand_macro(Exp, Tinfo, Toks, dict:new()), Ms0); + check_uses([{{Type,M}, none}], [], U, Lm), + Toks1 = expand_macros(expand_macro(Exp, Tinfo, [], dict:new()), Ms0), + expand_macros(Toks1++Toks, Ms0); {ok,{As,Exp}} -> + check_uses([{{Type,M}, length(As)}], [], U, Lm), {Bs,Toks1} = bind_args(Toks, Lm, M, As, dict:new()), - %%io:format("Bound arguments to macro ~w (~w)~n", [M,Bs]), - expand_macros(expand_macro(Exp, Tinfo, Toks1, Bs), Ms0); - {ok,undefined} -> - throw({error,Lm,{undefined,M}}); - error -> - throw({error,Lm,{undefined,M}}) + expand_macros(expand_macro(Exp, Tinfo, Toks1, Bs), Ms0) + end. + +expand_macro1(Type, Lm, M, Toks, Ms) -> + Arity = count_args(Toks, Lm, M), + case dict:find({Type,M}, Ms) of + error -> %% macro not found + throw({error,Lm,{undefined,M,Arity}}); + {ok, undefined} -> %% Predefined macro without definition + throw({error,Lm,{undefined,M,Arity}}); + {ok, [{none, Def}]} -> + {ok, Def}; + {ok, Defs} when is_list(Defs) -> + case proplists:get_value(Arity, Defs) of + undefined -> + throw({error,Lm,{mismatch,M}}); + Def -> + {ok, Def} + end; + {ok, PreDef} -> %% Predefined macro + {ok, PreDef} end. -check_uses(undefined, _Anc, _U, _Lm) -> - ok; check_uses([], _Anc, _U, _Lm) -> ok; check_uses([M|Rest], Anc, U, Lm) -> case lists:member(M, Anc) of true -> - {_, Name} = M, - throw({error,Lm,{circular,Name}}); + {{_, Name},Arity} = M, + throw({error,Lm,{circular,Name,Arity}}); false -> L = get_macro_uses(M, U), check_uses(L, [M|Anc], U, Lm), check_uses(Rest, Anc, U, Lm) end. - -get_macro_uses(M, U) -> + +get_macro_uses({M,Arity}, U) -> case dict:find(M, U) of error -> []; {ok, L} -> - L + proplists:get_value(Arity, L, proplists:get_value(none, L, [])) end. %% Macro expansion @@ -882,7 +905,7 @@ expand_macros([T|Ts], Ms) -> expand_macros([], _Ms) -> []. %% bind_args(Tokens, MacroLocation, MacroName, ArgumentVars, Bindings) -%% Collect the arguments to a macro call and check for correct number. +%% Collect the arguments to a macro call. bind_args([{'(',_Llp},{')',_Lrp}|Toks], _Lm, _M, [], Bs) -> {Bs,Toks}; @@ -890,7 +913,7 @@ bind_args([{'(',_Llp}|Toks0], Lm, M, [A|As], Bs) -> {Arg,Toks1} = macro_arg(Toks0, [], []), macro_args(Toks1, Lm, M, As, store_arg(Lm, M, A, Arg, Bs)); bind_args(_Toks, Lm, M, _As, _Bs) -> - throw({error,Lm,{mismatch,M}}). + throw({error,Lm,{mismatch,M}}). % Cannot happen. macro_args([{')',_Lrp}|Toks], _Lm, _M, [], Bs) -> {Bs,Toks}; @@ -898,15 +921,39 @@ macro_args([{',',_Lc}|Toks0], Lm, M, [A|As], Bs) -> {Arg,Toks1} = macro_arg(Toks0, [], []), macro_args(Toks1, Lm, M, As, store_arg(Lm, M, A, Arg, Bs)); macro_args([], Lm, M, _As, _Bs) -> - throw({error,Lm,{arg_error,M}}); + throw({error,Lm,{arg_error,M}}); % Cannot happen. macro_args(_Toks, Lm, M, _As, _Bs) -> - throw({error,Lm,{mismatch,M}}). + throw({error,Lm,{mismatch,M}}). % Cannot happen. store_arg(L, M, _A, [], _Bs) -> throw({error,L,{mismatch,M}}); store_arg(_L, _M, A, Arg, Bs) -> dict:store(A, Arg, Bs). +%% count_args(Tokens, MacroLine, MacroName) +%% Count the number of arguments in a macro call. +count_args([{'(', _Llp},{')',_Lrp}|_Toks], _Lm, _M) -> + 0; +count_args([{'(', _Llp},{',',_Lc}|_Toks], Lm, M) -> + throw({error,Lm,{arg_error,M}}); +count_args([{'(',_Llp}|Toks0], Lm, M) -> + {_Arg,Toks1} = macro_arg(Toks0, [], []), + count_args(Toks1, Lm, M, 1); +count_args(_Toks, _Lm, _M) -> + none. + +count_args([{')',_Lrp}|_Toks], _Lm, _M, NbArgs) -> + NbArgs; +count_args([{',',_Lc},{')',_Lrp}|_Toks], Lm, M, _NbArgs) -> + throw({error,Lm,{arg_error,M}}); +count_args([{',',_Lc}|Toks0], Lm, M, NbArgs) -> + {_Arg,Toks1} = macro_arg(Toks0, [], []), + count_args(Toks1, Lm, M, NbArgs+1); +count_args([], Lm, M, _NbArgs) -> + throw({error,Lm,{arg_error,M}}); +count_args(_Toks, Lm, M, _NbArgs) -> + throw({error,Lm,{mismatch,M}}). % Cannot happen. + %% macro_arg([Tok], [ClosePar], [ArgTok]) -> {[ArgTok],[RestTok]}. %% Collect argument tokens until we hit a ',' or a ')'. We know a %% enough about syntax to recognise "open parentheses" and keep 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 697a69b801..b2562c6169 100644 --- a/lib/stdlib/src/escript.erl +++ b/lib/stdlib/src/escript.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% -module(escript). @@ -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} -> @@ -180,7 +181,8 @@ parse_and_run(File, Args, Options) -> is_binary(FormsOrBin) -> case Source of archive -> - case code:set_primary_archive(File, FormsOrBin) of + {ok, FileInfo} = file:read_file_info(File), + case code:set_primary_archive(File, FormsOrBin, FileInfo) of ok when CheckOnly -> case code:load_file(Module) of {module, _} -> @@ -245,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 @@ -259,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) -> @@ -420,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 = @@ -432,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. @@ -494,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 @@ -563,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 de9e628e22..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). @@ -186,7 +186,7 @@ options(Option) -> options([{format, Format} | L], Opts) when Format =:= binary; Format =:= term; is_function(Format), - is_function(Format, 1) -> + is_function(Format, 1) -> options(L, Opts#opts{format = Format}); options([{format, binary_term} | L], Opts) -> options(L, Opts#opts{format = binary_term_fun()}); @@ -419,9 +419,9 @@ culprit_found(IFun, F, FNs, W, L, I, [_Size | BT]) -> IFun(close), check_files(FNs, W, [{F,I,binary_to_term(BT)} | L]). -files(_I, L, _LSz, #w{seq = 1}=W, []) -> +files(_I, L, _LSz, #w{seq = 1, out = Out}=W, []) -> %% No temporary files created, everything in L. - case W#w.out of + case Out of Fun when is_function(Fun) -> SL = internal_sort(L, W), W1 = outfun(binterm_objects(SL, []), W), @@ -462,8 +462,8 @@ fun_run(I, L, LSz, W, []) -> {cont, NW, Objs} -> fun_run(I, L, LSz, NW, Objs) end; -fun_run(I, L, LSz, W, Objs) when LSz < W#w.runsize -> - {NI, NObjs, NL, NLSz} = fun_objs(Objs, L, LSz, W#w.runsize, I, W), +fun_run(I, L, LSz, #w{runsize = Runsize}=W, Objs) when LSz < Runsize -> + {NI, NObjs, NL, NLSz} = fun_objs(Objs, L, LSz, Runsize, I, W), fun_run(NI, NL, NLSz, W, NObjs); fun_run(I, L, _LSz, W, Objs) -> NW = write_run(L, W), @@ -1201,11 +1201,11 @@ infun(W) -> erlang:raise(Class, Reason, erlang:get_stacktrace()) end. -outfun(A, W) when W#w.inout_value =/= no_value -> +outfun(A, #w{inout_value = Val} = W) when Val =/= no_value -> W1 = W#w{inout_value = no_value}, W2 = if W1#w.fun_out -> - outfun(W#w.inout_value, W1); + outfun(Val, W1); true -> W1 end, outfun(A, W2); @@ -1372,19 +1372,19 @@ cleanup(W) -> end, lists:foreach(F, W1#w.temp). -close_input(W) when is_function(W#w.in) -> - catch (W#w.in)(close), +close_input(#w{in = In}=W) when is_function(In) -> + catch In(close), W#w{in = undefined}; close_input(#w{in = undefined}=W) -> W. -close_out(W) when is_function(W#w.out) -> - catch (W#w.out)(close); +close_out(#w{out = Out}) when is_function(Out) -> + catch Out(close); close_out(_) -> ok. close_file(Fd, W) -> - {value, {Fd, FileName}} = lists:keysearch(Fd, 1, W#w.temp), + {Fd, FileName} = lists:keyfind(Fd, 1, W#w.temp), ?DEBUG("closing ~p~n", [FileName]), file:close(Fd), W#w{temp = [FileName | lists:keydelete(Fd, 1, W#w.temp)]}. diff --git a/lib/stdlib/src/filelib.erl b/lib/stdlib/src/filelib.erl index d65588f0d1..74c5172137 100644 --- a/lib/stdlib/src/filelib.erl +++ b/lib/stdlib/src/filelib.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(filelib). @@ -228,7 +228,17 @@ ensure_dir(F) -> ok; false -> ensure_dir(Dir), - file:make_dir(Dir) + case file:make_dir(Dir) of + {error,eexist}=EExist -> + case do_is_dir(Dir, file) of + true -> + ok; + false -> + EExist + end; + Err -> + Err + end end. diff --git a/lib/stdlib/src/gen_fsm.erl b/lib/stdlib/src/gen_fsm.erl index f3775f967a..ba0275ae2b 100644 --- a/lib/stdlib/src/gen_fsm.erl +++ b/lib/stdlib/src/gen_fsm.erl @@ -603,7 +603,12 @@ get_msg(Msg) -> Msg. format_status(Opt, StatusData) -> [PDict, SysState, Parent, Debug, [Name, StateName, StateData, Mod, _Time]] = StatusData, - Header = lists:concat(["Status for state machine ", Name]), + NameTag = if is_pid(Name) -> + pid_to_list(Name); + is_atom(Name) -> + Name + end, + Header = lists:concat(["Status for state machine ", NameTag]), Log = sys:get_debug(log, Debug, []), Specfic = case erlang:function_exported(Mod, format_status, 2) of 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/otp_internal.erl b/lib/stdlib/src/otp_internal.erl index 3df6f4bb90..7ea7de8d58 100644 --- a/lib/stdlib/src/otp_internal.erl +++ b/lib/stdlib/src/otp_internal.erl @@ -334,6 +334,10 @@ obsolete_1(ssl_pkix, decode_cert_file, A) when A =:= 1; A =:= 2 -> {deprecated,"deprecated (will be removed in R14B); use public_key:pem_to_der/1 and public_key:pkix_decode_cert/2 instead"}; obsolete_1(ssl_pkix, decode_cert, A) when A =:= 1; A =:= 2 -> {deprecated,{public_key,pkix_decode_cert,2},"R14B"}; + +%% Added in R13B04. +obsolete_1(erlang, concat_binary, 1) -> + {deprecated,{erlang,list_to_binary,1},"R14B"}; obsolete_1(_, _, _) -> no. diff --git a/lib/stdlib/src/qlc.erl b/lib/stdlib/src/qlc.erl index ef142e1c8a..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). @@ -528,122 +528,111 @@ options(Options0, [Key | Keys], L) when is_list(Options0) -> false -> Options0 end, - V = case lists:keysearch(Key, 1, Options) of - {value, {format_fun, U=undefined}} -> + V = case lists:keyfind(Key, 1, Options) of + {format_fun, U=undefined} -> {ok, U}; - {value, {info_fun, U=undefined}} -> + {info_fun, U=undefined} -> {ok, U}; - {value, {lookup_fun, U=undefined}} -> + {lookup_fun, U=undefined} -> {ok, U}; - {value, {parent_fun, U=undefined}} -> + {parent_fun, U=undefined} -> {ok, U}; - {value, {post_fun, U=undefined}} -> + {post_fun, U=undefined} -> {ok, U}; - {value, {pre_fun, U=undefined}} -> + {pre_fun, U=undefined} -> {ok, U}; - {value, {info_fun, Fun}} when is_function(Fun), - is_function(Fun, 1) -> + {info_fun, Fun} when is_function(Fun), is_function(Fun, 1) -> {ok, Fun}; - {value, {pre_fun, Fun}} when is_function(Fun), - is_function(Fun, 1) -> + {pre_fun, Fun} when is_function(Fun), is_function(Fun, 1) -> {ok, Fun}; - {value, {post_fun, Fun}} when is_function(Fun), - is_function(Fun, 0) -> + {post_fun, Fun} when is_function(Fun), is_function(Fun, 0) -> {ok, Fun}; - {value, {lookup_fun, Fun}} when is_function(Fun), - is_function(Fun, 2) -> + {lookup_fun, Fun} when is_function(Fun), is_function(Fun, 2) -> {ok, Fun}; - {value, {max_lookup, Max}} when is_integer(Max), Max >= 0 -> + {max_lookup, Max} when is_integer(Max), Max >= 0 -> {ok, Max}; - {value, {max_lookup, infinity}} -> + {max_lookup, infinity} -> {ok, -1}; - {value, {format_fun, Fun}} when is_function(Fun), - is_function(Fun, 1) -> + {format_fun, Fun} when is_function(Fun), is_function(Fun, 1) -> {ok, Fun}; - {value, {parent_fun, Fun}} when is_function(Fun), - is_function(Fun, 0) -> + {parent_fun, Fun} when is_function(Fun), is_function(Fun, 0) -> {ok, Fun}; - {value, {key_equality, KE='=='}}-> + {key_equality, KE='=='} -> {ok, KE}; - {value, {key_equality, KE='=:='}}-> + {key_equality, KE='=:='} -> {ok, KE}; - {value, {join, J=any}} -> + {join, J=any} -> {ok, J}; - {value, {join, J=nested_loop}} -> + {join, J=nested_loop} -> {ok, J}; - {value, {join, J=merge}} -> + {join, J=merge} -> {ok, J}; - {value, {join, J=lookup}} -> + {join, J=lookup} -> {ok, J}; - {value, {lookup, LookUp}} when LookUp; - not LookUp; - LookUp =:= any -> + {lookup, LookUp} when is_boolean(LookUp); LookUp =:= any -> {ok, LookUp}; - {value, {max_list_size, Max}} when is_integer(Max), Max >= 0 -> + {max_list_size, Max} when is_integer(Max), Max >= 0 -> {ok, Max}; - {value, {tmpdir_usage, TmpUsage}} when TmpUsage =:= allowed; - TmpUsage =:= not_allowed; - TmpUsage =:= info_msg; - TmpUsage =:= warning_msg; - TmpUsage =:= error_msg -> + {tmpdir_usage, TmpUsage} when TmpUsage =:= allowed; + TmpUsage =:= not_allowed; + TmpUsage =:= info_msg; + TmpUsage =:= warning_msg; + TmpUsage =:= error_msg -> {ok, TmpUsage}; - {value, {unique, Unique}} when Unique; not Unique -> + {unique, Unique} when is_boolean(Unique) -> {ok, Unique}; - {value, {cache, Cache}} when Cache; not Cache; Cache =:= list -> + {cache, Cache} when is_boolean(Cache); Cache =:= list -> {ok, Cache}; - {value, {cache, ets}} -> + {cache, ets} -> {ok, true}; - {value, {cache, no}} -> + {cache, no} -> {ok, false}; - {value, {unique_all, UniqueAll}} when UniqueAll; not UniqueAll -> + {unique_all, UniqueAll} when is_boolean(UniqueAll) -> {ok, UniqueAll}; - {value, {cache_all, CacheAll}} when CacheAll; - not CacheAll; - CacheAll =:= list -> + {cache_all, CacheAll} when is_boolean(CacheAll); + CacheAll =:= list -> {ok, CacheAll}; - {value, {cache_all, ets}} -> + {cache_all, ets} -> {ok, true}; - {value, {cache_all, no}} -> + {cache_all, no} -> {ok, false}; - {value, {spawn_options, default}} -> + {spawn_options, default} -> {ok, default}; - {value, {spawn_options, SpawnOptions}} -> + {spawn_options, SpawnOptions} -> case is_proper_list(SpawnOptions) of true -> {ok, SpawnOptions}; false -> badarg end; - {value, {flat, Flat}} when Flat; not Flat -> + {flat, Flat} when is_boolean(Flat) -> {ok, Flat}; - {value, {format, Format}} when Format =:= string; - Format =:= abstract_code; - Format =:= debug -> + {format, Format} when Format =:= string; + Format =:= abstract_code; + Format =:= debug -> {ok, Format}; - {value, {n_elements, NElements}} when NElements =:= infinity; - is_integer(NElements), - NElements > 0 -> + {n_elements, NElements} when NElements =:= infinity; + is_integer(NElements), + NElements > 0 -> {ok, NElements}; - {value, {depth, Depth}} when Depth =:= infinity; - is_integer(Depth), Depth >= 0 -> + {depth, Depth} when Depth =:= infinity; + is_integer(Depth), Depth >= 0 -> {ok, Depth}; - {value, {order, Order}} when is_function(Order), - is_function(Order, 2); - (Order =:= ascending); - (Order =:= descending) -> + {order, Order} when is_function(Order), is_function(Order, 2); + (Order =:= ascending); + (Order =:= descending) -> {ok, Order}; - {value, {compressed, Comp}} when Comp -> + {compressed, Comp} when Comp -> {ok, [compressed]}; - {value, {compressed, Comp}} when not Comp -> + {compressed, Comp} when not Comp -> {ok, []}; - {value, {tmpdir, T}} -> + {tmpdir, T} -> {ok, T}; - {value, {size, Size}} when is_integer(Size), Size > 0 -> + {size, Size} when is_integer(Size), Size > 0 -> {ok, Size}; - {value, {no_files, NoFiles}} when is_integer(NoFiles), - NoFiles > 1 -> + {no_files, NoFiles} when is_integer(NoFiles), NoFiles > 1 -> {ok, NoFiles}; - {value, {Key, _}} -> + {Key, _} -> badarg; false -> Default = default_option(Key), @@ -1457,7 +1446,7 @@ prep_qlc_lc({qlc_v1, QFun, CodeF, Qdata0, QOpt}, Opt, GOpt, _H) -> {?qual_data(QNum, GoI, SI, {gen, Prep}), ModGens} end, {Qdata, ModGens} = lists:mapfoldl(F, [], Qdata0), - SomeLookUp = lists:keymember(true, 2, ModGens) =/= false, + SomeLookUp = lists:keymember(true, 2, ModGens), check_lookup_option(Opt, SomeLookUp), case ModGens of [{_QNum, _LookUp, all, OnePrep}] -> @@ -1503,7 +1492,7 @@ pos_fun('==', QOpt, QNum) -> prep_gen(#qlc_table{lu_vals = LuV0, ms = MS0, trav_MS = TravMS, info_fun = IF, lookup_fun = LU_fun, - key_equality = KeyEquality}=LE0, + key_equality = KeyEquality}=LE0, Prep0, PosFun0, {MS, Fs}, Opt) -> PosFun = PosFun0(KeyEquality), {LuV, {STag,SkipFils}} = find_const_positions(IF, LU_fun, PosFun, Opt), @@ -1998,8 +1987,8 @@ no_cache_of_first_generator(Optz, 1) -> Optz#optz{cache = false}. maybe_sort(LE, QNum, DoSort, Opt) -> - case lists:keysearch(QNum, 1, DoSort) of - {value, {QNum, Col}} -> + case lists:keyfind(QNum, 1, DoSort) of + {QNum, Col} -> #qlc_opt{tmpdir = TmpDir, tmpdir_usage = TmpUsage} = Opt, SortOpts = [{tmpdir,Dir} || Dir <- [TmpDir], Dir =/= ""], Sort = #qlc_sort{h = LE, keypos = {keysort, Col}, unique = false, @@ -2025,7 +2014,7 @@ skip_lookup_filters(Qdata0, LU_SkipFs) -> %% specification it must be applied _after_ the lookup join (the %% filter must not be skipped!). activate_join_lookup_filter(QNum, Qdata) -> - {value, {_,GoI2,SI2,{gen,Prep2}}} = lists:keysearch(QNum, 1, Qdata), + {_,GoI2,SI2,{gen,Prep2}} = lists:keyfind(QNum, 1, Qdata), Table2 = Prep2#prepared.qh, NPrep2 = Prep2#prepared{qh = Table2#qlc_table{ms = no_match_spec}}, %% Table2#qlc_table.ms has been reset; the filter will be run. @@ -2059,7 +2048,7 @@ opt_join(Join, JoinOption, Qdata, Opt, LU_SkipQuals) -> opt_join_lu([{{_Q1,_C1,Q2,_C2}=J,[{lookup_join,_KEols,JKE,Skip0} | _]} | LJ], Qdata, LU_SkipQuals) -> - {value, {Q2,_,_,{gen,Prep2}}} = lists:keysearch(Q2, 1, Qdata), + {Q2,_,_,{gen,Prep2}} = lists:keyfind(Q2, 1, Qdata), #qlc_table{ms = MS, key_equality = KE, lookup_fun = LU_fun} = Prep2#prepared.qh, %% If there is no filter to skip (the match spec was derived @@ -2670,8 +2659,8 @@ sort_list_output(L) -> %% Don't use the file_sorter unless it is known that objects will be %% put on a temporary file (optimization). sort_handle(H, ListFun, FileFun, SortOptions, Post, LocalPost, TmpUsageM) -> - Size = case lists:keysearch(size, 1, SortOptions) of - {value, {size, Size0}} -> Size0; + Size = case lists:keyfind(size, 1, SortOptions) of + {size, Size0} -> Size0; false -> default_option(size) end, sort_cache(H, [], Size, {ListFun, FileFun, Post, LocalPost, TmpUsageM}). @@ -2891,8 +2880,8 @@ ucache_recall(UTab, MTab, SeqNo) -> Object = case ets:lookup(UTab, Hash) of [{Hash, SeqNo, Object0}] -> Object0; HashSeqObjects -> - {value, {Hash, SeqNo, Object0}} = - lists:keysearch(SeqNo, 2, HashSeqObjects), + {Hash, SeqNo, Object0} = + lists:keyfind(SeqNo, 2, HashSeqObjects), Object0 end, [Object | fun() -> ucache_recall(UTab, MTab, SeqNo + 1) end] @@ -3403,8 +3392,8 @@ merge_join_id() -> tmp_merge_file(MergeId) -> TmpFiles = get(?MERGE_JOIN_FILE), - case lists:keysearch(MergeId, 1, TmpFiles) of - {value, {MergeId, Fd, FileName}} -> + case lists:keyfind(MergeId, 1, TmpFiles) of + {MergeId, Fd, FileName} -> {Fd, FileName}; false -> none diff --git a/lib/stdlib/src/qlc_pt.erl b/lib/stdlib/src/qlc_pt.erl index 2d7874d99f..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). @@ -845,8 +845,8 @@ join_handle(AP, L, [F, H, O, C], Constants) -> join_handle_constants(QId, ExtraConstants) -> IdNo = QId#qid.no, - case lists:keysearch(IdNo, 1, ExtraConstants) of - {value, {IdNo, ConstOps}} -> + case lists:keyfind(IdNo, 1, ExtraConstants) of + {IdNo, ConstOps} -> ConstOps; false -> [] @@ -1231,9 +1231,9 @@ lu_skip(ColConstants, FilterData, PatternFrame, PatternVars, %% The filter can only be skipped if all constants %% are looked up. LookedUpConstants = - case lists:keysearch(Column, 1, ColConstants) of + case lists:keyfind(Column, 1, ColConstants) of false -> []; - {value, {Column,LUCs}} -> LUCs + {Column, LUCs} -> LUCs end, %% Don't try to handle filters that compare several %% values equal. See also frames_to_columns(). @@ -1279,8 +1279,8 @@ join_gens(Cs0, Qs, Skip) -> join_gens2(lists:filter(fun(C) -> length(C) > 2 end, Cs), FD, Skip)}. join_gens2(Cs0, FilterData, Skip) -> - [{J, skip_tag(case lists:keysearch(J, 1, Skip) of - {value, {J,FilL}} -> + [{J, skip_tag(case lists:keyfind(J, 1, Skip) of + {J, FilL} -> FilL; false -> [] @@ -1296,8 +1296,8 @@ skip_tag(FilList, FilterData) -> end, FilList}. skip_tag(Col, ColFils, FilterData) -> - case lists:keysearch(Col, 1, ColFils) of - {value, {Col, FilL}} -> + case lists:keyfind(Col, 1, ColFils) of + {Col, FilL} -> Tag = if length(FilterData) =:= length(FilL) -> all; @@ -1415,7 +1415,7 @@ sel_gf([], _N, _Deps, _RDs, _Gens, _Gens1) -> sel_gf([{#qid{no = N}=Id,{fil,F}}=Fil | FData], N, Deps, RDs, Gens, Gens1) -> case erl_lint:is_guard_test(F, RDs) of true -> - {value, {Id,GIds}} = lists:keysearch(Id, 1, Deps), + {Id,GIds} = lists:keyfind(Id, 1, Deps), case length(GIds) =< 1 of true -> case generators_in_scope(GIds, Gens1) of @@ -2572,8 +2572,8 @@ nos_pattern([P0 | Ps0], S0, PVs0) -> {[P | Ps], S, PVs}; nos_pattern({var,L,V}, {LI,Vs0,UV,A,Sg}, PVs0) when V =/= '_' -> {Name, Vs, PVs} = - case lists:keysearch(V, 1, PVs0) of - {value, {V,VN}} -> + case lists:keyfind(V, 1, PVs0) of + {V, VN} -> _ = used_var(V, Vs0, UV), {VN, Vs0, PVs0}; false -> diff --git a/lib/stdlib/src/re.erl b/lib/stdlib/src/re.erl index 5417ac02e5..296a6b3d23 100644 --- a/lib/stdlib/src/re.erl +++ b/lib/stdlib/src/re.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% %% -module(re). @@ -32,18 +32,7 @@ split(Subject,RE,Options) -> try {NewOpt,Convert,Unicode,Limit,Strip,Group} = process_split_params(Options,iodata,false,-1,false,false), - FlatSubject = - case is_binary(Subject) of - true -> - Subject; - false -> - case Unicode of - true -> - unicode:characters_to_binary(Subject,unicode); - false -> - iolist_to_binary(Subject) - end - end, + FlatSubject = to_binary(Subject, Unicode), case compile_split(RE,NewOpt) of {error,_Err} -> throw(badre); @@ -217,19 +206,9 @@ replace(Subject,RE,Replacement,Options) -> try {NewOpt,Convert,Unicode} = process_repl_params(Options,iodata,false), - FlatSubject = - case is_binary(Subject) of - true -> - Subject; - false -> - case Unicode of - true -> - unicode:characters_to_binary(Subject,unicode); - false -> - iolist_to_binary(Subject) - end - end, - case do_replace(FlatSubject,Subject,RE,Replacement,NewOpt) of + FlatSubject = to_binary(Subject, Unicode), + FlatReplacement = to_binary(Replacement, Unicode), + case do_replace(FlatSubject,Subject,RE,FlatReplacement,NewOpt) of {error,_Err} -> throw(badre); IoList -> @@ -237,7 +216,12 @@ replace(Subject,RE,Replacement,Options) -> iodata -> IoList; binary -> - iolist_to_binary(IoList); + case Unicode of + false -> + iolist_to_binary(IoList); + true -> + unicode:characters_to_binary(IoList,unicode) + end; list -> case Unicode of false -> @@ -324,8 +308,7 @@ process_split_params([H|T],C,U,L,S,G) -> {[H|NT],NC,NU,NL,NS,NG}. apply_mlist(Subject,Replacement,Mlist) -> - do_mlist(Subject,Subject,0,precomp_repl(iolist_to_binary(Replacement)), - Mlist). + do_mlist(Subject,Subject,0,precomp_repl(Replacement), Mlist). precomp_repl(<<>>) -> @@ -545,7 +528,7 @@ process_uparams([],Type) -> ucompile(RE,Options) -> try - re:compile(unicode:characters_to_binary(RE,unicode)) + re:compile(unicode:characters_to_binary(RE,unicode),Options) catch error:AnyError -> {'EXIT',{new_stacktrace,[{Mod,_,L}|Rest]}} = @@ -618,18 +601,7 @@ grun(Subject,RE,{Options,NeedClean,OrigRE}) -> grun2(Subject,RE,{Options,NeedClean}) -> Unicode = check_for_unicode(RE,Options), - FlatSubject = - case is_binary(Subject) of - true -> - Subject; - false -> - case Unicode of - true -> - unicode:characters_to_binary(Subject,unicode); - false -> - iolist_to_binary(Subject) - end - end, + FlatSubject = to_binary(Subject, Unicode), do_grun(FlatSubject,Subject,Unicode,RE,{Options,NeedClean}). do_grun(FlatSubject,Subject,Unicode,RE,{Options0,NeedClean}) -> @@ -749,3 +721,10 @@ runopt(global) -> true; runopt(_) -> false. + +to_binary(Bin, _IsUnicode) when is_binary(Bin) -> + Bin; +to_binary(Data, true) -> + unicode:characters_to_binary(Data,unicode); +to_binary(Data, false) -> + iolist_to_binary(Data). diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl index a8d31b4e6b..ebb221c151 100644 --- a/lib/stdlib/src/shell.erl +++ b/lib/stdlib/src/shell.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(shell). @@ -22,12 +22,14 @@ -export([whereis_evaluator/0, whereis_evaluator/1]). -export([start_restricted/1, stop_restricted/0]). -export([local_allowed/3, non_local_allowed/3]). +-export([prompt_func/1]). -define(LINEMAX, 30). -define(CHAR_MAX, 60). -define(DEF_HISTORY, 20). -define(DEF_RESULTS, 20). -define(DEF_CATCH_EXCEPTION, false). +-define(DEF_PROMPT_FUNC, default). -define(RECORDS, shell_records). @@ -235,14 +237,15 @@ server(StartSync) -> {History,Results} = check_and_get_history_and_results(), server_loop(0, start_eval(Bs, RT, []), Bs, RT, [], History, Results). -server_loop(N0, Eval_0, Bs0, RT, Ds0, History0, Results0) -> +server_loop(N0, Eval_0, Bs00, RT, Ds00, History0, Results0) -> N = N0 + 1, - {Res, Eval0} = get_command(prompt(N), Eval_0, Bs0, RT, Ds0), + {Eval_1,Bs0,Ds0,Prompt} = prompt(N, Eval_0, Bs00, RT, Ds00), + {Res,Eval0} = get_command(Prompt, Eval_1, Bs0, RT, Ds0), case Res of {ok,Es0,_EndLine} -> case expand_hist(Es0, N) of {ok,Es} -> - {V,Eval,Bs,Ds} = shell_cmd(Es, Eval0, Bs0, RT, Ds0), + {V,Eval,Bs,Ds} = shell_cmd(Es, Eval0, Bs0, RT, Ds0, cmd), {History,Results} = check_and_get_history_and_results(), add_cmd(N, Es, V), HB1 = del_cmd(command, N - History, N - History0, false), @@ -301,7 +304,42 @@ get_command1(Pid, Eval, Bs, RT, Ds) -> get_command1(Pid, start_eval(Bs, RT, Ds), Bs, RT, Ds) end. -prompt(N) -> +prompt(N, Eval0, Bs0, RT, Ds0) -> + case get_prompt_func() of + {M,F} -> + L = [{history,N}], + C = {call,1,{remote,1,{atom,1,M},{atom,1,F}},[{value,1,L}]}, + {V,Eval,Bs,Ds} = shell_cmd([C], Eval0, Bs0, RT, Ds0, pmt), + {Eval,Bs,Ds,case V of + {pmt,Val} -> + Val; + _ -> + bad_prompt_func({M,F}), + default_prompt(N) + end}; + default -> + {Eval0,Bs0,Ds0,default_prompt(N)} + end. + +get_prompt_func() -> + case application:get_env(stdlib, shell_prompt_func) of + {ok,{M,F}=PromptFunc} when is_atom(M), is_atom(F) -> + PromptFunc; + {ok,default=Default} -> + Default; + {ok,Term} -> + bad_prompt_func(Term), + default; + undefined -> + default + end. + +bad_prompt_func(M) -> + fwrite_severity(benign, <<"Bad prompt function: ~p">>, [M]). + +default_prompt(N) -> + %% Don't bother flattening the list irrespective of what the + %% I/O-protocol states. case is_alive() of true -> io_lib:format(<<"(~s)~w> ">>, [node(), N]); false -> io_lib:format(<<"~w> ">>, [N]) @@ -461,14 +499,16 @@ has_bin(T, I) -> has_bin(element(I, T)), has_bin(T, I - 1). -%% shell_cmd(Sequence, Evaluator, Bindings, RecordTable, Dictionary) +%% shell_cmd(Sequence, Evaluator, Bindings, RecordTable, Dictionary, What) %% shell_rep(Evaluator, Bindings, RecordTable, Dictionary) -> %% {Value,Evaluator,Bindings,Dictionary} %% Send a command to the evaluator and wait for the reply. Start a new %% evaluator if necessary. +%% What = pmt | cmd. When evaluating a prompt ('pmt') the evaluated value +%% must not be displayed, and it has to be returned. -shell_cmd(Es, Eval, Bs, RT, Ds) -> - Eval ! {shell_cmd,self(),{eval,Es}}, +shell_cmd(Es, Eval, Bs, RT, Ds, W) -> + Eval ! {shell_cmd,self(),{eval,Es}, W}, shell_rep(Eval, Bs, RT, Ds). shell_rep(Ev, Bs0, RT, Ds0) -> @@ -559,26 +599,26 @@ evaluator(Shell, Bs, RT, Ds) -> eval_loop(Shell, Bs0, RT) -> receive - {shell_cmd,Shell,{eval,Es}} -> + {shell_cmd,Shell,{eval,Es},W} -> Ef = {value, fun(MForFun, As) -> apply_fun(MForFun, As, Shell) end}, Lf = local_func_handler(Shell, RT, Ef), - Bs = eval_exprs(Es, Shell, Bs0, RT, Lf, Ef), + Bs = eval_exprs(Es, Shell, Bs0, RT, Lf, Ef, W), eval_loop(Shell, Bs, RT) end. restricted_eval_loop(Shell, Bs0, RT, RShMod) -> receive - {shell_cmd,Shell,{eval,Es}} -> + {shell_cmd,Shell,{eval,Es}, W} -> {LFH,NLFH} = restrict_handlers(RShMod, Shell, RT), put(restricted_expr_state, []), - Bs = eval_exprs(Es, Shell, Bs0, RT, {eval,LFH}, {value,NLFH}), + Bs = eval_exprs(Es, Shell, Bs0, RT, {eval,LFH}, {value,NLFH}, W), restricted_eval_loop(Shell, Bs, RT, RShMod) end. -eval_exprs(Es, Shell, Bs0, RT, Lf, Ef) -> +eval_exprs(Es, Shell, Bs0, RT, Lf, Ef, W) -> try - {R,Bs2} = exprs(Es, Bs0, RT, Lf, Ef), + {R,Bs2} = exprs(Es, Bs0, RT, Lf, Ef, W), Shell ! {shell_rep,self(),R}, Bs2 catch @@ -614,10 +654,10 @@ do_catch(_Class, _Reason) -> false end. -exprs(Es, Bs0, RT, Lf, Ef) -> - exprs(Es, Bs0, RT, Lf, Ef, Bs0). +exprs(Es, Bs0, RT, Lf, Ef, W) -> + exprs(Es, Bs0, RT, Lf, Ef, Bs0, W). -exprs([E0|Es], Bs1, RT, Lf, Ef, Bs0) -> +exprs([E0|Es], Bs1, RT, Lf, Ef, Bs0, W) -> UsedRecords = used_record_defs(E0, RT), RBs = record_bindings(UsedRecords, Bs1), case check_command(prep_check([E0]), RBs) of @@ -629,16 +669,20 @@ exprs([E0|Es], Bs1, RT, Lf, Ef, Bs0) -> if Es =:= [] -> VS = pp(V0, 1, RT), - io:requests([{put_chars, VS}, nl]), + [io:requests([{put_chars, VS}, nl]) || W =:= cmd], %% Don't send the result back if it will be %% discarded anyway. - V = case result_will_be_saved() of - true -> V0; - false -> ignored + V = if + W =:= pmt -> + {W,V0}; + true -> case result_will_be_saved() of + true -> V0; + false -> ignored + end end, {{value,V,Bs,get()},Bs}; true -> - exprs(Es, Bs, RT, Lf, Ef, Bs0) + exprs(Es, Bs, RT, Lf, Ef, Bs0, W) end; {error,Error} -> {{command_error,Error},Bs0} @@ -1383,7 +1427,7 @@ pp(V, I, RT) -> columns() -> case io:columns() of - {ok,N} -> N; + {ok,N} -> N; _ -> 80 end. @@ -1438,3 +1482,9 @@ results(L) when is_integer(L), L >= 0 -> catch_exception(Bool) -> set_env(stdlib, shell_catch_exception, Bool, ?DEF_CATCH_EXCEPTION). + +-type prompt_func() :: 'default' | {module(),atom()}. +-spec prompt_func(prompt_func()) -> prompt_func(). + +prompt_func(String) -> + set_env(stdlib, shell_prompt_func, String, ?DEF_PROMPT_FUNC). diff --git a/lib/stdlib/src/shell_default.erl b/lib/stdlib/src/shell_default.erl index 670f8cdb44..3fe359af0e 100644 --- a/lib/stdlib/src/shell_default.erl +++ b/lib/stdlib/src/shell_default.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% %% @@ -45,6 +45,7 @@ help() -> format("h() -- history\n"), format("history(N) -- set how many previous commands to keep\n"), format("results(N) -- set how many previous command results to keep\n"), + format("catch_exception(B) -- how exceptions are handled\n"), format("v(N) -- use the value of query <N>\n"), format("rd(R,D) -- define a record\n"), format("rf() -- remove all record information\n"), diff --git a/lib/stdlib/src/supervisor.erl b/lib/stdlib/src/supervisor.erl index fb1303d1eb..22269a8d1b 100644 --- a/lib/stdlib/src/supervisor.erl +++ b/lib/stdlib/src/supervisor.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(supervisor). @@ -24,7 +24,7 @@ -export([start_link/2,start_link/3, start_child/2, restart_child/2, delete_child/2, terminate_child/2, - which_children/1, + which_children/1, count_children/1, check_childspecs/1]). -export([behaviour_info/1]). @@ -95,6 +95,9 @@ terminate_child(Supervisor, Name) -> which_children(Supervisor) -> call(Supervisor, which_children). +count_children(Supervisor) -> + call(Supervisor, count_children). + call(Supervisor, Req) -> gen_server:call(Supervisor, Req, infinity). @@ -297,7 +300,49 @@ handle_call(which_children, _From, State) -> {Name, Pid, ChildType, Mods} end, State#state.children), - {reply, Resp, State}. + {reply, Resp, State}; + +handle_call(count_children, _From, State) when ?is_simple(State) -> + [#child{child_type = CT}] = State#state.children, + {Active, Count} = + ?DICT:fold(fun(Pid, _Val, {Alive, Tot}) -> + if is_pid(Pid) -> {Alive+1, Tot +1}; + true -> {Alive, Tot + 1} end + end, {0, 0}, State#state.dynamics), + Reply = case CT of + supervisor -> [{specs, 1}, {active, Active}, + {supervisors, Count}, {workers, 0}]; + worker -> [{specs, 1}, {active, Active}, + {supervisors, 0}, {workers, Count}] + end, + {reply, Reply, State}; + +handle_call(count_children, _From, State) -> + + %% Specs and children are together on the children list... + {Specs, Active, Supers, Workers} = + lists:foldl(fun(Child, Counts) -> + count_child(Child, Counts) + end, {0,0,0,0}, State#state.children), + + %% Reformat counts to a property list. + Reply = [{specs, Specs}, {active, Active}, + {supervisors, Supers}, {workers, Workers}], + {reply, Reply, State}. + + +count_child(#child{pid = Pid, child_type = worker}, + {Specs, Active, Supers, Workers}) -> + case is_pid(Pid) andalso is_process_alive(Pid) of + true -> {Specs+1, Active+1, Supers, Workers+1}; + false -> {Specs+1, Active, Supers, Workers+1} + end; +count_child(#child{pid = Pid, child_type = supervisor}, + {Specs, Active, Supers, Workers}) -> + case is_pid(Pid) andalso is_process_alive(Pid) of + true -> {Specs+1, Active+1, Supers+1, Workers}; + false -> {Specs+1, Active, Supers+1, Workers} + end. %%% Hopefully cause a function-clause as there is no API function diff --git a/lib/stdlib/src/sys.erl b/lib/stdlib/src/sys.erl index e0f2dbcd3c..12209c16d7 100644 --- a/lib/stdlib/src/sys.erl +++ b/lib/stdlib/src/sys.erl @@ -245,8 +245,17 @@ do_cmd(SysState, Other, _Parent, _Mod, Debug, Misc) -> {SysState, {error, {unknown_system_msg, Other}}, Debug, Misc}. get_status(SysState, Parent, Mod, Debug, Misc) -> + PDict = get(), + FmtMisc = + case erlang:function_exported(Mod, format_status, 2) of + true -> + FmtArgs = [PDict, SysState, Parent, Debug, Misc], + Mod:format_status(normal, FmtArgs); + _ -> + Misc + end, {status, self(), {module, Mod}, - [get(), SysState, Parent, Debug, Misc]}. + [PDict, SysState, Parent, Debug, FmtMisc]}. %%----------------------------------------------------------------- %% These are the system debug commands. diff --git a/lib/stdlib/test/ExpandTestCaps.erl b/lib/stdlib/test/ExpandTestCaps.erl new file mode 100644 index 0000000000..96c4115354 --- /dev/null +++ b/lib/stdlib/test/ExpandTestCaps.erl @@ -0,0 +1,32 @@ +%% +%% %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('ExpandTestCaps'). + +-export([a_fun_name/1, + a_less_fun_name/1, + b_comes_after_a/1]). + +a_fun_name(X) -> + X. + +a_less_fun_name(X) -> + X. + +b_comes_after_a(X) -> + X. diff --git a/lib/stdlib/test/ExpandTestCaps1.erl b/lib/stdlib/test/ExpandTestCaps1.erl new file mode 100644 index 0000000000..09ee9f81c4 --- /dev/null +++ b/lib/stdlib/test/ExpandTestCaps1.erl @@ -0,0 +1,44 @@ +%% +%% %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('ExpandTestCaps1'). + +-export([a_fun_name/1, + a_less_fun_name/1, + b_comes_after_a/1, + 'Quoted_fun_name'/0, + 'Quoted_fun_too'/0, + '#weird-fun-name'/0]). + +a_fun_name(X) -> + X. + +a_less_fun_name(X) -> + X. + +b_comes_after_a(X) -> + X. + +'Quoted_fun_name'() -> + whoopee. + +'Quoted_fun_too'() -> + too. + +'#weird-fun-name'() -> + weird. diff --git a/lib/stdlib/test/Makefile b/lib/stdlib/test/Makefile index 7a87eef5f3..9beac93eb8 100644 --- a/lib/stdlib/test/Makefile +++ b/lib/stdlib/test/Makefile @@ -18,6 +18,7 @@ MODULES= \ digraph_utils_SUITE \ dummy1_h \ dummy_h \ + edlin_expand_SUITE \ epp_SUITE \ erl_eval_helper \ erl_eval_SUITE \ @@ -29,6 +30,10 @@ MODULES= \ escript_SUITE \ ets_SUITE \ ets_tough_SUITE \ + expand_test \ + expand_test1 \ + ExpandTestCaps \ + ExpandTestCaps1 \ filelib_SUITE \ file_sorter_SUITE \ filename_SUITE \ @@ -105,7 +110,7 @@ COVERFILE=stdlib.cover make_emakefile: $(ERL_TOP)/make/make_emakefile $(ERL_COMPILE_FLAGS) -o$(EBIN) $(MODULES) \ - >> $(EMAKEFILE) + > $(EMAKEFILE) tests debug opt: make_emakefile erl $(ERL_MAKE_FLAGS) -make diff --git a/lib/stdlib/test/array_SUITE.erl b/lib/stdlib/test/array_SUITE.erl index 7cfdcf6dfd..e7cfc65be1 100644 --- a/lib/stdlib/test/array_SUITE.erl +++ b/lib/stdlib/test/array_SUITE.erl @@ -384,11 +384,17 @@ set_get_test_() -> ?_assert(array:get(0, set(0, 42, set(0, 17, new()))) =:= 42), - ?_assert(array:get(0, reset(0, new())) =:= undefined), - ?_assert(array:get(0, reset(0, set(0, 17, new()))) =:= undefined), - ?_assert(array:get(0, reset(0, new({default,42}))) =:= 42), - ?_assert(array:get(0, reset(0, set(0, 17, new({default,42})))) - =:= 42) + ?_assertError(badarg, array:get(0, reset(11, new([{size,10}])))), + ?_assertError(badarg, array:get(0, reset(-1, new([{size,10}])))), + ?_assert(array:get(0, reset(0, new())) =:= undefined), + ?_assert(array:get(0, reset(0, set(0, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(9, set(9, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(11, set(11, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(11, set(12, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(1, set(12, 17, new()))) =:= undefined), + ?_assert(array:get(0, reset(11, new())) =:= undefined), + ?_assert(array:get(0, reset(0, set(0, 17, new({default,42})))) =:= 42), + ?_assert(array:get(0, reset(0, new({default,42}))) =:= 42) ]. to_list_test_() -> diff --git a/lib/stdlib/test/c_SUITE.erl b/lib/stdlib/test/c_SUITE.erl index 5608d73d19..2edbc7ab4c 100644 --- a/lib/stdlib/test/c_SUITE.erl +++ b/lib/stdlib/test/c_SUITE.erl @@ -18,15 +18,16 @@ %% -module(c_SUITE). -export([all/1]). --export([c_1/1, c_2/1, c_3/1, c_4/1, memory/1]). +-export([c_1/1, c_2/1, c_3/1, c_4/1, nc_1/1, nc_2/1, nc_3/1, nc_4/1, + memory/1]). -include("test_server.hrl"). --import(c, [c/2]). +-import(c, [c/2, nc/2]). all(doc) -> ["Test cases for the 'c' module."]; all(suite) -> - [c_1, c_2, c_3, c_4, memory]. + [c_1, c_2, c_3, c_4, nc_1, nc_2, nc_3, nc_4, memory]. %%% Write output to a directory other than current directory: @@ -34,7 +35,7 @@ c_1(doc) -> ["Checks that c:c works also with option 'outdir' [ticket OTP-1209]."]; c_1(suite) -> []; -c_1(Config) when list(Config) -> +c_1(Config) when is_list(Config) -> ?line R = filename:join(?config(data_dir, Config), "m.erl"), ?line W = ?config(priv_dir, Config), ?line Result = c(R,[{outdir,W}]), @@ -44,7 +45,7 @@ c_2(doc) -> ["Checks that c:c works also with option 'outdir' [ticket OTP-1209]."]; c_2(suite) -> []; -c_2(Config) when list(Config) -> +c_2(Config) when is_list(Config) -> ?line R = filename:join(?config(data_dir, Config), "m"), ?line W = ?config(priv_dir, Config), ?line Result = c(R,[{outdir,W}]), @@ -59,7 +60,7 @@ c_3(doc) -> "directory). [ticket OTP-1209]."]; c_3(suite) -> []; -c_3(Config) when list(Config) -> +c_3(Config) when is_list(Config) -> ?line R = filename:join(?config(data_dir, Config), "m.erl"), ?line W = ?config(priv_dir, Config), ?line file:set_cwd(W), @@ -71,18 +72,68 @@ c_4(doc) -> "directory). [ticket OTP-1209]."]; c_4(suite) -> []; -c_4(Config) when list(Config) -> +c_4(Config) when is_list(Config) -> ?line R = filename:join(?config(data_dir, Config), "m"), ?line W = ?config(priv_dir, Config), ?line file:set_cwd(W), ?line Result = c(R,[{outdir,W}]), ?line {ok, m} = Result. +%%% Write output to a directory other than current directory: + +nc_1(doc) -> + ["Checks that c:nc works also with option 'outdir'."]; +nc_1(suite) -> + []; +nc_1(Config) when is_list(Config) -> + ?line R = filename:join(?config(data_dir, Config), "m.erl"), + ?line W = ?config(priv_dir, Config), + ?line Result = nc(R,[{outdir,W}]), + ?line {ok, m} = Result. + +nc_2(doc) -> + ["Checks that c:nc works also with option 'outdir'."]; +nc_2(suite) -> + []; +nc_2(Config) when is_list(Config) -> + ?line R = filename:join(?config(data_dir, Config), "m"), + ?line W = ?config(priv_dir, Config), + ?line Result = nc(R,[{outdir,W}]), + ?line {ok, m} = Result. + + +%%% Put results in current directory (or rather, change current dir +%%% to the output dir): + +nc_3(doc) -> + ["Checks that c:nc works also with option 'outdir' (same as current" + "directory)."]; +nc_3(suite) -> + []; +nc_3(Config) when is_list(Config) -> + ?line R = filename:join(?config(data_dir, Config), "m.erl"), + ?line W = ?config(priv_dir, Config), + ?line file:set_cwd(W), + ?line Result = nc(R,[{outdir,W}]), + ?line {ok, m} = Result. + +nc_4(doc) -> + ["Checks that c:nc works also with option 'outdir' (same as current" + "directory)."]; +nc_4(suite) -> + []; +nc_4(Config) when is_list(Config) -> + ?line R = filename:join(?config(data_dir, Config), "m"), + ?line W = ?config(priv_dir, Config), + ?line file:set_cwd(W), + ?line Result = nc(R,[{outdir,W}]), + ?line {ok, m} = Result. + memory(doc) -> ["Checks that c:memory/[0,1] returns consistent results."]; memory(suite) -> []; -memory(Config) when list(Config) -> +memory(Config) when is_list(Config) -> try ?line ML = c:memory(), ?line T = mget(total, ML), @@ -112,5 +163,5 @@ mget(K, L) -> ?line test_v(V). % Help function for c_SUITE:memory/1 -test_v(V) when integer(V) -> +test_v(V) when is_integer(V) -> ?line V. diff --git a/lib/stdlib/test/calendar_SUITE.erl b/lib/stdlib/test/calendar_SUITE.erl index ea81bb99a9..10fb72c1b1 100644 --- a/lib/stdlib/test/calendar_SUITE.erl +++ b/lib/stdlib/test/calendar_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(calendar_SUITE). @@ -48,7 +48,7 @@ gregorian_days(doc) -> "At the same time valid_date is tested."; gregorian_days(suite) -> []; -gregorian_days(Config) when list(Config) -> +gregorian_days(Config) when is_list(Config) -> ?line Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}), ?line MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}), ?line check_gregorian_days(Days, MaxDays). @@ -60,7 +60,7 @@ gregorian_seconds(doc) -> "every 2 days + 1 second."; gregorian_seconds(suite) -> []; -gregorian_seconds(Config) when list(Config) -> +gregorian_seconds(Config) when is_list(Config) -> ?line Secs = calendar:datetime_to_gregorian_seconds({{?START_YEAR, 1, 1}, {0, 0, 0}}), ?line MaxSecs = calendar:datetime_to_gregorian_seconds({{?END_YEAR, 1, 1}, @@ -72,7 +72,7 @@ day_of_the_week(doc) -> "year ?START_YEAR up to ?END_YEAR."; day_of_the_week(suite) -> []; -day_of_the_week(Config) when list(Config) -> +day_of_the_week(Config) when is_list(Config) -> ?line Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}), ?line MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}), ?line DayNumber = calendar:day_of_the_week({?START_YEAR, 1, 1}), @@ -82,7 +82,7 @@ day_of_the_week_calibrate(doc) -> "Tests that day_of_the_week for 1997-11-11 is Tuesday (2)"; day_of_the_week_calibrate(suite) -> []; -day_of_the_week_calibrate(Config) when list(Config) -> +day_of_the_week_calibrate(Config) when is_list(Config) -> ?line 2 = calendar:day_of_the_week({1997, 11, 11}). leap_years(doc) -> @@ -90,7 +90,7 @@ leap_years(doc) -> "year ?START_YEAR up to ?END_YEAR."; leap_years(suite) -> []; -leap_years(Config) when list(Config) -> +leap_years(Config) when is_list(Config) -> ?line check_leap_years(?START_YEAR, ?END_YEAR). last_day_of_the_month(doc) -> @@ -98,14 +98,14 @@ last_day_of_the_month(doc) -> "year ?START_YEAR up to ?END_YEAR."; last_day_of_the_month(suite) -> []; -last_day_of_the_month(Config) when list(Config) -> +last_day_of_the_month(Config) when is_list(Config) -> ?line check_last_day_of_the_month({?START_YEAR, 1}, {?END_YEAR, 1}). local_time_to_universal_time_dst(doc) -> "Tests local_time_to_universal_time_dst for MET"; local_time_to_universal_time_dst(suite) -> []; -local_time_to_universal_time_dst(Config) when list(Config) -> +local_time_to_universal_time_dst(Config) when is_list(Config) -> case os:type() of {unix,_} -> case os:cmd("date '+%Z'") of @@ -117,7 +117,7 @@ local_time_to_universal_time_dst(Config) when list(Config) -> _ -> local_time_to_universal_time_dst_x(Config) end. -local_time_to_universal_time_dst_x(Config) when list(Config) -> +local_time_to_universal_time_dst_x(Config) when is_list(Config) -> %% Assumes MET (UTC+1 / UTC+2(dst) ?line LtW = {{2003,01,15},{14,00,00}}, % Winter ?line UtW = {{2003,01,15},{13,00,00}}, % diff --git a/lib/stdlib/test/edlin_expand_SUITE.erl b/lib/stdlib/test/edlin_expand_SUITE.erl new file mode 100644 index 0000000000..613bfd000e --- /dev/null +++ b/lib/stdlib/test/edlin_expand_SUITE.erl @@ -0,0 +1,156 @@ +%% +%% %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(edlin_expand_SUITE). +-export([all/1]). + +-export([normal/1, quoted_fun/1, quoted_module/1, quoted_both/1]). + +-export([init_per_testcase/2, fin_per_testcase/2]). + +-include("test_server.hrl"). + +% Default timetrap timeout (set in init_per_testcase). +-define(default_timeout, ?t:minutes(1)). + +init_per_testcase(_Case, Config) -> + ?line Dog = ?t:timetrap(?default_timeout), + [{watchdog, Dog} | Config]. +fin_per_testcase(_Case, Config) -> + Dog = ?config(watchdog, Config), + test_server:timetrap_cancel(Dog), + ok. + +all(doc) -> + ["Test cases for edlin_expand."]; +all(suite) -> + [normal, quoted_fun, quoted_module, quoted_both]. + +normal(doc) -> + [""]; +normal(suite) -> + []; +normal(Config) when is_list(Config) -> + ?line {module,expand_test} = c:l(expand_test), + % These tests might fail if another module with the prefix "expand_" happens + % to also be loaded. + ?line {yes, "test:", []} = edlin_expand:expand(lists:reverse("expand_")), + ?line {no, [], []} = edlin_expand:expand(lists:reverse("expandXX_")), + ?line {no,[], + [{"a_fun_name",1}, + {"a_less_fun_name",1}, + {"b_comes_after_a",1}, + {"module_info",0}, + {"module_info",1}]} = edlin_expand:expand(lists:reverse("expand_test:")), + ?line {yes,[],[{"a_fun_name",1}, + {"a_less_fun_name",1}]} = edlin_expand:expand( + lists:reverse("expand_test:a_")), + ok. + +quoted_fun(doc) -> + ["Normal module name, some function names using quoted atoms"]; +quoted_fun(suite) -> + []; +quoted_fun(Config) when is_list(Config) -> + ?line {module,expand_test} = c:l(expand_test), + ?line {module,expand_test1} = c:l(expand_test1), + %% should be no colon after test this time + ?line {yes, "test", []} = edlin_expand:expand(lists:reverse("expand_")), + ?line {no, [], []} = edlin_expand:expand(lists:reverse("expandXX_")), + ?line {no,[],[{"'#weird-fun-name'",0}, + {"'Quoted_fun_name'",0}, + {"'Quoted_fun_too'",0}, + {"a_fun_name",1}, + {"a_less_fun_name",1}, + {"b_comes_after_a",1}, + {"module_info",0}, + {"module_info",1}]} = edlin_expand:expand( + lists:reverse("expand_test1:")), + ?line {yes,"_",[]} = edlin_expand:expand( + lists:reverse("expand_test1:a")), + ?line {yes,[],[{"a_fun_name",1}, + {"a_less_fun_name",1}]} = edlin_expand:expand( + lists:reverse("expand_test1:a_")), + ?line {yes,[], + [{"'#weird-fun-name'",0}, + {"'Quoted_fun_name'",0}, + {"'Quoted_fun_too'",0}]} = edlin_expand:expand( + lists:reverse("expand_test1:'")), + ?line {yes,"uoted_fun_",[]} = edlin_expand:expand( + lists:reverse("expand_test1:'Q")), + ?line {yes,[], + [{"'Quoted_fun_name'",0}, + {"'Quoted_fun_too'",0}]} = edlin_expand:expand( + lists:reverse("expand_test1:'Quoted_fun_")), + ?line {yes,"weird-fun-name'(",[]} = edlin_expand:expand( + lists:reverse("expand_test1:'#")), + ok. + +quoted_module(doc) -> + [""]; +quoted_module(suite) -> + []; +quoted_module(Config) when is_list(Config) -> + ?line {module,'ExpandTestCaps'} = c:l('ExpandTestCaps'), + ?line {yes, "Caps':", []} = edlin_expand:expand(lists:reverse("'ExpandTest")), + ?line {no,[], + [{"a_fun_name",1}, + {"a_less_fun_name",1}, + {"b_comes_after_a",1}, + {"module_info",0}, + {"module_info",1}]} = edlin_expand:expand(lists:reverse("'ExpandTestCaps':")), + ?line {yes,[],[{"a_fun_name",1}, + {"a_less_fun_name",1}]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps':a_")), + ok. + +quoted_both(suite) -> + []; +quoted_both(Config) when is_list(Config) -> + ?line {module,'ExpandTestCaps'} = c:l('ExpandTestCaps'), + ?line {module,'ExpandTestCaps1'} = c:l('ExpandTestCaps1'), + %% should be no colon (or quote) after test this time + ?line {yes, "Caps", []} = edlin_expand:expand(lists:reverse("'ExpandTest")), + ?line {no,[],[{"'#weird-fun-name'",0}, + {"'Quoted_fun_name'",0}, + {"'Quoted_fun_too'",0}, + {"a_fun_name",1}, + {"a_less_fun_name",1}, + {"b_comes_after_a",1}, + {"module_info",0}, + {"module_info",1}]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps1':")), + ?line {yes,"_",[]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps1':a")), + ?line {yes,[],[{"a_fun_name",1}, + {"a_less_fun_name",1}]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps1':a_")), + ?line {yes,[], + [{"'#weird-fun-name'",0}, + {"'Quoted_fun_name'",0}, + {"'Quoted_fun_too'",0}]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps1':'")), + ?line {yes,"uoted_fun_",[]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps1':'Q")), + ?line {yes,[], + [{"'Quoted_fun_name'",0}, + {"'Quoted_fun_too'",0}]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps1':'Quoted_fun_")), + ?line {yes,"weird-fun-name'(",[]} = edlin_expand:expand( + lists:reverse("'ExpandTestCaps1':'#")), + ok. diff --git a/lib/stdlib/test/epp_SUITE.erl b/lib/stdlib/test/epp_SUITE.erl index 67e20fd2e1..9a3ae0baf5 100644 --- a/lib/stdlib/test/epp_SUITE.erl +++ b/lib/stdlib/test/epp_SUITE.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(epp_SUITE). @@ -23,7 +23,7 @@ upcase_mac/1, upcase_mac_1/1, upcase_mac_2/1, variable/1, variable_1/1, otp_4870/1, otp_4871/1, otp_5362/1, pmod/1, not_circular/1, skip_header/1, otp_6277/1, otp_7702/1, - otp_8130/1]). + otp_8130/1, overload_mac/1, otp_8388/1]). -export([epp_parse_erl_form/2]). @@ -61,8 +61,9 @@ fin_per_testcase(_, Config) -> all(doc) -> ["Test cases for epp."]; all(suite) -> - [rec_1, upcase_mac, predef_mac, variable, otp_4870, otp_4871, otp_5362, - pmod, not_circular, skip_header, otp_6277, otp_7702, otp_8130]. + [rec_1, upcase_mac, predef_mac, variable, otp_4870, otp_4871, otp_5362, + pmod, not_circular, skip_header, otp_6277, otp_7702, otp_8130, + overload_mac, otp_8388]. rec_1(doc) -> ["Recursive macros hang or crash epp (OTP-1398)."]; @@ -466,7 +467,7 @@ otp_6277(Config) when is_list(Config) -> -define(ASSERT, ?MODULE). ?ASSERT().">>, - [{error,{{4,16},epp,{undefined,'MODULE'}}}]}], + [{error,{{4,16},epp,{undefined,'MODULE', none}}}]}], ?line [] = check(Config, Ts), ok. @@ -673,7 +674,7 @@ otp_8130(Config) when is_list(Config) -> {otp_8130_c7, <<"\nt() -> ?A.\n">>, - {errors,[{{2,9},epp,{undefined,'A'}}],[]}}, + {errors,[{{2,9},epp,{undefined,'A', none}}],[]}}, {otp_8130_c8, <<"\n-include_lib(\"$apa/foo.hrl\").\n">>, @@ -683,7 +684,7 @@ otp_8130(Config) when is_list(Config) -> {otp_8130_c9, <<"-define(S, ?S).\n" "t() -> ?S.\n">>, - {errors,[{{2,9},epp,{circular,'S'}}],[]}}, + {errors,[{{2,9},epp,{circular,'S', none}}],[]}}, {otp_8130_c10, <<"\n-file.">>, @@ -718,22 +719,22 @@ otp_8130(Config) when is_list(Config) -> {otp_8130_c17, <<"\n-define(A(B), B).\n" "-define(A, 1).\n">>, - {errors,[{{3,9},epp,{redefine,'A'}}],[]}}, + []}, {otp_8130_c18, <<"\n-define(A, 1).\n" "-define(A(B), B).\n">>, - {errors,[{{3,9},epp,{redefine,'A'}}],[]}}, + []}, {otp_8130_c19, <<"\n-define(a(B), B).\n" "-define(a, 1).\n">>, - {errors,[{{3,9},epp,{redefine,a}}],[]}}, + []}, {otp_8130_c20, <<"\n-define(a, 1).\n" "-define(a(B), B).\n">>, - {errors,[{{3,9},epp,{redefine,a}}],[]}}, + []}, {otp_8130_c21, <<"\n-define(A(B, B), B).\n">>, @@ -745,7 +746,7 @@ otp_8130(Config) when is_list(Config) -> {otp_8130_c23, <<"\n-file(?b, 3).\n">>, - {errors,[{{2,8},epp,{undefined,b}}],[]}}, + {errors,[{{2,8},epp,{undefined,b, none}}],[]}}, {otp_8130_c24, <<"\n-include(\"no such file.erl\").\n">>, @@ -821,7 +822,8 @@ macs(Epp) -> macro(Epp, N) -> case lists:keyfind({atom,N}, 1, epp:macro_defs(Epp)) of false -> false; - {{atom,N},{_,V}} -> V + {{atom,N},{_,V}} -> V; + {{atom,N},Defs} -> lists:append([V || {_,{_,V}} <- Defs]) end. ifdef(Config) -> @@ -1030,6 +1032,113 @@ ifdef(Config) -> ], ?line [] = run(Config, Ts). + + +overload_mac(doc) -> + ["Advanced test on overloading macros."]; +overload_mac(suite) -> + []; +overload_mac(Config) when is_list(Config) -> + Cs = [ + %% '-undef' removes all definitions of a macro + {overload_mac_c1, + <<"-define(A, a).\n" + "-define(A(X), X).\n" + "-undef(A).\n" + "t1() -> ?A.\n", + "t2() -> ?A(1).">>, + {errors,[{{4,9},epp,{undefined,'A', none}}, + {{5,9},epp,{undefined,'A', 1}}],[]}}, + + %% cannot overload predefined macros + {overload_mac_c2, + <<"-define(MODULE(X), X).">>, + {errors,[{{1,9},epp,{redefine_predef,'MODULE'}}],[]}}, + + %% cannot overload macros with same arity + {overload_mac_c3, + <<"-define(A(X), X).\n" + "-define(A(Y), Y).">>, + {errors,[{{2,9},epp,{redefine,'A'}}],[]}}, + + {overload_mac_c4, + <<"-define(A, a).\n" + "-define(A(X,Y), {X,Y}).\n" + "a(X) -> X.\n" + "t() -> ?A(1).">>, + {errors,[{{4,9},epp,{mismatch,'A'}}],[]}} + ], + ?line [] = compile(Config, Cs), + + Ts = [ + {overload_mac_r1, + <<"-define(A, 1).\n" + "-define(A(X), X).\n" + "-define(A(X, Y), {X, Y}).\n" + "t() -> {?A, ?A(2), ?A(3, 4)}.">>, + {1, 2, {3, 4}}}, + + {overload_mac_r2, + <<"-define(A, 1).\n" + "-define(A(X), X).\n" + "t() -> ?A(?A).">>, + 1}, + + {overload_mac_r3, + <<"-define(A, ?B).\n" + "-define(B, a).\n" + "-define(B(X), {b,X}).\n" + "a(X) -> X.\n" + "t() -> ?A(1).">>, + 1} + ], + ?line [] = run(Config, Ts). + + +otp_8388(doc) -> + ["OTP-8388. More tests on overloaded macros."]; +otp_8388(suite) -> + []; +otp_8388(Config) when is_list(Config) -> + Dir = ?config(priv_dir, Config), + ?line File = filename:join(Dir, "otp_8388.erl"), + ?line ok = file:write_file(File, <<"-module(otp_8388)." + "-define(LINE, a).">>), + fun() -> + PreDefMacros = [{'LINE', a}], + ?line {error,{redefine_predef,'LINE'}} = + epp:open(File, [], PreDefMacros) + end(), + + fun() -> + PreDefMacros = ['LINE'], + ?line {error,{redefine_predef,'LINE'}} = + epp:open(File, [], PreDefMacros) + end(), + + Ts = [ + {macro_1, + <<"-define(m(A), A).\n" + "t() -> ?m(,).\n">>, + {errors,[{{2,11},epp,{arg_error,m}}],[]}}, + {macro_2, + <<"-define(m(A), A).\n" + "t() -> ?m(a,).\n">>, + {errors,[{{2,12},epp,{arg_error,m}}],[]}}, + {macro_3, + <<"-define(LINE, a).\n">>, + {errors,[{{1,9},epp,{redefine_predef,'LINE'}}],[]}}, + {macro_4, + <<"-define(A(B, C, D), {B,C,D}).\n" + "t() -> ?A(a,,3).\n">>, + {errors,[{{2,8},epp,{mismatch,'A'}}],[]}}, + {macro_5, + <<"-define(Q, {?F0(), ?F1(,,4)}).\n">>, + {errors,[{{1,24},epp,{arg_error,'F1'}}],[]}} + ], + ?line [] = compile(Config, Ts), + ok. + check(Config, Tests) -> eval_tests(Config, fun check_test/2, Tests). 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/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index 6016bc9bdc..13c87ca005 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.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(ets_SUITE). @@ -4530,10 +4530,16 @@ meta_wb(Config) when is_list(Config) -> meta_wb_do(Opts) -> %% Do random new/delete/rename of colliding named tables - Names = [pioneer | colliding_names(pioneer)], + Names0 = [pioneer | colliding_names(pioneer)], + + %% Remove any names that happen to exist as tables already + Names = lists:filter(fun(Name) -> ets:info(Name) == undefined end, + Names0), Len = length(Names), OpFuns = {fun meta_wb_new/4, fun meta_wb_delete/4, fun meta_wb_rename/4}, + ?line true = (Len >= 3), + io:format("Colliding names = ~p\n",[Names]), F = fun(0,_,_) -> ok; (N,Tabs,Me) -> Name1 = lists:nth(random:uniform(Len),Names), diff --git a/lib/stdlib/test/ets_tough_SUITE.erl b/lib/stdlib/test/ets_tough_SUITE.erl index e3d44d00b9..4c8d941f13 100644 --- a/lib/stdlib/test/ets_tough_SUITE.erl +++ b/lib/stdlib/test/ets_tough_SUITE.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(ets_tough_SUITE). @@ -40,7 +40,7 @@ fin_per_testcase(_Func, Config) -> ets:delete(?GLOBAL_PARAMS). -ex1(Config) when list(Config) -> +ex1(Config) when is_list(Config) -> ?line ets:new(?GLOBAL_PARAMS,[named_table,public]), ?line ets:insert(?GLOBAL_PARAMS,{a,set}), ?line ets:insert(?GLOBAL_PARAMS,{b,set}), @@ -269,7 +269,7 @@ show_entries(Fd) -> start(DbName) -> case gen_server:start_link(ets_tough_SUITE,{DbName,no_dump_dir},[]) of - {ok,Pid} when pid(Pid) -> + {ok,Pid} when is_pid(Pid) -> {ok, Pid}; Other -> Other @@ -283,7 +283,7 @@ start(DbName) -> start(DbName,DumpDir) -> case gen_server:start_link(ets_tough_SUITE, {DbName,{dump_dir,DumpDir}},[]) of - {ok,Pid} when pid(Pid) -> + {ok,Pid} when is_pid(Pid) -> {ok, Pid}; Other -> Other @@ -1075,7 +1075,7 @@ phys_read_len(Fd) -> phys_read_entry(Fd,Len) -> case io:get_chars(Fd,'',Len) of - L when list(L), length(L) == Len -> + L when is_list(L), length(L) == Len -> {ok,binary_to_term(list_to_binary(L))}; Other -> {error,{read_term,Other}} diff --git a/lib/stdlib/test/expand_test.erl b/lib/stdlib/test/expand_test.erl new file mode 100644 index 0000000000..63e4bc3aa0 --- /dev/null +++ b/lib/stdlib/test/expand_test.erl @@ -0,0 +1,32 @@ +%% +%% %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(expand_test). + +-export([a_fun_name/1, + a_less_fun_name/1, + b_comes_after_a/1]). + +a_fun_name(X) -> + X. + +a_less_fun_name(X) -> + X. + +b_comes_after_a(X) -> + X. diff --git a/lib/stdlib/test/expand_test1.erl b/lib/stdlib/test/expand_test1.erl new file mode 100644 index 0000000000..11b6fec0f3 --- /dev/null +++ b/lib/stdlib/test/expand_test1.erl @@ -0,0 +1,44 @@ +%% +%% %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(expand_test1). + +-export([a_fun_name/1, + a_less_fun_name/1, + b_comes_after_a/1, + 'Quoted_fun_name'/0, + 'Quoted_fun_too'/0, + '#weird-fun-name'/0]). + +a_fun_name(X) -> + X. + +a_less_fun_name(X) -> + X. + +b_comes_after_a(X) -> + X. + +'Quoted_fun_name'() -> + whoopee. + +'Quoted_fun_too'() -> + too. + +'#weird-fun-name'() -> + weird. diff --git a/lib/stdlib/test/filelib_SUITE.erl b/lib/stdlib/test/filelib_SUITE.erl index c9c6054f7b..d54741051f 100644 --- a/lib/stdlib/test/filelib_SUITE.erl +++ b/lib/stdlib/test/filelib_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2005-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2005-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% %% @@ -21,7 +21,7 @@ -export([all/1,init_per_testcase/2,fin_per_testcase/2, wildcard_one/1,wildcard_two/1,wildcard_errors/1, - fold_files/1,otp_5960/1]). + fold_files/1,otp_5960/1,ensure_dir_eexist/1]). -import(lists, [foreach/2]). @@ -38,7 +38,8 @@ fin_per_testcase(_Case, Config) -> ok. all(suite) -> - [wildcard_one,wildcard_two,wildcard_errors,fold_files,otp_5960]. + [wildcard_one,wildcard_two,wildcard_errors,fold_files,otp_5960, + ensure_dir_eexist]. wildcard_one(Config) when is_list(Config) -> ?line {ok,OldCwd} = file:get_cwd(), @@ -223,7 +224,9 @@ otp_5960(Config) when is_list(Config) -> ?line Name1 = filename:join(Dir, name1), ?line Name2 = filename:join(Dir, name2), ?line ok = filelib:ensure_dir(Name1), % parent is created + ?line ok = filelib:ensure_dir(Name1), % repeating it should be OK ?line ok = filelib:ensure_dir(Name2), % parent already exists + ?line ok = filelib:ensure_dir(Name2), % repeating it should be OK ?line Name3 = filename:join(Name1, name3), ?line {ok, FileInfo} = file:read_file_info(Dir), case os:type() of @@ -239,3 +242,16 @@ otp_5960(Config) when is_list(Config) -> ?line ok = file:write_file_info(Dir, #file_info{mode=Mode}), ok end. + +ensure_dir_eexist(Config) when is_list(Config) -> + ?line PrivDir = ?config(priv_dir, Config), + ?line Dir = filename:join(PrivDir, ensure_dir_eexist), + ?line Name = filename:join(Dir, "same_name_as_file_and_dir"), + ?line ok = filelib:ensure_dir(Name), + ?line ok = file:write_file(Name, <<"some string\n">>), + + %% There already is a file with the name of the directory + %% we want to create. + ?line NeedFile = filename:join(Name, "file"), + ?line {error, eexist} = filelib:ensure_dir(NeedFile), + ok. diff --git a/lib/stdlib/test/fixtable_SUITE.erl b/lib/stdlib/test/fixtable_SUITE.erl index 9f21308ad4..1940ee147e 100644 --- a/lib/stdlib/test/fixtable_SUITE.erl +++ b/lib/stdlib/test/fixtable_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% %% %%%---------------------------------------------------------------------- @@ -83,7 +83,7 @@ fixbag(doc) -> "incorrect lookups"]; fixbag(suite) -> []; -fixbag(Config) when list(Config) -> +fixbag(Config) when is_list(Config) -> ?line T = ets:new(x,[bag]), ?line ets:insert(T,{a,1}), ?line ets:insert(T,{a,2}), @@ -101,7 +101,7 @@ insert_same_key(doc) -> ["Check correct behaviour if a key is deleted and reinserted during fixation."]; insert_same_key(suite) -> []; -insert_same_key(Config) when list(Config) -> +insert_same_key(Config) when is_list(Config) -> ?line {ok,Dets1} = dets:open_file(?DETS_TMP1, [{file, dets_filename(?DETS_TMP1,Config)}]), ?line Ets1 = ets:new(ets,[]), @@ -180,7 +180,7 @@ owner_dies(doc) -> ["Check correct behaviour if the table owner dies."]; owner_dies(suite) -> []; -owner_dies(Config) when list(Config) -> +owner_dies(Config) when is_list(Config) -> ?line P1 = start_commander(), ?line Ets1 = command(P1,{ets,new,[ets,[]]}), ?line command(P1,{ets,safe_fixtable,[Ets1,true]}), @@ -236,7 +236,7 @@ other_process_closes(doc) -> other_process_closes(suite) -> []; -other_process_closes(Config) when list(Config) -> +other_process_closes(Config) when is_list(Config) -> ?line {ok,Dets} = dets:open_file(?DETS_TMP1, [{file, dets_filename(tmp1,Config)}]), ?line P2 = start_commander(), @@ -265,7 +265,7 @@ other_process_deletes(doc) -> "deletes an ets table"]; other_process_deletes(suite) -> []; -other_process_deletes(Config) when list(Config) -> +other_process_deletes(Config) when is_list(Config) -> ?line Ets = ets:new(ets,[public]), ?line P = start_commander(), ?line ets:safe_fixtable(Ets,true), @@ -282,7 +282,7 @@ multiple_fixes(doc) -> ["Check that multiple safe_fixtable keeps the reference counter."]; multiple_fixes(suite) -> []; -multiple_fixes(Config) when list(Config) -> +multiple_fixes(Config) when is_list(Config) -> ?line {ok,Dets} = dets:open_file(?DETS_TMP1, [{file, dets_filename(?DETS_TMP1,Config)}]), ?line Ets = ets:new(ets,[]), @@ -317,7 +317,7 @@ multiple_processes(doc) -> "counted OK"]; multiple_processes(suite) -> []; -multiple_processes(Config) when list(Config) -> +multiple_processes(Config) when is_list(Config) -> ?line {ok,Dets} = dets:open_file(?DETS_TMP1,[{file, dets_filename(?DETS_TMP1, Config)}]), @@ -370,7 +370,7 @@ multiple_processes(Tab, Mod) -> %%% Helpers -dets_filename(Base, Config) when atom(Base) -> +dets_filename(Base, Config) when is_atom(Base) -> dets_filename(atom_to_list(Base) ++ ".dat", Config); dets_filename(Basename, Config) -> PrivDir = ?config(priv_dir,Config), diff --git a/lib/stdlib/test/format_SUITE.erl b/lib/stdlib/test/format_SUITE.erl index 2c415894f4..1c9e953003 100644 --- a/lib/stdlib/test/format_SUITE.erl +++ b/lib/stdlib/test/format_SUITE.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(format_SUITE). @@ -45,7 +45,7 @@ hang_1(doc) -> ["Bad args can hang (OTP-2400)"]; hang_1(suite) -> []; -hang_1(Config) when list(Config) -> +hang_1(Config) when is_list(Config) -> ?line _ = (catch io:format(a, "", [])), ?line _ = (catch io:format({}, "", [])), ok. diff --git a/lib/stdlib/test/gen_event_SUITE.erl b/lib/stdlib/test/gen_event_SUITE.erl index dc5ddebf53..8cbffaca56 100644 --- a/lib/stdlib/test/gen_event_SUITE.erl +++ b/lib/stdlib/test/gen_event_SUITE.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(gen_event_SUITE). @@ -33,7 +33,7 @@ all(suite) -> {req, [stdlib], [start, test_all, hibernate]}. start(doc) -> []; start(suite) -> []; -start(Config) when list(Config) -> +start(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), ?line {ok, Pid0} = gen_event:start(), %anonymous @@ -175,7 +175,7 @@ test_all(suite) -> [add_handler, add_sup_handler, delete_handler, add_handler(doc) -> []; add_handler(suite) -> []; -add_handler(Config) when list(Config) -> +add_handler(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line {error, my_error} = gen_event:add_handler(my_dummy_handler, dummy_h, make_error), @@ -196,7 +196,7 @@ add_handler(Config) when list(Config) -> add_sup_handler(doc) -> []; add_sup_handler(suite) -> []; -add_sup_handler(Config) when list(Config) -> +add_sup_handler(Config) when is_list(Config) -> ?line {ok,Pid} = gen_event:start({local, my_dummy_handler}), ?line {error, my_error} = gen_event:add_sup_handler(my_dummy_handler, dummy_h, make_error), @@ -238,7 +238,7 @@ add_sup_handler(Config) when list(Config) -> delete_handler(doc) -> []; delete_handler(suite) -> []; -delete_handler(Config) when list(Config) -> +delete_handler(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), ?line {error, module_not_found} = @@ -270,7 +270,7 @@ delete_handler(Config) when list(Config) -> swap_handler(doc) -> []; swap_handler(suite) -> []; -swap_handler(Config) when list(Config) -> +swap_handler(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), ?line {error, non_existing} = @@ -299,7 +299,7 @@ swap_handler(Config) when list(Config) -> swap_sup_handler(doc) -> []; swap_sup_handler(suite) -> []; -swap_sup_handler(Config) when list(Config) -> +swap_sup_handler(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), ?line {error, non_existing} = @@ -341,7 +341,7 @@ swap_sup_handler(Config) when list(Config) -> notify(doc) -> []; notify(suite) -> []; -notify(Config) when list(Config) -> +notify(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), Event = {event, self()}, @@ -457,7 +457,7 @@ notify(Config) when list(Config) -> sync_notify(doc) -> []; sync_notify(suite) -> []; -sync_notify(Config) when list(Config) -> +sync_notify(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), Event = {event, self()}, @@ -576,7 +576,7 @@ sync_notify(Config) when list(Config) -> call(doc) -> []; call(suite) -> []; -call(Config) when list(Config) -> +call(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h, 1}, [self()]), @@ -718,7 +718,7 @@ flush() -> info(doc) -> []; info(suite) -> []; -info(Config) when list(Config) -> +info(Config) when is_list(Config) -> ?line {ok,_} = gen_event:start({local, my_dummy_handler}), ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), Info = {info, self()}, diff --git a/lib/stdlib/test/gen_fsm_SUITE.erl b/lib/stdlib/test/gen_fsm_SUITE.erl index 62f8b2f9dd..23c1d9a193 100644 --- a/lib/stdlib/test/gen_fsm_SUITE.erl +++ b/lib/stdlib/test/gen_fsm_SUITE.erl @@ -30,7 +30,7 @@ -export([shutdown/1]). --export([sys/1, sys1/1]). +-export([sys/1, sys1/1, call_format_status/1]). -export([hibernate/1,hiber_idle/3,hiber_wakeup/3,hiber_idle/2,hiber_wakeup/2]). @@ -42,7 +42,7 @@ % The gen_fsm behaviour -export([init/1, handle_event/3, handle_sync_event/4, terminate/3, - handle_info/3]). + handle_info/3, format_status/2]). -export([idle/2, idle/3, timeout/2, wfor_conf/2, wfor_conf/3, @@ -305,7 +305,7 @@ shutdown(Config) when is_list(Config) -> ok. -sys(suite) -> [sys1]. +sys(suite) -> [sys1, call_format_status]. sys1(Config) when is_list(Config) -> ?line {ok, Pid} = @@ -317,6 +317,13 @@ sys1(Config) when is_list(Config) -> ?line sys:resume(Pid), ?line stop_it(Pid). +call_format_status(Config) when is_list(Config) -> + ?line {ok, Pid} = gen_fsm:start(gen_fsm_SUITE, [], []), + ?line Status = sys:get_status(Pid), + ?line {status, Pid, _Mod, [_PDict, running, _Parent, _, Data]} = Status, + ?line [format_status_called | _] = lists:reverse(Data), + ?line stop_it(Pid). + %% Hibernation hibernate(suite) -> []; @@ -836,3 +843,6 @@ handle_sync_event(stop_shutdown_reason, _From, _State, Data) -> {stop, {shutdown,reason}, {shutdown,reason}, Data}; handle_sync_event({get, _Pid}, _From, State, Data) -> {reply, {state, State, Data}, State, Data}. + +format_status(_Opt, [_Pdict, _StateData]) -> + [format_status_called]. diff --git a/lib/stdlib/test/gen_server_SUITE.erl b/lib/stdlib/test/gen_server_SUITE.erl index 86a5a65ba3..6efdce78a1 100644 --- a/lib/stdlib/test/gen_server_SUITE.erl +++ b/lib/stdlib/test/gen_server_SUITE.erl @@ -30,7 +30,7 @@ call_remote_n1/1, call_remote_n2/1, call_remote_n3/1, spec_init/1, spec_init_local_registered_parent/1, spec_init_global_registered_parent/1, - otp_5854/1, hibernate/1, otp_7669/1 + otp_5854/1, hibernate/1, otp_7669/1, call_format_status/1 ]). % spawn export @@ -42,7 +42,7 @@ % The gen_server behaviour -export([init/1, handle_call/3, handle_cast/2, - handle_info/2, terminate/2]). + handle_info/2, terminate/2, format_status/2]). all(suite) -> [start, crash, call, cast, cast_fast, info, @@ -51,7 +51,7 @@ all(suite) -> call_remote_n2, call_remote_n3, spec_init, spec_init_local_registered_parent, spec_init_global_registered_parent, - otp_5854,hibernate,otp_7669]. + otp_5854, hibernate, otp_7669, call_format_status]. -define(default_timeout, ?t:minutes(1)). @@ -851,7 +851,7 @@ otp_5854(Config) when is_list(Config) -> ok. %% If initialization fails (with ignore or {stop,Reason}), -%% make sure that the process is not registered when gen_sever:start() +%% make sure that the process is not registered when gen_server:start() %% returns. otp_7669(Config) when is_list(Config) -> @@ -887,6 +887,24 @@ do_otp_7669_stop() -> ?MODULE, stop, []), ?line undefined = global:whereis_name(?MODULE). +%% Verify that sys:get_status correctly calls our format_status/2 fun +%% +call_format_status(suite) -> + []; +call_format_status(doc) -> + ["Test that sys:get_status/1,2 calls format_status/2"]; +call_format_status(Config) when is_list(Config) -> + ?line {ok, Pid} = gen_server:start_link({local, call_format_status}, + gen_server_SUITE, [], []), + ?line Status1 = sys:get_status(call_format_status), + ?line {status, Pid, _Mod, [_PDict, running, _Parent, _, Data1]} = Status1, + ?line [format_status_called | _] = lists:reverse(Data1), + ?line Status2 = sys:get_status(call_format_status, 5000), + ?line {status, Pid, _Mod, [_PDict, running, _Parent, _, Data2]} = Status2, + ?line [format_status_called | _] = lists:reverse(Data2), + ok. + + %%-------------------------------------------------------------- %% Help functions to spec_init_* start_link(Init, Options) -> @@ -1046,4 +1064,5 @@ terminate({From, stopped_info}, _State) -> terminate(_Reason, _State) -> ok. - +format_status(_Opt, [_PDict, _State]) -> + [format_status_called]. diff --git a/lib/stdlib/test/io_proto_SUITE.erl b/lib/stdlib/test/io_proto_SUITE.erl index 46407193d7..93159fbd5b 100644 --- a/lib/stdlib/test/io_proto_SUITE.erl +++ b/lib/stdlib/test/io_proto_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(io_proto_SUITE). @@ -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,14 +45,17 @@ -define(privdir(Conf), ?config(priv_dir, Conf)). -endif. -%-define(debug, true). +-define(debug, true). -ifdef(debug). -define(format(S, A), io:format(S, A)). -define(dbg(Data),io:format(standard_error, "DBG: ~p\r\n",[Data])). +-define(RM_RF(Dir),begin io:format(standard_error, "Not Removed: ~p\r\n",[Dir]), + ok end). -else. -define(format(S, A), ok). -define(dbg(Data),noop). +-define(RM_RF(Dir),rm_rf(Dir)). -endif. @@ -79,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, { @@ -88,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) -> @@ -197,6 +244,15 @@ setopts_getopts(Config) when is_list(Config) -> {getline_re, ".*<<\"hej\\\\n\">>"} ],[],[],"-oldshell"), ok. + + +get_lc_ctype() -> + case {os:type(),os:version()} of + {{unix,sunos},{5,N,_}} when N =< 8 -> + "iso_8859_1"; + _ -> + "ISO-8859-1" + end. unicode_options(suite) -> []; @@ -369,7 +425,7 @@ unicode_options(Config) when is_list(Config) -> {getline, binary_to_list(unicode:characters_to_binary( [1024],unicode,utf8))} - ],[],"LC_CTYPE=\"ISO-8859-1\"; export LC_CTYPE; "), + ],[],"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; "), ?line rtnode([{putline,""}, {putline, "2."}, {getline_re, ".*2."}, @@ -384,7 +440,7 @@ unicode_options(Config) when is_list(Config) -> {getline_re, ".*"++binary_to_list(unicode:characters_to_binary( [1024],unicode,utf8))} - ],[],"LC_CTYPE=\"ISO-8859-1\"; export LC_CTYPE; ", + ],[],"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; ", " -oldshell "), ok. @@ -974,7 +1030,7 @@ answering_machine1(OthNode,OthReg,Me) -> {putline, TestDataUtf}, {getline_re, ".*Okej"} - ],Me,"LC_CTYPE=\"ISO-8859-1\"; export LC_CTYPE; "), + ],Me,"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; "), O = list_to_atom(OthReg), O ! {self(),done}, ok. @@ -1045,7 +1101,7 @@ answering_machine2(OthNode,OthReg,Me) -> {putline, TestDataUtf}, {getline_re, ".*Okej"} - ],Me,"LC_CTYPE=\"ISO-8859-1\"; export LC_CTYPE; "," -oldshell "), + ],Me,"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; "," -oldshell "), O = list_to_atom(OthReg), O ! {self(),done}, ok. @@ -1087,7 +1143,9 @@ read_modes_gl_1(_Config,Machine) -> [MyNodeList, "io_proto_suite", N2List]), ?line GL = receive X when is_pid(X) -> X end, + ?dbg({group_leader,X}), %% get_line + ?line receive after 500 -> ok end, % Dont clash with the new shell... ?line "Hej\n" = io:get_line(GL,"Prompt\n"), ?line io:setopts(GL,[binary]), ?line io:format(GL,"Okej~n",[]), @@ -1287,7 +1345,7 @@ rtnode(Commands,Nodename,ErlPrefix,Extra) -> ?line ok end, ?line wait_for_runerl_server(SPid), - ?line ok = rm_rf(Tempdir), + ?line ok = ?RM_RF(Tempdir), ?line ok = Res end end. @@ -1308,7 +1366,7 @@ timeout(normal) -> %% stop_noshell_node(Node) -> %% test_server:stop_node(Node). - +-ifndef(debug). rm_rf(Dir) -> try {ok,List} = file:list_dir(Dir), @@ -1324,7 +1382,7 @@ rm_rf(Dir) -> catch _:Exception -> {error, {Exception,Dir}} end. - +-endif. get_and_put(_CPid,[],_) -> ok; @@ -1527,6 +1585,8 @@ start_runerl_node(RunErl,Erl,Tempdir,Nodename,Extra) -> " "++Extra end, spawn(fun() -> + ?dbg(RunErl++" "++Tempdir++"/ "++Tempdir++" \""++ + Erl++XArg++XXArg++"\""), os:cmd(RunErl++" "++Tempdir++"/ "++Tempdir++" \""++ Erl++XArg++XXArg++"\"") end). diff --git a/lib/stdlib/test/ms_transform_SUITE.erl b/lib/stdlib/test/ms_transform_SUITE.erl index cf0926b7fa..79a0a9af89 100644 --- a/lib/stdlib/test/ms_transform_SUITE.erl +++ b/lib/stdlib/test/ms_transform_SUITE.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% %% -module(ms_transform_SUITE). @@ -56,7 +56,7 @@ andalso_orelse(suite) -> []; andalso_orelse(doc) -> ["Tests that andalso and orelse are allowed in guards."]; -andalso_orelse(Config) when list(Config) -> +andalso_orelse(Config) when is_list(Config) -> ?line setup(Config), ?line [{{'$1','$2'}, [{'and',{is_integer,'$1'},{'>',{'+','$1',5},'$2'}}], @@ -93,7 +93,7 @@ bitsyntax(suite) -> []; bitsyntax(doc) -> ["Tests that bitsyntax works and does not work where appropriate"]; -bitsyntax(Config) when list(Config) -> +bitsyntax(Config) when is_list(Config) -> ?line setup(Config), ?line [{'_',[], [<<0,27,0,27>>]}] = @@ -131,7 +131,7 @@ record_defaults(suite) -> []; record_defaults(doc) -> ["Tests that record defaults works"]; -record_defaults(Config) when list(Config) -> +record_defaults(Config) when is_list(Config) -> ?line setup(Config), ?line [{{<<27>>,{a,5,'$1',hej,hej}}, [], @@ -146,7 +146,7 @@ basic_ets(suite) -> []; basic_ets(doc) -> ["Tests basic ets:fun2ms"]; -basic_ets(Config) when list(Config) -> +basic_ets(Config) when is_list(Config) -> ?line setup(Config), ?line [{{a,b},[],[true]}] = compile_and_run( <<"ets:fun2ms(fun({a,b}) -> true end)">>), @@ -167,7 +167,7 @@ basic_dbg(suite) -> []; basic_dbg(doc) -> ["Tests basic ets:fun2ms"]; -basic_dbg(Config) when list(Config) -> +basic_dbg(Config) when is_list(Config) -> ?line setup(Config), ?line [{[a,b],[],[{message,banan},{return_trace}]}] = compile_and_run(<<"dbg:fun2ms(fun([a,b]) -> message(banan), ", @@ -186,7 +186,7 @@ from_shell(suite) -> []; from_shell(doc) -> ["Test calling of ets/dbg:fun2ms from the shell"]; -from_shell(Config) when list(Config) -> +from_shell(Config) when is_list(Config) -> ?line setup(Config), ?line Fun = do_eval("fun({a,b}) -> true end"), ?line [{{a,b},[],[true]}] = apply(ets,fun2ms,[Fun]), @@ -203,7 +203,7 @@ records(suite) -> []; records(doc) -> ["Tests expansion of records in fun2ms"]; -records(Config) when list(Config) -> +records(Config) when is_list(Config) -> ?line setup(Config), ?line RD = <<"-record(t, {" "t1 = []," @@ -253,7 +253,7 @@ record_index(suite) -> []; record_index(doc) -> ["Tests expansion of records in fun2ms, part 2"]; -record_index(Config) when list(Config) -> +record_index(Config) when is_list(Config) -> ?line setup(Config), ?line RD = <<"-record(a,{a,b}).">>, ?line [{{2},[],[true]}] = compile_and_run(RD, @@ -268,7 +268,7 @@ top_match(suite) -> []; top_match(doc) -> ["Tests matching on top level in head to give alias for object()"]; -top_match(Config) when list(Config) -> +top_match(Config) when is_list(Config) -> ?line setup(Config), ?line RD = <<"-record(a,{a,b}).">>, ?line [{{a,3,'_'},[],['$_']}] = @@ -295,7 +295,7 @@ multipass(suite) -> []; multipass(doc) -> ["Tests that multi-defined fields in records give errors."]; -multipass(Config) when list(Config) -> +multipass(Config) when is_list(Config) -> ?line setup(Config), ?line RD = <<"-record(a,{a,b}).">>, ?line expect_failure(RD,<<"ets:fun2ms(fun(A) -> #a{a=2,a=3} end)">>), @@ -319,7 +319,7 @@ old_guards(suite) -> []; old_guards(doc) -> ["Tests that old type tests in guards are translated"]; -old_guards(Config) when list(Config) -> +old_guards(Config) when is_list(Config) -> ?line setup(Config), Tests = [ {atom,is_atom}, @@ -382,7 +382,7 @@ autoimported(suite) -> autoimported(doc) -> ["Tests use of autoimported bif's used like erlang:'+'(A,B) in guards" " and body."]; -autoimported(Config) when list(Config) -> +autoimported(Config) when is_list(Config) -> ?line setup(Config), Allowed = [ {abs,1}, @@ -582,7 +582,7 @@ float_1_function(suite) -> []; float_1_function(doc) -> ["OTP-5297. The function float/1."]; -float_1_function(Config) when list(Config) -> +float_1_function(Config) when is_list(Config) -> ?line setup(Config), RunMS = fun(L, MS) -> ets:match_spec_run(L, ets:match_spec_compile(MS)) diff --git a/lib/stdlib/test/queue_SUITE.erl b/lib/stdlib/test/queue_SUITE.erl index ec3080baa0..2cd6b52311 100644 --- a/lib/stdlib/test/queue_SUITE.erl +++ b/lib/stdlib/test/queue_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(queue_SUITE). @@ -45,7 +45,7 @@ do(doc) -> [""]; do(suite) -> []; -do(Config) when list(Config) -> +do(Config) when is_list(Config) -> ?line L = [{in, 1}, {in, 2}, {out, {value, 1}}, @@ -66,7 +66,7 @@ to_list(doc) -> ["OTP-2701"]; to_list(suite) -> []; -to_list(Config) when list(Config) -> +to_list(Config) when is_list(Config) -> ?line E = queue:new(), ?line Q = do_queue(E, [{in, 1}, {in, 2}, @@ -104,7 +104,7 @@ io_test(doc) -> "Test input and output"; io_test(suite) -> []; -io_test(Config) when list(Config) -> +io_test(Config) when is_list(Config) -> E = queue:new(), do_io_test(E), ok. @@ -284,7 +284,7 @@ op_test(doc) -> "Test operations on whole queues"; op_test(suite) -> []; -op_test(Config) when list(Config) -> +op_test(Config) when is_list(Config) -> do_op_test(fun id/1), ok. @@ -382,7 +382,7 @@ error(doc) -> "Test queue errors"; error(suite) -> []; -error(Config) when list(Config) -> +error(Config) when is_list(Config) -> do_error(fun id/1, illegal_queue), do_error(fun id/1, {[],illegal_queue}), do_error(fun id/1, {illegal_queue,[17]}), @@ -449,7 +449,7 @@ oops(doc) -> "Test queue errors"; oops(suite) -> []; -oops(Config) when list(Config) -> +oops(Config) when is_list(Config) -> ?line N = 3142, ?line Optab = optab(), ?line Seed0 = random:seed0(), diff --git a/lib/stdlib/test/re_SUITE.erl b/lib/stdlib/test/re_SUITE.erl index 98eb66d1fb..02683f9f1a 100644 --- a/lib/stdlib/test/re_SUITE.erl +++ b/lib/stdlib/test/re_SUITE.erl @@ -1,29 +1,29 @@ %% %% %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% %% -module(re_SUITE). --export([all/1, pcre/1,compile_options/1,run_options/1,combined_options/1,replace_autogen/1,global_capture/1,replace_return/1,split_autogen/1,split_options/1,split_specials/1,error_handling/1]). +-export([all/1, pcre/1,compile_options/1,run_options/1,combined_options/1,replace_autogen/1,global_capture/1,replace_input_types/1,replace_return/1,split_autogen/1,split_options/1,split_specials/1,error_handling/1,pcre_cve_2008_2371/1]). -include("test_server.hrl"). -include_lib("kernel/include/file.hrl"). -all(suite) -> [pcre,compile_options,run_options,combined_options,replace_autogen,global_capture,replace_return,split_autogen,split_options,split_specials,error_handling]. +all(suite) -> [pcre,compile_options,run_options,combined_options,replace_autogen,global_capture,replace_input_types,replace_return,split_autogen,split_options,split_specials,error_handling,pcre_cve_2008_2371]. pcre(doc) -> ["Run all applicable tests from the PCRE testsuites."]; @@ -268,7 +268,17 @@ global_capture(Config) when is_list(Config) -> ?line {match,[[{3,5},{5,3}],[{11,4},{12,3}]]} = re:run("ABC�bcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,index},unicode]), ?t:timetrap_cancel(Dog), ok. - + +replace_input_types(doc) -> + ["Tests replace with different input types"]; +replace_input_types(Config) when is_list(Config) -> + Dog = ?t:timetrap(?t:minutes(3)), + ?line <<"abcd">> = re:replace("abcd","Z","X",[{return,binary},unicode]), + ?line <<"abcd">> = re:replace("abcd","\x{400}","X",[{return,binary},unicode]), + ?line <<"a",208,128,"cd">> = re:replace(<<"abcd">>,"b","\x{400}",[{return,binary},unicode]), + ?t:timetrap_cancel(Dog), + ok. + replace_return(doc) -> ["Tests return options of replace together with global searching"]; replace_return(Config) when is_list(Config) -> @@ -289,6 +299,10 @@ replace_return(Config) when is_list(Config) -> ?line <<"iXk">> = re:replace("abcdefghijk","(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)","\\9X",[{return,binary}]), ?line <<"jXk">> = re:replace("abcdefghijk","(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)","\\10X",[{return,binary}]), ?line <<"Xk">> = re:replace("abcdefghijk","(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)","\\11X",[{return,binary}]), + ?line "a\x{400}bcX" = re:replace("a\x{400}bcd","d","X",[global,{return,list},unicode]), + ?line <<"a",208,128,"bcX">> = re:replace("a\x{400}bcd","d","X",[global,{return,binary},unicode]), + ?line "a\x{400}bcd" = re:replace("a\x{400}bcd","Z","X",[global,{return,list},unicode]), + ?line <<"a",208,128,"bcd">> = re:replace("a\x{400}bcd","Z","X",[global,{return,binary},unicode]), ?t:timetrap_cancel(Dog), ok. @@ -524,3 +538,9 @@ error_handling(Config) when is_list(Config) -> ?t:timetrap_cancel(Dog), ok. +pcre_cve_2008_2371(doc) -> + "Fix as in http://vcs.pcre.org/viewvc?revision=360&view=revision"; +pcre_cve_2008_2371(Config) when is_list(Config) -> + %% Make sure it doesn't crash the emulator. + re:compile(<<"(?i)[\xc3\xa9\xc3\xbd]|[\xc3\xa9\xc3\xbdA]">>, [unicode]), + ok. diff --git a/lib/stdlib/test/re_SUITE_data/mod_testoutput8 b/lib/stdlib/test/re_SUITE_data/mod_testoutput8 new file mode 100644 index 0000000000..b7e7b02d6c --- /dev/null +++ b/lib/stdlib/test/re_SUITE_data/mod_testoutput8 @@ -0,0 +1,877 @@ +/-- Do not use the \x{} construct except with patterns that have the --/ +/-- /8 option set, because PCRE doesn't recognize them as UTF-8 unless --/ +No match +/-- that option is set. However, the latest Perls recognize them always. --/ +No match + +\x{100}ab/8 + \x{100}ab + 0: \x{100}ab + +/a\x{100}*b/8 + ab + 0: ab + a\x{100}b + 0: a\x{100}b + a\x{100}\x{100}b + 0: a\x{100}\x{100}b + +/a\x{100}+b/8 + a\x{100}b + 0: a\x{100}b + a\x{100}\x{100}b + 0: a\x{100}\x{100}b + *** Failers +No match + ab +No match + +/\bX/8 + Xoanon + 0: X + +Xoanon + 0: X + \x{300}Xoanon + 0: X + *** Failers +No match + YXoanon +No match + +/\BX/8 + YXoanon + 0: X + *** Failers +No match + Xoanon +No match + +Xoanon +No match + \x{300}Xoanon +No match + +/X\b/8 + X+oanon + 0: X + ZX\x{300}oanon + 0: X + FAX + 0: X + *** Failers +No match + Xoanon +No match + +/X\B/8 + Xoanon + 0: X + *** Failers +No match + X+oanon +No match + ZX\x{300}oanon +No match + FAX +No match + +/[^a]/8 + abcd + 0: b + a\x{100} + 0: \x{100} + +/^[abc\x{123}\x{400}-\x{402}]{2,3}\d/8 + ab99 + 0: ab9 + \x{123}\x{123}45 + 0: \x{123}\x{123}4 + \x{400}\x{401}\x{402}6 + 0: \x{400}\x{401}\x{402}6 + *** Failers +No match + d99 +No match + \x{123}\x{122}4 +No match + \x{400}\x{403}6 +No match + \x{400}\x{401}\x{402}\x{402}6 +No match + +/abc/8 + �] +Error -10 + � +Error -10 + ��� +Error -10 + ���\? +No match + +/a.b/8 + acb + 0: acb + a\x7fb + 0: a\x{7f}b + a\x{100}b + 0: a\x{100}b + *** Failers +No match + a\nb +No match + +/^[a\x{c0}]/8 + *** Failers +No match + \x{100} +No match + +/(?<=aXb)cd/8 + aXbcd + 0: cd + +/(?<=a\x{100}b)cd/8 + a\x{100}bcd + 0: cd + +/(?<=a\x{100000}b)cd/8 + a\x{100000}bcd + 0: cd + +/(?:\x{100}){3}b/8 + \x{100}\x{100}\x{100}b + 0: \x{100}\x{100}\x{100}b + *** Failers +No match + \x{100}\x{100}b +No match + +/\x{ab}/8 + \x{ab} + 0: \x{ab} + \xc2\xab + 0: \x{ab} + *** Failers +No match + \x00{ab} +No match + +/^[^a]{2}/8 + \x{100}bc + 0: \x{100}b + +/^[^a]{2,}/8 + \x{100}bcAa + 0: \x{100}bcA + +/^[^a]{2,}?/8 + \x{100}bca + 0: \x{100}b + +/^[^a]{2}/8i + \x{100}bc + 0: \x{100}b + +/^[^a]{2,}/8i + \x{100}bcAa + 0: \x{100}bc + +/^[^a]{2,}?/8iU + \x{100}bca + 0: \x{100}bc + +/\x{100}{0,0}/8 + abcd + 0: + +/\x{100}?/8 + abcd + 0: + \x{100}\x{100} + 0: \x{100} + +/\x{100}{0,3}/8 + \x{100}\x{100} + 0: \x{100}\x{100} + \x{100}\x{100}\x{100}\x{100} + 0: \x{100}\x{100}\x{100} + +/\x{100}*/8 + abce + 0: + \x{100}\x{100}\x{100}\x{100} + 0: \x{100}\x{100}\x{100}\x{100} + +/\x{100}{1,1}/8 + abcd\x{100}\x{100}\x{100}\x{100} + 0: \x{100} + +/\x{100}{1,3}/8 + abcd\x{100}\x{100}\x{100}\x{100} + 0: \x{100}\x{100}\x{100} + +/\x{100}+/8 + abcd\x{100}\x{100}\x{100}\x{100} + 0: \x{100}\x{100}\x{100}\x{100} + +/\x{100}{3}/8 + abcd\x{100}\x{100}\x{100}XX + 0: \x{100}\x{100}\x{100} + +/\x{100}{3,5}/8 + abcd\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}XX + 0: \x{100}\x{100}\x{100}\x{100}\x{100} + +/\x{100}{3,}/8 + abcd\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}XX + 0: \x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100} + +/(?<=a\x{100}{2}b)X/8 + Xyyya\x{100}\x{100}bXzzz + 0: X + +/\D*/8 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + +/\D*/8 + \x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100} + 0: \x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100}\x{100} + +/\D/8 + 1X2 + 0: X + 1\x{100}2 + 0: \x{100} + +/>\S/8 + > >X Y + 0: >X + > >\x{100} Y + 0: >\x{100} + +/\d/8 + \x{100}3 + 0: 3 + +/\s/8 + \x{100} X + 0: + +/\D+/8 + 12abcd34 + 0: abcd + *** Failers + 0: *** Failers + 1234 +No match + +/\d+/8 + 12abcd34 + 0: 12 + *** Failers +No match + +/\d{2,3}/8 + 12abcd34 + 0: 12 + 1234abcd + 0: 123 + *** Failers +No match + 1.4 +No match + +/\S+/8 + 12abcd34 + 0: 12abcd34 + *** Failers + 0: *** + \ \ +No match + +/>\s+</8 + 12> <34 + 0: > < + *** Failers +No match + +/>\s{2,3}</8 + ab> <cd + 0: > < + ab> <ce + 0: > < + *** Failers +No match + ab> <cd +No match + +/>\s{2,3}?</8 + ab> <cd + 0: > < + ab> <ce + 0: > < + *** Failers +No match + ab> <cd +No match + +/\w+/8 + 12 34 + 0: 12 + *** Failers + 0: Failers + +++=*! +No match + +/\w{2,3}/8 + ab cd + 0: ab + abcd ce + 0: abc + *** Failers + 0: Fai + a.b.c +No match + +/\W+/8 + 12====34 + 0: ==== + *** Failers + 0: *** + abcd +No match + +/\W{2,3}/8 + ab====cd + 0: === + ab==cd + 0: == + *** Failers + 0: *** + a.b.c +No match + +/\W{2,3}?/8U + ab====cd + 0: === + ab==cd + 0: == + *** Failers + 0: *** + a.b.c +No match + +/[\x{100}]/8 + \x{100} + 0: \x{100} + Z\x{100} + 0: \x{100} + \x{100}Z + 0: \x{100} + *** Failers +No match + +/[Z\x{100}]/8 + Z\x{100} + 0: Z + \x{100} + 0: \x{100} + \x{100}Z + 0: \x{100} + *** Failers +No match + +/[\x{100}\x{200}]/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + *** Failers +No match + +/[\x{100}-\x{200}]/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{111}cd + 0: \x{111} + *** Failers +No match + +/[z-\x{200}]/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{111}cd + 0: \x{111} + abzcd + 0: z + ab|cd + 0: | + *** Failers +No match + +/[Q\x{100}\x{200}]/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + Q? + 0: Q + *** Failers +No match + +/[Q\x{100}-\x{200}]/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{111}cd + 0: \x{111} + Q? + 0: Q + *** Failers +No match + +/[Qz-\x{200}]/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{111}cd + 0: \x{111} + abzcd + 0: z + ab|cd + 0: | + Q? + 0: Q + *** Failers +No match + +/[\x{100}\x{200}]{1,3}/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{200}\x{100}\x{200}\x{100}cd + 0: \x{200}\x{100}\x{200} + *** Failers +No match + +/[\x{100}\x{200}]{1,3}?/8U + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{200}\x{100}\x{200}\x{100}cd + 0: \x{200}\x{100}\x{200} + *** Failers +No match + +/[Q\x{100}\x{200}]{1,3}/8 + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{200}\x{100}\x{200}\x{100}cd + 0: \x{200}\x{100}\x{200} + *** Failers +No match + +/[Q\x{100}\x{200}]{1,3}?/8U + ab\x{100}cd + 0: \x{100} + ab\x{200}cd + 0: \x{200} + ab\x{200}\x{100}\x{200}\x{100}cd + 0: \x{200}\x{100}\x{200} + *** Failers +No match + +/(?<=[\x{100}\x{200}])X/8 + abc\x{200}X + 0: X + abc\x{100}X + 0: X + *** Failers +No match + X +No match + +/(?<=[Q\x{100}\x{200}])X/8 + abc\x{200}X + 0: X + abc\x{100}X + 0: X + abQX + 0: X + *** Failers +No match + X +No match + +/(?<=[\x{100}\x{200}]{3})X/8 + abc\x{100}\x{200}\x{100}X + 0: X + *** Failers +No match + abc\x{200}X +No match + X +No match + +/[^\x{100}\x{200}]X/8 + AX + 0: AX + \x{150}X + 0: \x{150}X + \x{500}X + 0: \x{500}X + *** Failers +No match + \x{100}X +No match + \x{200}X +No match + +/[^Q\x{100}\x{200}]X/8 + AX + 0: AX + \x{150}X + 0: \x{150}X + \x{500}X + 0: \x{500}X + *** Failers +No match + \x{100}X +No match + \x{200}X +No match + QX +No match + +/[^\x{100}-\x{200}]X/8 + AX + 0: AX + \x{500}X + 0: \x{500}X + *** Failers +No match + \x{100}X +No match + \x{150}X +No match + \x{200}X +No match + +/[z-\x{100}]/8i + z + 0: z + Z + 0: Z + \x{100} + 0: \x{100} + *** Failers +No match + \x{102} +No match + y +No match + +/[\xFF]/ + >\xff< + 0: \xff + +/[\xff]/8 + >\x{ff}< + 0: \x{ff} + +/[^\xFF]/ + XYZ + 0: X + +/[^\xff]/8 + XYZ + 0: X + \x{123} + 0: \x{123} + +/^[ac]*b/8 + xb +No match + +/^[ac\x{100}]*b/8 + xb +No match + +/^[^x]*b/8i + xb +No match + +/^[^x]*b/8 + xb +No match + +/^\d*b/8 + xb +No match + +/^\x{85}$/8i + \x{85} + 0: \x{85} + +/^abc./mgx8<any> + abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x{0085}abc7 \x{2028}abc8 \x{2029}abc9 JUNK + 0: abc1 + 0: abc2 + 0: abc3 + 0: abc4 + 0: abc5 + 0: abc6 + 0: abc7 + 0: abc8 + 0: abc9 + +/abc.$/mgx8<any> + abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x{0085} abc7\x{2028} abc8\x{2029} abc9 + 0: abc1 + 0: abc2 + 0: abc3 + 0: abc4 + 0: abc5 + 0: abc6 + 0: abc7 + 0: abc8 + 0: abc9 + +/^a\Rb/8<bsr_unicode> + a\nb + 0: a\x{0a}b + a\rb + 0: a\x{0d}b + a\r\nb + 0: a\x{0d}\x{0a}b + a\x0bb + 0: a\x{0b}b + a\x0cb + 0: a\x{0c}b + a\x{85}b + 0: a\x{85}b + a\x{2028}b + 0: a\x{2028}b + a\x{2029}b + 0: a\x{2029}b + ** Failers +No match + a\n\rb +No match + +/^a\R*b/8<bsr_unicode> + ab + 0: ab + a\nb + 0: a\x{0a}b + a\rb + 0: a\x{0d}b + a\r\nb + 0: a\x{0d}\x{0a}b + a\x0bb + 0: a\x{0b}b + a\x0c\x{2028}\x{2029}b + 0: a\x{0c}\x{2028}\x{2029}b + a\x{85}b + 0: a\x{85}b + a\n\rb + 0: a\x{0a}\x{0d}b + a\n\r\x{85}\x0cb + 0: a\x{0a}\x{0d}\x{85}\x{0c}b + +/^a\R+b/8<bsr_unicode> + a\nb + 0: a\x{0a}b + a\rb + 0: a\x{0d}b + a\r\nb + 0: a\x{0d}\x{0a}b + a\x0bb + 0: a\x{0b}b + a\x0c\x{2028}\x{2029}b + 0: a\x{0c}\x{2028}\x{2029}b + a\x{85}b + 0: a\x{85}b + a\n\rb + 0: a\x{0a}\x{0d}b + a\n\r\x{85}\x0cb + 0: a\x{0a}\x{0d}\x{85}\x{0c}b + ** Failers +No match + ab +No match + +/^a\R{1,3}b/8<bsr_unicode> + a\nb + 0: a\x{0a}b + a\n\rb + 0: a\x{0a}\x{0d}b + a\n\r\x{85}b + 0: a\x{0a}\x{0d}\x{85}b + a\r\n\r\nb + 0: a\x{0d}\x{0a}\x{0d}\x{0a}b + a\r\n\r\n\r\nb + 0: a\x{0d}\x{0a}\x{0d}\x{0a}\x{0d}\x{0a}b + a\n\r\n\rb + 0: a\x{0a}\x{0d}\x{0a}\x{0d}b + a\n\n\r\nb + 0: a\x{0a}\x{0a}\x{0d}\x{0a}b + ** Failers +No match + a\n\n\n\rb +No match + a\r +No match + +/\h+\V?\v{3,4}/8 + \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a + 0: \x{09} \x{a0}X\x{0a}\x{0b}\x{0c}\x{0d} + +/\V?\v{3,4}/8 + \x20\x{a0}X\x0a\x0b\x0c\x0d\x0a + 0: X\x{0a}\x{0b}\x{0c}\x{0d} + +/\h+\V?\v{3,4}/8 + >\x09\x20\x{a0}X\x0a\x0a\x0a< + 0: \x{09} \x{a0}X\x{0a}\x{0a}\x{0a} + +/\V?\v{3,4}/8 + >\x09\x20\x{a0}X\x0a\x0a\x0a< + 0: X\x{0a}\x{0a}\x{0a} + +/\H\h\V\v/8 + X X\x0a + 0: X X\x{0a} + X\x09X\x0b + 0: X\x{09}X\x{0b} + ** Failers +No match + \x{a0} X\x0a +No match + +/\H*\h+\V?\v{3,4}/8 + \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a + 0: \x{09} \x{a0}X\x{0a}\x{0b}\x{0c}\x{0d} + \x09\x20\x{a0}\x0a\x0b\x0c\x0d\x0a + 0: \x{09} \x{a0}\x{0a}\x{0b}\x{0c}\x{0d} + \x09\x20\x{a0}\x0a\x0b\x0c + 0: \x{09} \x{a0}\x{0a}\x{0b}\x{0c} + ** Failers +No match + \x09\x20\x{a0}\x0a\x0b +No match + +/\H\h\V\v/8 + \x{3001}\x{3000}\x{2030}\x{2028} + 0: \x{3001}\x{3000}\x{2030}\x{2028} + X\x{180e}X\x{85} + 0: X\x{180e}X\x{85} + ** Failers +No match + \x{2009} X\x0a +No match + +/\H*\h+\V?\v{3,4}/8 + \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x0c\x0d\x0a + 0: \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x{0c}\x{0d} + \x09\x{205f}\x{a0}\x0a\x{2029}\x0c\x{2028}\x0a + 0: \x{09}\x{205f}\x{a0}\x{0a}\x{2029}\x{0c}\x{2028} + \x09\x20\x{202f}\x0a\x0b\x0c + 0: \x{09} \x{202f}\x{0a}\x{0b}\x{0c} + ** Failers +No match + \x09\x{200a}\x{a0}\x{2028}\x0b +No match + +/a\Rb/I8<bsr_anycrlf> +Capturing subpattern count = 0 +Options: bsr_anycrlf utf8 +First char = 'a' +Need char = 'b' + a\rb + 0: a\x{0d}b + a\nb + 0: a\x{0a}b + a\r\nb + 0: a\x{0d}\x{0a}b + ** Failers +No match + a\x{85}b +No match + a\x0bb +No match + +/a\Rb/I8<bsr_unicode> +Capturing subpattern count = 0 +Options: bsr_unicode utf8 +First char = 'a' +Need char = 'b' + a\rb + 0: a\x{0d}b + a\nb + 0: a\x{0a}b + a\r\nb + 0: a\x{0d}\x{0a}b + a\x{85}b + 0: a\x{85}b + a\x0bb + 0: a\x{0b}b + ** Failers +No match + a\x{85}b\<bsr_anycrlf> +No match + a\x0bb\<bsr_anycrlf> +No match + +/a\R?b/I8<bsr_anycrlf> +Capturing subpattern count = 0 +Options: bsr_anycrlf utf8 +First char = 'a' +Need char = 'b' + a\rb + 0: a\x{0d}b + a\nb + 0: a\x{0a}b + a\r\nb + 0: a\x{0d}\x{0a}b + ** Failers +No match + a\x{85}b +No match + a\x0bb +No match + +/a\R?b/I8<bsr_unicode> +Capturing subpattern count = 0 +Options: bsr_unicode utf8 +First char = 'a' +Need char = 'b' + a\rb + 0: a\x{0d}b + a\nb + 0: a\x{0a}b + a\r\nb + 0: a\x{0d}\x{0a}b + a\x{85}b + 0: a\x{85}b + a\x0bb + 0: a\x{0b}b + ** Failers +No match + a\x{85}b\<bsr_anycrlf> +No match + a\x0bb\<bsr_anycrlf> +No match + +/ End of testinput 8 / diff --git a/lib/stdlib/test/re_testoutput1_replacement_test.erl b/lib/stdlib/test/re_testoutput1_replacement_test.erl index b20db3f9c3..69cb140e0d 100644 --- a/lib/stdlib/test/re_testoutput1_replacement_test.erl +++ b/lib/stdlib/test/re_testoutput1_replacement_test.erl @@ -1,23 +1,24 @@ %% %% %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% %% -module(re_testoutput1_replacement_test). -compile(export_all). +-compile(no_native). -include("test_server.hrl"). %% This file is generated by running run_pcre_tests:gen_repl_test("re_SUITE_data/testoutput1") run() -> diff --git a/lib/stdlib/test/re_testoutput1_split_test.erl b/lib/stdlib/test/re_testoutput1_split_test.erl index 7e2d3f79ec..e86a04b008 100644 --- a/lib/stdlib/test/re_testoutput1_split_test.erl +++ b/lib/stdlib/test/re_testoutput1_split_test.erl @@ -1,23 +1,24 @@ %% %% %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% %% -module(re_testoutput1_split_test). -compile(export_all). +-compile(no_native). -include("test_server.hrl"). %% This file is generated by running run_pcre_tests:gen_split_test("re_SUITE_data/testoutput1") join([]) -> []; diff --git a/lib/stdlib/test/run_pcre_tests.erl b/lib/stdlib/test/run_pcre_tests.erl index 0ef3986918..78b4803fc8 100644 --- a/lib/stdlib/test/run_pcre_tests.erl +++ b/lib/stdlib/test/run_pcre_tests.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% %% -module(run_pcre_tests). @@ -25,7 +25,7 @@ test(RootDir) -> erts_debug:set_internal_state(available_internal_state,true), io:format("oldlimit: ~p~n",[ erts_debug:set_internal_state(re_loop_limit,10)]), Testfiles0 = ["testoutput1", "testoutput2", "testoutput3", "testoutput4", - "testoutput5", "testoutput6", "testoutput10"], + "testoutput5", "testoutput6","mod_testoutput8","testoutput10"], Testfiles = [ filename:join([RootDir,FN]) || FN <- Testfiles0 ], Res = [ begin io:format("~s~n",[X]), t(X) end || X <- Testfiles ], io:format("limit was: ~p~n",[ erts_debug:set_internal_state(re_loop_limit,default)]), @@ -42,12 +42,14 @@ t(OneFile,Num) -> put(error_limit,Num), put(skipped,0), Res = - [test(Structured,true,index), - test(Structured,false,index), - test(Structured,true,binary), - test(Structured,false,binary), - test(Structured,true,list), - test(Structured,false,list)], + [test(Structured,true,index,false), + test(Structured,false,index,false), + test(Structured,true,index,true), + test(Structured,false,index,true), + test(Structured,true,binary,false), + test(Structured,false,binary,false), + test(Structured,true,list,false), + test(Structured,false,list,false)], {lists:sum(Res),length(Structured)*6,get(skipped)}. @@ -63,11 +65,21 @@ pick_exec_options([Opt|T]) -> pick_exec_options([]) -> {[],[]}. -test([],_,_) -> +test([],_,_,_) -> 0; -test([{RE,Line,Options0,Tests}|T],PreCompile,XMode) -> +test([{RE0,Line,Options0,Tests}|T],PreCompile,XMode,REAsList) -> %io:format("."), %case RE of <<>> -> io:format("Empty re:~w~n",[Line]); _ -> ok end, + Unicode = lists:member(unicode,Options0), + RE = case REAsList of + true -> + if + Unicode -> unicode:characters_to_list(RE0); + true -> binary_to_list(RE0) + end; + false -> + RE0 + end, {Options,ExecOptions} = pick_exec_options(Options0), {Cres, Xopt} = case PreCompile of true -> @@ -80,7 +92,7 @@ test([{RE,Line,Options0,Tests}|T],PreCompile,XMode) -> %erlang:display({testrun,RE,P,Tests,ExecOptions,Xopt,XMode}), case (catch testrun(RE,P,Tests,ExecOptions,Xopt,XMode)) of N when is_integer(N) -> - N + test(T,PreCompile,XMode); + N + test(T,PreCompile,XMode,REAsList); limit -> io:format("Error limit reached.~n"), 1; @@ -91,12 +103,12 @@ test([{RE,Line,Options0,Tests}|T],PreCompile,XMode) -> _ -> put(skipped,1) end, - test(T,PreCompile,XMode) + test(T,PreCompile,XMode,REAsList) end; {error,Err} -> io:format("Compile error(~w): ~w~n",[Line,Err]), case get(error_limit) of - infinite -> 1 + test(T,PreCompile,XMode); + infinite -> 1 + test(T,PreCompile,XMode,REAsList); X -> case X-1 of Y when Y =< 0 -> @@ -104,7 +116,7 @@ test([{RE,Line,Options0,Tests}|T],PreCompile,XMode) -> 1; Y -> put(error_limit,Y), - 1 + test(T,PreCompile,XMode) + 1 + test(T,PreCompile,XMode,REAsList) end end end. @@ -549,6 +561,8 @@ tr_option($N) -> [no_auto_capture]; tr_option($8) -> [unicode]; +tr_option($U) -> + [ungreedy]; tr_option($g) -> [{exec_option,g}]; tr_option(_) -> @@ -973,6 +987,7 @@ gen_split_test(OneFile) -> {ok,F}= file:open(ErlFileName,[write]), io:format(F,"-module(~s).~n",[ErlModule]), io:format(F,"-compile(export_all).~n",[]), + io:format(F,"-compile(no_native).~n",[]), io:format(F,"-include(\"test_server.hrl\").~n",[]), %io:format(F,"-define(line,erlang:display(?LINE),).~n",[]), io:format(F,"%% This file is generated by running ~w:gen_split_test(~p)~n", @@ -1054,6 +1069,7 @@ gen_repl_test(OneFile) -> {ok,F}= file:open(ErlFileName,[write]), io:format(F,"-module(~s).~n",[ErlModule]), io:format(F,"-compile(export_all).~n",[]), + io:format(F,"-compile(no_native).~n",[]), io:format(F,"-include(\"test_server.hrl\").~n",[]), io:format(F,"%% This file is generated by running ~w:gen_repl_test(~p)~n", [?MODULE,OneFile]), diff --git a/lib/stdlib/test/select_SUITE.erl b/lib/stdlib/test/select_SUITE.erl index 54664fbb00..6900f1a8f5 100644 --- a/lib/stdlib/test/select_SUITE.erl +++ b/lib/stdlib/test/select_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% %% @@ -79,14 +79,14 @@ select_test(suite) -> []; select_test(doc) -> ["Tests select in numerous ways"]; -select_test(Config) when list(Config) -> +select_test(Config) when is_list(Config) -> do_test(Config). return_values(suite) -> []; return_values(doc) -> ["Tests return values in specific situations for select/3 and select/1"]; -return_values(Config) when list(Config) -> +return_values(Config) when is_list(Config) -> do_return_values(). -endif. @@ -279,7 +279,7 @@ cmp_ms_to_fun({Mod,Tab}, MS, Fun1, Fun2, ChunkSize) -> MSRes = lists:sort(chunked_select(Mod,Tab,MS,ChunkSize)), FunRes0 = table_foldl(Fun1,[],{Mod,Tab}), FunRes = case Fun2 of - F when function(F) -> + F when is_function(F) -> FunRes1 = table_foldl(F,[],{Mod,Tab}), lists:merge(FunRes0,FunRes1); [] -> diff --git a/lib/stdlib/test/shell_SUITE.erl b/lib/stdlib/test/shell_SUITE.erl index 5827d5f332..588342d46a 100644 --- a/lib/stdlib/test/shell_SUITE.erl +++ b/lib/stdlib/test/shell_SUITE.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(shell_SUITE). @@ -28,13 +28,14 @@ progex/1, progex_bit_syntax/1, progex_records/1, progex_lc/1, progex_funs/1, tickets/1, otp_5990/1, otp_6166/1, otp_6554/1, otp_6785/1, - otp_7184/1, otp_7232/1]). + otp_7184/1, otp_7232/1, otp_8393/1]). -export([restricted/1, start_restricted_from_shell/1, start_restricted_on_command_line/1,restricted_local/1]). %% Internal export. --export([otp_5435_2/0]). +-export([otp_5435_2/0, prompt1/1, prompt2/1, prompt3/1, prompt4/1, + prompt5/1]). %% %% Define to run outside of test server @@ -2256,7 +2257,7 @@ progex_funs(Config) when is_list(Config) -> ok. tickets(suite) -> - [otp_5990, otp_6166, otp_6554, otp_6785, otp_7184, otp_7232]. + [otp_5990, otp_6166, otp_6554, otp_6785, otp_7184, otp_7232, otp_8393]. otp_5990(doc) -> "OTP-5990. {erlang,is_record}."; @@ -2598,6 +2599,93 @@ otp_7232(Config) when is_list(Config) -> " end}])" = evaluate(Info, []), ok. +otp_8393(doc) -> + "OTP-8393. Prompt string."; +otp_8393(suite) -> []; +otp_8393(Config) when is_list(Config) -> + ?line _ = shell:prompt_func(default), + ?line "Bad prompt function: '> '" = + prompt_err(<<"shell:prompt_func('> ').">>), + + ?line _ = shell:prompt_func(default), + ?line "exception error: bad argument in an arithmetic expression"++_ = + prompt_err(<<"shell:prompt_func({shell_SUITE,prompt4}).">>), + + ?line _ = shell:prompt_func(default), + ?line "default.\n" = + t(<<"shell:prompt_func({shell_SUITE,prompt2}).">>), + + ?line _ = shell:prompt_func(default), + ?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]). + local_allowed(_,_,State) -> + {false,State}. + + non_local_allowed({shell,stop_restricted},[],State) -> + {true,State}; + non_local_allowed({shell,prompt_func},[_L],State) -> + {true,State}; + non_local_allowed({shell_SUITE,prompt1},[_L],State) -> + {true,State}; + non_local_allowed(_,_,State) -> + {false,State}. + ">>, + ?line Test = filename:join(?config(priv_dir, Config), + "test_restricted_shell.erl"), + ?line ok = compile_file(Config, Test, Contents, []), + ?line _ = shell:prompt_func(default), + ?line "exception exit: restricted shell starts now" = + comm_err(<<"begin shell:start_restricted(" + "test_restricted_shell) end.">>), + ?line "default.\n"++_ = + t(<<"shell:prompt_func({shell_SUITE,prompt1}).">>), + ?line "exception exit: restricted shell does not allow apple(" ++ _ = + comm_err(<<"apple(1).">>), + ?line "{shell_SUITE,prompt1}.\n" = + t(<<"shell:prompt_func(default).">>), + ?line "exception exit: restricted shell stopped"= + comm_err(<<"begin shell:stop_restricted() end.">>), + ?line undefined = + application:get_env(stdlib, restricted_shell), + + ?line NR = shell:results(20), + ?line "default\n20.\n" = + t(<<"shell:prompt_func({shell_SUITE,prompt3}). results(0).">>), + + ?line _ = shell:prompt_func(default), + ?line 0 = shell:results(NR), + ok. + +prompt1(_L) -> + "prompt> ". + +prompt2(_L) -> + {'EXIT', []}. + +prompt3(L) -> + N = proplists:get_value(history, L), + integer_to_list(N). + +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), @@ -2627,7 +2715,16 @@ comm_err(B) -> Reply = t(B), S0 = string:left(Reply, string:chr(Reply, $\n)-1), S1 = string:strip(S0, left, $*), - S2 = string:strip(S1, both, $ ), + S2 = string:strip(S1, both, $ ), + S = string:strip(S2, both, $"), + string:strip(S, right, $.). + +prompt_err(B) -> + Reply = t(B), + S00 = string:sub_string(Reply, string:chr(Reply, $\n)+1), + S0 = string:left(S00, string:chr(S00, $\n)-1), + S1 = string:strip(S0, left, $*), + S2 = string:strip(S1, both, $ ), S = string:strip(S2, both, $"), string:strip(S, right, $.). diff --git a/lib/stdlib/test/slave_SUITE.erl b/lib/stdlib/test/slave_SUITE.erl index 3b737af64d..5c1282fe9b 100644 --- a/lib/stdlib/test/slave_SUITE.erl +++ b/lib/stdlib/test/slave_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(slave_SUITE). @@ -31,7 +31,7 @@ all(suite) -> [t_start_link, start_link_nodedown, t_start, errors]. t_start_link(suite) -> []; -t_start_link(Config) when list(Config) -> +t_start_link(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(20)), %% Define useful variables. @@ -81,7 +81,7 @@ t_start_link(Config) when list(Config) -> %% Test that slave:start_link() works when the master exits. start_link_nodedown(suite) -> []; -start_link_nodedown(Config) when list(Config) -> +start_link_nodedown(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(20)), %% Define useful variables. @@ -109,7 +109,7 @@ start_a_slave(ReplyTo, Host, Name) -> %% Test slave:start(). t_start(suite) -> []; -t_start(Config) when list(Config) -> +t_start(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(20)), %% Define useful variables. @@ -160,7 +160,7 @@ t_start(Config) when list(Config) -> %% in slave is 32 seconds). errors(suite) -> []; -errors(Config) when list(Config) -> +errors(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(50)), ?line process_flag(trap_exit, true), diff --git a/lib/stdlib/test/sofs_SUITE.erl b/lib/stdlib/test/sofs_SUITE.erl index 0849e0f59c..d60cfc6895 100644 --- a/lib/stdlib/test/sofs_SUITE.erl +++ b/lib/stdlib/test/sofs_SUITE.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(sofs_SUITE). @@ -115,7 +115,7 @@ sofs(suite) -> from_term_1(suite) -> []; from_term_1(doc) -> [""]; -from_term_1(Conf) when list(Conf) -> +from_term_1(Conf) when is_list(Conf) -> %% would go wrong: projection(1,from_term([{2,b},{1,a,b}])), ?line {'EXIT', {badarg, _}} = (catch from_term([], {atom,'_',atom})), @@ -203,7 +203,7 @@ from_term_1(Conf) when list(Conf) -> set_1(suite) -> []; set_1(doc) -> [""]; -set_1(Conf) when list(Conf) -> +set_1(Conf) when is_list(Conf) -> %% set/1 ?line {'EXIT', {badarg, _}} = (catch set(a)), ?line {'EXIT', {badarg, _}} = (catch set({a})), @@ -235,7 +235,7 @@ set_1(Conf) when list(Conf) -> from_sets_1(suite) -> []; from_sets_1(doc) -> [""]; -from_sets_1(Conf) when list(Conf) -> +from_sets_1(Conf) when is_list(Conf) -> ?line E = empty_set(), %% unordered @@ -272,7 +272,7 @@ from_sets_1(Conf) when list(Conf) -> relation_1(suite) -> []; relation_1(doc) -> [""]; -relation_1(Conf) when list(Conf) -> +relation_1(Conf) when is_list(Conf) -> %% relation/1 ?line eval(relation([]), from_term([], [{atom,atom}])), ?line eval(from_term([{a}]), relation([{a}])), @@ -305,7 +305,7 @@ relation_1(Conf) when list(Conf) -> a_function_1(suite) -> []; a_function_1(doc) -> [""]; -a_function_1(Conf) when list(Conf) -> +a_function_1(Conf) when is_list(Conf) -> %% a_function/1 ?line eval(a_function([]), from_term([], [{atom,atom}])), ?line eval(a_function([{a,b},{a,b},{b,c}]), from_term([{a,b},{b,c}])), @@ -352,7 +352,7 @@ a_function_1(Conf) when list(Conf) -> family_1(suite) -> []; family_1(doc) -> [""]; -family_1(Conf) when list(Conf) -> +family_1(Conf) when is_list(Conf) -> %% family/1 ?line eval(family([]), from_term([],[{atom,[atom]}])), ?line {'EXIT', {badarg, _}} = (catch family(a)), @@ -413,7 +413,7 @@ family_1(Conf) when list(Conf) -> projection(suite) -> []; projection(doc) -> [""]; -projection(Conf) when list(Conf) -> +projection(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), @@ -535,7 +535,7 @@ projection(Conf) when list(Conf) -> substitution(suite) -> []; substitution(doc) -> [""]; -substitution(Conf) when list(Conf) -> +substitution(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), @@ -633,7 +633,7 @@ substitution(Conf) when list(Conf) -> restriction(suite) -> []; restriction(doc) -> [""]; -restriction(Conf) when list(Conf) -> +restriction(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([], 2), @@ -752,7 +752,7 @@ restriction(Conf) when list(Conf) -> drestriction(suite) -> []; drestriction(doc) -> [""]; -drestriction(Conf) when list(Conf) -> +drestriction(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([], 2), @@ -869,7 +869,7 @@ drestriction(Conf) when list(Conf) -> strict_relation_1(suite) -> []; strict_relation_1(doc) -> [""]; -strict_relation_1(Conf) when list(Conf) -> +strict_relation_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([], 2), ?line eval(strict_relation(E), E), @@ -890,7 +890,7 @@ strict_relation_1(Conf) when list(Conf) -> extension(suite) -> []; extension(doc) -> [""]; -extension(Conf) when list(Conf) -> +extension(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([], 2), ?line EF = family([]), @@ -933,7 +933,7 @@ lextension(R, S, C) -> weak_relation_1(suite) -> []; weak_relation_1(doc) -> [""]; -weak_relation_1(Conf) when list(Conf) -> +weak_relation_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([], 2), ?line eval(weak_relation(E), E), @@ -966,7 +966,7 @@ weak_relation_1(Conf) when list(Conf) -> to_sets_1(suite) -> []; to_sets_1(doc) -> [""]; -to_sets_1(Conf) when list(Conf) -> +to_sets_1(Conf) when is_list(Conf) -> ?line {'EXIT', {badarg, _}} = (catch to_sets(from_term(a))), ?line {'EXIT', {function_clause, _}} = (catch to_sets(a)), %% unordered @@ -988,8 +988,8 @@ to_sets_1(Conf) when list(Conf) -> specification(suite) -> []; specification(doc) -> [""]; -specification(Conf) when list(Conf) -> - Fun = {external, fun(I) when integer(I) -> true; (_) -> false end}, +specification(Conf) when is_list(Conf) -> + Fun = {external, fun(I) when is_integer(I) -> true; (_) -> false end}, ?line [1,2,3] = to_external(specification(Fun, set([a,1,b,2,c,3]))), Fun2 = fun(S) -> is_subset(S, set([1,3,5,7,9])) end, @@ -1014,7 +1014,7 @@ specification(Conf) when list(Conf) -> union_1(suite) -> []; union_1(doc) -> [""]; -union_1(Conf) when list(Conf) -> +union_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([], 2), ?line {'EXIT', {badarg, _}} = (catch union(ER)), @@ -1044,7 +1044,7 @@ union_1(Conf) when list(Conf) -> intersection_1(suite) -> []; intersection_1(doc) -> [""]; -intersection_1(Conf) when list(Conf) -> +intersection_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line {'EXIT', {badarg, _}} = (catch intersection(from_term([a,b]))), ?line {'EXIT', {badarg, _}} = (catch intersection(E)), @@ -1068,7 +1068,7 @@ intersection_1(Conf) when list(Conf) -> difference(suite) -> []; difference(doc) -> [""]; -difference(Conf) when list(Conf) -> +difference(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line {'EXIT', {type_mismatch, _}} = (catch difference(relation([{a,b}]), relation([{a,b,c}]))), @@ -1089,7 +1089,7 @@ difference(Conf) when list(Conf) -> symdiff(suite) -> []; symdiff(doc) -> [""]; -symdiff(Conf) when list(Conf) -> +symdiff(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line {'EXIT', {type_mismatch, _}} = (catch symdiff(relation([{a,b}]), relation([{a,b,c}]))), @@ -1114,7 +1114,7 @@ symdiff(Conf) when list(Conf) -> symmetric_partition(suite) -> []; symmetric_partition(doc) -> [""]; -symmetric_partition(Conf) when list(Conf) -> +symmetric_partition(Conf) when is_list(Conf) -> ?line E = set([]), ?line S1 = set([1,2,3,4]), ?line S2 = set([3,4,5,6]), @@ -1148,7 +1148,7 @@ symmetric_partition(Conf) when list(Conf) -> is_sofs_set_1(suite) -> []; is_sofs_set_1(doc) -> [""]; -is_sofs_set_1(Conf) when list(Conf) -> +is_sofs_set_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line true = is_sofs_set(E), ?line true = is_sofs_set(from_term([a])), @@ -1159,7 +1159,7 @@ is_sofs_set_1(Conf) when list(Conf) -> is_set_1(suite) -> []; is_set_1(doc) -> [""]; -is_set_1(Conf) when list(Conf) -> +is_set_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line true = is_set(E), ?line true = is_set(from_term([a])), @@ -1177,7 +1177,7 @@ is_set_1(Conf) when list(Conf) -> is_equal(suite) -> []; is_equal(doc) -> [""]; -is_equal(Conf) when list(Conf) -> +is_equal(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line true = is_equal(E, E), ?line false = is_equal(from_term([a]), E), @@ -1212,7 +1212,7 @@ is_equal(Conf) when list(Conf) -> is_subset(suite) -> []; is_subset(doc) -> [""]; -is_subset(Conf) when list(Conf) -> +is_subset(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line true = is_subset(E, E), ?line true = is_subset(set([a,c,e]), set([a,b,c,d,e])), @@ -1230,7 +1230,7 @@ is_subset(Conf) when list(Conf) -> is_a_function_1(suite) -> []; is_a_function_1(doc) -> [""]; -is_a_function_1(Conf) when list(Conf) -> +is_a_function_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([], 2), ?line {'EXIT', {badarg, _}} = (catch is_a_function(set([a,b]))), @@ -1254,7 +1254,7 @@ is_a_function_1(Conf) when list(Conf) -> is_disjoint(suite) -> []; is_disjoint(doc) -> [""]; -is_disjoint(Conf) when list(Conf) -> +is_disjoint(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line {'EXIT', {type_mismatch, _}} = (catch is_disjoint(relation([{a,1}]), set([a,b]))), @@ -1268,7 +1268,7 @@ is_disjoint(Conf) when list(Conf) -> join(suite) -> []; join(doc) -> [""]; -join(Conf) when list(Conf) -> +join(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line {'EXIT', {badarg, _}} = (catch join(relation([{a,1}]), 3, E, 5)), @@ -1306,7 +1306,7 @@ join(Conf) when list(Conf) -> canonical(suite) -> []; canonical(doc) -> [""]; -canonical(Conf) when list(Conf) -> +canonical(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line {'EXIT', {badarg, _}} = (catch canonical_relation(set([a,b]))), @@ -1318,7 +1318,7 @@ canonical(Conf) when list(Conf) -> relation_to_family_1(suite) -> []; relation_to_family_1(doc) -> [""]; -relation_to_family_1(Conf) when list(Conf) -> +relation_to_family_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = family([]), ?line eval(relation_to_family(E), E), @@ -1333,7 +1333,7 @@ relation_to_family_1(Conf) when list(Conf) -> domain_1(suite) -> []; domain_1(doc) -> [""]; -domain_1(Conf) when list(Conf) -> +domain_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line {'EXIT', {badarg, _}} = (catch domain(relation([],3))), @@ -1355,7 +1355,7 @@ domain_1(Conf) when list(Conf) -> range_1(suite) -> []; range_1(doc) -> [""]; -range_1(Conf) when list(Conf) -> +range_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line {'EXIT', {badarg, _}} = (catch range(relation([],3))), @@ -1367,7 +1367,7 @@ range_1(Conf) when list(Conf) -> inverse_1(suite) -> []; inverse_1(doc) -> [""]; -inverse_1(Conf) when list(Conf) -> +inverse_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line {'EXIT', {badarg, _}} = (catch inverse(relation([],3))), @@ -1391,7 +1391,7 @@ inverse_1(Conf) when list(Conf) -> converse_1(suite) -> []; converse_1(doc) -> [""]; -converse_1(Conf) when list(Conf) -> +converse_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line {'EXIT', {badarg, _}} = (catch converse(relation([],3))), @@ -1407,7 +1407,7 @@ converse_1(Conf) when list(Conf) -> no_elements_1(suite) -> []; no_elements_1(doc) -> [""]; -no_elements_1(Conf) when list(Conf) -> +no_elements_1(Conf) when is_list(Conf) -> ?line 0 = no_elements(empty_set()), ?line 0 = no_elements(set([])), ?line 1 = no_elements(from_term([a])), @@ -1419,7 +1419,7 @@ no_elements_1(Conf) when list(Conf) -> image(suite) -> []; image(doc) -> [""]; -image(Conf) when list(Conf) -> +image(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line eval(image(E, E), E), @@ -1441,7 +1441,7 @@ image(Conf) when list(Conf) -> inverse_image(suite) -> []; inverse_image(doc) -> [""]; -inverse_image(Conf) when list(Conf) -> +inverse_image(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line eval(inverse_image(E, E), E), @@ -1468,7 +1468,7 @@ inverse_image(Conf) when list(Conf) -> composite_1(suite) -> []; composite_1(doc) -> [""]; -composite_1(Conf) when list(Conf) -> +composite_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = a_function([]), ?line eval(composite(E, E), E), @@ -1520,7 +1520,7 @@ composite_1(Conf) when list(Conf) -> relative_product_1(suite) -> []; relative_product_1(doc) -> [""]; -relative_product_1(Conf) when list(Conf) -> +relative_product_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line eval(relative_product1(E, E), E), @@ -1548,7 +1548,7 @@ relative_product_1(Conf) when list(Conf) -> relative_product_2(suite) -> []; relative_product_2(doc) -> [""]; -relative_product_2(Conf) when list(Conf) -> +relative_product_2(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), @@ -1597,7 +1597,7 @@ relative_product_2(Conf) when list(Conf) -> product_1(suite) -> []; product_1(doc) -> [""]; -product_1(Conf) when list(Conf) -> +product_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line eval(product(E, E), E), ?line eval(product(relation([]), E), E), @@ -1625,7 +1625,7 @@ product_1(Conf) when list(Conf) -> partition_1(suite) -> []; partition_1(doc) -> [""]; -partition_1(Conf) when list(Conf) -> +partition_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line Id = fun(A) -> A end, @@ -1671,7 +1671,7 @@ partition_1(Conf) when list(Conf) -> partition_3(suite) -> []; partition_3(doc) -> [""]; -partition_3(Conf) when list(Conf) -> +partition_3(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), @@ -1818,7 +1818,7 @@ lpartition(F, S1, S2) -> multiple_relative_product(suite) -> []; multiple_relative_product(doc) -> [""]; -multiple_relative_product(Conf) when list(Conf) -> +multiple_relative_product(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line T = relation([{a,1},{a,11},{b,2},{c,3},{c,33},{d,4}]), @@ -1842,7 +1842,7 @@ multiple_relative_product(Conf) when list(Conf) -> digraph(suite) -> []; digraph(doc) -> [""]; -digraph(Conf) when list(Conf) -> +digraph(Conf) when is_list(Conf) -> ?line T0 = ets:all(), ?line E = empty_set(), ?line R = relation([{a,b},{b,c},{c,d},{d,a}]), @@ -1901,7 +1901,7 @@ digraph(Conf) when list(Conf) -> constant_function(suite) -> []; constant_function(doc) -> [""]; -constant_function(Conf) when list(Conf) -> +constant_function(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line C = from_term(3), ?line eval(constant_function(E, C), E), @@ -1913,7 +1913,7 @@ constant_function(Conf) when list(Conf) -> misc(suite) -> []; misc(doc) -> [""]; -misc(Conf) when list(Conf) -> +misc(Conf) when is_list(Conf) -> % find "relational" part of relation: ?line S = relation([{a,b},{b,c},{b,d},{c,d}]), Id = fun(A) -> A end, @@ -1943,7 +1943,7 @@ sofs_family(suite) -> family_specification(suite) -> []; family_specification(doc) -> [""]; -family_specification(Conf) when list(Conf) -> +family_specification(Conf) when is_list(Conf) -> E = empty_set(), %% internal ?line eval(family_specification({sofs, is_set}, E), E), @@ -1963,7 +1963,7 @@ family_specification(Conf) when list(Conf) -> (catch family_specification(Fun3, F3)), %% external - IsList = {external, fun(L) when list(L) -> true; (_) -> false end}, + IsList = {external, fun(L) when is_list(L) -> true; (_) -> false end}, ?line eval(family_specification(IsList, E), E), ?line eval(family_specification(IsList, F1), F1), MF = {external, fun(L) -> lists:member(3, L) end}, @@ -1975,7 +1975,7 @@ family_specification(Conf) when list(Conf) -> family_domain_1(suite) -> []; family_domain_1(doc) -> [""]; -family_domain_1(Conf) when list(Conf) -> +family_domain_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = from_term([{a,[]},{b,[]}],[{atom,[{atom,atom}]}]), ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), @@ -2001,7 +2001,7 @@ family_domain_1(Conf) when list(Conf) -> family_range_1(suite) -> []; family_range_1(doc) -> [""]; -family_range_1(Conf) when list(Conf) -> +family_range_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = from_term([{a,[]},{b,[]}],[{atom,[{atom,atom}]}]), ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), @@ -2023,7 +2023,7 @@ family_range_1(Conf) when list(Conf) -> family_to_relation_1(suite) -> []; family_to_relation_1(doc) -> [""]; -family_to_relation_1(Conf) when list(Conf) -> +family_to_relation_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line ER = relation([]), ?line EF = family([]), @@ -2037,7 +2037,7 @@ family_to_relation_1(Conf) when list(Conf) -> union_of_family_1(suite) -> []; union_of_family_1(doc) -> [""]; -union_of_family_1(Conf) when list(Conf) -> +union_of_family_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), ?line eval(union_of_family(E), E), @@ -2052,7 +2052,7 @@ union_of_family_1(Conf) when list(Conf) -> intersection_of_family_1(suite) -> []; intersection_of_family_1(doc) -> [""]; -intersection_of_family_1(Conf) when list(Conf) -> +intersection_of_family_1(Conf) when is_list(Conf) -> ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), ?line eval(intersection_of_family(EF), set([])), ?line FR = from_term([{a,[1,2,3]},{b,[2,3]},{c,[3,4,5]}]), @@ -2066,7 +2066,7 @@ intersection_of_family_1(Conf) when list(Conf) -> family_projection(suite) -> []; family_projection(doc) -> [""]; -family_projection(Conf) when list(Conf) -> +family_projection(Conf) when is_list(Conf) -> SSType = [{atom,[[atom]]}], SRType = [{atom,[{atom,atom}]}], ?line E = empty_set(), @@ -2127,7 +2127,7 @@ family_projection(Conf) when list(Conf) -> family_difference(suite) -> []; family_difference(doc) -> [""]; -family_difference(Conf) when list(Conf) -> +family_difference(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = family([]), ?line F9 = from_term([{b,[b,c]}]), @@ -2164,7 +2164,7 @@ family_difference(Conf) when list(Conf) -> family_intersection_1(suite) -> []; family_intersection_1(doc) -> [""]; -family_intersection_1(Conf) when list(Conf) -> +family_intersection_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = family([]), ?line ES = from_term([], [{atom,[[atom]]}]), @@ -2184,7 +2184,7 @@ family_intersection_1(Conf) when list(Conf) -> family_intersection_2(suite) -> []; family_intersection_2(doc) -> [""]; -family_intersection_2(Conf) when list(Conf) -> +family_intersection_2(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = family([]), ?line F1 = from_term([{a,[1,2]},{b,[4,5]},{c,[7,8]},{d,[10,11]}]), @@ -2215,7 +2215,7 @@ family_intersection_2(Conf) when list(Conf) -> family_union_1(suite) -> []; family_union_1(doc) -> [""]; -family_union_1(Conf) when list(Conf) -> +family_union_1(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = family([]), ?line ES = from_term([], [{atom,[[atom]]}]), @@ -2230,7 +2230,7 @@ family_union_1(Conf) when list(Conf) -> family_union_2(suite) -> []; family_union_2(doc) -> [""]; -family_union_2(Conf) when list(Conf) -> +family_union_2(Conf) when is_list(Conf) -> ?line E = empty_set(), ?line EF = family([]), ?line F1 = from_term([{a,[1,2]},{b,[4,5]},{c,[7,8]},{d,[10,11]}]), @@ -2259,7 +2259,7 @@ family_union_2(Conf) when list(Conf) -> partition_family(suite) -> []; partition_family(doc) -> [""]; -partition_family(Conf) when list(Conf) -> +partition_family(Conf) when is_list(Conf) -> ?line E = empty_set(), %% set of ordered sets diff --git a/lib/stdlib/test/supervisor_SUITE.erl b/lib/stdlib/test/supervisor_SUITE.erl index b5d9ca44bf..039ea298c4 100644 --- a/lib/stdlib/test/supervisor_SUITE.erl +++ b/lib/stdlib/test/supervisor_SUITE.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% %% %% Description: Tests supervisor.erl @@ -50,7 +50,7 @@ simple_one_for_one_extra/1]). %% Misc tests --export([child_unlink/1, tree/1]). +-export([child_unlink/1, tree/1, count_children_memory/1]). %------------------------------------------------------------------------- @@ -60,7 +60,8 @@ all(suite) -> child_adm_simple, extra_return, child_specs, restart_one_for_one, restart_one_for_all, restart_simple_one_for_one, restart_rest_for_one, - normal_termination, abnormal_termination, child_unlink, tree]}. + normal_termination, abnormal_termination, child_unlink, tree, + count_children_memory]}. start(InitResult) -> @@ -72,6 +73,15 @@ init(fail) -> init(InitResult) -> InitResult. +%% Respect proplist return of supervisor:count_children +get_child_counts(Supervisor) -> + Counts = supervisor:count_children(Supervisor), + [proplists:get_value(specs, Counts), + proplists:get_value(active, Counts), + proplists:get_value(supervisors, Counts), + proplists:get_value(workers, Counts)]. + + %------------------------------------------------------------------------- % % Test cases starts here. @@ -89,7 +99,7 @@ sup_start_normal(doc) -> ["Tests that the supervisor process starts correctly and that it " "can be terminated gracefully."]; sup_start_normal(suite) -> []; -sup_start_normal(Config) when list(Config) -> +sup_start_normal(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {ok, Pid} = start({ok, {{one_for_one, 2, 3600}, []}}), ?line exit(Pid, shutdown), @@ -107,7 +117,7 @@ sup_start_normal(Config) when list(Config) -> sup_start_ignore_init(doc) -> ["Tests what happens if init-callback returns ignore"]; sup_start_ignore_init(suite) -> []; -sup_start_ignore_init(Config) when list(Config) -> +sup_start_ignore_init(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line ignore = start(ignore), @@ -127,7 +137,7 @@ sup_start_ignore_init(Config) when list(Config) -> sup_start_ignore_child(doc) -> ["Tests what happens if init-callback returns ignore"]; sup_start_ignore_child(suite) -> []; -sup_start_ignore_child(Config) when list(Config) -> +sup_start_ignore_child(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {ok, _Pid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, [ignore]}, @@ -140,13 +150,15 @@ sup_start_ignore_child(Config) when list(Config) -> ?line [{child2, CPid2, worker, []},{child1, undefined, worker, []}] = supervisor:which_children(sup_test), + ?line [2,1,0,2] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- sup_start_error_return(doc) -> ["Tests what happens if init-callback returns a invalid value"]; sup_start_error_return(suite) -> []; -sup_start_error_return(Config) when list(Config) -> +sup_start_error_return(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {error, Term} = start(invalid), @@ -165,7 +177,7 @@ sup_start_error_return(Config) when list(Config) -> sup_start_fail(doc) -> ["Tests what happens if init-callback fails"]; sup_start_fail(suite) -> []; -sup_start_fail(Config) when list(Config) -> +sup_start_fail(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {error, Term} = start(fail), @@ -192,7 +204,7 @@ sup_stop_infinity(doc) -> "for children of type supervisor"]; sup_stop_infinity(suite) -> []; -sup_stop_infinity(Config) when list(Config) -> +sup_stop_infinity(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {ok, Pid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, @@ -230,7 +242,7 @@ sup_stop_timeout(doc) -> ["See sup_stop/1 when Shutdown = 1000"]; sup_stop_timeout(suite) -> []; -sup_stop_timeout(Config) when list(Config) -> +sup_stop_timeout(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {ok, Pid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, @@ -278,7 +290,7 @@ sup_stop_brutal_kill(doc) -> ["See sup_stop/1 when Shutdown = brutal_kill"]; sup_stop_brutal_kill(suite) -> []; -sup_stop_brutal_kill(Config) when list(Config) -> +sup_stop_brutal_kill(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {ok, Pid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, @@ -327,7 +339,7 @@ extra_return(doc) -> "and restart_child/2"]; extra_return(suite) -> []; -extra_return(Config) when list(Config) -> +extra_return(Config) when is_list(Config) -> process_flag(trap_exit, true), Child = {child1, {supervisor_1, start_child, [extra_return]}, permanent, 1000, @@ -341,6 +353,8 @@ extra_return(Config) when list(Config) -> ?line {error, running} = supervisor:delete_child(sup_test, child1), ?line {error, running} = supervisor:restart_child(sup_test, child1), ?line [{child1, CPid, worker, []}] = supervisor:which_children(sup_test), + ?line [1,1,0,1] = get_child_counts(sup_test), + ?line ok = supervisor:terminate_child(sup_test, child1), receive {'EXIT', CPid, shutdown} -> ok; @@ -350,29 +364,39 @@ extra_return(Config) when list(Config) -> ?line test_server:fail(no_child_termination) end, ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test), + ?line [1,0,0,1] = get_child_counts(sup_test), + ?line {ok, CPid2,extra_return} = supervisor:restart_child(sup_test, child1), ?line [{child1, CPid2, worker, []}] = supervisor:which_children(sup_test), + ?line [1,1,0,1] = get_child_counts(sup_test), + ?line ok = supervisor:terminate_child(sup_test, child1), ?line ok = supervisor:terminate_child(sup_test, child1), ?line ok = supervisor:delete_child(sup_test, child1), ?line {error, not_found} = supervisor:restart_child(sup_test, child1), ?line [] = supervisor:which_children(sup_test), + ?line [0,0,0,0] = get_child_counts(sup_test), + ?line {ok, CPid3, extra_return} = supervisor:start_child(sup_test, Child), ?line [{child1, CPid3, worker, []}] = supervisor:which_children(sup_test), + ?line [1,1,0,1] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- child_adm(doc)-> ["Test API functions start_child/2, terminate_child/2, delete_child/2 " - "restart_child/2, which_children/1. Only correct childspecs are used, " - "handling of incorrect childspecs is tested in child_specs/1"]; + "restart_child/2, which_children/1, count_children/1. Only correct " + "childspecs are used, handling of incorrect childspecs is tested in " + "child_specs/1"]; child_adm(suite) -> []; -child_adm(Config) when list(Config) -> +child_adm(Config) when is_list(Config) -> process_flag(trap_exit, true), Child = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, ?line {ok, _Pid} = start({ok, {{one_for_one, 2, 3600}, [Child]}}), ?line [{child1, CPid, worker, []}] = supervisor:which_children(sup_test), + ?line [1,1,0,1] = get_child_counts(sup_test), link(CPid), %% Start of an already runnig process @@ -392,6 +416,7 @@ child_adm(Config) when list(Config) -> ?line test_server:fail(no_child_termination) end, ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test), + ?line [1,0,0,1] = get_child_counts(sup_test), %% Like deleting something that does not exist, it will succeed! ?line ok = supervisor:terminate_child(sup_test, child1), @@ -402,6 +427,7 @@ child_adm(Config) when list(Config) -> %% Restart ?line {ok, CPid2} = supervisor:restart_child(sup_test, child1), ?line [{child1, CPid2, worker, []}] = supervisor:which_children(sup_test), + ?line [1,1,0,1] = get_child_counts(sup_test), ?line {error, running} = supervisor:restart_child(sup_test, child1), ?line {error, not_found} = supervisor:restart_child(sup_test, child2), @@ -414,15 +440,19 @@ child_adm(Config) when list(Config) -> ?line ok = supervisor:delete_child(sup_test, child1), ?line {error, not_found} = supervisor:restart_child(sup_test, child1), ?line [] = supervisor:which_children(sup_test), + ?line [0,0,0,0] = get_child_counts(sup_test), %% Start ?line {'EXIT',{noproc,{gen_server,call, _}}} = (catch supervisor:start_child(foo, Child)), ?line {ok, CPid3} = supervisor:start_child(sup_test, Child), ?line [{child1, CPid3, worker, []}] = supervisor:which_children(sup_test), + ?line [1,1,0,1] = get_child_counts(sup_test), ?line {'EXIT',{noproc,{gen_server,call,[foo,which_children,infinity]}}} = (catch supervisor:which_children(foo)), + ?line {'EXIT',{noproc,{gen_server,call,[foo,count_children,infinity]}}} + = (catch supervisor:count_children(foo)), ok. %------------------------------------------------------------------------- child_adm_simple(doc) -> @@ -430,12 +460,13 @@ child_adm_simple(doc) -> "restart_child/2 are not valid for a simple_one_for_one supervisor " "check that the correct error message is returned."]; child_adm_simple(suite) -> []; -child_adm_simple(Config) when list(Config) -> +child_adm_simple(Config) when is_list(Config) -> Child = {child, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, ?line {ok, _Pid} = start({ok, {{simple_one_for_one, 2, 3600}, [Child]}}), %% In simple_one_for_one all children are added dynamically ?line [] = supervisor:which_children(sup_test), + ?line [1,0,0,0] = get_child_counts(sup_test), %% Start ?line {'EXIT',{noproc,{gen_server,call, _}}} = @@ -443,12 +474,14 @@ child_adm_simple(Config) when list(Config) -> ?line {ok, CPid1} = supervisor:start_child(sup_test, []), ?line [{undefined, CPid1, worker, []}] = supervisor:which_children(sup_test), + ?line [1,1,0,1] = get_child_counts(sup_test), ?line {ok, CPid2} = supervisor:start_child(sup_test, []), ?line Children = supervisor:which_children(sup_test), ?line 2 = length(Children), ?line true = lists:member({undefined, CPid2, worker, []}, Children), ?line true = lists:member({undefined, CPid1, worker, []}, Children), + ?line [1,2,0,2] = get_child_counts(sup_test), %% Termination ?line {error, simple_one_for_one} = @@ -467,7 +500,7 @@ child_adm_simple(Config) when list(Config) -> child_specs(doc) -> ["Tests child specs, invalid formats should be rejected."]; child_specs(suite) -> []; -child_specs(Config) when list(Config) -> +child_specs(Config) when is_list(Config) -> process_flag(trap_exit, true), ?line {ok, _Pid} = start({ok, {{one_for_one, 2, 3600}, []}}), ?line {error, _} = supervisor:start_child(sup_test, hej), @@ -526,7 +559,7 @@ normal_termination(suite) -> permanent_normal(doc) -> ["A permanent child should always be restarted"]; permanent_normal(suite) -> []; -permanent_normal(Config) when list(Config) -> +permanent_normal(Config) when is_list(Config) -> ?line {ok, _SupPid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -541,14 +574,16 @@ permanent_normal(Config) when list(Config) -> ok; false -> ?line test_server:fail({permanent_child_not_restarted, Child1}) - end. + end, + ?line [1,1,0,1] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- transient_normal(doc) -> ["A transient child should not be restarted if it exits with " "reason normal"]; transient_normal(suite) -> []; -transient_normal(Config) when list(Config) -> +transient_normal(Config) when is_list(Config) -> ?line {ok, _SupPid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, transient, 1000, worker, []}, @@ -558,13 +593,15 @@ transient_normal(Config) when list(Config) -> CPid1 ! stop, test_server:sleep(100), - ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test). + ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test), + ?line [1,0,0,1] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- temporary_normal(doc) -> ["A temporary process should never be restarted"]; temporary_normal(suite) -> []; -temporary_normal(Config) when list(Config) -> +temporary_normal(Config) when is_list(Config) -> ?line {ok, _SupPid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, temporary, 1000, worker, []}, @@ -574,8 +611,10 @@ temporary_normal(Config) when list(Config) -> CPid1 ! stop, test_server:sleep(100), - ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test). + ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test), + ?line [1,0,0,1] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- abnormal_termination(doc) -> ["Testes the supervisors behaviour if a child dies with reason abnormal"]; @@ -586,7 +625,7 @@ abnormal_termination(suite) -> permanent_abnormal(doc) -> ["A permanent child should always be restarted"]; permanent_abnormal(suite) -> []; -permanent_abnormal(Config) when list(Config) -> +permanent_abnormal(Config) when is_list(Config) -> ?line {ok, _SupPid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -601,14 +640,16 @@ permanent_abnormal(Config) when list(Config) -> ok; false -> ?line test_server:fail({permanent_child_not_restarted, Child1}) - end. + end, + ?line [1,1,0,1] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- transient_abnormal(doc) -> ["A transient child should be restarted if it exits with " "reason abnormal"]; transient_abnormal(suite) -> []; -transient_abnormal(Config) when list(Config) -> +transient_abnormal(Config) when is_list(Config) -> ?line {ok, _SupPid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, transient, 1000, worker, []}, @@ -624,14 +665,15 @@ transient_abnormal(Config) when list(Config) -> ok; false -> ?line test_server:fail({transient_child_not_restarted, Child1}) - end. - + end, + ?line [1,1,0,1] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- temporary_abnormal(doc) -> ["A temporary process should never be restarted"]; temporary_abnormal(suite) -> []; -temporary_abnormal(Config) when list(Config) -> +temporary_abnormal(Config) when is_list(Config) -> ?line {ok, _SupPid} = start({ok, {{one_for_one, 2, 3600}, []}}), Child1 = {child1, {supervisor_1, start_child, []}, temporary, 1000, worker, []}, @@ -641,8 +683,10 @@ temporary_abnormal(Config) when list(Config) -> CPid1 ! die, test_server:sleep(100), - ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test). + ?line [{child1,undefined,worker,[]}] = supervisor:which_children(sup_test), + ?line [1,0,0,1] = get_child_counts(sup_test), + ok. %------------------------------------------------------------------------- restart_one_for_one(doc) -> ["Test that the one_for_one strategy works."]; @@ -653,7 +697,7 @@ restart_one_for_one(suite) -> [one_for_one, one_for_one_escalation]. one_for_one(doc) -> ["Test the one_for_one base case."]; one_for_one(suite) -> []; -one_for_one(Config) when list(Config) -> +one_for_one(Config) when is_list(Config) -> process_flag(trap_exit, true), Child1 = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -679,6 +723,7 @@ one_for_one(Config) when list(Config) -> end; true -> ?line test_server:fail({bad_child_list, Children}) end, + ?line [2,2,0,2] = get_child_counts(sup_test), %% Test restart frequency property CPid2 ! die, @@ -697,7 +742,7 @@ one_for_one(Config) when list(Config) -> one_for_one_escalation(doc) -> ["Test restart escalation on a one_for_one supervisor."]; one_for_one_escalation(suite) -> []; -one_for_one_escalation(Config) when list(Config) -> +one_for_one_escalation(Config) when is_list(Config) -> process_flag(trap_exit, true), Child1 = {child1, {supervisor_1, start_child, [error]}, permanent, 1000, @@ -737,7 +782,7 @@ restart_one_for_all(suite) -> one_for_all(doc) -> ["Test the one_for_all base case."]; one_for_all(suite) -> []; -one_for_all(Config) when list(Config) -> +one_for_all(Config) when is_list(Config) -> process_flag(trap_exit, true), Child1 = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -772,6 +817,8 @@ one_for_all(Config) when list(Config) -> true -> ?line test_server:fail(bad_child); false -> ok end, + ?line [2,2,0,2] = get_child_counts(sup_test), + %%% Test restart frequency property [{_, Pid3, _, _}|_] = supervisor:which_children(sup_test), Pid3 ! die, @@ -788,7 +835,7 @@ one_for_all(Config) when list(Config) -> one_for_all_escalation(doc) -> ["Test restart escalation on a one_for_all supervisor."]; one_for_all_escalation(suite) -> []; -one_for_all_escalation(Config) when list(Config) -> +one_for_all_escalation(Config) when is_list(Config) -> process_flag(trap_exit, true), Child1 = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -830,7 +877,7 @@ restart_simple_one_for_one(suite) -> simple_one_for_one(doc) -> ["Test the simple_one_for_one base case."]; simple_one_for_one(suite) -> []; -simple_one_for_one(Config) when list(Config) -> +simple_one_for_one(Config) when is_list(Config) -> process_flag(trap_exit, true), Child = {child, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -854,6 +901,8 @@ simple_one_for_one(Config) when list(Config) -> end; true -> ?line test_server:fail({bad_child_list, Children}) end, + ?line [1,2,0,2] = get_child_counts(sup_test), + %% Test restart frequency property CPid2 ! die, receive @@ -872,7 +921,7 @@ simple_one_for_one_extra(doc) -> ["Tests automatic restart of children " "who's start function return extra info."]; simple_one_for_one_extra(suite) -> []; -simple_one_for_one_extra(Config) when list(Config) -> +simple_one_for_one_extra(Config) when is_list(Config) -> process_flag(trap_exit, true), Child = {child, {supervisor_1, start_child, [extra_info]}, permanent, 1000, worker, []}, @@ -896,6 +945,8 @@ simple_one_for_one_extra(Config) when list(Config) -> end; true -> ?line test_server:fail({bad_child_list, Children}) end, + ?line [1,2,0,2] = get_child_counts(sup_test), + CPid2 ! die, receive {'EXIT', CPid2, _} -> ok @@ -912,7 +963,7 @@ simple_one_for_one_extra(Config) when list(Config) -> simple_one_for_one_escalation(doc) -> ["Test restart escalation on a simple_one_for_one supervisor."]; simple_one_for_one_escalation(suite) -> []; -simple_one_for_one_escalation(Config) when list(Config) -> +simple_one_for_one_escalation(Config) when is_list(Config) -> process_flag(trap_exit, true), Child = {child, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -947,7 +998,7 @@ restart_rest_for_one(suite) -> [rest_for_one, rest_for_one_escalation]. rest_for_one(doc) -> ["Test the rest_for_one base case."]; rest_for_one(suite) -> []; -rest_for_one(Config) when list(Config) -> +rest_for_one(Config) when is_list(Config) -> process_flag(trap_exit, true), Child1 = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -962,6 +1013,8 @@ rest_for_one(Config) when list(Config) -> link(CPid2), ?line {ok, CPid3} = supervisor:start_child(sup_test, Child3), link(CPid3), + ?line [3,3,0,3] = get_child_counts(sup_test), + CPid2 ! die, receive {'EXIT', CPid2, died} -> ok; @@ -987,6 +1040,8 @@ rest_for_one(Config) when list(Config) -> if length(Children) == 3 -> ok; true -> ?line test_server:fail({bad_child_list, Children}) end, + ?line [3,3,0,3] = get_child_counts(sup_test), + %% Test that no old children is still alive SCh = lists:map(fun({_,P,_,_}) -> P end, Children), case lists:member(CPid1, SCh) of @@ -1018,7 +1073,7 @@ rest_for_one(Config) when list(Config) -> rest_for_one_escalation(doc) -> ["Test restart escalation on a rest_for_one supervisor."]; rest_for_one_escalation(suite) -> []; -rest_for_one_escalation(Config) when list(Config) -> +rest_for_one_escalation(Config) when is_list(Config) -> process_flag(trap_exit, true), Child1 = {child1, {supervisor_1, start_child, []}, permanent, 1000, worker, []}, @@ -1052,7 +1107,7 @@ rest_for_one_escalation(Config) when list(Config) -> child_unlink(doc)-> ["Test that the supervisor does not hang forever if " "the child unliks and then is terminated by the supervisor."]; child_unlink(suite) -> []; -child_unlink(Config) when list(Config) -> +child_unlink(Config) when is_list(Config) -> ?line {ok, SupPid} = start({ok, {{one_for_one, 2, 3600}, []}}), @@ -1081,7 +1136,7 @@ tree(doc) -> ["Test a basic supervison tree."]; tree(suite) -> []; -tree(Config) when list(Config) -> +tree(Config) when is_list(Config) -> process_flag(trap_exit, true), Child1 = {child1, {supervisor_1, start_child, []}, @@ -1114,15 +1169,19 @@ tree(Config) when list(Config) -> %% Child supervisors ?line {ok, Sup1} = supervisor:start_child(Pid, ChildSup1), ?line {ok, Sup2} = supervisor:start_child(Pid, ChildSup2), + ?line [2,2,2,0] = get_child_counts(Pid), %% Workers - ?line [{_, CPid2, _, _},{_, CPid1, _, _}] = supervisor:which_children(Sup1), + ?line [2,2,0,2] = get_child_counts(Sup1), + ?line [0,0,0,0] = get_child_counts(Sup2), %% Dynamic children ?line {ok, CPid3} = supervisor:start_child(Sup2, Child3), ?line {ok, CPid4} = supervisor:start_child(Sup2, Child4), + ?line [2,2,0,2] = get_child_counts(Sup1), + ?line [2,2,0,2] = get_child_counts(Sup2), link(Sup1), link(Sup2), @@ -1144,9 +1203,11 @@ tree(Config) when list(Config) -> ?line [{_, CPid2, _, _},{_, CPid1, _, _}] = supervisor:which_children(Sup1), + ?line [2,2,0,2] = get_child_counts(Sup1), ?line [{_, NewCPid4, _, _},{_, CPid3, _, _}] = supervisor:which_children(Sup2), + ?line [2,2,0,2] = get_child_counts(Sup2), link(NewCPid4), @@ -1195,9 +1256,99 @@ tree(Config) when list(Config) -> ?line [{supchild2, NewSup2, _, _},{supchild1, NewSup1, _, _}] = supervisor:which_children(Pid), + ?line [2,2,2,0] = get_child_counts(Pid), ?line [{child2, _, _, _},{child1, _, _, _}] = supervisor:which_children(NewSup1), + ?line [2,2,0,2] = get_child_counts(NewSup1), + ?line [] = supervisor:which_children(NewSup2), + ?line [0,0,0,0] = get_child_counts(NewSup2), ok. +%------------------------------------------------------------------------- +count_children_allocator_test(MemoryState) -> + Allocators = [temp_alloc, eheap_alloc, binary_alloc, ets_alloc, + driver_alloc, sl_alloc, ll_alloc, fix_alloc, std_alloc, + sys_alloc], + MemoryStateList = element(4, MemoryState), + AllocTypes = [lists:keyfind(Alloc, 1, MemoryStateList) + || Alloc <- Allocators], + AllocStates = [lists:keyfind(e, 1, AllocValue) + || {_Type, AllocValue} <- AllocTypes], + lists:all(fun(State) -> State == {e, true} end, AllocStates). + +count_children_memory(doc) -> + ["Test that which_children eats memory, but count_children does not."]; +count_children_memory(suite) -> + MemoryState = erlang:system_info(allocator), + case count_children_allocator_test(MemoryState) of + true -> []; + false -> + {skip, "+Meamin used during test; erlang:memory/1 not available"} + end; +count_children_memory(Config) when is_list(Config) -> + process_flag(trap_exit, true), + Child = {child, {supervisor_1, start_child, []}, temporary, 1000, + worker, []}, + ?line {ok, _Pid} = start({ok, {{simple_one_for_one, 2, 3600}, [Child]}}), + [supervisor:start_child(sup_test, []) || _Ignore <- lists:seq(1,1000)], + + garbage_collect(), + _Size1 = erlang:memory(processes_used), + Children = supervisor:which_children(sup_test), + _Size2 = erlang:memory(processes_used), + ChildCount = get_child_counts(sup_test), + Size3 = erlang:memory(processes_used), + + [supervisor:start_child(sup_test, []) || _Ignore2 <- lists:seq(1,1000)], + + garbage_collect(), + Children2 = supervisor:which_children(sup_test), + Size4 = erlang:memory(processes_used), + ChildCount2 = get_child_counts(sup_test), + Size5 = erlang:memory(processes_used), + + garbage_collect(), + Children3 = supervisor:which_children(sup_test), + Size6 = erlang:memory(processes_used), + ChildCount3 = get_child_counts(sup_test), + Size7 = erlang:memory(processes_used), + + ?line 1000 = length(Children), + ?line [1,1000,0,1000] = ChildCount, + ?line 2000 = length(Children2), + ?line [1,2000,0,2000] = ChildCount2, + ?line Children3 = Children2, + ?line ChildCount3 = ChildCount2, + + %% count_children consumes memory using an accumulator function, + %% but the space can be reclaimed incrementally, whereas + %% which_children generates a return list. + case (Size5 =< Size4) of + true -> ok; + false -> + ?line test_server:fail({count_children, used_more_memory}) + end, + case Size7 =< Size6 of + true -> ok; + false -> + ?line test_server:fail({count_children, used_more_memory}) + end, + + case Size4 > Size3 of + true -> ok; + false -> + ?line test_server:fail({which_children, used_no_memory}) + end, + case Size6 > Size5 of + true -> ok; + false -> + ?line test_server:fail({which_children, used_no_memory}) + end, + + [exit(Pid, kill) || {undefined, Pid, worker, _Modules} <- Children3], + test_server:sleep(100), + ?line [1,0,0,0] = get_child_counts(sup_test), + + ok. diff --git a/lib/stdlib/test/tar_SUITE.erl b/lib/stdlib/test/tar_SUITE.erl index af687ed2e1..7646f4c249 100644 --- a/lib/stdlib/test/tar_SUITE.erl +++ b/lib/stdlib/test/tar_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(tar_SUITE). @@ -183,7 +183,7 @@ atomic(doc) -> "and uncompressed archives." "Also test the 'cooked' option."]; atomic(suite) -> []; -atomic(Config) when list(Config) -> +atomic(Config) when is_list(Config) -> ?line ok = file:set_cwd(?config(priv_dir, Config)), ?line DataFiles = data_files(), ?line Names = [Name || {Name,_,_} <- DataFiles], @@ -369,7 +369,7 @@ try_bad(Name0, Reason, Config) -> case catch erl_tar:format_error(Reason) of {'EXIT', CrashReason} -> test_server:fail({format_error, crashed, CrashReason}); - String when list(String) -> + String when is_list(String) -> io:format("format_error(~p) -> ~s", [Reason, String]); Other -> test_server:fail({format_error, returned, Other}) @@ -413,7 +413,7 @@ try_error(M, F, A, Error) -> case catch erl_tar:format_error(Error) of {'EXIT', FReason} -> test_server:fail({format_error, crashed, FReason}); - String when list(String) -> + String when is_list(String) -> io:format("format_error(~p) -> ~s", [Error, String]); Other -> test_server:fail({format_error, returned, Other}) @@ -431,7 +431,7 @@ remove_prefix(_, Result) -> extract_from_binary(doc) -> "Test extracting a tar archive from a binary."; -extract_from_binary(Config) when list(Config) -> +extract_from_binary(Config) when is_list(Config) -> ?line DataDir = ?config(data_dir, Config), ?line PrivDir = ?config(priv_dir, Config), ?line Long = filename:join(DataDir, "no_fancy_stuff.tar"), diff --git a/lib/stdlib/test/timer_SUITE.erl b/lib/stdlib/test/timer_SUITE.erl index 86d8612b56..5f38c91c64 100644 --- a/lib/stdlib/test/timer_SUITE.erl +++ b/lib/stdlib/test/timer_SUITE.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(timer_SUITE). @@ -271,7 +271,7 @@ collect(N, {E,A,B}, I) -> print_report -> print_report({E,A,B,I}), collect(N,{E,A,B}, I); - {Pid, get_report} when pid(Pid) -> + {Pid, get_report} when is_pid(Pid) -> Pid ! {report, {E, A, B, I}}, collect(N,{E,A,B}, I); reset -> diff --git a/lib/stdlib/test/unicode_SUITE.erl b/lib/stdlib/test/unicode_SUITE.erl index 706445005c..141ac64606 100644 --- a/lib/stdlib/test/unicode_SUITE.erl +++ b/lib/stdlib/test/unicode_SUITE.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% %% -module(unicode_SUITE). @@ -276,7 +276,7 @@ ex_latin1(Config) when is_list(Config) -> unicode:characters_to_list(make_unaligned(MissingLastByte),unicode), ?line DoubleSize16 = byte_size(DoubleUtf16), - ?line DoubleUtf16_2 = erlang:concat_binary([DoubleUtf16,<<16#FFFFF/utf16-big>>]), + ?line DoubleUtf16_2 = list_to_binary([DoubleUtf16,<<16#FFFFF/utf16-big>>]), ?line DoubleSize16_2 = byte_size(DoubleUtf16_2), ?line AllBut1_16 = DoubleSize16 - 1, ?line AllBut2_16_2 = DoubleSize16_2 - 2, @@ -884,15 +884,15 @@ utf8_to_list_bsyntax(<<C/utf8,R/binary>>) -> list_to_utf8_bsyntax(List,unicode) -> FList = flatx(List), - erlang:concat_binary([ if - is_binary(E) -> - E; - true -> - <<E/utf8>> - end || E <- FList ]); + list_to_binary([ if + is_binary(E) -> + E; + true -> + <<E/utf8>> + end || E <- FList ]); list_to_utf8_bsyntax(List,latin1) -> FList = flatb(List), - erlang:concat_binary([ <<E/utf8>> || E <- FList ]). + list_to_binary([ <<E/utf8>> || E <- FList ]). @@ -954,15 +954,15 @@ utf16_big_to_list_bsyntax(<<C/utf16-big,R/binary>>) -> list_to_utf16_big_bsyntax(List,{utf16,big}) -> FList = flatx(List), - erlang:concat_binary([ if - is_binary(E) -> - E; - true -> - <<E/utf16-big>> - end || E <- FList ]); + list_to_binary([ if + is_binary(E) -> + E; + true -> + <<E/utf16-big>> + end || E <- FList ]); list_to_utf16_big_bsyntax(List,latin1) -> FList = flatb(List), - erlang:concat_binary([ <<E/utf16-big>> || E <- FList ]). + list_to_binary([ <<E/utf16-big>> || E <- FList ]). utf16_little_to_list_bsyntax(<<>>) -> @@ -972,15 +972,15 @@ utf16_little_to_list_bsyntax(<<C/utf16-little,R/binary>>) -> list_to_utf16_little_bsyntax(List,{utf16,little}) -> FList = flatx(List), - erlang:concat_binary([ if - is_binary(E) -> - E; - true -> - <<E/utf16-little>> - end || E <- FList ]); + list_to_binary([ if + is_binary(E) -> + E; + true -> + <<E/utf16-little>> + end || E <- FList ]); list_to_utf16_little_bsyntax(List,latin1) -> FList = flatb(List), - erlang:concat_binary([ <<E/utf16-little>> || E <- FList ]). + list_to_binary([ <<E/utf16-little>> || E <- FList ]). @@ -991,15 +991,15 @@ utf32_big_to_list_bsyntax(<<C/utf32-big,R/binary>>) -> list_to_utf32_big_bsyntax(List,{utf32,big}) -> FList = flatx(List), - erlang:concat_binary([ if - is_binary(E) -> - E; - true -> - <<E/utf32-big>> - end || E <- FList ]); + list_to_binary([ if + is_binary(E) -> + E; + true -> + <<E/utf32-big>> + end || E <- FList ]); list_to_utf32_big_bsyntax(List,latin1) -> FList = flatb(List), - erlang:concat_binary([ <<E/utf32-big>> || E <- FList ]). + list_to_binary([ <<E/utf32-big>> || E <- FList ]). utf32_little_to_list_bsyntax(<<>>) -> @@ -1009,15 +1009,15 @@ utf32_little_to_list_bsyntax(<<C/utf32-little,R/binary>>) -> list_to_utf32_little_bsyntax(List,{utf32,little}) -> FList = flatx(List), - erlang:concat_binary([ if - is_binary(E) -> - E; - true -> - <<E/utf32-little>> - end || E <- FList ]); + list_to_binary([ if + is_binary(E) -> + E; + true -> + <<E/utf32-little>> + end || E <- FList ]); list_to_utf32_little_bsyntax(List,latin1) -> FList = flatb(List), - erlang:concat_binary([ <<E/utf32-little>> || E <- FList ]). + list_to_binary([ <<E/utf32-little>> || E <- FList ]). diff --git a/lib/stdlib/test/win32reg_SUITE.erl b/lib/stdlib/test/win32reg_SUITE.erl index 3ad58eba03..c8cc82f61e 100644 --- a/lib/stdlib/test/win32reg_SUITE.erl +++ b/lib/stdlib/test/win32reg_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(win32reg_SUITE). @@ -37,7 +37,7 @@ fini(Config) when is_list(Config) -> Config. long(doc) -> "Test long keys and entries (OTP-3446)."; -long(Config) when list(Config) -> +long(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(10)), ?line LongKey = "software\\" ++ @@ -61,7 +61,7 @@ long(Config) when list(Config) -> ?line test_server:timetrap_cancel(Dog), ok. -evil_write(Config) when list(Config) -> +evil_write(Config) when is_list(Config) -> ?line Dog = test_server:timetrap(test_server:seconds(10)), ?line Key = "Software\\Ericsson\\Erlang", diff --git a/lib/stdlib/test/zip_SUITE.erl b/lib/stdlib/test/zip_SUITE.erl index 55cbd277ef..12ca655000 100644 --- a/lib/stdlib/test/zip_SUITE.erl +++ b/lib/stdlib/test/zip_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2006-2009. All Rights Reserved. -%% +%% +%% 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 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(zip_SUITE). @@ -181,7 +181,7 @@ atomic(doc) -> ["Test the 'atomic' operations: zip/unzip/list_dir, on archives." "Also test the 'cooked' option."]; atomic(suite) -> []; -atomic(Config) when list(Config) -> +atomic(Config) when is_list(Config) -> ok = file:set_cwd(?config(priv_dir, Config)), DataFiles = data_files(), Names = [Name || {Name,_,_} <- DataFiles], @@ -209,7 +209,7 @@ openzip_api(doc) -> ["Test the openzip_open/2, openzip_get/1, openzip_get/2, openzip_close/1 " "and openzip_list_dir/1 functions."]; openzip_api(suite) -> []; -openzip_api(Config) when list(Config) -> +openzip_api(Config) when is_list(Config) -> ok = file:set_cwd(?config(priv_dir, Config)), DataFiles = data_files(), Names = [Name || {Name, _, _} <- DataFiles], @@ -248,7 +248,7 @@ zip_api(doc) -> ["Test the zip_open/2, zip_get/1, zip_get/2, zip_close/1 " "and zip_list_dir/1 functions."]; zip_api(suite) -> []; -zip_api(Config) when list(Config) -> +zip_api(Config) when is_list(Config) -> ok = file:set_cwd(?config(priv_dir, Config)), DataFiles = data_files(), Names = [Name || {Name, _, _} <- DataFiles], @@ -550,7 +550,7 @@ aliases(Config) when is_list(Config) -> unzip_from_binary(doc) -> ["Test extracting a zip archive from a binary."]; -unzip_from_binary(Config) when list(Config) -> +unzip_from_binary(Config) when is_list(Config) -> DataDir = ?config(data_dir, Config), PrivDir = ?config(priv_dir, Config), ExtractDir = filename:join(PrivDir, "extract_from_binary"), @@ -626,7 +626,7 @@ delete_all_in(Dir) -> compress_control(doc) -> ["Test control of which files that should be compressed"]; compress_control(suite) -> []; -compress_control(Config) when list(Config) -> +compress_control(Config) when is_list(Config) -> ok = file:set_cwd(?config(priv_dir, Config)), Dir = "compress_control", Files = [ |