summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorJ08nY2017-05-19 18:00:00 +0200
committerJ08nY2017-05-19 18:00:00 +0200
commit132a768b5718cef1ff621380f2dcf21cd0553404 (patch)
tree77acc82153e0d0b73351258feaa504ce0d3bbd74 /src/math
parentbaa18605f6b9e6c6627d118a9ffc6c1c683ac12d (diff)
downloadecgen-132a768b5718cef1ff621380f2dcf21cd0553404.tar.gz
ecgen-132a768b5718cef1ff621380f2dcf21cd0553404.tar.zst
ecgen-132a768b5718cef1ff621380f2dcf21cd0553404.zip
Add debug logging with time, refactor allocation
Diffstat (limited to 'src/math')
-rw-r--r--src/math/arg.c17
-rw-r--r--src/math/curve.c11
-rw-r--r--src/math/point.c21
-rw-r--r--src/math/types.h2
4 files changed, 11 insertions, 40 deletions
diff --git a/src/math/arg.c b/src/math/arg.c
index d2eba9b..6b11777 100644
--- a/src/math/arg.c
+++ b/src/math/arg.c
@@ -3,22 +3,15 @@
* Copyright (C) 2017 J08nY
*/
#include "arg.h"
+#include "util/memory.h"
-arg_t *arg_new(void) {
- arg_t *arg = pari_malloc(sizeof(arg_t));
- if (!arg) {
- perror("Couldn't malloc.");
- exit(1);
- }
- memset(arg, 0, sizeof(arg_t));
- return arg;
-}
+arg_t *arg_new(void) { return try_calloc(sizeof(arg_t)); }
void arg_free(arg_t **arg) {
if (*arg) {
- if ((*arg)->mallocd) {
- pari_free((*arg)->mallocd);
- (*arg)->mallocd = NULL;
+ if ((*arg)->allocd) {
+ pari_free((*arg)->allocd);
+ (*arg)->allocd = NULL;
}
pari_free(*arg);
*arg = NULL;
diff --git a/src/math/curve.c b/src/math/curve.c
index 969e628..90799bb 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -6,16 +6,9 @@
#include "exhaustive/seed.h"
#include "field.h"
#include "point.h"
+#include "util/memory.h"
-curve_t *curve_new(void) {
- curve_t *curve = pari_malloc(sizeof(curve_t));
- if (!curve) {
- perror("Couldn't malloc.");
- exit(1);
- }
- memset(curve, 0, sizeof(curve_t));
- return curve;
-}
+curve_t *curve_new(void) { return try_calloc(sizeof(curve_t)); }
curve_t *curve_copy(const curve_t *src, curve_t *dest) {
if (src->seed) dest->seed = seed_copy(src->seed, dest->seed);
diff --git a/src/math/point.c b/src/math/point.c
index d8a9d8d..877cfe6 100644
--- a/src/math/point.c
+++ b/src/math/point.c
@@ -3,16 +3,9 @@
* Copyright (C) 2017 J08nY
*/
#include "point.h"
+#include "util/memory.h"
-point_t *point_new(void) {
- point_t *point = pari_malloc(sizeof(point_t));
- if (!point) {
- perror("Couldn't malloc.");
- exit(1);
- }
- memset(point, 0, sizeof(point_t));
- return point;
-}
+point_t *point_new(void) { return try_calloc(sizeof(point_t)); }
point_t *point_copy(const point_t *src, point_t *dest) {
if (src->point) dest->point = gcopy(src->point);
@@ -54,15 +47,7 @@ void point_free(point_t **point) {
}
}
-point_t **points_new(size_t num) {
- point_t **points = pari_malloc(num * sizeof(point_t *));
- if (!points) {
- perror("Couldn't malloc.");
- exit(1);
- }
- memset(points, 0, num * sizeof(point_t *));
- return points;
-}
+point_t **points_new(size_t num) { return try_calloc(num * sizeof(point_t *)); }
point_t **points_copy(point_t **const src, point_t **dest, size_t num) {
for (size_t i = 0; i < num; ++i) {
diff --git a/src/math/types.h b/src/math/types.h
index ab4b224..00d78c0 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -80,7 +80,7 @@ typedef enum {
typedef struct {
const void *args;
size_t nargs;
- void *mallocd;
+ void *allocd;
} arg_t;
/**