Skip to content

Commit

Permalink
Renamed repr_c as safer_ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhenrymantilla committed May 29, 2020
1 parent 1583b60 commit b6f0759
Show file tree
Hide file tree
Showing 40 changed files with 264 additions and 251 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
path = "src/_lib.rs"

[package]
name = "repr_c"
name = "safer_ffi"
version = "0.1.0"
authors = ["Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>"]
edition = "2018"
Expand Down Expand Up @@ -53,7 +53,7 @@ inventory = { version = "0.1.6", optional = true }
proc-macro-hack = { version = "0.5.15", optional = true }

[dependencies.proc_macro]
package = "repr_c-proc_macro"
package = "safer_ffi-proc_macro"
path = "src/proc_macro"
version = "0.1.0"

Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# `::repr_c`
# `::safer_ffi`

See the [user guide](https://getditto.github.io/safer_ffi).

# ⚠️ WIP ⚠️

Expand All @@ -25,16 +27,16 @@ edition = "2018"
crate-type = ["staticlib"]

[dependencies]
repr_c = { git = "https://github.com/getditto/rust-repr_c.git", features = ["proc_macros"] }
safer_ffi = { git = "https://github.com/getditto/rust-safer_ffi.git", features = ["proc_macros"] }

[features]
c-headers = ["repr_c/headers"]
c-headers = ["safer_ffi/headers"]
```

### `src/lib.rs`

```rust
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;

#[derive_ReprC]
#[repr(C)]
Expand Down Expand Up @@ -63,11 +65,11 @@ fn print_point (point: &'_ Point)
println!("{:?}", point);
}

#[::repr_c::cfg_headers]
#[::safer_ffi::cfg_headers]
#[test]
fn generate_headers () -> ::std::io::Result<()>
{
::repr_c::headers::builder()
::safer_ffi::headers::builder()
.to_file("rust_points.h")?
.generate()
}
Expand All @@ -87,13 +89,13 @@ cargo test --features c-headers -- generate_headers

```C
/*! \file */
/****************************************
* *
* File auto-generated by `::repr_c`. *
* *
* Do not manually edit this file. *
* *
****************************************/
/*******************************************
* *
* File auto-generated by `::safer_ffi`. *
* *
* Do not manually edit this file. *
* *
*******************************************/

#ifndef __RUST_CRATE_NAME__
#define __RUST_CRATE_NAME__
Expand Down
4 changes: 2 additions & 2 deletions ffi_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ authors = ["Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>"]
edition = "2018"

[dependencies]
repr_c = { path = "..", features = ["proc_macros"] }
safer_ffi = { path = "..", features = ["proc_macros"] }

[features]
generate-headers = ["repr_c/headers"]
generate-headers = ["safer_ffi/headers"]

# [dev-dependencies]
# cc = "1.0.50"
Expand Down
38 changes: 19 additions & 19 deletions ffi_tests/generated.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*! \file */
/****************************************
* *
* File auto-generated by `::repr_c`. *
* *
* Do not manually edit this file. *
* *
****************************************/
/*******************************************
* *
* File auto-generated by `::safer_ffi`. *
* *
* Do not manually edit this file. *
* *
*******************************************/

#ifndef __RUST_FFI_TESTS__
#define __RUST_FFI_TESTS__
Expand All @@ -14,9 +14,19 @@
extern "C" {
#endif

typedef struct foo foo_t;

foo_t * new_foo (void);


#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

int32_t read_foo (
foo_t const * foo);

void free_foo (
foo_t * foo);

/** \remark Has the same ABI as `uint8_t` **/
#ifdef DOXYGEN
Expand All @@ -36,16 +46,6 @@ Bar_t
void check_bar (
Bar_t _bar);

typedef struct foo foo_t;

foo_t * new_foo (void);

int32_t read_foo (
foo_t const * foo);

void free_foo (
foo_t * foo);

/** \brief
* Concatenate the two input strings into a new one.
*
Expand Down Expand Up @@ -87,7 +87,7 @@ void with_concat (
* typedef struct {
* // Cannot be NULL
* T * ptr;
* uintptr_t len;
* size_t len;
* } slice_T;
* ```
*
Expand Down
8 changes: 4 additions & 4 deletions ffi_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;

/// Concatenate the two input strings into a new one.
///
Expand Down Expand Up @@ -49,7 +49,7 @@ mod foo {
use super::*;

#[derive_ReprC]
#[repr_c::opaque("foo")]
#[ReprC::opaque("foo")]
pub
struct Foo { hidden: i32 }

Expand Down Expand Up @@ -84,12 +84,12 @@ mod bar {
{}
}

#[repr_c::cfg_headers]
#[safer_ffi::cfg_headers]
#[test]
fn generate_headers ()
-> ::std::io::Result<()>
{
let builder = ::repr_c::headers::builder();
let builder = ::safer_ffi::headers::builder();
if ::std::env::var("HEADERS_TO_STDOUT").ok().map_or(false, |it| it == "1") {
builder
.to_writer(::std::io::stdout())
Expand Down
4 changes: 2 additions & 2 deletions guide/book.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[book]
title = "`repr_c` User Guide"
guide = "A guide to learn how to use the `::repr_c` FFI framework"
title = "`safer_ffi` User Guide"
guide = "A guide to learn how to use the `::safer_ffi` FFI framework"
authors = ["Daniel Henry-Mantilla"]
language = "en"
multilingual = false
Expand Down
2 changes: 1 addition & 1 deletion guide/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@

[Appendix: FFI and C compilation](appendix/c-compilation.md)

[Appendix: how does `repr_c` work](appendix/how-does-repr_c-work.md)
[Appendix: how does `safer_ffi` work](appendix/how-does-safer_ffi-work.md)
2 changes: 1 addition & 1 deletion guide/src/appendix/free-compatibility.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appendix: Being compatible with `free()`

```rust,noplaypen
use ::repr_c::{prelude::*, ptr};
use ::safer_ffi::{prelude::*, ptr};
/// A `Box`-like owned pointer type, but which can be freed using `free()`.
#[derive_ReprC]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#include ../links.md}}

# Appendix: how does `repr_c` work
# Appendix: how does `safer_ffi` work

Most of the limitations of traditional FFI are related to the design of
`cbindgen` and its being **implemented as a syntactic tool**: without access to
Expand All @@ -22,13 +22,13 @@ course):

- by encoding invariants and reflection within the type system, through a
complex but stable use of helper traits. **This is the choice made by
`repr_c`**, whereby _two_ traits suffice to express the necssary semantics
`safer_ffi`**, whereby _two_ traits suffice to express the necssary semantics
for FFI compatibility and integration:

- the user-facing [`ReprC`] trait, implemented for types having a defined
C layout:

- either directly provided by the `repr_c` crate (_c.f._ [its
- either directly provided by the `safer_ffi` crate (_c.f._ [its
dedicated chapter][repr-c-forall]),

- or implemented for custom types having the
Expand Down
10 changes: 5 additions & 5 deletions guide/src/derive-reprc/_.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

- [API Documentation][`ReprC`]

`ReprC` is the core trait around `repr_c`'s design.
`ReprC` is the core trait around `safer_ffi`'s design.

- Feel free to [look at the appendix to understand why and
how][how-does-repr_c-work].
how][how-does-safer_ffi-work].

Indeed,

Expand Down Expand Up @@ -35,7 +35,7 @@ wrapper. A convenience macro is planned to be added to automate that step.

</details>

- when it is [a specialy-crafted type exported from the `repr_c` crate](
- when it is [a specialy-crafted type exported from the `safer_ffi` crate](
../motivation/repr-c-forall.md),

- or **when it is a custom type that is `#[derive_ReprC]`-annotated**.
Expand Down Expand Up @@ -64,10 +64,10 @@ Currently, the supported types for the attribute are:
declaration: `typedef struct MyOpaque MyOpaque_t;`

```rust,noplaypen
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;
#[derive_ReprC]
#[repr_c::opaque]
#[ReprC::opaque]
struct MyOpaque {
/* anything goes here */
}
Expand Down
4 changes: 2 additions & 2 deletions guide/src/derive-reprc/enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ See [the reference for more info about them][rust-reference-fieldless-enums].
### Usage

```rust,noplaypen
use ::repr_c::prelude:*;
use ::safer_ffi::prelude:*;
#[derive_ReprC] // <- `::repr_c`'s attribute
#[derive_ReprC] // <- `::safer_ffi`'s attribute
#[repr(u8)] // <- explicit integer `repr` is mandatory!
pub
enum LogLevel {
Expand Down
8 changes: 4 additions & 4 deletions guide/src/derive-reprc/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
## Usage

```rust,noplaypen
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;
#[derive_ReprC] // <- `::repr_c`'s attribute
#[derive_ReprC] // <- `::safer_ffi`'s attribute
#[repr(C)] // <- defined C layout is mandatory!
pub
struct Point {
Expand Down Expand Up @@ -42,7 +42,7 @@ Point_t get_origin (void);
`#[derive_ReprC]` supports generic structs:
```rust,noplaypen
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;
/// The struct can be generic...
#[derive_ReprC]
Expand Down Expand Up @@ -100,7 +100,7 @@ Each monomorphization leads to its own C definition:
<details><summary>Transparent newtype wrapper</summary>

```rust,noplaypen
use ::repr_c::{prelude::*, ptr};
use ::safer_ffi::{prelude::*, ptr};
/// A `Box`-like owned pointer type, but which can be freed using `free()`.
#[derive_ReprC]
Expand Down
2 changes: 1 addition & 1 deletion guide/src/disclaimer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<span class="warning">

Warning: `repr_c` is still in an alpha stage.
Warning: `safer_ffi` is still in an alpha stage.
Some features may be missing, while others may be changed when further improving it.

</span>
7 changes: 4 additions & 3 deletions guide/src/ffi-export/_.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The only currently supported such "item"s are function definitions: `const` and
</div>

```rust,noplaypen
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;
#[ffi_export]
fn adder (x: i32, y: i32) -> i32
Expand All @@ -36,8 +36,9 @@ fn adder (x: i32, y: i32) -> i32
- That is, the following function definition is valid:

```rust,noplaypen
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;
#[ffi_export]
fn max<'xs> (xs: c_slice::Ref<'xs, i32>)
-> Option<&'xs i32>
{
Expand All @@ -50,7 +51,7 @@ fn adder (x: i32, y: i32) -> i32
- But the following one is **not**:

```rust,noplaypen,compile_fail
use ::repr_c::prelude::*;
use ::safer_ffi::prelude::*;
#[derive_ReprC]
#[repr(C)]
Expand Down
4 changes: 2 additions & 2 deletions guide/src/ffi-export/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ These are not yet implemented

```rust,noplaypen
#[ffi_export]
#[repr_c(unsafe { skip_sanity_checks() })]
#[safer_ffi(unsafe { skip_sanity_checks() })]
fn ...
```

Expand All @@ -60,7 +60,7 @@ These are not yet implemented
```rust,noplaypen
#[ffi_export]
fn set_log_level (
#[repr_c(unsafe { skip_sanity_checks() })]
#[safer_ffi(unsafe { skip_sanity_checks() })]
level: LogLevel,
...
) -> ...
Expand Down
Loading

0 comments on commit b6f0759

Please sign in to comment.