From 85162999c8428f8e42bc3090f1a2df337e2489e9 Mon Sep 17 00:00:00 2001 From: scemama Date: Tue, 4 May 2021 08:04:57 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20TREX-CoE?= =?UTF-8?q?/trexio@daf3fdeb8beca7516c841e63b6545d0ae1540754=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.html | 4 +- index.html | 4 +- templator_front.html | 149 ++++++++++++++++++++++------------------- templator_hdf5.html | 40 +++++------ templator_text.html | 156 +++++++++++++++++++++++++------------------ 5 files changed, 195 insertions(+), 158 deletions(-) diff --git a/README.html b/README.html index d30b3a6..594da1e 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TREXIO source code documentation @@ -341,7 +341,7 @@ and bug reports should be submitted at

Author: TREX-CoE

-

Created: 2021-05-03 Mon 13:59

+

Created: 2021-05-04 Tue 08:04

Validate

diff --git a/index.html b/index.html index d30b3a6..594da1e 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TREXIO source code documentation @@ -341,7 +341,7 @@ and bug reports should be submitted at

Author: TREX-CoE

-

Created: 2021-05-03 Mon 13:59

+

Created: 2021-05-04 Tue 08:04

Validate

diff --git a/templator_front.html b/templator_front.html index 3c80c03..fda7eb7 100644 --- a/templator_front.html +++ b/templator_front.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Front end API @@ -311,45 +311,45 @@ for the JavaScript code in this tag.

Table of Contents

-
-

1 Coding conventions

+
+

1 Coding conventions

  • integer types will be defined using types given in stdint.h
  • @@ -364,8 +364,8 @@ for the JavaScript code in this tag.
-
-

1.1 Memory allocation

+
+

1.1 Memory allocation

Memory allocation of structures can be facilitated by using the @@ -374,8 +374,8 @@ object is the same as the size of the data type pointed by the pointer.

-
#define MALLOC(T) (T*) malloc (sizeof(T));
-#define CALLOC(N,T) (T*) calloc ((N),sizeof(T));
+
#define MALLOC(T) (T*) malloc (sizeof(T))
+#define CALLOC(N,T) (T*) calloc ( (N) , sizeof(T) )
 
@@ -388,12 +388,19 @@ This can be facilitated by the use of the following macro:
#define FREE(X) { free(X) ; (X)=NULL; }
 
-
-
-
-
-

2 Front end

+

+The maximum string size for the filenames is 4096 characters. +

+
+
#define TREXIO_MAX_FILENAME_LENGTH 4096
+
+
+
+
+ +
+

2 Front end

All calls to TREXIO are thread-safe. @@ -401,10 +408,10 @@ TREXIO front end is modular, which simplifies impelementation of new back ends.

-
-

2.1 Error handling

+
+

2.1 Error handling

- +
@@ -605,8 +612,8 @@ The text strings are extracted from the previous table. -
-

2.2 Back ends

+
+

2.2 Back ends

TREXIO has several back ends: @@ -636,8 +643,8 @@ lines that correspond to the TREXIO_JSON back end (not implemented

-
-

2.3 Read/write behavior

+
+

2.3 Read/write behavior

Every time a reading function is called, the data is read from the @@ -665,8 +672,8 @@ concurrent programs, the behavior is not specified.

-
-

2.4 TREXIO file type

+
+

2.4 TREXIO file type

trexio_s is the the main type for TREXIO files, visible to the users @@ -698,8 +705,8 @@ TREXIO files will have as a first argument the TREXIO file handle.

-
-

2.5 Polymorphism of the file handle

+
+

2.5 Polymorphism of the file handle

Polymorphism of the trexio_t type is handled by ensuring that the @@ -718,8 +725,8 @@ corresponding types for all back ends can be safely casted to

-
-

2.6 File opening

+
+

2.6 File opening

trexio_open creates a new TREXIO file or opens existing one. @@ -764,6 +771,7 @@ should tend to avoid renaming the .txt data files. if (file_name == NULL) return NULL; if (file_name[0] == '\0') return NULL; + /* Check overflow in file_name */ if (back_end < 0) return NULL; if (back_end >= TREXIO_INVALID_BACK_END) return NULL; @@ -794,8 +802,14 @@ should tend to avoid renaming the .txt data files. /* Data for the parent type */ - result->file_name = CALLOC(strlen(file_name)+1, char); - strncpy(result->file_name, file_name, strlen(file_name)+1); + result->file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char); + strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH); + if (result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') { + free(result->file_name); + free(result); + return NULL; + } + result->back_end = back_end; result->mode = mode; int irc = pthread_mutex_init ( &(result->thread_lock), NULL); @@ -874,8 +888,8 @@ should tend to avoid renaming the .txt data files.

-
-

2.7 File closing

+
+

2.7 File closing

trexio_close closes an existing trexio_t file. @@ -920,8 +934,8 @@ output: } if (rc != TREXIO_SUCCESS) { - free(file->file_name); - free(file); + FREE(file->file_name); + FREE(file); return TREXIO_FAILURE; } @@ -947,8 +961,7 @@ output: /* Terminate front end */ - free(file->file_name); - file->file_name = NULL; + FREE(file->file_name); int irc = pthread_mutex_destroy( &(file->thread_lock) ); @@ -975,8 +988,8 @@ output:

-
-

3 Templates for front end

+
+

3 Templates for front end

Consider the following block of trex.json: @@ -1137,8 +1150,8 @@ TREXIO supports I/O with single or double precision for integer and floating poi

-
-

3.1 Templates for front end has/read/write a dimension

+
+

3.1 Templates for front end has/read/write a dimension

This section concerns API calls related to dimensioning variables. @@ -1207,8 +1220,8 @@ This section concerns API calls related to dimensioning variables.

-
-

3.1.1 C templates for front end

+
+

3.1.1 C templates for front end

The C templates that correspond to each of the abovementioned functions can be found below. @@ -1397,8 +1410,8 @@ The basic (non-suffixed) API call on dimensioning variables deals with single pr

-
-

3.1.2 Fortran templates for front end

+
+

3.1.2 Fortran templates for front end

The Fortran templates that provide an access to the C API calls from Fortran. @@ -1485,8 +1498,8 @@ These templates are based on the use of iso_c_binding. Pointers hav

-
-

3.2 Templates for front end has/read/write a dataset

+
+

3.2 Templates for front end has/read/write a dataset

This section concerns API calls related to datasets. @@ -1555,8 +1568,8 @@ This section concerns API calls related to datasets.

-
-

3.2.1 C templates for front end

+
+

3.2.1 C templates for front end

The C templates that correspond to each of the abovementioned functions can be found below. @@ -1814,8 +1827,8 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T

-
-

3.2.2 Fortran templates for front end

+
+

3.2.2 Fortran templates for front end

The Fortran templates that provide an access to the C API calls from Fortran. @@ -1902,8 +1915,8 @@ These templates are based on the use of iso_c_binding. Pointers hav

-
-

4 Fortran helper/wrapper functions

+
+

4 Fortran helper/wrapper functions

The function below adapts the original C-based trexio_open for Fortran. @@ -1932,7 +1945,7 @@ Note, that Fortran interface calls the main TREXIO API, which is wr

Author: TREX-CoE

-

Created: 2021-05-03 Mon 13:59

+

Created: 2021-05-04 Tue 08:04

Validate

diff --git a/templator_hdf5.html b/templator_hdf5.html index 7709d6a..2f4ba1d 100644 --- a/templator_hdf5.html +++ b/templator_hdf5.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + HDF5 back end @@ -311,25 +311,25 @@ for the JavaScript code in this tag.

Table of Contents

-
-

1 HDF5 back end

+
+

1 HDF5 back end

-
-

1.1 Template for HDF5 definitions

+
+

1.1 Template for HDF5 definitions

#define $GROUP$_GROUP_NAME          "$group$"
@@ -340,8 +340,8 @@ for the JavaScript code in this tag.
 
-
-

1.2 Template for HDF5 structures

+
+

1.2 Template for HDF5 structures

typedef struct trexio_hdf5_s {
@@ -356,8 +356,8 @@ for the JavaScript code in this tag.
 
-
-

1.3 Template for HDF5 init/deinit

+
+

1.3 Template for HDF5 init/deinit

trexio_exit_code
@@ -440,8 +440,8 @@ for the JavaScript code in this tag.
 
-
-

1.4 Template for HDF5 has/read/write a number

+
+

1.4 Template for HDF5 has/read/write a number

trexio_exit_code
@@ -564,8 +564,8 @@ for the JavaScript code in this tag.
 
-
-

1.5 Template for HDF5 has/read/write a dataset

+
+

1.5 Template for HDF5 has/read/write a dataset

trexio_exit_code
@@ -696,7 +696,7 @@ for the JavaScript code in this tag.
 

Author: TREX-CoE

-

Created: 2021-05-03 Mon 13:59

+

Created: 2021-05-04 Tue 08:04

Validate

diff --git a/templator_text.html b/templator_text.html index 96487e2..06f6e6c 100644 --- a/templator_text.html +++ b/templator_text.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TEXT back end @@ -311,24 +311,24 @@ for the JavaScript code in this tag.

Table of Contents

-
-

1 TEXT back end

+
+

1 TEXT back end

The "file" produced by the text back end is a directory with one @@ -359,8 +359,8 @@ The file is written when closed, or when the flush function is called.

-
-

1.1 Template for group-related structures in text back end

+
+

1.1 Template for group-related structures in text back end

typedef struct $group$_s {
@@ -376,8 +376,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.2 Template for general structure in text back end

+
+

1.2 Template for general structure in text back end

typedef struct rdm_s {
@@ -403,8 +403,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.3 Initialize function (constant part)

+
+

1.3 Initialize function (constant part)

trexio_exit_code
@@ -434,15 +434,19 @@ The file is written when closed, or when the flush function is called.
   /* Create the lock file in the directory */
   const char* lock_file_name = "/.lock";
 
-  size_t str_size = strlen(file->file_name) + strlen(lock_file_name) + 1;
-  char* file_name = CALLOC(str_size, char);
+  char* file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char);
 
   if (file_name == NULL) {
     return TREXIO_ALLOCATION_FAILED;
   }
 
-  strncpy (file_name, file->file_name, str_size);
-  strncat (file_name, lock_file_name, strlen(lock_file_name));
+  strncpy (file_name, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
+  strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name));
+
+  if (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
+    FREE(file_name);
+    return TREXIO_ALLOCATION_FAILED;
+  }
 
   f->lock_file = open(file_name,O_WRONLY|O_CREAT|O_TRUNC, 0644);
   FREE(file_name);
@@ -507,8 +511,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.4 Deinitialize function (templated part)

+
+

1.4 Deinitialize function (templated part)

trexio_exit_code
@@ -532,8 +536,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.5 Template for text read struct

+
+

1.5 Template for text read struct

$group$_t*
@@ -555,16 +559,22 @@ trexio_text_read_$group$ (trexio_text_t* Build the file name */
   const char* $group$_file_name = "/$group$.txt";
-  size_t str_size = strlen(file->parent.file_name) + strlen($group$_file_name) + 1;
-  char * file_name = CALLOC(str_size, char);
+  char * file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char);
 
   if (file_name == NULL) {
     FREE($group$);
     return NULL;
   }
 
-  strncpy (file_name, file->parent.file_name, str_size);
-  strncat (file_name, $group$_file_name, strlen($group$_file_name));
+  strncpy (file_name, file->parent.file_name, TREXIO_MAX_FILENAME_LENGTH);
+  strncat (file_name, $group$_file_name,
+           TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));
+
+  if (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
+    FREE(file_name);
+    FREE($group$);
+    return NULL;
+  }
 
   /* If the file exists, read it */
   FILE* f = fopen(file_name,"r");
@@ -724,8 +734,8 @@ trexio_text_read_$group$ (trexio_text_t* 
 
-
-

1.6 Template for text flush struct

+
+

1.6 Template for text flush struct

trexio_exit_code
@@ -783,8 +793,8 @@ trexio_text_read_$group$ (trexio_text_t* 
 
-
-

1.7 Template for text free memory

+
+

1.7 Template for text free memory

Memory is allocated when reading. The following function frees memory. @@ -825,8 +835,8 @@ Memory is allocated when reading. The following function frees memory.

-
-

1.8 Template for has/read/write the $group_num$ attribute

+
+

1.8 Template for has/read/write the $group_num$ attribute

trexio_exit_code
@@ -888,8 +898,8 @@ Memory is allocated when reading. The following function frees memory.
 
-
-

1.9 Template for has/read/write the $group_dset$ dataset

+
+

1.9 Template for has/read/write the $group_dset$ dataset

The group_dset array is assumed allocated with the appropriate size. @@ -986,12 +996,12 @@ The group_dset array is assumed allocated with the appropriate size

-
-

1.10 RDM struct (hard-coded)

+
+

1.10 RDM struct (hard-coded)

-
-

1.10.1 Read the complete struct

+
+

1.10.1 Read the complete struct

rdm_t* trexio_text_read_rdm(trexio_text_t* const file);
@@ -1005,7 +1015,7 @@ The group_dset array is assumed allocated with the appropriate size
   if (file->rdm != NULL) return file->rdm;
 
   /* Allocate the data structure */
-  rdm_t* const rdm = MALLOC(rdm_t);
+  rdm_t* rdm = MALLOC(rdm_t);
   assert (rdm != NULL);
 
   rdm->one_e           = NULL;
@@ -1015,13 +1025,19 @@ The group_dset array is assumed allocated with the appropriate size
 
   /* Try to open the file. If the file does not exist, return */
   const char* rdm_file_name = "/rdm.txt";
-  size_t str_size = strlen(file->parent.file_name) + strlen(rdm_file_name) + 1;
-  char * file_name = CALLOC(str_size, char);
+  char* file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char);
 
   assert (file_name != NULL);
-  strncpy (file_name, file->parent.file_name, str_size);
-  strncat (file_name, rdm_file_name, strlen(rdm_file_name));
+  strncpy (file_name, file->parent.file_name, TREXIO_MAX_FILENAME_LENGTH);
 
+  strncat (file_name, rdm_file_name,
+           TREXIO_MAX_FILENAME_LENGTH-strlen(rdm_file_name));
+
+  if (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
+    FREE(file_name);
+    FREE(rdm);
+    return NULL;
+  }
   /* If the file exists, read it */
   FILE* f = fopen(file_name,"r");
   if (f != NULL) {
@@ -1063,9 +1079,17 @@ The group_dset array is assumed allocated with the appropriate size
 
     rc = fscanf(f, "%1023s", buffer);
     assert (rc == 1);
-    str_size = strlen(buffer);
-    rdm->two_e_file_name = CALLOC(str_size,char);
-    strncpy(rdm->two_e_file_name, buffer, str_size);
+    rdm->two_e_file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH,char);
+    strncpy(rdm->two_e_file_name, buffer, 1024);
+    if (rdm->two_e_file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
+      FREE(file_name);
+      FREE(buffer);
+      FREE(rdm->one_e);
+      FREE(rdm->two_e_file_name);
+      FREE(rdm);
+      fclose(f);
+      return NULL;
+    }
 
     FREE(buffer);
     fclose(f);
@@ -1085,8 +1109,8 @@ The group_dset array is assumed allocated with the appropriate size
 
-
-

1.10.2 Flush the complete struct

+
+

1.10.2 Flush the complete struct

trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file);
@@ -1129,8 +1153,8 @@ The group_dset array is assumed allocated with the appropriate size
 
-
-

1.10.3 Free memory

+
+

1.10.3 Free memory

Memory is allocated when reading. The followig function frees memory. @@ -1175,8 +1199,8 @@ Memory is allocated when reading. The followig function frees memory.

-
-

1.10.4 Read/Write the onee attribute

+
+

1.10.4 Read/Write the onee attribute

The one_e array is assumed allocated with the appropriate size. @@ -1242,8 +1266,8 @@ The one_e array is assumed allocated with the appropriate size.

-
-

1.10.5 Read/Write the twoe attribute

+
+

1.10.5 Read/Write the twoe attribute

two_e is a sparse data structure, which can be too large to fit @@ -1351,7 +1375,7 @@ file for each sparse float structure.

Author: TREX-CoE

-

Created: 2021-05-03 Mon 13:59

+

Created: 2021-05-04 Tue 08:04

Validate