Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
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
The Tor Project
Core
Tor
Commits
01a977b4
Unverified
Commit
01a977b4
authored
7 years ago
by
teor
Browse files
Options
Downloads
Patches
Plain Diff
Update the primitive types explanation in the Rust coding standards
Part of
#25368
. Includes c_double in anticipation of
#23061
.
parent
54e25ab1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/HACKING/CodingStandardsRust.md
+18
-4
18 additions, 4 deletions
doc/HACKING/CodingStandardsRust.md
with
18 additions
and
4 deletions
doc/HACKING/CodingStandardsRust.md
+
18
−
4
View file @
01a977b4
...
...
@@ -284,12 +284,26 @@ Here are some additional bits of advice and rules:
}
}
3.
Pass only
integer
types and bytes over the boundary
3.
Pass only
C-compatible primitive
types and bytes over the boundary
The only non-integer type which may cross the FFI boundary is
Rust's C-compatible primitive types are integers and floats.
These types are declared in the
[
libc crate
](
https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/index.html#types
)
.
Most Rust objects have different
[
representations
](
https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/index.html#types
)
in C and Rust, so they can't be passed using FFI.
Tor currently uses the following Rust primitive types from libc for FFI:
*
defined-size integers:
`uint32_t`
*
native-sized integers:
`c_int`
*
native-sized floats:
`c_double`
*
native-sized raw pointers:
`* c_void`
,
`* c_char`
,
`** c_char`
TODO: C smartlist to Stringlist conversion using FFI
The only non-primitive type which may cross the FFI boundary is
bytes, e.g.
`&[u8]`
. This SHOULD be done on the Rust side by
passing a pointer (
`*mut libc::c_char`
) and a length
(
`libc::size_t`
).
passing a pointer (
`*mut libc::c_char`
). The length can be passed
explicitly (
`libc::size_t`
), or the string can be NUL-byte terminated
C string.
One might be tempted to do this via doing
`CString::new("blah").unwrap().into_raw()`
. This has several problems:
...
...
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