Improve handling of C-API constants

Because this wasn't retrieving a reference to the map, no entries
actually ended up being stored. This means that every time we would do a
lookup with an empty map. Also extracted from #2710.