Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Memory API #21

Merged
merged 4 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON) # GNU extensions and POSIX standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

Expand Down
3 changes: 2 additions & 1 deletion include/collect-c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Purpose: Common elements.
*
* Created: 5th February 2025
* Updated: 14th February 2025
* Updated: 15th February 2025
*
* ////////////////////////////////////////////////////////////////////// */

Expand All @@ -14,6 +14,7 @@
*/

#include <collect-c/common/macros.h>
#include <collect-c/common/mem_api.h>
#ifndef __cplusplus
# include <collect-c/common/version.h>
#endif
Expand Down
87 changes: 87 additions & 0 deletions include/collect-c/common/mem_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* /////////////////////////////////////////////////////////////////////////
* File: collect-c/common/mem_api.h
*
* Purpose: Memory API.
*
* Created: 14th February 2025
* Updated: 15th February 2025
*
* ////////////////////////////////////////////////////////////////////// */


/* /////////////////////////////////////////////////////////////////////////
* includes
*/

#include <stdlib.h>


/* /////////////////////////////////////////////////////////////////////////
* compatibility
*/


/* /////////////////////////////////////////////////////////////////////////
* API types
*/

typedef void* (*collect_c_mem_pfn_alloc)(void* param, size_t cb_new);
typedef void* (*collect_c_mem_pfn_realloc)(void* param, void* pv_curr, size_t cb_curr, size_t cb_new);
typedef void (*collect_c_mem_pfn_free)(void* param, void* pv_curr, size_t cb_curr);

struct collect_c_mem_api_t
{
collect_c_mem_pfn_alloc pfn_alloc;
collect_c_mem_pfn_realloc pfn_realloc;
collect_c_mem_pfn_free pfn_free;
void* param;
};
#ifndef __cplusplus
typedef struct collect_c_mem_api_t collect_c_mem_api_t;
#endif


/* /////////////////////////////////////////////////////////////////////////
* API functions
*/

#ifdef __cplusplus
extern "C" {
#endif

void*
collect_c_mem_std_alloc(
void* param
, size_t cb_new
);

void*
collect_c_mem_std_realloc(
void* param
, void* pv_curr
, size_t cb_curr
, size_t cb_new
);

void
collect_c_mem_std_free(
void* param
, void* pv_curr
, size_t cb_curr
);


#ifdef __cplusplus
} /* extern "C" */
#endif


/* /////////////////////////////////////////////////////////////////////////
* inclusion control
*/

#pragma once


/* ///////////////////////////// end of file //////////////////////////// */

3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Purpose: CMake lists file for collect-c library
#
# Created: 4th February 2025
# Updated: 11th February 2025
# Updated: 14th February 2025
#
# ######################################################################## #

Expand Down Expand Up @@ -42,6 +42,7 @@ endif()
set(CORE_SRCS
circq.c
dlist.c
mem_api.c
vec.c
version.c
)
Expand Down
3 changes: 0 additions & 3 deletions src/dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

#include <errno.h>
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>


/* /////////////////////////////////////////////////////////////////////////
Expand Down
72 changes: 72 additions & 0 deletions src/mem_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* /////////////////////////////////////////////////////////////////////////
* File: src/mem_api.c
*
* Purpose: Memory API.
*
* Created: 14th February 2025
* Updated: 15th February 2025
*
* ////////////////////////////////////////////////////////////////////// */


/* /////////////////////////////////////////////////////////////////////////
* includes
*/

#include <collect-c/common/mem_api.h>

#include <stdlib.h>


/* /////////////////////////////////////////////////////////////////////////
* API functions
*/

void*
collect_c_mem_std_alloc(
void* param
, size_t cb_new
)
{
((void)&param);

/*
if (0 != cb_new)
{
return NULL;
}
*/

return malloc(cb_new);
}

void*
collect_c_mem_std_realloc(
void* param
, void* pv_curr
, size_t cb_curr
, size_t cb_new
)
{
((void)&param);
((void)&cb_curr);

return realloc(pv_curr, cb_new);
}

void
collect_c_mem_std_free(
void* param
, void* pv_curr
, size_t cb_curr
)
{
((void)&param);
((void)&cb_curr);

free(pv_curr);
}


/* ///////////////////////////// end of file //////////////////////////// */

4 changes: 1 addition & 3 deletions src/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Purpose: Vector container.
*
* Created: 5th February 2025
* Updated: 10th February 2025
* Updated: 14th February 2025
*
* ////////////////////////////////////////////////////////////////////// */

Expand Down Expand Up @@ -412,8 +412,6 @@ collect_c_v_push_front_by_ref(
return 0;
}
}

return -1;
}


Expand Down