Code Monkey home page Code Monkey logo

Comments (5)

robertsawko avatar robertsawko commented on June 8, 2024 1

Thanks for quick reply. I've stumbled across it randomly as I was trying to avoid copy constructors.

Just to confirm:

#include <conduit.hpp>

int main (int argc, char *argv[]) {
    conduit::Node root;

    double* ptr = new double[3]{1, 2, 3};
    conduit::Node subtree;
    subtree["to/data"].set_external(ptr, 3);
    root["path"].move(subtree);
    root["empty"];
    root.print();
    std::cout << "Node name: " << root["path"].name() << std::endl;
    std::cout << "Node name: " << root["empty"].name() << std::endl;
    conduit::Node copy = root;
    std::cout << "Node name after copy: " << copy["path"].name() << std::endl;
    return 0;
}

Gives on Conduit 0.8.8:

path:
  to:
    data: [1.0, 2.0, 3.0]
empty:

Node name:
Node name: empty
Node name after copy: path

from conduit.

cyrush avatar cyrush commented on June 8, 2024

@robertsawko

Thanks for the question, executing:

root["path"]

Will create an empty node named "path"` as a child for root node - before the move is executed.

The move destination is the node it is called on, so in this case it is root["path"] instead of root

I would expect:

std::cout << "Node name: " << root["path"].name() << std::endl;

To show path, since this did not work- sounds like a bug & we need to fix the move implementation.

We will look into this more.

from conduit.

cyrush avatar cyrush commented on June 8, 2024

thanks for the output -- we will work to fix this case.

from conduit.

JustinPrivitera avatar JustinPrivitera commented on June 8, 2024

Here is a simpler reproducer - it has to do with Node::swap():

Node root, subtree;
subtree["to/data"] = 5;
root["path"]["to"]["data"] = 6;


std::cout << "Node name: " << root["path"].name() << std::endl;
if (root["path"].schema().parent() != NULL)
    std::cout << "path schema parent exists" << std::endl;
else
    std::cout << "path schema parent does not exist" << std::endl;

// swap gets rid of the schema parent, which breaks name()
root["path"].swap(subtree);

std::cout << "Node name: " << root["path"].name() << std::endl;
if (root["path"].schema().parent() != NULL)
    std::cout << "path schema parent exists" << std::endl;
else
    std::cout << "path schema parent does not exist" << std::endl;

yields:

Node name: path
path schema parent exists
Node name: 
path schema parent does not exist

swap is used internally by move.

from conduit.

JustinPrivitera avatar JustinPrivitera commented on June 8, 2024

here is a fix: #1179

from conduit.

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.