Skip to content

Commit c3fd541

Browse files
committed
feat: better ffi error impl
1 parent c8ec928 commit c3fd541

File tree

1 file changed

+55
-68
lines changed

1 file changed

+55
-68
lines changed

float-pigment-css/float_pigment_css.h

Lines changed: 55 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ struct Warning {
301301
uint32_t end_col;
302302
};
303303

304-
using BufferPtr = uint8_t*;
305-
306304
template<typename T>
307305
struct Box {
308306
T *ptr;
@@ -8741,8 +8739,6 @@ struct ColorValue {
87418739
uint8_t alpha;
87428740
};
87438741

8744-
using CCharPtr = const char*;
8745-
87468742
struct SelectorRelationType {
87478743
enum class Tag {
87488744
None,
@@ -9024,10 +9020,6 @@ struct StyleSheet {
90249020

90259021
using RawMutPtr = void*;
90269022

9027-
using StyleSheetImportIndexPtr = RawMutPtr;
9028-
9029-
using StyleSheetResourcePtr = RawMutPtr;
9030-
90319023
struct CParserHooksContext {
90329024
void *inner;
90339025
};
@@ -9047,119 +9039,114 @@ FfiResult<NullPtr> FPArrayStrRefFree(Array<StrRef> *x);
90479039

90489040
FfiResult<NullPtr> FPArrayWarningFree(Array<Warning> *warnings);
90499041

9050-
FfiResult<NullPtr> FPBufferFree(BufferPtr buffer_ptr, size_t buffer_len);
9042+
FfiResult<NullPtr> FPBufferFree(uint8_t *buffer_ptr, size_t buffer_len);
90519043

90529044
FfiResult<StrRef*> FPCssParserVersion();
90539045

90549046
FfiResult<NullPtr> FPInlineStyleFree(InlineRule *inline_rule);
90559047

9056-
FfiResult<ColorValue> FPParseColorFromString(CCharPtr source);
9048+
FfiResult<ColorValue> FPParseColorFromString(const char *source);
90579049

9058-
FfiResult<InlineRule*> FPParseInlineStyle(CCharPtr inline_style_text_ptr,
9050+
FfiResult<InlineRule*> FPParseInlineStyle(const char *inline_style_text_ptr,
90599051
Array<Warning> **warnings);
90609052

9061-
FfiResult<Selector*> FPParseSelectorFromString(CCharPtr selector_text_ptr);
9053+
FfiResult<Selector*> FPParseSelectorFromString(const char *selector_text_ptr);
90629054

9063-
FfiResult<StyleSheet*> FPParseStyleSheetFromString(CCharPtr style_text_ptr);
9055+
FfiResult<StyleSheet*> FPParseStyleSheetFromString(const char *style_text_ptr);
90649056

90659057
FfiResult<NullPtr> FPSelectorFree(Selector *selector);
90669058

9067-
FfiResult<NullPtr> FPStrFree(CCharPtr ptr);
9059+
FfiResult<NullPtr> FPStrFree(const char *ptr);
90689060

9069-
FfiResult<StrRef*> FPStyleSheetBincodeVersion(BufferPtr buffer_ptr, size_t buffer_len);
9061+
FfiResult<StrRef*> FPStyleSheetBincodeVersion(uint8_t *buffer_ptr, size_t buffer_len);
90709062

90719063
FfiResult<NullPtr> FPStyleSheetFree(StyleSheet *style_sheet);
90729064

9073-
FfiResult<NullPtr> FPStyleSheetImportIndexAddBincode(StyleSheetImportIndexPtr this_,
9074-
CCharPtr path,
9075-
BufferPtr buffer_ptr,
9065+
FfiResult<NullPtr> FPStyleSheetImportIndexAddBincode(RawMutPtr this_,
9066+
const char *path,
9067+
uint8_t *buffer_ptr,
90769068
size_t buffer_len,
90779069
void (*drop_fn)(RawMutPtr),
90789070
RawMutPtr drop_args,
90799071
Array<Warning> **warnings);
90809072

9081-
FfiResult<StyleSheetImportIndexPtr> FPStyleSheetImportIndexDeserializeBincode(BufferPtr buffer_ptr,
9082-
size_t buffer_len,
9083-
void (*drop_fn)(RawMutPtr),
9084-
RawMutPtr drop_args);
9073+
FfiResult<RawMutPtr> FPStyleSheetImportIndexDeserializeBincode(uint8_t *buffer_ptr,
9074+
size_t buffer_len,
9075+
void (*drop_fn)(RawMutPtr),
9076+
RawMutPtr drop_args);
90859077

9086-
FfiResult<StyleSheetImportIndexPtr> FPStyleSheetImportIndexDeserializeJson(CCharPtr json);
9078+
FfiResult<RawMutPtr> FPStyleSheetImportIndexDeserializeJson(const char *json);
90879079

9088-
FfiResult<NullPtr> FPStyleSheetImportIndexFree(StyleSheetImportIndexPtr this_);
9080+
FfiResult<NullPtr> FPStyleSheetImportIndexFree(RawMutPtr this_);
90899081

9090-
FfiResult<StyleSheet*> FPStyleSheetImportIndexGetStyleSheet(StyleSheetImportIndexPtr this_,
9091-
CCharPtr path);
9082+
FfiResult<StyleSheet*> FPStyleSheetImportIndexGetStyleSheet(RawMutPtr this_, const char *path);
90929083

9093-
FfiResult<Array<StrRef>*> FPStyleSheetImportIndexListDependencies(StyleSheetImportIndexPtr this_,
9094-
CCharPtr path);
9084+
FfiResult<Array<StrRef>*> FPStyleSheetImportIndexListDependencies(RawMutPtr this_,
9085+
const char *path);
90959086

9096-
FfiResult<Array<StrRef>*> FPStyleSheetImportIndexListDependency(StyleSheetImportIndexPtr this_,
9097-
CCharPtr path);
9087+
FfiResult<Array<StrRef>*> FPStyleSheetImportIndexListDependency(RawMutPtr this_, const char *path);
90989088

9099-
FfiResult<NullPtr> FPStyleSheetImportIndexMergeBincode(StyleSheetImportIndexPtr this_,
9100-
BufferPtr buffer_ptr,
9089+
FfiResult<NullPtr> FPStyleSheetImportIndexMergeBincode(RawMutPtr this_,
9090+
uint8_t *buffer_ptr,
91019091
size_t buffer_len,
91029092
void (*drop_fn)(void*),
91039093
void *drop_args);
91049094

9105-
FfiResult<StyleSheetImportIndexPtr> FPStyleSheetImportIndexNew();
9095+
FfiResult<RawMutPtr> FPStyleSheetImportIndexNew();
91069096

9107-
FfiResult<Array<StrRef>*> FPStyleSheetImportIndexQueryAndMarkDependencies(StyleSheetImportIndexPtr this_,
9108-
CCharPtr path);
9097+
FfiResult<Array<StrRef>*> FPStyleSheetImportIndexQueryAndMarkDependencies(RawMutPtr this_,
9098+
const char *path);
91099099

9110-
FfiResult<NullPtr> FPStyleSheetImportIndexRemoveBincode(StyleSheetImportIndexPtr this_,
9111-
CCharPtr path);
9100+
FfiResult<NullPtr> FPStyleSheetImportIndexRemoveBincode(RawMutPtr this_, const char *path);
91129101

9113-
FfiResult<BufferPtr> FPStyleSheetImportIndexSerializeBincode(StyleSheetImportIndexPtr this_,
9114-
size_t *ret_buffer_len);
9102+
FfiResult<uint8_t*> FPStyleSheetImportIndexSerializeBincode(RawMutPtr this_,
9103+
size_t *ret_buffer_len);
91159104

9116-
FfiResult<BufferPtr> FPStyleSheetImportIndexSerializeJson(StyleSheetImportIndexPtr this_,
9117-
size_t *ret_buffer_len);
9105+
FfiResult<uint8_t*> FPStyleSheetImportIndexSerializeJson(RawMutPtr this_, size_t *ret_buffer_len);
91189106

9119-
FfiResult<NullPtr> FPStyleSheetResourceAddBincode(StyleSheetResourcePtr this_,
9120-
CCharPtr path,
9121-
BufferPtr buffer_ptr,
9107+
FfiResult<NullPtr> FPStyleSheetResourceAddBincode(RawMutPtr this_,
9108+
const char *path,
9109+
uint8_t *buffer_ptr,
91229110
size_t buffer_len,
91239111
void (*drop_fn)(RawMutPtr),
91249112
RawMutPtr drop_args,
91259113
Array<Warning> **warnings);
91269114

9127-
FfiResult<NullPtr> FPStyleSheetResourceAddSource(StyleSheetResourcePtr this_,
9128-
CCharPtr path,
9129-
CCharPtr source,
9115+
FfiResult<NullPtr> FPStyleSheetResourceAddSource(RawMutPtr this_,
9116+
const char *path,
9117+
const char *source,
91309118
Array<Warning> **warnings);
91319119

9132-
FfiResult<NullPtr> FPStyleSheetResourceAddSourceWithHooks(StyleSheetResourcePtr this_,
9120+
FfiResult<NullPtr> FPStyleSheetResourceAddSourceWithHooks(RawMutPtr this_,
91339121
CParserHooks hooks,
9134-
CCharPtr path,
9135-
CCharPtr source,
9122+
const char *path,
9123+
const char *source,
91369124
Array<Warning> **warnings);
91379125

9138-
FfiResult<NullPtr> FPStyleSheetResourceAddTagNamePrefix(StyleSheetResourcePtr this_,
9139-
CCharPtr path,
9140-
CCharPtr prefix);
9126+
FfiResult<NullPtr> FPStyleSheetResourceAddTagNamePrefix(RawMutPtr this_,
9127+
const char *path,
9128+
const char *prefix);
91419129

9142-
FfiResult<Array<StrRef>*> FPStyleSheetResourceDirectDependencies(StyleSheetResourcePtr this_,
9143-
CCharPtr path);
9130+
FfiResult<Array<StrRef>*> FPStyleSheetResourceDirectDependencies(RawMutPtr this_, const char *path);
91449131

9145-
FfiResult<NullPtr> FPStyleSheetResourceFree(StyleSheetResourcePtr this_);
9132+
FfiResult<NullPtr> FPStyleSheetResourceFree(RawMutPtr this_);
91469133

9147-
FfiResult<StyleSheetImportIndexPtr> FPStyleSheetResourceGenerateImportIndex(StyleSheetResourcePtr this_);
9134+
FfiResult<RawMutPtr> FPStyleSheetResourceGenerateImportIndex(RawMutPtr this_);
91489135

9149-
FfiResult<StyleSheetResourcePtr> FPStyleSheetResourceNew();
9136+
FfiResult<RawMutPtr> FPStyleSheetResourceNew();
91509137

9151-
FfiResult<BufferPtr> FPStyleSheetResourceSerializeBincode(StyleSheetResourcePtr this_,
9152-
CCharPtr path,
9153-
size_t *ret_buffer_len);
9138+
FfiResult<uint8_t*> FPStyleSheetResourceSerializeBincode(RawMutPtr this_,
9139+
const char *path,
9140+
size_t *ret_buffer_len);
91549141

9155-
FfiResult<BufferPtr> FPStyleSheetResourceSerializeJson(StyleSheetResourcePtr this_,
9156-
CCharPtr path,
9157-
size_t *ret_buffer_len);
9142+
FfiResult<uint8_t*> FPStyleSheetResourceSerializeJson(RawMutPtr this_,
9143+
const char *path,
9144+
size_t *ret_buffer_len);
91589145

9159-
FfiResult<CCharPtr> FPSubstituteVariable(CCharPtr expr_ptr,
9160-
RawMutPtr map,
9161-
CustomPropertyGetter getter,
9162-
CustomPropertySetter setter);
9146+
FfiResult<const char*> FPSubstituteVariable(const char *expr_ptr,
9147+
RawMutPtr map,
9148+
CustomPropertyGetter getter,
9149+
CustomPropertySetter setter);
91639150

91649151
FfiResult<NullPtr> generate_warning(CParserHooksContext *self, const char *message);
91659152

0 commit comments

Comments
 (0)