lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <mar...@rectangular.com>
Subject [lucy-dev] Extract values with allot_params()
Date Fri, 07 Jan 2011 04:10:21 GMT
Greets,

The second improvement I'd like to see in allot_params() is an increase in its
responsibility for extracting values.

At present, allot_params() finds the Perl scalar which has been assigned to
the named param, but it is the responsibility of the caller to extract the
value from the scalar and to ensure that all required parameters were
supplied.  Here is example autogenerated code for IndexSearcher#hits:

        lucy_Obj* query;
        uint32_t offset;
        uint32_t num_wanted;
        lucy_SortSpec* sort_spec;
        SV* query_sv = NULL;
        SV* offset_sv = NULL;
        SV* num_wanted_sv = NULL;
        SV* sort_spec_sv = NULL;

        bool_t args_ok = XSBind_allot_params( &(ST(0)), 1, items, "Lucy::Search::Searcher::hits_PARAMS",
            &query_sv, "query", 5,
            &offset_sv, "offset", 6,
            &num_wanted_sv, "num_wanted", 10,
            &sort_spec_sv, "sort_spec", 9,
            NULL);
        if (!args_ok) {
            CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
        }

        if ( !query_sv || !XSBind_sv_defined(query_sv) ) { CFISH_THROW(CFISH_ERR, "Missing
required param 'query'"); }
        query = (lucy_Obj*)XSBind_sv_to_cfish_obj(query_sv, LUCY_OBJ, alloca(cfish_ZCB_size()));;
        if ( offset_sv && XSBind_sv_defined(offset_sv) ) {
            offset = (uint32_t)SvUV( offset_sv );;
        }
        else {
            offset = 0;
        }
        if ( num_wanted_sv && XSBind_sv_defined(num_wanted_sv) ) {
            num_wanted = (uint32_t)SvUV( num_wanted_sv );;
        }
        else {
            num_wanted = 10;
        }
        if ( sort_spec_sv && XSBind_sv_defined(sort_spec_sv) ) {
            sort_spec = (lucy_SortSpec*)XSBind_sv_to_cfish_obj(sort_spec_sv, LUCY_SORTSPEC,
NULL);;
        }
        else {
            sort_spec = NULL;
        }

If we give allot_params() the task of extracting values, we can streamline
away a lot of that calling code.  Here's more or less what I'd like to see in
the autogenerated XS binding code instead:

        lucy_Obj* query = NULL;
        uint32_t offset = 0;
        uint32_t num_wanted = 10
        lucy_SortSpec* sort_spec = NULL;

        chy_bool_t args_ok = XSBind_allot_params( &(ST(0)), 1, 
            items, "Lucy::Search::Searcher::hits_PARAMS",
            ALLOT_OBJ(LUCY_OBJ, &query, "query", 5, true),
            ALLOT_U32(&offset, "offset", 6, false),
            ALLOT_U32(&num_wanted, "num_wanted", 10, false),
            ALLOT_OBJ(LUCY_SORTSPEC, "sort_spec", 9, false),
            NULL);
        if (!args_ok) {
            CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
        }

Consolidating extraction functionality in allot_params() should allow us to
shrink the size of Lucy.xs substantially.  That's important, because Lucy.xs
is so big that it takes 30 seconds to compile on my MacBook Pro, and won't
even compile on certain systems:

    http://www.cpantesters.org/cpan/report/1bf5a982-17b0-11e0-afb0-adca6bb533f3

Marvin Humphrey




Mime
View raw message