pike.git / src / post_modules / GTK2 / source / support.c

version» Context lines:

pike.git/src/post_modules/GTK2/source/support.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id$ +    */      #include <version.h>   #include <bignum.h>   #include <stdarg.h>      #ifndef INIT_VARIABLES   extern struct program *image_color_program;   extern struct program *image_program;   #endif
pike.git/src/post_modules/GTK2/source/support.c:70:    push_text(what);    f_index(2);   #ifdef PIKE_DEBUG    if (TYPEOF(Pike_sp[-1]) == PIKE_T_INT)    Pike_error("Internal indexing error.\n");   #endif   }      int get_color_from_pikecolor(struct object *o, INT_TYPE *r, INT_TYPE *g, INT_TYPE *b) {    struct color_struct *col; -  col=(struct color_struct *)get_storage(o,image_color_program); +  col=get_storage(o,image_color_program);    if (!col)    return 0;    *r=col->rgbl.r/(COLORLMAX/65535);    *g=col->rgbl.g/(COLORLMAX/65535);    *b=col->rgbl.b/(COLORLMAX/65535);    return 1;   }      GdkImage *gdkimage_from_pikeimage(struct object *img, int fast, GObject **pi) {    GdkImage *i;    GdkColormap *col=gdk_colormap_get_system();    GdkVisual *vis=gdk_visual_get_system();    struct image *img_data;    INT_TYPE x,y;       TIMER_INIT("Getting extents");    -  img_data=(struct image*)get_storage(img, image_program); +  img_data=get_storage(img, image_program);       /* 1a: create the actual image... */    x = img_data->xsize;    y = img_data->ysize;          if (x==0 || y==0)    Pike_error("Size of image must be > 0x0\n");    if (pi) {    i = GDK_IMAGE(*pi);
pike.git/src/post_modules/GTK2/source/support.c:156:    2/ use that array to build a pike X-image colormap.    3/ call Image.X.encode_pseudocolor( img, bpp, lpad, depth, colormp )    4/ copy the actual data to the image..    */    if (!colors_allocated) {   #define COLORMAP_SIZE 256    char allocated[COLORMAP_SIZE];    int j,i,r,g,b;    PFTIME("Creating colormap");    colors_allocated=1; -  MEMSET(allocated,0,sizeof(allocated)); +  memset(allocated,0,sizeof(allocated));    for (r=0; r<3; r++) for (g=0; g<4; g++) for (b=0; b<3; b++) {    GdkColor color;    color.red = (guint16)(r * (65535/2.0));    color.green = (guint16)(g * (65535/3.0));    color.blue = (guint16)(b * (65535/2.0));    color.pixel = 0;    if (gdk_color_alloc(col,&color))    if (color.pixel<COLORMAP_SIZE)    allocated[color.pixel]=1;    }
pike.git/src/post_modules/GTK2/source/support.c:241:    push_object(pike_cmap);    /* on stack: function img bpp linepad depth cmap*/    /* 6 5 4 3 2 1 */    PFTIME("Dithering image");    apply_svalue(Pike_sp-6,5);    if (TYPEOF(Pike_sp[-1]) != PIKE_T_STRING) {    gdk_image_destroy((void *)i);    Pike_error("Failed to convert image\n");    }    PFTIME("Converting image"); -  MEMCPY(i->mem,Pike_sp[-1].u.string->str,Pike_sp[-1].u.string->len); +  memcpy(i->mem,Pike_sp[-1].u.string->str,Pike_sp[-1].u.string->len);    pop_stack(); /* string */    pop_stack(); /* function */    }    }    TIMER_END();    return i;   }      int pgtk2_is_object_program(struct program *X);   
pike.git/src/post_modules/GTK2/source/support.c:293:    ((struct object_wrapper *)o->storage)->obj=obj;    ((struct object_wrapper *)o->storage)->owned = owned;    push_object(o);    return;   }      GObject *get_pg2object(struct object *from, struct program *type) {    struct object_wrapper * o;    if (!from)    return NULL; -  o=(struct object_wrapper *)get_storage(from,type); +  o=get_storage(from,type);    if (!o)    return 0;    return o->obj;   }      void *get_pgdk2object(struct object *from, struct program *type) {    void *f;    if (!from)    return NULL;    if (type)    f=get_storage( from, type );    else    f=from->storage; /* Add a warning? */    if (!f)    return 0;    return (void *)((struct object_wrapper *)f)->obj;   }      void pgtk2_destruct(struct object *o) { -  struct object_wrapper *ow= -  (struct object_wrapper *)get_storage(o,pg2_object_program); +  struct object_wrapper *ow=get_storage(o,pg2_object_program);    if (ow) /* This should always be true. But let's add a check anyway. */    ow->obj=NULL;    if (o->refs>1)    destruct(o);    free_object(o); /* ref added in __init_object below. */   }      void pgtk2__init_object(struct object *o) {    GObject *go=get_gobject(o);    if (!go) /* Not a real GObject. Refhandling done elsewhere */
pike.git/src/post_modules/GTK2/source/support.c:343:    void *dest, long *mask, int len) {    struct svalue *s;    if ((s=simple_mapping_string_lookup(map,name))) {    if (TYPEOF(*s) == type) {    switch(type) {    case PIKE_T_STRING:   #ifdef PIKE_DEBUG    if (len!=sizeof(char *))    Pike_fatal("oddities detected\n");   #endif -  MEMCPY(((char **)dest),&s->u.string->str,sizeof(char *)); +  memcpy(dest,&s->u.string->str,sizeof(char *));    break;    case PIKE_T_INT:    if (len==2) {    short i=(short)s->u.integer; -  MEMCPY(((short *)dest),&i,2); +  memcpy(dest,&i,2);    } else if (len==4) -  MEMCPY(((int *)dest),&s->u.integer,len); +  memcpy(dest,&s->u.integer,len);    break;    case PIKE_T_FLOAT:    if (len==sizeof(FLOAT_TYPE)) -  MEMCPY(((FLOAT_TYPE *)dest),&s->u.float_number,len); +  memcpy(dest,&s->u.float_number,len);    else if (len==sizeof(double)) {    double d=s->u.float_number; -  MEMCPY(((double *)dest),&d,len); +  memcpy(dest,&d,len);    }    break;    }    if (mask)    *mask|=madd;    }    }   }      GdkAtom get_gdkatom(struct object *o) {
pike.git/src/post_modules/GTK2/source/support.c:431:   }      void push_atom(GdkAtom a) {    /* this should really be inserted in the GDK.Atom mapping. */    push_pgdk2object((void *)a,pgdk2__atom_program,0);   }      void push_Xpseudo32bitstring(void *f, int nelems) {    if (sizeof(long)!=4) {    long *q=(long *)f; -  int *res=(int *)xalloc(nelems*4),i; +  int *res=xalloc(nelems*4),i;    for (i=0; i<nelems; i++)    res[i]=q[i];    push_string(make_shared_binary_string2((const p_wchar2 *)res,nelems));    xfree(res);    } else {    push_string(make_shared_binary_string2(f,nelems));    }   }      /*
pike.git/src/post_modules/GTK2/source/support.c:501:    return PUSHED_VALUE;   }      static int pgtk2_push_gdk_event_param(const GValue *a) {    push_gdk_event(g_value_get_boxed(a));    return NEED_RETURN;   }      static int pgtk2_push_gdk_rectangle_param(const GValue *a) {    GdkRectangle *r = (GdkRectangle *) g_value_get_boxed(a); -  push_text("x"); push_int(r->x); -  push_text("y"); push_int(r->y); -  push_text("width"); push_int(r->width); -  push_text("height"); push_int(r->height); +  push_static_text("x"); push_int(r->x); +  push_static_text("y"); push_int(r->y); +  push_static_text("width"); push_int(r->width); +  push_static_text("height"); push_int(r->height);    f_aggregate_mapping(8);    return PUSHED_VALUE;   }      static int pgtk2_push_int_param(const GValue *a) {    LONGEST retval;    switch (G_VALUE_TYPE(a)) {    case G_TYPE_UINT:    retval=(LONGEST)g_value_get_uint(a);    break;
pike.git/src/post_modules/GTK2/source/support.c:537:    case G_TYPE_FLAGS:    retval=(LONGEST)g_value_get_flags(a);    break;    case G_TYPE_BOOLEAN:    retval=(LONGEST)g_value_get_boolean(a);    break;    case G_TYPE_LONG:    retval=(LONGEST)g_value_get_long(a);    break;    case G_TYPE_CHAR: + #ifdef HAVE_G_VALUE_GET_SCHAR +  retval=(LONGEST)g_value_get_schar(a); + #else    retval=(LONGEST)g_value_get_char(a); -  + #endif    break;    default:    retval=(LONGEST)g_value_get_uint(a);    break;    }    push_int64(retval);    return PUSHED_VALUE;   }      static int pgtk2_push_float_param(const GValue *a) {
pike.git/src/post_modules/GTK2/source/support.c:579:    if (g_type_is_a(G_VALUE_TYPE(a),G_TYPE_BOXED)) {    gp=g_value_get_boxed(a);    if (G_VALUE_HOLDS(a,g_type_from_name("GdkColor"))) {    push_gdkobject(gp,color,0);    } else if (G_VALUE_HOLDS(a,g_type_from_name("GtkTreePath"))) {    push_pgdk2object(gp,pgtk2_tree_path_program,0);    } else if (G_VALUE_HOLDS(a,g_type_from_name("GdkRectangle"))) {    push_gdkobject(gp,rectangle,0);    } else if (G_VALUE_HOLDS(a,g_type_from_name("GdkRegion"))) {    push_gdkobject(gp,region,0); +  } else { +  /* Don't know how to push this sort of object, so push its name */ +  PGTK_PUSH_GCHAR(G_VALUE_TYPE_NAME(a));    }    } else {    obj=g_value_get_object(a);    if (obj)    push_gobject(obj);    }    return PUSHED_VALUE;   }      static int pgtk2_push_pike_object_param(const GValue *a) { -  struct object *o=g_value_get_pointer(a); -  if (o) -  ref_push_object(o); +  push_int64((LONGEST)g_value_get_pointer(a));    return PUSHED_VALUE;   }      static int pgtk2_push_gparamspec_param(const GValue *a) {    push_int(0);    return PUSHED_VALUE;   }      static struct push_callback {    int (*callback)(const GValue *);
pike.git/src/post_modules/GTK2/source/support.c:836:    mode=Pike_sp[-args].u.integer;    pgtk2_pop_n_elems(args);    if (mode!='O') {    push_undefined();    return;    }    push_string(make_shared_binary_string(__pgtk2_string_data+offset,len));   }      void pgtk2_clear_obj_struct(struct object *o) { -  MEMSET(Pike_fp->current_storage,0,sizeof(struct object_wrapper)); +  memset(Pike_fp->current_storage,0,sizeof(struct object_wrapper));   }      void pgtk2_setup_mixin(struct object *o, struct program *p) {    ptrdiff_t offset;    offset = low_get_storage(o->prog, p);    if(offset == -1)    Pike_error("This class can not be instantiated on its own.\n");    ((struct mixin_wrapper *)Pike_fp->current_storage)->offset = offset;   }      LONGEST pgtk2_get_int(struct svalue *s) {    if (TYPEOF(*s) == PIKE_T_INT)    return s->u.integer; - #ifdef AUTO_BIGNUM +     if (is_bignum_object_in_svalue(s)) {    LONGEST res;    int64_from_bignum(&res,s->u.object);    return res;    } - #endif +     if (TYPEOF(*s) == PIKE_T_FLOAT)    return (LONGEST)s->u.float_number;    return 0;   }      int pgtk2_is_int(struct svalue *s) {    return ((TYPEOF(*s) == PIKE_T_INT) || -  (TYPEOF(*s) == PIKE_T_FLOAT) - #ifdef AUTO_BIGNUM -  || is_bignum_object_in_svalue(s) - #endif -  ); +  (TYPEOF(*s) == PIKE_T_FLOAT) || +  is_bignum_object_in_svalue(s));   }      /* double should be enough */   double pgtk2_get_float(struct svalue *s) {    if (TYPEOF(*s) == PIKE_T_FLOAT)    return s->u.float_number;    if (TYPEOF(*s) == PIKE_T_INT)    return (double)s->u.integer; - #ifdef AUTO_BIGNUM +     if (is_bignum_object_in_svalue(s)) {    FLOAT_TYPE f; -  push_text("float"); -  apply(s->u.object,"cast",1); +  ref_push_type_value(float_type_string); +  stack_swap(); +  f_cast();    f=Pike_sp[-1].u.float_number;    pop_stack();    return (double)f;    } - #endif +     return 0.0;   }      void pgtk2_free_object(struct object *o) {    free_object(o);   }      int pgtk2_is_float(struct svalue *s) {    return ((TYPEOF(*s) == PIKE_T_FLOAT) || -  (TYPEOF(*s) == PIKE_T_INT) - #ifdef AUTO_BIGNUM -  || is_bignum_object_in_svalue(s) - #endif -  ); +  (TYPEOF(*s) == PIKE_T_INT) || +  is_bignum_object_in_svalue(s));   }      void pgtk2_set_property(GObject *g, char *prop, struct svalue *sv) {    GParamSpec *gps;    GType v;    gps=g_object_class_find_property(G_OBJECT_GET_CLASS(g),prop);    if (!gps)    Pike_error("This object does not have a property called %s.\n",prop);    if (!(gps->flags & G_PARAM_WRITABLE))    Pike_error("This property is not writable.\n");
pike.git/src/post_modules/GTK2/source/support.c:1195:    return;    }    switch (gt) {    case G_TYPE_INT:    g_value_set_int(gv,(gint)PGTK_GETINT(sv));    break;    case G_TYPE_UINT:    g_value_set_uint(gv,(guint)PGTK_GETINT(sv));    break;    case G_TYPE_CHAR: + #ifdef HAVE_G_VALUE_SET_SCHAR +  g_value_set_schar(gv,(gchar)PGTK_GETINT(sv)); + #else    g_value_set_char(gv,(gchar)PGTK_GETINT(sv)); -  + #endif    break;    case G_TYPE_UCHAR:    g_value_set_uchar(gv,(guchar)PGTK_GETINT(sv));    break;    case G_TYPE_LONG:    g_value_set_long(gv,(glong)PGTK_GETINT(sv));    break;    case G_TYPE_ULONG:    g_value_set_ulong(gv,(gulong)PGTK_GETINT(sv));    break;
pike.git/src/post_modules/GTK2/source/support.c:1322:    GValue *return_value,    guint n_params,    const GValue *param_values,    gpointer invocation_hint,    gpointer marshal_data) {    typedef void (*pgtk2_marshal_func)(gpointer data1,    gpointer data2,    guint n_params,    const GValue *param_values,    GValue *return_value); -  register pgtk2_marshal_func callback; -  register GCClosure *cc=(GCClosure *)closure; -  register gpointer data1,data2; +  pgtk2_marshal_func callback; +  GCClosure *cc=(GCClosure *)closure; +  gpointer data1,data2;    -  +     if (G_CCLOSURE_SWAP_DATA(closure)) {    data1=closure->data;    data2=g_value_peek_pointer(param_values+0);    } else {    data1=g_value_peek_pointer(param_values+0);    data2=closure->data;    }       callback=(pgtk2_marshal_func)(marshal_data?marshal_data:cc->callback);    callback(data1,data2,n_params-1,param_values+1,return_value);
pike.git/src/post_modules/GTK2/source/support.c:1437:    }    g_string_append(str,"\n");    }    g_free(signal_ids);    g_string_append(str,"\n");    }    if (class)    g_type_class_unref(class);   }    - struct svalue *pgtk2_get_doc(GObject *o, int pushv) { + void pgtk2_get_doc(GObject *o, struct svalue *dest) {    GType type=0;    GString *str; -  struct svalue *sv; +       /*    if (o)    type=G_OBJECT_TYPE(G_OBJECT(o)->obj);    else -  return NULL; +  return;   */    type=G_OBJECT_TYPE(o);    str=g_string_new_len(NULL,512);       if (g_type_is_a(type,G_TYPE_INTERFACE))    g_string_append_printf(str,"Interface %s\n\n",g_type_name(type));    else if (g_type_is_a(type,G_TYPE_OBJECT))    g_string_append_printf(str,"Object %s\n\n",g_type_name(type));       if (g_type_is_a(type,G_TYPE_OBJECT)) {
pike.git/src/post_modules/GTK2/source/support.c:1482:       interfaces=g_type_interfaces(parent,&n);    for (i=0; i<n; i++)    add_signal_docs(interfaces[i],str);    g_free(interfaces);    }    g_array_free(parents,TRUE);    }    push_string(make_shared_binary_string(str->str,str->len));    g_string_free(str,TRUE); -  if (!pushv) { -  sv=g_new0(struct svalue,1); -  assign_svalue_no_free(sv,&Pike_sp[-1]); +  if (dest) { +  assign_svalue_no_free(dest, Pike_sp - 1);    pop_stack(); -  return sv; +     } -  return sv; +    }