Giter Site home page Giter Site logo

Comments (21)

jjrv avatar jjrv commented on May 14, 2024 1

GCC comes with several executables, and g++ runs cc1plus to do the actual C++ compiling.

For debugging a Node.js addon, if you would normally test it like node test.js, you could just instead use gdb node and type run test.js in the GDB prompt. That should be the easiest way to actually call the C++ methods.

Also, you should modify nbind.gypi (inside nbind's src directory) and maybe your own binding.gyp, to remove any -O? flags and instead add a -g flag, then remove the build directory and recompile. This allows GDB to show much more information.

from nbind.

jjrv avatar jjrv commented on May 14, 2024 1

I'm looking for a way to either stop it from compiling or throw a more useful error message without crashing. Generally when passing any objects, pointers, vectors or any other reference or structure between C++ and JavaScript, any classes whose name appears in the C++ data type name must have a corresponding NBIND_CLASS block. That means Foo, Foo *, std::vector<Foo>, std::shared_ptr<Foo> or anything similar used as an argument or return type, requires NBIND_CLASS(Foo).

Typedefs can sometimes hide this... If you have typedef std::vector<Foo> Bar and later use Bar then it's still Foo that needs a binding.

from nbind.

jjrv avatar jjrv commented on May 14, 2024 1

The earlier initialization was better, casts are better avoided if possible. Just the return type needs changing, this:

AG constructAnnotationGraph(std::string fasta_file_name, std::string vcf_file_name,
  std::string gff_file_name) {

to this:

std::shared_ptr<AG> constructAnnotationGraph(std::string fasta_file_name, std::string vcf_file_name,
  std::string gff_file_name) {

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

Hi Again :)

Not quite sure if this belongs into this issue, but if you think the following does not fit into here at all, please open a new one:

Just a short background explanation: I wrote some code making use of vg and wanted to bind that code with nbind. When I execute the code, it folds throwing Segmentation fault: 11 (to be precise, this happens at the return of a C++ function). So my first guess was that maybe my code has some bugs or something is wrong with vg. However, the code I wanted to run via 'node' works when I integrate it into vg and run it as an extra submodule. This did confuse me a little since the error described above is of a C++ nature.
So I just used your tip and voila, there seems to be a problem with the V8 engine. Maybe you can help me out here?

Thread 1 received signal SIGSEGV, Segmentation fault.
0x0000000103c3aefc in v8::Local<v8::Function> Nan::New<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >(Nan::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > const&) ()
   from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
(gdb) bt
#0  0x0000000103c3aefc in v8::Local<v8::Function> Nan::New<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >(Nan::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > const&) ()
   from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#1  0x0000000103c4467a in nbind::BindingType<vg::AG>::toWireType(vg::AG&&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#2  0x0000000103c4477d in v8::Local<v8::Value> nbind::Caller<vg::AG, nbind::TypeList<nbind::ArgFromWire<nbind::PolicyListType<>, 0ul, std::string>, nbind::ArgFromWire<nbind::PolicyListType<>, 1ul, std::string>, nbind::ArgFromWire<nbind::PolicyListType<>, 2ul, std::string> > >::callFunction<vg::AG (*)(std::string, std::string, std::string), Nan::FunctionCallbackInfo<v8::Value> const>(vg::AG (*)(std::string, std::string, std::string), Nan::FunctionCallbackInfo<v8::Value> const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#3  0x0000000103c448f4 in void nbind::TemplatedBaseSignature<nbind::FunctionSignature<vg::AG (*)(std::string, std::string, std::string), decltype(nullptr), nbind::PolicyListType<>, vg::AG<std::string, std::string, std::string> >, vg::AG<std::string, std::string, std::string>, vg::AG<std::string, std::string, std::string> >::callInnerSafely<void, Nan::FunctionCallbackInfo<v8::Value> const, Nan::FunctionCallbackInfo<v8::Value> >(Nan::FunctionCallbackInfo<v8::Value> const&, Nan::FunctionCallbackInfo<v8::Value>&, unsigned int) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#4  0x0000000103c46c97 in Nan::imp::FunctionCallbackWrapper(v8::FunctionCallbackInfo<v8::Value> const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#5  0x000000010017c59a in v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) ()
#6  0x00000001001e029c in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) ()
#7  0x00000001001df6d9 in v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) ()
#8  0x00003eee6e1063a7 in ?? ()
#9  0x0000000000000004 in ?? ()
#10 0x00003eee6e1062e1 in ?? ()
#11 0x00007fff5fbfe5e0 in ?? ()
#12 0x0000000300000000 in ?? ()
#13 0x00007fff5fbfe698 in ?? ()
#14 0x00003eee6e2409c0 in ?? ()
#15 0x00001db165f04311 in ?? ()
#16 0x000002b82006b0a1 in ?? ()
---Type <return> to continue, or q <return> to quit---
#17 0x0000000700000000 in ?? ()
#18 0x000002b820059f39 in ?? ()
#19 0x000002b820059ee9 in ?? ()
#20 0x000002b820059e99 in ?? ()
#21 0x000018239fac1d89 in ?? ()
#22 0x000002b82006b0a1 in ?? ()
#23 0x00001db165f04311 in ?? ()
#24 0x000002b820059f89 in ?? ()
#25 0x000002b820059f39 in ?? ()
#26 0x000002b820059ee9 in ?? ()
#27 0x000002b820059e99 in ?? ()
#28 0x000018239fac1d89 in ?? ()
#29 0x000018239fab2a49 in ?? ()
#30 0x000018239fa05aa1 in ?? ()
#31 0x00001db165f9e3d1 in ?? ()
#32 0x00007fff5fbfe748 in ?? ()
#33 0x00003eee6e24058f in ?? ()
#34 0x000018239fa05ae9 in ?? ()
#35 0x000018239fa05b11 in ?? ()
#36 0x000018239fa05991 in ?? ()
#37 0x000018239fa05a59 in ?? ()
#38 0x000018239fa05b61 in ?? ()
#39 0x000018239fa05b61 in ?? ()
#40 0x00001db165fa7cd9 in ?? ()
#41 0x00001db165f04311 in ?? ()
#42 0x0000000000000000 in ?? ()

Could this be an nan bug?

Or does NonCopyablePersistentTraits indicate that something could be wrong with a copy constructor on the C++ side?

All the best.

from nbind.

jjrv avatar jjrv commented on May 14, 2024

You have somewhere a function with 3 std::string arguments that returns vg::AG, and nbind is having trouble converting the return value, which may be an invalid pointer or reference.

Can you find such a function and paste its source code here? Also the NBIND_CLASS block for vg::AG might be helpful.

from nbind.

jjrv avatar jjrv commented on May 14, 2024

In general, bugs in nan are very unlikely (the code is quite straightforward and difficult for bugs to hide in) and v8 bugs even less so (Chrome's security depends on eliminating them).

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

When you take a closer look above, you can see that in line 4 the bt begins already ;)

This is the function I am having issues with:

AG constructAnnotationGraph(std::string fasta_file_name, std::string vcf_file_name,
  std::string gff_file_name) {

  	FastaReference reference;
    reference.open(fasta_file_name);

    vcflib::VariantCallFile variant_file;
    variant_file.open(vcf_file_name);

    std::string region;
    bool region_is_chrom = false;

    // values extracted from main
    int vars_per_region = 25000;
    int max_node_size = 1000;

    bool flat_alts = false;
    bool load_phasing_paths = true;
    bool load_alt_paths = false;
    bool progress = true;
    set<string>* propagate = nullptr;

    AG annotation_graph(variant_file, reference, region, gff_file_name, region_is_chrom,
  			vars_per_region, max_node_size, flat_alts, load_phasing_paths,
  			load_alt_paths, progress, propagate);
    std::cout<<"AnnotationGraph successfully build!\n";
    // we want to load the phasing paths, too
    set<string> non_phase_paths;
    std::string phase_prefix = "_phase";
    annotation_graph.paths.for_each_name(
        [&](string path_name) {
          if(!equal(phase_prefix.begin(), phase_prefix.end(), path_name.begin())) {
            // Path is not a phase path
            non_phase_paths.insert(path_name);
          }
        });
    std::cout<<"Loading phasing paths done.\n";
    return annotation_graph;
}

Loading phasing paths done. is still printed out, then the SIGSEGV comes.
The corresponding binding in the file:

// global functions
NBIND_GLOBAL() {
  // construct graph
  function(constructGraph);

  // construct annotation graph
  function(constructAnnotationGraph);

  // index graph
  function(createIndexFromGraph);

  // graph to json
  function(graphToJson);
}

Just for completion, here is how I invoke the function on the JavaScript side:

var nbind = require('nbind');
var lib = nbind.init().lib;

var fasta_file_name = "tiny/tiny.fa";
var vcf_file_name = "tiny/tiny.vcf.gz";
var gff_file_name = "tiny/tiny.gff";

var json_out_name = "tiny/tiny.json";

console.log("constructing annotation graph...");
var annotationGraph = lib.constructAnnotationGraph(fasta_file_name, vcf_file_name,
  gff_file_name);

from nbind.

jjrv avatar jjrv commented on May 14, 2024

It seems I managed to replicate the crash. I guess you don't have any NBIND_CLASS block for the AG class?

Ideally it shouldn't compile at all, but apparently it does and then things go wrong. If you just add:

NBIND_CLASS(AG) {}

Then it shoudn't crash there any more.

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

No, I didn't have. But now I do and it works like a charm. Thank you very much!

From now on I know, that I will have to add the class I may give back as a return value of a function. Maybe you can point this out in the UserGuide section Functions?

Could you maybe fix nbind that it does not compile when the above case is happening? Would it be much work to do?

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

I ran into another, I think similar issue as above. The code I will show does work when I execute it using vg only. However, using nbind a Segmentation fault: 11 occurs.

annotation graph successfully build!
loading phasing paths...
done.
indexing graph...
entered index method.
[New Thread 0x180b of process 28219]

Thread 1 received signal SIGSEGV, Segmentation fault.
0x0000000105d13e5b in get_adjusted_ptr(std::type_info const*, std::type_info const*, void**) () from /usr/local/opt/gcc49/lib/gcc/4.9/libstdc++.6.dylib
(gdb) bt
#0  0x0000000105d13e5b in get_adjusted_ptr(std::type_info const*, std::type_info const*, void**) () from /usr/local/opt/gcc49/lib/gcc/4.9/libstdc++.6.dylib
#1  0x0000000105d14709 in __gxx_personality_v0 () from /usr/local/opt/gcc49/lib/gcc/4.9/libstdc++.6.dylib
#2  0x00007fff85fb99ba in _Unwind_RaiseException () from /usr/lib/system/libunwind.dylib
#3  0x00007fff97451a69 in __cxa_throw () from /usr/lib/libc++abi.dylib
#4  0x0000000105d78320 in std::__throw_out_of_range(char const*) () from /usr/local/opt/gcc49/lib/gcc/4.9/libstdc++.6.dylib
#5  0x000000010492e623 in std::map<vg::Mapping*, std::_List_iterator<vg::Mapping>, std::less<vg::Mapping*>, std::allocator<std::pair<vg::Mapping* const, std::_List_iterator<vg::Mapping> > > >::at(vg::Mapping* const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#6  0x00000001049259ae in vg::Paths::traverse_right(vg::Mapping*) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#7  0x0000000104996cd8 in vg::snp_allele_counts(vg::VG&, std::pair<long long, long long>, std::pair<long long, long long>)::{lambda(std::string const&)#1}::operator()(std::string const&) const () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#8  0x000000010499bc0e in std::_Function_handler<void (std::string const&), vg::snp_allele_counts(vg::VG&, std::pair<long long, long long>, std::pair<long long, long long>)::{lambda(std::string const&)#1}>::_M_invoke(std::_Any_data const&, std::string const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#9  0x000000010486f28b in std::function<void (std::string const&)>::operator()(std::string const&) const (
    this=<error reading variable: Could not find the frame base for "std::function<void (std::string const&)>::operator()(std::string const&) const".>, 
    __args#0=<error reading variable: Could not find the frame base for "std::function<void (std::string const&)>::operator()(std::string const&) const".>)
    at /usr/local/Cellar/gcc49/4.9.3/include/c++/4.9.3/functional:2439
#10 0x0000000104922def in vg::Paths::for_each_name(std::function<void (std::string const&)> const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#11 0x000000010499726c in vg::snp_allele_counts(vg::VG&, std::pair<long long, long long>, std::pair<long long, long long>) ()
   from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#12 0x00000001049979fb in vg::snp_ld_variance(vg::VG&, std::pair<long long, long long>, std::pair<long long, long long>) ()
   from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#13 0x00000001049977ca in vg::snp_ld_ci(vg::VG&, std::pair<long long, long long>, std::pair<long long, long long>, float) ()
   from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#14 0x00000001049986ad in vg::snp_ld_weight(vg::VG&, std::pair<long long, long long>, std::pair<long long, long long>, float, float) ()
   from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#15 0x0000000104998aea in vg::get_haploblocks(vg::VG&, float, float)::{lambda(std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&)#1}::operator()(std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&) const () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#16 0x000000010499beb0 in std::_Function_handler<bool (std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&), vg::get_haploblocks(vg::VG&, float, float)::{lambda(std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&)#1}>::_M_invoke(std::_Any_data const&, std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#17 0x000000010499dea6 in std::function<bool (std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&)>::operator()(std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&) const () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#18 0x0000000104998801 in vg::get_blocks(vg::VG&, std::function<bool (std::pair<long long, long long>&, std::pair<long long, long long> const&, std::vector<std::pair<long long, long long>, std::allocator<std::pair<long long, long long> > > const&)>) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#19 0x0000000104998c85 in vg::get_haploblocks(vg::VG&, float, float) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#20 0x00000001049a255a in vg::XAG::from_AG(vg::AG&, bool, bool, bool, bool) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#21 0x0000000104c3a537 in createIndexFromGraph(vg::AG&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#22 0x0000000104c4386b in v8::Local<v8::Value> nbind::Caller<vg::XAG, nbind::TypeList<nbind::ArgFromWire<nbind::PolicyListType<>, 0ul, vg::AG&> > >::callFunction<vg::XAG (*)(vg::AG&), Nan::FunctionCallbackInfo<v8::Value> const>(vg::XAG (*)(vg::AG&), Nan::FunctionCallbackInfo<v8::Value> const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#23 0x0000000104c43972 in void nbind::TemplatedBaseSignature<nbind::FunctionSignature<vg::XAG (*)(vg::AG&), decltype(nullptr), nbind::PolicyListType<>, vg::XAG<vg::AG&> >, vg::XAG<vg::AG&>, vg::XAG<vg::AG&> >::callInnerSafely<void, Nan::FunctionCallbackInfo<v8::Value> const, Nan::FunctionCallbackInfo<v8::Value> >(Nan::FunctionCallbackInfo<v8::Value> const&, Nan::FunctionCallbackInfo<v8::Value>&, unsigned int) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node
#24 0x0000000104c46c33 in Nan::imp::FunctionCallbackWrapper(v8::FunctionCallbackInfo<v8::Value> const&) () from /Users/heumos/git/genome-graph-visualization/build/Release/nbind.node

But this time I did add

// add class XAG
NBIND_CLASS(XAG){}

Here is the corresponding code C++ code:

XAG createIndexFromGraph(AG& graph) {
    std::cout<<"entered index method.\n";
    XAG index;
    index.from_AG(graph);
    std::cout<<"index created successfully.\n";
    return index;
}

The constructAnnotationGraph method is the same as above.
Here the relevant JavaScript:

var nbind = require('nbind');
var lib = nbind.init().lib;

var fasta_file_name = "tiny/tiny.fa";
var vcf_file_name = "tiny/tiny.vcf.gz";
var gff_file_name = "tiny/tiny.gff";

var json_out_name = "tiny/tiny.json";

console.log("constructing annotation graph...");
var annotationGraph = lib.constructAnnotationGraph(fasta_file_name, vcf_file_name,
  gff_file_name);

console.log("indexing graph...");
var xag = lib.createIndexFromGraph(annotationGraph);

What did I miss?

from nbind.

jjrv avatar jjrv commented on May 14, 2024

Now the crash is deep inside vg. One possible issue is that earlier you're returning annotation_graph by value, so it will be copied or moved to the heap afterwards. Maybe it wasn't meant to be copied or moved at all? In that case you'd have to instead allocate it like auto annotation_graph = std::make_shared<AG>(variant_file...

I'm afraid debugging this may involve figuring out what goes wrong inside vg. I'll try to look for the AG class definition and see if there's any obvious clues...

from nbind.

jjrv avatar jjrv commented on May 14, 2024

I made a mistake in the previous comment so if you already read how to allocate using pointers, forget what it said before this edited version...

from nbind.

jjrv avatar jjrv commented on May 14, 2024

Is the code for AG and XAG classes publicly available somewhere? For example searching Google for get_haploblocks I only find Python code, and I also tried searching the vg codebase after git clone --recursive https://github.com/vgteam/vg.git but got no results.

Without seeing the code, I'd suggest to try not returning the AG object by value.

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

Unfortunately, you won't find any AG in the current version of vg as I am using an extended version for which a pull and merge is not yet done.

However I am still surprised that this does not work, because the following code that I tested directly in vg does work:

AG graph = constructAnnotationGraph(fasta_file_name, vcf_file_name, gff_file_name);

XAG index = createIndexFromGraph(graph);

The method definitions are the same as above. Maybe I am having trouble with C++ reference, value, address stuff.

from nbind.

jjrv avatar jjrv commented on May 14, 2024

Your pure C++ code keeps the graph object in the C++ stack, not needing any copies or moves. Also if you return such an object by value to another C++ function, the compiler can still perform magic to avoid moving it around. Once you return it to JavaScript, it has to go out of the stack and to the heap, or it would get destroyed. The constructors implemented may not support this, so one option is to make sure it's placed in the heap initially, where it can safely stay.

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

Now I see the problem :)

So i have to rethink everything, keeping this in mind:
http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/
Thanks for the useful hints!
I will try out the stuff tomorrow.

from nbind.

jjrv avatar jjrv commented on May 14, 2024

That may not be the cause of the issue, but it's worth a try. Testing std::make_shared instead of allocating on the stack shouldn't require big changes in this case.

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

I tried, but it does not work. I think due to the reason that AG inherits from VG.

../cpp/JS_AG.cpp: In function 'vg::AG constructAnnotationGraph(std::string, std::string, std::string)':
../cpp/JS_AG.cpp:96:22: error: 'class std::shared_ptr<vg::AG>' has no member named 'paths'
     annotation_graph.paths.write(paths_out);
                      ^
../cpp/JS_AG.cpp:102:22: error: 'class std::shared_ptr<vg::AG>' has no member named 'paths'
     annotation_graph.paths.for_each_name(
                      ^
../cpp/JS_AG.cpp:110:12: error: could not convert 'annotation_graph' from 'std::shared_ptr<vg::AG>' to 'vg::AG'
     return annotation_graph;
            ^
../cpp/JS_AG.cpp:111:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make: *** [Release/obj.target/nbind/cpp/JS_AG.o] Error 1

Or did I do it wrong?

AG constructAnnotationGraph(std::string fasta_file_name, std::string vcf_file_name,
  std::string gff_file_name) {

  	FastaReference reference;
    reference.open(fasta_file_name);

    vcflib::VariantCallFile variant_file;
    variant_file.open(vcf_file_name);

    std::string region;
    bool region_is_chrom = false;

    // values extracted from main
    int vars_per_region = 25000;
    int max_node_size = 1000;

    bool flat_alts = true;
    bool load_phasing_paths = true;
    bool load_alt_paths = false;
    bool progress = true;
    set<string>* propagate = nullptr;

    auto annotation_graph = std::make_shared<AG>(variant_file, reference, region, gff_file_name, region_is_chrom,
  			vars_per_region, max_node_size, flat_alts, load_phasing_paths,
  			load_alt_paths, progress, propagate);
    std::cout<<"annotation graph successfully build!\n";
    // "-P ref_paths_file"
    ofstream paths_out("/dev/null");
    annotation_graph.paths.write(paths_out);

    // we want to load the phasing paths, too
    std::cout<<"loading phasing paths...\n";
    set<string> non_phase_paths;
    std::string phase_prefix = "_phase";
    annotation_graph.paths.for_each_name(
        [&](string path_name) {
          if(!equal(phase_prefix.begin(), phase_prefix.end(), path_name.begin())) {
            // Path is not a phase path
            non_phase_paths.insert(path_name);
          }
        });
    std::cout<<"done.\n";
    return annotation_graph;
}

from nbind.

jjrv avatar jjrv commented on May 14, 2024

Now that the type of annotation_graph is a kind of pointer, you need to access its members like annotation_graph->paths. Also if AG extends VG and later you want to call VG methods on AG objects in JavaScript, you'll want to do:

NBIND_CLASS(AG) {
  inherit(VG);
}

or

NBIND_CLASS(JS_AG, AG) {
  inherit(JS_VG);
}

This is also needed if a method takes a VG parameter and you have an AG object in JavaScript.

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

The no member errors are gone, but it is still not convertible.

Looking here http://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast in the example, I would have suggested the following:

    std::shared_ptr<VG> ptr_to_vg(std::make_shared<AG>());

    auto annotation_graph = std::static_pointer_cast<AG>(ptr_to_vg)->AG(variant_file, reference, region, gff_file_name, region_is_chrom,
  			vars_per_region, max_node_size, flat_alts, load_phasing_paths,
  			load_alt_paths, progress, propagate);

But:

../cpp/JS_AG.cpp: In function 'vg::AG constructAnnotationGraph(std::string, std::string, std::string)':
../cpp/JS_AG.cpp:92:70: error: invalid use of 'vg::AG::AG'
     auto annotation_graph = std::static_pointer_cast<AG>(ptr_to_vg)->AG(variant_file, reference, region, gff_file_name, region_is_chrom,
                                                                      ^
../cpp/JS_AG.cpp:113:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make: *** [Release/obj.target/nbind/cpp/JS_AG.o] Error 1

from nbind.

subwaystation avatar subwaystation commented on May 14, 2024

Oh man, sure. FACEPALM
Thanks, now it works 👍

from nbind.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.