- Add NDT_Root pointer to NDT_Allocator & NDT_Deallocator functions,

- API Break!
This commit is contained in:
Arnaud G. GIBERT 2024-05-03 00:24:51 +02:00
parent e919b5d83c
commit c52ced19c5
4 changed files with 42 additions and 30 deletions

View File

@ -30,7 +30,7 @@
# define _LIBNODE_H_ # define _LIBNODE_H_
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { //extern "C" {
# endif # endif
# include <stdlib.h> # include <stdlib.h>
@ -539,8 +539,11 @@ typedef short NDT_Index_Nb;
struct NDT_Root; /* Predefinition */
struct NDT_Node;
typedef struct NDT_Node NDT_Node;
typedef struct NDT_Index NDT_Index;
typedef struct NDT_Root NDT_Root;
@ -561,7 +564,7 @@ typedef NDT_Status NDT_Manager( struct NDT_Root *, NDT_Index_Id, struct NDT_Nod
typedef char *NDT_Allocator_Name; typedef char *NDT_Allocator_Name;
typedef NDT_Status NDT_Allocator( void **, size_t, void *); typedef NDT_Status NDT_Allocator( void **, NDT_Root *, size_t, void *);
/* Memory deallocator function pointer */ /* Memory deallocator function pointer */
@ -571,7 +574,7 @@ typedef NDT_Status NDT_Allocator( void **, size_t, void *);
typedef char *NDT_Deallocator_Name; typedef char *NDT_Deallocator_Name;
typedef NDT_Status NDT_Deallocator( void *, void *); typedef NDT_Status NDT_Deallocator( void *, NDT_Root *, void *);
@ -1296,13 +1299,15 @@ NDD_DLL_API NDT_Status ND_Manager_Exec_C( NDT_Root *, NDT_Index_Id, NDT_Node
/* Execute an allocator function */ /* Execute an allocator function */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (O) Value_Ptr_Ptr: Value pointer address */ /* (O) Value_Ptr_Ptr: Value pointer address */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Size: Allocation size */
/* (I) Allocator_Name: Value allocator function name */ /* (I) Allocator_Name: Value allocator function name */
/* (I) Allocator_Ptr: Value allocator function pointer */ /* (I) Allocator_Ptr: Value allocator function pointer */
/* (I) Data_Ptr: User pointer */ /* (I) Data_Ptr: User pointer */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDD_DLL_API NDT_Status ND_Allocator_Exec_I( void **, size_t, NDT_Allocator_Name, NDT_Allocator *, void *); NDD_DLL_API NDT_Status ND_Allocator_Exec_I( void **, NDT_Root *, size_t, NDT_Allocator_Name, NDT_Allocator *, void *);
NDD_DLL_API NDT_Status ND_Allocator_Exec_C( void **, size_t, NDT_Allocator_Name, NDT_Allocator *, void *); NDD_DLL_API NDT_Status ND_Allocator_Exec_C( void **, NDT_Root *, size_t, NDT_Allocator_Name, NDT_Allocator *, void *);
@ -1310,18 +1315,19 @@ NDD_DLL_API NDT_Status ND_Allocator_Exec_C( void **, size_t, NDT_Allocator_Nam
/* Execute a deallocator function */ /* Execute a deallocator function */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (I) Value_Ptr: Value pointer */ /* (I) Value_Ptr: Value pointer */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Allocator_Name: Value deallocator function name */ /* (I) Allocator_Name: Value deallocator function name */
/* (I) Allocator_Ptr: Value deallocator function pointer */ /* (I) Allocator_Ptr: Value deallocator function pointer */
/* (I) Data_Ptr: User pointer */ /* (I) Data_Ptr: User pointer */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDD_DLL_API NDT_Status ND_Deallocator_Exec_I( void *, NDT_Deallocator_Name, NDT_Deallocator *, void *); NDD_DLL_API NDT_Status ND_Deallocator_Exec_I( void *, NDT_Root *, NDT_Deallocator_Name, NDT_Deallocator *, void *);
NDD_DLL_API NDT_Status ND_Deallocator_Exec_C( void *, NDT_Deallocator_Name, NDT_Deallocator *, void *); NDD_DLL_API NDT_Status ND_Deallocator_Exec_C( void *, NDT_Root *, NDT_Deallocator_Name, NDT_Deallocator *, void *);
# ifdef __cplusplus # ifdef __cplusplus
} //}
# endif # endif
#endif #endif

View File

@ -3544,12 +3544,14 @@ NDT_Status ND_Manager_Exec_C( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_
/* Execute an allocator function */ /* Execute an allocator function */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (O) Value_Ptr_Ptr: Value pointer address */ /* (O) Value_Ptr_Ptr: Value pointer address */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Size: Allocation size */
/* (I) Allocator_Name: Value allocator function name */ /* (I) Allocator_Name: Value allocator function name */
/* (I) Allocator_Ptr: Value allocator function pointer */ /* (I) Allocator_Ptr: Value allocator function pointer */
/* (I) Data_Ptr: User pointer */ /* (I) Data_Ptr: User pointer */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Allocator_Exec_I( void **Ptr_Ptr, size_t Size, NDT_Allocator_Name Allocator_Name, NDT_Allocator *Allocator_Ptr, void *Data_Ptr) NDT_Status ND_Allocator_Exec_I( void **Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, NDT_Allocator_Name Allocator_Name, NDT_Allocator *Allocator_Ptr, void *Data_Ptr)
{ {
NDT_Allocator *allocator_ptr; NDT_Allocator *allocator_ptr;
@ -3568,7 +3570,7 @@ NDT_Status ND_Allocator_Exec_I( void **Ptr_Ptr, size_t Size, NDT_Allocator_Na
} }
} }
return allocator_ptr( Ptr_Ptr, Size, Data_Ptr); return( allocator_ptr( Ptr_Ptr, Root_Ptr, Size, Data_Ptr));
} }
@ -3579,12 +3581,14 @@ NDT_Status ND_Allocator_Exec_I( void **Ptr_Ptr, size_t Size, NDT_Allocator_Na
/* Execute an allocator function */ /* Execute an allocator function */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (O) Value_Ptr_Ptr: Value pointer address */ /* (O) Value_Ptr_Ptr: Value pointer address */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Size: Allocation size */
/* (I) Allocator_Name: Value allocator function name */ /* (I) Allocator_Name: Value allocator function name */
/* (I) Allocator_Ptr: Value allocator function pointer */ /* (I) Allocator_Ptr: Value allocator function pointer */
/* (I) Data_Ptr: User pointer */ /* (I) Data_Ptr: User pointer */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Allocator_Exec_C( void **Ptr_Ptr, size_t Size, NDT_Allocator_Name Allocator_Name, NDT_Allocator *Allocator_Ptr, void *Data_Ptr) NDT_Status ND_Allocator_Exec_C( void **Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, NDT_Allocator_Name Allocator_Name, NDT_Allocator *Allocator_Ptr, void *Data_Ptr)
{ {
ND_LIBNODE_OPEN_CHECK(); ND_LIBNODE_OPEN_CHECK();
@ -3595,7 +3599,7 @@ NDT_Status ND_Allocator_Exec_C( void **Ptr_Ptr, size_t Size, NDT_Allocator_Na
return( NDS_ERRAPI); return( NDS_ERRAPI);
} }
return( ND_Allocator_Exec_I( Ptr_Ptr, Size, Allocator_Name, Allocator_Ptr, Data_Ptr)); return( ND_Allocator_Exec_I( Ptr_Ptr, Root_Ptr, Size, Allocator_Name, Allocator_Ptr, Data_Ptr));
} }
@ -3606,12 +3610,13 @@ NDT_Status ND_Allocator_Exec_C( void **Ptr_Ptr, size_t Size, NDT_Allocator_Na
/* Execute a deallocator function */ /* Execute a deallocator function */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (I) Value_Ptr: Value pointer */ /* (I) Value_Ptr: Value pointer */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Allocator_Name: Value deallocator function name */ /* (I) Allocator_Name: Value deallocator function name */
/* (I) Allocator_Ptr: Value deallocator function pointer */ /* (I) Allocator_Ptr: Value deallocator function pointer */
/* (I) Data_Ptr: User pointer */ /* (I) Data_Ptr: User pointer */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Deallocator_Exec_I( void *Ptr, NDT_Deallocator_Name Deallocator_Name, NDT_Deallocator *Deallocator_Ptr, void *Data_Ptr) NDT_Status ND_Deallocator_Exec_I( void *Ptr, NDT_Root *Root_Ptr, NDT_Deallocator_Name Deallocator_Name, NDT_Deallocator *Deallocator_Ptr, void *Data_Ptr)
{ {
NDT_Deallocator *deallocator_ptr; NDT_Deallocator *deallocator_ptr;
@ -3630,7 +3635,7 @@ NDT_Status ND_Deallocator_Exec_I( void *Ptr, NDT_Deallocator_Name Deallocator_
} }
} }
return( deallocator_ptr( Ptr, Data_Ptr)); return( deallocator_ptr( Ptr, Root_Ptr, Data_Ptr));
} }
@ -3641,12 +3646,13 @@ NDT_Status ND_Deallocator_Exec_I( void *Ptr, NDT_Deallocator_Name Deallocator_
/* Execute a deallocator function */ /* Execute a deallocator function */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (I) Value_Ptr: Value pointer */ /* (I) Value_Ptr: Value pointer */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Allocator_Name: Value deallocator function name */ /* (I) Allocator_Name: Value deallocator function name */
/* (I) Allocator_Ptr: Value deallocator function pointer */ /* (I) Allocator_Ptr: Value deallocator function pointer */
/* (I) Data_Ptr: User pointer */ /* (I) Data_Ptr: User pointer */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Deallocator_Exec_C( void *Ptr, NDT_Deallocator_Name Deallocator_Name, NDT_Deallocator *Deallocator_Ptr, void *Data_Ptr) NDT_Status ND_Deallocator_Exec_C( void *Ptr, NDT_Root *Root_Ptr, NDT_Deallocator_Name Deallocator_Name, NDT_Deallocator *Deallocator_Ptr, void *Data_Ptr)
{ {
ND_LIBNODE_OPEN_CHECK(); ND_LIBNODE_OPEN_CHECK();
@ -3657,7 +3663,7 @@ NDT_Status ND_Deallocator_Exec_C( void *Ptr, NDT_Deallocator_Name Deallocator_
return( NDS_ERRAPI); return( NDS_ERRAPI);
} }
return( ND_Deallocator_Exec_I( Ptr, Deallocator_Name, Deallocator_Ptr, Data_Ptr)); return( ND_Deallocator_Exec_I( Ptr, Root_Ptr, Deallocator_Name, Deallocator_Ptr, Data_Ptr));
} }
@ -3745,7 +3751,7 @@ NDT_Status ND_Node_Alloc( NDT_Root *Root_Ptr, NDT_Node **Node_Ptr_Ptr )
NDT_Status rc; NDT_Status rc;
rc = ND_Allocator_Exec_I( (void **)Node_Ptr_Ptr, sizeof(NDT_Node), Root_Ptr->Allocator_Name, Root_Ptr->Allocator_Ptr, Root_Ptr->User_Ptr); rc = ND_Allocator_Exec_I( (void **)Node_Ptr_Ptr, Root_Ptr, sizeof(NDT_Node), Root_Ptr->Allocator_Name, Root_Ptr->Allocator_Ptr, Root_Ptr->User_Ptr);
if( ND_ERROR( rc)) return( rc); if( ND_ERROR( rc)) return( rc);
(*Node_Ptr_Ptr)->Root = NULL; (*Node_Ptr_Ptr)->Root = NULL;
@ -3770,7 +3776,7 @@ NDT_Status ND_Node_Alloc( NDT_Root *Root_Ptr, NDT_Node **Node_Ptr_Ptr )
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Node_Free( NDT_Root *Root_Ptr, NDT_Node *Node_Ptr) NDT_Status ND_Node_Free( NDT_Root *Root_Ptr, NDT_Node *Node_Ptr)
{ {
return( ND_Deallocator_Exec_I( Node_Ptr, Root_Ptr->Deallocator_Name, Root_Ptr->Deallocator_Ptr, Root_Ptr->User_Ptr)); return( ND_Deallocator_Exec_I( Node_Ptr, Root_Ptr, Root_Ptr->Deallocator_Name, Root_Ptr->Deallocator_Ptr, Root_Ptr->User_Ptr));
} }
@ -3826,7 +3832,7 @@ NDT_Status ND_Node_Root_Alloc( NDT_Root **Root_Ptr_Ptr, NDT_Index_Nb Index_Nb,
NDT_Index_Id index_id; NDT_Index_Id index_id;
status = ND_Allocator_Exec_I( (void **)Root_Ptr_Ptr, ( sizeof( NDT_Root) + sizeof(NDT_Index) * (Index_Nb - 1)), Allocator_Name, Allocator_Ptr, Data_Ptr); status = ND_Allocator_Exec_I( (void **)Root_Ptr_Ptr, NULL, ( sizeof( NDT_Root) + sizeof(NDT_Index) * (Index_Nb - 1)), Allocator_Name, Allocator_Ptr, Data_Ptr);
if( ND_ERROR(status)) return( status); if( ND_ERROR(status)) return( status);
if( strlen( Manager_Name) > NDD_MANAGER_NAME_LEN_MAX) return( NDS_ERRAPI); if( strlen( Manager_Name) > NDD_MANAGER_NAME_LEN_MAX) return( NDS_ERRAPI);
@ -3881,7 +3887,7 @@ NDT_Status ND_Node_Root_Alloc( NDT_Root **Root_Ptr_Ptr, NDT_Index_Nb Index_Nb,
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Node_Root_Free( NDT_Root *Root_Ptr) NDT_Status ND_Node_Root_Free( NDT_Root *Root_Ptr)
{ {
return( ND_Deallocator_Exec_I( Root_Ptr, Root_Ptr->Deallocator_Name, Root_Ptr->Deallocator_Ptr, Root_Ptr->User_Ptr)); return( ND_Deallocator_Exec_I( Root_Ptr, NULL, Root_Ptr->Deallocator_Name, Root_Ptr->Deallocator_Ptr, Root_Ptr->User_Ptr));
} }
@ -4823,7 +4829,7 @@ NDT_Node *ND_Tree_Node_Last_Recursive_Get( NDT_Node *Node_Ptr)
/* Redéfinition de la fonction malloc() avec retour de type NDT_Status */ /* Redéfinition de la fonction malloc() avec retour de type NDT_Status */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Default_Allocator( void **Ptr_Ptr, size_t Size, void *Data_Ptr) NDT_Status ND_Default_Allocator( void **Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, void *Data_Ptr)
{ {
*Ptr_Ptr = malloc( Size); *Ptr_Ptr = malloc( Size);
@ -4841,7 +4847,7 @@ NDT_Status ND_Default_Allocator( void **Ptr_Ptr, size_t Size, void *Data_Ptr
/* Redéfinition de la fonction free() avec retour de type NDT_Status */ /* Redéfinition de la fonction free() avec retour de type NDT_Status */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Default_Deallocator( void *Ptr, void *Data_Ptr) NDT_Status ND_Default_Deallocator( void *Ptr, NDT_Root *Root_Ptr, void *Data_Ptr)
{ {
if( !Ptr) return( NDS_ERRAPI); if( !Ptr) return( NDS_ERRAPI);

View File

@ -152,12 +152,12 @@ NDT_Status ND_OpenStruct_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_C
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Redéfinition de la fonction malloc() avec retour de type NDT_Status */ /* Redéfinition de la fonction malloc() avec retour de type NDT_Status */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Default_Allocator( void **, size_t, void *); NDT_Status ND_Default_Allocator( void **, NDT_Root *, size_t, void *);
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Redéfinition de la fonction free() avec retour de type NDT_Status */ /* Redéfinition de la fonction free() avec retour de type NDT_Status */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
NDT_Status ND_Default_Deallocator( void *, void *); NDT_Status ND_Default_Deallocator( void *, NDT_Root *, void *);
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Création d'un noeud */ /* Création d'un noeud */