[DGD]string reference/swapout problems

Marc Spoorendonk marc at freud.et.tudelft.nl
Fri Mar 5 20:33:09 CET 1999


# ifndef FUNCDEF
# include "kfun.h"

string *R_errstr=0;	// error string

# endif

# ifdef FUNCDEF
FUNCDEF("set_errstr", kf_set_errstr, pt_set_errstr)
# else
char pt_set_errstr[] = { C_TYPECHECKED | C_STATIC, T_VOID, 1, T_STRING };

int kf_set_errstr()
{
    if(R_errstr) {
	str_del(R_errstr);
    }
    str_ref(R_errstr=sp->u.string);
    return 0;
}
#endif

# ifdef FUNCDEF
FUNCDEF("get_errstr", kf_get_errstr, pt_get_errstr)
# else
char pt_get_errstr[] = { C_STATIC, T_STRING, 0 };

int kf_get_errstr()
{
    sp--;
    if(!R_errstr) {
       sp->type=T_INT;
       sp->u.number=0;
       return 0;
    }
    sp->type=T_STRING;
    str_ref(sp->u.string=R_errstr);
    return 0;
}
#endif

//----------------------------------------------------------------------

Hi,

I have attempted to code a really simple piece of code: A global errstr
string which can be shown to the coder when a function returns an error
state.

What I want is:
void set_errstr(string error_string);	// stores a string into the driver
string get_errstr();			// retrieves the string

Ofcourse this can be done with a str_new() but i thought that it should be
possible to store just a pointer to the string in the driver. (see the
paste of the source code) This works fine but when i force a swapout, the
string gets swapped out and we get stuck with a string pointer which
points into unknown space.

My question is: Is there a way to prevent the string from being swapped
out?

And the general question: When do i need to str_ref() or str_del() when
using strings in kfuns? 

I hope that you can make this matter a bit more clear to me. (Or point me
a manual about it.)

--
Marc Spoorendonk
Department of Electrical Engineering
Delft University of Technology

e-mail			: Marc at freud.et.tudelft.nl
mud			: telnet://freud.et.tudelft.nl:8888
URL			: http://freud.et.tudelft.nl/~marc/index.html


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list