Luxoft / iviLink

iviLINK application connectivity stack for in-vehicle infotainment
16 stars 6 forks source link

Exceptions #1

Open tim-oleksii opened 12 years ago

tim-oleksii commented 12 years ago

Does ivilink use exceptions?

I mean

char *someVar = new char[  0xDEAD ];
strcpy( someVar, "I can fly" );

If new fails, what's going to happen?

Vanuan commented 12 years ago

If new fails, what's going to happen?

std::bad_alloc will be thrown.

Vanuan commented 12 years ago
char *someVar = new char[  0xDEAD ];
strcpy( someVar, "I can fly" );

What's the problem with this code?

tim-oleksii commented 12 years ago

By posting my comment I meant following : 1) If iviLink uses exceptions, bad_alloc will be thrown, and I do not see any try\catch instructions inside of iviLink. 2) If iviLink uses it is own memory allocator, where is it?

What is more, Konstantin informed me that no exceptions is used. Does iviLink uses standard library built without exceptions? If it does not, it is problem, because new will generate exceptions anyway.

Vanuan commented 12 years ago

If iviLink uses exceptions, bad_alloc will be thrown, and I do not see any try\catch instructions inside of iviLink.

What do you expect iviLink to do if such an exception is thrown? Or if you used a new operator that returns 0 on failure? Even in your own example:

char *someVar = new (std::nothrow) char[  0xDEAD ];
if(someVar)
{
    strcpy( someVar, "I can fly" );
}
else
{
    // how do you handle such situation?
}

If you'll just exit(-1); it's silly. And it makes code much cluttered with all those if(variable) all over the place.

Does iviLink uses standard library built without exceptions?

It depends on how you build it. If you build on ubuntu, a standard library with exceptions will be used. BTW, AFAIK, this exeption will be thrown even if you build with -fno-exception flag.

tim-oleksii commented 12 years ago

I'd use set_new_handler or my implementation of 'new' to log this situation. I dunno the policy of crash recordings on possible head units, but the slog should be available.

Yes, it's true, it'll generate exceptions anyway.

Vanuan commented 12 years ago

So, you shouldn't care about whether new throws an exception or not. Since you can override new operator and do whatever you want there.

tim-oleksii commented 12 years ago

New is not a case there. There are few references of usage std::map, and std::string. I point that a developer which uses iviLink should care about exceptions.

As it is a problem that exception is raised inside a library that is declared 'not using exceptions'. This is crucial here.

Vanuan commented 12 years ago

std::map and std::string

Using STL doesn't imply you're using exceptions. There are STL implementations without exceptions.

As it is a problem that exception is raised inside a library that is declared 'not using exceptions'.

"not using exceptions" just means that exceptions are not used for error handling. As far as a library is buildable with -fno-exceptions flag, it doesn't use exceptions.

SergeyDmitriev commented 12 years ago

AFAIK. Just for now we avoid mention any exceptions or RTTI-depend constructions (dynamic_cast, etc) in sources because of the specificity of the CRT's of android. I agree that it looks ugly but there is no solution for now.

@Vanuan, JFYI. There are a lots of calls for delete, there are a lots of exception-unsafe code in sources. No shared_ptr, weak_ptr, unique_ptr, std::swap(), RAII pattern, etc uses in the code. For me this looks like a field activities in the future. And about code style. I'm don't care about naming: CBuffer, Buffer, buffer. Really I don't care even about tabs and spaces. But for me e.g. the 'buffer' class should represent and care the memory not about formatted IO. All of this is my IMHO of course.

kostiakhait commented 12 years ago

Hm... The power of "Pentium generation programmers" :), who consider no exceptions, RTTI, managed code, JavaScript and HTML5 mean ugly :). Guys, we probably will need to port iviLink to the low end systems with kilobytes of memory and tens MHz of CPU. We shall be as light as possible and consider portability (not just to Android) as a top priority.

Vanuan commented 12 years ago

low end systems with kilobytes of memory and tens MHz of CPU.

800x600 video streaming requires at least 500 MHz. Kilobytes of memory wouldn't be enough even for 1 video frame.