Skip to content
Permalink
Browse files

api: moved inline array functions to array.c

This fixes #13.
  • Loading branch information...
Snaipe committed May 1, 2017
1 parent 4956778 commit 5bc7aad8cab5f8d9d64308dcffb1a397e86a6b0c
Showing with 46 additions and 14 deletions.
  1. +1 −0 CMakeLists.txt
  2. +6 −14 include/csptr/array.h
  3. +39 −0 src/array.c
@@ -52,6 +52,7 @@ configure_file(
# List sources and headers

set(SOURCE_FILES
src/array.c
src/mman.c
src/mman.h
)
@@ -33,19 +33,11 @@ typedef struct {
size_t size;
} s_meta_array;

CSPTR_PURE CSPTR_INLINE size_t array_length(void *ptr) {
s_meta_array *meta = get_smart_ptr_meta(ptr);
return meta ? meta->nmemb : 0;
}

CSPTR_PURE CSPTR_INLINE size_t array_type_size(void *ptr) {
s_meta_array *meta = get_smart_ptr_meta(ptr);
return meta ? meta->size : 0;
}

CSPTR_PURE CSPTR_INLINE void *array_user_meta(void *ptr) {
s_meta_array *meta = get_smart_ptr_meta(ptr);
return meta ? meta + 1 : NULL;
}
CSPTR_PURE size_t array_length(void *ptr);

CSPTR_PURE size_t array_type_size(void *ptr);

CSPTR_PURE void *array_user_meta(void *ptr);


#endif /* !CSPTR_ARRAY_H_ */
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright © 2015-2017 Franklin "Snaipe" Mathieu <http://snai.pe/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "array.h"

CSPTR_PURE size_t array_length(void *ptr) {
s_meta_array *meta = get_smart_ptr_meta(ptr);
return meta ? meta->nmemb : 0;
}

CSPTR_PURE size_t array_type_size(void *ptr) {
s_meta_array *meta = get_smart_ptr_meta(ptr);
return meta ? meta->size : 0;
}

CSPTR_PURE CSPTR_INLINE void *array_user_meta(void *ptr) {
s_meta_array *meta = get_smart_ptr_meta(ptr);
return meta ? meta + 1 : NULL;
}

0 comments on commit 5bc7aad

Please sign in to comment.
You can’t perform that action at this time.