Thread: Node functions not quite working as expected

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733

    Node functions not quite working as expected

    These 2 are supposed to managed pointers for various object types but somehow makeNode() is hitting a situation where it's re-allocating objects that are already in use, I'm not seeing what's causing it, anyone have any ideas?
    Code:
    SHARED_EXP dint	makeNode( void *ud, NODES *Nodes, void **Node )
    {
    	uint i, j = 0, *k;
    	dint err;
    	BUFFER *Shared;
    	BUFFER *Erased;
    	void **nodes, **object = NULL;
    
    	if ( *Node )
    		return 0;
    
    	err = makeNodes( ud, Nodes );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		return err;
    	}
    
    	Shared = Nodes->shared;
    	Erased = Nodes->erased;
    
    	nodes = (void**)(Shared->array);
    
    	do
    	{
    		i = Erased->count;
    		if ( i )
    		{
    			uint *clear = Erased->array;
    			j = clear[--i];
    			clear[i] = 0;
    			object = nodes + j;
    			Erased->count--;
    			break;
    		}
    
    		j = Shared->count + !(Shared->count);
    		if ( Shared->total <= j )
    		{
    			err = markBuffert( ud, Shared, j + bitsof(int) );
    			if ( err )
    			{
    				ECHO_ERRNO( stdout, err );
    				return err;
    			}
    		}
    
    		nodes = (void**)(Shared->array);
    		object = nodes + j;
    		*object = NULL;
    		err = makeObject( ud, object, Nodes->Vsize, Nodes->makeCB );
    		if ( err )
    		{
    			ECHO_ERRNO( stdout, err );
    			return err;
    		}
    	}
    	while (0);
    
    	*Node = *object;
    	k = Nodes->gaveCB( *object );
    	assert( !(*k) );
    	*k = j;
    	return 0;
    }
    
    SHARED_EXP dint	voidNode( void *ud, NODES *Nodes, void **Node )
    {
    	uint j = 0, *k;
    	dint err;
    	BUFFER *Shared = Nodes->shared;
    	BUFFER *Erased = Nodes->erased;
    	void **nodes, **object = NULL;
    	uint *clear;
    
    	if ( !Shared || !(*Node) )
    		return 0;
    
    	k = Nodes->gaveCB( *Node );
    	nodes = (void**)(Shared->array);
    	object = nodes + *k;
    
    	err = Nodes->termCB( ud, *object );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		return err;
    	}
    	*Node = NULL;
    
    	/* Try to keep the node available for re-use */
    	j = Erased->count;
    	err = growBufferc( ud, Erased, 1 );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		voidObject( ud, object, Nodes->voidCB );
    		return err;
    	}
    
    	clear = Erased->array;
    	clear[j] = *k;
    	*k = 0;
    	return 0;
    }

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Never mind, it finally occurred to me that maybe I had passed the wrong NODES object so I adjusted the code and added an assert to catch the occurrence, turned out I was, well it resolved one issue but doesn't resolve another issue which is triggering the same assert yet there's no visible reason from the code paths:

    Code:
    SHARED_EXP dint	voidNode( void *ud, NODES *Nodes, void **Node )
    {
    	uint j = 0, *k;
    	dint err;
    	BUFFER *Shared = Nodes->shared;
    	BUFFER *Erased = Nodes->erased;
    	void **nodes, **n;
    	uint *clear;
    
    	if ( !Shared || !(*Node) )
    		return 0;
    	nodes = (void**)(Shared->array);
    	k = Nodes->gaveCB( *Node );
    	n = nodes + *k;
    	if ( *n != *Node )
    	{
    		err = EPERM;
    		ECHO_ERRNO( stdout, err );
    		assert( false );
    		return err;
    	}
    
    	err = Nodes->termCB( ud, *Node );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		return err;
    	}
    	*Node = NULL;
    
    	/* Try to keep the node available for re-use */
    	j = Erased->count;
    	err = growBufferc( ud, Erased, 1 );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		voidObject( ud, n, Nodes->voidCB );
    		return err;
    	}
    
    	clear = Erased->array;
    	clear[j] = *k;
    	*k = 0;
    	return 0;
    }
    ...
    SHARED_EXP dint readNextLine( void *ud, SOURCE *src )
    {
    	ACHS **S = &(src->Line);
    	ACHS *B = *S;
    	achs text = src->Text->array;
    	uint i = src->pos, end = src->Text->count - !!(src->Text->count);
    	dint err;
    
    	if ( i >= end )
    	{
    		voidAchs( ud, S );
    		return ENODATA;
    	}
    
    	if ( !B )
    	{
    		err = makeAchsn( ud, S, text, end - i );
    		if ( err )
    		{
    			ECHO_ERRNO( stdout, err );
    			return err;
    		}
    		B = *S;
    	}
    
    	err = termAchs( ud, B );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		return err;
    	}
    
    	for ( ; i < end && !isnewline( text[i] ); ++i );
    
    	err = initAchsn( ud, B, text + src->pos, i - src->pos );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		return err;
    	}
    
    	i += (i < end && text[i] == '\r' && text[i + 1] == '\n');
    	i +=
    	(
    		i < end
    		&& (text[i] == '\r' || text[i] == '\n')
    		&& text[i + 1] == '\f'
    	);
    	i += (i < end);
    	src->ins = src->pos;
    	src->pos = i;
    	src->line++;
    	return 0;
    }
    I'm gonna upload the latest changes then provide the link for anyone interested in seeing if they can find the cause before I do.

    Edit: Here's the link starting from readNextLine:

    src/libparse/c.c * aec637929d2899e56ab1350d67ebcb9f906b9736 * Lee Shallis / Dragonbuilder * GitLab

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Ironed out some issues that I found in makeNode:

    Files * 896a3105bb2a48e53552dd11e1fcf35d9a3cd343 * Lee Shallis / Dragonbuilder * GitLab

    Code:
    SHARED_EXP dint	makeNode( void *ud, NODES *Nodes, void **Node )
    {
    	uint i, j = 0, *k;
    	dint err;
    	BUFFER *Shared;
    	BUFFER *Erased;
    	void **nodes, **n = NULL;
    
    	if ( *Node )
    		return 0;
    
    	err = makeNodes( ud, Nodes );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		return err;
    	}
    
    	Shared = Nodes->shared;
    	Erased = Nodes->erased;
    
    	i = Erased->count;
    	if ( i )
    	{
    		uint *clear = Erased->array;
    		nodes = (void**)(Shared->array);
    		j = clear[--i];
    		clear[i] = 0;
    		n = nodes + j;
    		Erased->count--;
    		*Node = *n;
    		return 0;
    	}
    
    	j = Shared->count + !(Shared->count);
    	err = markBufferc( ud, Shared, j + 1 );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		return err;
    	}
    
    	nodes = (void**)(Shared->array);
    	n = nodes + j;
    	err = makeObject( ud, n, Nodes->Vsize, Nodes->makeCB );
    	if ( err )
    	{
    		ECHO_ERRNO( stdout, err );
    		Shared->count--;
    		return err;
    	}
    	k = Nodes->gaveCB( *n );
    	*Node = *n;
    	*k = j;
    	return 0;
    }

  4. #4
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    After some further fixes I hit another issue related to node management, not sure where it's coming from yet though:

    Files * 8f3b12dfd69a51ae1757c66651d26a132c7aafa2 * Lee Shallis / Dragonbuilder * GitLab

    Code:
    make rebuild valgrind
    ...
    rm -f -r obj/*
    rm -f -r lib/*
    rm -f -r bin/*
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc -D _QUICK -O3 -o *._x86_64_linux_cc -c src/libbasic/agedby.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_debug -D _DEBUG -ggdb -o *._x86_64_linux_cc_debug -c src/libbasic/agedby.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_gprof -D _GPROF -pg -o *._x86_64_linux_cc_gprof -c src/libbasic/agedby.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_trace -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o *._x86_64_linux_cc_trace -c src/libbasic/agedby.c
    ...
    cc -fPIC -shared -D _QUICK -O3 -o bin/libbasic._x86_64_linux_cc.so src/libbasic/*.o src/libbasic/buffer/*.o src/libbasic/buffer/obj/*.o src/libbasic/obj/*.o src/libbasic/string/*.o src/libbasic/string/obj/*.o -Wl,-rpath,. -L bin -L lib -lpthread -ldl -lm
    cc -fPIC -shared -D _DEBUG -ggdb -o bin/libbasic._x86_64_linux_cc_debug.so src/libbasic/*.o src/libbasic/buffer/*.o src/libbasic/buffer/obj/*.o src/libbasic/obj/*.o src/libbasic/string/*.o src/libbasic/string/obj/*.o -Wl,-rpath,. -L bin -L lib -lpthread -ldl -lm
    cc -fPIC -shared -D _GPROF -pg -o bin/libbasic._x86_64_linux_cc_gprof.so src/libbasic/*.o src/libbasic/buffer/*.o src/libbasic/buffer/obj/*.o src/libbasic/obj/*.o src/libbasic/string/*.o src/libbasic/string/obj/*.o -Wl,-rpath,. -L bin -L lib -lpthread -ldl -lm
    cc -fPIC -shared -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/libbasic._x86_64_linux_cc_trace.so src/libbasic/*.o src/libbasic/buffer/*.o src/libbasic/buffer/obj/*.o src/libbasic/obj/*.o src/libbasic/string/*.o src/libbasic/string/obj/*.o -Wl,-rpath,. -L bin -L lib -lpthread -ldl -lm
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc -D _QUICK -O3 -o *._x86_64_linux_cc -c src/libparse/c.c
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_debug -D _DEBUG -ggdb -o *._x86_64_linux_cc_debug -c src/libparse/c.c
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_gprof -D _GPROF -pg -o *._x86_64_linux_cc_gprof -c src/libparse/c.c
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_trace -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o *._x86_64_linux_cc_trace -c src/libparse/c.c
    cc -fPIC -shared -D _QUICK -O3 -o bin/libparse._x86_64_linux_cc.so src/libparse/*.o src/libparse/obj/*.o src/libparse/ops/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc
    cc -fPIC -shared -D _DEBUG -ggdb -o bin/libparse._x86_64_linux_cc_debug.so src/libparse/*.o src/libparse/obj/*.o src/libparse/ops/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_debug
    cc -fPIC -shared -D _GPROF -pg -o bin/libparse._x86_64_linux_cc_gprof.so src/libparse/*.o src/libparse/obj/*.o src/libparse/ops/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_gprof
    cc -fPIC -shared -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/libparse._x86_64_linux_cc_trace.so src/libparse/*.o src/libparse/obj/*.o src/libparse/ops/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_trace
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc -D _QUICK -O3 -o *._x86_64_linux_cc -c src/libextra/viewfx/shader.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_debug -D _DEBUG -ggdb -o *._x86_64_linux_cc_debug -c src/libextra/viewfx/shader.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_gprof -D _GPROF -pg -o *._x86_64_linux_cc_gprof -c src/libextra/viewfx/shader.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_trace -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o *._x86_64_linux_cc_trace -c src/libextra/viewfx/shader.c
    ...
    cc -fPIC -shared -D _QUICK -O3 -o bin/libextra._x86_64_linux_cc.so src/libextra/*.o src/libextra/obj/*.o src/libextra/viewfx/*.o src/libextra/viewfx/obj/*.o src/libextra/zipped/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc -lparse._x86_64_linux_cc
    cc -fPIC -shared -D _DEBUG -ggdb -o bin/libextra._x86_64_linux_cc_debug.so src/libextra/*.o src/libextra/obj/*.o src/libextra/viewfx/*.o src/libextra/viewfx/obj/*.o src/libextra/zipped/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_debug -lparse._x86_64_linux_cc_debug
    cc -fPIC -shared -D _GPROF -pg -o bin/libextra._x86_64_linux_cc_gprof.so src/libextra/*.o src/libextra/obj/*.o src/libextra/viewfx/*.o src/libextra/viewfx/obj/*.o src/libextra/zipped/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_gprof -lparse._x86_64_linux_cc_gprof
    cc -fPIC -shared -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/libextra._x86_64_linux_cc_trace.so src/libextra/*.o src/libextra/obj/*.o src/libextra/viewfx/*.o src/libextra/viewfx/obj/*.o src/libextra/zipped/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_trace -lparse._x86_64_linux_cc_trace
    cc -fPIC -shared -D _QUICK -O3 -o bin/libimage._x86_64_linux_cc.so src/libimage/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc
    cc -fPIC -shared -D _DEBUG -ggdb -o bin/libimage._x86_64_linux_cc_debug.so src/libimage/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_debug
    cc -fPIC -shared -D _GPROF -pg -o bin/libimage._x86_64_linux_cc_gprof.so src/libimage/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_gprof
    cc -fPIC -shared -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/libimage._x86_64_linux_cc_trace.so src/libimage/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_trace
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc -D _QUICK -O3 -o *._x86_64_linux_cc -c src/libvfxgl/opengl_defect.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_debug -D _DEBUG -ggdb -o *._x86_64_linux_cc_debug -c src/libvfxgl/opengl_defect.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_gprof -D _GPROF -pg -o *._x86_64_linux_cc_gprof -c src/libvfxgl/opengl_defect.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_trace -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o *._x86_64_linux_cc_trace -c src/libvfxgl/opengl_defect.c
    ...
    cc -fPIC -shared -D _QUICK -O3 -o bin/libvfxgl._x86_64_linux_cc.so src/libvfxgl/*.o src/libvfxgl/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc -lbasic._x86_64_linux_cc -lGLEW
    cc -fPIC -shared -D _DEBUG -ggdb -o bin/libvfxgl._x86_64_linux_cc_debug.so src/libvfxgl/*.o src/libvfxgl/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_debug -lbasic._x86_64_linux_cc_debug -lGLEW
    cc -fPIC -shared -D _GPROF -pg -o bin/libvfxgl._x86_64_linux_cc_gprof.so src/libvfxgl/*.o src/libvfxgl/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_gprof -lbasic._x86_64_linux_cc_gprof -lGLEW
    cc -fPIC -shared -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/libvfxgl._x86_64_linux_cc_trace.so src/libvfxgl/*.o src/libvfxgl/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_trace -lbasic._x86_64_linux_cc_trace -lGLEW
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc -D _QUICK -O3 -o *._x86_64_linux_cc -c src/libvfxglfw/glfw_eio.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_debug -D _DEBUG -ggdb -o *._x86_64_linux_cc_debug -c src/libvfxglfw/glfw_eio.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_gprof -D _GPROF -pg -o *._x86_64_linux_cc_gprof -c src/libvfxglfw/glfw_eio.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_trace -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o *._x86_64_linux_cc_trace -c src/libvfxglfw/glfw_eio.c
    ...
    cc -fPIC -shared -D _QUICK -O3 -o bin/libvfxglfw._x86_64_linux_cc.so src/libvfxglfw/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc -lbasic._x86_64_linux_cc -lglfw -lGLEW
    cc -fPIC -shared -D _DEBUG -ggdb -o bin/libvfxglfw._x86_64_linux_cc_debug.so src/libvfxglfw/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_debug -lbasic._x86_64_linux_cc_debug -lglfw -lGLEW
    cc -fPIC -shared -D _GPROF -pg -o bin/libvfxglfw._x86_64_linux_cc_gprof.so src/libvfxglfw/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_gprof -lbasic._x86_64_linux_cc_gprof -lglfw -lGLEW
    cc -fPIC -shared -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/libvfxglfw._x86_64_linux_cc_trace.so src/libvfxglfw/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_trace -lbasic._x86_64_linux_cc_trace -lglfw -lGLEW
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc -D _QUICK -O3 -o *._x86_64_linux_cc -c src/trybasic/main.c
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_debug -D _DEBUG -ggdb -o *._x86_64_linux_cc_debug -c src/trybasic/main.c
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_gprof -D _GPROF -pg -o *._x86_64_linux_cc_gprof -c src/trybasic/main.c
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_trace -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o *._x86_64_linux_cc_trace -c src/trybasic/main.c
    cc -D _QUICK -O3 -o bin/trybasic._x86_64_linux_cc.elf src/trybasic/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc
    cc -D _DEBUG -ggdb -o bin/trybasic._x86_64_linux_cc_debug.elf src/trybasic/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_debug
    cc -D _GPROF -pg -o bin/trybasic._x86_64_linux_cc_gprof.elf src/trybasic/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_gprof
    cc -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/trybasic._x86_64_linux_cc_trace.elf src/trybasic/*.o -Wl,-rpath,. -L bin -L lib -lbasic._x86_64_linux_cc_trace
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc -D _QUICK -O3 -o *._x86_64_linux_cc -c src/tryextra/create.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_debug -D _DEBUG -ggdb -o *._x86_64_linux_cc_debug -c src/tryextra/create.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_gprof -D _GPROF -pg -o *._x86_64_linux_cc_gprof -c src/tryextra/create.c
    ...
    cc -Wall -Wextra -fPIC -D __X86_64__=1 -D _linux=1 -D _PAW_PFX=_x86_64_linux_cc_trace -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o *._x86_64_linux_cc_trace -c src/tryextra/create.c
    ...
    cc -D _QUICK -O3 -o bin/tryextra._x86_64_linux_cc.elf src/tryextra/*.o src/tryextra/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc -lparse._x86_64_linux_cc -lbasic._x86_64_linux_cc
    cc -D _DEBUG -ggdb -o bin/tryextra._x86_64_linux_cc_debug.elf src/tryextra/*.o src/tryextra/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_debug -lparse._x86_64_linux_cc_debug -lbasic._x86_64_linux_cc_debug
    cc -D _GPROF -pg -o bin/tryextra._x86_64_linux_cc_gprof.elf src/tryextra/*.o src/tryextra/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_gprof -lparse._x86_64_linux_cc_gprof -lbasic._x86_64_linux_cc_gprof
    cc -D _DEBUG -ggdb -fno-omit-frame-pointer -fsanitize=leak -fsanitize=address -o bin/tryextra._x86_64_linux_cc_trace.elf src/tryextra/*.o src/tryextra/obj/*.o -Wl,-rpath,. -L bin -L lib -lextra._x86_64_linux_cc_trace -lparse._x86_64_linux_cc_trace -lbasic._x86_64_linux_cc_trace
    cd bin && valgrind ./tryextra._x86_64_linux_cc_debug.elf -D APP_DATA=../run
    ==28110== Memcheck, a memory error detector
    ==28110== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==28110== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
    ==28110== Command: ./tryextra._x86_64_linux_cc_debug.elf -D APP_DATA=../run
    ==28110==
    ==28110== Invalid write of size 8
    ==28110==    at 0x48811E7: makeNode (nodes.c:165)
    ==28110==    by 0x4888BA2: makeText (text.c:169)
    ==28110==    by 0x4888BCE: makeTextc (text.c:172)
    ==28110==    by 0x4888CB9: makeTextt (text.c:188)
    ==28110==    by 0x488B2DE: markTextv (text.c:953)
    ==28110==    by 0x4885B25: cramAchsv (achs.c:307)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==    by 0x4885293: makeAchsv (achs.c:195)
    ==28110==    by 0x48853AA: makeAchsf (achs.c:208)
    ==28110==    by 0x10C5A8: main (main.c:111)
    ==28110==  Address 0x4c05900 is 4 bytes after a block of size 12 alloc'd
    ==28110==    at 0x4843CD3: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==28110==    by 0x48824FE: allot (shared.c:90)
    ==28110==    by 0x487F878: markBuffert (buffer.c:302)
    ==28110==    by 0x487F6F6: markBufferc (buffer.c:274)
    ==28110==    by 0x48810FD: makeNode (nodes.c:150)
    ==28110==    by 0x4888BA2: makeText (text.c:169)
    ==28110==    by 0x4888BCE: makeTextc (text.c:172)
    ==28110==    by 0x4888CB9: makeTextt (text.c:188)
    ==28110==    by 0x488B2DE: markTextv (text.c:953)
    ==28110==    by 0x4885B25: cramAchsv (achs.c:307)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==
    ==28110== Invalid read of size 8
    ==28110==    at 0x4881204: makeNode (nodes.c:166)
    ==28110==    by 0x4888BA2: makeText (text.c:169)
    ==28110==    by 0x4888BCE: makeTextc (text.c:172)
    ==28110==    by 0x4888CB9: makeTextt (text.c:188)
    ==28110==    by 0x488B2DE: markTextv (text.c:953)
    ==28110==    by 0x4885B25: cramAchsv (achs.c:307)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==    by 0x4885293: makeAchsv (achs.c:195)
    ==28110==    by 0x48853AA: makeAchsf (achs.c:208)
    ==28110==    by 0x10C5A8: main (main.c:111)
    ==28110==  Address 0x4c05900 is 4 bytes after a block of size 12 alloc'd
    ==28110==    at 0x4843CD3: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==28110==    by 0x48824FE: allot (shared.c:90)
    ==28110==    by 0x487F878: markBuffert (buffer.c:302)
    ==28110==    by 0x487F6F6: markBufferc (buffer.c:274)
    ==28110==    by 0x48810FD: makeNode (nodes.c:150)
    ==28110==    by 0x4888BA2: makeText (text.c:169)
    ==28110==    by 0x4888BCE: makeTextc (text.c:172)
    ==28110==    by 0x4888CB9: makeTextt (text.c:188)
    ==28110==    by 0x488B2DE: markTextv (text.c:953)
    ==28110==    by 0x4885B25: cramAchsv (achs.c:307)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==
    ==28110== Invalid read of size 8
    ==28110==    at 0x48812B3: voidNode (nodes.c:185)
    ==28110==    by 0x4888B76: voidText (text.c:167)
    ==28110==    by 0x4885C7C: cramAchsv (achs.c:329)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==    by 0x4885293: makeAchsv (achs.c:195)
    ==28110==    by 0x48853AA: makeAchsf (achs.c:208)
    ==28110==    by 0x10C5A8: main (main.c:111)
    ==28110==  Address 0x4c05900 is 4 bytes after a block of size 12 alloc'd
    ==28110==    at 0x4843CD3: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==28110==    by 0x48824FE: allot (shared.c:90)
    ==28110==    by 0x487F878: markBuffert (buffer.c:302)
    ==28110==    by 0x487F6F6: markBufferc (buffer.c:274)
    ==28110==    by 0x48810FD: makeNode (nodes.c:150)
    ==28110==    by 0x4888BA2: makeText (text.c:169)
    ==28110==    by 0x4888BCE: makeTextc (text.c:172)
    ==28110==    by 0x4888CB9: makeTextt (text.c:188)
    ==28110==    by 0x488B2DE: markTextv (text.c:953)
    ==28110==    by 0x4885B25: cramAchsv (achs.c:307)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==
    ==28110== Invalid read of size 8
    ==28110==    at 0x48810B6: makeNode (nodes.c:145)
    ==28110==    by 0x4888BA2: makeText (text.c:169)
    ==28110==    by 0x4885121: makeAchs (achs.c:178)
    ==28110==    by 0x4885230: makeAchsv (achs.c:189)
    ==28110==    by 0x48853AA: makeAchsf (achs.c:208)
    ==28110==    by 0x10C600: main (main.c:118)
    ==28110==  Address 0x4c05900 is 4 bytes after a block of size 12 alloc'd
    ==28110==    at 0x4843CD3: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==28110==    by 0x48824FE: allot (shared.c:90)
    ==28110==    by 0x487F878: markBuffert (buffer.c:302)
    ==28110==    by 0x487F6F6: markBufferc (buffer.c:274)
    ==28110==    by 0x48810FD: makeNode (nodes.c:150)
    ==28110==    by 0x4888BA2: makeText (text.c:169)
    ==28110==    by 0x4888BCE: makeTextc (text.c:172)
    ==28110==    by 0x4888CB9: makeTextt (text.c:188)
    ==28110==    by 0x488B2DE: markTextv (text.c:953)
    ==28110==    by 0x4885B25: cramAchsv (achs.c:307)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==
    src/libbasic/nodes.c:188: EPERM
    tryextra._x86_64_linux_cc_debug.elf: src/libbasic/nodes.c:189: voidNode: Assertion `false' failed.
    ==28110==
    ==28110== Process terminating with default action of signal 6 (SIGABRT): dumping core
    ==28110==    at 0x4904D22: raise (in /usr/lib/libc-2.33.so)
    ==28110==    by 0x48EE861: abort (in /usr/lib/libc-2.33.so)
    ==28110==    by 0x48EE746: __assert_fail_base.cold (in /usr/lib/libc-2.33.so)
    ==28110==    by 0x48FD615: __assert_fail (in /usr/lib/libc-2.33.so)
    ==28110==    by 0x488132A: voidNode (nodes.c:189)
    ==28110==    by 0x487FA8D: voidBuffer (buffer.c:340)
    ==28110==    by 0x4886418: voidDints (dints.c:91)
    ==28110==    by 0x4885C8F: cramAchsv (achs.c:332)
    ==28110==    by 0x488584B: growAchsv (achs.c:264)
    ==28110==    by 0x4885591: initAchsv (achs.c:233)
    ==28110==    by 0x4885293: makeAchsv (achs.c:195)
    ==28110==    by 0x48853AA: makeAchsf (achs.c:208)
    ==28110==
    ==28110== HEAP SUMMARY:
    ==28110==     in use at exit: 1,548 bytes in 20 blocks
    ==28110==   total heap usage: 31 allocs, 11 frees, 11,450 bytes allocated
    ==28110==
    ==28110== LEAK SUMMARY:
    ==28110==    definitely lost: 105 bytes in 2 blocks
    ==28110==    indirectly lost: 0 bytes in 0 blocks
    ==28110==      possibly lost: 0 bytes in 0 blocks
    ==28110==    still reachable: 1,443 bytes in 18 blocks
    ==28110==         suppressed: 0 bytes in 0 blocks
    ==28110== Rerun with --leak-check=full to see details of leaked memory
    ==28110==
    ==28110== For lists of detected and suppressed errors, rerun with: -s
    ==28110== ERROR SUMMARY: 7 errors from 4 contexts (suppressed: 0 from 0)
    make: *** [gnu.mak:49: valgrind] Aborted (core dumped)
    Compilation failed.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It seems to me that what you need is a decent set of module tests so you can thoroughly test all the functions within a given source file before you integrate it with some 50+ other files.

    > not sure where it's coming from yet though:
    valgrind can trigger the debugger (RTFM).

    Meaning you don't have to stare at line 165 of nodes.c and wonder what's going on.
    You can instead directly see the values of all the variables and figure it out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by Salem View Post
    It seems to me that what you need is a decent set of module tests so you can thoroughly test all the functions within a given source file before you integrate it with some 50+ other files.

    > not sure where it's coming from yet though:
    valgrind can trigger the debugger (RTFM).

    Meaning you don't have to stare at line 165 of nodes.c and wonder what's going on.
    You can instead directly see the values of all the variables and figure it out.
    I already looked with gede, I still didn't see what went wrong, I only know that the assert was triggered from a situation that not only should not have occurred but is seemingly impossible, I haven't even started with multi-threading (besides what opengl &/or glfw launches) so I'm certain it's not related to that (even if I had used threads I've got a tested means of locking my objects from being modified by other threads using the same API, likewise with memory allocations, so I'm not concerned with that when I start doing so), the only thing I can think of is that somehow a write somewhere did a bit more than it should or started somewhere it shouldn't of, the problem is finding it, it's likely not directly in the node's or buffer APIs but rather somewhere in the text APIs which I'm working with so if your gonna look then I suggest looking through src/libbasic/buffer/achs.c as the starting file and work your way inwards, if you want to check the integer types I'm using just look in include/basic/number.h, they generally default to the stddef.h/stdint.h equivalents.

  7. #7
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Welp dunno what it was but after changing how I made the Args buffer when I noticed it was still use makeDintsc it stopped complaining about that particular bug, looking at the next bug now

  8. #8
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Dunno how but was somehow initiating the buffers inconsistent with how they're used so I've now switched to calling initBuffer on them after they've been made, also forgot to terminate them when voiding the objects so I fixed that as well. After fixing that and a couple of other bugs I'm left with this:

    Code:
    make valgrind
    ...
    cd ../../bin && valgrind --leak-check=full --show-leak-kinds=all ./tryextra._x86_64_linux_cc_debug.elf -D APP_DATA=../run
    ==34826== Memcheck, a memory error detector
    ==34826== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==34826== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
    ==34826== Command: ./tryextra._x86_64_linux_cc_debug.elf -D APP_DATA=../run
    ==34826==
    ==34826== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
    ==34826==
    ==34826== Process terminating with default action of signal 11 (SIGSEGV): dumping core
    ==34826==  Access not within mapped region at address 0x1FFE801FE8
    ==34826== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
    ==34826==    at 0x487FDD8: initBuffern (buffer.c:391)
    ==34826==  If you believe this happened as a result of a stack
    ==34826==  overflow in your program's main thread (unlikely but
    ==34826==  possible), you can try to increase the size of the
    ==34826==  main thread stack using the --main-stacksize= flag.
    ==34826==  The main thread stack size used in this run was 8388608.
    ==34826==
    ==34826== HEAP SUMMARY:
    ==34826==     in use at exit: 128 bytes in 2 blocks
    ==34826==   total heap usage: 2 allocs, 0 frees, 128 bytes allocated
    ==34826==
    ==34826== 64 bytes in 1 blocks are still reachable in loss record 1 of 2
    ==34826==    at 0x483E899: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==34826==    by 0x488253F: allot (shared.c:90)
    ==34826==    by 0x4882343: makeObject (shared.c:51)
    ==34826==    by 0x4880AB0: makeNodes (nodes.c:23)
    ==34826==    by 0x4880FCB: makeNode (nodes.c:144)
    ==34826==    by 0x10C5F9: main (main.c:117)
    ==34826==
    ==34826== 64 bytes in 1 blocks are still reachable in loss record 2 of 2
    ==34826==    at 0x483E899: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==34826==    by 0x488253F: allot (shared.c:90)
    ==34826==    by 0x4882343: makeObject (shared.c:51)
    ==34826==    by 0x4880B44: makeNodes (nodes.c:37)
    ==34826==    by 0x4880FCB: makeNode (nodes.c:144)
    ==34826==    by 0x10C5F9: main (main.c:117)
    ==34826==
    ==34826== LEAK SUMMARY:
    ==34826==    definitely lost: 0 bytes in 0 blocks
    ==34826==    indirectly lost: 0 bytes in 0 blocks
    ==34826==      possibly lost: 0 bytes in 0 blocks
    ==34826==    still reachable: 128 bytes in 2 blocks
    ==34826==         suppressed: 0 bytes in 0 blocks
    ==34826==
    ==34826== For lists of detected and suppressed errors, rerun with: -s
    ==34826== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    make: *** [../../gnu.mak:50: valgrind] Segmentation fault (core dumped)
    Compilation failed.
    In theory that should be impossible, I'll provide a link in a moment, just gotta upload it

    Edit: src/tryextra/main.c * d17c3419e804b2993ff0a311365e5a50851d03ab * Lee Shallis / Dragonbuilder * GitLab

  9. #9
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Took me way too long to notice there was a segfault, one caused by a silly mistake, had 2 functions calling each other for setup, fixing that got me to my next issue, I'll get some shut eye then look into it 2mw

  10. #10
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    K, a bug I thought went away was actually hidden by other bugs, for now the one that's flumexing me is show with the attached image

    Code:
    SHARED_EXP bool readNextChar( SOURCE *src, WHERE *pos )
    {
    	/* Branchless length extraction */
    	uint len = src->Line->count - !!(src->Line->count), inci, incl;
    	achs line = src->Line->array;
    	dint c = pos->c;
    	/* Branchless index increment */
    	inci = (pos->c && pos->i < len);
    	pos->i += inci;
    	/* No getting round this branch */
    	pos->c = line ? inci * line[pos->i] : 0;
    	/* Branchless line increment */
    	incl = (pos->c == '\f' && !(c == '\n' || c == '\r'));
    	incl = (incl || (pos->c == '\n' && !(c == '\r')));
    	incl = (incl || pos->c == '\r');
    	pos->line += incl;
    	/* Branchless col set */
    	pos->col = !incl * pos->col + 1;
    	/* Branchless stopping point check */
    	return (inci && !incl);
    }
    
    
    SHARED_EXP dint readVersion( void *ud, SOURCE *src )
    {
    	dint err = readNextLine( ud, src );
    
    	src->version = 0;
    
    	if ( err )
    	{
    		SHARED_ECHO_ERRNO( stdout, err );
    		return err;
    	}
    
    	do
    	{
    		ach *line = src->Line->array, *name;
    		WHERE pos = {0};
    
    		/* We don't care about whitespace */
    		while ( readNextChar( src, &pos ) && isspace( pos.c ) );
    
    		/* Not a version directive, ignore it */
    		if ( pos.c != '#' )
    			break;
    
    		/* Again, we don't care about whitespace */
    		while ( readNextChar( src, &pos ) && isspace( pos.c ) );
    
    		name = line + pos.i;
    
    		if ( achsfind( name, "version" ) != name )
    			break;
    
    		/* Get past the name */
    		while ( isalpha( pos.c ) && readNextChar( src, &pos ) );
    
    		/* Yet again we don't care about whitespace */
    		while ( isspace( pos.c ) && readNextChar( src, &pos ) );
    
    		sscanf( line + pos.i, "%lu", &(src->version) );
    		return 0;
    	}
    	while (0);
    
    	src->line = 0;
    	src->ins = 0;
    	src->pos = 0;
    
    	return 0;
    }
    I've not spotted the cause yet, any ideas why readNextChar is failing to get the 1st character?
    Attached Images Attached Images Node functions not quite working as expected-screenshot-2022-02-20-14-26-57-jpg 

  11. #11
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Fixed it removing the "inci *" from the "pos->c =" line of readNextChar, version is now read as expected, #line command is not ending up in the correct place though, I'll have to investigate why on that

  12. #12
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    *face palm* the segfault that kept occuring at the end was because of a double call of termVfxDbg which is accompanied by a double call of termVfxVai, the 2nd being expected and accounted for, now that I expect termVfxDbg to be potentially be called twice I've added a branch that steers away from calling a NULL'd function pointer (caused by a call to termVfxVai), segfault disappeared after that, now I just gotta investigate the opengl related errors

  13. #13
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Welp turned out the majority of the errors I was seeing was because the program wasn't linked which in turn turned out to be down to readNextLine returning false on the 1st character which in turn was because readNextChar was doing likewise, after investigating and fixing those issues I'm now finding that readNextLine isn't quite working as intended, it should leave src->ins at the start of the current line, src->nxt should be the start of the next line which src->ins gets set to on the next call, somehow the src->nxt ends up in the wrong position sometimes (1 behind where it should be), causing reliant code to miss the lines it's looking for, I've not spotted the source of the problem yet so I'd like some help in doing so, here's the relevant code and input file, perhaps someone here can spot what I'm not.

    Code:
    SHARED_EXP bool readNextChar( ACHS *Text, WHERE *pos )
    {
    	/* Branchless length extraction */
    	uint len = Text->count - !!(Text->count), inc = 0;
    	achs text = Text->array;
    	pos->p = pos->c;
    	/* Branchless index increment */
    	pos->i += (pos->c && pos->i < len);
    	/* No getting round this branch */
    	pos->c = text ? text[pos->i] : 0;
    	/* Branchless line increment */
    	inc = (pos->c == '\f' && !(pos->p == '\n' || pos->p == '\r'));
    	inc = (inc || (pos->c == '\n' && !(pos->p == '\r')));
    	inc = (inc || pos->c == '\r');
    	pos->line += inc;
    	/* Branchless col set */
    	pos->col = !inc * (pos->col + 1);
    	/* Branchless stopping point check */
    	return (pos->c && !inc);
    }
    
    SHARED_EXP bool readNextLine( void *ud, SOURCE *src )
    {
    	ACHS *Text = src->Text;
    	WHERE pos = src->nxt;
    
    	(void)ud;
    
    	/* Start of line */
    	src->ins = pos;
    
    	while ( readNextChar( Text, &pos ) );
    
    	/* End of line */
    	src->pos = pos;
    
    	/* Ensure the next call starts after the new line character */
    	while ( isnewline( pos.c ) && readNextChar( Text, &pos ) );
    
    	/* Start of next line */
    	src->nxt = pos;
    
    	return (src->ins.i < pos.i);
    }
    ...
    	while ( readNextLine( ud, &src ) )
    	{
    		uint not0 = src.pos.i - src.ins.i;
    		ach *line = temp + src.ins.i, *init = NULL, *term = NULL;
    
    		if ( achsifind( line, "[vfxapp." ) != line )
    			continue;
    
    		init = (ach*)achscharn( line, not0, '.' );
    		term = (ach*)achscharn( line, not0, ']' );
    		name = init + 1;
    		*term = 0;
    
    		if ( _name && achsicmp( name, _name ) )
    		{
    			name = NULL;
    			*term = ']';
    			continue;
    		}
    
    		printf( "Creating program '%s'\n", name );
    		*term = ']';
    		break;
    	}
    
    	if ( !name )
    	{
    		err = ENODATA;
    		SHARED_ECHO_ERRNO( stdout, err );
    		return err;
    	}
    ...
    Code:
    [vfxapp]
    ! This is an example, it will not be processed
    share=share.glsl
    other=other.glsl
    point=point.glsl
    ! Geometry shaders deal with primitives (lines, points & triangles) instead of
    ! general shapes as the name leads one to believe, apparently we can blame
    ! Microsoft for the stupid name
    basic=shape.glsl
    tctrl=tctrl.glsl
    teval=teval.glsl
    color=color.glsl
    
    ![vfxapp.spec]
    !share=same.glsl
    !point=spec.glsl
    !color=frag.glsl
    
    [vfxapp.flat]
    share=same.glsl
    point=spec.glsl
    color=frag.glsl
    
    ![vfxapp.dome]
    !share=same.glsl
    !point=dome.glsl
    !color=frag.glsl

  14. #14
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    I think I fixed it, at the very least the initial file is now read correctly, this is what I now have:

    Code:
    SHARED_EXP bool readNextChar( ACHS *Text, WHERE *pos )
    {
    	/* Branchless length extraction */
    	uint not0 = Text->count - !!(Text->count), inc = 0;
    	achs text = Text->array;
    	pos->p = pos->c;
    	/* We're not supposed to start with line 0 */
    	pos->line += (pos->line == 0);
    	/* Branchless index increment */
    	pos->i += (pos->c && pos->i < not0);
    	/* No getting round this branch */
    	pos->c = text ? text[pos->i] : 0;
    	/* Branchless line increment */
    	inc = (pos->c == '\f' && !(pos->p == '\n' || pos->p == '\r'));
    	inc = (inc || (pos->c == '\n' && !(pos->p == '\r')));
    	inc = (inc || pos->c == '\r');
    	pos->line += inc;
    	/* Branchless col set */
    	pos->col = !inc * (pos->col + 1);
    	/* Branchless stopping point check */
    	return (pos->c && !inc);
    }
    
    SHARED_EXP bool readNextLine( void *ud, SOURCE *src )
    {
    	ACHS *Text = src->Text;
    	WHERE pos = src->pos;
    
    	(void)ud;
    
    	/* Start of line */
    	src->ins = pos;
    
    	while ( readNextChar( Text, &pos ) );
    
    	/* End of line */
    	src->pos = pos;
    
    	/* Ensure the line starts after the new line character */
    	while
    	(
    		pos.i - src->ins.i
    		&& readNextChar( Text, &(src->ins) )
    		&& isnewline( src->ins.c )
    	);
    
    	src->ins.col = 0;
    	return !!(pos.c);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program not working as expected
    By xants in forum C Programming
    Replies: 18
    Last Post: 07-03-2016, 12:30 AM
  2. && not working as expected
    By TonyBalony in forum C Programming
    Replies: 4
    Last Post: 12-14-2011, 12:30 PM
  3. Multithreading not working as expected
    By shiroaisu in forum Windows Programming
    Replies: 5
    Last Post: 06-18-2011, 02:34 AM
  4. IntersectRect() not working as expected?
    By dxfoo in forum Windows Programming
    Replies: 1
    Last Post: 09-05-2006, 04:52 PM
  5. cin.get(); doesn't seem to be working as expected
    By Diablo84 in forum C++ Programming
    Replies: 5
    Last Post: 03-30-2005, 07:00 PM

Tags for this Thread