After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 318611 - Data hiding in the code of EMsgComposer
Data hiding in the code of EMsgComposer
Status: RESOLVED FIXED
Product: evolution
Classification: Applications
Component: Mailer
unspecified
Other All
: High major
: ---
Assigned To: evolution-mail-maintainers
Evolution QA team
Depends on:
Blocks: 318613
 
 
Reported: 2005-10-11 20:31 UTC by Philip Van Hoof
Modified: 2005-10-19 11:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The patch that fixes this (131.91 KB, patch)
2005-10-11 20:32 UTC, Philip Van Hoof
none Details | Review
Same patch but now without _PRIVATE() (133.44 KB, patch)
2005-10-13 07:44 UTC, Philip Van Hoof
none Details | Review
Little fix in the patch (133.89 KB, patch)
2005-10-13 07:54 UTC, Philip Van Hoof
accepted-commit_now Details | Review

Description Philip Van Hoof 2005-10-11 20:31:53 UTC
Please describe the problem:
Hi there,

I know it's unavoidable in projects like Evolution, yet it's always nice to go
over code and fix the occurrences of unavoidable mistakes.

One such mistake (well, it's not really a mistake but makes replacing the
GtkHtml widget a lot more difficult) is violation of data hiding.

For example:


  <mystruct.h>

  typedef struct {
	int hidden_a;
  } MyStruct;

  int mystruct_get_a (MyStruct *instance);


  <myprogram.c>

  #include <mystruct.h>

  int test (MyStruct *struc)
  {
	printf ("It has %d\n", struc->hidden_a);
  }

Of course should the programmer here have used this:

int test (MyStruct *struc) 
{
	printf ("It has %d\n", mystruct_get_a (struc));
}

What can be done about this (I know most Evolution developers know this, but I'm
repeating it to illustrate what I did in this patch):

  <mystruct.h>

  typedef struct _MyStructPrivate MyStructPrivate;
  typedef struct {
	MyStructPrivate *priv;
  } MyStruct;

  int mystruct_get_a (MyStruct *instance);

  <mystruct.c>
  struct _MyStructPrivate {
    int hidden_a;
  };

  int mystruct_get_a (MyStruct *instance)
  {
     return instance->priv->hidden_a;
  }


That is basically what I did with e-msg-composer.c and e-msg-composer.h


The reason why I also like this to get accepted (and tested) is because this
will be the basis of replacing the GtkHtml widget with a GtkMozEmbed widget.

You see, if I'm sure that NOBODY used anything else but the agreed EMsgComposer
API as defined in e-msg-composer.h, then I can securely replace the internals of
e-msg-composer.c.

I can then for example replace the Bonobo/CORBA stuff with normal method calls
on a GObject/GtkWidget. And then also replace the GtkHtml widget with a
GtkMozEmbed that has been set editable (check our go-evolution wiki for more
information about that).

Steps to reproduce:


Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 Philip Van Hoof 2005-10-11 20:32:28 UTC
Created attachment 53342 [details] [review]
The patch that fixes this
Comment 2 Christian Persch 2005-10-11 21:55:06 UTC
If you're changing the public struct, you could include a pointer to the priv
data there and use that in all the functions since doing object->priv is pretty
much zero cost, while _PRIVATE(object) is a hash table lookup.
Comment 3 Philip Van Hoof 2005-10-11 22:25:26 UTC
Right .. I might indeed change that (I have been thinking about it too). I tried
reusing what was already in place. And the prev. evolution developer decided to
use the GObject stuff for private data. I didn't want to break stuff when I
began moving the struct-members. But found out that, indeed, it might be simpler
and better to just replace it with a *priv and a typedef for EMsgComposerPrivate
in e-msg-composer.h.

Comment 4 Jeffrey Stedfast 2005-10-12 15:15:54 UTC
yes, please do.
Comment 5 Philip Van Hoof 2005-10-13 07:44:09 UTC
Created attachment 53405 [details] [review]
Same patch but now without _PRIVATE()

This patch uses a normal *priv and forward declares the structs in the .c
files.
Comment 6 Philip Van Hoof 2005-10-13 07:54:30 UTC
Created attachment 53406 [details] [review]
Little fix in the patch

53405 had a few small diff-problems (some lines weren't correctly being
replaced). I created a new diff that doesn't have these problems. (So use this
one, not the previous one).
Comment 7 parthasarathi susarla 2005-10-19 06:48:39 UTC
The patch looks fine. I think its ok to commit to HEAD. Thanks
Comment 8 Philip Van Hoof 2005-10-19 11:21:24 UTC
Committed