Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PMC's and setting flags

15 views
Skip to first unread message

Clinton A. Pierce

unread,
May 5, 2003, 3:46:53 PM5/5/03
to 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

unread,
May 5, 2003, 4:24:30 PM5/5/03
to 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

unread,
May 5, 2003, 4:37:51 PM5/5/03
to 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

unread,
May 5, 2003, 4:44:24 PM5/5/03
to 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

unread,
May 5, 2003, 4:52:10 PM5/5/03
to 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 new messages