libextractor-perl

GNU libextractor
Log | Files | Refs | README

pextract.c (1626B)


      1 #include "pextract.h"
      2 
      3 void
      4  _pextractor_call_XS(pTHX_ void (*subaddr) (pTHX_ CV*), CV* cv, SV** mark) {
      5 	 dSP;
      6 	 PUSHMARK(mark);
      7 	 (*subaddr)(aTHX_ cv);
      8 	 PUTBACK;
      9  }
     10 
     11 SV*
     12 pextract_new_object(void* object, const char* package) {
     13 	SV* obj;
     14 	SV* sv;
     15 	HV* stash;
     16 
     17 	if (!object) {
     18 		return &PL_sv_undef;
     19 	}
     20 
     21 	obj = (SV*)newHV();
     22 	sv_magic(obj, 0, PERL_MAGIC_ext, (const char*)object, 0);
     23 	sv = newRV_inc(obj);
     24 	stash = gv_stashpv(package, 1);
     25 	sv_bless(sv, stash);
     26 
     27 	return sv;
     28 }
     29 
     30 void*
     31 pextract_get_object(SV* sv, const char* package) {
     32 	MAGIC* mg;
     33 
     34 	if (!sv || !SvOK(sv) || !SvROK(sv) || !sv_isobject(sv) || !sv_isa(sv, package) || !(mg = mg_find(SvRV(sv), PERL_MAGIC_ext)))
     35 		return NULL;
     36 	return (void*)mg->mg_ptr;
     37 }
     38 
     39 HV*
     40 pextract_get_hv_from_file_extract_obj(SV* hvref) {
     41 	if (!hvref
     42 			|| !SvOK(hvref)
     43 			|| !SvROK(hvref)
     44 			|| !(SvTYPE(SvRV(hvref)) == SVt_PVHV)
     45 			|| !sv_isobject(hvref)
     46 			|| !sv_isa(hvref, "File::Extract"))
     47 		return NULL;
     48 	return (HV*)SvRV((SV*)hvref);
     49 }
     50 
     51 SV*
     52 pextract_get_extractor_list(SV* extractor) {
     53 	HV* hv = pextract_get_hv_from_file_extract_obj(extractor);
     54 	if (!hv)
     55 		return NULL;
     56 	return *hv_fetch(hv, "extractor_list", 14, 0);
     57 }
     58 
     59 void
     60 pextract_hv_store_extractor_list_noinc(SV* extractor, SV* list) {
     61 	HV* hv = pextract_get_hv_from_file_extract_obj(extractor);
     62 	if (hv) {
     63 		hv_store(hv, "extractor_list", 14, list, 0);
     64 	} else {
     65 		croak("bar");
     66 	}
     67 }
     68 
     69 void
     70 pextract_hv_store_extractor_list_inc(SV* extractor, SV* list) {
     71 	HV* hv = pextract_get_hv_from_file_extract_obj(extractor);
     72 	if (hv) {
     73 		SvREFCNT_inc(list);
     74 		hv_store(hv, "extractor_list", 14, list, 0);
     75 	} else {
     76 		croak("bar");
     77 	}
     78 }