Workable split of library

Rather than trying to force things in via library constructors
and weak symbols and --whole-archive and pkg-config tricks, just
add new functions ncdirect_core_init() and notcurses_core_init().
libnotcurses has ncdirect_init() and notcurses_init(), which pass
through to these. apps linking against notcurses-core ought use
the _core_ variants directly. This gets exactly the linkage we
want, everywhere. Convert many PoCs to _core_ variants. #1301

Signed-off-by: nick black <dankamongmen@gmail.com>
pull/1307/head
nick black 3 years ago committed by Nick Black
parent fb85bb9a53
commit 6bd288f056

@ -9,9 +9,6 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Passes -Wl,-no-as-needed to linker steps, necessary to reliably link
# libnotcurses.so into executables...for now. This is grotesque. FIXME
set(CMAKE_LINK_WHAT_YOU_USE ON)
include(CTest)
include(GNUInstallDirs)
@ -602,7 +599,7 @@ target_include_directories(ncls
)
tarGET_Link_libraries(ncls
PRIVATE
notcurses
notcurses++
)
############################################################################

@ -44,6 +44,10 @@ typedef struct ncplane ncdirectv;
// Returns NULL on error, including any failure initializing terminfo.
API struct ncdirect* ncdirect_init(const char* termtype, FILE* fp, uint64_t flags);
// The same as ncdirect_init(), but without any multimedia functionality,
// allowing for a svelter binary. Link with notcurses-core if this is used.
API struct ncdirect* ncdirect_core_init(const char* termtype, FILE* fp, uint64_t flags);
// Direct mode. This API can be used to colorize and stylize output generated
// outside of notcurses, without ever calling notcurses_render(). These should
// not be intermixed with standard Notcurses rendering.

@ -892,6 +892,10 @@ API const char* notcurses_str_scalemode(ncscale_e scalemode);
// failure initializing terminfo.
API struct notcurses* notcurses_init(const notcurses_options* opts, FILE* fp);
// The same as notcurses_init(), but without any multimedia functionality,
// allowing for a svelter binary. Link with notcurses-core if this is used.
API struct notcurses* notcurses_core_init(const notcurses_options* opts, FILE* fp);
// Destroy a Notcurses context.
API int notcurses_stop(struct notcurses* nc);

@ -621,7 +621,7 @@ ncdirect_stop_minimal(void* vnc){
return ret;
}
ncdirect* ncdirect_init(const char* termtype, FILE* outfp, uint64_t flags){
ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
if(flags > (NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS << 1)){ // allow them through with warning
logwarn((struct notcurses*)NULL, "Passed unsupported flags 0x%016jx\n", (uintmax_t)flags);
}

@ -1080,7 +1080,13 @@ typedef struct ncvisual_implementation {
// overriden by strong symbol in libnotcurses.so if built with multimedia
extern const ncvisual_implementation* visual_implementation
__attribute__ ((visibility("default")));
__attribute__ ((visibility("default")));
struct ncvisual* ncvisual_from_file(const char* filename)
__attribute__ ((visibility("default")));
struct ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags)
__attribute__ ((visibility("default")));
#ifdef __cplusplus
}

@ -882,7 +882,8 @@ int ncinputlayer_init(ncinputlayer* nilayer, FILE* infp){
}
// initialize a recursive mutex lock in a way that works on both glibc + musl
int recursive_lock_init(pthread_mutex_t *lock){
static int
recursive_lock_init(pthread_mutex_t *lock){
#ifndef __GLIBC__
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif
@ -905,7 +906,7 @@ int recursive_lock_init(pthread_mutex_t *lock){
#endif
}
notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
notcurses_options defaultopts;
memset(&defaultopts, 0, sizeof(defaultopts));
if(!opts){

@ -4,7 +4,8 @@
#include "visual-details.h"
#include "internal.h"
const __attribute__ ((weak)) ncvisual_implementation* visual_implementation = nullptr;
const __attribute__ ((weak))
ncvisual_implementation* visual_implementation = nullptr;
auto ncvisual_decode(ncvisual* nc) -> int {
int ret = -1;
@ -47,7 +48,8 @@ auto ncvisual_init(int loglevel) -> int {
return ret;
}
auto ncvisual_from_file(const char* filename) -> ncvisual* {
auto __attribute__ ((weak))
ncvisual_from_file(const char* filename) -> ncvisual* {
ncvisual* ret = nullptr;
if(visual_implementation){
ret = visual_implementation->ncvisual_from_file(filename);

@ -289,7 +289,7 @@ auto ffmpeg_create() -> ncvisual* {
return nc;
}
ncvisual* ffmpeg_from_file(const char* filename) {
ncvisual* ncvisual_from_file(const char* filename) {
AVStream* st;
ncvisual* ncv = ffmpeg_create();
if(ncv == nullptr){
@ -571,9 +571,9 @@ auto ffmpeg_init(int loglevel) -> int {
void ffmpeg_printbanner(const notcurses* nc __attribute__ ((unused))){
printf(" avformat %u.%u.%u avutil %u.%u.%u swscale %u.%u.%u\n",
LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO,
LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO,
LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO,
LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO,
LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
}
auto ffmpeg_details_destroy(ncvisual_details* deets) -> void {
@ -594,7 +594,7 @@ const static ncvisual_implementation ffmpeg_impl = {
.ncvisual_decode = ffmpeg_decode,
.ncvisual_blit = ffmpeg_blit,
.ncvisual_create = ffmpeg_create,
.ncvisual_from_file = ffmpeg_from_file,
.ncvisual_from_file = ncvisual_from_file,
.ncvisual_printbanner = ffmpeg_printbanner,
.ncvisual_details_seed = ffmpeg_details_seed,
.ncvisual_details_destroy = ffmpeg_details_destroy,

@ -0,0 +1,10 @@
#include "notcurses/direct.h"
#include "internal.h"
ncdirect* ncdirect_init(const char* termtype, FILE* outfp, uint64_t flags){
return ncdirect_core_init(termtype, outfp, flags);
}
notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
return notcurses_core_init(opts, outfp);
}

@ -7,7 +7,7 @@ int main(void){
notcurses_options nopts = {
.flags = NCOPTION_INHIBIT_SETLOCALE,
};
struct notcurses* nc = notcurses_init(&nopts, NULL);
struct notcurses* nc = notcurses_core_init(&nopts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -4,7 +4,7 @@
#include <notcurses/direct.h>
int main(void){
struct ncdirect* n = ncdirect_init(NULL, NULL, 0);
struct ncdirect* n = ncdirect_core_init(NULL, NULL, 0);
if(n == NULL){
return EXIT_FAILURE;
}

@ -14,7 +14,7 @@ int main(void){
return EXIT_FAILURE;
}
struct ncdirect* n; // see bug #391
if((n = ncdirect_init(NULL, NULL, 0)) == NULL){
if((n = ncdirect_core_init(NULL, NULL, 0)) == NULL){
return EXIT_FAILURE;
}
int dimy = ncdirect_dim_y(n);

@ -56,7 +56,7 @@ int main(void){
if(!setlocale(LC_ALL, "")){
return EXIT_FAILURE;
}
struct ncdirect* nc = ncdirect_init(NULL, stdout, 0);
struct ncdirect* nc = ncdirect_core_init(NULL, stdout, 0);
if(!nc){
return EXIT_FAILURE;
}

@ -6,7 +6,7 @@ int main(void){
if(!setlocale(LC_ALL, "")){
return EXIT_FAILURE;
}
struct ncdirect* n = ncdirect_init(NULL, stdout, 0);
struct ncdirect* n = ncdirect_core_init(NULL, stdout, 0);
putchar('\n');
for(int i = 0 ; i < 15 ; ++i){
uint64_t c1 = 0, c2 = 0;

@ -45,7 +45,7 @@ int main(int argc, char** argv){
.flags = NCOPTION_INHIBIT_SETLOCALE |
NCOPTION_SUPPRESS_BANNERS,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
struct ncplane* n = notcurses_stdplane(nc);
ncplane_set_scrolling(n, true);
while(*++argv){

@ -72,7 +72,7 @@ int main(void){
struct notcurses_options opts = {
.flags = NCOPTION_INHIBIT_SETLOCALE,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -1,7 +1,7 @@
#include <notcurses/direct.h>
int main(void){
struct ncdirect* n = ncdirect_init(NULL, NULL, 0);
struct ncdirect* n = ncdirect_core_init(NULL, NULL, 0);
if(!n){
return EXIT_FAILURE;
}

@ -66,7 +66,7 @@ int main(void){
notcurses_options opts = {
.flags = NCOPTION_INHIBIT_SETLOCALE,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -11,7 +11,7 @@ int main(void){
.tv_sec = 1,
.tv_nsec = 500000000,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
int dimy, dimx;
struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx);
struct ncvisual* ncv = ncvisual_from_plane(std, NCBLIT_2x1, 0, 0, dimy / 2, dimx / 2);

@ -46,7 +46,7 @@ int main(int argc, char** argv){
.flags = NCOPTION_INHIBIT_SETLOCALE |
NCOPTION_SUPPRESS_BANNERS,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -110,7 +110,7 @@ pbar_make(struct notcurses* nc, uint64_t flags){
}
int main(void){
struct notcurses* nc = notcurses_init(NULL, NULL);
struct notcurses* nc = notcurses_core_init(NULL, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -11,7 +11,7 @@ int main(void){
struct notcurses_options opts = {
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -5,7 +5,7 @@ int main(void){
struct notcurses_options opts = {
.flags = NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(!nc){
return EXIT_FAILURE;
}

@ -7,7 +7,7 @@ int main(void){
struct notcurses_options opts = {
.flags = NCOPTION_INHIBIT_SETLOCALE,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct notcurses* nc = notcurses_core_init(&opts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -8,7 +8,7 @@ int main(void){
if(!setlocale(LC_ALL, "")){
return EXIT_FAILURE;
}
struct ncdirect* nc = ncdirect_init(NULL, stdout, 0);
struct ncdirect* nc = ncdirect_core_init(NULL, stdout, 0);
if(!nc){
return EXIT_FAILURE;
}

@ -6,7 +6,7 @@ int main(void){
struct notcurses_options nopts = {
.flags = NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&nopts, NULL);
struct notcurses* nc = notcurses_core_init(&nopts, NULL);
if(nc == NULL){
return EXIT_FAILURE;
}

@ -5,7 +5,7 @@ int main(void){
struct notcurses_options nops = {
.flags = NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&nops, NULL);
struct notcurses* nc = notcurses_core_init(&nops, NULL);
struct ncplane* n = notcurses_stdplane(nc);
const int y = 10;
ncplane_putstr_aligned(n, y + 0, NCALIGN_CENTER, "Pack my box with five dozen liquor jugs.");

Loading…
Cancel
Save