[info-performer] pfMalloc api inconsistency

Date view Thread view Subject view Author view

From: jan p. springer (jsd++at++igroup.org)
Date: 08/06/2003 04:34:33


pfHi,

a peered code review revealed an inconsistency within the performer api wrt.
pfMalloc. the following should allocate from the heap

    int* i1 = (int*) pfMalloc(sizeof(int), 0);

while the next one allocates from the arena (provided pfInitArenas() was
called)

    int* i2 = (int*) pfMalloc(sizeof(int), pfGetSharedArena());

now this is true for the C API only. when using the C++ API then
Performer/pr/pfMemory.h provides the following "override"

#ifndef __BUILDCAPI__

#if PF_CPLUSPLUS_API

#define pfMalloc pfMemory::malloc

#endif // PF_CPLUSPLUS_API

#endif // !__BUILDCAPI__

aha! and looking into the class declaration of pfMemory one finds the
following

class pfMemory {

   :
   :

public:
     // static functions
     // CAPI:header #if !PF_CPLUSPLUS_API

     // malloc from specific arena
     static void* malloc(size_t nbytes, void *arena);
       :

     // malloc from current shared arena
     //CAPI:private
     static void* malloc(size_t nbytes);
       :

};

this means a call like

   int* i3 = (int*) pfMalloc(sizeof(int));

would resolve to

   int* i3 = (int*) pfMemory::malloc(sizeof(int));

which would mean one allocates from the arena. so it seems that somehow
while introducing this convenience function the access specification to be
protected/private was forgotten. c++ programmers using pfMalloc w/ only one
arg are not flagged by the compiler because there is a perfectly viable
function matching the argument list. i believe this is a bug because it's
contrary to what the pfMalloc interface says: that when the second argument
is a null pointer pfMalloc will allocate from the heap.
using the one argument version of pfMemory::malloc seems semantically
equivalent to calling two argument version of pfMemory::malloc with the
second argument being 0 (NULL).

within our own software we're able to workaround this w/ sth. like:

#undef pfMalloc
#define pfMalloc(a,b) pfMemory::malloc((a),(b))

but we would greatly appreciate a clarification on this.

this is w/ performer 3.0.2.

        j.

-- 
+------------------------------------+--------------------------------------+
| jan p. springer                    | jsd++at++igroup.org                       |
| computer science, buw.media.vrsys  | jan.springer++at++medien.uni-weimar.de    |
+------------------------------------+--------------------------------------+



Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 06 2003 - 04:36:01 PDT