diff --git a/benchmarks/benchmark_gmio/main.c b/benchmarks/benchmark_gmio/main.c index c64084a..436757e 100644 --- a/benchmarks/benchmark_gmio/main.c +++ b/benchmarks/benchmark_gmio/main.c @@ -175,12 +175,12 @@ static void bmk_gmio_stl_readwrite_conv(const char* filepath) rw_conv.out_format = GMIO_STL_FORMAT_ASCII; if (infile != NULL) { - in_trsf.buffer = gmio_buffer_malloc(512 * 1024); + in_trsf.memblock = gmio_memblock_malloc(512 * 1024); in_trsf.stream = gmio_stream_stdio(infile); rw_conv.in_format = gmio_stl_get_format(&in_trsf.stream); } if (outfile != NULL) { - rw_conv.trsf.buffer = gmio_buffer_malloc(512 * 1024); + rw_conv.trsf.memblock = gmio_memblock_malloc(512 * 1024); rw_conv.trsf.stream = gmio_stream_stdio(outfile); rw_conv.trsf.stream.func_get_pos( rw_conv.trsf.stream.cookie, @@ -195,8 +195,8 @@ static void bmk_gmio_stl_readwrite_conv(const char* filepath) error = gmio_stl_read(&in_trsf, &mesh_creator); - gmio_buffer_deallocate(&in_trsf.buffer); - gmio_buffer_deallocate(&rw_conv.trsf.buffer); + gmio_memblock_deallocate(&in_trsf.memblock); + gmio_memblock_deallocate(&rw_conv.trsf.memblock); if (error != GMIO_ERROR_OK) printf("gmio error: 0x%X\n", error); diff --git a/src/gmio_core/buffer.c b/src/gmio_core/buffer.c deleted file mode 100644 index 7f8aa2f..0000000 --- a/src/gmio_core/buffer.c +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** gmio -** Copyright Fougue (2 Mar. 2015) -** contact@fougue.pro -** -** This software is a reusable library whose purpose is to provide complete -** I/O support for various CAD file formats (eg. STL) -** -** This software is governed by the CeCILL-B license under French law and -** abiding by the rules of distribution of free software. You can use, -** modify and/ or redistribute the software under the terms of the CeCILL-B -** license as circulated by CEA, CNRS and INRIA at the following URL -** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". -****************************************************************************/ - -#include "buffer.h" - -#include - -GMIO_INLINE gmio_buffer_t gmio_buffer_null() -{ - gmio_buffer_t buff = {0}; - return buff; -} - -gmio_buffer_t gmio_buffer( - void* ptr, size_t size, void (*func_deallocate)(void*)) -{ - gmio_buffer_t buff; - buff.ptr = ptr; - buff.size = ptr != NULL ? size : 0; - buff.func_deallocate = func_deallocate; - return buff; -} - -gmio_buffer_t gmio_buffer_malloc(size_t size) -{ - return gmio_buffer(malloc(size), size, &free); -} - -gmio_buffer_t gmio_buffer_calloc(size_t num, size_t size) -{ - return gmio_buffer(calloc(num, size), num * size, &free); -} - -gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size) -{ - return gmio_buffer(realloc(ptr, size), size, &free); -} - -void gmio_buffer_deallocate(gmio_buffer_t *buffer) -{ - if (buffer != NULL && buffer->func_deallocate != NULL) - buffer->func_deallocate(buffer->ptr); -} - -static gmio_buffer_t gmio_buffer_default_internal_ctor() -{ - return gmio_buffer_malloc(128 * 1024); /* 128 KB */ -} - -/* Warning: global variable ... */ -static gmio_buffer_constructor_func_t gmio_global_buffer_ctor = - gmio_buffer_default_internal_ctor; - -void gmio_buffer_set_default_constructor(gmio_buffer_constructor_func_t ctor) -{ - if (ctor != NULL) - gmio_global_buffer_ctor = ctor; -} - -gmio_buffer_constructor_func_t gmio_buffer_default_constructor() -{ - return gmio_global_buffer_ctor; -} - -gmio_buffer_t gmio_buffer_default() -{ - return gmio_global_buffer_ctor(); -} diff --git a/src/gmio_core/buffer.h b/src/gmio_core/buffer.h deleted file mode 100644 index 3f94b77..0000000 --- a/src/gmio_core/buffer.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** gmio -** Copyright Fougue (2 Mar. 2015) -** contact@fougue.pro -** -** This software is a reusable library whose purpose is to provide complete -** I/O support for various CAD file formats (eg. STL) -** -** This software is governed by the CeCILL-B license under French law and -** abiding by the rules of distribution of free software. You can use, -** modify and/ or redistribute the software under the terms of the CeCILL-B -** license as circulated by CEA, CNRS and INRIA at the following URL -** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". -****************************************************************************/ - -/*! \file buffer.h - * Declaration of gmio_buffer and utility functions - * - * \addtogroup gmio_core - * @{ - */ - -#ifndef GMIO_BUFFER_H -#define GMIO_BUFFER_H - -#include "global.h" - -#include - -/*! Basic block of memory */ -struct gmio_buffer -{ - /*! Pointer to the beginning of the block of memory */ - void* ptr; - - /*! Size (in bytes) of the memory buffer */ - size_t size; - - /*! Optional pointer on a function that deallocates the memory block - * beginning at \p ptr */ - void (*func_deallocate)(void* ptr); -}; -typedef struct gmio_buffer gmio_buffer_t; - -GMIO_C_LINKAGE_BEGIN - -/*! Returns an initialized gmio_buffer object - * - * If \p ptr is NULL then gmio_buffer::size is forced to \c 0 - */ -GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer( - void* ptr, size_t size, void (*func_deallocate)(void*)); - -/*! Returns a gmio_buffer object allocated with standard \c malloc() */ -GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_malloc(size_t size); - -/*! Returns a gmio_buffer object allocated with standard \c calloc() */ -GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_calloc(size_t num, size_t size); - -/*! Returns a gmio_buffer object allocated with standard \c realloc() */ -GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size); - -/*! Safe and convenient call to gmio_buffer::func_deallocate() */ -GMIO_LIB_EXPORT void gmio_buffer_deallocate(gmio_buffer_t* buffer); - -/*! Typedef for a pointer to a function that creates an allocated buffer - * - * Signature: - * \code gmio_buffer_t buffer_ctor(); \endcode - */ -typedef gmio_buffer_t (*gmio_buffer_constructor_func_t)(); - -/*! Installs a global function to construct gmio_buffer objects - * - * The constructor function allocates a gmio_buffer object on demand, to be - * used when a temporary buffer is needed. - * - * This function is not thread-safe. - */ -GMIO_LIB_EXPORT void gmio_buffer_set_default_constructor( - gmio_buffer_constructor_func_t ctor); - -/*! Returns the currently installed function to construct gmio_buffer objects - * - * It is initialized to gmio_buffer_malloc(128KB) - */ -GMIO_LIB_EXPORT gmio_buffer_constructor_func_t gmio_buffer_default_constructor(); - -/*! Returns a gmio_buffer object created using the function - * gmio_buffer_default_constructor() */ -GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_default(); - -GMIO_C_LINKAGE_END - -#endif /* GMIO_BUFFER_H */ -/*! @} */ diff --git a/src/gmio_core/error.h b/src/gmio_core/error.h index 5a45043..df4684e 100644 --- a/src/gmio_core/error.h +++ b/src/gmio_core/error.h @@ -34,11 +34,11 @@ enum gmio_error /*! Pointer on argument gmio_transfer_t is NULL */ GMIO_ERROR_NULL_TRANSFER, - /*! Pointer on argument buffer is NULL */ - GMIO_ERROR_NULL_BUFFER, + /*! Pointer on argument memory block is NULL */ + GMIO_ERROR_NULL_MEMBLOCK, - /*! Argument buffer's size is too small */ - GMIO_ERROR_INVALID_BUFFER_SIZE, + /*! Argument size for the memory block is too small */ + GMIO_ERROR_INVALID_MEMBLOCK_SIZE, /*! An error occurred with gmio_stream */ GMIO_ERROR_STREAM, diff --git a/src/gmio_core/memblock.c b/src/gmio_core/memblock.c new file mode 100644 index 0000000..e290a89 --- /dev/null +++ b/src/gmio_core/memblock.c @@ -0,0 +1,80 @@ +/**************************************************************************** +** gmio +** Copyright Fougue (2 Mar. 2015) +** contact@fougue.pro +** +** This software is a reusable library whose purpose is to provide complete +** I/O support for various CAD file formats (eg. STL) +** +** This software is governed by the CeCILL-B license under French law and +** abiding by the rules of distribution of free software. You can use, +** modify and/ or redistribute the software under the terms of the CeCILL-B +** license as circulated by CEA, CNRS and INRIA at the following URL +** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". +****************************************************************************/ + +#include "memblock.h" + +#include + +GMIO_INLINE gmio_memblock_t gmio_memblock_null() +{ + gmio_memblock_t buff = {0}; + return buff; +} + +gmio_memblock_t gmio_memblock( + void* ptr, size_t size, void (*func_deallocate)(void*)) +{ + gmio_memblock_t buff; + buff.ptr = ptr; + buff.size = ptr != NULL ? size : 0; + buff.func_deallocate = func_deallocate; + return buff; +} + +gmio_memblock_t gmio_memblock_malloc(size_t size) +{ + return gmio_memblock(malloc(size), size, &free); +} + +gmio_memblock_t gmio_memblock_calloc(size_t num, size_t size) +{ + return gmio_memblock(calloc(num, size), num * size, &free); +} + +gmio_memblock_t gmio_memblock_realloc(void* ptr, size_t size) +{ + return gmio_memblock(realloc(ptr, size), size, &free); +} + +void gmio_memblock_deallocate(gmio_memblock_t *mblock) +{ + if (mblock != NULL && mblock->func_deallocate != NULL) + mblock->func_deallocate(mblock->ptr); +} + +static gmio_memblock_t gmio_memblock_default_internal_ctor() +{ + return gmio_memblock_malloc(128 * 1024); /* 128 KB */ +} + +/* Warning: global variable ... */ +static gmio_memblock_constructor_func_t gmio_global_mblock_ctor = + gmio_memblock_default_internal_ctor; + +void gmio_memblock_set_default_constructor(gmio_memblock_constructor_func_t ctor) +{ + if (ctor != NULL) + gmio_global_mblock_ctor = ctor; +} + +gmio_memblock_constructor_func_t gmio_memblock_default_constructor() +{ + return gmio_global_mblock_ctor; +} + +gmio_memblock_t gmio_memblock_default() +{ + return gmio_global_mblock_ctor(); +} diff --git a/src/gmio_core/memblock.h b/src/gmio_core/memblock.h new file mode 100644 index 0000000..419c5eb --- /dev/null +++ b/src/gmio_core/memblock.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** gmio +** Copyright Fougue (2 Mar. 2015) +** contact@fougue.pro +** +** This software is a reusable library whose purpose is to provide complete +** I/O support for various CAD file formats (eg. STL) +** +** This software is governed by the CeCILL-B license under French law and +** abiding by the rules of distribution of free software. You can use, +** modify and/ or redistribute the software under the terms of the CeCILL-B +** license as circulated by CEA, CNRS and INRIA at the following URL +** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". +****************************************************************************/ + +/*! \file memblock.h + * Declaration of gmio_memblock and utility functions + * + * \addtogroup gmio_core + * @{ + */ + +#ifndef GMIO_MEMBLOCK_H +#define GMIO_MEMBLOCK_H + +#include "global.h" + +#include + +/*! Basic memory block */ +struct gmio_memblock +{ + /*! Pointer to the beginning of the memory block */ + void* ptr; + + /*! Size (in bytes) of the memory block */ + size_t size; + + /*! Optional pointer on a function that deallocates the memory block + * beginning at \p ptr */ + void (*func_deallocate)(void* ptr); +}; +typedef struct gmio_memblock gmio_memblock_t; + +GMIO_C_LINKAGE_BEGIN + +/*! Returns an initialized gmio_memblock object + * + * If \p ptr is NULL then gmio_memblock::size is forced to \c 0 + */ +GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock( + void* ptr, size_t size, void (*func_deallocate)(void*)); + +/*! Returns a gmio_memblock object allocated with standard \c malloc() */ +GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_malloc(size_t size); + +/*! Returns a gmio_memblock object allocated with standard \c calloc() */ +GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_calloc(size_t num, size_t size); + +/*! Returns a gmio_memblock object allocated with standard \c realloc() */ +GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_realloc(void* ptr, size_t size); + +/*! Safe and convenient call to gmio_memblock::func_deallocate() */ +GMIO_LIB_EXPORT void gmio_memblock_deallocate(gmio_memblock_t* mblock); + +/*! Typedef for a pointer to a function that creates an allocated mblock + * + * Signature: + * \code gmio_memblock_t mblock_ctor(); \endcode + */ +typedef gmio_memblock_t (*gmio_memblock_constructor_func_t)(); + +/*! Installs a global function to construct gmio_memblock objects + * + * The constructor function allocates a gmio_memblock object on demand, to be + * used when a temporary mblock is needed. + * + * This function is not thread-safe. + */ +GMIO_LIB_EXPORT void gmio_memblock_set_default_constructor( + gmio_memblock_constructor_func_t ctor); + +/*! Returns the currently installed function to construct gmio_memblock objects + * + * It is initialized to gmio_memblock_malloc(128KB) + */ +GMIO_LIB_EXPORT gmio_memblock_constructor_func_t gmio_memblock_default_constructor(); + +/*! Returns a gmio_memblock object created using the function + * gmio_memblock_default_constructor() */ +GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_default(); + +GMIO_C_LINKAGE_END + +#endif /* GMIO_MEMBLOCK_H */ +/*! @} */ diff --git a/src/gmio_core/transfer.h b/src/gmio_core/transfer.h index 2e1d9f0..3f66ab1 100644 --- a/src/gmio_core/transfer.h +++ b/src/gmio_core/transfer.h @@ -23,8 +23,8 @@ #ifndef GMIO_TRANSFER_H #define GMIO_TRANSFER_H -#include "buffer.h" #include "global.h" +#include "memblock.h" #include "stream.h" #include "task_iface.h" @@ -35,7 +35,7 @@ struct gmio_transfer gmio_stream_t stream; /*! The memory block used by the transfer for stream buffering */ - gmio_buffer_t buffer; + gmio_memblock_t memblock; /*! The interface object by which the transfer task can be controlled */ gmio_task_iface_t task_iface; diff --git a/src/gmio_stl/internal/stl_rw_common.c b/src/gmio_stl/internal/stl_rw_common.c index f310ee6..9bcf36c 100644 --- a/src/gmio_stl/internal/stl_rw_common.c +++ b/src/gmio_stl/internal/stl_rw_common.c @@ -25,10 +25,10 @@ gmio_bool_t gmio_check_transfer(int *error, const gmio_transfer_t* trsf) *error = GMIO_ERROR_NULL_TRANSFER; } else { - if (trsf->buffer.ptr == NULL) - *error = GMIO_ERROR_NULL_BUFFER; - else if (trsf->buffer.size == 0) - *error = GMIO_ERROR_INVALID_BUFFER_SIZE; + if (trsf->memblock.ptr == NULL) + *error = GMIO_ERROR_NULL_MEMBLOCK; + else if (trsf->memblock.size == 0) + *error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE; } return gmio_no_error(*error); @@ -53,8 +53,8 @@ gmio_bool_t gmio_stlb_check_params( if (!gmio_check_transfer(error, trsf)) return GMIO_FALSE; - if (trsf->buffer.size < GMIO_STLB_MIN_CONTENTS_SIZE) - *error = GMIO_ERROR_INVALID_BUFFER_SIZE; + if (trsf->memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE) + *error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE; if (byte_order != GMIO_ENDIANNESS_LITTLE && byte_order != GMIO_ENDIANNESS_BIG) { diff --git a/src/gmio_stl/internal/stla_write.c b/src/gmio_stl/internal/stla_write.c index d32dd91..e0e08a2 100644 --- a/src/gmio_stl/internal/stla_write.c +++ b/src/gmio_stl/internal/stla_write.c @@ -122,7 +122,7 @@ GMIO_INLINE char* gmio_write_coords( static gmio_bool_t gmio_transfer_flush_buffer(gmio_transfer_t* trsf, size_t n) { const size_t write_count = - gmio_stream_write(&trsf->stream, trsf->buffer.ptr, sizeof(char), n); + gmio_stream_write(&trsf->stream, trsf->memblock.ptr, sizeof(char), n); return write_count == n; } @@ -135,7 +135,7 @@ int gmio_stla_write( const uint32_t total_facet_count = mesh != NULL ? mesh->triangle_count : 0; const uint32_t buffer_facet_count = trsf != NULL ? - gmio_size_to_uint32(trsf->buffer.size / GMIO_STLA_FACET_SIZE_P2) + gmio_size_to_uint32(trsf->memblock.size / GMIO_STLA_FACET_SIZE_P2) : 0; const char* solid_name = options != NULL ? options->stla_solid_name : NULL; @@ -149,8 +149,8 @@ int gmio_stla_write( options != NULL ? options->stl_write_triangles_only : GMIO_FALSE; /* Variables */ uint32_t ifacet = 0; - void* buffer_ptr = trsf != NULL ? trsf->buffer.ptr : NULL; - char* buffc = buffer_ptr; + void* mblock_ptr = trsf != NULL ? trsf->memblock.ptr : NULL; + char* buffc = mblock_ptr; char coords_format[64]; int error = GMIO_ERROR_OK; @@ -161,8 +161,8 @@ int gmio_stla_write( return error; if (float32_prec == 0 || float32_prec > 9) return GMIO_STL_ERROR_INVALID_FLOAT32_PREC; - if (trsf->buffer.size < GMIO_STLA_FACET_SIZE_P2) - return GMIO_ERROR_INVALID_BUFFER_SIZE; + if (trsf->memblock.size < GMIO_STLA_FACET_SIZE_P2) + return GMIO_ERROR_INVALID_MEMBLOCK_SIZE; { /* Create XYZ coords format string (for normal and vertex coords) */ const char float32_specifier = @@ -181,7 +181,7 @@ int gmio_stla_write( if (!write_triangles_only) { buffc = gmio_write_string(buffc, "solid "); buffc = gmio_write_string_eol(buffc, solid_name); - if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)buffer_ptr)) + if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)mblock_ptr)) return GMIO_ERROR_STREAM; } @@ -198,7 +198,7 @@ int gmio_stla_write( gmio_transfer_handle_progress(trsf, ifacet, total_facet_count); /* Writing of facets is buffered */ - buffc = buffer_ptr; + buffc = mblock_ptr; for (ibuffer_facet = ifacet; ibuffer_facet < clamped_facet_count; ++ibuffer_facet) @@ -223,7 +223,7 @@ int gmio_stla_write( buffc = gmio_write_string_eol(buffc, "endfacet"); } /* end for (ibuffer_facet) */ - if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)buffer_ptr)) + if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)mblock_ptr)) error = GMIO_ERROR_STREAM; /* Task control */ @@ -233,9 +233,9 @@ int gmio_stla_write( /* Write end of solid */ if (gmio_no_error(error) && !write_triangles_only) { - buffc = gmio_write_string(trsf->buffer.ptr, "endsolid "); + buffc = gmio_write_string(trsf->memblock.ptr, "endsolid "); buffc = gmio_write_string_eol(buffc, solid_name); - if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)buffer_ptr)) + if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)mblock_ptr)) error = GMIO_ERROR_STREAM; } diff --git a/src/gmio_stl/internal/stla_write.h b/src/gmio_stl/internal/stla_write.h index 42d9592..4c16ae2 100644 --- a/src/gmio_stl/internal/stla_write.h +++ b/src/gmio_stl/internal/stla_write.h @@ -24,8 +24,8 @@ /*! Writes geometry in the STL ascii format * * \return Error code (see error.h and stl_error.h) - * \retval GMIO_ERROR_INVALID_BUFFER_SIZE - * if trsf->buffer.size < 512 + * \retval GMIO_ERROR_INVALID_MEMBLOCK_SIZE + * if trsf->memblock.size < 512 */ int gmio_stla_write( gmio_transfer_t* trsf, diff --git a/src/gmio_stl/internal/stlb_write.c b/src/gmio_stl/internal/stlb_write.c index 99da2c1..0e4826c 100644 --- a/src/gmio_stl/internal/stlb_write.c +++ b/src/gmio_stl/internal/stlb_write.c @@ -30,20 +30,20 @@ #include GMIO_INLINE void write_triangle_memcpy( - const gmio_stl_triangle_t* triangle, uint8_t* buffer) + const gmio_stl_triangle_t* triangle, uint8_t* mblock) { - memcpy(buffer, triangle, GMIO_STLB_TRIANGLE_RAWSIZE); + memcpy(mblock, triangle, GMIO_STLB_TRIANGLE_RAWSIZE); } static void gmio_stlb_write_facets( const gmio_stl_mesh_t* mesh, - uint8_t* buffer, + uint8_t* mblock, const gmio_stlb_readwrite_helper_t* wparams) { const uint32_t facet_count = wparams->facet_count; const uint32_t i_facet_offset = wparams->i_facet_offset; gmio_stl_triangle_t triangle; - uint32_t buffer_offset = 0; + uint32_t mblock_offset = 0; uint32_t i_facet = 0; if (mesh == NULL || mesh->func_get_triangle == NULL) @@ -59,9 +59,9 @@ static void gmio_stlb_write_facets( if (wparams->func_fix_endian != NULL) wparams->func_fix_endian(&triangle); - write_triangle_memcpy(&triangle, buffer + buffer_offset); + write_triangle_memcpy(&triangle, mblock + mblock_offset); - buffer_offset += GMIO_STLB_TRIANGLE_RAWSIZE; + mblock_offset += GMIO_STLB_TRIANGLE_RAWSIZE; } /* end for */ } @@ -77,7 +77,7 @@ int gmio_stlb_write( const gmio_bool_t write_triangles_only = options != NULL ? options->stl_write_triangles_only : GMIO_FALSE; /* Variables */ - void* buffer_ptr = trsf != NULL ? trsf->buffer.ptr : NULL; + void* mblock_ptr = trsf != NULL ? trsf->memblock.ptr : NULL; gmio_stlb_readwrite_helper_t wparams = {0}; uint32_t i_facet = 0; int error = GMIO_ERROR_OK; @@ -94,7 +94,7 @@ int gmio_stlb_write( /* Note: trsf != NULL certified by gmio_stlb_check_params() */ /* coverity[var_deref_op : FALSE] */ wparams.facet_count = gmio_size_to_uint32( - trsf->buffer.size / GMIO_STLB_TRIANGLE_RAWSIZE); + trsf->memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE); if (!write_triangles_only) { error = gmio_stlb_write_header( @@ -113,17 +113,17 @@ int gmio_stlb_write( { gmio_transfer_handle_progress(trsf, i_facet, facet_count); - /* Write to buffer */ + /* Write to memory block */ wparams.facet_count = GMIO_MIN(wparams.facet_count, facet_count - wparams.i_facet_offset); - gmio_stlb_write_facets(mesh, buffer_ptr, &wparams); + gmio_stlb_write_facets(mesh, mblock_ptr, &wparams); wparams.i_facet_offset += wparams.facet_count; - /* Write buffer to stream */ + /* Write memory block to stream */ if (gmio_stream_write( &trsf->stream, - buffer_ptr, + mblock_ptr, GMIO_STLB_TRIANGLE_RAWSIZE, wparams.facet_count) != wparams.facet_count) diff --git a/src/gmio_stl/internal/stlb_write.h b/src/gmio_stl/internal/stlb_write.h index e67ae0b..11aec3f 100644 --- a/src/gmio_stl/internal/stlb_write.h +++ b/src/gmio_stl/internal/stlb_write.h @@ -24,8 +24,8 @@ /*! Writes geometry in the STL binary format * * \return Error code (see error.h and stl_error.h) - * \retval GMIO_INVALID_BUFFER_SIZE_ERROR - * if trsf->buffer.size < GMIO_STLB_MIN_CONTENTS_SIZE + * \retval GMIO_INVALID_MEMBLOCK_SIZE_ERROR + * if trsf->memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE */ int gmio_stlb_write( gmio_transfer_t* trsf, diff --git a/src/gmio_stl/stl_io.c b/src/gmio_stl/stl_io.c index 47ace02..c9bd4f2 100644 --- a/src/gmio_stl/stl_io.c +++ b/src/gmio_stl/stl_io.c @@ -37,13 +37,13 @@ int gmio_stl_read_file( if (file != NULL) { gmio_transfer_t trsf = {0}; trsf.stream = gmio_stream_stdio(file); - trsf.buffer = gmio_buffer_default(); + trsf.memblock = gmio_memblock_default(); if (task_iface != NULL) trsf.task_iface = *task_iface; error = gmio_stl_read(&trsf, creator); fclose(file); - gmio_buffer_deallocate(&trsf.buffer); + gmio_memblock_deallocate(&trsf.memblock); } else { error = GMIO_ERROR_STDIO; @@ -98,13 +98,13 @@ int gmio_stl_write_file( if (file != NULL) { gmio_transfer_t trsf = {0}; trsf.stream = gmio_stream_stdio(file); - trsf.buffer = gmio_buffer_default(); + trsf.memblock = gmio_memblock_default(); if (task_iface != NULL) trsf.task_iface = *task_iface; error = gmio_stl_write(format, &trsf, mesh, options); fclose(file); - gmio_buffer_deallocate(&trsf.buffer); + gmio_memblock_deallocate(&trsf.memblock); } else { error = GMIO_ERROR_STDIO; diff --git a/src/gmio_stl/stl_io.h b/src/gmio_stl/stl_io.h index 6d0bea4..3fd9b7b 100644 --- a/src/gmio_stl/stl_io.h +++ b/src/gmio_stl/stl_io.h @@ -37,8 +37,8 @@ GMIO_C_LINKAGE_BEGIN * * Internally, it uses: * \li the builtin stream wrapper around FILE* (see gmio_stream_stdio()) - * \li the global default function to construct a temporary gmio_buffer - * object (see gmio_buffer_default()) + * \li the global default function to construct a temporary gmio_memblock + * object (see gmio_memblock_default()) * * \return Error code (see error.h and stl_error.h) */ @@ -74,8 +74,8 @@ int gmio_stl_read( * * Internally, it uses: * \li the builtin stream wrapper around FILE* (see gmio_stream_stdio()) - * \li the global default function to construct a temporary gmio_buffer - * object (see gmio_buffer_default()) + * \li the global default function to construct a temporary gmio_memblock + * object (see gmio_memblock_default()) * * \return Error code (see error.h and stl_error.h) */ @@ -147,8 +147,8 @@ enum { GMIO_STLB_MIN_CONTENTS_SIZE = 284 }; /*! Reads geometry from STL binary stream * * \return Error code (see error.h and stl_error.h) - * \retval GMIO_ERROR_INVALID_BUFFER_SIZE - * if trsf->buffer.size < GMIO_STLB_MIN_CONTENTS_SIZE + * \retval GMIO_ERROR_INVALID_MEMBLOCK_SIZE + * if trsf->memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE */ GMIO_LIBSTL_EXPORT int gmio_stlb_read( diff --git a/src/gmio_stl/stla_read.c b/src/gmio_stl/stla_read.c index 5b73495..8909020 100644 --- a/src/gmio_stl/stla_read.c +++ b/src/gmio_stl/stla_read.c @@ -520,8 +520,8 @@ int gmio_stla_read(gmio_transfer_t* trsf, gmio_stl_mesh_creator_t* creator) parse_data.stream_iterator_cookie.is_stop_requested = GMIO_FALSE; parse_data.stream_iterator.stream = &trsf->stream; - parse_data.stream_iterator.buffer.ptr = trsf->buffer.ptr; - parse_data.stream_iterator.buffer.max_len = trsf->buffer.size; + parse_data.stream_iterator.buffer.ptr = trsf->memblock.ptr; + parse_data.stream_iterator.buffer.max_len = trsf->memblock.size; parse_data.stream_iterator.cookie = &parse_data.stream_iterator_cookie; parse_data.stream_iterator.stream_read_hook = gmio_stream_fwd_iterator_stla_read_hook; diff --git a/src/gmio_stl/stlb_read.c b/src/gmio_stl/stlb_read.c index d0fc60a..52cd2f6 100644 --- a/src/gmio_stl/stlb_read.c +++ b/src/gmio_stl/stlb_read.c @@ -74,10 +74,10 @@ int gmio_stlb_read( const uint32_t max_facet_count_per_read = trsf != NULL ? gmio_size_to_uint32( - trsf->buffer.size / GMIO_STLB_TRIANGLE_RAWSIZE) + trsf->memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE) : 0; /* Variables */ - void* buffer_ptr = trsf != NULL ? trsf->buffer.ptr : NULL; + void* mblock_ptr = trsf != NULL ? trsf->memblock.ptr : NULL; gmio_stlb_readwrite_helper_t rparams = {0}; gmio_stlb_header_t header; uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */ @@ -99,13 +99,13 @@ int gmio_stlb_read( } /* Read facet count */ - if (gmio_stream_read(&trsf->stream, buffer_ptr, sizeof(uint32_t), 1) + if (gmio_stream_read(&trsf->stream, mblock_ptr, sizeof(uint32_t), 1) != 1) { return GMIO_STL_ERROR_FACET_COUNT; } - memcpy(&total_facet_count, buffer_ptr, sizeof(uint32_t)); + memcpy(&total_facet_count, mblock_ptr, sizeof(uint32_t)); if (byte_order != GMIO_ENDIANNESS_HOST) total_facet_count = gmio_uint32_bswap(total_facet_count); @@ -124,7 +124,7 @@ int gmio_stlb_read( gmio_size_to_uint32( gmio_stream_read( &trsf->stream, - buffer_ptr, + mblock_ptr, GMIO_STLB_TRIANGLE_RAWSIZE, max_facet_count_per_read)); if (gmio_stream_error(&trsf->stream) != 0) @@ -135,7 +135,7 @@ int gmio_stlb_read( break; /* Exit if no facet to read */ if (gmio_no_error(error)) { - gmio_stlb_read_facets(creator, buffer_ptr, &rparams); + gmio_stlb_read_facets(creator, mblock_ptr, &rparams); rparams.i_facet_offset += rparams.facet_count; if (gmio_transfer_is_stop_requested(trsf)) error = GMIO_ERROR_TRANSFER_STOPPED; diff --git a/tests/test_core.c b/tests/test_core.c index 9dce2c3..f5e2152 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -15,7 +15,7 @@ #include "utest_assert.h" -#include "../src/gmio_core/buffer.h" +#include "../src/gmio_core/memblock.h" #include "../src/gmio_core/endian.h" #include "../src/gmio_core/error.h" #include "../src/gmio_core/stream.h" @@ -23,20 +23,20 @@ #include #include -static gmio_buffer_t buffer_ctor() +static gmio_memblock_t buffer_ctor() { - return gmio_buffer_calloc(4, 256); + return gmio_memblock_calloc(4, 256); } const char* test_core__buffer() { - /* gmio_buffer_calloc() */ + /* gmio_memblock_calloc() */ { const size_t obj_count = 4; const size_t obj_size = 256; const size_t buff_size = obj_count * obj_size; const uint8_t zero_buff[4 * 256] = {0}; - gmio_buffer_t buff = gmio_buffer_calloc(obj_count, obj_size); + gmio_memblock_t buff = gmio_memblock_calloc(obj_count, obj_size); UTEST_ASSERT(buff.ptr != NULL); UTEST_ASSERT(buff.size == buff_size); UTEST_ASSERT(memcmp(buff.ptr, &zero_buff[0], buff_size) == 0); @@ -44,32 +44,32 @@ const char* test_core__buffer() * In this case free() has not the same address in libgmio.dll and * test_core.exe */ UTEST_ASSERT(buff.func_deallocate == &free); - gmio_buffer_deallocate(&buff); + gmio_memblock_deallocate(&buff); } - /* gmio_buffer_malloc() */ + /* gmio_memblock_malloc() */ { const size_t buff_size = 2 * 1024; /* 2KB */ - gmio_buffer_t buff = gmio_buffer_malloc(buff_size); + gmio_memblock_t buff = gmio_memblock_malloc(buff_size); UTEST_ASSERT(buff.ptr != NULL); UTEST_ASSERT(buff.size == buff_size); UTEST_ASSERT(buff.func_deallocate == &free); - gmio_buffer_deallocate(&buff); + gmio_memblock_deallocate(&buff); } - /* gmio_buffer_realloc() */ + /* gmio_memblock_realloc() */ { const size_t buff_size = 1024; /* 1KB */ - gmio_buffer_t buff = gmio_buffer_malloc(buff_size); - buff = gmio_buffer_realloc(buff.ptr, 2 * buff_size); + gmio_memblock_t buff = gmio_memblock_malloc(buff_size); + buff = gmio_memblock_realloc(buff.ptr, 2 * buff_size); UTEST_ASSERT(buff.ptr != NULL); UTEST_ASSERT(buff.size == (2 * buff_size)); UTEST_ASSERT(buff.func_deallocate == &free); - gmio_buffer_deallocate(&buff); + gmio_memblock_deallocate(&buff); } /* default ctor */ { - UTEST_ASSERT(gmio_buffer_default_constructor() != NULL); - gmio_buffer_set_default_constructor(&buffer_ctor); - UTEST_ASSERT(gmio_buffer_default_constructor() == &buffer_ctor); + UTEST_ASSERT(gmio_memblock_default_constructor() != NULL); + gmio_memblock_set_default_constructor(&buffer_ctor); + UTEST_ASSERT(gmio_memblock_default_constructor() == &buffer_ctor); } return NULL; diff --git a/tests/test_core_platform.c b/tests/test_core_platform.c index 6b42988..8d825a7 100644 --- a/tests/test_core_platform.c +++ b/tests/test_core_platform.c @@ -84,7 +84,7 @@ const char* test_platform__compiler() == 0); UTEST_ASSERT(sizeof(gmio_transfer_t) >= (sizeof(gmio_stream_t) - + sizeof(gmio_buffer_t) + + sizeof(gmio_memblock_t) + sizeof(gmio_task_iface_t))); } diff --git a/tests/test_stl_internal.c b/tests/test_stl_internal.c index 84e7116..3b1a564 100644 --- a/tests/test_stl_internal.c +++ b/tests/test_stl_internal.c @@ -38,13 +38,13 @@ const char* test_stl_internal__rw_common() UTEST_ASSERT(!gmio_check_transfer(&error, &trsf)); UTEST_ASSERT(error == GMIO_ERROR_NULL_BUFFER); - trsf.buffer = gmio_buffer(&buff[0], 0, NULL); + trsf.buffer = gmio_memblock(&buff[0], 0, NULL); UTEST_ASSERT(!gmio_check_transfer(&error, &trsf)); UTEST_ASSERT(error == GMIO_ERROR_INVALID_BUFFER_SIZE); /* Verify that gmio_check_transfer() doesn't touch error when in case of * success */ - trsf.buffer = gmio_buffer(&buff[0], sizeof(buff), NULL); + trsf.buffer = gmio_memblock(&buff[0], sizeof(buff), NULL); UTEST_ASSERT(!gmio_check_transfer(&error, &trsf)); UTEST_ASSERT(error == GMIO_ERROR_INVALID_BUFFER_SIZE); @@ -87,12 +87,12 @@ const char* test_stl_internal__rw_common() UTEST_ASSERT(error == GMIO_ERROR_NULL_TRANSFER); error = GMIO_ERROR_OK; - trsf.buffer = gmio_buffer(&buff[0], GMIO_STLB_MIN_CONTENTS_SIZE / 2, NULL); + trsf.buffer = gmio_memblock(&buff[0], GMIO_STLB_MIN_CONTENTS_SIZE / 2, NULL); UTEST_ASSERT(!gmio_stlb_check_params(&error, &trsf, GMIO_ENDIANNESS_HOST)); UTEST_ASSERT(error == GMIO_ERROR_INVALID_BUFFER_SIZE); error = GMIO_ERROR_OK; - trsf.buffer = gmio_buffer(&buff[0], sizeof(buff), NULL); + trsf.buffer = gmio_memblock(&buff[0], sizeof(buff), NULL); UTEST_ASSERT(gmio_stlb_check_params(&error, &trsf, GMIO_ENDIANNESS_HOST)); UTEST_ASSERT(error == GMIO_ERROR_OK);