INGOR
Loading...
Searching...
No Matches
ytLib.h
1/*
2 ytLib.{h,c} : YT Lib common routines
3 Copyright (C) 2016-2021, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 * Neither the name of Hirosaki University, Kyoto University, The
19 University of Tokyo, nor the names of its contributors may be
20 used to endorse or promote products derived from this software
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35*/
36
37#ifndef __YTLIB_H
38#define __YTLIB_H
39
40#include <stdio.h>
41
50extern FILE * ytLib_ERR;
51
52void ytLib_init();
53const char * ytLib_version();
54void * ytLib_malloc_regist(size_t size, const char * file, int line);
55void * ytLib_realloc_regist(void * ptr, size_t size, const char * file, int line);
56void ytLib_free_regist(void * ptr, const char * file, int line);
57void ytLib_registMemoryTable(void * ptr, size_t size, const char * file, int line, int type);
58void ytLib_removeMemoryTable(void * ptr, const char * file, int line, int type);
59
60void * ytLib_mallocBase(size_t size, const char * file, int line, const char * func, int code, int location);
61void * ytLib_reallocBase(void * ptr, size_t size, const char * file, int line, const char * func, int code, int location);
62
63#ifdef YTLIB_MEMCHECK
64
65#define malloc(x) ytLib_malloc_regist(x, __FILE__, __LINE__)
66#define realloc(x,y) ytLib_realloc_regist(x, y, __FILE__, __LINE__)
67#define free(x) ytLib_free_regist(x, __FILE__, __LINE__)
68#else
69#define malloc(x) ytLib_mallocBase(x,__FILE__,__LINE__,__func__,999999,0)
70#define realloc(x,y) ytLib_reallocBase(x,y,__FILE__,__LINE__,__func__,999999,0)
71#endif
72
73#define ytLib_malloc(x,y,z) ytLib_mallocBase(x,__FILE__,__LINE__,__func__,y,z)
74#define ytLib_realloc(x,y,z,a) ytLib_reallocBase(x,y,__FILE__,__LINE__,__func__,z,a)
75
76void ytLib_showMemoryTable(FILE * fp);
78
79void ytLib_assertBase(int value, char * file, int line);
80#define ytLib_assert(x) ytLib_assertBase(x, __FILE__, __LINE__)
81
82#endif /* __YTLIB_H */
size_t ytLib_getAllocMemory()
Returns the total size of allocated memory.
Definition ytLib.c:234
const char * ytLib_version()
Returns the ytLib Git version.
Definition ytLib.c:55
void ytLib_init()
Initializes the YT Lib library.
Definition ytLib.c:49
FILE * ytLib_ERR
File pointer for error output.
Definition ytLib.c:44
void ytLib_showMemoryTable(FILE *fp)
Prints the ytLib memory table.
Definition ytLib.c:205