Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nora Puchreiner
Nix
Commits
b4edc3ca
Commit
b4edc3ca
authored
5 years ago
by
Eelco Dolstra
Browse files
Options
Downloads
Patches
Plain Diff
Don't leak exceptions
parent
e6bd8887
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
nix-rust/src/error.rs
+18
-2
18 additions, 2 deletions
nix-rust/src/error.rs
src/libutil/rust-ffi.cc
+5
-1
5 additions, 1 deletion
src/libutil/rust-ffi.cc
src/libutil/rust-ffi.hh
+25
-6
25 additions, 6 deletions
src/libutil/rust-ffi.hh
with
48 additions
and
9 deletions
nix-rust/src/error.rs
+
18
−
2
View file @
b4edc3ca
...
...
@@ -76,7 +76,7 @@ impl From<Error> for CppException {
fn
from
(
err
:
Error
)
->
Self
{
match
err
{
Error
::
Foreign
(
ex
)
=>
ex
,
_
=>
unsafe
{
make_error
(
&
err
.to_string
())
}
,
_
=>
CppException
::
new
(
&
err
.to_string
()),
}
}
}
...
...
@@ -85,7 +85,23 @@ impl From<Error> for CppException {
#[derive(Debug)]
pub
struct
CppException
(
*
const
libc
::
c_void
);
// == std::exception_ptr*
impl
CppException
{
fn
new
(
s
:
&
str
)
->
Self
{
Self
(
unsafe
{
make_error
(
s
)
})
}
}
impl
Drop
for
CppException
{
fn
drop
(
&
mut
self
)
{
unsafe
{
destroy_error
(
self
.0
);
}
}
}
extern
"C"
{
#[allow(improper_ctypes)]
// YOLO
fn
make_error
(
s
:
&
str
)
->
CppException
;
fn
make_error
(
s
:
&
str
)
->
*
const
libc
::
c_void
;
fn
destroy_error
(
exc
:
*
const
libc
::
c_void
);
}
This diff is collapsed.
Click to expand it.
src/libutil/rust-ffi.cc
+
5
−
1
View file @
b4edc3ca
...
...
@@ -3,10 +3,14 @@
extern
"C"
std
::
exception_ptr
*
make_error
(
rust
::
StringSlice
s
)
{
// FIXME: leak
return
new
std
::
exception_ptr
(
std
::
make_exception_ptr
(
nix
::
Error
(
std
::
string
(
s
.
ptr
,
s
.
size
))));
}
extern
"C"
void
destroy_error
(
std
::
exception_ptr
*
ex
)
{
free
(
ex
);
}
namespace
rust
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
str
,
const
String
&
s
)
...
...
This diff is collapsed.
Click to expand it.
src/libutil/rust-ffi.hh
+
25
−
6
View file @
b4edc3ca
...
...
@@ -152,28 +152,47 @@ struct Source
template
<
typename
T
>
struct
Result
{
unsigned
int
tag
;
enum
{
Ok
=
0
,
Err
=
1
,
Uninit
=
2
}
tag
;
union
{
T
data
;
std
::
exception_ptr
*
exc
;
};
Result
()
:
tag
(
Uninit
)
{
};
// FIXME: remove
Result
(
const
Result
&
)
=
delete
;
Result
(
Result
&&
other
)
:
tag
(
other
.
tag
)
{
other
.
tag
=
Uninit
;
if
(
tag
==
Ok
)
data
=
std
::
move
(
other
.
data
);
else
if
(
tag
==
Err
)
exc
=
other
.
exc
;
}
~
Result
()
{
if
(
tag
==
0
)
if
(
tag
==
Ok
)
data
.
~
T
();
else
if
(
tag
==
1
)
// FIXME: don't leak exc
else
if
(
tag
==
Err
)
free
(
exc
);
else
if
(
tag
==
Uninit
)
;
else
abort
();
}
/* Rethrow the wrapped exception or return the wrapped value. */
T
unwrap
()
{
if
(
tag
==
0
)
if
(
tag
==
Ok
)
{
tag
=
Uninit
;
return
std
::
move
(
data
);
else
if
(
tag
==
1
)
}
else
if
(
tag
==
Err
)
std
::
rethrow_exception
(
*
exc
);
else
abort
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment