mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-26 22:50:48 +00:00
Introduce new R_* macros to define direction, null, defaults, etc in function signatures (#11546)
- Helps to identify some bugs at compile time - Useful for git grep and understand the usage of the functions - Improve readability - Fix memleak introduced in previous anal/var pr - Help to find unnecessary null checks and start to use r_assert - Deprecate R_TRUFAE R_TRUE R_FALSE and R_ERROR - Add r2api script to ease system-wide git grep for r2 devs - Use more R_OWN and r_return_val_if_fail
This commit is contained in:
parent
945e9566fb
commit
cc8a2b84be
@ -68,11 +68,9 @@ R_API bool r_anal_var_display(RAnal *anal, int delta, char kind, const char *typ
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API bool r_anal_var_add(RAnal *a, ut64 addr, int scope, int delta, char kind, const char *type, int size,
|
||||
bool isarg, const char *name) {
|
||||
if (!a) {
|
||||
return false;
|
||||
}
|
||||
R_API bool r_anal_var_add(RAnal *a, ut64 addr, int scope, int delta, char kind, R_IFNULL("int") const char *type, int size, bool isarg, R_NONNULL const char *name) {
|
||||
r_return_val_if_fail (a, false);
|
||||
r_return_val_if_fail (name, false);
|
||||
if (!kind) {
|
||||
kind = R_ANAL_VAR_KIND_BPV;
|
||||
}
|
||||
|
@ -13,6 +13,20 @@
|
||||
#undef __UNIX__
|
||||
#undef __WINDOWS__
|
||||
|
||||
#define R_IN /* do not use, implicit */
|
||||
#define R_OWN /* pointer ownership is transferred */
|
||||
#define R_OUT /* parameter is written, not read */
|
||||
#define R_INOUT /* parameter is read and written */
|
||||
#define R_NULLABLE /* pointer can be null */
|
||||
#define R_IFNULL(x) /* default value for the pointer when null */
|
||||
#ifdef __GNUC__
|
||||
#define R_NONNULL __attribute__((__nonnull__))
|
||||
#define R_UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define R_NONNULL /* nonnull */
|
||||
#define R_UNUSED /* unused */
|
||||
#endif
|
||||
|
||||
#ifdef R_NEW
|
||||
#undef R_NEW
|
||||
#endif
|
||||
@ -201,14 +215,6 @@ extern "C" {
|
||||
#define __packed __attribute__((__packed__))
|
||||
#endif
|
||||
|
||||
#ifndef UNUSED
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define UNUSED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef int (*PrintfCallback)(const char *str, ...);
|
||||
|
||||
// TODO NOT USED. DEPREACATE
|
||||
|
@ -59,13 +59,11 @@ typedef struct _utX{
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define R_ERROR -2
|
||||
#define R_FAIL -1
|
||||
#define R_FALSE 0
|
||||
#define R_TRUE 1
|
||||
#define R_TRUFAE 2
|
||||
// must be deprecated
|
||||
#define R_NOTNULL (void*)(size_t)1
|
||||
#define R_EMPTY { 0 }
|
||||
#define R_EMPTY2 {{ 0 }}
|
||||
|
||||
/* limits */
|
||||
#undef UT64_MAX
|
||||
|
@ -36,10 +36,10 @@ R_API char *r_type_format(Sdb *TDB, const char *t);
|
||||
R_API int r_type_func_exist(Sdb *TDB, const char *func_name);
|
||||
R_API const char *r_type_func_cc(Sdb *TDB, const char *func_name);
|
||||
R_API const char *r_type_func_ret(Sdb *TDB, const char *func_name);
|
||||
R_API int r_type_func_args_count(Sdb *TDB, const char *func_name);
|
||||
R_API char *r_type_func_args_type(Sdb *TDB, const char *func_name, int i);
|
||||
R_API char *r_type_func_args_name(Sdb *TDB, const char *func_name, int i);
|
||||
R_API char *r_type_func_guess(Sdb *TDB, char *func_name);
|
||||
R_API int r_type_func_args_count(Sdb *TDB, R_NONNULL const char *func_name);
|
||||
R_API R_OWN char *r_type_func_args_type(Sdb *TDB, R_NONNULL const char *func_name, int i);
|
||||
R_API const char *r_type_func_args_name(Sdb *TDB, R_NONNULL const char *func_name, int i);
|
||||
R_API R_OWN char *r_type_func_guess(Sdb *TDB, R_NONNULL char *func_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* radare - LGPL - Copyright 2013-2018 - pancake, oddcoder, sivaramaaa */
|
||||
|
||||
#include "r_util.h"
|
||||
#include <r_util.h>
|
||||
|
||||
R_API int r_type_set(Sdb *TDB, ut64 at, const char *field, ut64 val) {
|
||||
const char *kind;
|
||||
@ -456,7 +456,7 @@ R_API int r_type_func_args_count(Sdb *TDB, const char *func_name) {
|
||||
return sdb_num_get (TDB, query, 0);
|
||||
}
|
||||
|
||||
R_API char *r_type_func_args_type(Sdb *TDB, const char *func_name, int i) {
|
||||
R_API R_OWN char *r_type_func_args_type(Sdb *TDB, R_NONNULL const char *func_name, int i) {
|
||||
const char *query = sdb_fmt ("func.%s.arg.%d", func_name, i);
|
||||
char *ret = sdb_get (TDB, query, 0);
|
||||
if (ret) {
|
||||
@ -470,7 +470,7 @@ R_API char *r_type_func_args_type(Sdb *TDB, const char *func_name, int i) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API char *r_type_func_args_name(Sdb *TDB, const char *func_name, int i) {
|
||||
R_API const char *r_type_func_args_name(Sdb *TDB, R_NONNULL const char *func_name, int i) {
|
||||
const char *query = sdb_fmt ("func.%s.arg.%d", func_name, i);
|
||||
const char *get = sdb_const_get (TDB, query, 0);
|
||||
if (get) {
|
||||
@ -482,7 +482,7 @@ R_API char *r_type_func_args_name(Sdb *TDB, const char *func_name, int i) {
|
||||
|
||||
#define MIN_MATCH_LEN 4
|
||||
|
||||
static char *type_func_try_guess(Sdb *TDB, char *name) {
|
||||
static R_OWN char *type_func_try_guess(Sdb *TDB, R_NONNULL char *name) {
|
||||
const char *res;
|
||||
if (r_str_nlen (name, MIN_MATCH_LEN) < MIN_MATCH_LEN) {
|
||||
return NULL;
|
||||
@ -499,14 +499,13 @@ static char *type_func_try_guess(Sdb *TDB, char *name) {
|
||||
// TODO:
|
||||
// - symbol names are long and noisy, some of them might not be matched due
|
||||
// to additional information added around name
|
||||
R_API char *r_type_func_guess(Sdb *TDB, char *func_name) {
|
||||
R_API R_OWN char *r_type_func_guess(Sdb *TDB, R_NONNULL char *func_name) {
|
||||
int offset = 0;
|
||||
char *str = func_name;
|
||||
char *result = NULL;
|
||||
char *first, *last;
|
||||
if (!func_name) {
|
||||
return NULL;
|
||||
}
|
||||
r_return_val_if_fail (TDB, false);
|
||||
r_return_val_if_fail (func_name, false);
|
||||
|
||||
size_t slen = strlen (str);
|
||||
if (slen < MIN_MATCH_LEN) {
|
||||
|
14
sys/r2api.sh
Executable file
14
sys/r2api.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
cd $HOME/prg/radare2
|
||||
IFS=:
|
||||
for a in $PATH ; do
|
||||
if [ -x "$a/radare2" ]; then
|
||||
D=$(dirname `readlink /usr/local/bin/radare2`)
|
||||
cd "$D/../.."
|
||||
if [ -d libr/include ]; then
|
||||
git grep "$1" libr/include | grep -v '#include' | less -p "$1" -R
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "Cant find r2"
|
Loading…
Reference in New Issue
Block a user