Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PORT! state binary appears empty when it is not #2314

Closed
hostilefork opened this issue Jun 16, 2018 · 6 comments
Closed

PORT! state binary appears empty when it is not #2314

hostilefork opened this issue Jun 16, 2018 · 6 comments

Comments

@hostilefork
Copy link
Member

hostilefork commented Jun 16, 2018

The port state in the following examples contains bytes that are being used by the port, yet appear empty--meaning the bytes won't be copied, and it breaks the invariant of a BINARY! which may trip up in other ways:

>> p: open %test.txt
>> p/state
== #{}

>> p: open http://example.com
>> open p
>> p/state/connection/state
== #{}

The reason this happens is that the binary is created, but the length is never set:

https://github.com/rebol/rebol/blob/25033f897b2bd466068d7663563cd3ff64740b94/src/core/c-port.c#L100

Make_Binary() takes a capacity, but Make_Series() sets the length to 0, regardless of that capacity.

@hostilefork
Copy link
Member Author

This was resolved in Ren-C some time ago, just mentioning it because it came up trying to write up some history-of-ports-in-R3-Alpha document, and it's easier to point to this issue than to go on a tangent about it in that document.

@Oldes
Copy link

Oldes commented Jun 16, 2018

Question is.. if this value should be accessible.. when it is internal private area.

@hostilefork
Copy link
Member Author

hostilefork commented Jun 16, 2018

Question is.. if this value should be accessible.. when it is internal private area.

If you want more opacity, the HANDLE! type was introduced for that. But I'm more interested in turning this binary-representation-of-a-C-struct into a Rebol-structured OBJECT!, for more transparency.

My point about the binary is just that if the length is incorrect, then operations like copying and such won't work...the copy will be empty though the original was not. And of course it confuses people who are working on the "internal implementation" who wonder "huh, I didn't think it was empty, why is it empty?" Or perhaps someone upgrades the GC to reclaim space and it says "oh, the allocation here is bigger than the length, we can shorten that".

@Oldes
Copy link

Oldes commented Jun 16, 2018

The question is, why this line was commented out.

@metaeducation metaeducation deleted a comment from Oldes Jun 16, 2018
@metaeducation metaeducation deleted a comment from Oldes Jun 16, 2018
@Oldes
Copy link

Oldes commented Jun 16, 2018

When someone else will be reading it... the Guard_Series call in the original code was removed by Atronix in this commit: zsx/r3@4d7e521

Oldes added a commit to Oldes/Rebol3 that referenced this issue Jun 16, 2018
fixes: metaeducation/rebol-issues#2314

I believe that the size setting was commented out to hide the state, so I added series protection so it cannot be modified from Rebol layer
@Oldes
Copy link

Oldes commented Jun 16, 2018

In my branch it is now:

>> p: open %sss  
>> p/state      
== #{
000000000300000000000000000000003060AD0A010000000500000000000000
0200000000000000030100001100000000000000000000000000000000000000
0000000030198E8BC17F00000000000000000000000000000000000090D9245B
00000000
}

>> clear p/state 
** Script error: protected value or series - cannot modify
** Where: clear
** Near: clear p/state

Let's see if it breaks something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants