Google Ryhmät ei enää tue uusia Usenet-postauksia tai ‐tilauksia. Aiempi sisältö on edelleen nähtävissä.

PMC's and setting flags

6 katselukertaa
Siirry ensimmäiseen lukemattomaan viestiin

Clinton A. Pierce

lukematon,
5.5.2003 klo 15.46.535.5.2003
vastaanottaja perl6-i...@perl.org
I've got an UnManagedStruct PMC doing some very basic stuff now. If I set it:

new P0, .UnManagedStruct
set P0, 512

I get memory allocated for SELF->data just peachy. My question is, I need
to set a flag based on whether the memory management of SELF->data is mine
(because I set it and created my own UnManagedStruct data area) or someone
else's (because ->invoke on an external subroutine gave me a buffer pointer
which was put into an UnManagedStruct).

Where's an appopriate place to put the flag? Can you suggest an example?


Dan Sugalski

lukematon,
5.5.2003 klo 16.24.305.5.2003
vastaanottaja Clinton A. Pierce, perl6-i...@perl.org
At 3:46 PM -0400 5/5/03, Clinton A. Pierce wrote:
>I've got an UnManagedStruct PMC doing some very basic stuff now. If I set it:
>
> new P0, .UnManagedStruct
> set P0, 512
>
>I get memory allocated for SELF->data just peachy. My question is,
>I need to set a flag based on whether the memory management of
>SELF->data is mine (because I set it and created my own
>UnManagedStruct data area) or someone else's (because ->invoke on an
>external subroutine gave me a buffer pointer which was put into an
>UnManagedStruct).

I presume you want the data pointer ignored by the DOD sweep, right?
(Since this is a PMC, the data won't get compacted) That's the
default, unless PObj_is_PMC_ptr_FLAG, PObj_is_buffer_ptr_FLAG, or
PObj_custom_mark_FLAG is set.
--
Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

Clinton A. Pierce

lukematon,
5.5.2003 klo 16.37.515.5.2003
vastaanottaja Dan Sugalski, perl6-i...@perl.org
At 04:24 PM 5/5/2003 -0400, Dan Sugalski wrote:
>At 3:46 PM -0400 5/5/03, Clinton A. Pierce wrote:
>>I've got an UnManagedStruct PMC doing some very basic stuff now. If I
>>set it:
>>
>> new P0, .UnManagedStruct
>> set P0, 512
>>
>>I get memory allocated for SELF->data just peachy. My question is, I
>>need to set a flag based on whether the memory management of SELF->data
>>is mine (because I set it and created my own UnManagedStruct data area)
>>or someone else's (because ->invoke on an external subroutine gave me a
>>buffer pointer which was put into an UnManagedStruct).
>
>I presume you want the data pointer ignored by the DOD sweep, right?
>(Since this is a PMC, the data won't get compacted) That's the default,
>unless PObj_is_PMC_ptr_FLAG, PObj_is_buffer_ptr_FLAG, or
>PObj_custom_mark_FLAG is set.

Correct, becuase something external may have a pointer to this memory and I
wouldn't want to trip it up.

I noticed references to user-defined flags in vtables.pod in the "What you
can do and cannot do" section, but I've been unable to find any examples of
this kind of flag. Is this just:

if (SELF->obj->flags & Pobj_private0_FLAG) {
...
}

And using this enum example inside of the class definition makes pmc2c.pl
silently unhappy.


Simon Glover

lukematon,
5.5.2003 klo 16.44.245.5.2003
vastaanottaja Clinton A. Pierce, Dan Sugalski, perl6-i...@perl.org

The flags are defined in pobj.h, along with a bunch of accessor macros
(which use should probably use in preference to fiddling with the flags
directly).

Simon


Dan Sugalski

lukematon,
5.5.2003 klo 16.52.105.5.2003
vastaanottaja Clinton A. Pierce, perl6-i...@perl.org
At 4:37 PM -0400 5/5/03, Clinton A. Pierce wrote:
>At 04:24 PM 5/5/2003 -0400, Dan Sugalski wrote:
>>At 3:46 PM -0400 5/5/03, Clinton A. Pierce wrote:
>>>I've got an UnManagedStruct PMC doing some very basic stuff now.
>>>If I set it:
>>>
>>> new P0, .UnManagedStruct
>>> set P0, 512
>>>
>>>I get memory allocated for SELF->data just peachy. My question
>>>is, I need to set a flag based on whether the memory management of
>>>SELF->data is mine (because I set it and created my own
>>>UnManagedStruct data area) or someone else's (because ->invoke on
>>>an external subroutine gave me a buffer pointer which was put into
>>>an UnManagedStruct).
>>
>>I presume you want the data pointer ignored by the DOD sweep,
>>right? (Since this is a PMC, the data won't get compacted) That's
>>the default, unless PObj_is_PMC_ptr_FLAG, PObj_is_buffer_ptr_FLAG,
>>or PObj_custom_mark_FLAG is set.
>
>Correct, becuase something external may have a pointer to this
>memory and I wouldn't want to trip it up.

Then don't set the flags and you should be OK.

FWIW, I'm halfway (okay, maybe a thirdway) through some basic string
ops--allocating new strings, changing encodings, setting lengths, and
pinning/unpinning their memory.

>I noticed references to user-defined flags in vtables.pod in the
>"What you can do and cannot do" section, but I've been unable to
>find any examples of this kind of flag. Is this just:
>
> if (SELF->obj->flags & Pobj_private0_FLAG) {
> ...
> }

That second -> should be a ., IIRC: SELF->obj.flags. flags is an
element of the obj struct that's in the PMC that SELF points to.

0 uutta viestiä