Skip to content

Allow to overwrite the Constant Pool#137

Merged
m3m0r7 merged 5 commits into
string/internfrom
allow-to-overwrite-the-constantpool
May 9, 2019
Merged

Allow to overwrite the Constant Pool#137
m3m0r7 merged 5 commits into
string/internfrom
allow-to-overwrite-the-constantpool

Conversation

@m3m0r7
Copy link
Copy Markdown
Member

@m3m0r7 m3m0r7 commented May 8, 2019

No description provided.

@m3m0r7 m3m0r7 changed the base branch from master to string/intern May 8, 2019 04:38
@m3m0r7
Copy link
Copy Markdown
Member Author

m3m0r7 commented May 8, 2019

🤔

@m3m0r7
Copy link
Copy Markdown
Member Author

m3m0r7 commented May 8, 2019

@chitoku-k
Can you review this PR?

Comment thread src/Packages/java/lang/_String.php Outdated
Comment thread src/Packages/java/lang/_String.php Outdated
Comment thread src/Packages/java/lang/_String.php Outdated
->enableWrite(true)
->setString((string) $this->object)
->setStringObject($this)
->enableWrite(false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this set $this->object to a different instance (the one from the constant pool)?

Copy link
Copy Markdown
Member Author

@m3m0r7 m3m0r7 May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chitoku-k
Because $this->object may be a string (on PHP type) or an other object.
$this->object allows being a dynamic generated object, not just a reference to the Constant Pool.

For the above reasons, if the code substitutes a value to $this->object, the $this->object ensures the Constant Pool entry string data. (In this case, it ensures a _Utf8 structure.)

Herewith, if operand stack is stacking _String object, but operations can be proceeded correctly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your answer but it still does not seem to answer my question, in other words, why does it need to set it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, it turned out that $this->object must be equal to the instance already existing in the constant pool because any later comparison might not be guaranteed to treat them equal (such as if_a operation). Although it somewhat looks like String#intern() is affected by the internal object in the constant pool, this implementation is actually derived from the restriction of the way _Utf8 and _String relate to each other.

Comment thread src/Kernel/Structures/_Utf8.php
@m3m0r7
Copy link
Copy Markdown
Member Author

m3m0r7 commented May 9, 2019

Okay, I merge this PR.

@m3m0r7 m3m0r7 merged commit 2892724 into string/intern May 9, 2019
@m3m0r7 m3m0r7 deleted the allow-to-overwrite-the-constantpool branch May 9, 2019 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants