radare2
radare2 copied to clipboard
void init
all _init() methods should return void imho
0$ git grep _init| grep R_API| grep -v void
libr/anal/xrefs.c:R_API bool r_anal_xrefs_init(RAnal *anal) {
libr/core/cconfig.c:R_API int r_core_config_init(RCore *core) {
libr/core/cmd_seek.c:R_API int r_core_lines_initcache(RCore *core, ut64 start_addr, ut64 end_addr) {
libr/core/core.c:R_API bool r_core_init(RCore *core) {
libr/core/cplugin.c:R_API bool r_core_plugin_init(RCmd *cmd) {
libr/core/rvc.c:R_API Rvc *r_vc_git_init(const char *path) {
libr/core/rvc.c:R_API Rvc *rvc_git_init(const RCore *core, const char *path) {
libr/crypto/crypto.c:R_API RCrypto *r_crypto_init(RCrypto *cry, int hard) {
libr/debug/p/bfvm.c:R_API int bfvm_init(BfvmCPU *c, ut32 size, int circular) {
libr/include/r_anal.h:R_API bool r_anal_xrefs_init(RAnal *anal);
libr/include/r_cons.h:R_API int r_cons_palette_init(const unsigned char *pal);
libr/include/r_core.h:R_API bool r_core_init(RCore *core);
libr/include/r_core.h:R_API int r_core_config_init(RCore *core);
libr/include/r_core.h:R_API int r_core_lines_initcache(RCore *core, ut64 start_addr, ut64 end_addr);
libr/include/r_core.h:R_API bool r_core_plugin_init(RCmd *cmd);
libr/include/r_crypto.h:R_API RCrypto *r_crypto_init(RCrypto *cry, int hard);
libr/include/r_io.h:R_API RIO *r_io_init(RIO *io);
libr/include/r_io.h:R_API bool r_io_plugin_init(RIO *io);
libr/include/r_io.h:R_API int r_io_undo_init(RIO *io);
libr/include/r_io.h:R_API bool r_io_desc_cache_init(RIODesc *desc);
libr/include/r_reg.h:R_API RReg *r_reg_init(RReg *reg);
libr/include/r_regex.h:R_API int r_regex_init(RRegex*, const char *pattern, int flags);
libr/include/r_util/r_spaces.h:R_API bool r_spaces_init(RSpaces *sp, const char *name);
libr/include/r_util/r_str_constpool.h:R_API bool r_str_constpool_init(RStrConstPool *pool);
libr/include/r_util/r_strbuf.h:R_API const char *r_strbuf_initf(RStrBuf *sb, const char *fmt, ...); // same as init + setf for convenience
libr/include/rvc.h:R_API Rvc *r_vc_git_init(const char *path);
libr/include/rvc.h:R_API Rvc *rvc_git_init(const RCore *core, const char *path);
libr/io/io_plugin.c:R_API bool r_io_plugin_init(RIO *io) {
libr/io/p_cache.c:R_API bool r_io_desc_cache_init(RIODesc *desc) {
libr/io/undo.c:R_API int r_io_undo_init(RIO *io) {
libr/reg/reg.c:R_API RReg *r_reg_init(RReg *reg) {
libr/util/regex/regcomp.c:R_API int r_regex_init(RRegex *preg, const char *pattern, int cflags) {
libr/util/spaces.c:R_API bool r_spaces_init(RSpaces *sp, const char *name) {
libr/util/str_constpool.c:R_API bool r_str_constpool_init(RStrConstPool *pool) {
libr/util/strbuf.c:R_API const char *r_strbuf_initf(RStrBuf *sb, const char *fmt, ...) {
0$
the how do you know if init was successful? init in io intentionally returns bool.
Its kind of common that init methods return void. Its done in gobject, objc, java, vala, python, swift..
Usually in object oriented paradigns like new/init/fini/free work the same. They cannot throw exceptions or fail. Thats quite imprecise because you can call allocators inside the init method and they can fail and theres no way to report back to the user because those languages assume a malloc failure implies a full program crash. R2 aims to be more flexible on this. But then we open the door of error reporting with error code or string, to be clear on whats actualy failing.
I may find some literature on this to see how that's handled in languages that really consider those corner cases and the only one i know is zig. Which returns !void which is an optional error or void
my only concern is that it will be good to be consistent and use R_MUSTUSE to force programmers check for the return value when calling them in that case
Such conventions do not really matter imo. I'm not jumping off a bridge because the cool kids do it.
totally not a blocker for 5.8
the how do you know if init was successful? init in io intentionally returns bool.
I did a quick git grep for r_core_config_init
and r_core_init
none of their callers use their return values as far as I can tell.
Worth improving