From e035737c20ac0caf47e9e48e3b11f006e9132e9c Mon Sep 17 00:00:00 2001 From: pop Date: Tue, 4 Mar 2003 23:32:55 +0000 Subject: [PATCH] Fixed perl API for new layout --- perl/IDZebra.i | 54 +++++++++++++- perl/IDZebra_wrap.c | 192 +------------------------------------------------ perl/lib/IDZebra.pm | 72 ------------------- perl/t/06_retrieval.t | 5 +- perl/zebra_api_ext.c | 1 - perl/zebra_api_ext.h | 5 -- 6 files changed, 54 insertions(+), 275 deletions(-) diff --git a/perl/IDZebra.i b/perl/IDZebra.i index 7f5e063..61a8c61 100644 --- a/perl/IDZebra.i +++ b/perl/IDZebra.i @@ -1,6 +1,7 @@ %module "IDZebra" %include typemaps.i // Load the typemaps librayr + %{ #include "zebraapi.h" #include "zebra_perl.h" @@ -11,8 +12,6 @@ /* == Typemaps ============================================================= */ -/* RetrievalRecordBuff is a special construct, to allow to map a char * buf - to non-null terminated perl string scalar value (SVpv). */ %typemap(in) int * { int i; if (!SvIOK($input)) @@ -27,6 +26,8 @@ argvi++; } +/* RetrievalRecordBuff is a special construct, to allow to map a char * buf + to non-null terminated perl string scalar value (SVpv). */ %typemap(out) RetrievalRecordBuf * { if ($1->len) { $result = newSVpv($1->buf,$1->len); @@ -85,7 +86,52 @@ /* == Structures for shadow classes ======================================= */ -%include "zebra_perl.h" + +/*%include "zebra_perl.h" */ +typedef struct { + char *groupName; + char *databaseName; + char *path; + char *recordId; + char *recordType; + int flagStoreData; + int flagStoreKeys; + int flagRw; + int fileVerboseLimit; + int databaseNamePath; + int explainDatabase; + int followLinks; +} recordGroup; + +typedef struct { + int noOfRecords; + ZebraRetrievalRecord *records; +} RetrievalObj; + +typedef struct { + int errCode; /* non-zero if error when fetching this */ + char *errString; /* error string */ + int position; /* position of record in result set (1,2,..) */ + char *base; + int sysno; + int score; + char *format; /* record syntax */ + RetrievalRecordBuf *buf; +} RetrievalRecord; + +/* Scan Term Descriptor */ +typedef struct { + int occurrences; /* scan term occurrences */ + char *term; /* scan term string */ +} scanEntry; + +typedef struct { + int num_entries; + int position; + int is_partial; + scanEntry *entries; +} ScanObj; + typedef struct { int processed; @@ -97,6 +143,8 @@ typedef struct { } ZebraTransactionStatus; + + /* == Module initialization and cleanup (zebra_perl.c) ===================== */ void init (void); diff --git a/perl/IDZebra_wrap.c b/perl/IDZebra_wrap.c index efbe3b8..1052668 100644 --- a/perl/IDZebra_wrap.c +++ b/perl/IDZebra_wrap.c @@ -212,7 +212,7 @@ SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { * perl5.swg * * Perl5 runtime library - * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.11 2003-03-04 23:05:31 pop Exp $ + * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.12 2003-03-04 23:32:55 pop Exp $ * ----------------------------------------------------------------------------- */ #define SWIGPERL @@ -1549,187 +1549,6 @@ XS(_wrap_delete_RetrievalObj) { } -XS(_wrap_RetrievalRecordBuf_buf_set) { - char _swigmsg[SWIG_MAX_ERRMSG] = ""; - const char *_swigerr = _swigmsg; - { - RetrievalRecordBuf *arg1 ; - char *arg2 ; - int argvi = 0; - dXSARGS; - - if ((items < 2) || (items > 2)) { - SWIG_croak("Usage: RetrievalRecordBuf_buf_set(self,buf);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) { - SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_buf_set. Expected _p_RetrievalRecordBuf"); - } - } - if (!SvOK((SV*) ST(1))) arg2 = 0; - else arg2 = (char *) SvPV(ST(1), PL_na); - { - if (arg1->buf) free((char*)arg1->buf); - arg1->buf = (char *) malloc(strlen(arg2)+1); - strcpy((char*)arg1->buf,arg2); - } - - XSRETURN(argvi); - fail: - (void) _swigerr; - } - croak(_swigerr); -} - - -XS(_wrap_RetrievalRecordBuf_buf_get) { - char _swigmsg[SWIG_MAX_ERRMSG] = ""; - const char *_swigerr = _swigmsg; - { - RetrievalRecordBuf *arg1 ; - char *result; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: RetrievalRecordBuf_buf_get(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) { - SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_buf_get. Expected _p_RetrievalRecordBuf"); - } - } - result = (char *) ((arg1)->buf); - - ST(argvi) = sv_newmortal(); - if (result) { - sv_setpv((SV*)ST(argvi++), (char *) result); - }else { - sv_setsv((SV*)ST(argvi++), &PL_sv_undef); - } - XSRETURN(argvi); - fail: - (void) _swigerr; - } - croak(_swigerr); -} - - -XS(_wrap_RetrievalRecordBuf_len_set) { - char _swigmsg[SWIG_MAX_ERRMSG] = ""; - const char *_swigerr = _swigmsg; - { - RetrievalRecordBuf *arg1 ; - int arg2 ; - int argvi = 0; - dXSARGS; - - if ((items < 2) || (items > 2)) { - SWIG_croak("Usage: RetrievalRecordBuf_len_set(self,len);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) { - SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_len_set. Expected _p_RetrievalRecordBuf"); - } - } - arg2 = (int) SvIV(ST(1)); - if (arg1) (arg1)->len = arg2; - - - XSRETURN(argvi); - fail: - (void) _swigerr; - } - croak(_swigerr); -} - - -XS(_wrap_RetrievalRecordBuf_len_get) { - char _swigmsg[SWIG_MAX_ERRMSG] = ""; - const char *_swigerr = _swigmsg; - { - RetrievalRecordBuf *arg1 ; - int result; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: RetrievalRecordBuf_len_get(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) { - SWIG_croak("Type error in argument 1 of RetrievalRecordBuf_len_get. Expected _p_RetrievalRecordBuf"); - } - } - result = (int) ((arg1)->len); - - ST(argvi) = sv_newmortal(); - sv_setiv(ST(argvi++), (IV) result); - XSRETURN(argvi); - fail: - (void) _swigerr; - } - croak(_swigerr); -} - - -XS(_wrap_new_RetrievalRecordBuf) { - char _swigmsg[SWIG_MAX_ERRMSG] = ""; - const char *_swigerr = _swigmsg; - { - RetrievalRecordBuf *result; - int argvi = 0; - dXSARGS; - - if ((items < 0) || (items > 0)) { - SWIG_croak("Usage: new_RetrievalRecordBuf();"); - } - result = (RetrievalRecordBuf *)(RetrievalRecordBuf *) calloc(1, sizeof(RetrievalRecordBuf)); - - { - if (result->len) { - ST(argvi) = newSVpv(result->buf,result->len); - }else { - ST(argvi) = newSVpv("",0); - } - sv_2mortal(ST(argvi)); - argvi++; - } - XSRETURN(argvi); - fail: - (void) _swigerr; - } - croak(_swigerr); -} - - -XS(_wrap_delete_RetrievalRecordBuf) { - char _swigmsg[SWIG_MAX_ERRMSG] = ""; - const char *_swigerr = _swigmsg; - { - RetrievalRecordBuf *arg1 ; - int argvi = 0; - dXSARGS; - - if ((items < 1) || (items > 1)) { - SWIG_croak("Usage: delete_RetrievalRecordBuf(self);"); - } - { - if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_RetrievalRecordBuf,0) < 0) { - SWIG_croak("Type error in argument 1 of delete_RetrievalRecordBuf. Expected _p_RetrievalRecordBuf"); - } - } - free((char *) arg1); - - - XSRETURN(argvi); - fail: - (void) _swigerr; - } - croak(_swigerr); -} - - XS(_wrap_RetrievalRecord_errCode_set) { char _swigmsg[SWIG_MAX_ERRMSG] = ""; const char *_swigerr = _swigmsg; @@ -8459,7 +8278,7 @@ static swig_type_info _swigt__p_Z_Espec1[] = {{"_p_Z_Espec1", 0, "Z_Espec1 *", 0 static swig_type_info _swigt__p_off_t[] = {{"_p_off_t", 0, "off_t *", 0},{"_p_off_t"},{0}}; static swig_type_info _swigt__p_Odr_oid[] = {{"_p_Odr_oid", 0, "Odr_oid *", 0},{"_p_Odr_oid"},{0}}; static swig_type_info _swigt__p_data1_varset[] = {{"_p_data1_varset", 0, "data1_varset *", 0},{"_p_data1_varset"},{0}}; -static swig_type_info _swigt__p_RetrievalRecordBuf[] = {{"IDZebra::RetrievalRecordBuf", 0, "RetrievalRecordBuf *", 0},{"IDZebra::RetrievalRecordBuf"},{0}}; +static swig_type_info _swigt__p_RetrievalRecordBuf[] = {{"_p_RetrievalRecordBuf", 0, "RetrievalRecordBuf *", 0},{"_p_RetrievalRecordBuf"},{0}}; static swig_type_info _swigt__p_perl_context[] = {{"_p_perl_context", 0, "struct perl_context *", 0},{"_p_perl_context"},{0}}; static swig_type_info _swigt__p_data1_node[] = {{"_p_data1_node", 0, "data1_node *", 0},{"_p_data1_node"},{0}}; static swig_type_info _swigt__p_ScanObj[] = {{"IDZebra::ScanObj", 0, "ScanObj *", 0},{"IDZebra::ScanObj"},{0}}; @@ -8618,12 +8437,6 @@ static swig_command_info swig_commands[] = { {"IDZebrac::RetrievalObj_records_get", _wrap_RetrievalObj_records_get}, {"IDZebrac::new_RetrievalObj", _wrap_new_RetrievalObj}, {"IDZebrac::delete_RetrievalObj", _wrap_delete_RetrievalObj}, -{"IDZebrac::RetrievalRecordBuf_buf_set", _wrap_RetrievalRecordBuf_buf_set}, -{"IDZebrac::RetrievalRecordBuf_buf_get", _wrap_RetrievalRecordBuf_buf_get}, -{"IDZebrac::RetrievalRecordBuf_len_set", _wrap_RetrievalRecordBuf_len_set}, -{"IDZebrac::RetrievalRecordBuf_len_get", _wrap_RetrievalRecordBuf_len_get}, -{"IDZebrac::new_RetrievalRecordBuf", _wrap_new_RetrievalRecordBuf}, -{"IDZebrac::delete_RetrievalRecordBuf", _wrap_delete_RetrievalRecordBuf}, {"IDZebrac::RetrievalRecord_errCode_set", _wrap_RetrievalRecord_errCode_set}, {"IDZebrac::RetrievalRecord_errCode_get", _wrap_RetrievalRecord_errCode_get}, {"IDZebrac::RetrievalRecord_errString_set", _wrap_RetrievalRecord_errString_set}, @@ -8866,7 +8679,6 @@ XS(SWIG_init) { SWIG_TypeClientData(SWIGTYPE_p_recordGroup, (void*) "IDZebra::recordGroup"); SWIG_TypeClientData(SWIGTYPE_p_RetrievalObj, (void*) "IDZebra::RetrievalObj"); - SWIG_TypeClientData(SWIGTYPE_p_RetrievalRecordBuf, (void*) "IDZebra::RetrievalRecordBuf"); SWIG_TypeClientData(SWIGTYPE_p_RetrievalRecord, (void*) "IDZebra::RetrievalRecord"); SWIG_TypeClientData(SWIGTYPE_p_scanEntry, (void*) "IDZebra::scanEntry"); SWIG_TypeClientData(SWIGTYPE_p_ScanObj, (void*) "IDZebra::ScanObj"); diff --git a/perl/lib/IDZebra.pm b/perl/lib/IDZebra.pm index dd9365b..8253bb5 100644 --- a/perl/lib/IDZebra.pm +++ b/perl/lib/IDZebra.pm @@ -334,84 +334,12 @@ sub STORE { } -############# Class : IDZebra::RetrievalRecordBuf ############## - -package IDZebra::RetrievalRecordBuf; -@ISA = qw( IDZebra ); -%OWNER = (); -%BLESSEDMEMBERS = ( -); - -%ITERATORS = (); -*swig_buf_get = *IDZebrac::RetrievalRecordBuf_buf_get; -*swig_buf_set = *IDZebrac::RetrievalRecordBuf_buf_set; -*swig_len_get = *IDZebrac::RetrievalRecordBuf_len_get; -*swig_len_set = *IDZebrac::RetrievalRecordBuf_len_set; -sub new { - my $pkg = shift; - my @args = @_; - my $self = IDZebrac::new_RetrievalRecordBuf(@args); - return undef if (!defined($self)); - $OWNER{$self} = 1; - my %retval; - tie %retval, "IDZebra::RetrievalRecordBuf", $self; - return bless \%retval, $pkg; -} - -sub DESTROY { - return unless $_[0]->isa('HASH'); - my $self = tied(%{$_[0]}); - return unless defined $self; - delete $ITERATORS{$self}; - if (exists $OWNER{$self}) { - IDZebrac::delete_RetrievalRecordBuf($self); - delete $OWNER{$self}; - } -} - -sub DISOWN { - my $self = shift; - my $ptr = tied(%$self); - delete $OWNER{$ptr}; - }; - -sub ACQUIRE { - my $self = shift; - my $ptr = tied(%$self); - $OWNER{$ptr} = 1; - }; - -sub FETCH { - my ($self,$field) = @_; - my $member_func = "swig_${field}_get"; - my $val = $self->$member_func(); - if (exists $BLESSEDMEMBERS{$field}) { - return undef if (!defined($val)); - my %retval; - tie %retval,$BLESSEDMEMBERS{$field},$val; - return bless \%retval, $BLESSEDMEMBERS{$field}; - } - return $val; -} - -sub STORE { - my ($self,$field,$newval) = @_; - my $member_func = "swig_${field}_set"; - if (exists $BLESSEDMEMBERS{$field}) { - $self->$member_func(tied(%{$newval})); - } else { - $self->$member_func($newval); - } -} - - ############# Class : IDZebra::RetrievalRecord ############## package IDZebra::RetrievalRecord; @ISA = qw( IDZebra ); %OWNER = (); %BLESSEDMEMBERS = ( - buf => 'IDZebra::RetrievalRecordBuf', ); %ITERATORS = (); diff --git a/perl/t/06_retrieval.t b/perl/t/06_retrieval.t index 152c8c3..9ddec71 100644 --- a/perl/t/06_retrieval.t +++ b/perl/t/06_retrieval.t @@ -1,6 +1,6 @@ #!perl # ============================================================================= -# $Id: 06_retrieval.t,v 1.3 2003-03-04 19:33:53 pop Exp $ +# $Id: 06_retrieval.t,v 1.4 2003-03-04 23:32:55 pop Exp $ # # Perl API header # ============================================================================= @@ -66,9 +66,6 @@ ok (($rec1->{score}), "score: $rec1->{score}"); ok (($rec1->{format} eq 'SUTRS'), "format: $rec1->{format}"); ok ((length($rec1->{buf}) > 0), "buf: ". length($rec1->{buf})." bytes"); - -#$rs1 = undef; - # ---------------------------------------------------------------------------- # Close session, check for rs availability diff --git a/perl/zebra_api_ext.c b/perl/zebra_api_ext.c index 0ec92dc..c0927fa 100644 --- a/perl/zebra_api_ext.c +++ b/perl/zebra_api_ext.c @@ -15,7 +15,6 @@ #include "zebra_perl.h" #include "zebra_api_ext.h" #include "yaz/log.h" -#include #include diff --git a/perl/zebra_api_ext.h b/perl/zebra_api_ext.h index a946b48..fbba0f8 100644 --- a/perl/zebra_api_ext.h +++ b/perl/zebra_api_ext.h @@ -7,10 +7,5 @@ void api_records_retrieve (ZebraHandle zh, ODR stream, const char *setname, Z_RecordComposition *comp, oid_value input_format, int num_recs, ZebraRetrievalRecord *recs); -typedef struct { - char *buf; /* record buffer (void pointer really) */ - int len; /* length */ -} RetrievalRecordBuf; - #endif -- 1.7.10.4