Bug 196652 - Fix games/xmoto with libc++ r224926
Summary: Fix games/xmoto with libc++ r224926
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: Dmitry Marakasov
URL:
Keywords:
Depends on:
Blocks: 196535
  Show dependency treegraph
 
Reported: 2015-01-12 19:27 UTC by Dimitry Andric
Modified: 2015-01-25 01:41 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (amdmi3)


Attachments
Fix games/xmoto with libc++ r224926 (6.37 KB, patch)
2015-01-12 19:27 UTC, Dimitry Andric
no flags Details | Diff
Fix games/xmoto with libc++ r224926 (5.01 KB, patch)
2015-01-12 22:22 UTC, Dimitry Andric
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2015-01-12 19:27:07 UTC
Created attachment 151474 [details]
Fix games/xmoto with libc++ r224926

Bug 196535 shows that deskutils/strigidaemon fails to compile when libc++
r224926 is imported:

http://package18.nyi.freebsd.org/data/headamd64PR196535-default/2015-01-07_20h10m47s/logs/errors/xmoto-0.5.11_6.log

The build errors are caused by games/xmoto/files/patch-src-VTexture.h and games/xmoto/files/patch-src-drawlib-DrawLibOpenGL.cpp, which are incorrect, in the sense that the maps are still used to index char pointers, not std::strings.  Also, std::string does not have a default hash function to call (the 'call operator error' indicate this.

I simply removed these two patches, which makes the port build.

Additionally, I've added two patches to make the port with -std=c+11.  These are really just nice-to-haves, and one of them actually fixes a small bug in WWW.cpp.
Comment 1 Bugzilla Automation freebsd_committer freebsd_triage 2015-01-12 19:27:07 UTC
Auto-assigned to maintainer amdmi3@FreeBSD.org
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2015-01-12 19:28:07 UTC
Copy/pasto: deskutils/strigidaemon was from a related bug, this is of course all about the games/xmoto port.
Comment 3 Dmitry Marakasov freebsd_committer freebsd_triage 2015-01-12 21:30:10 UTC
> which are incorrect, in the sense that the maps are still used to index char pointers, not std::strings

No, they are correct - they should be indexed by strings. Using char pointers there is broken, as different pointers may refer to equal strings. You may run xmoto without the patch to see how it's broken.

Regarding the hash function, N3337 specifies that there is std::hash specification for std::string, and it the port works fine with current version of libc++. What has changed so newer version doesn't have it? I see __gnu_cxx references in the log, maybe switching to std::unordered_map will fix it?
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2015-01-12 21:37:14 UTC
hash_map was never a standard, it's something from the original STI STL, which ended up in libstdc++'s ext/ directory.  Since so many code relies on this, libc++ also implemented a version in ext/hash_map, but apparently the most  recent version is not entirely compatible.  But I have no idea at this point why the newer version of libc++ does not like to instantiate a hash_map with a std::string as index.

That said, migrating to unordered_map is likely to work better, but that might not work so good with older versions of gcc and/or libstdc++.
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2015-01-12 21:46:48 UTC
It seems intentional, at least according to this libc++ commit:
http://llvm.org/viewvc/llvm-project?view=revision&revision=203070

(The review link in the commit message is outdated, should now point to http://reviews.llvm.org/D2747 instead.)

So the solution is probably to define an explicit specialization for std::string.  I'll have a look if that is easier than changing to unordered_map.
Comment 6 Dimitry Andric freebsd_committer freebsd_triage 2015-01-12 22:22:36 UTC
Created attachment 151511 [details]
Fix games/xmoto with libc++ r224926

Ok, here is a better patch, which:
1) does not remove the patch-src-VTexture.h and patch-src-drawlib-DrawLibOpenGL.cpp files
2) removes the now unused struct hashcmp_str
3) for the libc++ case, adds a __gnucxx::hash<std::string> specialization, which reuses the const char * specialization (and that, in turn calls libc++'s __do_string_hash(), which is based on either murmur2 or cityhash).

I can't check here whether the specialization works correctly for the case that you fixed in r373383, e.g. the broken text rendering.  I can only hope it will. :)
Comment 7 Dmitry Marakasov freebsd_committer freebsd_triage 2015-01-25 01:41:23 UTC
Yes, this looks good and works without problems. Committed, thanks!
Comment 8 commit-hook freebsd_committer freebsd_triage 2015-01-25 01:41:32 UTC
A commit references this bug:

Author: amdmi3
Date: Sun Jan 25 01:41:05 UTC 2015
New revision: 377854
URL: https://svnweb.freebsd.org/changeset/ports/377854

Log:
  - Fix build with new libc++

  PR:		196652
  Submitted by:	dim

Changes:
  head/games/xmoto/files/patch-src-GameInit.cpp
  head/games/xmoto/files/patch-src-WWW.cpp
  head/games/xmoto/files/patch-src-include-xm__hashmap.h