home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / amiga / programm / 12883 < prev    next >
Encoding:
Text File  |  1992-08-30  |  5.6 KB  |  166 lines

  1. Path: sparky!uunet!wupost!waikato.ac.nz!comp.vuw.ac.nz!canterbury.ac.nz!betelgeux!cree
  2. Newsgroups: comp.sys.amiga.programmer
  3. Subject: Boopsi custom gadget problem
  4. Message-ID: <1992Aug31.134444.571@csc.canterbury.ac.nz>
  5. From: cree@elec.canterbury.ac.nz (Michael Cree)
  6. Date: 31 Aug 92 13:44:41 +1200
  7. Organization: Electrical Engineering, University of Canterbury, New Zealand
  8. Keywords: Boopsi, custom gadget.
  9. Summary: Having problems implementing custom gadget. Require help.
  10. Nntp-Posting-Host: elec.canterbury.ac.nz
  11. X-Newsreader: Tin 1.1 PL5
  12. Lines: 152
  13.  
  14. I am having a problem implementing a string gadget as a subclass of
  15. 'strgclass'. The idea is to to have a longint gadget that limits the
  16. input value to be within minimun and maximun values. On a go inactive
  17. command it checks the value and if not in range calls DoSuperMethod on
  18. the superclass with the command OM_SET to put it back in range.
  19.  
  20. This, in fact, works from the viewpoint of the user running the code,
  21. however a check of memory afterwards finds 8 bytes not freed. I then
  22. run mungwall which illuminates the problem further. It reports a
  23. mismatched FreeMem of 15 bytes when it should be 20 bytes (hence the
  24. lost 8 bytes) and then causes the programme to crash with a CPU trap
  25. (think it was illegal address violation). This all happens when the
  26. programme is exiting and deallocating the string gadget class I
  27. implemented. Using the owner command on the address from which the
  28. FreeMem was called reports that it occured somewhere in the intuition
  29. library ROM code, but doesn't identify which routine.
  30.  
  31. I am at complete loss as to understanding why this is happening. Any
  32. help would be appreciated. The code implementing the custom gadget
  33. follows. It, at present, assumes the calling programme passes the tag
  34. STRINGA_LongInt as part of the taglist when allocating an object.
  35. Also, MSTRINGA_MinVal (MSTRINGA_MaxVal) is defined as one(two) plus the
  36. user tag identifier. This was run on a basic A500+ (thus version 37
  37. ROMS) with 1MB of chip, no fast memory  and a DataFlyer IDE hard drive.
  38.  
  39. Michael
  40.  
  41. -----------------------Code folows----->
  42.  
  43. /* For mstrgclass */
  44.  
  45. struct nlimits {                /* Structure to hold min and max values. */
  46.    LONG min,max;
  47. };
  48.  
  49. int GadgAct;                   /* These are flags for testing purposes. */
  50. int GadgWhy;
  51.  
  52.  
  53. Class *
  54. initMStrGClass()
  55. {
  56.    ULONG hookEntry();
  57.    Class *cl;
  58.    Class *MakeClass();
  59.  
  60.    if ( cl =  MakeClass( NULL, "strgclass", NULL, sizeof(struct nlimits), 0 )) {
  61.       cl->cl_Dispatcher.h_Entry = hookEntry;
  62.       cl->cl_Dispatcher.h_SubEntry = dispatchMStrG;
  63.       cl->cl_Dispatcher.h_Data = (VOID *) 0xFACE;
  64.       GadgAct = 0;
  65.    }
  66.    return ( cl );
  67. }
  68.  
  69.  
  70.  
  71. BOOL freeMStrGClass( cl )
  72. Class *cl;
  73. {
  74.    return ( FreeClass( cl )  );
  75. }
  76.  
  77.  
  78.  
  79. ULONG dispatchMStrG( cl, o, msg )
  80. Class   *cl;
  81. Object  *o;
  82. Msg     msg;
  83. {
  84.    struct gpGoInactive *gpg;
  85.    Object *no;
  86.    struct nlimits *nl;
  87.    struct opSet *ops;
  88.    struct TagItem *ti;
  89.    struct StringInfo *si;
  90.    struct TagItem taglist[2];
  91.  
  92.    geta4();
  93.    switch ( msg->MethodID ) {
  94.    case OM_NEW:
  95.       D(bug("Hit OM_NEW in gadget\n"));
  96.       if (no = (Object *)DoSuperMethodA(cl,o,msg)) {
  97.          D(bug( "  Got object at 0x%lx", no));
  98.          nl = INST_DATA(cl, no);
  99.          D(bug( " My data is at 0x%lx and of length %ld.\n",nl,cl->cl_InstSize));
  100.          ops = (struct opSet *)msg;
  101.          D(bug( "  Doing tagitems\n" ));
  102.          if (ti = FindTagItem(MSTRINGA_MinVal,ops->ops_AttrList))
  103.             nl->min = ti->ti_Data;
  104.          else
  105.             nl->min = 0x80000000;
  106.          if (ti = FindTagItem(MSTRINGA_MaxVal,ops->ops_AttrList))
  107.             nl->max = ti->ti_Data;
  108.          else
  109.             nl->max = 0x7fffffff;
  110.       }
  111.       D(bug("...Done\n"));
  112.       return (ULONG)no;
  113.    case OM_SET:
  114.       D(bug( "Doing OM_SET ...\n"));
  115.       nl = INST_DATA(cl, o);
  116.       D(bug("  My data is at 0x%lx.\n",nl));
  117.       ops = (struct opSet *)msg;
  118.       if (ti = FindTagItem(MSTRINGA_MinVal,ops->ops_AttrList)) {
  119.          D(bug( "   MSTRINGA_MinVal present.\n" ));
  120.          nl->min = ti->ti_Data;
  121.       }
  122.       if (ti = FindTagItem(MSTRINGA_MaxVal,ops->ops_AttrList)) {
  123.          D(bug( "   MSTRINGA_MaxVal present.\n" ));
  124.          nl->max = ti->ti_Data;
  125.       }
  126.       if (ti = FindTagItem(STRINGA_LongVal,ops->ops_AttrList)) {
  127.          if (ti->ti_Data < nl->min) ti->ti_Data = nl->min;
  128.          if (ti->ti_Data > nl->max) ti->ti_Data = nl->max;
  129.       }
  130.       D(bug("...Done\n"));
  131.       return ( (ULONG) DoSuperMethodA( cl, o, msg ) );
  132.    case GM_GOINACTIVE:
  133.       D(bug( "Doing GM_GOINACTIVE\n"));
  134.       gpg = (struct gpGoInactive *)msg;
  135.       GadgWhy = gpg->gpgi_Abort;
  136.       nl = INST_DATA(cl, o);
  137.       D(bug("  My data is at 0x%lx.\n",nl));
  138.       si = ((struct Gadget *)o)->SpecialInfo;
  139.       taglist[0].ti_Tag = STRINGA_LongVal;
  140.       taglist[1].ti_Tag = TAG_DONE;
  141.       if (si->LongInt < nl->min) {
  142.          taglist[0].ti_Data = nl->min;
  143.          DoSuperMethod(cl,o,OM_SET,taglist,gpg->gpgi_GInfo);
  144.       }
  145.       if (si->LongInt > nl->max) {
  146.          taglist[0].ti_Data = nl->max;
  147.          DoSuperMethod(cl,o,OM_SET,taglist,gpg->gpgi_GInfo);
  148.       }
  149.       D(bug( " Falling through now...\n"));
  150.    case GM_GOACTIVE:
  151.       GadgAct = (msg->MethodID == GM_GOACTIVE);
  152.       D(bug("...Done\n"));
  153.    default:
  154.       return ( (ULONG) DoSuperMethodA( cl, o, msg ) );
  155.    }
  156.  
  157.    return FALSE;
  158. }
  159.  
  160. -----------------------------------------------------------------------------
  161. Michael Cree                              Gold there is
  162. cree@elec.canterbury.ac.nz                 and rubies in abundance;
  163.                                           But lips that speak knowledge
  164.                                            are a rare jewel. (Prov 20:15)
  165. ------------------------------------------------------------------------------
  166.