Re: Why cani i initialize prefix with a default string?

2011-12-10 Thread Gary Kline
On Sat, Dec 10, 2011 at 03:23:10AM +0100, David Ne??as wrote:
 Date: Sat, 10 Dec 2011 03:23:10 +0100
 From: David Ne??as y...@physics.muni.cz
 Subject: Re: Why cani i initialize prefix with a default string?
 To: Gary Kline kl...@thought.org
 Cc: GTK Devel List gtk-app-devel-list@gnome.org
 
 On Fri, Dec 09, 2011 at 05:40:09PM -0800, Gary Kline wrote:
  guys, i am appending a piece of gtk test code.  it saves the
  internal filename buffer for espeak -f %s ifbuf to run
  on--to be the user's voice.  if i set 
  
  static char *prefix = talk; 
  
  then back up and enter another string in the box at the
  bottom, strange things happen.  Anybody know where i am
  messing up?
 
 Strange things most likely occur after attempting to free the const
 string in entry_changed_cb()
 
 g_free(prefix);
 
 which was fine if prefix was NULL initially.  You can use -Wwrite-strings
 to catch that.  

your advice was right on target.  i changed the gcc line,
then checked 

if (prefix == NULL)
printf(NOT NULL\n)

early in main().  since i set prefix , the string printed to
stdout.  long-story-short, my test program works the way i 
want.

 Unforutnately, passing constant strings as various
 user-data-kind arguments or to g_hash_table_insets() then produces
 warnings too.

okay; i'll watch out!

 
 Also learn to use valgrind; it would show you this problem immediately.
 

a couple hours ago i installed valgrind and a front end.

The next thing on my to-try list is to get the
increase/decrease buttons together;  this means reading up
on the hbox stuff.  i found one example somewhere last week
and it looks tricky.  --anyhow, thans for your keen
insights.  

gary


 Yeti
 

-- 
 Gary Kline  kl...@thought.org  http://www.thought.org  Public Service Unix
   Journey Toward the Dawn, E-Book: http://www.thought.org
  The 8.57a release of Jottings: http://jottings.thought.org
 Twenty-five years of service to the Unix community.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread Antonio Weber
Hi list,

I'm trying to write a small app which uses a GtkTreeView to display a table. 
For some reason it does not work as expected so I extracted my usage in a small 
tableTest app (which a attach to this mail).
I have 10 columns and 100 rows.

Basically this is the central function:

static void populateTable(GtkTreeView *treeView) {
    int i;
    char data[1024];
    GType types[COLUMN_COUNT];
    GtkTreeViewColumn *column;

    for(i = 0; i  COLUMN_COUNT; i++) {
    sprintf(data, %d, i + 1);
    types[i] = G_TYPE_STRING;
    
    column = gtk_tree_view_column_new_with_attributes(data, 
gtk_cell_renderer_text_new(), text, 0, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), column);
    }

    int j;
    GtkTreeIter iter;
    GtkListStore *listStore = gtk_list_store_newv(COLUMN_COUNT, types);

    for(i = 0; i  ROW_COUNT; i++) {
    /*
    GValue values[COLUMN_COUNT];
    gint columnIds[COLUMN_COUNT];
    */

    GValue *values = g_slice_alloc0(sizeof(GValue) * COLUMN_COUNT);
    gint *columnIds = g_slice_alloc0(sizeof(gint) * COLUMN_COUNT);
    
    memset(values, 0x0, sizeof(values));
    
    gtk_list_store_append(listStore, iter);

    for(j = 0; j  COLUMN_COUNT; j++) {
    
    sprintf(data, %d, j + 1);
    printf(Data=%s\n, data);

    g_assert(!G_VALUE_HOLDS_STRING(values[j]));
    g_value_init(values[j], G_TYPE_STRING);
    g_value_set_string(values[j], data);

    columnIds[j] = j;
    }
    gtk_list_store_set_valuesv(listStore, iter, columnIds, values, 
COLUMN_COUNT);
    g_slice_free1(sizeof(GValue) * COLUMN_COUNT, values);
    g_slice_free1(sizeof(gint) * COLUMN_COUNT, columnIds);
    }
    gtk_tree_view_set_model(treeView, GTK_TREE_MODEL(listStore));    
}

I expected that in each row I see
col '1' = '1'  | col '2' = '2' etc...

But In my case each cell holds the value '1'

What do I wrong here?

Thanks a lot,
Antonio

___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread Antonio Weber
Sorry - really tried to attach a file - my fault :)
Here you can get the tar: 
https://sites.google.com/site/webadone/tableTest.tar.gz[../redirect?goto=https%3A%2F%2Fsites.google.com%2Fsite%2Fwebadone%2FtableTest.tar.gz]

Thanks a lot,
Antonio


-Ursprüngliche Nachricht-
Von: Antonio Weber antonio_we...@web.de
Gesendet: 10.12.2011 20:16:39
An: gtk-app-devel-list@gnome.org
Betreff: Usage of gtk_list_store_set_valuesv()

Hi list,

I'm trying to write a small app which uses a GtkTreeView to display a table. 
For some reason it does not work as expected so I extracted my usage in a 
small tableTest app (which a attach to this mail).
I have 10 columns and 100 rows.

Basically this is the central function:

static void populateTable(GtkTreeView *treeView) {
    int i;
    char data[1024];
    GType types[COLUMN_COUNT];
    GtkTreeViewColumn *column;

    for(i = 0; i  COLUMN_COUNT; i++) {
    sprintf(data, %d, i + 1);
    types[i] = G_TYPE_STRING;
    
    column = gtk_tree_view_column_new_with_attributes(data, 
gtk_cell_renderer_text_new(), text, 0, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), column);
    }

    int j;
    GtkTreeIter iter;
    GtkListStore *listStore = gtk_list_store_newv(COLUMN_COUNT, types);

    for(i = 0; i  ROW_COUNT; i++) {
    /*
    GValue values[COLUMN_COUNT];
    gint columnIds[COLUMN_COUNT];
    */

    GValue *values = g_slice_alloc0(sizeof(GValue) * COLUMN_COUNT);
    gint *columnIds = g_slice_alloc0(sizeof(gint) * COLUMN_COUNT);
    
    memset(values, 0x0, sizeof(values));
    
    gtk_list_store_append(listStore, iter);

    for(j = 0; j  COLUMN_COUNT; j++) {
    
    sprintf(data, %d, j + 1);
    printf(Data=%s\n, data);

    g_assert(!G_VALUE_HOLDS_STRING(values[j]));
    g_value_init(values[j], G_TYPE_STRING);
    g_value_set_string(values[j], data);

    columnIds[j] = j;
    }
    gtk_list_store_set_valuesv(listStore, iter, columnIds, values, 
COLUMN_COUNT);
    g_slice_free1(sizeof(GValue) * COLUMN_COUNT, values);
    g_slice_free1(sizeof(gint) * COLUMN_COUNT, columnIds);
    }
    gtk_tree_view_set_model(treeView, GTK_TREE_MODEL(listStore));    
}

I expected that in each row I see
col '1' = '1'  | col '2' = '2' etc...

But In my case each cell holds the value '1'

What do I wrong here?

Thanks a lot,
Antonio

___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192


___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread David Nečas
On Sat, Dec 10, 2011 at 08:16:39PM +0100, Antonio Weber wrote:
 I'm trying to write a small app which uses a GtkTreeView to display a
 table. For some reason it does not work as expected so I extracted my
 usage in a small tableTest app (which a attach to this mail).

You bind all view columns to model column 0.  So they all display the
data in column 0.  See your gtk_tree_view_column_new_with_attributes().

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Usage of gtk_list_store_set_valuesv()

2011-12-10 Thread Antonio Weber
Ah thanks a lot thats it!
Sorry was my fault - should have had a closer look on it.

have a nice weekend,
Antonio


-Ursprüngliche Nachricht-
Von: David Nečas y...@physics.muni.cz
Gesendet: 10.12.2011 20:53:59
An: Antonio Weber antonio_we...@web.de
Betreff: Re: Usage of gtk_list_store_set_valuesv()

On Sat, Dec 10, 2011 at 08:16:39PM +0100, Antonio Weber wrote:
 I'm trying to write a small app which uses a GtkTreeView to display a
 table. For some reason it does not work as expected so I extracted my
 usage in a small tableTest app (which a attach to this mail).

You bind all view columns to model column 0. So they all display the
data in column 0. See your gtk_tree_view_column_new_with_attributes().

Yeti



___
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: GLIB for a webserver

2011-12-10 Thread Marcelo Elias Del Valle
Hello,

 Sorry for the delay to replay..

 If you write applications which don't leak memory, then you probably won't
 have any problem. Also if your web server fails because it consumes too much
 memory, this also probably means that either your HW is not strong enough to
 support your web server or your web server is leaking memory, and in this
 last case having it fail and restarting it is IMHO quite a good idea (much
 better code than trying to handle failed memory allocations).
Actually, I am going to be honest in saying that I don't totally
agree to you. You are right in saying that more hardware is needed or
that leaking memory shouldn't exist. However, when we talk about a web
server, we are talking about an application that will use memory on a
per request basis.
Imagine the following scenario: the application running on my web
server spends 20k of memory for each concurrent request. If I have
enough concurrent requests in a way it will consume more memory than,
let's say, 2Gb available memory, the expected result would be to
refuse new connections, not restart the application and all current
requests being handle. Agree?
Anyway, let me just make a point clear, first of all: I didn't
asked this expecting someone on the list to solve this problem and my
interest is not to criticize glib either. Actually, I understand this
problem exists and I am willing to (and want to) use glib anyway. My
fear is that I start to use it and see the glib development going in a
different path in future, for example: someone might change the lib
design in future in a way it would serve each time less server side
applications, to focus better on being a basis to graphical frontend.
   The main question I tried to ask (I am usually bad to express it
well, sorry), is: what are the plans for glib? Do you thing it will be
each time more an independent library, with general use purpose, or
will it be something focused to gnome apps?
I was reading about D-BUS, for example, as I was interested in
ways to implement IPC using glib, but althought it is part of GIO, its
intention is to serve only to desktop apps, isn't it?

 Please have a look at the LibSoup library, I've used it before for a small
 embedded web server (in Libgda's console's tool) and it worked quite well,
 but it really depends on what you want to do.
   Thanks again for the recommendation. I took a look and it seems an
excelent library for what I want to do. However, I still need to read
the docs in details, it was not clear to me how the lib deals with
threads to service calls and if it supports blocking/non blocking
service handling.  But if it serves to me, it will be my first choice.
I already entered the mailing list too! :D

Regards,
-- 
Marcelo Elias Del Valle
http://mvalle.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GLIB for a webserver

2011-12-10 Thread Marcelo Elias Del Valle
Hello,

 - On Apache ARP project, they said they created it instead of using
 glib because the lack of IPC functions like memory mapping.
 This makes no sense since they could use glib and also write mmap
 functions...
   Well, that's what I thought too. That's why I made the decision to
ask here if it would make sense.

 - In some forums, people were complaining about the fact glib aborts
 when memory allocation fails, which is bad for a 24/7 running web
 server.
 A robust Web server would probably have a framework that restarted
 components as needed; Apache already does some of this with workers.

 The main problem with memory allocation comes when someone else's
 process is using all the memory.

   My server code is too smal yet to compare, but it is being already
planned to do it. I start each application hosted by my server in a
different  process, so I will be able to restart it if the process
segfaults or quits for some reason. But I think like this (please tell
me if you agree or not):
 - If the server itself (my code) seg fault, so it should stop. I
should solve this by fixing my code, not by writting whatdog for it,
as I explained above;
 - However, as you said, if someone elses code (like applications or
service plugins in my case) segfaults, my server should be able to
restart the applications as needed.
But I pay a price for it. As this is implemented with IPC and I
need multiple processes, I will spend more computer resources
(CPU/memory) to deal with it, to make it more reliable. Pays the way,
but I imagine it's where it will need more optimization.

 If you are writing a new Web server (why?) glib is probably fine.

   By this affirmation, I understand glib is not only a basis for
desktop app, right? Good! I will like to use it.
   The reason why I am writting is a bit of Linus Torwalds fault. :D
After reading hundreds of messages on a GIT mailing list on a thread
he started (http://article.gmane.org/gmane.comp.version-control.git/57918),
I realized I agree with him. My intention is not exactly to write a
web server, but an application server, like JBoss
(http://www.jboss.org/), but in C. I use Java app servers on my
day-by-day work, but just because people pay me to do that. I _hate_
Java resource consumption and I think it should exist a FAST, easy to
use alternative in C.
It's my pet project, by now.

 Don't fight it, though. There's no portable way to find the system's
 free memory, and even if there were, it wouldn't help -

    if (amount_of_memory  amount_available) {
         // imagine that after that test succeeds,
         // your program happens to get swapped out,
         // and another program allocates all of memory

         allocate_memory(); // fails
    }

   You are right. I haven't thought about it.

 So it's better to assume that things will fail. Robustness does not come
 from avoiding failure - it comes from recovering from failure.

This paragraph made me think a lot (thanks for it!). I fully agree
with you if I think on others' processes, but talking about the server
itself... Need to think. Anyway, the fact glib exits when memory
allocation fails wouldn't stop me from using it. I am sure there is a
way of solving it, one way or another. Of course finding it will be a
bit hard... But will think carefully on what you've said.

 For a Web server that may just mean restarting. Sure, some users will
 have to reload Web pages; if that's actually a problem, use persistent
 storage to record state.

   In the case of my server, each request may result in an open
database connection and possibly a started transaction. Stop all
current transactions because the server is on its limit is something
that might happen, but I don't consider good. I can recover from that,
but finding a way of not letting that happen would be preferable.

 Apache and IIS are fairly large codebases for a reason, though -- a
 secure reliable production Web server would have a lot of catching up to
 do.
Sure, but I have no intention of replacing it. I plan to let my
server work as an apache or NGinx plugin someday. My project is much
more like Phusion Passenger (http://www.modrails.com/) or JBoss, but
for C development.
Of course there will be a lot of catching up too, but differently
of these servers, that focus mostly on how to service something in a
reliable way, I want to focus on providing an easy to use API for the
application developer, as my server hosts applications. I would
provide services like message queueing, database connection pools,
load monitoring, etc.
Here is where I found the power of gnome would help me a lot. By
using the APIs provided by gnome, as GDA, GLib itself, GIO, etc., the
application developer would have a portable, powerful and easy to use
API at his/her disposal, to write server side apps and application
middleware.
Unless all these libs are supposed to be used only by desktop apps
and I shouldn't be trying to use it for middleware... :D