Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use two full size members instead of using a static array as a union #8620

Merged
merged 1 commit into from Dec 20, 2015

Conversation

klusark
Copy link
Contributor

@klusark klusark commented Dec 19, 2015

This really shouldn't change anything, but the current implementation
fails to work correctly when using the new C++11 ABI in gcc 5.1 and up.
I'm hoping someone will be able to find the root cause, but this is better
than nothing.

Bugs to reference:
http://trac.kodi.tv/ticket/16414
http://trac.kodi.tv/ticket/16421

@ronie ronie added Type: Fix non-breaking change which fixes an issue Backport: Needed Component: Python labels Dec 19, 2015
@ronie
Copy link
Member

ronie commented Dec 19, 2015

thanx! will test it and let you know.

@tamland / @jimfcarroll for review

@tadly
Copy link
Member

tadly commented Dec 19, 2015

Tested on arch with gcc 5.3 (stdc 6.0.21), isengard 15.2 and works for me :)

@tamland
Copy link
Member

tamland commented Dec 19, 2015

Oddly enough it does. @klusark have you tried using a regular union here instead of the array?

@klusark
Copy link
Contributor Author

klusark commented Dec 19, 2015

@tamland that was my first thought as well, but c++ does not allow unions of types with constructors.

@ronie
Copy link
Member

ronie commented Dec 19, 2015

confirmed on ubuntu 15.10 / gcc 5.2.1 as well.

@tamland
Copy link
Member

tamland commented Dec 19, 2015

@klusark Should be possible http://en.cppreference.com/w/cpp/language/union (see 'Explanation') as long as you implement all special members. I'm guessing that's the root cause here. It relies on defaults so same a unions, the destructor of T1 or T2 will never be called for one thing. (Just use the two full size members though. It's too hard to implement this right.)

@@ -31,58 +31,52 @@ namespace XBMCAddon
public:
private:
WhichAlternative pos;
unsigned char m_data[sizeof(T1) > sizeof(T2) ? sizeof(T1) : sizeof(T2)];
T1 d1;
T2 d2;

public:
Alternative() : pos(none) {}
Alternative(const Alternative& o)

This comment was marked as spam.

This really shouldn't change anything, but the current implementation
fails to work correctly when using the new C++11 ABI in gcc 5.1 and up.
I'm hoping someone will be able to find the root cause, but this is better
than nothing.
@klusark
Copy link
Contributor Author

klusark commented Dec 19, 2015

I spent around an hour trying to get it working with a union. I got it to compile, but it kept segfaulting in random places. Probably not worth the effort.

@razzeee
Copy link
Member

razzeee commented Dec 20, 2015

jenkins build this please

tamland added a commit that referenced this pull request Dec 20, 2015
Use two full size members instead of using a static array as a union
@tamland tamland merged commit 585fc74 into xbmc:master Dec 20, 2015
@tamland
Copy link
Member

tamland commented Dec 20, 2015

@klusark can you create a PR for the Jarvis branch as well?

@klusark
Copy link
Contributor Author

klusark commented Dec 20, 2015

@tamland will do

@klusark
Copy link
Contributor Author

klusark commented Dec 20, 2015

@tamland #8633

@MartijnKaijser MartijnKaijser added this to the K***** 17.0-alpha1 milestone Dec 20, 2015
@jimfcarroll
Copy link
Member

I don't understand why it wasn't working. If anything it should have been a memory leak since any "Alternative" that has a destructor wouldn't have been called. But other than that I don't understand what was happening.

@klusark
Copy link
Contributor Author

klusark commented Jan 6, 2016

@jimfcarroll My guess is that it has something to do with using placement new on approximately the same stack address repeatedly along with some undefined behavior in the standard library.

@tamland
Copy link
Member

tamland commented Jan 6, 2016

@jimfcarroll It didn't implement copy assignment operator, so the default one is generated making shallow copies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants