Fix C# binding thread-safety.

GitOrigin-RevId: 48b4ec74878f815d2a3d280a9f9f8a524509ab93
This commit is contained in:
levlam 2018-09-03 12:47:32 +03:00
parent a56f70c340
commit dea5dea49a
3 changed files with 12 additions and 23 deletions

View File

@ -213,7 +213,7 @@ EOT
/// </summary>
EOT;
foreach ($known_fields as $name => $type) {
$full_doc .= '\r\n /// <param name="'.$this->getParameterName($name, $class_name).'">'.$info[$name]."</param>";
$full_doc .= "\r\n /// <param name=\"".$this->getParameterName($name, $class_name).'">'.$info[$name]."</param>";
}
$this->addDocumentation($full_constructor, $full_doc);
}

View File

@ -527,9 +527,7 @@ class TlWriterDotNet : public TL_writer {
return ss.str();
}
ss << "{\n";
ss << " CallFromUnmanaged<" << class_name << "^> res;\n";
ss << " downcast_call(from, res);\n";
ss << " return CallFromUnmanagedRes<" << class_name << "^>::res;\n";
ss << " return DoFromUnmanaged<" << class_name << "^>(from);\n";
ss << "}\n";
}
return ss.str();

View File

@ -100,30 +100,21 @@ auto CLRCALL FromUnmanaged(td::td_api::object_ptr<T> &from) -> decltype(FromUnma
return FromUnmanaged(*from.get());
}
template <class ResT>
ref class CallFromUnmanagedRes {
public:
static property ResT res;
};
template <class ResT>
struct CallFromUnmanaged {
template <class T>
void operator()(T &val) const {
CallFromUnmanagedRes<ResT>::res = FromUnmanaged(val);
template <class ResT, class T>
inline ResT DoFromUnmanaged(T &from) {
ResT res;
downcast_call(from, [&](auto &from_downcasted) {
res = FromUnmanaged(from_downcasted);
});
return res;
}
};
inline BaseObject^ FromUnmanaged(td::td_api::Function &from) {
CallFromUnmanaged<BaseObject^> res;
downcast_call(from, res);
return CallFromUnmanagedRes<BaseObject^>::res;
return DoFromUnmanaged<BaseObject^>(from);
}
inline BaseObject^ FromUnmanaged(td::td_api::Object &from) {
CallFromUnmanaged<BaseObject^> res;
downcast_call(from, res);
return CallFromUnmanagedRes<BaseObject^>::res;
return DoFromUnmanaged<BaseObject^>(from);
}
// to unmanaged