mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-11-03 20:54:07 +01:00
use built-in trexio_text_free_group function for garbage collection
This commit is contained in:
parent
5eb697abcc
commit
68d34a0ace
@ -80,12 +80,12 @@
|
|||||||
#+begin_src c :tangle struct_text_group_dset.h
|
#+begin_src c :tangle struct_text_group_dset.h
|
||||||
typedef struct $group$_s {
|
typedef struct $group$_s {
|
||||||
$group_num_dtype_double$ $group_num$;
|
$group_num_dtype_double$ $group_num$;
|
||||||
bool $group_num$_isSet;
|
|
||||||
$group_dset_dtype$* $group_dset$;
|
$group_dset_dtype$* $group_dset$;
|
||||||
uint32_t rank_$group_dset$;
|
|
||||||
uint32_t to_flush;
|
|
||||||
uint64_t dims_$group_dset$[16];
|
uint64_t dims_$group_dset$[16];
|
||||||
uint64_t len_$group_str$;
|
uint64_t len_$group_str$;
|
||||||
|
uint32_t rank_$group_dset$;
|
||||||
|
uint32_t to_flush;
|
||||||
|
bool $group_num$_isSet;
|
||||||
char* $group_str$;
|
char* $group_str$;
|
||||||
char file_name[TREXIO_MAX_FILENAME_LENGTH];
|
char file_name[TREXIO_MAX_FILENAME_LENGTH];
|
||||||
} $group$_t;
|
} $group$_t;
|
||||||
@ -319,6 +319,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
trexio_exit_code rc_free = TREXIO_FAILURE;
|
||||||
|
|
||||||
/* workaround for the case of missing blocks in the file */
|
/* workaround for the case of missing blocks in the file */
|
||||||
// START REPEAT GROUP_DSET_ALL
|
// START REPEAT GROUP_DSET_ALL
|
||||||
@ -336,7 +337,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +353,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if ((rc != 2) || (strcmp(buffer, "dims_$group_dset$") != 0) || (j!=i)) {
|
if ((rc != 2) || (strcmp(buffer, "dims_$group_dset$") != 0) || (j!=i)) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +365,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +383,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if ($group$->$group_dset$ == NULL) {
|
if ($group$->$group_dset$ == NULL) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,7 +395,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -397,7 +413,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if ($group$->$group_dset$ == NULL) {
|
if ($group$->$group_dset$ == NULL) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,7 +436,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +460,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +473,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if ((rc != 1) || (strcmp(buffer, "$group_num$") != 0)) {
|
if ((rc != 1) || (strcmp(buffer, "$group_num$") != 0)) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +485,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -471,7 +502,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,8 +514,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if ((rc != 1) || (strcmp(buffer, "$group_str$") != 0)) {
|
if ((rc != 1) || (strcmp(buffer, "$group_str$") != 0)) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$->$group_str$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
FREE($group$);
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,8 +528,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if ($group$->$group_str$ == NULL) {
|
if ($group$->$group_str$ == NULL) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$->$group_str$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
FREE($group$);
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,8 +540,10 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
FREE(buffer);
|
FREE(buffer);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
FREE($group$->$group_str$);
|
/* Set pointer to the struct so that the garbage collector can do the job on file handle */
|
||||||
FREE($group$);
|
file->$group$ = $group$;
|
||||||
|
rc_free = trexio_text_free_$group$(file);
|
||||||
|
assert(rc_free == TREXIO_SUCCESS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,8 +311,6 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
subloop_dset = False
|
subloop_dset = False
|
||||||
subloop_num = False
|
subloop_num = False
|
||||||
loop_body = ''
|
loop_body = ''
|
||||||
dset_allocated = []
|
|
||||||
str_allocated = []
|
|
||||||
|
|
||||||
for line in f_in :
|
for line in f_in :
|
||||||
|
|
||||||
@ -335,25 +333,12 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
if ('REPEAT GROUP_DSET_NUM' in line) and (detailed_dset[dset]['group_dset_dtype'] == 'char*'):
|
if ('REPEAT GROUP_DSET_NUM' in line) and (detailed_dset[dset]['group_dset_dtype'] == 'char*'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dset_allocated.append(dset)
|
save_body = loop_body
|
||||||
|
populated_body = recursive_replace_line(save_body, triggers, detailed_dset[dset])
|
||||||
if 'FREE($group$->$group_dset$)' in loop_body:
|
f_out.write(populated_body)
|
||||||
tmp_string = ''
|
|
||||||
for dset_alloc in dset_allocated:
|
|
||||||
tmp_string += f'FREE({group}->{dset_alloc});\n '
|
|
||||||
|
|
||||||
tmp_body = loop_body.replace('FREE($group$->$group_dset$);', tmp_string)
|
|
||||||
|
|
||||||
populated_body = recursive_replace_line(tmp_body, triggers, detailed_dset[dset])
|
|
||||||
f_out.write(populated_body)
|
|
||||||
else:
|
|
||||||
save_body = loop_body
|
|
||||||
populated_body = recursive_replace_line(save_body, triggers, detailed_dset[dset])
|
|
||||||
f_out.write(populated_body)
|
|
||||||
|
|
||||||
subloop_dset = False
|
subloop_dset = False
|
||||||
loop_body = ''
|
loop_body = ''
|
||||||
dset_allocated = []
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif 'END REPEAT GROUP_NUM' in line:
|
elif 'END REPEAT GROUP_NUM' in line:
|
||||||
@ -374,26 +359,12 @@ def special_populate_text_group(fname: str, paths: dict, group_dict: dict, detai
|
|||||||
if group != detailed_strings[str]['group']:
|
if group != detailed_strings[str]['group']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
str_allocated.append(str)
|
save_body = loop_body
|
||||||
|
populated_body = recursive_replace_line(save_body, triggers, detailed_strings[str])
|
||||||
if 'FREE($group$->$group_str$)' in loop_body:
|
f_out.write(populated_body)
|
||||||
tmp_string = ''
|
|
||||||
for str_alloc in str_allocated:
|
|
||||||
tmp_string += f'FREE({group}->{str_alloc});\n '
|
|
||||||
|
|
||||||
tmp_body = loop_body.replace('FREE($group$->$group_str$);', tmp_string)
|
|
||||||
|
|
||||||
populated_body = recursive_replace_line(tmp_body, triggers, detailed_strings[str])
|
|
||||||
f_out.write(populated_body)
|
|
||||||
else:
|
|
||||||
save_body = loop_body
|
|
||||||
populated_body = recursive_replace_line(save_body, triggers, detailed_strings[str])
|
|
||||||
f_out.write(populated_body)
|
|
||||||
|
|
||||||
subloop_num = False
|
subloop_num = False
|
||||||
loop_body = ''
|
loop_body = ''
|
||||||
str_allocated = []
|
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not subloop_num and not subloop_dset:
|
if not subloop_num and not subloop_dset:
|
||||||
|
Loading…
Reference in New Issue
Block a user