pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dict_var_resized


From: John Darrington
Subject: Re: dict_var_resized
Date: Sat, 2 May 2009 08:18:26 +0800
User-agent: Mutt/1.5.18 (2008-05-17)

dict_var_resized exists for one purpose only -  it informs the GUI
that the size of a variable has changed.  That way, the var sheet 
always displays the correct information, even if a variable changes
due to some low level operation (eg: running syntax).

d is null, because the variable doesn't belong to any dictionary.
It was created with var_create_internal.

Solution 1: Is it not possible to delay creation of the variable until
after the loop:     for (i = 0; i < n_vars; i++)    ?

That way, you can pass the correct width to var_create_internal,
and  avoid calling var_set_width at all.

That is something like:

  result->n_vars = n_vars;
  for (i = 0; i < n_vars; i++)
    {
      result->members[i] = vars[i];
      if (var_is_alpha (vars[i]))
        {
          result->n_alpha++;
        }
    }

  result->intr = var_create_internal (MAX_SHORT_STRING * result->n_alpha + 1);

Solution 2:  If that's not possible, then I think it'll be acceptable
    to simply test for d == NULL inside dict_var_resized and do
    nothing in that situation.

I'd prefer solution 1 if at all possible.



On Fri, May 01, 2009 at 05:29:46PM -0400, Jason Stover wrote:
     I was just testing the code in covariance-matrix.c and interaction.c.
     A pointer to a dictionary is null somewhere "down there" in
     dictionary.c, so I have a question about how dictionaries are created
     and populated.
     
     For completeness, below is a summary of the execution path. Everything
     looks OK to me until the code in dictionary.c. If you want to just
     skip to the problem, see the line marked PROBLEM below.
     
     The path of execution starts here, in a modified version of glm.q
     (http://math.gcsu.edu/~jhs/glm.q to see the whole file):
     
           size_t n_inter = 2;
           interaction_vars = xnmalloc (n_inter, sizeof (*interaction_vars));
           interaction_vars[0] = all_vars[0];
           interaction_vars[1] = all_vars[1];
           interactions[0] = interaction_variable_create (interaction_vars, 
n_inter);
     ...
     
     Then in interaction_variable_create (interaction_vars, n_inter) in
     src/math/interaction.c:
     
     struct interaction_variable *
     interaction_variable_create (const struct variable **vars, int n_vars)
     {
       struct interaction_variable *result = NULL;
       size_t i;
     
       if (n_vars > 0)
         {
           result = xmalloc (sizeof (*result));
           result->n_alpha = 0;
           result->members = xnmalloc (n_vars, sizeof (*result->members));
           result->intr = var_create_internal (0);
           result->n_vars = n_vars;
           for (i = 0; i < n_vars; i++)
           {
             result->members[i] = vars[i];
          if (var_is_alpha (vars[i]))
              {
                    result->n_alpha++;
              }
           }
         }
       /*
         VAR_SET_WIDTH sets the type of the variable.
        */
       var_set_width (result->intr, MAX_SHORT_STRING * result->n_alpha + 1);
     
     ...then to var_set_width:
     
           dict_var_resized (v, new_val_count - old_val_count);
     
     ...then to dict_var_resized, line 1050 of dictionary.c:
     
          for (i = 0; i < d->var_cnt; ++i)
     
     PROBLEM: d is null.
     
     My questions:
     
     1. Is d null because I haven't called some function that creates it
     yet? Or some other reason?  (Notice this all happens before passing
     through the data.)
     
     2. Where can I learn more about the relevant issue here?

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.


Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]