Ticket #230: search-xapian-generate-errors.04.patch
File search-xapian-generate-errors.04.patch, 29.2 KB (added by , 17 years ago) |
---|
-
XS/BM25Weight.xs
=== XS/BM25Weight.xs ==================================================================
5 5 BM25Weight * 6 6 new1() 7 7 CODE: 8 try { 8 9 RETVAL = new BM25Weight(); 10 } catch (...) { 11 handleException(); 12 } 9 13 OUTPUT: 10 14 RETVAL 11 15 … … 17 21 double b 18 22 double min_normlen 19 23 CODE: 20 RETVAL = new BM25Weight(k1, k2, k3, b, min_normlen); 24 try { 25 RETVAL = new BM25Weight(k1, k2, k3, b, min_normlen); 26 } catch (...) { 27 handleException(); 28 } 21 29 OUTPUT: 22 30 RETVAL 23 31 -
XS/BoolWeight.xs
=== XS/BoolWeight.xs ==================================================================
5 5 BoolWeight * 6 6 new1() 7 7 CODE: 8 RETVAL = new BoolWeight(); 8 try { 9 RETVAL = new BoolWeight(); 10 } catch (...) { 11 handleException(); 12 } 9 13 OUTPUT: 10 14 RETVAL 11 15 -
XS/Database.xs
=== XS/Database.xs ==================================================================
6 6 new1(file) 7 7 string file 8 8 CODE: 9 9 try { 10 10 RETVAL = new Database(file); 11 } 12 catch (const Error &error) { 13 croak( "Exception: %s", error.get_msg().c_str() ); 14 } 11 } catch (...) { 12 handleException(); 13 } 15 14 OUTPUT: 16 15 RETVAL 17 16 … … 19 18 new2(database) 20 19 Database * database 21 20 CODE: 22 21 try { 23 22 RETVAL = new Database(*database); 24 } 25 catch (const Error &error) { 26 croak( "Exception: %s", error.get_msg().c_str() ); 27 } 23 } catch (...) { 24 handleException(); 25 } 28 26 OUTPUT: 29 27 RETVAL 30 28 … … 32 30 Database::add_database(database) 33 31 Database * database 34 32 CODE: 35 33 try { 36 34 THIS->add_database(*database); 37 } 38 catch (const Error &error) { 39 croak( "Exception: %s", error.get_msg().c_str() ); 40 } 35 } catch (...) { 36 handleException(); 37 } 41 38 42 39 void 43 40 Database::reopen() 44 41 CODE: 45 try { 46 THIS->reopen(); 47 } 48 catch (const Error &error) { 49 croak( "Exception: %s", error.get_msg().c_str() ); 50 } 42 try { 43 THIS->reopen(); 44 } catch (...) { 45 handleException(); 46 } 51 47 52 48 string 53 49 Database::get_description() 54 50 CODE: 55 try { 56 RETVAL = THIS->get_description(); 57 } 58 catch (const Error &error) { 59 croak( "Exception: %s", error.get_msg().c_str() ); 60 } 51 try { 52 RETVAL = THIS->get_description(); 53 } catch (...) { 54 handleException(); 55 } 61 56 OUTPUT: 62 57 RETVAL 63 58 … … 65 60 Database::termlist_begin(did) 66 61 docid did 67 62 CODE: 68 63 try { 69 64 RETVAL = new TermIterator(THIS->termlist_begin(did)); 70 } 71 catch (const Error &error) { 72 croak( "Exception: %s", error.get_msg().c_str() ); 73 } 65 } catch (...) { 66 handleException(); 67 } 74 68 OUTPUT: 75 69 RETVAL 76 70 … … 78 72 Database::termlist_end(did) 79 73 docid did 80 74 CODE: 81 75 try { 82 76 RETVAL = new TermIterator(THIS->termlist_end(did)); 83 } 84 catch (const Error &error) { 85 croak( "Exception: %s", error.get_msg().c_str() ); 86 } 77 } catch (...) { 78 handleException(); 79 } 87 80 OUTPUT: 88 81 RETVAL 89 82 … … 92 85 docid did 93 86 string term 94 87 CODE: 95 88 try { 96 89 RETVAL = new PositionIterator(THIS->positionlist_begin(did, term)); 97 } 98 catch (const Error &error) { 99 croak( "Exception: %s", error.get_msg().c_str() ); 100 } 90 } catch (...) { 91 handleException(); 92 } 101 93 OUTPUT: 102 94 RETVAL 103 95 … … 106 98 docid did 107 99 string term 108 100 CODE: 109 101 try { 110 102 RETVAL = new PositionIterator(THIS->positionlist_end(did, term)); 111 } 112 catch (const Error &error) { 113 croak( "Exception: %s", error.get_msg().c_str() ); 114 } 103 } catch (...) { 104 handleException(); 105 } 115 106 OUTPUT: 116 107 RETVAL 117 108 … … 119 110 Database::allterms_begin(prefix = "") 120 111 string prefix 121 112 CODE: 122 113 try { 123 114 RETVAL = new TermIterator(THIS->allterms_begin(prefix)); 124 } 125 catch (const Error &error) { 126 croak( "Exception: %s", error.get_msg().c_str() ); 127 } 115 } catch (...) { 116 handleException(); 117 } 128 118 OUTPUT: 129 119 RETVAL 130 120 … … 132 122 Database::allterms_end(prefix = "") 133 123 string prefix 134 124 CODE: 135 125 try { 136 126 RETVAL = new TermIterator(THIS->allterms_end(prefix)); 137 } 138 catch (const Error &error) { 139 croak( "Exception: %s", error.get_msg().c_str() ); 140 } 127 } catch (...) { 128 handleException(); 129 } 141 130 OUTPUT: 142 131 RETVAL 143 132 … … 145 134 Database::postlist_begin(term) 146 135 string term 147 136 CODE: 148 137 try { 149 138 RETVAL = new PostingIterator(THIS->postlist_begin(term)); 150 } 151 catch (const Error &error) { 152 croak( "Exception: %s", error.get_msg().c_str() ); 153 } 139 } catch (...) { 140 handleException(); 141 } 154 142 OUTPUT: 155 143 RETVAL 156 144 … … 158 146 Database::postlist_end(term) 159 147 string term 160 148 CODE: 161 149 try { 162 150 RETVAL = new PostingIterator(THIS->postlist_end(term)); 163 } 164 catch (const Error &error) { 165 croak( "Exception: %s", error.get_msg().c_str() ); 166 } 151 } catch (...) { 152 handleException(); 153 } 167 154 OUTPUT: 168 155 RETVAL 169 156 170 157 doccount 171 158 Database::get_doccount() 172 159 CODE: 173 try { 174 RETVAL = THIS->get_doccount(); 175 } 176 catch (const Error &error) { 177 croak( "Exception: %s", error.get_msg().c_str() ); 178 } 160 try { 161 RETVAL = THIS->get_doccount(); 162 } catch (...) { 163 handleException(); 164 } 179 165 OUTPUT: 180 166 RETVAL 181 167 182 168 docid 183 169 Database::get_lastdocid() 184 170 CODE: 185 try { 186 RETVAL = THIS->get_lastdocid(); 187 } 188 catch (const Error &error) { 189 croak( "Exception: %s", error.get_msg().c_str() ); 190 } 171 try { 172 RETVAL = THIS->get_lastdocid(); 173 } catch (...) { 174 handleException(); 175 } 191 176 OUTPUT: 192 177 RETVAL 193 178 194 179 doclength 195 180 Database::get_avlength() 196 181 CODE: 197 try { 198 RETVAL = THIS->get_avlength(); 199 } 200 catch (const Error &error) { 201 croak( "Exception: %s", error.get_msg().c_str() ); 202 } 182 try { 183 RETVAL = THIS->get_avlength(); 184 } catch (...) { 185 handleException(); 186 } 203 187 OUTPUT: 204 188 RETVAL 205 189 … … 207 191 Database::get_termfreq(tname) 208 192 string tname 209 193 CODE: 210 try { 211 RETVAL = THIS->get_termfreq(tname); 212 } 213 catch (const Error &error) { 214 croak( "Exception: %s", error.get_msg().c_str() ); 215 } 194 try { 195 RETVAL = THIS->get_termfreq(tname); 196 } catch (...) { 197 handleException(); 198 } 216 199 OUTPUT: 217 200 RETVAL 218 201 … … 220 203 Database::term_exists(tname) 221 204 string tname 222 205 CODE: 223 206 try { 224 207 RETVAL = THIS->term_exists(tname); 225 } 226 catch (const Error &error) { 227 croak( "Exception: %s", error.get_msg().c_str() ); 228 } 208 } catch (...) { 209 handleException(); 210 } 229 211 OUTPUT: 230 212 RETVAL 231 213 … … 233 215 Database::get_collection_freq(tname) 234 216 string tname 235 217 CODE: 236 218 try { 237 219 RETVAL = THIS->get_collection_freq(tname); 238 } 239 catch (const Error &error) { 240 croak( "Exception: %s", error.get_msg().c_str() ); 241 } 220 } catch (...) { 221 handleException(); 222 } 242 223 OUTPUT: 243 224 RETVAL 244 225 … … 246 227 Database::get_doclength(did) 247 228 docid did 248 229 CODE: 249 230 try { 250 231 RETVAL = THIS->get_doclength(did); 251 } 252 catch (const Error &error) { 253 croak( "Exception: %s", error.get_msg().c_str() ); 254 } 232 } catch (...) { 233 handleException(); 234 } 255 235 OUTPUT: 256 236 RETVAL 257 237 258 238 void 259 239 Database::keep_alive() 260 240 CODE: 261 241 try { 262 242 THIS->keep_alive(); 263 } 264 catch (const Error &error) { 265 croak( "Exception: %s", error.get_msg().c_str() ); 266 } 243 } catch (...) { 244 handleException(); 245 } 267 246 268 247 Document * 269 248 Database::get_document(docid did) 270 249 CODE: 271 250 try { 272 251 RETVAL = new Document(THIS->get_document(did)); 273 } 274 catch (const Error &error) { 275 croak( "Exception: %s", error.get_msg().c_str() ); 276 } 252 } catch (...) { 253 handleException(); 254 } 277 255 OUTPUT: 278 256 RETVAL 279 257 -
XS/Enquire.xs
=== XS/Enquire.xs ==================================================================
6 6 Enquire::new(databases) 7 7 Database * databases 8 8 CODE: 9 try { 9 10 RETVAL = new Enquire(*databases); 11 } catch (...) { 12 handleException(); 13 } 10 14 OUTPUT: 11 15 RETVAL 12 16 … … 14 18 Enquire::set_query1(query) 15 19 Query * query 16 20 CODE: 17 THIS->set_query(*query); 21 try { 22 THIS->set_query(*query); 23 } catch (...) { 24 handleException(); 25 } 18 26 19 27 void 20 28 Enquire::set_query2(query, len) 21 29 Query * query 22 30 termcount len 23 31 CODE: 24 THIS->set_query(*query, len); 32 try { 33 THIS->set_query(*query, len); 34 } catch (...) { 35 handleException(); 36 } 25 37 26 38 Query * 27 39 Enquire::get_query(); 28 40 CODE: 41 try { 29 42 RETVAL = new Query(THIS->get_query()); 43 } catch (...) { 44 handleException(); 45 } 30 46 OUTPUT: 31 47 RETVAL 32 48 … … 34 50 Enquire::set_collapse_key(collapse_key) 35 51 valueno collapse_key 36 52 CODE: 53 try { 37 54 THIS->set_collapse_key(collapse_key); 38 55 } catch (...) { 56 handleException(); 57 } 58 39 59 void 40 60 Enquire::set_docid_order(order) 41 61 int order 42 62 CODE: 63 try { 43 64 THIS->set_docid_order(static_cast<Enquire::docid_order>(order)); 44 65 } catch (...) { 66 handleException(); 67 } 68 45 69 void 46 70 Enquire::set_cutoff(percent_cutoff, weight_cutoff = NO_INIT) 47 71 percent percent_cutoff 48 72 weight weight_cutoff 49 73 CODE: 74 try { 50 75 if (items == 3) { /* items includes the hidden this pointer */ 51 76 THIS->set_cutoff(percent_cutoff, weight_cutoff); 52 77 } else { 53 78 THIS->set_cutoff(percent_cutoff); 54 79 } 55 80 } catch (...) { 81 handleException(); 82 } 83 56 84 void 57 85 Enquire::set_sort_by_relevance() 58 86 … … 61 89 valueno sort_key 62 90 bool ascending 63 91 CODE: 64 if (items == 3) { /* items includes the hidden this pointer */ 65 THIS->set_sort_by_value(sort_key, ascending); 66 } else { 67 THIS->set_sort_by_value(sort_key); 68 } 69 92 try { 93 if (items == 3) { /* items includes the hidden this pointer */ 94 THIS->set_sort_by_value(sort_key, ascending); 95 } else { 96 THIS->set_sort_by_value(sort_key); 97 } 98 } catch (...) { 99 handleException(); 100 } 101 70 102 void 71 103 Enquire::set_sort_by_value_then_relevance(sort_key, ascending = NO_INIT) 72 104 valueno sort_key 73 105 bool ascending 74 106 CODE: 75 if (items == 3) { /* items includes the hidden this pointer */ 76 THIS->set_sort_by_value_then_relevance(sort_key, ascending); 77 } else { 78 THIS->set_sort_by_value_then_relevance(sort_key); 79 } 107 try { 108 if (items == 3) { /* items includes the hidden this pointer */ 109 THIS->set_sort_by_value_then_relevance(sort_key, ascending); 110 } else { 111 THIS->set_sort_by_value_then_relevance(sort_key); 112 } 113 } catch (...) { 114 handleException(); 115 } 80 116 81 117 void 82 118 Enquire::set_sort_by_relevance_then_value(sort_key, ascending = NO_INIT) 83 119 valueno sort_key 84 120 bool ascending 85 121 CODE: 86 if (items == 3) { /* items includes the hidden this pointer */ 87 THIS->set_sort_by_relevance_then_value(sort_key, ascending); 88 } else { 89 THIS->set_sort_by_relevance_then_value(sort_key); 90 } 122 try { 123 if (items == 3) { /* items includes the hidden this pointer */ 124 THIS->set_sort_by_relevance_then_value(sort_key, ascending); 125 } else { 126 THIS->set_sort_by_relevance_then_value(sort_key); 127 } 128 } catch (...) { 129 handleException(); 130 } 91 131 92 132 void 93 133 Enquire::set_sort_by_key(sorter, ascending = NO_INIT) 94 134 MultiValueSorter * sorter 95 135 bool ascending 96 136 CODE: 97 // FIXME: no corresponding SvREFCNT_dec(), but a leak seems better than 98 // a SEGV! 99 SvREFCNT_inc(ST(1)); 100 if (items == 3) { /* items includes the hidden this pointer */ 101 THIS->set_sort_by_key(sorter, ascending); 102 } else { 103 THIS->set_sort_by_key(sorter); 104 } 137 try { 138 // FIXME: no corresponding SvREFCNT_dec(), but a leak seems better than 139 // a SEGV! 140 SvREFCNT_inc(ST(1)); 141 if (items == 3) { /* items includes the hidden this pointer */ 142 THIS->set_sort_by_key(sorter, ascending); 143 } else { 144 THIS->set_sort_by_key(sorter); 145 } 146 } catch (...) { 147 handleException(); 148 } 149 105 150 106 151 void 107 152 Enquire::set_sort_by_key_then_relevance(sorter, ascending = NO_INIT) 108 153 MultiValueSorter * sorter 109 154 bool ascending 110 155 CODE: 111 // FIXME: no corresponding SvREFCNT_dec(), but a leak seems better than 112 // a SEGV! 113 SvREFCNT_inc(ST(1)); 114 if (items == 3) { /* items includes the hidden this pointer */ 115 THIS->set_sort_by_key_then_relevance(sorter, ascending); 116 } else { 117 THIS->set_sort_by_key_then_relevance(sorter); 118 } 156 try { 157 // FIXME: no corresponding SvREFCNT_dec(), but a leak seems better than 158 // a SEGV! 159 SvREFCNT_inc(ST(1)); 160 if (items == 3) { /* items includes the hidden this pointer */ 161 THIS->set_sort_by_key_then_relevance(sorter, ascending); 162 } else { 163 THIS->set_sort_by_key_then_relevance(sorter); 164 } 165 } catch (...) { 166 handleException(); 167 } 119 168 120 169 void 121 170 Enquire::set_sort_by_relevance_then_key(sorter, ascending = NO_INIT) 122 171 MultiValueSorter * sorter 123 172 bool ascending 124 173 CODE: 125 // FIXME: no corresponding SvREFCNT_dec(), but a leak seems better than 126 // a SEGV! 127 SvREFCNT_inc(ST(1)); 128 if (items == 3) { /* items includes the hidden this pointer */ 129 THIS->set_sort_by_relevance_then_key(sorter, ascending); 130 } else { 131 THIS->set_sort_by_relevance_then_key(sorter); 132 } 174 try { 175 // FIXME: no corresponding SvREFCNT_dec(), but a leak seems better than 176 // a SEGV! 177 SvREFCNT_inc(ST(1)); 178 if (items == 3) { /* items includes the hidden this pointer */ 179 THIS->set_sort_by_relevance_then_key(sorter, ascending); 180 } else { 181 THIS->set_sort_by_relevance_then_key(sorter); 182 } 183 } catch (...) { 184 handleException(); 185 } 186 133 187 134 188 MSet * 135 189 Enquire::get_mset1(first, maxitems, checkatleast = NO_INIT, rset = NO_INIT, func = NO_INIT) … … 139 193 RSet * rset 140 194 SV * func 141 195 CODE: 142 MSet mset; 143 switch (items) { /* items includes the hidden this pointer */ 144 case 3: 145 mset = THIS->get_mset(first, maxitems); 146 break; 147 case 4: 148 mset = THIS->get_mset(first, maxitems, checkatleast); 149 break; 150 case 5: 151 mset = THIS->get_mset(first, maxitems, checkatleast, rset); 152 break; 153 case 6: { 154 perlMatchDecider d = perlMatchDecider(func); 155 mset = THIS->get_mset(first, maxitems, checkatleast, rset, &d); 156 break; 157 } 158 default: 159 croak("Bad parameter count for get_mset1"); 160 } 161 RETVAL = new MSet(mset); 196 try { 197 MSet mset; 198 switch (items) { /* items includes the hidden this pointer */ 199 case 3: { 200 mset = THIS->get_mset(first, maxitems); 201 break; 202 } 203 case 4: { 204 mset = THIS->get_mset(first, maxitems, checkatleast); 205 break; 206 } 207 case 5: { 208 mset = THIS->get_mset(first, maxitems, checkatleast, rset); 209 break; 210 } 211 case 6: { 212 perlMatchDecider d = perlMatchDecider(func); 213 mset = THIS->get_mset(first, maxitems, checkatleast, rset, &d); 214 break; 215 } 216 default: 217 croak("Bad parameter count for get_mset1"); 218 } 219 RETVAL = new MSet(mset); 220 } catch (...) { 221 handleException(); 222 } 162 223 OUTPUT: 163 224 RETVAL 164 225 … … 168 229 doccount maxitems 169 230 SV * func 170 231 CODE: 171 perlMatchDecider d = perlMatchDecider(func); 172 RETVAL = new MSet(THIS->get_mset(first, maxitems, 0, NULL, &d)); 232 try { 233 perlMatchDecider d = perlMatchDecider(func); 234 RETVAL = new MSet(THIS->get_mset(first, maxitems, 0, NULL, &d)); 235 } catch (...) { 236 handleException(); 237 } 173 238 OUTPUT: 174 239 RETVAL 175 240 … … 178 243 doccount maxitems 179 244 RSet * rset 180 245 CODE: 246 try { 181 247 RETVAL = new ESet(THIS->get_eset(maxitems, *rset)); 248 } catch (...) { 249 handleException(); 250 } 182 251 OUTPUT: 183 252 RETVAL 184 253 185 254 TermIterator * 186 255 Enquire::get_matching_terms_begin1(docid did) 187 256 CODE: 257 try { 188 258 RETVAL = new TermIterator(THIS->get_matching_terms_begin(did)); 259 } catch (...) { 260 handleException(); 261 } 189 262 OUTPUT: 190 263 RETVAL 191 264 192 265 TermIterator * 193 266 Enquire::get_matching_terms_begin2(it) 194 267 MSetIterator * it 195 268 CODE: 269 try { 196 270 RETVAL = new TermIterator(THIS->get_matching_terms_begin(* it)); 271 } catch (...) { 272 handleException(); 273 } 197 274 OUTPUT: 198 275 RETVAL 199 276 200 277 TermIterator * 201 278 Enquire::get_matching_terms_end1(docid did) 202 279 CODE: 280 try { 203 281 RETVAL = new TermIterator(THIS->get_matching_terms_end(did)); 282 } catch (...) { 283 handleException(); 284 } 204 285 OUTPUT: 205 286 RETVAL 206 287 207 288 TermIterator * 208 289 Enquire::get_matching_terms_end2(it) 209 290 MSetIterator * it 210 291 CODE: 292 try { 211 293 RETVAL = new TermIterator(THIS->get_matching_terms_end(* it)); 294 } catch (...) { 295 handleException(); 296 } 212 297 OUTPUT: 213 298 RETVAL 214 299 … … 216 301 Enquire::set_weighting_scheme(weight_) 217 302 Weight * weight_ 218 303 CODE: 219 THIS->set_weighting_scheme(*weight_); 304 try { 305 THIS->set_weighting_scheme(*weight_); 306 } catch (...) { 307 handleException(); 308 } 220 309 221 310 222 311 string -
Xapian.pm
=== Xapian.pm ==================================================================
12 12 use Search::Xapian::Document; 13 13 use Search::Xapian::ESet; 14 14 use Search::Xapian::ESetIterator; 15 use Search::Xapian::Error; 15 16 use Search::Xapian::MSet; 16 17 use Search::Xapian::MSetIterator; 17 18 use Search::Xapian::MultiValueSorter; -
Xapian.xs
=== Xapian.xs ==================================================================
13 13 #ifdef __cplusplus 14 14 } 15 15 #endif 16 #undef get_context 16 17 17 18 using namespace std; 18 19 using namespace Xapian; 19 20 21 #include "handleException.c" 22 20 23 /* PerlStopper class 21 24 * 22 25 * Make operator() call Perl $OBJECT->stop_word … … 121 124 INCLUDE: XS/MSet.xs 122 125 INCLUDE: XS/MSetIterator.xs 123 126 INCLUDE: XS/ESet.xs 127 INCLUDE: XS/Error.xs 124 128 INCLUDE: XS/ESetIterator.xs 125 129 INCLUDE: XS/RSet.xs 126 130 INCLUDE: XS/MultiValueSorter.xs -
t/databasemodified.t
=== t/databasemodified.t ==================================================================
1 # Before `make install' is performed this script should be runnable with 2 # `make test'. After `make install' it should work as `perl test.pl' 3 4 ######################### 5 6 # change 'tests => 1' to 'tests => last_test_to_print'; 7 8 use Test; 9 use Devel::Peek; 10 BEGIN { plan tests => 5 }; 11 use Search::Xapian qw(:standard); 12 ok(1); # If we made it this far, we're ok. 13 14 ######################### 15 16 # Insert your test code below, the Test module is use()ed here so read 17 # its man page ( perldoc Test ) for help writing this test script. 18 19 # first create database dir, if it doesn't exist; 20 my $db_dir = 'testdb-exception-modified'; 21 22 if( (! -e $db_dir) or (! -d $db_dir) ) { 23 mkdir( $db_dir ); 24 } 25 26 opendir( DB_DIR, $db_dir ); 27 while( defined( my $file = readdir( DB_DIR ) ) ) { 28 next if $file =~ /^\.+$/; 29 unlink( "$db_dir/$file" ) or die "Could not delete '$db_dir/$file': $!"; 30 } 31 closedir( DB_DIR ); 32 33 my $create = Search::Xapian::WritableDatabase->new( $db_dir, [Search::Xapian::DB_CREATE, 4096]); 34 35 $create = undef; 36 37 my $read = Search::Xapian::Database->new( $db_dir ); 38 39 my $write = Search::Xapian::WritableDatabase->new( $db_dir, Search::Xapian::DB_CREATE_OR_OPEN ); 40 41 42 43 my $enq = $read->enquire(OP_OR, "test"); 44 45 # lets try to index something 46 my $term = 'test'; 47 48 my $docid; 49 for my $num (1..1000) { 50 my $doc = Search::Xapian::Document->new(); 51 52 $doc->set_data( "$term $num" ); 53 54 $doc->add_posting( $term, 0 ); 55 $doc->add_posting( $num, 1 ); 56 57 $doc->add_value(0, $num); 58 $write->add_document( $doc ); 59 60 } 61 $write->flush(); 62 $read->reopen(); 63 64 for my $num qw (three four five) { 65 my $doc = Search::Xapian::Document->new(); 66 67 $doc->set_data( "$term $num" ); 68 69 $doc->add_posting( $term, 0 ); 70 $doc->add_posting( $num, 1 ); 71 72 $doc->add_value(0, $num); 73 $write->add_document( $doc ); 74 $write->flush(); 75 } 76 $write->flush(); 77 #$read->reopen(); 78 #yay 79 eval { 80 my $mset = $enq->get_mset(0, 10); 81 }; 82 ok($@); 83 ok(ref($@), "Search::Xapian::DatabaseModifiedError", "correct class for exception"); 84 ok(UNIVERSAL::isa($@, 'Search::Xapian::Error')); 85 86 ok($@->get_msg, "The revision being read has been discarded - you should call Xapian::Database::reopen() and retry the operation", "get_msg works"); 87 88 1; -
generate_exception_modules.pl
=== generate_exception_modules.pl ==================================================================
1 #!/usr/bin/perl 2 3 # Author: Andreas Marienborg <andreas.marienborg@gmail.com> 4 # Donated as is to xapian project. Use and modify as see fit 5 6 use strict; 7 use warnings; 8 9 use Template; 10 11 BEGIN { 12 my $l = shift; 13 if (!defined($l) or $l eq '') { 14 die <<END; 15 First parameter should be directory where 'exception_data.pm' can be found 16 It will be added to INC for this session. 17 END 18 } 19 push(@INC, $l); 20 21 } 22 # We could default to ".", as that is the most logical, but I prefer a 23 # propper "Yes, I do want to create it here, since it modifies some files" 24 25 my $path = shift or die "No second parameter (output-path) specified"; 26 27 mkdir($path) unless -d $path; 28 mkdir("$path/Xapian") unless -d "$path/Xapian"; 29 mkdir("$path/XS") unless -d "$path/XS"; 30 31 # We load the exception data from xapian-core. 32 use exception_data qw(@baseclasses @classes); 33 34 my $classes = parse_classes(@baseclasses, @classes); 35 my $templates = read_templates(); 36 37 # create a template-toolkit object that we use troughout 38 my $tt = Template->new(); 39 #die dump($templates); 40 41 # render is recursive, rendering all children on the class etc 42 render($tt, $classes->{'Error'}); 43 44 45 # fix typemap 46 open(my $TM, "<", "typemap") or die "cannot read 'typemap': $!"; 47 my @tm = <$TM>; 48 close($TM); 49 50 51 # Need to find the position of the Error definitions. Any missing 52 # exception-classes will be added after that. 53 # Since typemap is a "dumb" file, we modify it in place 54 55 my $pos = 0; 56 foreach (@tm) { 57 $pos++; 58 last if (/^Error \*/); 59 } 60 foreach my $cls (keys %$classes) { 61 $cls = $cls; 62 63 warn "checking for $cls\n"; 64 if (!grep { /^$cls/} @tm) { 65 warn " not found, inserting at $pos\n"; 66 splice(@tm, $pos++, 0, "$cls\tO_OBJECT\n"); 67 splice(@tm, $pos++, 0, "$cls *\tO_OBJECT\n"); 68 69 } 70 } 71 # truncate and output 72 open($TM, ">", "typemap") or die "cannot write 'typemap': $!"; 73 print $TM join("", @tm); 74 close $TM; 75 76 # The exception catching in C needs to be properly sorted 77 # with the rightmost class first (the ones without children) 78 # order_children creates a flat tree 79 my $ordered_classes = order_children($classes->{'Error'}); 80 81 # write new handleException.h 82 { 83 my $t = $templates->{'handleException'}; 84 $tt->process(\$t, { 85 'classes' => $ordered_classes 86 }, "handleException.c") || die $tt->error; 87 } 88 # done!; 89 exit(0); 90 91 sub render { 92 my $tt = shift; 93 my $class = shift; 94 return unless $class->{class}; 95 warn "rendering " . $class->{class}; 96 my $t = $class->{class} eq 'Error' ? $templates->{'Error.pm'} : $templates->{'Children.pm'}; 97 my $xs_t = $templates->{'Error.xs'}; 98 $tt->process(\$t, { 99 'class' => $class 100 }, "$path/Xapian/" . $class->{class} . ".pm") || die $tt->error; 101 $tt->process(\$xs_t, { 102 'class' => $class 103 }, "$path/XS/" . $class->{class} . ".xs") || die $tt->error; 104 foreach my $child (@{$class->{children}}) { 105 render($tt, $child); 106 } 107 108 } 109 110 # returns an ordered list of decreasing catch-priority 111 112 sub order_children { 113 my $class = shift; 114 my @o; 115 if ($class->{children}) { 116 foreach (@{ $class->{children}}) { 117 push(@o, order_children($_)); 118 } 119 } 120 push @o, $class; 121 return wantarray ? @o : \@o; 122 } 123 124 # parses trough the classes found and builds a hash-structure of it 125 126 sub parse_classes { 127 my $classes = { 128 'Error' => { 129 'class' => 'Error', 130 } 131 }; 132 foreach (@_) { 133 my ($cls, $parent, $description) = split /\t/; 134 print $cls . " - " . $parent . "\n"; 135 $description =~ s!^(/| )\*(\*|/|)!!mg; 136 $description =~ s!\*/$!!mg; 137 my ($head, $desc) = split('\n\n', $description, 2) if ($description =~ m/\n\n/); 138 139 #only one line of description 140 $head = $description if (!$head); 141 my $class = { 142 'class' => $cls, 143 'parent' => $parent, 144 'orig_desc' => $description, 145 'header' => $head, 146 'description' => $desc 147 }; 148 push(@{ $classes->{$parent}->{children}}, $class); 149 $classes->{$cls} = $class; 150 } 151 return $classes; 152 153 } 154 155 # this reads trough our templates in __DATA__ and parses it into 156 # different sections 157 158 sub read_templates { 159 my $templates = {}; 160 my $templ = ''; 161 my @t; 162 while (<DATA>) { 163 next if (/^\s*$/) && !$templ; 164 if (/^# TMPL (.*)/) { 165 # new template found 166 if ($templ) { 167 # save old template 168 $templates->{$templ} = join('', @t); 169 @t = (); 170 } 171 $templ = $1; 172 } else { 173 push(@t, $_); 174 # print "$templ : $_"; 175 } 176 177 } 178 $templates->{$templ} = join('', @t); 179 return $templates; 180 } 181 1; 182 183 __DATA__ 184 185 # TMPL Error.pm 186 package Search::Xapian::Error; 187 188 =head1 NAME 189 190 Search::Xapian::[% class.class %] - Base-class for all exceptions in Search::Xapian 191 192 =head1 DESCRIPTION 193 194 This class is an abstract class in C++, it cannot be instanated itself. In perl there 195 is no such concept, but you should not need to create instances of theese objects 196 yourself. 197 198 =head1 METHODS 199 200 All exception-objects has the following methods 201 202 =head2 get_msg 203 204 Returns a string with a descriptive error message, useful for outputing 205 206 =head2 get_type 207 208 The type of this error (e.g. "DocNotFoundError".). 209 210 =head2 get_context 211 212 Optional context information, returned as a string 213 214 =head2 get_errno 215 216 Returns the errno for this error (optional) 217 218 =cut 219 220 use 5.006; 221 use strict; 222 use warnings; 223 use Carp; 224 225 require DynaLoader; 226 227 [% FOR cls IN class.children -%] 228 use Search::Xapian::[% cls.class %]; 229 [% END %] 230 our @ISA = qw(DynaLoader); 231 232 # Preloaded methods go here. 233 234 # In a new thread, copy objects of this class to unblessed, undef values. 235 sub CLONE_SKIP { 1 } 236 237 sub new { 238 my $class = shift; 239 my ($self); 240 bless $self, $class; 241 242 return $self; 243 } 244 245 1; 246 247 248 # TMPL Error.xs 249 MODULE = Search::Xapian PACKAGE = Search::Xapian::[% class.class %] 250 251 PROTOTYPES: ENABLE 252 253 string 254 [% class.class %]::get_type() 255 256 string 257 [% class.class %]::get_msg() 258 259 string 260 [% class.class %]::get_context() 261 262 int 263 [% class.class %]::get_errno() 264 265 void 266 [% class.class %]::DESTROY() 267 268 [% FOR cls IN class.children -%] 269 INCLUDE: XS/[% cls.class %].xs 270 [% END %] 271 272 # TMPL Children.pm 273 package Search::Xapian::[% class.class %]; 274 275 =head1 NAME 276 277 Search::Xapian::[% class.class %] - [% class.header %] 278 279 =head1 DESCRIPTION 280 281 [% class.description -%] 282 =cut 283 284 use 5.006; 285 use strict; 286 use warnings; 287 use Carp; 288 289 require DynaLoader; 290 [% FOR cls IN class.children -%] 291 use Search::Xapian::[% cls.class %]; 292 [% END %] 293 294 our @ISA = qw(DynaLoader Search::Xapian::[% class.parent %]); 295 296 1; 297 298 # TMPL handleException 299 /* handleException function 300 * 301 * called in catch-blocks to croak or rethrow in perl-land 302 */ 303 304 int handleException() { 305 306 try { 307 throw; 308 [% FOR cls IN classes %] 309 } catch (const Xapian::[% cls.class %] & error) { 310 SV * errsv; 311 errsv = get_sv("@", TRUE); 312 sv_setref_pv(errsv, "Search::Xapian::[% cls.class %]", (void *) new [% cls.class %](error)); 313 croak(Nullch); 314 [% END %] 315 } catch (const std::exception & error) { 316 croak( "std::exception: %s", error.what()); 317 } catch (...) { 318 croak("something terrible happend"); 319 } 320 }