~hp/d2tk.lv2

64686ccf9c89ecb97c3b2b5cd3e3b1c21ab14e93 — Hanspeter Portner 3 years ago 1059e62
Squashed 'subprojects/d2tk/' changes from 820f3571a..5a3295fa5

5a3295fa5 base: properly discover console mouse support.
e3df17dd1 Merge commit '268cadaeb0b190faa7c4aca0ec00fcd05131d165'
268cadaeb Squashed 'linenoise/' changes from 42b1d41ba..9dfa3862c
3779e8309 base: close pty master after freeing vterm.
43a666461 base: fix segfault in lineedit atom gc.
ebff6eed2 base: prototype atom garbage collection.

git-subtree-dir: subprojects/d2tk
git-subtree-split: 5a3295fa5b2e0fe4724125e5c8473f1d13d04caa
6 files changed, 74 insertions(+), 28 deletions(-)

M VERSION
M example/example.c
M linenoise/linenoise.c
M src/base.c
M src/base_internal.h
M src/base_pty.c
M VERSION => VERSION +1 -1
@@ 1,1 1,1 @@
0.1.1241
0.1.1253

M example/example.c => example/example.c +1 -1
@@ 67,7 67,7 @@ typedef enum _bar_t {
	BAR_MAX
} bar_t;

static int32_t bar = BAR_MIX;
static int32_t bar = BAR_LINEEDIT;
static const char *bar_lbl [BAR_MAX] = {
	[BAR_MIX]        = "Mix of many",
	[BAR_SPINNER]    = "Spinner",

M linenoise/linenoise.c => linenoise/linenoise.c +0 -1
@@ 1164,7 1164,6 @@ static int linenoiseRaw(linenoiseApp *app, char *buf, size_t buflen, const char 
    if (enableRawMode(app, app->fd_in) == -1) return -1;
    count = linenoiseEdit(app, app->fd_in, app->fd_out, buf, buflen, prompt);
    disableRawMode(app, app->fd_in);
    printf("\n");
    return count;
}


M src/base.c => src/base.c +40 -9
@@ 173,6 173,7 @@ _d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
			}
		}

		atom->ttl = 32; //FIXME
		return atom->body;
	}



@@ 793,24 794,52 @@ d2tk_base_set_ttls(d2tk_base_t *base, uint32_t sprites, uint32_t memcaches)
	d2tk_core_set_ttls(base->core, sprites, memcaches);
}

D2TK_API void
d2tk_base_free(d2tk_base_t *base)
static void
_d2tk_atom_deinit(d2tk_atom_t *atom)
{
	atom->id = 0;
	atom->type = 0;
	if(atom->event)
	{
		atom->event(D2TK_ATOM_EVENT_DEINIT, atom->body);
		atom->event = NULL;
	}
	free(atom->body);
	atom->body = NULL;
	atom->ttl = 0;
}

static void
_d2tk_atom_gc(d2tk_base_t *base)
{
	for(unsigned i = 0; i < _D2TK_MAX_ATOM; i++)
	{
		d2tk_atom_t *atom = &base->atoms[i];

		atom->id = 0;
		atom->type = 0;
		if(atom->event)
		if(!atom->id || (--atom->ttl > 0) )
		{
			atom->event(D2TK_ATOM_EVENT_DEINIT, atom->body);
			atom->event = NULL;
			continue;
		}
		free(atom->body);
		atom->body = NULL;

		_d2tk_atom_deinit(atom);
	}
}

static void
_d2tk_atom_free(d2tk_base_t *base)
{
	for(unsigned i = 0; i < _D2TK_MAX_ATOM; i++)
	{
		d2tk_atom_t *atom = &base->atoms[i];

		_d2tk_atom_deinit(atom);
	}
}

D2TK_API void
d2tk_base_free(d2tk_base_t *base)
{
	_d2tk_atom_free(base);
	d2tk_core_free(base->core);
	free(base);
}


@@ 867,6 896,8 @@ d2tk_base_post(d2tk_base_t *base)

	_d2tk_base_clear_chars(base);

	_d2tk_atom_gc(base);

	d2tk_core_post(base->core);
}


M src/base_internal.h => src/base_internal.h +1 -0
@@ 56,6 56,7 @@ struct _d2tk_flip_t {
struct _d2tk_atom_t {
	d2tk_id_t id;
	d2tk_atom_type_t type;
	uint32_t ttl;
	void *body;
	d2tk_atom_event_t event;
};

M src/base_pty.c => src/base_pty.c +31 -16
@@ 91,9 91,10 @@ struct _d2tk_atom_body_pty_t {
	d2tk_coord_t ncols;
	d2tk_coord_t nrows;
	unsigned bell;
	bool hasmouse;

	int fd;
	pid_t kid;
	ptrdiff_t kid;

	thread_data_t thread_data;
	bool is_threaded;


@@ 184,6 185,11 @@ _term_done_thread(d2tk_atom_body_pty_t *vpty)

	pthread_join(vpty->kid, NULL);

#if D2TK_DEBUG == 1
				fprintf(stderr, "[%s] child with pid %ld has exited\n",
					__func__, vpty->kid);
#endif

	_term_clear(vpty);
	return 1;
}


@@ 192,9 198,9 @@ static inline int
_term_done_fork(d2tk_atom_body_pty_t *vpty)
{
	int stat = 0;
	const int kid = waitpid(vpty->kid, NULL, WNOHANG);
	const ptrdiff_t kid = waitpid(vpty->kid, NULL, WNOHANG);
#if D2TK_DEBUG == 1
	fprintf(stderr, "[%s] waitpid of child with pid %d: %d (%d)\n",
	fprintf(stderr, "[%s] waitpid of child with pid %ld: %ld (%d)\n",
		__func__, vpty->kid, kid, stat);
#endif



@@ 212,14 218,14 @@ _term_done_fork(d2tk_atom_body_pty_t *vpty)
	if(WIFSIGNALED(stat))
	{
#if D2TK_DEBUG == 1
		fprintf(stderr, "[%s] child with pid %d has exited with signal %d\n",
		fprintf(stderr, "[%s] child with pid %ld has exited with signal %d\n",
			__func__, vpty->kid, WTERMSIG(stat));
#endif
	}
	else if(WIFEXITED(stat))
	{
#if D2TK_DEBUG == 1
		fprintf(stderr, "[%s] child with pid %d has exited with status %d\n",
		fprintf(stderr, "[%s] child with pid %ld has exited with status %d\n",
			__func__, vpty->kid, WEXITSTATUS(stat));
#endif
	}


@@ 270,6 276,10 @@ _screen_settermprop(VTermProp prop, VTermValue *val, void *data)
		{
			vpty->cursor_shape = val->number;
		} break;
		case VTERM_PROP_MOUSE:
		{
			vpty->hasmouse = true;
		} break;

		default:
		{


@@ 393,7 403,7 @@ _thread(void *data)
	return NULL;
}

static int
static ptrdiff_t
_threadpty(int *amaster, const struct termios *termp, const struct winsize *winp,
	d2tk_base_pty_cb_t cb, void *data, thread_data_t *thread_data)
{


@@ 425,7 435,7 @@ _threadpty(int *amaster, const struct termios *termp, const struct winsize *winp
	return thread;
}

static int
static ptrdiff_t
_forkpty(int *amaster, const struct termios *termp, const struct winsize *winp,
	void *data)
{


@@ 545,7 555,7 @@ _term_init(d2tk_atom_body_pty_t *vpty, d2tk_base_pty_cb_t cb, void *data,
	}

#if D2TK_DEBUG == 1
	fprintf(stderr, "[%s] child with pid %i has spawned\n", __func__, vpty->kid);
	fprintf(stderr, "[%s] child with pid %ld has spawned\n", __func__, vpty->kid);
#endif

  fcntl(vpty->fd, F_SETFL, fcntl(vpty->fd, F_GETFL) | O_NONBLOCK);


@@ 579,6 589,11 @@ _term_deinit_thread(d2tk_atom_body_pty_t *vpty)

		pthread_join(vpty->kid, NULL);

#if D2TK_DEBUG == 1
				fprintf(stderr, "[%s] child with pid %ld has exited\n",
					__func__, vpty->kid);
#endif

		_term_clear(vpty);
	}



@@ 620,14 635,14 @@ _term_deinit_fork(d2tk_atom_body_pty_t *vpty)
			if(WIFSIGNALED(stat))
			{
#if D2TK_DEBUG == 1
				fprintf(stderr, "[%s] child with pid %d has exited with signal %d\n",
				fprintf(stderr, "[%s] child with pid %ld has exited with signal %d\n",
					__func__, vpty->kid, WTERMSIG(stat));
#endif
			}
			else if(WIFEXITED(stat))
			{
#if D2TK_DEBUG == 1
				fprintf(stderr, "[%s] child with pid %d has exited with status %d\n",
				fprintf(stderr, "[%s] child with pid %ld has exited with status %d\n",
					__func__, vpty->kid, WEXITSTATUS(stat));
#endif
			}


@@ 652,6 667,11 @@ _term_deinit(d2tk_atom_body_pty_t *vpty)
		? _term_deinit_thread(vpty)
		: _term_deinit_fork(vpty);

	if(vpty->vterm)
	{
		vterm_free(vpty->vterm);
	}

	if(vpty->fd)
	{
		close(vpty->fd);


@@ 659,11 679,6 @@ _term_deinit(d2tk_atom_body_pty_t *vpty)
		vpty->fd = 0;
	}

	if(vpty->vterm)
	{
		vterm_free(vpty->vterm);
	}

	memset(vpty, 0x0, sizeof(d2tk_atom_body_pty_t));

	return ret;


@@ 1015,7 1030,7 @@ _term_behave(d2tk_base_t *base, d2tk_atom_body_pty_t *vpty,
		vterm_state_focus_out(vpty->state);
	}

	if(flags & D2TK_FLAG_PTY_NOMOUSE)
	if( !vpty->hasmouse || (flags & D2TK_FLAG_PTY_NOMOUSE) )
	{
		return state;
	}