Ignore:
Timestamp:
11/29/18 10:12:59 (2 years ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
fdf23b8
Parents:
d74ca03
Message:

Apply changes required for pull request #81

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/data-struct/object_cache.c

    rb6ff245 r2193905  
    143143 */
    144144static void resize_memory_caches(struct local_caches *lcs) {
    145         /*assert (lcs->t_mem_caches_total > 0);*/
    146145        if (lcs->t_mem_caches_total <= 0) {
    147146                fprintf(stderr, "Expected lcs->t_mem_caches_total to be greater or equal to 0 in resize_memory_caches()\n");
     
    170169                /* This thread has not been used with a memory pool before */
    171170                /* Allocate our TLS */
    172                 /*assert(lcs == NULL);*/
    173171                if (lcs) {
    174172                        fprintf(stderr, "Expected lcs to be NULL in get_local_caches()\n");
     
    176174                }
    177175                lcs = calloc(1, sizeof (struct local_caches));
    178                 /*assert(lcs);*/
    179176                if (!lcs) {
    180177                        fprintf(stderr, "Unable to allocate memory for lcs in get_local_caches()\n");
     
    186183                lcs->t_mem_caches_total = 0x10;
    187184                lcs->t_mem_caches = calloc(0x10, sizeof(struct local_cache));
    188                 /*assert(lcs);*/
    189                 /*assert(lcs->t_mem_caches);*/
    190185                if (!lcs->t_mem_caches) {
    191                         fprintf(stderr, "Unable to allocate memory for lcs->t_mem_caches in get_local_cahces()\n");
     186                        fprintf(stderr, "Unable to allocate memory for lcs->t_mem_caches in get_local_caches()\n");
    192187                        return NULL;
    193188                }
     
    226221        }
    227222
    228         /*assert(!lc->invalid);*/
    229223        if (lc->invalid) {
    230224                fprintf(stderr, "lc cache is invalid in find_cache()\n");
     
    266260                                    size_t buffer_size, bool limit_size) {
    267261
    268         /*assert(buffer_size);*/
    269         if (!buffer_size) {
     262        if (buffer_size <= 0) {
    270263                fprintf(stderr, "NULL buffer_size passed into libtrace_ocache_init()\n");
    271264                return -1;
    272265        }
    273         /*assert(alloc);*/
    274266        if (!alloc) {
    275267                fprintf(stderr, "NULL alloc passed into libtrace_ocache_init()\n");
    276268                return -1;
    277269        }
    278         /*assert(free);*/
    279270        if (!free) {
    280271                fprintf(stderr, "NULL free method passed into libtrace_ocache_init()\n");
     
    398389        mem_hits.read.miss += nb_buffers - i;
    399390#endif
    400         /*assert(i >= min_nb_buffers);*/
    401391        if (i < min_nb_buffers) {
    402392                fprintf(stderr, "Unable to fill remaining cache in libtrace_ocache_alloc_cache()\n");
     
    412402        bool try_alloc = !(oc->max_allocations && oc->max_allocations <= oc->current_allocations);
    413403
    414         assert(oc->max_allocations ? nb_buffers < oc->max_allocations : 1);
     404        if (oc->max_allocations) {
     405                if(nb_buffers >= oc->max_allocations) {
     406                        fprintf(stderr, "Expected nb_buffers to be less than or equal to the object cache "
     407                                "max allocation in libtrace_ocache_alloc()\n");
     408                        return ~0U;
     409                }
     410        }
    415411        min = try_alloc ? 0: min_nb_buffers;
    416412        if (lc)
     
    435431                for (;i < nb; ++i) {
    436432                        values[i] = (*oc->alloc)();
    437                         /*assert(values[i]);*/
    438433                        if (!values[i]) {
    439434                                fprintf(stderr, "Unable to alloc memory for values[%zu] in libtrace_ocache_alloc()\n", i);
     
    441436                        }
    442437                }
    443                 /*assert (i == nb);*/
     438
    444439                if (i != nb) {
    445440                        fprintf(stderr, "Expected i == nb in libtrace_ocache_alloc()\n");
     
    454449                }
    455450        }
    456         /*assert(i >= min_nb_buffers);*/
    457451        if (i < min_nb_buffers) {
    458                 fprintf(stderr, "Expected min_nb_buffers to be equal or less than i in libtrace_ocache_alloc()\n");
     452                fprintf(stderr, "Failed to allocate minimum number of buffers for libtrace "
     453                        "object cache in libtrace_ocache_alloc()\n");
    459454                return ~0U;
    460455        }
     
    535530        size_t min;
    536531
    537         assert(oc->max_allocations ? nb_buffers < oc->max_allocations : 1);
     532        if (oc->max_allocations) {
     533                if(nb_buffers >= oc->max_allocations) {
     534                        fprintf(stderr, "Expected nb_buffers to be less than or equal to the object cache "
     535                                "max allocation in libtrace_ocache_alloc()\n");
     536                        return ~0U;
     537                }
     538        }
    538539        min = oc->max_allocations ? min_nb_buffers : 0;
    539540        if (lc)
Note: See TracChangeset for help on using the changeset viewer.