🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

cbindgen

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cbindgen - cargo Package Compare versions

Comparing version
0.29.3
to
0.29.4
tests/expectations-symbols/const_enum.c.sym

Sorry, the diff of this file is not supported yet

+30
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum FillRule
#if __STDC_VERSION__ >= 202311L
: uint8_t
#endif // __STDC_VERSION__ >= 202311L
{
Nonzero,
Evenodd,
};
#if __STDC_VERSION__ >= 202311L
typedef enum FillRule FillRule;
#else
typedef uint8_t FillRule;
#endif // __STDC_VERSION__ >= 202311L
typedef struct Style {
FillRule rule;
} Style;
#define Style_DEFAULT_RULE Nonzero
#define Style_ALL_RULES { Nonzero, Evenodd, }
#define DEFAULT_FILL_RULE Nonzero
#define ALL_FILL_RULES { Nonzero, Evenodd, }
void root(FillRule rule, struct Style style);
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum FillRule
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint8_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
Nonzero,
Evenodd,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum FillRule FillRule;
#else
typedef uint8_t FillRule;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
typedef struct Style {
FillRule rule;
} Style;
#define Style_DEFAULT_RULE Nonzero
#define Style_ALL_RULES { Nonzero, Evenodd, }
#define DEFAULT_FILL_RULE Nonzero
#define ALL_FILL_RULES { Nonzero, Evenodd, }
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void root(FillRule rule, struct Style style);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum FillRule
#if __STDC_VERSION__ >= 202311L
: uint8_t
#endif // __STDC_VERSION__ >= 202311L
{
Nonzero,
Evenodd,
};
#if __STDC_VERSION__ >= 202311L
typedef enum FillRule FillRule;
#else
typedef uint8_t FillRule;
#endif // __STDC_VERSION__ >= 202311L
struct Style {
FillRule rule;
};
#define Style_DEFAULT_RULE Nonzero
#define Style_ALL_RULES { Nonzero, Evenodd, }
#define DEFAULT_FILL_RULE Nonzero
#define ALL_FILL_RULES { Nonzero, Evenodd, }
void root(FillRule rule, struct Style style);
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum FillRule
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint8_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
Nonzero,
Evenodd,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum FillRule FillRule;
#else
typedef uint8_t FillRule;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
struct Style {
FillRule rule;
};
#define Style_DEFAULT_RULE Nonzero
#define Style_ALL_RULES { Nonzero, Evenodd, }
#define DEFAULT_FILL_RULE Nonzero
#define ALL_FILL_RULES { Nonzero, Evenodd, }
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void root(FillRule rule, struct Style style);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
cdef enum:
Nonzero,
Evenodd,
ctypedef uint8_t FillRule;
cdef struct Style:
FillRule rule;
const FillRule Style_DEFAULT_RULE # = Nonzero
const FillRule Style_ALL_RULES[2] # = [ Nonzero, Evenodd, ]
const FillRule DEFAULT_FILL_RULE # = Nonzero
const FillRule ALL_FILL_RULES[2] # = [ Nonzero, Evenodd, ]
void root(FillRule rule, Style style);
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum FillRule
#if __STDC_VERSION__ >= 202311L
: uint8_t
#endif // __STDC_VERSION__ >= 202311L
{
Nonzero,
Evenodd,
};
#if __STDC_VERSION__ >= 202311L
typedef enum FillRule FillRule;
#else
typedef uint8_t FillRule;
#endif // __STDC_VERSION__ >= 202311L
typedef struct {
FillRule rule;
} Style;
#define Style_DEFAULT_RULE Nonzero
#define Style_ALL_RULES { Nonzero, Evenodd, }
#define DEFAULT_FILL_RULE Nonzero
#define ALL_FILL_RULES { Nonzero, Evenodd, }
void root(FillRule rule, Style style);
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum FillRule
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint8_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
Nonzero,
Evenodd,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum FillRule FillRule;
#else
typedef uint8_t FillRule;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
typedef struct {
FillRule rule;
} Style;
#define Style_DEFAULT_RULE Nonzero
#define Style_ALL_RULES { Nonzero, Evenodd, }
#define DEFAULT_FILL_RULE Nonzero
#define ALL_FILL_RULES { Nonzero, Evenodd, }
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void root(FillRule rule, Style style);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
enum class FillRule : uint8_t {
Nonzero,
Evenodd,
};
struct Style {
FillRule rule;
};
constexpr static const FillRule Style_DEFAULT_RULE = FillRule::Nonzero;
constexpr static const FillRule Style_ALL_RULES[2] = { FillRule::Nonzero, FillRule::Evenodd, };
constexpr static const FillRule DEFAULT_FILL_RULE = FillRule::Nonzero;
constexpr static const FillRule ALL_FILL_RULES[2] = { FillRule::Nonzero, FillRule::Evenodd, };
extern "C" {
void root(FillRule rule, Style style);
} // extern "C"
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
cdef enum:
Nonzero,
Evenodd,
ctypedef uint8_t FillRule;
ctypedef struct Style:
FillRule rule;
const FillRule Style_DEFAULT_RULE # = Nonzero
const FillRule Style_ALL_RULES[2] # = [ Nonzero, Evenodd, ]
const FillRule DEFAULT_FILL_RULE # = Nonzero
const FillRule ALL_FILL_RULES[2] # = [ Nonzero, Evenodd, ]
void root(FillRule rule, Style style);
#[repr(u8)]
pub enum FillRule {
Nonzero,
Evenodd,
}
pub const DEFAULT_FILL_RULE: FillRule = FillRule::Nonzero;
pub const ALL_FILL_RULES: [FillRule; 2] = [FillRule::Nonzero, FillRule::Evenodd];
#[repr(C)]
pub struct Style {
rule: FillRule,
}
impl Style {
pub const DEFAULT_RULE: FillRule = FillRule::Nonzero;
pub const ALL_RULES: [FillRule; 2] = [FillRule::Nonzero, FillRule::Evenodd];
}
#[no_mangle]
pub extern "C" fn root(rule: FillRule, style: Style) {}
+1
-1
{
"git": {
"sha1": "b5f2a978302e86fa06659a945a26c1b8b9aa9b8d"
"sha1": "b826cb8911488fe8a209d2b693492c0c673e8cca"
},
"path_in_vcs": ""
}

@@ -69,3 +69,3 @@ # This file is automatically @generated by Cargo.

name = "cbindgen"
version = "0.29.3"
version = "0.29.4"
dependencies = [

@@ -72,0 +72,0 @@ "clap",

@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

name = "cbindgen"
version = "0.29.3"
version = "0.29.4"
authors = [

@@ -19,0 +19,0 @@ "Emilio Cobos Álvarez <emilio@crisal.io>",

# unreleased
# 0.29.4
* Support constant enums and arrays.
# 0.29.3

@@ -4,0 +8,0 @@

@@ -16,3 +16,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

use crate::bindgen::ir::{
Constant, Function, ItemContainer, ItemMap, Path as BindgenPath, Static, Struct, Type, Typedef,
Constant, Enum, Function, ItemContainer, ItemMap, Path as BindgenPath, Static, Struct, Type,
Typedef,
};

@@ -30,2 +31,5 @@ use crate::bindgen::language_backend::{

struct_map: ItemMap<Struct>,
/// The map from path to enum, used to validate enum-variant paths that
/// appear in constant literals.
enum_map: ItemMap<Enum>,
typedef_map: ItemMap<Typedef>,

@@ -49,2 +53,3 @@ struct_fileds_memo: RefCell<HashMap<BindgenPath, Rc<Vec<String>>>>,

struct_map: ItemMap<Struct>,
enum_map: ItemMap<Enum>,
typedef_map: ItemMap<Typedef>,

@@ -62,2 +67,3 @@ constants: Vec<Constant>,

struct_map,
enum_map,
typedef_map,

@@ -107,2 +113,33 @@ struct_fileds_memo: Default::default(),

pub fn enum_exists(&self, path: &BindgenPath) -> bool {
let mut any = false;
self.enum_map.for_items(path, |_| any = true);
any
}
/// Returns how the variant `variant_name` of the enum at `path` should be
/// referenced in generated code: `Enum::Variant` for a C++ `enum class`,
/// or the bare (possibly prefixed) variant name otherwise. Returns `None`
/// if the enum or the variant isn't known.
pub fn enum_variant_reference(&self, path: &BindgenPath, variant_name: &str) -> Option<String> {
let config = &self.config;
let mut result = None;
self.enum_map.for_items(path, |e| {
if result.is_some() {
return;
}
let Some(variant) = e.variants.iter().find(|v| v.name == variant_name) else {
return;
};
let qualify =
config.language == Language::Cxx && config.enumeration.enum_class(&e.annotations);
result = Some(if qualify {
format!("{}::{}", e.export_name, variant.export_name)
} else {
variant.export_name.clone()
});
});
result
}
pub fn struct_field_names(&self, path: &BindgenPath) -> Rc<Vec<String>> {

@@ -109,0 +146,0 @@ let mut memos = self.struct_fileds_memo.borrow_mut();

@@ -368,2 +368,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

Default::default(),
Default::default(),
true,

@@ -370,0 +371,0 @@ String::new(),

@@ -117,2 +117,5 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

},
Array {
items: Vec<Literal>,
},
}

@@ -186,2 +189,7 @@

}
Literal::Array { ref mut items } => {
for item in items {
item.replace_self_with(self_ty);
}
}
Literal::Expr(..) => {}

@@ -194,2 +202,3 @@ }

Literal::Expr(..) => true,
Literal::Array { ref items } => items.iter().all(|i| i.is_valid(bindings)),
Literal::Path {

@@ -201,2 +210,3 @@ ref associated_to,

return bindings.struct_exists(path)
|| bindings.enum_exists(path)
|| to_known_assoc_constant(path, name).is_some();

@@ -234,2 +244,10 @@ }

} => left.visit(visitor) && right.visit(visitor),
Literal::Array { ref items } => {
for item in items {
if !item.visit(visitor) {
return false;
}
}
true
}
Literal::FieldAccess { ref base, .. } => base.visit(visitor),

@@ -312,2 +330,7 @@ Literal::Struct { ref fields, .. } => {

}
Literal::Array { ref mut items } => {
for item in items {
item.rename_for_config(config);
}
}
Literal::Expr(_) => {}

@@ -514,2 +537,10 @@ Literal::Cast {

syn::Expr::Array(syn::ExprArray { ref elems, .. }) => {
let mut items = vec![];
for elem in elems {
items.push(Self::load(elem)?);
}
Ok(Literal::Array { items })
}
_ => Err(format!("Unsupported expression. {:?}", *expr)),

@@ -674,4 +705,10 @@ }

}
language_backend.write_type(out, &self.ty);
write!(out, " {};", self.export_name());
crate::bindgen::cdecl::write_field(
language_backend,
out,
&self.ty,
self.export_name(),
config,
);
write!(out, ";");
condition.write_after(config, out);

@@ -769,5 +806,4 @@ }

}
language_backend.write_type(out, &self.ty);
write!(out, " {name} = ");
crate::bindgen::cdecl::write_field(language_backend, out, &self.ty, &name, config);
write!(out, " = ");
language_backend.write_literal(out, value);

@@ -782,6 +818,6 @@ write!(out, ";");

out.write("const ");
language_backend.write_type(out, &self.ty);
// For extern Cython declarations the initializer is ignored,
// but still useful as documentation, so we write it as a comment.
write!(out, " {name} # = ");
crate::bindgen::cdecl::write_field(language_backend, out, &self.ty, &name, config);
write!(out, " # = ");
language_backend.write_literal(out, value);

@@ -788,0 +824,0 @@ }

@@ -232,3 +232,3 @@ use std::io::Write;

GenericArgument::Type(ref mut ty) => ty.rename_for_config(config, generic_params),
GenericArgument::Const(ref mut expr) => expr.rename_for_config(config),
GenericArgument::Const(ref mut expr) => expr.rename_for_config(config, generic_params),
}

@@ -235,0 +235,0 @@ }

@@ -240,3 +240,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

pub enum ConstExpr {
Name(String),
Path(GenericPath),
Value(String),

@@ -248,9 +248,10 @@ }

match *self {
ConstExpr::Name(ref string) | ConstExpr::Value(ref string) => string,
ConstExpr::Path(ref path) => path.export_name(),
ConstExpr::Value(ref string) => string,
}
}
pub fn rename_for_config(&mut self, config: &Config) {
if let ConstExpr::Name(ref mut name) = self {
config.export.rename(name);
pub fn rename_for_config(&mut self, config: &Config, generic_params: &GenericParams) {
if let ConstExpr::Path(ref mut path) = self {
path.rename_for_config(config, generic_params);
}

@@ -271,6 +272,3 @@ }

}
syn::Expr::Path(ref path) => {
let generic_path = GenericPath::load(&path.path)?;
Ok(ConstExpr::Name(generic_path.export_name().to_owned()))
}
syn::Expr::Path(ref path) => Ok(ConstExpr::Path(GenericPath::load(&path.path)?)),
syn::Expr::Cast(ref cast) => Ok(ConstExpr::load(&cast.expr)?),

@@ -282,7 +280,6 @@ _ => Err(format!("can't handle const expression {expr:?}")),

pub fn specialize(&self, mappings: &[(&Path, &GenericArgument)]) -> ConstExpr {
match *self {
ConstExpr::Name(ref name) => {
let path = Path::new(name);
if let ConstExpr::Path(ref path) = *self {
if path.is_single_identifier() {
for &(param, value) in mappings {
if path == *param {
if *param == *path.path() {
match *value {

@@ -293,3 +290,3 @@ GenericArgument::Type(Type::Path(ref path))

// This happens when the generic argument is a path.
return ConstExpr::Name(path.name().to_string());
return ConstExpr::Path(path.clone());
}

@@ -306,3 +303,2 @@ GenericArgument::Const(ref expr) => {

}
ConstExpr::Value(_) => {}
}

@@ -775,3 +771,3 @@ self.clone()

ty.rename_for_config(config, generic_params);
len.rename_for_config(config);
len.rename_for_config(config, generic_params);
}

@@ -778,0 +774,0 @@ Type::FuncPtr {

@@ -843,2 +843,10 @@ use crate::bindgen::ir::{

Literal::Expr(v) => write!(out, "{v}"),
Literal::Array { items } => {
write!(out, "{{ ");
for item in items {
self.write_literal(out, item);
write!(out, ", ");
}
write!(out, "}}");
}
Literal::Path {

@@ -852,2 +860,5 @@ ref associated_to,

}
if let Some(variant) = out.bindings().enum_variant_reference(path, name) {
return write!(out, "{variant}");
}
let path_separator = if self.config.language == Language::C {

@@ -854,0 +865,0 @@ "_"

@@ -351,2 +351,5 @@ use crate::bindgen::ir::{

}
if let Some(variant) = out.bindings().enum_variant_reference(path, name) {
return write!(out, "{variant}");
}
write!(out, "{export_name}_")

@@ -385,2 +388,10 @@ }

}
Literal::Array { ref items } => {
write!(out, "[ ");
for item in items {
self.write_literal(out, item);
write!(out, ", ");
}
write!(out, "]");
}
Literal::Struct {

@@ -387,0 +398,0 @@ export_name,

@@ -140,2 +140,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

self.structs,
self.enums,
self.typedefs,

@@ -142,0 +143,0 @@ constants,

@@ -6,3 +6,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

use crate::bindgen::config::MangleConfig;
use crate::bindgen::ir::{ConstExpr, GenericArgument, GenericPath, Path, Type};
use crate::bindgen::ir::{ConstExpr, GenericArgument, Path, Type};
use crate::bindgen::rename::IdentifierType;

@@ -77,8 +77,7 @@

GenericArgument::Type(ref ty) => self.append_mangled_type(ty, last),
GenericArgument::Const(ConstExpr::Name(ref name)) => {
GenericArgument::Const(ConstExpr::Path(ref path)) => {
// This must behave the same as a GenericArgument::Type,
// because const arguments are commonly represented as Types;
// see the comment on `enum GenericArgument`.
let fake_ty = Type::Path(GenericPath::new(Path::new(name), vec![]));
self.append_mangled_type(&fake_ty, last);
self.append_mangled_type(&Type::Path(path.clone()), last);
}

@@ -325,3 +324,6 @@ GenericArgument::Const(ConstExpr::Value(ref val)) => self.output.push_str(val),

&Path::new("Top"),
&[GenericArgument::Const(ConstExpr::Name("N".to_string()))],
&[GenericArgument::Const(ConstExpr::Path(GenericPath::new(
Path::new("N"),
vec![],
)))],
&MangleConfig::default(),

@@ -328,0 +330,0 @@ ),

@@ -96,10 +96,10 @@ #if 0

None = 0,
Center = (uint8_t)PositionAreaTrack_Center,
SpanAll = (uint8_t)PositionAreaTrack_SpanAll,
Start = (uint8_t)PositionAreaTrack_Start,
End = (uint8_t)PositionAreaTrack_End,
SpanStart = (uint8_t)PositionAreaTrack_SpanStart,
SpanEnd = (uint8_t)PositionAreaTrack_SpanEnd,
Top = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_Start),
Bottom = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_End),
Center = (uint8_t)Center,
SpanAll = (uint8_t)SpanAll,
Start = (uint8_t)Start,
End = (uint8_t)End,
SpanStart = (uint8_t)SpanStart,
SpanEnd = (uint8_t)SpanEnd,
Top = (((uint8_t)Vertical << AXIS_SHIFT) | (uint8_t)Start),
Bottom = (((uint8_t)Vertical << AXIS_SHIFT) | (uint8_t)End),
};

@@ -106,0 +106,0 @@ #if __STDC_VERSION__ >= 202311L

@@ -100,10 +100,10 @@ #if 0

None = 0,
Center = (uint8_t)PositionAreaTrack_Center,
SpanAll = (uint8_t)PositionAreaTrack_SpanAll,
Start = (uint8_t)PositionAreaTrack_Start,
End = (uint8_t)PositionAreaTrack_End,
SpanStart = (uint8_t)PositionAreaTrack_SpanStart,
SpanEnd = (uint8_t)PositionAreaTrack_SpanEnd,
Top = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_Start),
Bottom = (((uint8_t)PositionAreaAxis_Vertical << AXIS_SHIFT) | (uint8_t)PositionAreaTrack_End),
Center = (uint8_t)Center,
SpanAll = (uint8_t)SpanAll,
Start = (uint8_t)Start,
End = (uint8_t)End,
SpanStart = (uint8_t)SpanStart,
SpanEnd = (uint8_t)SpanEnd,
Top = (((uint8_t)Vertical << AXIS_SHIFT) | (uint8_t)Start),
Bottom = (((uint8_t)Vertical << AXIS_SHIFT) | (uint8_t)End),
};

@@ -110,0 +110,0 @@ #ifndef __cplusplus

@@ -59,10 +59,10 @@ #if 0

None # = 0,
Center # = <uint8_t>PositionAreaTrack_Center,
SpanAll # = <uint8_t>PositionAreaTrack_SpanAll,
Start # = <uint8_t>PositionAreaTrack_Start,
End # = <uint8_t>PositionAreaTrack_End,
SpanStart # = <uint8_t>PositionAreaTrack_SpanStart,
SpanEnd # = <uint8_t>PositionAreaTrack_SpanEnd,
Top # = ((<uint8_t>PositionAreaAxis_Vertical << AXIS_SHIFT) | <uint8_t>PositionAreaTrack_Start),
Bottom # = ((<uint8_t>PositionAreaAxis_Vertical << AXIS_SHIFT) | <uint8_t>PositionAreaTrack_End),
Center # = <uint8_t>Center,
SpanAll # = <uint8_t>SpanAll,
Start # = <uint8_t>Start,
End # = <uint8_t>End,
SpanStart # = <uint8_t>SpanStart,
SpanEnd # = <uint8_t>SpanEnd,
Top # = ((<uint8_t>Vertical << AXIS_SHIFT) | <uint8_t>Start),
Bottom # = ((<uint8_t>Vertical << AXIS_SHIFT) | <uint8_t>End),
ctypedef uint8_t PositionAreaKeyword;

@@ -69,0 +69,0 @@

Sorry, the diff of this file is not supported yet