rdmenezes / ting

Automatically exported from code.google.com/p/ting
0 stars 0 forks source link

Compile error raised under Sun Solaris system. #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
$g++ -I. -g -O2 -MT ting.o -MD -MP -MF .deps/ting.Tpo -c -o ting.o ting.cpp
ting.cpp: In function 'T_Semaphore&
CastToSemaphore(ting::Semaphore::SystemIndependentSemaphoreHandle&)':
ting.cpp:102: error: cannot declare field
'CastToSemaphore(ting::Semaphore::SystemIndependentSemaphoreHandle&)::StaticAsse
rtInst_102::STATIC_ASSERTION_FAILED'
to be of abstract type 'ting::StaticAssert<false>'
ting.hpp:52: note:   because the following virtual functions are pure
within 'ting::StaticAssert<false>':
ting.hpp:53: note:      void
ting::StaticAssert<b>::STATIC_ASSERTION_FAILED() [with bool b = false]
*** Error code 1

The causing code is :

M_TING_STATIC_ASSERT( sizeof(sem) >= sizeof(T_Semaphore) )

I tested the size of sem_t and ting::sem on Solaris(SunOS 5/sparc), the
following is output:

sizeof(sem_t) = 48
sizeof(struct SystemIndependentSemaphoreHandle) = 16

I'm curious, why not just put #ifdef #elif #endif for platform into
ting.hpp, rather than ting.cpp? If put them to ting.hpp, we can directly
define the type as following:

class Semaphore{
public:
#if defined(__WIN32__) || defined(WIN32)
#include <windows.h>
typedef HANDLE Semaphore_t;

#elif defined(__SYMBIAN32__)
#include <string.h>
#include <e32std.h>
#include <hal.h>
typedef RSemaphore Semaphore_t;

#else //assume pthread
#include <semaphore.h>
typedef sem_t Semaphore_t;

#endif
...
    Semaphore_t sem;
...
};

Keeping enlarge the possible size of SystemIndependentXxxxxHandle is not
looks design correctly.

Original issue reported on code.google.com by Dancef...@gmail.com on 2 Aug 2008 at 4:37

GoogleCodeExporter commented 9 years ago
One more thing need to mention, compiling 'ting' under Solaris, we need to add 
"-lrt"
to gcc arguments, since all sem_*() is belong to librt.

Original comment by Dancef...@gmail.com on 3 Aug 2008 at 7:02

GoogleCodeExporter commented 9 years ago
Hi Dancefire,

>I'm curious, why not just put #ifdef #elif #endif for platform into
>ting.hpp, rather than ting.cpp?

What I wanted to achieve by doing so is to eliminate dependency of ting.hpp from
other .h files (except std lib headers), so when the lib is compiled as dll the 
user
 only needs to have ting.hpp and ting.dll and does not necessarily need to have other
stuff as windows.h etc. to compile. Keeping SystemIndependentXxxxxHandle large 
should
not make large memory usage impact on modern systems with gigabytes of RAM.

Well, now I see that such approach has its own difficulties, and now I'm not 
sure
that a benefit from this is large enough, so I may be considering rewriting the 
ting
to have platform #ifdefs in .hpp.

Do you think my initial idea with #ifdefs in .cpp does not have any reason to 
exist?
I'm asking because now I'm not sure it really does...

Original comment by igagis@gmail.com on 3 Aug 2008 at 9:38

GoogleCodeExporter commented 9 years ago
I think in most environments under windows, <windows.h> is installed by default.
otherwise, just install PlatformSDK, and the user will got what he need. It 
should
not be a problem for a developer, since for most Windows developer, <windows.h> 
is
necessary, even if ting doesn't depend on it, the developer will eventually 
install
the PlatformSDK or alternative for other components in the projects.

If it's still not acceptable, we can define the type by ourself, such as:

#ifdef (WIN32)
typedef void* semaphore_type;
#else
typedef sem_t semaphore_type;
#endif

since, WinNT.h:typedef void *HANDLE;

And there might be another way to do it, just use void* pointer in the .hpp, 
and cast
to the correct type when use it(in .cpp). such as:

[ting.hpp]

class Semaphore{
...
    void* handle;
};

[ting.cpp]

#if defined(__WIN32__) || defined(WIN32)
...
typedef HANDLE semaphore_type;
#elif defined(__SYMBIAN32__)
...
typedef RSemaphore semaphore_type;
#else //assume pthread
...
typedef sem_t semaphore_type;
#endif

...

inline static semaphore_type& CastToSemaphore(void* sem){
    return reinterpret_cast<semaphore_type>(*sem);
};

...

Semaphore::Semaphore(uint initialValue){
    this->handle = new semaphore_type();
    semaphore_type& s = CastToSemaphore(this->handle);
#ifdef __WIN32__
    s = CreateSemaphore(NULL, initialValue, 0xffffff, NULL);
    if(s == NULL){
        throw ting::Exc("Semaphore::Semaphore(): creating semaphore failed");
    }
#elif defined(__SYMBIAN32__)
    if(s.CreateLocal(initialValue) != KErrNone){
        throw ting::Exc("Semaphore::Semaphore(): creating semaphore failed");
    }
#else //pthread
    if( sem_init(&s, 0, initialValue) < 0 ){
        throw ting::Exc("Semaphore::Semaphore(): creating semaphore failed");
    }
#endif
};

Original comment by Dancef...@gmail.com on 3 Aug 2008 at 12:49

GoogleCodeExporter commented 9 years ago
Hi Dancefire,

I think that it will be better to just use the old good method, i.e. add the 
platform
specific #ifdef's into .hpp and get rid of SystemIndependentSemaphoreHandle and
CastToSemaphore things.

By the way, would you join the ting project? I'm not always have enough time to 
work
on the project, so I would not refuse some help.

Original comment by igagis@gmail.com on 4 Aug 2008 at 9:24

GoogleCodeExporter commented 9 years ago
Ok, using #ifdefs in hpp should not be a problem.

I don't have a lot of time either, however, I can contribute some of my time to 
the
project. So, may I join the project?

Original comment by Dancef...@gmail.com on 5 Aug 2008 at 7:53

GoogleCodeExporter commented 9 years ago
Hi Dancefire,

I added you to the project members.

Original comment by igagis@gmail.com on 5 Aug 2008 at 9:36

GoogleCodeExporter commented 9 years ago
I suppose this issue is no longer visible on the latest trunk revision.
Closing the issue now. If it still exists indicate it there please and the 
Issue will
be reopened.

Original comment by igagis@gmail.com on 10 Nov 2008 at 8:11