NoMethodError: undefined method `pack' 问题,在使用代码搜索引擎Gonzui
jwl-214
|
1#
jwl-214 发表于 2008-05-04 17:59
NoMethodError: undefined method `pack' 问题,在使用代码搜索引擎Gonzui
请问一下NoMethodError: undefined method `pack' 该如何解决? 一般是什么原因造成的.
以下是的碰到的出错输出: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< test_index(IndexerTest): NoMethodError: undefined method `pack' for Gonzui:eltaDumper:Module ../gonzui/delta.rb:38:in `dump_ids' ../gonzui/indexer.rb:165:in `flush_cache' ../gonzui/indexer.rb:255:in `index_content' ../gonzui/indexer.rb:289:in `add_content_with_indexing' ../gonzui/indexer.rb:300:in `add_content' ../gonzui/indexer.rb:309:in `index' indexer.rb:20:in `test_index' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 以下是../gonzui/delta.rb文件: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< # # delta.rb - byte-oriented delta compression implementation # # Copyright (C) 2004-2005 Satoru Takabayashi <satoru@namazu.org> # All rights reserved. # This is free software with ABSOLUTELY NO WARRANTY. # # You can redistribute it and/or modify it under the terms of # the GNU General Public License version 2. # require 'gonzui/delta.so' module Gonzui module DeltaDumper PACK_FORMAT = "w*" module_function def dump_tuples(klass, list) encode_tuples(list, klass:eltaSize, klass::UnitSize) return list.pack(PACK_FORMAT) end def undump_tuples(klass, dump) list = dump.unpack(PACK_FORMAT) decode_tuples(list, klass:eltaSize, klass::UnitSize) # # Make an array of arrays for convinence of the caller # [1,2,3,4,5,6] => [[1,2], [3,4], [5,6] if UnitSize is 2 # values = (0...(list.length / klass::UnitSize)).map {|i| list[i * klass::UnitSize, klass::UnitSize] } return values end def dump_fixnums(list) encode_fixnums(list).pack(PACK_FORMAT) end def undump_fixnums(dump) decode_fixnums(dump.unpack(PACK_FORMAT)) end alias dump_ids dump_fixnums alias undump_ids undump_fixnums module_function :dump_ids, :undump_ids end end >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 以下是delta.c用来产生delta.so的. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 2 c-style: "BSD" -*- */ /* * delta.c - byte-oriented delta compression implementation * * Copyright (C) 2005 Satoru Takabayashi <satoru@namazu.org> * Copyright (C) 2005 Keisuke Nishida <knishida@open-cobol.org> * All rights reserved. * This is free software with ABSOLUTELY NO WARRANTY. * * You can redistribute it and/or modify it under the terms of * the GNU General Public License version 2. */ #include <ruby.h> #include <assert.h> typedef void (*CodeFunc)(VALUE *p, int i, int *prev); static inline void decode(VALUE *p, int i, int *prev) { int this; if (TYPE(p) != T_FIXNUM) { rb_raise(rb_eTypeError, "wrong argument type (fixnum required)"); } this = FIX2INT(p); p = INT2FIX(this + *prev); *prev = FIX2INT(p); } static inline void encode(VALUE *p, int i, int *prev) { int this; if (TYPE(p) != T_FIXNUM) { rb_raise(rb_eTypeError, "wrong argument type (fixnum required)"); } this = FIX2INT(p); p = INT2FIX(this - *prev); if (FIX2INT(p) < 0) { rb_raise(rb_eArgError, "Encode failed: value becomes minus"); } *prev = this; } static VALUE rb_delta_code_tuples(VALUE obj, VALUE list, VALUE delta_size, VALUE unit_size, CodeFunc code) { enum { PREV_MAX = 128 }; int i, j; int dsize; int usize; long len; int prev[PREV_MAX]; VALUE *p; if (!(TYPE(list) == T_ARRAY && TYPE(delta_size) == T_FIXNUM && TYPE(unit_size) == T_FIXNUM && FIX2INT(delta_size) < PREV_MAX )) { rb_raise(rb_eTypeError, "wrong argument type"); } dsize = FIX2INT(delta_size); usize = FIX2INT(unit_size); len = RARRAY(list)->len; if (!(len % usize == 0 && dsize <= usize)) { rb_raise(rb_eArgError, "wrong argument size"); } p = RARRAY(list)->ptr; memset(prev, 0, sizeof(int) * dsize); for (i = 0; i < len; i += usize) { for (j = 0; j < dsize; j++) { code(p, i + j, prev + j); } } return list; } static VALUE rb_delta_decode_tuples(VALUE obj, VALUE list, VALUE delta_size, VALUE unit_size) { return rb_delta_code_tuples(obj, list, delta_size, unit_size, decode); } static VALUE rb_delta_encode_tuples(VALUE obj, VALUE list, VALUE delta_size, VALUE unit_size) { return rb_delta_code_tuples(obj, list, delta_size, unit_size, encode); } static VALUE rb_delta_code_fixnums(VALUE obj, VALUE list, CodeFunc code) { int i; long len; VALUE *p; int prev = 0; if (TYPE(list) != T_ARRAY) { rb_raise(rb_eTypeError, "wrong argument type"); } p = RARRAY(list)->ptr; len = RARRAY(list)->len; for (i = 0; i < len; i++) { code(p, i, &prev); } return list; } static VALUE rb_delta_decode_fixnums(VALUE obj, VALUE list) { rb_delta_code_fixnums(obj, list, decode); } static VALUE rb_delta_encode_fixnums(VALUE obj, VALUE list) { rb_delta_code_fixnums(obj, list, encode); } void Init_delta() { VALUE mGonzui, mDelta; mGonzui = rb_define_module("Gonzui"); mDelta = rb_define_module_under(mGonzui, "DeltaDumper"); rb_define_module_function(mDelta, "encode_tuples", rb_delta_encode_tuples, 3); rb_define_module_function(mDelta, "decode_tuples", rb_delta_decode_tuples, 3); rb_define_module_function(mDelta, "encode_fixnums", rb_delta_encode_fixnums, 1); rb_define_module_function(mDelta, "decode_fixnums", rb_delta_decode_fixnums, 1); } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 谢谢! |