Info Patch 1.9.29: gbx_value.c

Fragen und Informationen zur Installation von Gambas
Antworten
rammelteid
Foriker
Beiträge: 18
Registriert: Mo 3. Apr 2006, 11:31
Kontaktdaten:

Info Patch 1.9.29: gbx_value.c

Beitrag von rammelteid » Di 25. Apr 2006, 14:05

Nicht mehr ganz taufrisch, für den, der das User-Digest nicht abonniert hat:

--__--__--

Message: 6
From: Benoit Minisini <gambas@users.sourceforge.net>
To: gambas-user@lists.sourceforge.net
Date: Fri, 21 Apr 2006 21:16:10 +0200
Subject: [Gambas-user] Stupid bug in 1.9.29
Reply-To: gambas-user@lists.sourceforge.net

--Boundary-00=_69SSEs8i+DsnV0W
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

There is a stupid bug in the Val() function in 1.9.29: Val("True") or
Val("False") always returns NULL instead of returning their corresponding
boolean values.

Here is a patch, and sorry for the inconvenience!

Regards,

--
Benoit Minisini

--Boundary-00=_69SSEs8i+DsnV0W
Content-Type: text/x-csrc;
charset="us-ascii";
name="gbx_value.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="gbx_value.c"

/***************************************************************************

value.c

Datatype management routines. Conversions between each Gambas datatype,
and conversions between Gambas datatypes and native datatypes.

(c) 2000-2005 Beno=EF=BF=BD Minisini <gambas@users.sourceforge.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

***************************************************************************/


#include <float.h>
#include <math.h>
#include <limits.h>

#include "gb_common.h"
#include "gb_common_case.h"

#include "gbx_math.h"
#include "gbx_type.h"

#include "gbx_array.h"
#include "gbx_string.h"
#include "gbx_number.h"
#include "gbx_object.h"
#include "gbx_variant.h"
#include "gbx_date.h"

#include "gbx_exec.h"
#include "gbx_local.h"
#include "gb_common_buffer.h"

#include "gbx_value.h"


/* This function must keep the datatype, as it is used for initializing loc=
al variables */

PUBLIC void VALUE_default(VALUE *value, TYPE type)
{
static void *jump[16] =3D {
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__=
SINGLE, &&__FLOAT, &&__DATE,
&&__STRING, &&__STRING, &&__VARIANT, &&__ARRAY, &&__FUNCTION, &&__CLASS=
, &&__NULL
};

value->type =3D type;

if (TYPE_is_object(type))
goto __OBJECT;
else
goto *jump[type];

__BOOLEAN:
__BYTE:
__SHORT:
__INTEGER:

value->_integer.value =3D 0;
return;

__LONG:

value->_long.value =3D 0;
return;

__SINGLE:
__FLOAT:
value->_float.value =3D 0;
return;

__STRING:
value->_string.addr =3D NULL;
value->_string.start =3D 0;
value->_string.len =3D 0;
return;

__VARIANT:
value->_variant.vtype =3D T_NULL;
return;

__DATE:
value->_date.date =3D 0;
value->_date.time =3D 0;
return;

__VOID:
return;

__OBJECT:
value->_object.class =3D (CLASS *)type;
value->_object.object =3D NULL;
return;

__ARRAY:
__FUNCTION:
__CLASS:
__NULL:
ERROR_panic("VALUE_default: Unknown default type");
}


PUBLIC void VALUE_convert(VALUE *value, TYPE type)
{
static void *jump[16][16] =3D
{
/* void b c h i l =
g f d cs s v =
array func class n */
/* void */ { &&__OK, &&__NR, &&__NR, &&__NR, &&__NR, &&=
__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, =
&&__NR, &&__NR, &&__NR, &&__NR, },
/* b */ { &&__N, &&__OK, &&__b2c, &&__b2h, &&__TYPE, &&=
__b2l, &&__b2f, &&__b2f, &&__N, &&__b2s, &&__b2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* c */ { &&__N, &&__c2b, &&__OK, &&__c2h, &&__TYPE, &&=
__c2l, &&__c2f, &&__c2f, &&__c2d, &&__c2s, &&__c2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* h */ { &&__N, &&__h2b, &&__h2c, &&__OK, &&__TYPE, &&=
__h2l, &&__h2f, &&__h2f, &&__h2d, &&__h2s, &&__h2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* i */ { &&__N, &&__i2b, &&__i2c, &&__i2h, &&__OK, &&=
__i2l, &&__i2f, &&__i2f, &&__i2d, &&__i2s, &&__i2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* l */ { &&__N, &&__l2b, &&__l2c, &&__l2h, &&__l2i, &&=
__OK, &&__l2g, &&__l2f, &&__l2d, &&__l2s, &&__l2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* g */ { &&__N, &&__f2b, &&__f2c, &&__f2h, &&__f2i, &&=
__f2l, &&__OK, &&__TYPE, &&__f2d, &&__f2s, &&__g2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* f */ { &&__N, &&__f2b, &&__f2c, &&__f2h, &&__f2i, &&=
__f2l, &&__f2g, &&__OK, &&__f2d, &&__f2s, &&__f2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* d */ { &&__N, &&__d2b, &&__d2c, &&__d2h, &&__d2i, &&=
__d2l, &&__d2f, &&__d2f, &&__OK, &&__d2s, &&__d2s, &&__2v, =
&&__N, &&__N, &&__N, &&__N, },
/* cs */ { &&__N, &&__s2b, &&__s2c, &&__s2h, &&__s2i, &&=
__s2l, &&__s2f, &&__s2f, &&__s2d, &&__OK, &&__OK, &&__s2v, =
&&__N, &&__N, &&__N, &&__N, },
/* s */ { &&__N, &&__s2b, &&__s2c, &&__s2h, &&__s2i, &&=
__s2l, &&__s2f, &&__s2f, &&__s2d, &&__OK, &&__OK, &&__s2v, =
&&__N, &&__N, &&__N, &&__N, },
/* v */ { &&__N, &&__v2, &&__v2, &&__v2, &&__v2, &&=
__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__OK, =
&&__N, &&__N, &&__N, &&__v2, },
/* array */ { &&__N, &&__N, &&__N, &&__N, &&__N, &&=
__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, =
&&__OK, &&__N, &&__N, &&__N, },
/* func */ { &&__N, &&__N, &&__N, &&__N, &&__N, &&=
__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, =
&&__N, &&__OK, &&__N, &&__N, },
/* class */ { &&__N, &&__N, &&__N, &&__N, &&__N, &&=
__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, =
&&__N, &&__N, &&__OK, &&__N, },
/* null */ { &&__N, &&__n2b, &&__N, &&__N, &&__N, &&=
__N, &&__N, &&__N, &&__n2d, &&__n2s, &&__n2s, &&__2v, =
&&__N, &&__N, &&__N, &&__OK, },
};

long len;
char *addr;
long index;
CLASS *class;
boolean test;

__CONV:

if ((type | value->type) >> 4)
goto __OBJECT;
else
goto *jump[value->type][type];

__c2b:
__h2b:
__i2b:

value->_integer.value =3D (value->_integer.value !=3D 0) ? -1 : 0;
goto __TYPE;

__l2b:

value->_integer.value =3D (value->_long.value !=3D 0) ? -1 : 0;
goto __TYPE;

__f2b:

value->_integer.value =3D (value->_float.value !=3D 0) ? -1 : 0;
goto __TYPE;

__d2b:
value->_integer.value =3D (value->_date.date !=3D 0 || value->_date.time =
!=3D 0) ? -1 : 0;
goto __TYPE;

__b2c:
__h2c:
__i2c:

value->_integer.value =3D (unsigned char)value->_integer.value;
goto __TYPE;

__l2c:

value->_integer.value =3D (unsigned char)value->_long.value;
goto __TYPE;

__f2c:

value->_integer.value =3D (unsigned char)value->_float.value;
goto __TYPE;

__b2h:
__c2h:
__i2h:

value->_integer.value =3D (short)value->_integer.value;
goto __TYPE;

__l2h:

value->_integer.value =3D (short)value->_long.value;
goto __TYPE;

__f2h:

value->_integer.value =3D (short)value->_float.value;
goto __TYPE;

__l2i:

value->_long.value =3D (long)value->_long.value;
goto __TYPE;

__f2i:

value->_integer.value =3D (long)value->_float.value;
goto __TYPE;

__b2l:
__c2l:
__h2l:
__i2l:

value->_long.value =3D (long long)value->_integer.value;
goto __TYPE;

__f2l:

value->_long.value =3D (long long)value->_float.value;
goto __TYPE;

__l2g:

value->_float.value =3D (float)value->_long.value;
if (!finite(value->_float.value))
THROW(E_OVERFLOW);
goto __TYPE;

__f2g:

value->_float.value =3D (float)value->_float.value;
if (!finite(value->_float.value))
THROW(E_OVERFLOW);
goto __TYPE;

__b2f:
__c2f:
__h2f:
__i2f:

value->_float.value =3D value->_integer.value;
goto __TYPE;

__l2f:

value->_float.value =3D value->_long.value;
goto __TYPE;

__c2d:
__h2d:
__i2d:

value->_date.date =3D Max(0, value->_integer.value);
value->_date.time =3D 0;
goto __TYPE;

__l2d:

if (value->_long.value < 0)
value->_date.date =3D 0;
else if (value->_long.value > LONG_MAX)
value->_date.date =3D LONG_MAX;
else
value->_date.date =3D (long)value->_long.value;

value->_date.time =3D 0;
goto __TYPE;

__f2d:

index =3D (long)fix(value->_float.value);
value->_date.time =3D (long)((value->_float.value - index) * 86400000.0 +=
0.5);
value->_date.date =3D index;
goto __TYPE;

__d2c:
__d2h:
__d2i:

value->_integer.value =3D value->_date.date;
value->type =3D T_INTEGER;
goto *jump[T_INTEGER][type];

__d2l:

value->_long.value =3D value->_date.date;
goto __TYPE;

__d2f:

value->_float.value =3D (double)value->_date.date + (double)value->_date.=
time / 86400000.0;
goto __TYPE;

__b2s:

if (value->_boolean.value)
STRING_char_value(value, 'T');
else
STRING_void_value(value);
return;

__c2s:
__h2s:
__i2s:

len =3D sprintf(COMMON_buffer, "%ld", value->_integer.value);
STRING_new_temp_value(value, COMMON_buffer, len);
BORROW(value);
return;

__l2s:

len =3D sprintf(COMMON_buffer, "%lld", value->_long.value);
STRING_new_temp_value(value, COMMON_buffer, len);
BORROW(value);
return;

__g2s:
__f2s:

LOCAL_format_number(value->_float.value, LF_GENERAL_NUMBER, NULL, 0, &add=
r, &len, FALSE);
STRING_new_temp_value(value, addr, len);
BORROW(value);
return;

__d2s:

len =3D DATE_to_string(COMMON_buffer, value);
STRING_new_temp_value(value, COMMON_buffer, len);
BORROW(value);
return;

__s2b:

addr =3D value->_string.addr;
value->_integer.value =3D ((addr !=3D NULL) && (value->_string.len !=3D 0=
)) ? -1 : 0;
if (value->type =3D=3D T_STRING)
STRING_unref(&addr);
goto __TYPE;

__s2c:
__s2h:
__s2i:

addr =3D value->type =3D=3D T_STRING ? value->_string.addr : NULL;

if (NUMBER_from_string(NB_READ_INTEGER, value->_string.addr + value->_str=
ing.start, value->_string.len, value))
goto __N;

STRING_unref(&addr);
goto *jump[T_INTEGER][type];

__s2l:

addr =3D value->type =3D=3D T_STRING ? value->_string.addr : NULL;

if (NUMBER_from_string(NB_READ_LONG, value->_string.addr + value->_string=
=2Estart, value->_string.len, value))
goto __N;

STRING_unref(&addr);
return;

__s2f:

addr =3D value->type =3D=3D T_STRING ? value->_string.addr : NULL;

if (NUMBER_from_string(NB_READ_FLOAT, value->_string.addr + value->_strin=
g.start, value->_string.len, value))
goto __N;

STRING_unref(&addr);
return;

__s2d:

addr =3D value->type =3D=3D T_STRING ? value->_string.addr : NULL;

if (DATE_from_string(value->_string.addr + value->_string.start, value->_=
string.len, value, FALSE))
goto __N;

STRING_unref(&addr);
return;

__n2b:

value->_integer.value =3D 0;
goto __TYPE;

__n2d:

DATE_void_value(value);
return;

__n2s:

STRING_void_value(value);
return;

__v2:

/* ATTENTION !
VALUE_read sert normalement =EF=BF=BDlire un stockage en m=EF=BF=BDoire.
On le d=EF=BF=BDourne ici pour convertir le variant.
Mais si le variant contient un T_STRING, =EF=BF=BD doit rester un T_STR=
ING ! */

index =3D value->_variant.vtype;

if (index !=3D T_NULL)
VALUE_read(value, &value->_variant.value, value->_variant.vtype);
value->type =3D index;

goto __CONV;

__s2v:

STRING_copy_from_value_temp(&addr, value);

if (addr !=3D value->_string.addr)
{
STRING_ref(addr);

if (value->type =3D=3D T_STRING)
STRING_unref(&value->_string.addr);
}

*((char **)value->_variant.value) =3D addr;

value->_variant.vtype =3D T_STRING;

goto __TYPE;

__2v:

/* VALUE_put ne fonctionne pas avec T_STRING ! */
if (value->type !=3D T_NULL)
VALUE_put(value, &value->_variant.value, value->type);

value->_variant.vtype =3D value->type;
goto __TYPE;

__OBJECT:

if (!TYPE_is_object(type))
{
if (type =3D=3D T_BOOLEAN)
{
test =3D (value->_object.object !=3D NULL);
OBJECT_UNREF(&value->_object.object, "VALUE_convert");
value->_boolean.value =3D test ? -1 : 0;
goto __TYPE;
}

if (type =3D=3D T_VARIANT)
goto __2v;

goto __N;
}

if (!TYPE_is_object(value->type))
{
if (value->type =3D=3D T_NULL)
{
OBJECT_null(value, (CLASS *)type); /* marche aussi pour type =3D T_OB=
JECT */
goto __TYPE;
}

if (value->type =3D=3D T_VARIANT)
goto __v2;

if (value->type =3D=3D T_CLASS)
{
class =3D value->_class.class;
CLASS_load(class);

if (class->auto_create)
value->_object.object =3D CLASS_auto_create(class, 0);
else
value->_object.object =3D class;

OBJECT_REF(value->_object.object, "VALUE_convert");
value->type =3D T_OBJECT;
/* on continue... */
}
else
goto __N;

}

if (value->type =3D=3D T_OBJECT)
{
if (value->_object.object =3D=3D NULL)
goto __TYPE;

class =3D OBJECT_class(value->_object.object);
/* on continue */
}
else
class =3D value->_object.class;

if (CLASS_is_virtual(class))
THROW(E_VIRTUAL);

if (type =3D=3D T_OBJECT)
goto __TYPE;

__RETRY:

if ((class =3D=3D (CLASS *)type) || CLASS_inherits(class, (CLASS *)type))
goto __TYPE;

if (value->type !=3D T_OBJECT && value->_object.object)
{
class =3D OBJECT_class(value->_object.object);
value->type =3D T_OBJECT;
goto __RETRY;
}


THROW(E_TYPE, TYPE_get_name(type), TYPE_get_name((TYPE)class));

__TYPE:

value->type =3D type;

__OK:

return;

__N:

THROW(E_TYPE, TYPE_get_name(type), TYPE_get_name(value->type));

__NR:

THROW(E_NRETURN);
}



PUBLIC void VALUE_write(VALUE *value, void *addr, TYPE type)
{
static void *jump[16] =3D {
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__=
SINGLE, &&__FLOAT, &&__DATE,
&&__STRING, &&__STRING, &&__VARIANT, &&__ARRAY, &&__FUNCTION, &&__CLASS=
, &&__NULL
};

char *str;

__CONV:

if (TYPE_is_object(type))
goto __OBJECT;
else
goto *jump[type];

__BOOLEAN:

VALUE_conv(value, type);
*((unsigned char *)addr) =3D (value->_boolean.value !=3D 0 ? 255 : 0);
return;

__BYTE:

VALUE_conv(value, type);
*((unsigned char *)addr) =3D (unsigned char)(value->_byte.value);
return;

__SHORT:

VALUE_conv(value, type);
*((short *)addr) =3D (short)(value->_short.value);
return;

__INTEGER:

VALUE_conv(value, type);
*((long *)addr) =3D value->_integer.value;
return;

__LONG:

VALUE_conv(value, type);
*((long long *)addr) =3D value->_long.value;
return;

__SINGLE:

VALUE_conv(value, type);
*((float *)addr) =3D (float)value->_float.value;
return;

__FLOAT:

VALUE_conv(value, type);
*((double *)addr) =3D value->_float.value;
return;

__DATE:

VALUE_conv(value, type);
((long *)addr)[0] =3D value->_date.date;
((long *)addr)[1] =3D value->_date.time;
return;

__STRING:

/* Il faut faire l'affectation en deux temps au cas o
value->_string.addr =3D=3D *addr ! */

VALUE_conv(value, type);

STRING_copy_from_value_temp(&str, value);
STRING_ref(str);
STRING_unref((char **)addr);
*((char **)addr) =3D str;
return;

__OBJECT:

VALUE_conv(value, type);

OBJECT_REF(value->_object.object, "VALUE_write");
OBJECT_UNREF(((void **)addr), "VALUE_write");
*((void **)addr) =3D value->_object.object;
return;

__VARIANT:

VARIANT_undo(value);

type =3D value->type;
if (type =3D=3D T_CSTRING)
type =3D T_STRING;

VARIANT_clear((VARIANT *)addr);

((VARIANT *)addr)->type =3D type;

/* Et si type ne fait pas partie des types valides pour cette fonction ??=
*/
if (type =3D=3D T_NULL)
return;

addr =3D ((VARIANT *)addr)->value;
/*goto *jump[Min(T_OBJECT, type)];*/
goto __CONV;

/*
{
VARIANT *var =3D ((VARIANT *)addr);

VARIANT_free(var);

var->type =3D value->_variant.vtype;
VARIANT_copy(value->_variant.value, var->value);

if (TYPE_is_object(var->type))
OBJECT_$ref(*((void **)var->value));

return;
}
*/

__VOID:
__ARRAY:
__FUNCTION:
__CLASS:
__NULL:

ERROR_panic("Bad type (%d) for VALUE_write", type);
}



PUBLIC void VALUE_read(VALUE *value, void *addr, TYPE type)
{
static void *jump[16] =3D {
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__=
SINGLE, &&__FLOAT, &&__DATE,
&&__STRING, &&__CSTRING, &&__VARIANT, &&__ARRAY, &&__FUNCTION, &&__CLAS=
S, &&__NULL
};

char *str;

value->type =3D type;

if (TYPE_is_object(type))
goto __OBJECT;
else
goto *jump[type];

__BOOLEAN:

value->_boolean.value =3D (*((unsigned char *)addr) !=3D 0) ? (-1) : 0;
return;

__BYTE:

value->_byte.value =3D *((unsigned char *)addr);
return;

__SHORT:

value->_short.value =3D *((short *)addr);
return;

__INTEGER:

value->_integer.value =3D *((long *)addr);
return;

__LONG:

value->_long.value =3D *((long long *)addr);
return;

__SINGLE:

value->_single.value =3D *((float *)addr);
return;

__FLOAT:

value->_float.value =3D *((double *)addr);
return;

__DATE:

value->_date.date =3D ((long *)addr)[0];
value->_date.time =3D ((long *)addr)[1];
return;

__STRING:

str =3D *((char **)addr);

value->type =3D T_STRING;
value->_string.addr =3D str;
value->_string.start =3D 0;
/*value->_string.len =3D (str =3D=3D NULL) ? 0 : strlen(str);*/
value->_string.len =3D STRING_length(str);

return;

__CSTRING:

str =3D *((char **)addr);

value->type =3D T_CSTRING;
value->_string.addr =3D str;
value->_string.start =3D 0;
value->_string.len =3D (str =3D=3D NULL) ? 0 : strlen(str);
/*value->_string.len =3D STRING_length(str);*/

return;

__OBJECT:

value->_object.object =3D *((void **)addr);
return;

__VARIANT:

value->_variant.type =3D T_VARIANT;
value->_variant.vtype =3D ((VARIANT *)addr)->type;

/*if (value->_variant.vtype =3D=3D T_STRING)
value->_variant.vtype =3D T_STRING;
else*/ if (value->_variant.vtype =3D=3D T_VOID)
value->_variant.vtype =3D T_NULL;

VARIANT_copy(((VARIANT *)addr)->value, value->_variant.value);

return;

__VOID:
__ARRAY:
__CLASS:
__FUNCTION:
__NULL:

ERROR_panic("Bad type (%d) for VALUE_read", type);
}


/* Retourne TRUE s'il y a eu besoin d'allouer qqch */

/*
#define MAX_FREE_PTR 64

static int free_count =3D 0;
static void *free_ptr[MAX_FREE_PTR];


static void add_free_ptr(void *ptr)
{
if (free_count >=3D MAX_FREE_PTR)
ERROR_panic("VALUE_put: too many pointers to free");

free_ptr[free_count] =3D ptr;
free_count++;
}

PUBLIC void VALUE_put_free(void)
{
int i;

for (i =3D 0; i < free_count; i++)
STRING_free((char **)&free_ptr[i]);

free_count =3D 0;
}

PUBLIC void VALUE_put_forget(void)
{
free_count =3D 0;
}
*/

PUBLIC void VALUE_put(VALUE *value, void *addr, TYPE type)
{
static void *jump[16] =3D {
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__=
SINGLE, &&__FLOAT, &&__DATE,
&&__STRING, &&__STRING, &&__VARIANT, &&__ARRAY, &&__FUNCTION, &&__CLASS=
, &&__NULL
};

VALUE_conv(value, type);

if (TYPE_is_object(type))
goto __OBJECT;
else
goto *jump[type];

__BOOLEAN:

*((unsigned char *)addr) =3D (value->_boolean.value !=3D 0 ? 255 : 0);
return;

__BYTE:

*((unsigned char *)addr) =3D (unsigned char)(value->_byte.value);
return;

__SHORT:

*((short *)addr) =3D (short)(value->_short.value);
return;

__INTEGER:

*((long *)addr) =3D value->_integer.value;
return;

__LONG:

*((long long *)addr) =3D value->_long.value;
return;

__SINGLE:

*((float *)addr) =3D (float)value->_float.value;
return;

__FLOAT:

*((double *)addr) =3D value->_float.value;
return;

__DATE:

/* Inverser au cas o value ~=3D addr */

((long *)addr)[1] =3D value->_date.time;
((long *)addr)[0] =3D value->_date.date;
return;

__STRING:

((long *)addr)[0] =3D (long)(value->_string.addr + value->_string.start);
((long *)addr)[1] =3D value->_string.len;
return;

__OBJECT:

*((void **)addr) =3D value->_object.object;
return;

__VARIANT:

*((VARIANT *)addr) =3D *((VARIANT *)&value->_variant.vtype);
return;

/*
if
type =3D value->type;

((VARIANT *)addr)->type =3D type;
addr =3D ((VARIANT *)addr)->value;
goto __CONV;
*/

__VOID:
__ARRAY:
__CLASS:
__FUNCTION:
__NULL:

ERROR_panic("Bad type (%d) for VALUE_put", type);
}


PUBLIC void VALUE_free(void *addr, TYPE type)
{
if (type =3D=3D T_STRING)
{
STRING_unref((char **)addr);
*((char **)addr) =3D NULL;
}
else if (TYPE_is_object(type))
{
OBJECT_unref((void **)addr);
*((void **)addr) =3D NULL;
}
else if (type =3D=3D T_VARIANT)
{
VARIANT_free((VARIANT *)addr);
((VARIANT *)addr)->type =3D T_NULL;
}
}



PUBLIC void VALUE_to_string(VALUE *value, char **addr, long *len)
{
static void *jump[16] =3D {
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__=
SINGLE, &&__FLOAT, &&__DATE,
&&__STRING, &&__STRING, &&__VARIANT, &&__ARRAY, &&__FUNCTION, &&__CLASS=
, &&__NULL
};

__CONV:

if (TYPE_is_object(value->type))
goto __OBJECT;
else
goto *jump[value->type];

__NULL:

*addr =3D ""; /* Pour =EF=BF=BDre coh=EF=BF=BDent avec print "" puisque N=
ull =3D=3D "" */
*len =3D 0;
return;

__BOOLEAN:

if (value->_boolean.value)
{
*addr =3D "True";
*len =3D 4;
}
else
{
*addr =3D "False";
*len =3D 5;
}
return;

__BYTE:
__SHORT:
__INTEGER:

*len =3D sprintf(COMMON_buffer, "%ld", value->_integer.value);
*addr =3D COMMON_buffer;

return;

__LONG:

*len =3D sprintf(COMMON_buffer, "%lld", value->_long.value);
*addr =3D COMMON_buffer;

return;

__DATE:


LOCAL_format_date(DATE_split(value), LF_STANDARD, NULL, 0, addr, len);
return;

__SINGLE:
__FLOAT:

LOCAL_format_number(value->_float.value, LF_STANDARD, NULL, 0, addr, len,=
TRUE);
return;

__STRING:

*len =3D value->_string.len;
*addr =3D value->_string.addr + value->_string.start;
return;

__OBJECT:

if (VALUE_is_null(value))
goto __NULL;

*len =3D sprintf(COMMON_buffer, "(%s %p)", OBJECT_class(value->_object.ob=
ject)->name, value->_object.object);
*addr =3D COMMON_buffer;
return;

__VARIANT:

VARIANT_undo(value);
goto __CONV;

__VOID:

THROW(E_NRETURN);

__CLASS:

*len =3D sprintf(COMMON_buffer, "(Class %s)", OBJECT_class((OBJECT *)valu=
e->_class.class)->name);
*addr =3D COMMON_buffer;
return;

__ARRAY:
__FUNCTION:

*len =3D sprintf(COMMON_buffer, "(%s ?)", TYPE_get_name(value->type));
*addr =3D COMMON_buffer;

/*THROW(E_TYPE, TYPE_get_name(T_STRING), TYPE_get_name(value->type));*/
}


PUBLIC void VALUE_from_string(VALUE *value, const char *addr, long len)
{
value->type =3D T_NULL;

if (!len || *addr =3D=3D 0)
return;

if (!DATE_from_string(addr, len, value, TRUE))
return;

if (!NUMBER_from_string(NB_READ_ALL | NB_READ_HEX_BIN | NB_LOCAL, addr, l=
en, value))
return;

if (len =3D=3D 4 && strncasecmp(addr, "true", len) =3D=3D 0)
{
value->type =3D T_BOOLEAN;
value->_boolean.value =3D -1;
return;
}

if (len =3D=3D 5 && strncasecmp(addr, "false", len) =3D=3D 0)
{
value->type =3D T_BOOLEAN;
value->_boolean.value =3D 0;
return;
}
}


PUBLIC void VALUE_class_read(CLASS *class, VALUE *value, char *addr, CTYPE =
ctype)
{
if (ctype.id =3D=3D T_OBJECT)
{
VALUE_read(value, addr, (ctype.value >=3D 0) ? (TYPE)class->load->class=
_ref[ctype.value] : T_OBJECT);
}
else if (ctype.id =3D=3D T_ARRAY)
{
value->type =3D T_ARRAY;
value->_array.desc =3D class->load->array[ctype.value];
value->_array.addr =3D addr;
}
else
VALUE_read(value, addr, (TYPE)ctype.id);
}


PUBLIC void VALUE_class_write(CLASS *class, VALUE *value, char *addr, CTYPE=
ctype)
{
if (ctype.id =3D=3D T_OBJECT)
{
VALUE_write(value, addr, (ctype.value >=3D 0) ? (TYPE)class->load->clas=
s_ref[ctype.value] : T_OBJECT);
}
else if (ctype.id =3D=3D T_ARRAY)
{
THROW(E_UNKNOWN);
}
else
VALUE_write(value, addr, (TYPE)ctype.id);
}


PUBLIC void VALUE_class_default(CLASS *class, VALUE *value, CTYPE ctype)
{
if (ctype.id =3D=3D T_OBJECT)
{
VALUE_default(value, (ctype.value >=3D 0) ? (TYPE)class->load->class_re=
f[ctype.value] : T_OBJECT);
}
else if (ctype.id =3D=3D T_ARRAY)
{
value->type =3D T_ARRAY;
value->_array.desc =3D class->load->array[ctype.value];
value->_array.keep =3D FALSE;
ARRAY_new(&value->_array.addr, (ARRAY_DESC *)value->_array.desc);
}
else
VALUE_default(value, (TYPE)ctype.id);
}


PUBLIC void VALUE_class_constant(CLASS *class, VALUE *value, int ind)
{
static void *jump[] =3D
{
&&__ILLEGAL, &&__INTEGER, &&__INTEGER, &&__INTEGER, &&__INTEGER, &&__LO=
NG, &&__FLOAT, &&__FLOAT,
&&__ILLEGAL, &&__STRING, &&__CSTRING, &&__ILLEGAL, &&__ILLEGAL, &&__ILL=
EGAL, &&__ILLEGAL, &&__ILLEGAL
};

CLASS_CONST *cc;

if (ind < 0)
goto __ILLEGAL;

cc =3D &class->load->cst[ind];

value->type =3D cc->type;
goto *jump[cc->type];

__INTEGER:

value->_integer.value =3D cc->_integer.value;
return;

__LONG:

value->_long.value =3D cc->_long.value;
return;

__FLOAT:

value->_float.value =3D cc->_float.value;
return;

__STRING:

value->type =3D T_CSTRING;
value->_string.addr =3D (char *)cc->_string.addr;
value->_string.start =3D 0;
value->_string.len =3D cc->_string.len;
return;

__CSTRING:

value->type =3D T_CSTRING;
value->_string.addr =3D (char *)LOCAL_gettext(cc->_string.addr);
value->_string.start =3D 0;
value->_string.len =3D strlen(value->_string.addr);
return;

__ILLEGAL:

EXEC_ILLEGAL();
}


PUBLIC bool VALUE_is_null(VALUE *val)
{
if (val->type =3D=3D T_NULL)
return TRUE;

if (VALUE_is_string(val) && (val->_string.addr =3D=3D 0 || val->_string.l=
en =3D=3D 0))
return TRUE;

if (VALUE_is_object(val) && (val->_object.object =3D=3D NULL))
return TRUE;

if (val->type =3D=3D T_DATE && val->_date.date =3D=3D 0 && val->_date.tim=
e =3D=3D 0)
return TRUE;

if (val->type =3D=3D T_VARIANT)
{
if (val->_variant.vtype =3D=3D T_NULL)
return TRUE;

if (val->_variant.vtype =3D=3D T_STRING && *((char **)val->_variant.val=
ue) =3D=3D NULL)
return TRUE;

if (val->_variant.vtype =3D=3D T_DATE
&& ((DATE *)val->_variant.value)->date =3D=3D 0
&& ((DATE *)val->_variant.value)->time =3D=3D 0)
return TRUE;

if (TYPE_is_object(val->_variant.vtype) && *((void **)val->_variant.val=
ue) =3D=3D NULL)
return TRUE;
}

return FALSE;
}


PUBLIC void VALUE_get_string(VALUE *val, char **text, long *length)
{
if (VALUE_is_null(val))
{
*text =3D 0;
*length =3D 0;
}
else
{
*length =3D val->_string.len;
if (*length)
*text =3D val->_string.start + val->_string.addr;
else
*text =3D NULL;
}
}


--Boundary-00=_69SSEs8i+DsnV0W--

Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast