Changeset 4001 for lang/perl/Senna/trunk

Show
Ignore:
Timestamp:
01/03/08 02:14:17 (5 years ago)
Author:
daisuke
Message:

lang/perl/Senna; incomplete query imp, plus a lot of change to use typemaps correctly

Location:
lang/perl/Senna/trunk
Files:
4 added
7 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Senna/trunk/lib/Senna.xs

    r3991 r4001  
    5050SV * 
    5151SennaPerl_Index__XS_info(self) 
    52         SV *self; 
     52        SennaPerl_Index *self; 
    5353    CODE: 
    5454        RETVAL = SennaPerl_Index_info(self); 
     
    5858SV * 
    5959SennaPerl_Index_path(self) 
    60         SV *self; 
     60        SennaPerl_Index *self; 
    6161 
    6262SV * 
    6363SennaPerl_Index_remove(self) 
    64         SV *self; 
     64        SennaPerl_Index *self; 
    6565 
    6666SV * 
    6767SennaPerl_Index_close(self) 
    68         SV *self; 
     68        SennaPerl_Index *self; 
    6969 
    7070SV * 
    7171SennaPerl_Index_update(self, key, oldvalue, newvalue) 
    72         SV *self; 
     72        SennaPerl_Index *self; 
    7373        SV *key; 
    7474        SV *oldvalue; 
     
    7777SV * 
    7878SennaPerl_Index__XS_insert(self, key, newvalue) 
    79         SV *self; 
     79        SennaPerl_Index *self; 
    8080        SV *key; 
    8181        SV *newvalue; 
     
    9696void 
    9797SennaPerl_Index_DESTROY(self) 
    98         SV *self; 
     98        SennaPerl_Index *self; 
    9999 
    100100MODULE = Senna     PACKAGE = Senna::Encoding    PREFIX = SennaPerl_Encoding_ 
     
    105105SennaPerl_Encoding_enc2str(enc) 
    106106        sen_encoding enc; 
    107     CODE: 
    108         RETVAL = SennaPerl_Encoding_XS_enc2str(enc); 
    109     OUTPUT: 
    110         RETVAL 
    111107 
    112108MODULE = Senna     PACKAGE = Senna::Records    PREFIX = SennaPerl_Records_ 
     
    115111 
    116112SV * 
     113SennaPerl_Records_open(pkg, record_unit, subrec_unit, max_n_subrecs) 
     114        char *pkg; 
     115        sen_rec_unit record_unit; 
     116        sen_rec_unit subrec_unit; 
     117        unsigned int max_n_subrecs; 
     118 
     119SV * 
    117120SennaPerl_Records__XS_next(self) 
    118         SV *self; 
     121        SennaPerl_Records *self; 
    119122    CODE: 
    120123        RETVAL = SennaPerl_Records_next(self); 
     
    124127SV * 
    125128SennaPerl_Records_nhits(self) 
    126         SV *self; 
     129        SennaPerl_Records *self; 
    127130 
    128131SV * 
    129132SennaPerl_Records_curr_key(self) 
    130         SV *self; 
     133        SennaPerl_Records *self; 
    131134 
    132135SV * 
    133136SennaPerl_Records_sort(self, limit = 10, optarg = NULL) 
    134         SV *self; 
     137        SennaPerl_Records *self; 
    135138        int limit; 
    136139        HV *optarg; 
     
    138141void 
    139142SennaPerl_Records_DESTROY(self) 
    140         SV *self; 
     143        SennaPerl_Records *self; 
     144 
     145sen_rc 
     146SennaPerl_Records_close(self) 
     147        SennaPerl_Records *self; 
    141148 
    142149MODULE = Senna     PACKAGE = Senna::Symbol    PREFIX = SennaPerl_Symbol_ 
     
    180187SennaPerl_Symbol_DESTROY(obj) 
    181188        SV *obj; 
     189 
     190MODULE = Senna     PACKAGE = Senna::Query    PREFIX = SennaPerl_Query_ 
     191 
     192PROTOTYPES: DISABLE 
     193 
     194SV * 
     195SennaPerl_Query_open(pkg, str, default_op, max_exprs, encoding) 
     196        char *pkg; 
     197        char *str; 
     198        sen_sel_operator default_op; 
     199        int max_exprs; 
     200        sen_encoding encoding; 
     201 
     202sen_rc 
     203SennaPerl_Query_close(obj) 
     204        SennaPerl_Query *obj; 
     205 
     206void 
     207SennaPerl_Query_DESTROY(obj) 
     208        SennaPerl_Query *obj; 
     209 
     210sen_rc 
     211SennaPerl_Query_exec(obj, index, records, op) 
     212        SennaPerl_Query *obj; 
     213        SennaPerl_Index *index; 
     214        SennaPerl_Records *records; 
     215        sen_sel_operator op 
     216 
     217SV * 
     218SennaPerl_Query_snip(query, flags, width, max_results, n_tags, opentags_av, closetags_av, mapping) 
     219        SennaPerl_Query *query; 
     220        int flags; 
     221        unsigned int width; 
     222        unsigned int max_results; 
     223        unsigned int n_tags; 
     224        AV *opentags_av; 
     225        AV *closetags_av; 
     226        sen_snip_mapping *mapping; 
     227 
     228 
  • lang/perl/Senna/trunk/senna-encoding.c

    r3767 r4001  
     1/* $Id$ 
     2 * 
     3 * Copyright (c) 2005-2008 Daisuke Maki <daisuke@endeworks.jp> 
     4 * All rights reserved. 
     5 */ 
    16#include "senna-perl.h" 
     7#ifndef  __SENNA_ENCODING_C__ 
     8#define  __SENNA_ENCODING_C__ 
    29 
    310int 
     
    2027 
    2128SV * 
    22 SennaPerl_Encoding_XS_enc2str(enc) 
     29SennaPerl_Encoding_enc2str(enc) 
    2330        sen_encoding enc; 
    2431{ 
     
    4148    return sv; 
    4249} 
     50 
     51#endif /* ifndef  __SENNA_ENCODING_C__ */ 
  • lang/perl/Senna/trunk/senna-index.c

    r3991 r4001  
    9090 
    9191SV * 
    92 SennaPerl_Index_info(self) 
    93         SV *self; 
    94 { 
    95     SennaPerl_Index *index; 
     92SennaPerl_Index_info(index) 
     93        SennaPerl_Index *index; 
     94{ 
    9695    int key_size = 0; 
    9796    int flags = 0; 
     
    106105    sen_rc rc; 
    107106 
    108     index = XS_STATE(SennaPerl_Index *, self); 
    109107    rc = sen_index_info(index->index, 
    110108        &key_size, &flags, &initial_n_segments, &encoding, 
     
    155153 
    156154SV * 
    157 SennaPerl_Index_remove(self) 
    158         SV *self; 
    159 { 
    160     SennaPerl_Index *index; 
     155SennaPerl_Index_remove(index) 
     156        SennaPerl_Index *index; 
     157{ 
    161158    char       path[ SEN_MAX_PATH_SIZE ]; 
    162159 
    163     index = XS_STATE(SennaPerl_Index *, self); 
    164160    if (! sen_index_path( index->index, path, SEN_MAX_PATH_SIZE) ) { 
    165161        croak("sen_index_path() did not return a proper path"); 
     
    170166 
    171167SV * 
    172 SennaPerl_Index_close(obj) 
    173         SV *obj; 
    174 { 
    175     SennaPerl_Index *index; 
    176     index = XS_STATE(SennaPerl_Index *, obj); 
     168SennaPerl_Index_close(index) 
     169        SennaPerl_Index *index; 
     170{ 
    177171    if (index == NULL || ! index->open) { 
    178172        return SennaPerl_Global_sen_rc2obj( sen_other_error ); 
     
    184178 
    185179void 
    186 SennaPerl_Index_DESTROY(obj) 
    187         SV *obj; 
    188 { 
    189     SennaPerl_Index *index; 
    190 SP_DEBUG("Senna::Index::DESTROY"); 
    191     index = XS_STATE(SennaPerl_Index *, obj); 
    192  
    193 SP_DEBUG("Senna::Index::close"); 
    194     SennaPerl_Index_close(obj); 
    195 SP_DEBUG("Senna::Index Safefree"); 
     180SennaPerl_Index_DESTROY(index) 
     181        SennaPerl_Index *index; 
     182{ 
     183    SennaPerl_Index_close(index); 
    196184    Safefree(index); 
    197 SP_DEBUG("Senna::Index::DESTROY done"); 
    198 } 
    199  
    200 SV * 
    201 SennaPerl_Index_path(obj) 
    202         SV *obj; 
    203 { 
    204     SennaPerl_Index *index; 
     185} 
     186 
     187SV * 
     188SennaPerl_Index_path(index) 
     189        SennaPerl_Index *index; 
     190{ 
    205191    char *buf; 
    206192    SV *sv; 
    207193 
    208     index = XS_STATE(SennaPerl_Index *, obj); 
    209194    buf = malloc(sizeof(char) * SEN_MAX_PATH_SIZE); 
    210195 
     
    216201 
    217202SV * 
    218 SennaPerl_Index_update(obj, key, oldvalue, newvalue) 
    219         SV *obj; 
     203SennaPerl_Index_update(index, key, oldvalue, newvalue) 
     204        SennaPerl_Index *index; 
    220205        SV *key; 
    221206        SV *oldvalue; 
    222207        SV *newvalue; 
    223208{ 
    224     SennaPerl_Index *index = XS_STATE(SennaPerl_Index *, obj); 
    225209    void *pkey = SennaPerl_Global_sv2key(key); 
    226210    char *oldc = NULL; 
     
    244228 
    245229SV * 
    246 SennaPerl_Index_insert(obj, key, value) 
    247         SV *obj; 
     230SennaPerl_Index_insert(index, key, value) 
     231        SennaPerl_Index *index; 
    248232        SV *key; 
    249233        SV *value; 
    250234{ 
    251     return SennaPerl_Index_update(obj, key, NULL, value); 
     235    return SennaPerl_Index_update(index, key, NULL, value); 
    252236} 
    253237 
  • lang/perl/Senna/trunk/senna-perl.h

    r3991 r4001  
    6464} SennaPerl_Index ; 
    6565 
    66 typedef struct { 
    67     sen_records *records; 
    68 } SennaPerl_Records; 
     66#define XS_2SENINDEX(x) x->index 
     67#define XS_2SENINDEX_OPEN(x) x->open 
     68 
     69typedef sen_records SennaPerl_Records; 
     70#define XS_2SENRECORDS(x) x 
    6971 
    7072typedef struct { 
     
    7274    char *path; 
    7375} SennaPerl_Symbol; 
     76#define XS_2SENSYM(x) x->sym 
     77#define XS_2SENSYM_PATH(x) x->path 
     78 
     79typedef sen_query SennaPerl_Query; 
     80#define XS_2SENQUERY(x) x 
     81 
     82typedef sen_snip SennaPerl_Snip; 
     83#define XS_2SENSNUP(x) x 
    7484 
    7585/* SennaPerl_Global */ 
     
    8191 
    8292/* SennaPerl_Encoding */ 
    83 SV *SennaPerl_Encoding_XS_enc2str(sen_encoding enc); 
     93SV *SennaPerl_Encoding_enc2str(sen_encoding enc); 
    8494 
    8595/* SennaPerl_Index */ 
    86 SV *SennaPerl_Index_XS_create( char *pkg, char *path, int key_size, int flags, int initial_n_segments, sen_encoding encoding); 
     96SV *SennaPerl_Index_create( char *pkg, char *path, int key_size, int flags, int initial_n_segments, sen_encoding encoding); 
    8797SV *SennaPerl_Index_open( char *pkg, char *path ); 
    88 SV *SennaPerl_Index_remove(SV *self); 
    89 SV *SennaPerl_Index_info(SV *self); 
    90 SV *SennaPerl_Index_update(SV *self, SV *key, SV *oldvalue, SV *newvalue); 
    91 SV *SennaPerl_Index_path(SV *self); 
    92 SV *SennaPerl_Index_close(SV *self); 
     98SV *SennaPerl_Index_remove(SennaPerl_Index *index); 
     99SV *SennaPerl_Index_info(SennaPerl_Index *index); 
     100SV *SennaPerl_Index_update(SennaPerl_Index *index, SV *key, SV *oldvalue, SV *newvalue); 
     101SV *SennaPerl_Index_path(SennaPerl_Index *self); 
     102SV *SennaPerl_Index_close(SennaPerl_Index *self); 
    93103SV *SennaPerl_Index_rename(SV *self, char *from, char *to); 
    94 SV *SennaPerl_Index_insert(SV *self, SV *key, SV *value); 
     104SV *SennaPerl_Index_insert(SennaPerl_Index *self, SV *key, SV *value); 
    95105SV *SennaPerl_Index_select(SV *self, SV *query); 
    96 void SennaPerl_Index_DESTROY(SV *self); 
     106void SennaPerl_Index_DESTROY(SennaPerl_Index *self); 
    97107 
    98108/* SennaPerl_Records */ 
    99109void SennaPerl_Records_bootstrap(); 
    100110SV *SennaPerl_Records_new(char *pkg, sen_records *records); 
    101 SV *SennaPerl_Records_next(SV *self); 
    102 SV *SennaPerl_Records_nhits(SV *self); 
    103 SV *SennaPerl_Records_curr_key(SV *self); 
    104 SV *SennaPerl_Records_sort(SV *self, int limit, HV *optarg); 
    105 void SennaPerl_Records_DESTROY(SV *self); 
     111SV *SennaPerl_Records_open(char *pkg, sen_rec_unit record_unit, sen_rec_unit subrec_unit, unsigned int max_n_subrecs); 
     112SV *SennaPerl_Records_next(SennaPerl_Records *self); 
     113SV *SennaPerl_Records_nhits(SennaPerl_Records *self); 
     114SV *SennaPerl_Records_curr_key(SennaPerl_Records *self); 
     115SV *SennaPerl_Records_sort(SennaPerl_Records *self, int limit, HV *optarg); 
     116sen_rc SennaPerl_Records_close(SennaPerl_Records *self); 
     117void SennaPerl_Records_DESTROY(SennaPerl_Records *self); 
    106118 
    107119/* SennaPerl_Symbol */ 
     
    114126SV *SennaPerl_Symbol_path(SV *obj); 
    115127 
     128/* SennaPerl_Query */ 
     129SV *SennaPerl_Query_open(char *pkg, char *str, sen_sel_operator default_op, int max_exprs, sen_encoding encoding); 
     130sen_rc SennaPerl_Query_close(SennaPerl_Query *obj); 
     131void SennaPerl_Query_DESTROY(SennaPerl_Query *obj); 
     132sen_rc SennaPerl_Query_exec(SennaPerl_Query *obj, SennaPerl_Index *index, SennaPerl_Records *records, sen_sel_operator op); 
     133 
    116134#endif /* ifndef __SENNA_PERL_H__ */ 
  • lang/perl/Senna/trunk/senna-records.c

    r3962 r4001  
    44 * All rights reserved. 
    55 */ 
     6#include "senna-perl.h" 
    67#ifndef __SENNA_RECORDS_C__ 
    78#define __SENNA_RECORDS_C__ 
    8  
    9 #include "senna-perl.h" 
    109 
    1110void 
     
    2524        sen_records *records; 
    2625{ 
    27     SennaPerl_Records *xs; 
    2826    SV *sv; 
    29  
    30     Newz(1234, xs, 1, SennaPerl_Records); 
    31  
    32     xs->records = records; 
    33  
    34     XS_STRUCT2OBJ(sv, pkg, xs); 
     27    XS_STRUCT2OBJ(sv, pkg, records); 
    3528    SvREADONLY_on(sv); 
    3629    return sv; 
     
    3831 
    3932SV * 
    40 SennaPerl_Records_next(obj) 
    41         SV *obj; 
     33SennaPerl_Records_open(pkg, record_unit, subrec_unit, max_n_subrecs) 
     34        char *pkg; 
     35        sen_rec_unit record_unit; 
     36        sen_rec_unit subrec_unit; 
     37        unsigned int max_n_subrecs; 
     38{ 
     39    SV *sv; 
     40    sen_records *records; 
     41 
     42    records = sen_records_open(record_unit, subrec_unit, max_n_subrecs); 
     43    return SennaPerl_Records_new(pkg, records); 
     44} 
     45 
     46SV * 
     47SennaPerl_Records_next(records) 
     48        SennaPerl_Records *records; 
    4249{ 
    4350    SV *sv; 
    4451    char keybuf[SEN_MAX_KEY_SIZE]; 
    4552    int score; 
    46     SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj); 
    4753 
    48     if (sen_records_next(records->records, &keybuf, SEN_MAX_KEY_SIZE, &score)) { 
     54    if (sen_records_next(XS_2SENRECORDS(records), &keybuf, SEN_MAX_KEY_SIZE, &score)) { 
    4955        dSP; 
    5056        ENTER; 
     
    7884 
    7985SV * 
    80 SennaPerl_Records_nhits(obj) 
    81         SV *obj; 
     86SennaPerl_Records_nhits(records) 
     87        SennaPerl_Records *records; 
    8288{ 
    83     SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj); 
    84     return newSViv( sen_records_nhits( records->records ) ); 
     89    return newSViv( sen_records_nhits( XS_2SENRECORDS(records)) ); 
     90} 
     91 
     92sen_rc 
     93SennaPerl_Records_close(records) 
     94        SennaPerl_Records *records; 
     95{ 
     96    return sen_records_close(XS_2SENRECORDS(records)); 
    8597} 
    8698 
    8799void 
    88 SennaPerl_Records_DESTROY(obj) 
    89         SV *obj; 
     100SennaPerl_Records_DESTROY(records) 
     101        SennaPerl_Records *records; 
    90102{ 
    91     SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj); 
    92     sen_records_close(records->records); 
    93     Safefree(records); 
     103    if (XS_2SENRECORDS(records)) { 
     104        sen_records_close(XS_2SENRECORDS(records)); 
     105    } 
    94106} 
    95107 
    96108SV * 
    97 SennaPerl_Records_curr_key(obj) 
    98         SV *obj; 
     109SennaPerl_Records_curr_key(records) 
     110        SennaPerl_Records *records; 
    99111{ 
    100112    char keybuf[SEN_MAX_KEY_SIZE]; 
    101     SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj); 
    102     if (sen_records_curr_key(records->records, keybuf, SEN_MAX_KEY_SIZE)) { 
     113    if (sen_records_curr_key(XS_2SENRECORDS(records), keybuf, SEN_MAX_KEY_SIZE)) { 
    103114        return newSVpvf("%s", keybuf); 
    104115    } 
     
    107118 
    108119SV * 
    109 SennaPerl_Records_sort(obj, limit, optarg) 
    110         SV *obj; 
     120SennaPerl_Records_sort(records, limit, optarg) 
     121        SennaPerl_Records *records; 
    111122        int limit; 
    112123        HV *optarg; 
    113124{ 
    114125    SV *sv; 
    115     SennaPerl_Records *records = XS_STATE(SennaPerl_Records *, obj); 
    116126    sen_sort_optarg *o = NULL; 
    117127    if (optarg != NULL) { 
     
    128138    } 
    129139 
    130     sv = sen_rc2obj(sen_records_sort(records->records, limit, o)); 
     140    sv = sen_rc2obj(sen_records_sort(XS_2SENRECORDS(records), limit, o)); 
    131141 
    132142    if (o) { 
  • lang/perl/Senna/trunk/senna-sym.c

    r3993 r4001  
    9292{ 
    9393    SennaPerl_Symbol *symbol = XS_STATE(SennaPerl_Symbol *, obj); 
    94     SennaPerl_Symbol_close(obj); 
     94    SvREFCNT_dec(SennaPerl_Symbol_close(obj)); 
    9595    Safefree(symbol->path); 
    9696    Safefree(symbol); 
  • lang/perl/Senna/trunk/typemap

    r3767 r4001  
    11TYPEMAP 
    2 Senna::Index        T_PTROBJ 
     2SennaPerl_Index *   T_PTROBJ_INDEX 
     3SennaPerl_Query *   T_PTROBJ_QUERY 
     4SennaPerl_Records * T_PTROBJ_RECORDS 
     5SennaPerl_Snip    * T_PTROBJ_SNIP 
    36sen_encoding        T_ENUM 
    47sen_sel_mode        T_ENUM 
     
    811sen_id              T_U_INT 
    912sen_sel_operator    T_ENUM 
    10 sen_snip_mapping    T_PRTOBJ 
     13sen_snip_mapping *  T_PTROBJ 
     14 
     15INPUT 
     16T_PTROBJ_INDEX 
     17        $var = XS_STATE(SennaPerl_Index *, $arg); 
     18 
     19T_PTROBJ_QUERY 
     20        $var = XS_STATE(SennaPerl_Query *, $arg); 
     21 
     22T_PTROBJ_RECORDS 
     23        $var = XS_STATE(SennaPerl_Records *, $arg); 
     24 
     25T_PTROBJ_SNIP 
     26        $var = XS_STATE(SennaPerl_Snip *, $arg); 
     27