View Single Post
Old 2018-04-27, 16:12   #14
jcrombie
 
jcrombie's Avatar
 
"Jonathan"
Jul 2010
In a tangled web...

2·107 Posts
Default

Quote:
Originally Posted by jasonp View Post
The calls to exit() were a holdover from when the library was only used in one application and not the complete factoring frameworks we have now. Getting rid of them is easy but they need to be replaced with actual return paths that e.g. close any open files and propagate error information up. Not having this makes embedding libmsieve within application much harder.
If you're willing to mess with the code a bit, this should work. (I noticed msieve is now at version 1019, but all the modified files seem to be untouched since ver 1015).

Quote:
jcrombie@dads-pc:~/msieve/latest_for_yafu$ svn diff
Index: common/filter/filter.c
===================================================================
--- common/filter/filter.c (revision 1015)
+++ common/filter/filter.c (working copy)
@@ -59,11 +59,11 @@
}

/*--------------------------------------------------------------------*/
-void filter_make_relsets(msieve_obj *obj, filter_t *filter,
+int filter_make_relsets(msieve_obj *obj, filter_t *filter,
merge_t *merge, uint32 min_cycles) {

filter_purge_cliques(obj, filter);
filter_merge_init(obj, filter);
filter_merge_2way(obj, filter, merge);
- filter_merge_full(obj, merge, min_cycles);
+ return filter_merge_full(obj, merge, min_cycles);
}
Index: common/filter/filter.h
===================================================================
--- common/filter/filter.h (revision 1015)
+++ common/filter/filter.h (working copy)
@@ -139,7 +139,7 @@
of relations. min_cycles is the absolute minimum number of
relation sets that are required */

-void filter_make_relsets(msieve_obj *obj, filter_t *filter,
+int filter_make_relsets(msieve_obj *obj, filter_t *filter,
merge_t *merge, uint32 min_cycles);

/* perform post-processing optimizations on the collection of cycles
Index: common/filter/filter_priv.h
===================================================================
--- common/filter/filter_priv.h (revision 1015)
+++ common/filter/filter_priv.h (working copy)
@@ -91,7 +91,7 @@
built (the actual matrix is expected to be much larger than
this). */

-void filter_merge_full(msieve_obj *obj, merge_t *merge, uint32 min_cycles);
+int filter_merge_full(msieve_obj *obj, merge_t *merge, uint32 min_cycles);

#ifdef __cplusplus
}
Index: common/filter/merge.c
===================================================================
--- common/filter/merge.c (revision 1015)
+++ common/filter/merge.c (working copy)
@@ -331,7 +331,7 @@
/*--------------------------------------------------------------------*/
#define NUM_CYCLE_BINS 9

-void filter_merge_full(msieve_obj *obj, merge_t *merge, uint32 min_cycles) {
+int filter_merge_full(msieve_obj *obj, merge_t *merge, uint32 min_cycles) {

/* The core of the NFS merge phase; this routine starts
with a collection of relation sets, each containing entries
@@ -621,7 +621,13 @@
if (num_cycles < 0.8 * target_cycles) {
logprintf(obj, "too few cycles, matrix probably "
"cannot build\n");
- exit(0); /* a non-zero exit code aborts factMsieve.pl */
+ matrix_weight_free(&mat_weight);
+ heap_free(&active_heap);
+ heap_free(&inactive_heap);
+ ideal_list_free(&ideal_list);
+ free(aux);
+ return 1;
+/* exit(0); *//* a non-zero exit code aborts factMsieve.pl */
}

qsort(relset_array, (size_t)num_cycles,
@@ -675,4 +681,5 @@
heap_free(&inactive_heap);
ideal_list_free(&ideal_list);
free(aux);
+ return 0;
}
Index: gnfs/filter/filter.c
===================================================================
--- gnfs/filter/filter.c (revision 1015)
+++ gnfs/filter/filter.c (working copy)
@@ -184,7 +184,9 @@
if (target_density != 0)
merge->target_density = target_density;

- filter_make_relsets(obj, filter, merge, extra_needed);
+ if ( filter_make_relsets(obj, filter, merge, extra_needed) != 0 )
+ return 1000000;
+
return 0;
}
jcrombie is offline   Reply With Quote