Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectRef ownership lose issue #4

Open
Trzeth opened this issue Jun 20, 2022 · 1 comment
Open

ObjectRef ownership lose issue #4

Trzeth opened this issue Jun 20, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@Trzeth
Copy link

Trzeth commented Jun 20, 2022

When I try to deal with json data encounter this, here is some test code.

    let root = Request::new("https://api.dmzj.com/dynamic/comicinfo/40956.json", HttpMethod::Get).json().as_object()?;
    
    // two level get will make result empty
    let infoNodeEmpty = root.get("data").as_object()?.get("info").as_object()?;
    check!(infoNodeEmpty);
    //check!(infoNode.get("id").as_string().read());

    let infoNodeOK = root
        .get("data")
        .as_object()?
        .get("info")
        .clone()// Add clone make this ok
        .as_object()?;
    check!(infoNodeOK);

    let dataNode = root.get("data");
    vcheck!(dataNode);// OK

    let dataNodeCopy = root.get("data");
    let infoNode1 = dataNodeCopy.as_object()?.get("info");
    vcheck!(infoNode1);// Empty
    // Maybe this cause issue.


    let dataNodeObject = root.get("data").as_object()?;
    check!(dataNodeObject);

used marco

macro_rules! check {
    ($e: expr) => {
        println!(
            "ObjectRef {}:{} is {}",
            stringify!($e),
            $e.rid(),
            match $e.is_empty() {
                true => "Empty",
                false => "OK",
            }
        );
    };
}

macro_rules! vcheck {
    ($e: expr) => {
        println!(
            "ValueRef {}:{} is {}",
            stringify!($e),
            $e.rid(),
            match $e.is_none() {
                true => "Empty",
                false => "OK",
            }
        )
    };
}
@Skittyblock Skittyblock added the bug Something isn't working label Jun 20, 2022
@Skittyblock
Copy link
Member

This is due to rust dropping a value that Aidoku needs to stay alive. I could fix this on Aidoku's side but it would mean more difficult memory management for any source language apart from rust, so ideally if there's a rust way to do it better that would be best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants