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

[Pytorch] Fix StringSupplier and TensorIdGetter returning pointers to local variables #1391

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bytedeco.pytorch.functions;

import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.FunctionPointer;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
Expand All @@ -25,5 +26,5 @@ protected NamedModuleApplyFunction() {

private native void allocate();

public native void call(@Const @StdString @ByRef String name, @ByRef Module m);
public native void call(@Const @StdString BytePointer name, @ByRef Module m);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bytedeco.pytorch.functions;

import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.FunctionPointer;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
Expand All @@ -25,5 +26,5 @@ protected NamedSharedModuleApplyFunction() {

private native void allocate();

public native void call(@Const @StdString @ByRef String name, @ByRef @SharedPtr @Cast({"", "std::shared_ptr<torch::nn::Module>"}) Module m);
public native void call(@Const @StdString BytePointer name, @ByRef @SharedPtr @Cast({"", "std::shared_ptr<torch::nn::Module>"}) Module m);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ protected PickleWriter() {

private native void allocate();

public native void call(@Cast("const char *") BytePointer buf, @Cast("size_t") long nbytes);
public native void call(@Cast("const char*") BytePointer buf, @Cast("size_t") long nbytes);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.bytedeco.pytorch.functions;

import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.FunctionPointer;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.annotation.Cast;
import org.bytedeco.javacpp.annotation.Const;
import org.bytedeco.javacpp.annotation.Properties;
import org.bytedeco.javacpp.annotation.StdString;

Expand All @@ -26,5 +27,6 @@ protected StringConsumer() {

private native void allocate();

public native void call(@Cast({"", "const std::string&"}) @StdString String s);
// std::function<void(const std::string&)>
public native void call(@Const @StdString BytePointer s);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.bytedeco.pytorch.functions;

import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.FunctionPointer;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.annotation.Cast;
import org.bytedeco.javacpp.annotation.Properties;
import org.bytedeco.javacpp.annotation.StdString;

Expand All @@ -25,5 +27,6 @@ protected StringSupplier() {

private native void allocate();

public native @StdString String call();
// Without the cast, the function returns a std::basic_string<char>& and the cast from StringAdapter returns a reference to a variable in the stack.
public native @StdString @Cast({"", "char*"}) BytePointer call();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ protected TensorIdGetter() {
private native void allocate();

// std::function<std::string(const at::Tensor&)>
public native @StdString String call(@Const @ByRef Tensor tensor);
// Without the cast, the function returns a std::basic_string<char>& and the cast from StringAdapter returns a reference to a variable in the stack.
public native @StdString @Cast({"", "char*"}) BytePointer call(@Const @ByRef Tensor tensor);
}