LCOV - code coverage report
Current view: top level - src/detail - ppg_malloc_detail.c (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 4 6 66.7 %
Date: 2018-01-08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
       2             :  *
       3             :  * This program is free software: you can redistribute it and/or modify
       4             :  * it under the terms of the GNU Lesser General Public License as published by
       5             :  * the Free Software Foundation, either version 3 of the License, or
       6             :  * (at your option) any later version.
       7             :  *
       8             :  * This program is distributed in the hope that it will be useful,
       9             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      10             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11             :  * GNU Lesser General Public License for more details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      15             :  */
      16             : 
      17             : #include "detail/ppg_malloc_detail.h"
      18             : 
      19             : #include "string.h"
      20             : 
      21             : // static void ppg_debug_malloc(void)
      22             : // {
      23             : //    printf("__malloc_heap_start = %p\n", __malloc_heap_start);
      24             : //    printf("__malloc_heap_end = %p\n", __malloc_heap_end);
      25             : //    
      26             : // //    printf("__malloc_heap_margin = %lu\n", (unsigned long)__malloc_heap_margin);
      27             : // }
      28             : 
      29             : #if PPG_HAVE_ASSERTIONS
      30        2754 : void *ppg_safe_malloc(size_t n_bytes,
      31             :                       char *file,
      32             :                       unsigned long line)
      33             : {
      34             : //    ppg_debug_malloc();
      35             :    
      36        2754 :     void* p = malloc(n_bytes);
      37        2754 :     if (!p)
      38             :     {
      39           0 :         PPG_ERROR("[%s:%lu] Out of memory(%lu bytes)\n",
      40             :                 file, line, (unsigned long)n_bytes);
      41           0 :          abort();
      42             :     }
      43        2754 :     return p;
      44             : }
      45             : 
      46             : #else
      47             : 
      48             : void *ppg_safe_malloc(size_t n_bytes)
      49             : {
      50             : //    ppg_debug_malloc();
      51             : //    printf("allocating %lu bytes\n", (unsigned long)n_bytes);
      52             :    
      53             :     void* p = malloc(n_bytes);
      54             :     if (!p)
      55             :     {
      56             :         PPG_ERROR("Out of memory(%lu bytes)\n",
      57             :                 (unsigned long)n_bytes);
      58             :          abort();
      59             :     }
      60             :     return p;
      61             : }
      62             : 
      63             : #endif

Generated by: LCOV version 1.10