Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xrc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Lukas Markeffsky
xrc
Commits
0faba12c
Commit
0faba12c
authored
1 year ago
by
Lukas Markeffsky
Browse files
Options
Downloads
Patches
Plain Diff
bonus asserts + test
parent
35cdd195
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib.rs
+19
-0
19 additions, 0 deletions
src/lib.rs
with
19 additions
and
0 deletions
src/lib.rs
+
19
−
0
View file @
0faba12c
...
@@ -135,6 +135,7 @@ pub struct Unclaimed<T> {
...
@@ -135,6 +135,7 @@ pub struct Unclaimed<T> {
impl
<
T
>
Unclaimed
<
T
>
{
impl
<
T
>
Unclaimed
<
T
>
{
pub
fn
claim
(
self
,
value
:
T
)
->
Xrc
<
T
>
{
pub
fn
claim
(
self
,
value
:
T
)
->
Xrc
<
T
>
{
unsafe
{
unsafe
{
debug_assert_eq!
((
*
self
.ptr
.as_ptr
())
.state
.get
(),
STATE_UNCLAIMED
);
(
*
self
.ptr
.as_ptr
())
.state
.set
(
STATE_SHARED_INIT
);
(
*
self
.ptr
.as_ptr
())
.state
.set
(
STATE_SHARED_INIT
);
}
}
...
@@ -163,6 +164,7 @@ impl<T: ?Sized> Drop for Xrc<T> {
...
@@ -163,6 +164,7 @@ impl<T: ?Sized> Drop for Xrc<T> {
let
state_ref
=
unsafe
{
&
(
*
root
.as_ptr
())
.state
};
let
state_ref
=
unsafe
{
&
(
*
root
.as_ptr
())
.state
};
let
state
=
state_ref
.get
();
let
state
=
state_ref
.get
();
debug_assert!
(
state
<=
STATE_SHARED_MAX
);
if
state
!=
STATE_SHARED_INIT
{
if
state
!=
STATE_SHARED_INIT
{
state_ref
.set
(
state
-
1
);
state_ref
.set
(
state
-
1
);
return
;
return
;
...
@@ -184,6 +186,7 @@ impl<T> Clone for Xrc<T> {
...
@@ -184,6 +186,7 @@ impl<T> Clone for Xrc<T> {
let
state_ref
=
unsafe
{
&
(
*
root
.as_ptr
())
.state
};
let
state_ref
=
unsafe
{
&
(
*
root
.as_ptr
())
.state
};
let
state
=
state_ref
.get
();
let
state
=
state_ref
.get
();
debug_assert!
(
state
<=
STATE_SHARED_MAX
);
if
state
==
STATE_SHARED_MAX
{
if
state
==
STATE_SHARED_MAX
{
panic!
(
"ref count overflow"
);
panic!
(
"ref count overflow"
);
}
}
...
@@ -243,6 +246,7 @@ mod tests {
...
@@ -243,6 +246,7 @@ mod tests {
use
std
::
pin
::
pin
;
use
std
::
pin
::
pin
;
use
std
::
ptr
;
use
std
::
ptr
;
use
std
::
rc
::
Rc
;
use
std
::
rc
::
Rc
;
use
std
::
panic
::{
self
,
AssertUnwindSafe
};
fn
iter_pinned_mut
<
T
>
(
slice
:
Pin
<&
mut
[
T
]
>
)
->
impl
Iterator
<
Item
=
Pin
<&
mut
T
>>
{
fn
iter_pinned_mut
<
T
>
(
slice
:
Pin
<&
mut
[
T
]
>
)
->
impl
Iterator
<
Item
=
Pin
<&
mut
T
>>
{
unsafe
{
unsafe
{
...
@@ -260,6 +264,21 @@ mod tests {
...
@@ -260,6 +264,21 @@ mod tests {
assert_eq!
(
xrc
.0
,
42
);
assert_eq!
(
xrc
.0
,
42
);
}
}
#[test]
fn
unpin_hack
()
{
let
mut
root
=
pin!
(
Root
::
new
());
let
xrc
=
root
.as_mut
()
.unclaimed
()
.claim
(
NoReclaim
(
42
));
let
res
=
panic
::
catch_unwind
(
AssertUnwindSafe
(||
{
// This must not create an unique borrow ...
let
_
=
root
.unclaimed
();
}));
assert!
(
res
.is_err
());
// ... to not invalidate this shared read-only borrow.
assert_eq!
(
xrc
.0
,
42
);
}
#[test]
#[test]
#[ignore
=
"will abort"
]
#[ignore
=
"will abort"
]
fn
abort
()
{
fn
abort
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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