[libfann] 47/242: fixed some stuff with the error printing
Christian Kastner
chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:18 UTC 2014
This is an automated email from the git hooks/post-receive script.
chrisk-guest pushed a commit to tag Version2_0_0
in repository libfann.
commit d646cd405ccc36b5ec4c832001bf10c0b91b5216
Author: Steffen Nissen <lukesky at diku.dk>
Date: Mon Jan 12 22:40:13 2004 +0000
fixed some stuff with the error printing
---
src/fann.c | 16 ++++++++--------
src/fann_internal.c | 20 +++++++++++++++-----
src/include/fann_errno.h | 5 ++++-
3 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/src/fann.c b/src/fann.c
index f9b0f59..05623a0 100644
--- a/src/fann.c
+++ b/src/fann.c
@@ -61,10 +61,6 @@ struct fann * fann_create_array(float connection_rate, float learning_rate, unsi
#endif
fann_initialise_result_array(ann);
- /* Reset the errno/errstr information */
- fann_reset_errstr(ann);
- fann_reset_errno(ann);
-
/* determine how many neurons there should be in each layer */
i = 0;
for(layer_it = ann->first_layer; layer_it != ann->last_layer; layer_it++){
@@ -287,6 +283,11 @@ struct fann * fann_create_from_file(const char *configuration_file)
}
read_version = (char *)calloc(strlen(FANN_CONF_VERSION"\n"), 1);
+ if(read_version == NULL){
+ fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
+ return NULL;
+ }
+
fread(read_version, 1, strlen(FANN_CONF_VERSION"\n"), conf); /* reads version */
/* compares the version information */
@@ -294,6 +295,8 @@ struct fann * fann_create_from_file(const char *configuration_file)
fann_error(NULL, FANN_E_WRONG_CONFIG_VERSION, configuration_file);
return NULL;
}
+
+ free(read_version);
#ifdef FIXEDFANN
if(fscanf(conf, "%u\n", &decimal_point) != 1){
@@ -311,10 +314,6 @@ struct fann * fann_create_from_file(const char *configuration_file)
ann = fann_allocate_structure(learning_rate, num_layers);
ann->connection_rate = connection_rate;
- /* Reset the errno/errstr information */
- fann_reset_errstr(ann);
- fann_reset_errno(ann);
-
#ifdef FIXEDFANN
ann->decimal_point = decimal_point;
ann->multiplier = multiplier;
@@ -395,6 +394,7 @@ void fann_destroy(struct fann *ann)
free(ann->first_layer);
free(ann->output);
if(ann->train_deltas != NULL) free(ann->train_deltas);
+ fann_reset_errstr(ann); /* free ann->errstr if exists */
free(ann);
}
diff --git a/src/fann_internal.c b/src/fann_internal.c
index 3ada91c..408e416 100644
--- a/src/fann_internal.c
+++ b/src/fann_internal.c
@@ -52,6 +52,8 @@ struct fann * fann_allocate_structure(float learning_rate, unsigned int num_laye
ann->train_deltas = NULL;
ann->num_errors = 0;
ann->error_value = 0;
+ ann->errstr = NULL;
+ ann->errno_f = 0;
#ifdef FIXEDFANN
/* these values are only boring defaults, and should really
@@ -453,7 +455,11 @@ void fann_error(struct fann *ann, const unsigned int errno, ...)
unsigned int flag = 0;
char * errstr;
- errstr = (char *)malloc(FANN_ERRSTR_MAX);
+ if(ann != NULL && ann->errstr != NULL){
+ errstr = ann->errstr;
+ }else{
+ errstr = (char *)malloc(FANN_ERRSTR_MAX);
+ }
va_start(ap, errno);
switch ( errno ) {
@@ -489,14 +495,18 @@ void fann_error(struct fann *ann, const unsigned int errno, ...)
case FANN_E_CANT_READ_TD:
vsnprintf(errstr, FANN_ERRSTR_MAX, "Error reading info from train data file \"%s\", line: %d.\n", ap);
break;
+ case FANN_E_CANT_ALLOCATE_MEM:
+ snprintf(errstr, FANN_ERRSTR_MAX, "Unable to allocate memory.\n");
+ break;
default:
vsnprintf(errstr, FANN_ERRSTR_MAX, "Unknown error.\n", ap);
break;
}
va_end(ap);
- if ( ann == NULL )
- fprintf(stderr, "Error: %s\n", errstr);
- else
- ann->errstr = errstr;
+ if ( ann == NULL ) {
+ fprintf(stderr, "FANN Error %d: %s", errno, errstr);
+ } else {
+ ann->errstr = errstr;
+ }
}
diff --git a/src/include/fann_errno.h b/src/include/fann_errno.h
index 0510a4a..2ae9f94 100644
--- a/src/include/fann_errno.h
+++ b/src/include/fann_errno.h
@@ -59,7 +59,10 @@ enum {
FANN_E_CANT_OPEN_TD_R,
/* Error reading training data from file. */
- FANN_E_CANT_READ_TD
+ FANN_E_CANT_READ_TD,
+
+ /* Unable to allocate memory. */
+ FANN_E_CANT_ALLOCATE_MEM
};
#ifdef __cplusplus
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/libfann.git
More information about the debian-science-commits
mailing list