You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
curl::easy::Easy2::default_configure registers an error buffer like this:
self.setopt_ptr(
curl_sys::CURLOPT_ERRORBUFFER,self.inner.error_buf.borrow().as_ptr()as*const_,).expect("failed to set error buffer");
CURLOPT_ERRORBUFFER requires mutable access over the buffer, and it is important that the buffer pointer is still valid later on when further library calls are made. However, error_buf is borrowed immutably and only for a short time (until the end of the statement).
Using a raw pointer to the error buffer with no extra safety features. This is functionally equivalent to the status quo. No idea if this is sound; that would depend on libcurl. The documentation page on error buffers is not very detailed. This option is kinda bad because unsafe would be spread over the entire file instead of being contained in an abstraction.
structInner<H>{// ...error_buf:*mutu8,// ...}
Registering a new error buffer for every call to libcurl and then reregistering the previous buffer afterwards.
Creating a custom cell type (HandleCell) similar to a RefCell that ensures that you never have a RawHandle and an ErrorBuf at the same time. This would prevent reentrant usage of curl functions. That might be a breaking change if reentrant usage is currently allowed.
mod cell {// notably not Clone or CopystructCurlHandle<'a>(*mut curl_sys::CURL,&'a Cell<HandleCellState>);implCurlHandle<'_>{pubfnsetopt_long(&mutself,opt: curl_sys::CURLoption,val:c_long) -> Result<(),Error>{/* ... */}/* + all other functions which call a libcurl fn with a handle ... */}implDropforCurlHandle<'_>{/* reset state of cell */}structErrorBufRef<'a>(&'a [u8],&'a Cell<HandleCellState>);implDropforErrorBufRef<'_>{/* reset state of cell */}pubstructHandleCell{state:Cell<HandleCellState>,handle:*mut curl_sys::CURL,error_buf:Vec<u8>,}/// What field is currently borrowed?enumHandleCell{None,Handle,ErrorBuf,}implHandleCell{pubfnget_handle(&self) -> CurlHandle<'_>{/* ... */}pubfnget_error_buf(&self) -> ErrorBufRef<'_>{/* ... */}}}
Same as 3., except that reentrant usage is made possible. If a reentrant (non-outermost) call to libcurl ends up failing, it would not be possible to read the error buffer and the standard error message would be used instead.
I prefer option 1. because I'd assume that it is always okay to read the error buffer whenever our machine is not executing code from libcurl.
curl::easy::Easy2::default_configure
registers an error buffer like this:CURLOPT_ERRORBUFFER
requires mutable access over the buffer, and it is important that the buffer pointer is still valid later on when further library calls are made. However,error_buf
is borrowed immutably and only for a short time (until the end of the statement).(A mutable borrow might look like this:
That does not solve the lifetime problem, though.)
The text was updated successfully, but these errors were encountered: