diff options
| author | Thomas Schmucker <ts@its1.de> | 2020-06-21 11:12:18 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2020-06-21 11:12:18 +0200 |
| commit | dd7e73ec6c990c23a08d4e82f050804caa9789df (patch) | |
| tree | 5091c9c5e79e7b632b588a897444f2aa18a3304b /csv.c | |
| parent | 4f23f3d2b3137ca369c5e27f833a13e329431505 (diff) | |
| download | libcsv-dd7e73ec6c990c23a08d4e82f050804caa9789df.tar.gz libcsv-dd7e73ec6c990c23a08d4e82f050804caa9789df.tar.bz2 libcsv-dd7e73ec6c990c23a08d4e82f050804caa9789df.zip | |
Benutze unterschiedliche Callback-Argumente für die Memory- und Error-Callback-Handler
Diffstat (limited to 'csv.c')
| -rw-r--r-- | csv.c | 14 |
1 files changed, 7 insertions, 7 deletions
| @@ -50,7 +50,7 @@ INLINE void | |||
| 50 | csv_fatal_error(const char *msg, const csv_options_t * const csv_options) | 50 | csv_fatal_error(const char *msg, const csv_options_t * const csv_options) |
| 51 | { | 51 | { |
| 52 | if ( csv_options->cb_error != NULL ) { | 52 | if ( csv_options->cb_error != NULL ) { |
| 53 | (*csv_options->cb_error)(msg, csv_options->cb_arg); | 53 | (*csv_options->cb_error)(msg, csv_options->cb_error_arg); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | fprintf(stderr, "fatal error: %s\n", msg); | 56 | fprintf(stderr, "fatal error: %s\n", msg); |
| @@ -95,7 +95,7 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t * const | |||
| 95 | 95 | ||
| 96 | if ( csv_string->pos == csv_string->cap ) { /* grow if needed */ | 96 | if ( csv_string->pos == csv_string->cap ) { /* grow if needed */ |
| 97 | if ( csv_string->str == NULL ) { /* first call? */ | 97 | if ( csv_string->str == NULL ) { /* first call? */ |
| 98 | if ( (csv_string->str = csv_options->cb_allocate(INITIAL_CAP, 1, csv_options->cb_arg)) == NULL ) { | 98 | if ( (csv_string->str = csv_options->cb_allocate(INITIAL_CAP, 1, csv_options->cb_memory_arg)) == NULL ) { |
| 99 | csv_fatal_error("out of memory...", csv_options); | 99 | csv_fatal_error("out of memory...", csv_options); |
| 100 | return; | 100 | return; |
| 101 | } | 101 | } |
| @@ -104,7 +104,7 @@ csv_string_append(csv_string_t *csv_string, char ch, const csv_options_t * const | |||
| 104 | } | 104 | } |
| 105 | else { /* subsequent call */ | 105 | else { /* subsequent call */ |
| 106 | int cap = (csv_string->cap * 3) / 2; /* *= 1.5 */ | 106 | int cap = (csv_string->cap * 3) / 2; /* *= 1.5 */ |
| 107 | char *str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_arg); | 107 | char *str = csv_options->cb_reallocate(csv_string->str, cap, 1, csv_options->cb_memory_arg); |
| 108 | if ( str == NULL ) { | 108 | if ( str == NULL ) { |
| 109 | csv_fatal_error("out of memory...", csv_options); | 109 | csv_fatal_error("out of memory...", csv_options); |
| 110 | return; | 110 | return; |
| @@ -123,7 +123,7 @@ csv_string_free(csv_string_t *csv_string, const csv_options_t * const csv_option | |||
| 123 | assert(csv_string != NULL); | 123 | assert(csv_string != NULL); |
| 124 | assert(csv_options != NULL); | 124 | assert(csv_options != NULL); |
| 125 | 125 | ||
| 126 | csv_options->cb_free(csv_string->str, csv_string->cap, csv_options->cb_arg); | 126 | csv_options->cb_free(csv_string->str, csv_string->cap, csv_options->cb_memory_arg); |
| 127 | 127 | ||
| 128 | /* call *_init() for sane default values; prevent possible double-free */ | 128 | /* call *_init() for sane default values; prevent possible double-free */ |
| 129 | csv_string_init(csv_string); | 129 | csv_string_init(csv_string); |
| @@ -159,7 +159,7 @@ csv_field_append(csv_field_t *csv_field, int idx, const csv_options_t * const cs | |||
| 159 | 159 | ||
| 160 | if ( csv_field->pos == csv_field->cap ) { /* grow if needed */ | 160 | if ( csv_field->pos == csv_field->cap ) { /* grow if needed */ |
| 161 | if ( csv_field->fields == NULL ) { | 161 | if ( csv_field->fields == NULL ) { |
| 162 | if ( (csv_field->fields = csv_options->cb_allocate(INITIAL_CAP, sizeof(csv_field->fields[0]), csv_options->cb_arg)) == NULL ) { | 162 | if ( (csv_field->fields = csv_options->cb_allocate(INITIAL_CAP, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg)) == NULL ) { |
| 163 | csv_fatal_error("out of memory", csv_options); | 163 | csv_fatal_error("out of memory", csv_options); |
| 164 | return; | 164 | return; |
| 165 | } | 165 | } |
| @@ -168,7 +168,7 @@ csv_field_append(csv_field_t *csv_field, int idx, const csv_options_t * const cs | |||
| 168 | } | 168 | } |
| 169 | else { | 169 | else { |
| 170 | int cap = (csv_field->cap * 3) / 2; /* *= 1.5 */ | 170 | int cap = (csv_field->cap * 3) / 2; /* *= 1.5 */ |
| 171 | int *fields = csv_options->cb_reallocate(csv_field->fields, cap, sizeof(csv_field->fields[0]), csv_options->cb_arg); | 171 | int *fields = csv_options->cb_reallocate(csv_field->fields, cap, sizeof(csv_field->fields[0]), csv_options->cb_memory_arg); |
| 172 | if ( fields == NULL ) { | 172 | if ( fields == NULL ) { |
| 173 | csv_fatal_error("out of memory", csv_options); | 173 | csv_fatal_error("out of memory", csv_options); |
| 174 | return; | 174 | return; |
| @@ -187,7 +187,7 @@ csv_field_free(csv_field_t *csv_field, const csv_options_t * const csv_options) | |||
| 187 | assert(csv_field != NULL); | 187 | assert(csv_field != NULL); |
| 188 | assert(csv_options != NULL); | 188 | assert(csv_options != NULL); |
| 189 | 189 | ||
| 190 | csv_options->cb_free(csv_field->fields, csv_field->cap, csv_options->cb_arg); | 190 | csv_options->cb_free(csv_field->fields, csv_field->cap, csv_options->cb_memory_arg); |
| 191 | 191 | ||
| 192 | csv_field_init(csv_field); | 192 | csv_field_init(csv_field); |
| 193 | } | 193 | } |
