Skip to content

Commit

Permalink
Stop destroying of invalid instances from crashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafl committed Nov 17, 2009
1 parent 8341b06 commit 7964e74
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Extractor.xs
Expand Up @@ -36,7 +36,7 @@ EXTRACTOR_loadConfigLibraries (prev, config)
const char *config
POSTCALL:
if (prev) {
perl_extractor_invalidate_object (ST(0));
perl_extractor_invalidate_object (ST (0));
}

EXTRACTOR_ExtractorList *
Expand All @@ -45,7 +45,7 @@ EXTRACTOR_addLibrary (prev, library)
const char *library
POSTCALL:
if (prev) {
perl_extractor_invalidate_object (ST(0));
perl_extractor_invalidate_object (ST (0));
}

EXTRACTOR_ExtractorList *
Expand All @@ -54,15 +54,15 @@ EXTRACTOR_addLibraryLast (prev, library)
const char *library
POSTCALL:
if (prev) {
perl_extractor_invalidate_object (ST(0));
perl_extractor_invalidate_object (ST (0));
}

EXTRACTOR_ExtractorList *
EXTRACTOR_removeLibrary (prev, library)
EXTRACTOR_ExtractorList *prev
const char *library
POSTCALL:
perl_extractor_invalidate_object (ST(0));
perl_extractor_invalidate_object (ST (0));

void
EXTRACTOR_getKeywords (extractor, data)
Expand Down Expand Up @@ -98,7 +98,7 @@ EXTRACTOR_getKeywords (extractor, data)

void
DESTROY (libraries)
EXTRACTOR_ExtractorList *libraries = perl_extractor_object_is_invalid($arg) ? NULL : ($type)perl_extractor_get_ptr_from_sv ($arg, "File::Extractor");
EXTRACTOR_ExtractorList *libraries = perl_extractor_object_is_invalid ($arg) ? NULL : ($type)perl_extractor_get_ptr_from_sv ($arg, "File::Extractor");
CODE:
if (libraries) {
EXTRACTOR_removeAll (libraries);
Expand Down
3 changes: 2 additions & 1 deletion Makefile.PL
Expand Up @@ -8,7 +8,8 @@ use inc::Module::Install;
name 'File-Extractor';
all_from 'lib/File/Extractor.pm';

build_requires 'ExtUtils::PkgConfig' => 0;
configure_requires 'ExtUtils::PkgConfig';

build_requires 'IO::File' => 0;
build_requires 'Test::Exception' => 0;
build_requires 'Test::More' => 0;
Expand Down
10 changes: 8 additions & 2 deletions perl_extractor.c
Expand Up @@ -71,7 +71,7 @@ perl_extractor_invalidate_object (SV *obj) {
HV *hv;

hv = (HV *)SvRV (obj);
if (!hv_store (hv, "invalidated", 11, &PL_sv_yes, 0)) {
if (!hv_stores (hv, PERL_EXTRACTOR_INVALIDED, &PL_sv_yes)) {
croak ("failed to store invalidation flag");
}
}
Expand All @@ -81,8 +81,14 @@ perl_extractor_object_is_invalid (SV *obj) {
HV *hv;
SV **val;

if (!obj || !SvOK (obj) || !SvROK (obj)
|| SvTYPE (SvRV (obj)) != SVt_PVHV
|| !mg_find (SvRV (obj), PERL_MAGIC_ext)) {
croak ("invalid object");
}

hv = (HV *)SvRV (obj);
val = hv_fetch(hv, "invalidated", 11, 0);
val = hv_fetchs (hv, PERL_EXTRACTOR_INVALIDED, 0);

if (!val || !*val) {
return 0;
Expand Down
2 changes: 2 additions & 0 deletions perl_extractor.h
Expand Up @@ -15,6 +15,8 @@

#define EXTRACTOR_ExtractorList_or_null EXTRACTOR_ExtractorList

#define PERL_EXTRACTOR_INVALIDED "invalidated"

START_EXTERN_C

SV *perl_extractor_new_sv_from_ptr (void *ptr, const char *class);
Expand Down

0 comments on commit 7964e74

Please sign in to comment.