Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add P5SV as a base class for P5 data
This includes reference count logic; eventually will be much more.
- Loading branch information
Showing
7 changed files
with
105 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright (C) 2009-2010, Jonathan Worthington and friends | ||
$Id$ | ||
|
||
=head1 NAME | ||
|
||
src/pmc/p5sv.pmc - common base class for Perl 5 objects | ||
|
||
=head1 DESCRIPTION | ||
|
||
These are the vtable functions for the P5SV class. | ||
|
||
=cut | ||
|
||
*/ | ||
|
||
/* Various Perl 5 headers that we need. */ | ||
#undef __attribute__ | ||
#undef __attribute__noreturn__ | ||
#undef __attribute__deprecated__ | ||
#undef __attribute__pure__ | ||
#undef __attribute__format__ | ||
#undef __attribute__nonnull__ | ||
#undef __attribute__warn_unused_result__ | ||
#undef __attribute__unused__ | ||
#define __attribute__(x) /* */ | ||
#include <EXTERN.h> | ||
#include <perl.h> | ||
|
||
/* Plus need to know about the interpreter PMC. */ | ||
#include "pmc_p5interpreter.h" | ||
|
||
pmclass P5SV group blizkost_group dynpmc { | ||
ATTR PMC *p5i; | ||
ATTR struct sv *sv; | ||
|
||
/* | ||
|
||
=item C<void init()> | ||
|
||
Set up P5SV PMC. | ||
|
||
=cut | ||
|
||
*/ | ||
|
||
VTABLE void init() { | ||
/* Set up the underlying structure. */ | ||
PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_P5SV_attributes); | ||
PObj_custom_mark_SET(SELF); | ||
PObj_custom_destroy_SET(SELF); | ||
} | ||
|
||
/* | ||
|
||
=item C<void mark()> | ||
|
||
Mark GC-ables. | ||
|
||
=cut | ||
|
||
*/ | ||
VTABLE void mark() { | ||
if (PMC_data(SELF)) { | ||
PMC *p5i; | ||
GETATTR_P5Scalar_p5i(interp, SELF, p5i); | ||
if (p5i) | ||
Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i); | ||
} | ||
} | ||
|
||
|
||
/* | ||
|
||
=item C<void destroy()> | ||
|
||
Decrement reference count of held SV. | ||
|
||
=cut | ||
|
||
*/ | ||
VTABLE void destroy() { | ||
if (PMC_data(SELF)) { | ||
PMC *p5i; | ||
PerlInterpreter *my_perl; | ||
struct sv *sv; | ||
GETATTR_P5SV_p5i(interp, SELF, p5i); | ||
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl); | ||
GETATTR_P5SV_sv(interp, SELF, sv); | ||
SvREFCNT_dec(sv); | ||
mem_sys_free(PMC_data(SELF)); | ||
PMC_data(SELF) = NULL; | ||
} | ||
} | ||
|
||
} |