Distinguish C string utilities that return allocated strings from those that don't.

Some utilities that return a c_string return a string that has been freshly allocated off
the heap, while others to not.  To make the interface self-documenting, I created yet
another alias for "const char*" and called it c_string_copy.  To that one, I ascribed the
interpretation that it contains a freshly-allocated C string.  Thus:
```
  c_string foo();
    // Returns a pointer-copy of (i.e. a reference to) a C string owned by another program
    // entity.  The caller of foo() should not free the return value.
  c_string_copy bar();
    // Returns a freshly-allocated C string.  The caller should free the returned C string
    // (or arrange in some other way that it be cleaned up).
```
Since the C compiler treats the type aliases `c_string` and `c_string_copy` as equivalent,
a variable (or return value) of type `c_string_copy` can be supplied to a routine
expecting a `c_string` argument.

### DETAILS
####./runtime/include/chpl-mem.h
Piped the filename and linenumber arguments through, for better memory tracking.

####./runtime/include/chpl-string-support.h
Added the new typedef `c_string_copy` with comments explaining how it differs from c_string.
Updated return value types using `c_string_copy` where the returned string is
heap-allocated and should be managed by the caller.

####./runtime/include/chpl-string.h
Added comments to describe the interface to stringMove().
Updated the return type of remoteStringCopy, to say that it returns a heap-allocated c_string.

####./runtime/include/chplcast.{h,c}
Updated the interfaces to all integral_to_c_string() functions, to say that they return a
heap-allocated c_string result.
Added a comment to warn that this is not true for the boolean_to_c_string() functions.
Added comments to chpl_string_to_c_string and c_string_to_chpl_string, explaining why they
do not leak memory.

####./runtime/include/chplgmp.{h,c}
Changed the return type of chpl_gmp_mpz_get_str() to say that it returns a heap-allocated
c_string.

####./runtime/include/chplsys.{h,c}
Changed the return type of chpl_nodeName() to say that it returns a heap-allocated
c_string.

####./runtime/include/qio/qio_formatted.{h,c}
Changed the return type of qio_encode_to_string() to say that it returns a heap-allocated
c_string.

####./runtime/src/chpl-string-support.c
Changed the return type of chpl_format(), string_copy(), string_concat(), string_select()
and string_index() to say that they return a heap-allocated c_string.
Updated string_index to ensure that the returned c_string_copy can always be safely
deallocated.

####./runtime/src/chpl-string.c
Added comments about the semantics of stringMove().
Changed the return type of remoteStringCopy() to say that it returns a heap-allocated
c_string.

####./runtime/src/config.c
Added a comment about chpl_config_get_value() being inherently thread-safe.
Add new type c_string_copy to track owned c_strings.

Formerly, c_string was used to represent low-level C strings without regard to whether
they behave like fully-constructed (owned) objects or like references (unowned).  To
simplify the task of tracking allocations across the runtime/module interface, I added the
new type c_string_copy.

Now, c_string is used to represent unowned strings and c_string_copy is used to represent
owned strings.  To prevent memory leaks, an owned string should be freed before it goes
out of scope (or its ownership transferred to another program entity).  An unowned string
should not be feed.

When a c_string is used to initialize an object (such as a chpl_string)
that is expected to own its data, it must be copied into that object.  When a
c_string_copy is used to initialize such an object, a pointer copy will suffice.
Ownership of the c_string_copy is then transferred to the new object.

Note that a c_string_copy can be coerced to a c_string without breaking this ownership
invariant.  Ownership is retained by the original (c_string_copy) and not by the duplicate
(c_string).  This seems a good place to justify the naming: A c_string_copy is produced by
passing a c_string to the function string_copy().

[This version compiles and runs hello.chpl]

###DETAILS

####compiler/AST/expr.cpp
Moved all of the conversions between chpl_string, c_string and various fundamental types
from the PRIM_CAST clause of CallExpr::codegen() out to module code.
TODO: A PRIM_CAST returning an owned object should probably allocate that object.  This is
not a problem for fundamental types, but is probably a problem for c_string_copy,
chpl_string and records.  (Record casts are handled by compiler-generated cast functions
unless overridden.)

####compiler/AST/primitive.cpp
Added the new type info functions returnInfoStringCopy, and used this to inform the
compiler that the primitives
  string_concat
  string_index
  string_copy
  string_select
return c_string_copy objects.

####compiler/include/symbol.h
####compiler/AST/symbol.cpp
Added the new global initializer symbol gStringCopy.

####compiler/include/type.h
####compiler/AST/type.cpp
Added the new internal type dtStringCopy.
Added some comments suggesting future revisions.

####compiler/passes/resolveIntents.cpp
Added dtStringCopy to the list of types whose blank intent is equivalent to "const in".

####compiler/resolution/functionResolution.cpp
Added a coercion from c_string_copy to c_string.

####modules/internal/ChapelIO.chpl
Changed the return type of chpl_format() to c_string_copy.  These functions always
returned an owned c_string, and now we advertise that in the interface.

####modules/internal/String.chpl
Added an overload for toString() that takes a c_string_copy operand.  The new version
assumes ownership of the passed-in c_string_copy.  There were notations in the code that
we could use a non-allocating form of toString().  Now that task is accomplished.
Added the non-allocating versions of toString() -- taking a c_string_copy and returning a
chpl_string.
Added the c_string_copy to c_string cast used by the added coercion.

Removed the workaround for the string allocation bug in casts between c_strings and
chpl_string fixed before release, and replaced it with code that should not leak.
Some of the casts from fundamental types (e.g. enums and bools) to c_string yielded
an unowned c_string, while others yielded an owned c_string (i.e. a c_string_copy).  The
c_string cases had to be handled special w.r.t. the call to chpl_free_c_string().  Now,
copies are made of the c_string results, while the c_string_copy results are just usurped
buy the resulting chpl_string.

Added back the casts that used to be implemented by PRIM_CAST:
* bool to c_string
* integral to c_string_copy
* real to c_string_copy
* imag to c_string_copy

Revised c_string.substring() to always return a c_string_copy.  The ownership state of the
returned value used to be ambiguous, because if the range was empty it would return a
reference to a literal empty string (a c_string).

####modules/standard/GMP.chpl
chpl_gmp_mpz_get_str() now returns a c_string_copy.

####modules/standard/IO.chpl
qio_encode_to_string() now returns a c_string_copy.
The cast of an ioChar to a c_string now returns a c_string_copy.

####modules/standard/NewString.chpl
remoteStringCopy now returns a c_string_copy.

####runtime/include/chpl-string.h
Added string_from_c_string_copy() and wide_string_from_c_string_copy() to create a string
from a c_string_copy without allocating new memory.  Ownership of the c_string_copy
argument is transferred to the new string.

####runtime/include/chplcast.h
####runtime/src/chplcast.c
Replaced the individual int type to c_string functions with integral_to_c_string_copy().
Replaced the real and imag type to c_string functions with real_to_c_string_copy().

####runtime/include/chplsys.h
chpl_nodeName() actually returns a shared, statically-allocated string, so I changed its
return type to c_string from c_string_copy.

####runtime/src/chpl-string-support.c
Reworked string_select so it always returns a newly-allocated c_string_copy or NULL.

####runtime/src/chpl-string.c
Added string_from_c_string_copy().  This function steals the data owned by the passed-in
c_string_copy, so it creates a string from a c_string_copy without requiring a new
allocation and copy.  This is is used to implement the "non-allocating toString" mentioned
in several TODOs by Sung (which also allowed me to resolve those TODOs).

Added wide_string_from_c_string_copy(), which is the wide version of the above.

Reworked stringMove() so it always reuses the buffer provided.  The use of a zero-length
string to represent an empty c_string_copy is deprecated in favor of a null pointer.

####runtime/src/chplsys.c
Reworked chpl_nodeName() so it always returns an unowned c_string.
The thread safety of returning a shared object implies that it should be initialized only
once (pre node).  Although I don't guarantee that, it's pretty likely.
Using the assumption that the node name does not change in the course of execution of a
program, I moved the initialization inside the namespace==NULL test, so (in the absence of
races) it is, in fact, initialized only once.
If the node name is expected to change during a run, this routine would have to be
reworked using unshared data, and return a c_string_copy.
Add some missing casts to and from c_strings.

Removal from codegen of the conversion from c_strings to fundamental types means that they
had to be added as explicit casts in Strings.chpl.

This version passes all primers tests (local only).

###DETAILS

####/compiler/AST/primitive.cpp
The "string_copy" primitive actually returns a c_string_copy.

####/modules/internal/ChapelIO.chpl
Reworked StringWriter, so its state data is a c_string_copy, not a c_string.  This allows
us to make the calls to chpl_free_c_string() unconditional.

####/modules/internal/String.chpl
The cast to string type now also works if the source type is a c_string or a
c_string_copy, so I was able to remove the "x.type != c_string" exclusion.

I removed the "cast a string to types other than c_string, and enumerated the types to
which a string can be cast.

The casts from c_string to primitive types formerly performed in the codegen for PRIM_CAST
are now enumerated explicitly in module code.

The cast from complex to c_string_copy did not make it into the previous commit, so that
support is added here.

I needed to provide an implementation for _defaultOf(c_string_copy).  It returns a
_nullString, which is effectively "(const char*) NULL".

I needed to provide definitions of assignment from c_string to c_string_copy and
c_string_copy to c_string_copy.

I needed to supply a cast from a chpl_string to a c_string_copy.  This creates a
newly-allocated copy.

I needed to provide a cast from boolean types to c_string_copy.

I had to supply a return type for the real_to_c_string_copy() extern prototype.

####/modules/standard/IO.chpl
I needed to add a cast from ioNewline and ioLiteral to c_string_copy.

####/runtime/include/chplcast.h
####/runtime/src/chplcast.c
Removed the older implementation of the integral_to_c_string and real_to_c_string functions.
Adjusted indentation in real_to_c_string_copy().
Some tweaks after first paratest run.

Now the result of a cast of any type to a string-ish thing is c_string_copy.  Adjusted the
memory management in that routine and also in string.write and c_string.write routines.

Made the coercion cast from c_string_copy to c_string return the right type.
Added a writeThis() method for c_string_copy.

Down to 401 failures (std).
Further tweaks.

Added a string-to-enum cast.
Now use the "insert line file info" pragma to pass line number information to the c_string
to integer, c_string to real and c_string to complex conversions.
Removed the redundant (and incorrect) cast from imag to c_string.

Empty c_string_copies are now represented by a null pointer, so I fixed two places that
used the old "" value instead.

Failure count is now down to 90 (std),
Continued tweaks from standard testing.

Disable redundant cast from c_string to string in ChapelBase.
Add explicit cast from enumerated to c_string_copy.
Add explicit casts from real, imag and complex to c_string, to support tests in
types/string/sungeun/c_string.  These should be deprecated and removed ASAP.
Add an explicit cast to c_string in c_string_copy.write(), to avoid infinite recursion.
Add null tests in the runtime support routines, since an empty c_string_copy can be a null pointer.
Rewrite string_concat() so it handles null input strings efficiently.
Revised the comment on c_string_from_wide_string, to indicate that an empty string is
represented by null, not "" (now that it returns a c_string_copy).

Down to 90 failures.
Work in progress.

The changes in this commit at one point got the error count down to about 40, but then
further changes introduced double deletion errors so that nearly every test fails.  Branch
from the previous commit and cherry-pick from this branch to duplicate that.
Further debugging of test results.

In Error.chpl, use cast-to-c_string_copy, to force conversion of offset using integer
formatting.
Made qio_channel_read_string() and qio_channel_scan_string() write their results into a
c_string_copy, to show that these results are newly allocated.
Changed signature of stringMove, so that dest is typed as a c_string_copy.  It now
allocates memory if the input dest pointer is NULL.
As a workaround, changed all "beer" test programs to use a c_string_copy cast on bottleNum
(because the string cast does not work).
Changed test/types/string/sungeun/c_string/substr.chpl to report that substr on a c_string
returns a c_string_copy, while substr on a string returns a string.

Now down to 12 failures, all in NewString.chpl.
A few tweaks to get tests in StringImpl to work.

Added concatenation operators taking a c_string_copy as one argument, so that internal
casts produce a c_string_copy that is then stolen.

The concatenation helper routines now use a c_string_copy, but leak memory somewhere.

Casts from other types to string_rec now go through the c_string_copy version, and the
output of this is stolen.  Note that special handling of Enum and Bool and ioLiteral and
ioEndOfLine and other literal strings is avoided.

Added a workaround to stringMove, to also allocate a new string if the input string is the
empty string.  This might leak memory in general, but the way it is used in NewString
currently does not cause this problem.
Changes in the new string implementation, to eliminate memory leaks.

In versions of proc +() taking a c_string_copy operand, it was necessary to delete (the
representation owned by) that operand.  This is consistent with the rule that the
recipient of a c_string_copy argument is expected to take ownership of it.

Changed string_select() and string_index() to return a NULL to represent an empty string.
The current string_rec implementation will not delete a string of zero length (without
extensive rework), so a NULL is returned instead to avoid leaks.  It does not matter
whether the NULL is reference-counted and deleted or never deleted, so regardless how
string_rec handles this return value, the memory management part comes out right.

TODO: Clients of c_str() should perform a NULL test before attempting to evaluate it as a
string literal.  Either the documentation for c_str should state this clearly, or c_str() be
changed to return a literal "" if the underlying representation is NULL.

stringMove() was modified, so it can accept a NULL input string and will return a NULL in
that case.
Back explicit cast to c_string_copy out of beer programs.

The beer programs were failing because the return type of describeBottles is established
by the cast of bottleNum to "string" in the "then" clause, but (because of the
concatenations) the type of the else clause is c_string_copy and the compiler finds no way
to promote a value of this type to match the "string" type of the "then" clause.

The solution was to add a clause for the c_string_copy --> string coercion in the
canCoerce() function in the compiler.  This allowed me to put back all the "beer" programs
as they were.
Add the c_string.txt technote to publish the pertinent design ideas.
Recode some IO routines to avoid double-free errors.

In some places, used c_string_copy in place of c_string to show that a variable has
ownership of that temp string.

We still leak in string concatenation.  Intermediate c_string_copy results must be
captured so they can later be freed.  Or better yet, if concatenation is overloaded to
accept one or two c_string_copy args, those can be freed by concatenation itself.

"this.s = _nullString;" does not do what you would expect, since it calls assignment.  I
replaced some of these with __primitive("=", this.s, _nullString); to prevent double frees
in some cases.

In the cast to complex, I made "im" be always a c_string_copy to simplify memory tracking.

In Regexp.chpl, removed some TODOs to use a toString() that does not allocate space.  We
do that now.
Fix revised c_strings to pass no-local testing.

###DETAILS
####modules/internal/ChapelIO.chpl
Must use primitive to set freed string pointer to null.

####modules/internal/String.chpl
Removed TODO: Operand type of chpl_rt_free_c_string is now c_string_copy, as required.

####modules/standard/NewString.chpl
Added workaround implementation of free_baseType().
Workaround is needed because baseType is c_string and not c_string_copy.
The latter is technically correct, because that field actually owns the string data it
points to.

####runtime/src/chpl-string.c
Changed chpl_string_widen() to accommodate a NULL input pointer.
Merge branch 'master' into fixCStringsB

Conflicts:
	modules/standard/IO.chpl
Merge pull request #601 from hildeth/fixCStringsB

Add c_string_copy type to support low-level string memory management.

This change removes the workaround (9cd7020) that was added to avoid the GCC error reporting an attempt to free statically-allocated memory. The workaround caused memory leakage across all tests to jump from 1.19Gb to 1.22Gb. This change returns memory leakage to the earlier level.

The main change involves splitting the low-level string representation type c_string into two types:

c_string to represent "un-owned" character strings (such as string literals); and
c_string_copy to represent "owned" character strings (i.e. heap-allocated copies). The low-level and Chapel string implementation code can then use this distinction to manage memory with greater precision. Refer to the new technote c_string.txt (included in this PR) for details.
An additional change was to move some of the casts between strings (in their various forms) and fundamental types out of codegen and into module code. This change was motivated by the prospect of having to add lots of cases to codegen to handle the new c_string_copy type I was adding. It was way easier to do this in module code. Once I started down this path, I also discovered that Chapel's ability to resolve overloaded argument types made the job of writing the equivalent module code much easier.

Because Chapel does not yet support the definition of coercions at the source level, the compiler had to be modified to support two new coercions:

c_string --> c_string_copy
c_string_copy --> string Adding them to the compiler was simple: we just needed two new clauses in canCoerce(). While there, I cleaned up special tests to prevent a symbol that is not a variable or an argument from c_string to string. Test results on this change are still pending.
TODOS:

For this first cut, I left the baseType of both string and string_rec as c_string. Technically, these should both be c_string_copy.