Skip to content

Commit

Permalink
fix C compilation warnings + typo in sourceview3
Browse files Browse the repository at this point in the history
  • Loading branch information
garrigue committed Jan 23, 2020
1 parent cf7e726 commit d66addf
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 26 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ LablGTK changes log
In Lablgtk-2.18.10:

2020.01.23 [Jacques]
* headers changed again in ocaml 4.10.beta2
* headers changed again in ocaml 4.10.0beta2
* fix C compilation warnings
* fix SourceMarkAttributes.new_attribute

In Lablgtk-2.18.9:

Expand Down
4 changes: 2 additions & 2 deletions src/ml_gdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

CAMLprim void ml_raise_gdk (const char *errmsg)
{
static value * exn = NULL;
static const value * exn = NULL;
if (exn == NULL)
exn = caml_named_value ("gdkerror");
raise_with_string (*exn, (char*)errmsg);
Expand Down Expand Up @@ -478,7 +478,7 @@ CAMLprim value copy_xdata (gint format, void *xdata, gulong nitems)
switch (format) {
case 8:
data = alloc_string (nitems);
memcpy (String_val(data), xdata, sizeof(char) * nitems);
memcpy (Bytes_val(data), xdata, sizeof(char) * nitems);
tag = MLTAG_BYTES;
break;
case 16:
Expand Down
6 changes: 3 additions & 3 deletions src/ml_gdkpixbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ convert_gdk_pixbuf_options (value options, char ***opt_k, char ***opt_v, gboolea
{
char *s;
value pair = Field(cell, 0);
s = String_val(Field(pair, 0));
s = Bytes_val(Field(pair, 0));
*opt_k[i] = copy ? g_strdup (s) : s;
s = String_val(Field(pair, 1));
s = Bytes_val(Field(pair, 1));
*opt_v[i] = copy ? g_strdup (s) : s;
cell = Field(cell, 1);
}
Expand Down Expand Up @@ -345,7 +345,7 @@ ml_gdkpixbuf_savefunc (const gchar *buf, gsize count, GError **error, gpointer d
value *cb = data;
value res, s;
s = alloc_string (count);
memcpy (String_val(s), buf, count);
memcpy (Bytes_val(s), buf, count);
res = callback_exn (*cb, s);
if (Is_exception_result (res))
{
Expand Down
20 changes: 10 additions & 10 deletions src/ml_glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ CAMLprim value copy_string_g_free (char *str)

static void ml_raise_glib (const char *errmsg)
{
static value * exn = NULL;
static const value * exn = NULL;
if (exn == NULL)
exn = caml_named_value ("gerror");
raise_with_string (*exn, (char*)errmsg);
Expand Down Expand Up @@ -133,7 +133,7 @@ static GSList *exn_map;
struct exn_data {
GQuark domain;
char *caml_exn_name;
value *caml_exn;
const value *caml_exn;
};

CAMLprim void ml_register_exn_map (GQuark domain, char *caml_name)
Expand All @@ -145,7 +145,7 @@ CAMLprim void ml_register_exn_map (GQuark domain, char *caml_name)
exn_map = g_slist_prepend (exn_map, exn_data);
}

static value *lookup_exn_map (GQuark domain)
static const value *lookup_exn_map (GQuark domain)
{
GSList *l = exn_map;
struct exn_data *exn_data;
Expand All @@ -160,8 +160,8 @@ static value *lookup_exn_map (GQuark domain)
return NULL;
}

static void ml_raise_gerror_exn(GError *, value *) Noreturn;
static void ml_raise_gerror_exn(GError *err, value *exn)
static void ml_raise_gerror_exn(GError *, const value *) Noreturn;
static void ml_raise_gerror_exn(GError *err, const value *exn)
{
CAMLparam0();
CAMLlocal2(b, msg);
Expand All @@ -178,7 +178,7 @@ static void ml_raise_gerror_exn(GError *err, value *exn)
static void ml_raise_generic_gerror (GError *) Noreturn;
static void ml_raise_generic_gerror (GError *err)
{
static value *exn;
static const value *exn;
value msg;
if (exn == NULL) {
exn = caml_named_value ("gerror");
Expand All @@ -192,7 +192,7 @@ static void ml_raise_generic_gerror (GError *err)

CAMLprim void ml_raise_gerror(GError *err)
{
value *caml_exn;
const value *caml_exn;
g_assert (err);
caml_exn = lookup_exn_map (err->domain);
if (caml_exn)
Expand Down Expand Up @@ -368,7 +368,7 @@ CAMLprim value ml_g_io_channel_read(value io, value str, value offset,
{
gsize read;
switch (g_io_channel_read(GIOChannel_val(io),
String_val(str) + Int_val(offset),
Bytes_val(str) + Int_val(offset),
Int_val(count),
&read)) {
case G_IO_ERROR_NONE:
Expand All @@ -390,7 +390,7 @@ CAMLprim value ml_g_io_channel_read_chars(value io, value str, value offset,
GError *err = NULL;
GIOStatus result =
g_io_channel_read_chars(GIOChannel_val(io),
String_val(str) + Int_val(offset),
Bytes_val(str) + Int_val(offset),
Int_val(count),
&read,
&err);
Expand Down Expand Up @@ -463,7 +463,7 @@ caml_copy_string_len_and_free (char *str, size_t len)
value v;
g_assert (str != NULL);
v = alloc_string (len);
memcpy (String_val(v), str, len);
memcpy (Bytes_val(v), str, len);
g_free (str);
return v;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ml_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

void ml_raise_gtk (const char *errmsg)
{
static value * exn = NULL;
static const value * exn = NULL;
if (exn == NULL)
exn = caml_named_value ("gtkerror");
raise_with_string (*exn, (char*)errmsg);
Expand Down Expand Up @@ -397,7 +397,7 @@ CAMLprim value ml_gtk_widget_style_get_property (value w, value n)
CAMLparam2 (w, n);
CAMLlocal1 (ret);
GtkWidget *widget = GtkWidget_val (w);
gchar *name = String_val (n);
gchar *name = Bytes_val (n);
GParamSpec * pspec;
pspec = gtk_widget_class_find_style_property
(GTK_WIDGET_GET_CLASS (widget), name);
Expand Down Expand Up @@ -448,7 +448,7 @@ CAMLprim value ml_gtk_drag_dest_set (value w, value f, value t, value a)
alloc (Wosize_asize(n_targets * sizeof(GtkTargetEntry)),
Abstract_tag);
for (i=0; i<n_targets; i++) {
targets[i].target = String_val(Field(Field(t, i), 0));
targets[i].target = Bytes_val(Field(Field(t, i), 0));
targets[i].flags = Flags_Target_flags_val(Field(Field(t, i), 1));
targets[i].info = Int_val(Field(Field(t, i), 2));
}
Expand Down Expand Up @@ -485,7 +485,7 @@ CAMLprim value ml_gtk_drag_source_set (value w, value m, value t, value a)
alloc (Wosize_asize(n_targets * sizeof(GtkTargetEntry)),
Abstract_tag);
for (i=0; i<n_targets; i++) {
targets[i].target = String_val(Field(Field(t, i), 0));
targets[i].target = Bytes_val(Field(Field(t, i), 0));
targets[i].flags = Flags_Target_flags_val(Field(Field(t, i), 1));
targets[i].info = Int_val(Field(Field(t, i), 2));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ml_gtksourceview2.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ CAMLprim value ml_gtk_source_view_init(value unit)

static gpointer string_val(value v)
{
return String_val(v);
return Bytes_val(v);
}

GSList *ml_gslist_of_string_list(value list)
Expand Down
4 changes: 2 additions & 2 deletions src/ml_gtkstock.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ ML_1 (gtk_icon_factory_lookup_default, String_val, Val_GtkIconSet)
CAMLprim value ml_gtk_stock_add(value item)
{
GtkStockItem it;
it.stock_id = String_val(Field(item, 0));
it.label = String_val(Field(item, 1));
it.stock_id = Bytes_val(Field(item, 0));
it.label = Bytes_val(Field(item, 1));
it.modifier = Flags_GdkModifier_val(Field(item, 2)) ;
it.keyval = Int_val(Field(item, 3));
it.translation_domain = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/ml_gtktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ ml_gtk_tree_view_enable_model_drag_dest (value tv, value t, value a)
, Abstract_tag );
for (i=0; i<n_targets; i++)
{
targets[i].target = String_val(Field(Field(t, i), 0));
targets[i].target = Bytes_val(Field(Field(t, i), 0));
targets[i].flags = Flags_Target_flags_val(Field(Field(t, i), 1));
targets[i].info = Int_val(Field(Field(t, i), 2));
}
Expand All @@ -551,7 +551,7 @@ ml_gtk_tree_view_enable_model_drag_source (value tv, value m, value t, value a)
, Abstract_tag );
for (i=0; i<n_targets; i++)
{
targets[i].target = String_val(Field(Field(t, i), 0));
targets[i].target = Bytes_val(Field(Field(t, i), 0));
targets[i].flags = Flags_Target_flags_val(Field(Field(t, i), 1));
targets[i].info = Int_val(Field(Field(t, i), 2));
}
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ value ml_cons (value v, value l)

void ml_raise_null_pointer ()
{
static value * exn = NULL;
static const value * exn = NULL;
if (exn == NULL)
exn = caml_named_value ("null_pointer");
raise_constant (*exn);
Expand Down
4 changes: 4 additions & 0 deletions src/wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#define Is_young_block(v) \
(Is_block(v) && (value*)(v) < young_end && (value*)(v) > young_start)

#ifndef Bytes_val
#define Bytes_val String_val
#endif

CAMLexport value copy_memblock_indirected (void *src, asize_t size);
value alloc_memblock_indirected (asize_t size);
CAMLexport value ml_alloc_custom(struct custom_operations * ops,
Expand Down

0 comments on commit d66addf

Please sign in to comment.