Peter Gibbs wrote:

Leopold Toetsch wrote:

Fine. But how do we know, which version we could take. Please read again
Peter's example. It depends on the semantics of Sx register usage all
over the program IMHO.

In an attempt to clarify the positions here, let us start with a shorter
example:
  set S0, "zero"
  set S1, "one"
  set S0, S1

The first line will create a new string header, which will COW-reference
the constant string data "zero", and store the address of that header
in register S0.
The second line creates another string header, COWing to "one",
and stores its address in register S1.
The third line could do any of the following:
   a) Create a new string header, COW-referencing string "one",
      and store that new address in register S0
   b) Re-use the existing string header created in line 1, changing
      it to point to string "one"; the register does not change
   c) Store the address of the string header created in line 2 into
      string register S0; no headers are affected in any way
The current implementation is (c).
Does anybody believe this should be different?

An extended version of my previous example follows, as it points
out some more inconsistent behaviour.

Printing (with string_set):
not
test
test
not

Thanks for this example:

- PerlStrings set_string does a string_copy
- PerlArray stores a PMC* and does a set_string_native, which converts the PerlUndef to a string and does set_string i.e. string_copy
- PerlHash stores the STRING* pointer of the string.
I have an example too - dunno but doesn't look consistent to me either:

set S0, "test"
new P1, .PerlArray
set P1[0], S0
set S1, "not"
set S0, S1
set S3, P1[0]
print S3
print "\n"

set S0, "test"
new P2, .PerlString
set P2, S0
new P1, .PerlArray
set P1[0], P2
set S1, "not"
set P2, S1
set P3, P1[0]
print P3
print "\n"

set S0, "test"
new P1, .PerlHash
set P1["a"], S0
set S1, "not"
set S0, S1
set S3, P1["a"]
print S3
print "\n"

set S0, "test"
new P2, .PerlString
set P2, S0
new P1, .PerlHash
set P1["a"], P2
set S1, "not"
set P2, S1
set P3, P1["a"]
print P3
print "\n"

end

This prints (string_set is not involved here):
test
not
test
not

So the issue is still, when and how to copy a string, or
set S0, S1
a) b) or c)

leo

Reply via email to