Changeset 1314


Ignore:
Timestamp:
07/11/24 17:22:23 (3 months ago)
Author:
Maciej Komosinski
Message:

Added realloc() implementation that behaves like free() when size==0 - consistently on all platforms, in contrast to standard realloc()

Location:
cpp
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/Makefile-SDK

    r1242 r1314  
    99sdk_tests: $(SDK_TESTS)
    1010
    11 CXXWARNINGS=-Wall -Wno-parentheses -Wno-overloaded-virtual -Wno-format -Werror=return-type
     11CXXWARNINGS=-Wall -Wno-parentheses -Wno-overloaded-virtual -Wno-format -Wno-invalid-offsetof -Werror=return-type
    1212
    1313SDK_BUILD_CONFIG= -include frams/config/sdk-build-config.h
  • cpp/frams/Makefile-SDK-files

    r1260 r1314  
    4141NN_LAYOUT_OBJS=frams/canvas/nn_layout_model.o frams/canvas/nn_simple_layout.o frams/canvas/nn_smart_layout.o
    4242
    43 SDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/param/paramlist.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/log.o common/util-string.o common/util-file.o common/nonstd_stdio.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o common/loggers/loggers.o frams/param/paramobj.o frams/genetics/genooperators.o common/nonstd_math.o frams/util/validitychecks.o common/Convert.o frams/util/rndutil.o common/virtfile/stringfile.o common/virtfile/stdinoutfilesystem.o $(PRINTFLOAT_OBJS)
     43SDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/param/paramlist.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/log.o common/util-string.o common/util-file.o common/nonstd_stdio.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o common/loggers/loggers.o frams/param/paramobj.o frams/genetics/genooperators.o common/nonstd_math.o frams/util/validitychecks.o common/Convert.o frams/util/rndutil.o common/virtfile/stringfile.o common/virtfile/stdinoutfilesystem.o common/realloc-free0size.o $(PRINTFLOAT_OBJS)
    4444
    4545STDOUT_LOGGER_OBJS=common/virtfile/virtfile.o common/loggers/loggertostdout.o common/console.o
  • cpp/frams/util/list.h

    r793 r1314  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2024  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    99#include <string.h>
    1010#include <common/nonstd.h>
     11#include <common/realloc-free0size.h>
    1112
    1213//#define SLISTSTATS
     
    4445                if (mem || x)
    4546                {
    46                         mem = (T*)realloc(mem, x*sizeof(T));
     47                        mem = (T*)realloc_free0size(mem, x*sizeof(T));
    4748#ifdef SLISTSTATS
    4849                        SListStats::stats.allocations++;
    4950                        SListStats::stats.copied += sizeof(T)*min(x, have);
    50 #endif 
     51#endif
    5152                }
    5253                have = x;
     
    150151        {
    151152                setSize(src.size());
    152                 memcpy(mem, src.mem, src.size()*sizeof(T));
     153                if (mem != NULL)
     154                        memcpy(mem, src.mem, src.size()*sizeof(T));
    153155        }
    154156        void operator+=(const SListTempl<T>&src) ///< append src contents
  • cpp/frams/util/sstring-simple.cpp

    r1280 r1314  
    33#include <assert.h>
    44#include <common/nonstd_math.h>
     5#include <common/realloc-free0size.h>
    56
    67#ifdef __ANDROID__
     
    5253{
    5354        if (newsize == allocated) return;
    54         txt = (char*)realloc(txt, newsize);
     55        txt = (char*)realloc_free0size(txt, newsize);
    5556        allocated = newsize;
    5657}
Note: See TracChangeset for help on using the changeset viewer.