diff options
author | Taylor R Campbell <campbell+tor@mumble.net> | 2019-01-10 18:08:20 +0000 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2019-01-11 14:41:28 +0200 |
commit | d82a8a7f9d268728b2447b2dbbaa346140784f9b (patch) | |
tree | c6ef75aa9a01885cba0f3bd3bdd99d8a1cfc21a6 /src/lib/math | |
parent | 0f8253bddbaae4e73fe2ff9ecf1c342e3f66b798 (diff) | |
download | tor-d82a8a7f9d268728b2447b2dbbaa346140784f9b.tar.gz tor-d82a8a7f9d268728b2447b2dbbaa346140784f9b.zip |
Add some more type checking.
NOTE: This commit breaks the build, because there was a mistake in an
earlier change of exactly the sort that this is meant to detect! I'm
leaving it broken for illustration.
Diffstat (limited to 'src/lib/math')
-rw-r--r-- | src/lib/math/prob_distr.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/math/prob_distr.h b/src/lib/math/prob_distr.h index 981fc2017d..66acb796fd 100644 --- a/src/lib/math/prob_distr.h +++ b/src/lib/math/prob_distr.h @@ -20,6 +20,8 @@ struct dist { }; #define DIST_BASE(OPS) { .ops = (OPS) } +#define DIST_BASE_TYPED(OPS, OBJ, TYPE) \ + DIST_BASE((OPS) + 0*sizeof(&(OBJ) - (const TYPE *)&(OBJ))) const char *dist_name(const struct dist *); double dist_sample(const struct dist *); @@ -46,6 +48,9 @@ struct geometric { extern const struct dist_ops geometric_ops; +#define GEOMETRIC(OBJ) \ + DIST_BASE_TYPED(&geometric_ops, OBJ, struct geometric) + /* Pareto distribution */ struct genpareto { @@ -57,6 +62,9 @@ struct genpareto { extern const struct dist_ops genpareto_ops; +#define GENPARETO(OBJ) \ + DIST_BASE_TYPED(&genpareto_ops, OBJ, struct genpareto) + /* Weibull distribution */ struct weibull { @@ -67,6 +75,9 @@ struct weibull { extern const struct dist_ops weibull_ops; +#define WEIBULL(OBJ) \ + DIST_BASE_TYPED(&weibull_ops, OBJ, struct weibull) + /* Log-logistic distribution */ struct log_logistic { @@ -77,6 +88,9 @@ struct log_logistic { extern const struct dist_ops log_logistic_ops; +#define LOG_LOGISTIC(OBJ) \ + DIST_BASE_TYPED(&log_logistic_ops, OBJ, struct log_logistic) + /* Logistic distribution */ struct logistic { @@ -87,6 +101,9 @@ struct logistic { extern const struct dist_ops logistic_ops; +#define LOGISTIC(OBJ) \ + DIST_BASE_TYPED(&logistic_ops, OBJ, struct logistic) + /* Uniform distribution */ struct uniform { @@ -97,6 +114,9 @@ struct uniform { extern const struct dist_ops uniform_ops; +#define UNIFORM(OBJ) \ + DIST_BASE_TYPED(&uniform_ops, OBJ, struct uniform) + /** Only by unittests */ #ifdef PROB_DISTR_PRIVATE |