Skip to content

CxxWrap fails to distinguish between vectors of shared pointers to value/const value #405

@graeme-a-stewart

Description

@graeme-a-stewart

Hello

I have a project to wrap the high-energy physics library HepMC3, where CxxWrap has an issue when there are two functions, where one takes vector of shared pointers to T and the other a vector of shared pointers to const T.

A minimum reproducer is:

#include "jlcxx/jlcxx.hpp"
#include "jlcxx/stl.hpp"

#include <memory>
#include <vector>

void g(std::vector<std::shared_ptr<int>> v){}
void h(std::vector<std::shared_ptr<const int>> w){}


JLCXX_MODULE define_julia_module(jlcxx::Module& types){
  types.method("g", g);
  types.method("h", h);
}

A library built to wrap these functions will fail to load with the error:

ERROR: LoadError: Double registration for method (:constructor, :StdVector, :dr, 0xa0c245c5f9fa2716)

This doesn't happen with bare pointers, but unfortunately the library I am wrapping makes heavy used of shared_ptr and it's a blocker for us not to have the two versions supported.

Thanks in advance for any fixes or suggestions (and thanks to @grasph for helping track this down).


P.S. The actual library code causing the issue is found in cases like this:

  • std::vector<GenParticlePtr> parents(); defined here
  • std::vector<ConstGenParticlePtr> parents() const; defined here

where GenParticlePtr and ConstGenParticlePtr types are:

using GenParticlePtr = std::shared_ptr<GenParticle>;
using ConstGenParticlePtr = std::shared_ptr<const GenParticle>;

as defined here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions