plot: match delete, not free, with new

This commit is contained in:
nick black 2020-04-29 05:15:57 -04:00
parent 6a774afb27
commit e156bd42be
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 24 additions and 22 deletions

View File

@ -1,3 +1,5 @@
* clang-tidy check:
* `cmake "-DCMAKE_CXX_CLANG_TIDY=/usr/bin/clang-tidy-9;-checks=*" ..`
* Run tools/release.sh $OLDVERSION $VERSION
* Finalize CHANGELOG.md
* Bumps version numbers everywhere they need bumping

View File

@ -29,21 +29,21 @@ class ncppplot {
static bool create(ncppplot<T>* ncpp, ncplane* n, const ncplot_options* opts, T miny, T maxy){
// if miny == maxy, they both must be equal to 0
if(miny == maxy && miny){
return NULL;
return false;
}
if(opts->rangex < 0){
return NULL;
return false;
}
if(maxy < miny){
return NULL;
return false;
}
if(opts->gridtype < 0 || opts->gridtype >= sizeof(geomdata) / sizeof(*geomdata)){
return NULL;
return false;
}
int sdimy, sdimx;
ncplane_dim_yx(n, &sdimy, &sdimx);
if(sdimx <= 0){
return NULL;
return false;
}
int dimx = sdimx;
ncpp->rangex = opts->rangex;

View File

@ -1,69 +1,69 @@
#include "cpp.h"
typedef struct ncuplot {
using ncuplot = struct ncuplot {
ncppplot<uint64_t> n;
} ncuplot;
};
typedef struct ncdplot {
using ncdplot = struct ncdplot {
ncppplot<double> n;
} ncdplot;
};
extern "C" {
ncuplot* ncuplot_create(ncplane* n, const ncplot_options* opts, uint64_t miny, uint64_t maxy){
ncuplot* ncuplot_create(ncplane* n, const ncplot_options* opts, uint64_t miny, uint64_t maxy) {
auto ret = new ncuplot;
if(ret){
if(ncppplot<uint64_t>::create(&ret->n, n, opts, miny, maxy)){
return ret;
}
free(ret);
delete ret;
}
return nullptr;
}
ncplane* ncuplot_plane(ncuplot* n){
ncplane* ncuplot_plane(ncuplot* n) {
return n->n.ncp;
}
int ncuplot_add_sample(ncuplot* n, uint64_t x, uint64_t y){
int ncuplot_add_sample(ncuplot* n, uint64_t x, uint64_t y) {
return n->n.add_sample(x, y);
}
int ncuplot_set_sample(ncuplot* n, uint64_t x, uint64_t y){
int ncuplot_set_sample(ncuplot* n, uint64_t x, uint64_t y) {
return n->n.set_sample(x, y);
}
void ncuplot_destroy(ncuplot* n){
void ncuplot_destroy(ncuplot* n) {
if(n){
n->n.destroy();
delete n;
}
}
ncdplot* ncdplot_create(ncplane* n, const ncplot_options* opts, double miny, double maxy){
ncdplot* ncdplot_create(ncplane* n, const ncplot_options* opts, double miny, double maxy) {
auto ret = new ncdplot;
if(ret){
if(ncppplot<double>::create(&ret->n, n, opts, miny, maxy)){
return ret;
}
free(ret);
delete ret;
}
return nullptr;
}
ncplane* ncdplot_plane(ncdplot* n){
ncplane* ncdplot_plane(ncdplot* n) {
return n->n.ncp;
}
int ncdplot_add_sample(ncdplot* n, uint64_t x, double y){
int ncdplot_add_sample(ncdplot* n, uint64_t x, double y) {
return n->n.add_sample(x, y);
}
int ncdplot_set_sample(ncdplot* n, uint64_t x, double y){
int ncdplot_set_sample(ncdplot* n, uint64_t x, double y) {
return n->n.set_sample(x, y);
}
void ncdplot_destroy(ncdplot* n){
void ncdplot_destroy(ncdplot* n) {
if(n){
n->n.destroy();
delete n;

View File

@ -9,7 +9,7 @@ TEST_CASE("ZAxisTest") {
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.suppress_banner = true;
FILE* outfp_ = fopen("/dev/tty", "wb");
FILE* outfp_ = fopen("/dev/tty", "wbe");
REQUIRE(outfp_);
struct notcurses* nc_ = notcurses_init(&nopts, outfp_);
REQUIRE(nc_);