Changeset 5038

Show
Ignore:
Timestamp:
01/20/08 14:23:51 (5 years ago)
Author:
daisuke
Message:

lang/perl/Cache-Memcached-LibMemcached?; call compress/serialize via CVs, not SV(w/pv)

Location:
lang/perl/Cache-Memcached-LibMemcached/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Cache-Memcached-LibMemcached/trunk/LibMemcached.xs

    r4735 r5038  
    1515 
    1616SV * 
    17 Cache_LibMemcached__XS_new(pkg, have_zlib, compress_enabled, compress_threshold, compress_savings) 
     17Cache_LibMemcached__XS_new(pkg, have_zlib, compress_enabled, compress_threshold, compress_savings, compress_method, uncompress_method, serialize_method, deserialize_method) 
    1818        char *pkg; 
    1919        bool have_zlib; 
     
    2121        size_t compress_threshold; 
    2222        float compress_savings; 
    23     CODE: 
    24         RETVAL = Cache_LibMemcached_create(pkg, have_zlib, compress_enabled, compress_threshold, compress_savings); 
     23        SV *compress_method; 
     24        SV *uncompress_method; 
     25        SV *serialize_method; 
     26        SV *deserialize_method; 
     27    CODE: 
     28        RETVAL = Cache_LibMemcached_create(pkg, have_zlib, compress_enabled, compress_threshold, compress_savings, compress_method, uncompress_method, serialize_method, deserialize_method); 
    2529    OUTPUT: 
    2630        RETVAL 
  • lang/perl/Cache-Memcached-LibMemcached/trunk/lib/Cache/Memcached/LibMemcached.pm

    r5025 r5038  
    88use warnings; 
    99use Carp 'croak'; 
    10 use Storable; 
     10use Storable (); 
    1111use constant HAVE_ZLIB => eval "use Compress::Zlib (); 1;"; 
    1212use constant COMPRESS_SAVINGS => 0.20; 
     
    3838        $args->{compress_threshold} || 0, 
    3939        COMPRESS_SAVINGS, 
    40         \&Compress::Zlib::memGzip, 
    41         \&Compress::Zlib::memGunzip, 
     40        HAVE_ZLIB ? \&Compress::Zlib::memGzip : undef, 
     41        HAVE_ZLIB ? \&Compress::Zlib::memGunzip : undef, 
    4242        \&Storable::nfreeze, 
    4343        \&Storable::thaw, 
  • lang/perl/Cache-Memcached-LibMemcached/trunk/perl-libmemcached.c

    r4986 r5038  
    88#define __PERL_LIBMEMCACHED_C__ 
    99#include "perl-libmemcached.h" 
     10 
     11#define ASSERT_CALLBACK(x) \ 
     12    if (! SvOK(x) || ! SvROK(x) || SvTYPE(SvRV(x) ) != SVt_PVCV) { \ 
     13        croak("provided argument is not a coderef!"); \ 
     14    } 
    1015 
    1116#define CONSTSUBi(name, x) \ 
     
    112117        PUTBACK; 
    113118 
    114         if (call_pv("Compress::Zlib::memGunzip", G_SCALAR) <= 0) { 
    115             croak("Compress::Zlib::memGunzip did not return a proper value"); 
     119        if (call_sv(MEMCACHED_UNCOMPRESS_METHOD(cache), G_SCALAR) <= 0) { 
     120            croak("uncompress_method did not return a proper value"); 
    116121        } 
    117122        SPAGAIN; 
     
    142147        PUTBACK; 
    143148 
    144         if (call_pv("Storable::thaw", G_SCALAR) <= 0) { 
    145             croak("Storable::thaw did not return a proper value"); 
     149        if (call_sv(MEMCACHED_DESERIALIZE_METHOD(cache), G_SCALAR) <= 0) { 
     150            croak("deserialize_method did not return a proper value"); 
    146151        } 
    147152        SPAGAIN; 
     
    173178        PUTBACK; 
    174179 
    175         if (call_pv("Storable::freeze", G_SCALAR) <= 0) { 
    176             croak("Storable::freeze did not return a proper value"); 
     180        if (call_sv(MEMCACHED_SERIALIZE_METHOD(cache), G_SCALAR) <= 0) { 
     181            croak("serialize_method did not return a proper value"); 
    177182        } 
    178183        SPAGAIN; 
     
    217222        PUTBACK; 
    218223 
    219         if (call_pv("Compress::Zlib::memGzip", G_SCALAR) <= 0) { 
    220             croak("Compress::Zlib::memGzip did not return a proper value"); 
     224        if (call_sv(MEMCACHED_COMPRESS_METHOD(cache), G_SCALAR) <= 0) { 
     225            croak("compress_method did not return a proper value"); 
    221226        } 
    222227        SPAGAIN; 
     
    311316 
    312317SV * 
    313 Cache_LibMemcached_create(pkg, have_zlib, compress_enabled, compress_threshold, compress_savings) 
     318Cache_LibMemcached_create(pkg, have_zlib, compress_enabled, compress_threshold, compress_savings, compress_method, uncompress_method, serialize_method, deserialize_method) 
    314319        char *pkg; 
    315320        bool have_zlib; 
     
    317322        size_t compress_threshold; 
    318323        float compress_savings; 
     324        SV *compress_method; 
     325        SV *uncompress_method; 
     326        SV *serialize_method; 
     327        SV *deserialize_method; 
    319328{ 
    320329    SV *sv; 
     
    329338    MEMCACHED_COMPRESS_THRESHOLD(xs) = compress_threshold; 
    330339    MEMCACHED_COMPRESS_SAVINGS(xs)   = compress_savings; 
     340    MEMCACHED_COMPRESS_METHOD(xs)    = compress_method; 
     341    MEMCACHED_UNCOMPRESS_METHOD(xs)  = uncompress_method; 
     342    MEMCACHED_SERIALIZE_METHOD(xs)   = serialize_method; 
     343    MEMCACHED_DESERIALIZE_METHOD(xs) = deserialize_method; 
     344 
     345    SvREFCNT_inc(compress_method); 
     346    SvREFCNT_inc(uncompress_method); 
     347    SvREFCNT_inc(serialize_method); 
     348    SvREFCNT_inc(deserialize_method); 
     349    ASSERT_CALLBACK( MEMCACHED_SERIALIZE_METHOD(xs) ); 
    331350 
    332351    XS_STRUCT2OBJ(sv, "Cache::Memcached::LibMemcached", xs); 
     
    341360    memcached_quit(MEMCACHED_CACHE(cache)); 
    342361    memcached_free(MEMCACHED_CACHE(cache)); 
     362    SvREFCNT_dec(MEMCACHED_COMPRESS_METHOD(cache)); 
     363    SvREFCNT_dec(MEMCACHED_UNCOMPRESS_METHOD(cache)); 
     364    SvREFCNT_dec(MEMCACHED_DESERIALIZE_METHOD(cache)); 
     365    SvREFCNT_dec(MEMCACHED_SERIALIZE_METHOD(cache)); 
    343366} 
    344367 
     
    419442 
    420443    hv = newHV(); 
    421     while (1) { 
     444    for(i = 0; i < keys_len; i++) { 
     445/*    while (1) {*/ 
    422446        char *value; 
    423447        char key[MEMCACHED_MAX_KEY]; 
  • lang/perl/Cache-Memcached-LibMemcached/trunk/perl-libmemcached.h

    r4736 r5038  
    3535    size_t        compress_threshold; 
    3636    NV            compress_savings; 
     37    SV           *compress_method; 
     38    SV           *uncompress_method; 
     39    SV           *serialize_method; 
     40    SV           *deserialize_method; 
    3741} Cache_LibMemcached; 
    3842 
     
    4246#define MEMCACHED_COMPRESS_THRESHOLD(x) x->compress_threshold 
    4347#define MEMCACHED_COMPRESS_SAVINGS(x)   x->compress_savings 
     48#define MEMCACHED_COMPRESS_METHOD(x)    x->compress_method 
     49#define MEMCACHED_UNCOMPRESS_METHOD(x)  x->uncompress_method 
     50#define MEMCACHED_SERIALIZE_METHOD(x)   x->serialize_method 
     51#define MEMCACHED_DESERIALIZE_METHOD(x) x->deserialize_method 
    4452 
    4553typedef memcached_return Cache_LibMemcached_rc; 
    4654typedef memcached_stat_st Cache_LibMemcached_stat; 
    4755 
    48 SV *Cache_LibMemcached_create( 
    49         char *pkg, 
    50         bool have_zlib, 
    51         bool compress_enabled, 
    52         size_t compress_threshold, 
    53         float compress_savings 
     56SV * 
     57Cache_LibMemcached_create( 
     58    char *pkg, 
     59    bool have_zlib, 
     60    bool compress_enabled, 
     61    size_t compress_threshold, 
     62    float compress_savings, 
     63    SV *compress_method, 
     64    SV *decompress_method, 
     65    SV *serialize_method, 
     66    SV *deserialize_method 
    5467); 
    5568