Skip to content

Commit

Permalink
Rename namespace prefix
Browse files Browse the repository at this point in the history
From ddprof_ffi_ to ddog_
  • Loading branch information
paullegranddc committed Jul 12, 2022
1 parent 004f9bf commit 0a5c2d8
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 136 deletions.
10 changes: 5 additions & 5 deletions ddcommon-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tab_width = 2
header = """// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
"""
include_guard = "DDCOMMON_FFI_H"
include_guard = "DDOG_COMMON_H"
style = "both"

no_includes = true
Expand All @@ -15,11 +15,11 @@ sys_includes = ["stdbool.h", "stddef.h", "stdint.h"]
after_includes = """
#if defined(_MSC_VER)
#define DDPROF_FFI_CHARSLICE_C(string) \\
#define DDOG_CHARSLICE_C(string) \\
/* NOTE: Compilation fails if you pass in a char* instead of a literal */ {.ptr = "" string, .len = sizeof(string) - 1}
#else
#define DDPROF_FFI_CHARSLICE_C(string) \\
/* NOTE: Compilation fails if you pass in a char* instead of a literal */ ((ddprof_ffi_CharSlice){ .ptr = "" string, .len = sizeof(string) - 1 })
#define DDOG_CHARSLICE_C(string) \\
/* NOTE: Compilation fails if you pass in a char* instead of a literal */ ((ddog_CharSlice){ .ptr = "" string, .len = sizeof(string) - 1 })
#endif
#if defined(__cplusplus) && (__cplusplus >= 201703L)
Expand All @@ -34,7 +34,7 @@ after_includes = """
#endif"""

[export]
prefix = "ddprof_ffi_"
prefix = "ddog_"

[export.mangle]
rename_types="SnakeCase"
Expand Down
30 changes: 13 additions & 17 deletions ddcommon-ffi/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use ddcommon::tag::{parse_tags, Tag};

#[must_use]
#[no_mangle]
pub extern "C" fn ddprof_ffi_Vec_tag_new() -> crate::Vec<Tag> {
pub extern "C" fn ddog_Vec_tag_new() -> crate::Vec<Tag> {
crate::Vec::default()
}

#[no_mangle]
pub extern "C" fn ddprof_ffi_Vec_tag_drop(_: crate::Vec<Tag>) {}
pub extern "C" fn ddog_Vec_tag_drop(_: crate::Vec<Tag>) {}

#[repr(C)]
pub enum PushTagResult {
Expand All @@ -20,7 +20,7 @@ pub enum PushTagResult {
}

#[no_mangle]
pub extern "C" fn ddprof_ffi_PushTagResult_drop(_: PushTagResult) {}
pub extern "C" fn ddog_PushTagResult_drop(_: PushTagResult) {}

/// Creates a new Tag from the provided `key` and `value` by doing a utf8
/// lossy conversion, and pushes into the `vec`. The strings `key` and `value`
Expand All @@ -32,7 +32,7 @@ pub extern "C" fn ddprof_ffi_PushTagResult_drop(_: PushTagResult) {}
/// `.len` properties claim.
#[must_use]
#[no_mangle]
pub unsafe extern "C" fn ddprof_ffi_Vec_tag_push(
pub unsafe extern "C" fn ddog_Vec_tag_push(
vec: &mut crate::Vec<Tag>,
key: CharSlice,
value: CharSlice,
Expand All @@ -59,7 +59,7 @@ pub struct ParseTagsResult {
/// .len property.
#[must_use]
#[no_mangle]
pub unsafe extern "C" fn ddprof_ffi_Vec_tag_parse(string: CharSlice) -> ParseTagsResult {
pub unsafe extern "C" fn ddog_Vec_tag_parse(string: CharSlice) -> ParseTagsResult {
let string = string.to_utf8_lossy();
let (tags, error) = parse_tags(string.as_ref());
ParseTagsResult {
Expand All @@ -75,22 +75,21 @@ mod tests {
#[test]
fn empty_tag_name() {
unsafe {
let mut tags = ddprof_ffi_Vec_tag_new();
let result =
ddprof_ffi_Vec_tag_push(&mut tags, CharSlice::from(""), CharSlice::from("woof"));
let mut tags = ddog_Vec_tag_new();
let result = ddog_Vec_tag_push(&mut tags, CharSlice::from(""), CharSlice::from("woof"));
assert!(!matches!(result, PushTagResult::Ok));
}
}

#[test]
fn test_lifetimes() {
let mut tags = ddprof_ffi_Vec_tag_new();
let mut tags = ddog_Vec_tag_new();
unsafe {
// make a string here so it has a scoped lifetime
let key = String::from("key1");
{
let value = String::from("value1");
let result = ddprof_ffi_Vec_tag_push(
let result = ddog_Vec_tag_push(
&mut tags,
CharSlice::from(key.as_str()),
CharSlice::from(value.as_str()),
Expand All @@ -106,12 +105,9 @@ mod tests {
#[test]
fn test_get() {
unsafe {
let mut tags = ddprof_ffi_Vec_tag_new();
let result = ddprof_ffi_Vec_tag_push(
&mut tags,
CharSlice::from("sound"),
CharSlice::from("woof"),
);
let mut tags = ddog_Vec_tag_new();
let result =
ddog_Vec_tag_push(&mut tags, CharSlice::from("sound"), CharSlice::from("woof"));
assert!(matches!(result, PushTagResult::Ok));
assert_eq!(1, tags.len());
assert_eq!("sound:woof", tags.get(0).unwrap().to_string());
Expand All @@ -123,7 +119,7 @@ mod tests {
let dd_tags = "env:staging:east, tags:, env_staging:east"; // contains an error

// SAFETY: CharSlices from Rust strings are safe.
let result = unsafe { ddprof_ffi_Vec_tag_parse(CharSlice::from(dd_tags)) };
let result = unsafe { ddog_Vec_tag_parse(CharSlice::from(dd_tags)) };
assert_eq!(2, result.tags.len());
assert_eq!("env:staging:east", result.tags.get(0).unwrap().to_string());
assert_eq!("env_staging:east", result.tags.get(1).unwrap().to_string());
Expand Down
4 changes: 2 additions & 2 deletions ddprof-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ tab_width = 2
header = """// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
"""
include_guard = "DDPROF_FFI_H"
include_guard = "DDOG_PROFILING_H"
style = "both"

no_includes = true
sys_includes = ["stdbool.h", "stddef.h", "stdint.h"]
includes = ["datadog/common.h"]

[export]
prefix = "ddprof_ffi_"
prefix = "ddog_"

[export.mangle]
rename_types="SnakeCase"
Expand Down
38 changes: 19 additions & 19 deletions ddprof-ffi/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum NewProfileExporterV3Result {
Err(ddcommon_ffi::Vec<u8>),
}

#[export_name = "ddprof_ffi_NewProfileExporterV3Result_drop"]
#[export_name = "ddog_NewProfileExporterV3Result_drop"]
pub unsafe extern "C" fn new_profile_exporter_v3_result_drop(result: NewProfileExporterV3Result) {
match result {
NewProfileExporterV3Result::Ok(ptr) => {
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct HttpStatus(u16);
/// Creates an endpoint that uses the agent.
/// # Arguments
/// * `base_url` - Contains a URL with scheme, host, and port e.g. "https://agent:8126/".
#[export_name = "ddprof_ffi_EndpointV3_agent"]
#[export_name = "ddog_EndpointV3_agent"]
pub extern "C" fn endpoint_agent(base_url: CharSlice) -> EndpointV3 {
EndpointV3::Agent(base_url)
}
Expand All @@ -74,7 +74,7 @@ pub extern "C" fn endpoint_agent(base_url: CharSlice) -> EndpointV3 {
/// # Arguments
/// * `site` - Contains a host and port e.g. "datadoghq.com".
/// * `api_key` - Contains the Datadog API key.
#[export_name = "ddprof_ffi_EndpointV3_agentless"]
#[export_name = "ddog_EndpointV3_agentless"]
pub extern "C" fn endpoint_agentless<'a>(
site: CharSlice<'a>,
api_key: CharSlice<'a>,
Expand Down Expand Up @@ -116,7 +116,7 @@ unsafe fn try_to_endpoint(
}

#[must_use]
#[export_name = "ddprof_ffi_ProfileExporterV3_new"]
#[export_name = "ddog_ProfileExporterV3_new"]
pub extern "C" fn profile_exporter_new(
family: CharSlice,
tags: Option<&ddcommon_ffi::Vec<Tag>>,
Expand All @@ -133,7 +133,7 @@ pub extern "C" fn profile_exporter_new(
}
}

#[export_name = "ddprof_ffi_ProfileExporterV3_delete"]
#[export_name = "ddog_ProfileExporterV3_delete"]
pub extern "C" fn profile_exporter_delete(exporter: Option<Box<ProfileExporterV3>>) {
std::mem::drop(exporter)
}
Expand All @@ -155,7 +155,7 @@ unsafe fn into_vec_files<'a>(slice: Slice<'a, File>) -> Vec<ddprof_exporter::Fil
/// # Safety
/// The `exporter` and the files inside of the `files` slice need to have been
/// created by this module.
#[export_name = "ddprof_ffi_ProfileExporterV3_build"]
#[export_name = "ddog_ProfileExporterV3_build"]
pub unsafe extern "C" fn profile_exporter_build(
exporter: Option<NonNull<ProfileExporterV3>>,
start: Timespec,
Expand Down Expand Up @@ -194,7 +194,7 @@ pub unsafe extern "C" fn profile_exporter_build(
/// # Safety
/// All non-null arguments MUST have been created by created by apis in this module.
#[must_use]
#[export_name = "ddprof_ffi_ProfileExporterV3_send"]
#[export_name = "ddog_ProfileExporterV3_send"]
pub unsafe extern "C" fn profile_exporter_send(
exporter: Option<NonNull<ProfileExporterV3>>,
request: Option<Box<Request>>,
Expand Down Expand Up @@ -229,7 +229,7 @@ pub unsafe extern "C" fn profile_exporter_send(
}

#[no_mangle]
pub extern "C" fn ddprof_ffi_Request_drop(_request: Option<Box<Request>>) {}
pub extern "C" fn ddog_Request_drop(_request: Option<Box<Request>>) {}

fn unwrap_cancellation_token<'a>(
cancel: Option<NonNull<CancellationToken>>,
Expand All @@ -245,7 +245,7 @@ fn unwrap_cancellation_token<'a>(
/// Can be passed as an argument to send and then be used to asynchronously cancel it from a different thread.
#[no_mangle]
#[must_use]
pub extern "C" fn ddprof_ffi_CancellationToken_new() -> *mut CancellationToken {
pub extern "C" fn ddog_CancellationToken_new() -> *mut CancellationToken {
Box::into_raw(Box::new(CancellationToken(
tokio_util::sync::CancellationToken::new(),
)))
Expand All @@ -259,22 +259,22 @@ pub extern "C" fn ddprof_ffi_CancellationToken_new() -> *mut CancellationToken {
///
/// Thus, it's possible to do something like:
/// ```c
/// cancel_t1 = ddprof_ffi_CancellationToken_new();
/// cancel_t2 = ddprof_ffi_CancellationToken_clone(cancel_t1);
/// cancel_t1 = ddog_CancellationToken_new();
/// cancel_t2 = ddog_CancellationToken_clone(cancel_t1);
///
/// // On thread t1:
/// ddprof_ffi_ProfileExporterV3_send(..., cancel_t1);
/// ddprof_ffi_CancellationToken_drop(cancel_t1);
/// ddog_ProfileExporterV3_send(..., cancel_t1);
/// ddog_CancellationToken_drop(cancel_t1);
///
/// // On thread t2:
/// ddprof_ffi_CancellationToken_cancel(cancel_t2);
/// ddprof_ffi_CancellationToken_drop(cancel_t2);
/// ddog_CancellationToken_cancel(cancel_t2);
/// ddog_CancellationToken_drop(cancel_t2);
/// ```
///
/// Without clone, both t1 and t2 would need to synchronize to make sure neither was using the cancel
/// before it could be dropped. With clone, there is no need for such synchronization, both threads
/// have their own cancel and should drop that cancel after they are done with it.
pub extern "C" fn ddprof_ffi_CancellationToken_clone(
pub extern "C" fn ddog_CancellationToken_clone(
cancel: Option<NonNull<CancellationToken>>,
) -> *mut CancellationToken {
match unwrap_cancellation_token(cancel) {
Expand All @@ -287,7 +287,7 @@ pub extern "C" fn ddprof_ffi_CancellationToken_clone(
/// Note that cancellation is a terminal state; cancelling a token more than once does nothing.
/// Returns `true` if token was successfully cancelled.
#[no_mangle]
pub extern "C" fn ddprof_ffi_CancellationToken_cancel(
pub extern "C" fn ddog_CancellationToken_cancel(
cancel: Option<NonNull<CancellationToken>>,
) -> bool {
let cancel_reference = match unwrap_cancellation_token(cancel) {
Expand All @@ -304,11 +304,11 @@ pub extern "C" fn ddprof_ffi_CancellationToken_cancel(
}

#[no_mangle]
pub extern "C" fn ddprof_ffi_CancellationToken_drop(_cancel: Option<Box<CancellationToken>>) {
pub extern "C" fn ddog_CancellationToken_drop(_cancel: Option<Box<CancellationToken>>) {
// _cancel implicitly dropped because we've turned it into a Box
}

#[export_name = "ddprof_ffi_SendResult_drop"]
#[export_name = "ddog_SendResult_drop"]
pub unsafe extern "C" fn send_result_drop(result: SendResult) {
std::mem::drop(result)
}
Expand Down
Loading

0 comments on commit 0a5c2d8

Please sign in to comment.