4
9
Fork
You've already forked libchewing
3

Define SUCCESS and ERROR return type #21

Open
opened 2012年10月15日 16:18:42 +02:00 by kanru · 5 comments
kanru commented 2012年10月15日 16:18:42 +02:00 (Migrated from github.com)
Copy link

Currently our API and internal function aren't very consistent about the return value. Whether should non-zero result be success or error? We should define the SUCCESS and ERROR symbol instead of return the raw integer.

Currently our API and internal function aren't very consistent about the return value. Whether should non-zero result be success or error? We should define the SUCCESS and ERROR symbol instead of return the raw integer.
Contributor
Copy link

is this any time pressure on this issue ?

ps. let me doubt about the good for first label (LOL)

is this any time pressure on this issue ? ps. let me doubt about the `good for first` label (LOL)
Owner
Copy link

Absolutely not time sensitive. It has been opened 13 years after all :-)

It's nice to have since the current API has two major incompatible return value styles, following C conventions:

  1. Boolean where 1 is true and 0 is false
  2. Result where -1 is fail and 0 is success

After working on this, you will learn

  1. how to change the API signature and update the generate chewing.h header
  2. how to expose rust types to C FFI safely
  3. high level understanding of how each API treat return values
Absolutely not time sensitive. It has been opened 13 years after all :-) It's nice to have since the current API has two major incompatible return value styles, following C conventions: 1. Boolean where 1 is true and 0 is false 2. Result where -1 is fail and 0 is success After working on this, you will learn 1. how to change the API signature and update the generate `chewing.h` header 2. how to expose rust types to C FFI safely 3. high level understanding of how each API treat return values
Contributor
Copy link

Need basic knowledge of C and Rust. I do not have any of that (cry)

why :

  • incompatible interface works now ?
  • any reason want to change it ?
  • a simple function or interface example that make you decide to change it ?

I think I should make project build works, and learn FFI design for first.

This is why I doubt about the "good for first" label (LOL)

Need basic knowledge of C and Rust. I do not have any of that (cry) why : - incompatible interface works now ? - any reason want to change it ? - a simple function or interface example that make you decide to change it ? I think I should make project build works, and learn FFI design for first. This is why I doubt about the "good for first" label (LOL)
Contributor
Copy link

I can only found success / error definition in file /src/exn.rs :

pub(crate)traitResultExt{type Success;type Error: Error+Send+Sync+'static;}

is this the definition which is hope to been updated ?


there is a C header file which mention about return value : /capi/include/chewing.h. I am not sure if it is the file we need to consider.

I can only found success / error definition in file `/src/exn.rs` : ```rust pub(crate) trait ResultExt { type Success; type Error: Error + Send + Sync + 'static; } ``` is this the definition which is hope to been updated ? ---- there is a C header file which mention about return value : `/capi/include/chewing.h`. I am not sure if it is the file we need to consider.
Owner
Copy link

We want to update the C interface.

I think we can move this definition

Lines 47 to 50 in 90c949e
constTRUE: c_int=1;
constFALSE: c_int=0;
constOK: c_int=0;
constERROR: c_int=-1;

to somewhere after

Lines 39 to 43 in 90c949e
/// The size of internal buffer for pre-edit buffer.
pubconstMAX_PHONE_SEQ_LEN: usize =50;
/// The maximum phrase size.
pubconstMAX_PHRASE_LEN: usize =11;

and change them to public.

then use them in
90c949e75d/capi/src/io.rs, check comments like

/// The return value is 0 on success and -1 on failure.
We want to update the C interface. I think we can move this definition https://codeberg.org/chewing/libchewing/src/commit/90c949e75dfb8b80fe0b944425fb457835733acb/capi/src/io.rs#L47-L50 to somewhere after https://codeberg.org/chewing/libchewing/src/commit/90c949e75dfb8b80fe0b944425fb457835733acb/capi/src/public.rs#L39-L43 and change them to public. then use them in https://codeberg.org/chewing/libchewing/src/commit/90c949e75dfb8b80fe0b944425fb457835733acb/capi/src/io.rs, check comments like ``` /// The return value is 0 on success and -1 on failure. ```
Sign in to join this conversation.
No Branch/Tag specified
master
release/0.13.x
push-qlrtqulwmpmp
push-wtuvoynpwosl
release/0.10.x
release/0.8.x
optimize-conversion
refactor-trie-loader
v0.13.0
v0.12.0
v0.12.0-alpha.1
v0.11.0
v0.11.0-alpha.1
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.1
v0.9.0
v0.9.0-rc.3
v0.9.0-rc.2
v0.9.0-rc.1
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.8.0-rc.4
v0.8.0-rc.3
v0.8.0-rc.2
v0.8.0-rc.1
v0.7.0
v0.7.0-rc.2
v0.7.0-rc.1
v0.6.0
v0.6.0-rc.2
v0.6.0-rc.1
v0.5.1
v0.5.0
v0.4.0
v0.3.5
v0.3.4
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.7
v0.2.6
v0.2.5
v0.2.4
Labels
Clear labels
dictionary
duplicate
fixed
0.11.0

Archived

fixed
0.13.0
refactoring

Archived

rewrite in rust
Might be fixed by the rust rewrite
thirdparty
arch
aarch64
系統架構是 Aarch64
arch
x86_64
系統架構是 x86_64
cannot reproduce
無法重現問題 Cannot reproduce the issue
contribution welcome
歡迎來幫忙 Contributions are very welcome, get started here
duplicate
重複的問題回報 This issue or pull request already exists
good first issue
適合新手 Interested in contributing? Get started here.
help wanted
需要高手相助 Need some help
invalid
回報的問題無效 Something is wrong
kind
bug
有東西不正常運作 Something is not working
kind
doc
加強文件說明 Enhance documentation
kind
enhancement
新功能 New feature
kind
mega issue
同一個問題回報中包含多個問題 Multiple issues reported
kind
question
只是問問題 Asking a question
needinfo
需要更多資訊 More information is needed
os
apple
作業系統是 MacOS 或 iOS
os
linux
作業系統是 GNU Linux
os
windows
作業系統是 Windows
to be determined
還未被說服有需求 Can't decide whether this is needed
upstream
跟上游軟體相關 Related to an upstream repository, already reported there
wontfix
我們決定不處理 Won't be fixed
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chewing/libchewing#21
Reference in a new issue
chewing/libchewing
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?