AllocSysObject ???

7 posts / 0 new
Last post
JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
AllocSysObject ???

The source below is compiled with

gcc guis:Dev/Gui4Cli_Dev/G4C_18/piper.c -gstabs -lauto -N -o g18:piper
and gives no errors or warnings.

The debug print statements observed are indicated with "seen"

  1. int main(void)
  2. {
  3. LONG ProgRET=20, c ;///d
  4. BOOL rxmsgreplied=0; ///, wnmsgreplied, flag=0;
  5. char *buff=NULL;/// *gcdata=NULL;
  6. int stop=0; ///, comret, INTUIisopen=0;
  7. struct RexxMsg *rxmsg = NULL;
  8. struct g4cmsg *gcmess= NULL;
  9. struct Remember *rkey=NULL;
  10. struct LaunchMessage *lmess; ///used also with xPIPE handling
  11. char *pt; ///*gp=NULL, *pt;
  12. ///struct GCmain *gd=NULL;
  13. strcpy (myportname, "Gui4Cli"); // * name of default port * /
  14. RexxSysBase = OpenLibrary ("rexxsyslib.library",45); //changed
  15. if (RexxSysBase)
  16. IRexxSys = (APTR)GetInterface(RexxSysBase, "main", 1L, NULL); //changed
  17. else PutStr("no RexxSysBase"); // not seen
  18. if (!(gd = (struct GCmain *)AllocRemember (&rkey, sizeof(struct GCmain), MEMF_CLEAR))) /// IIntuition->
  19. { PutStr("no GCmain obtained\n"); //not seen
  20. goto endprog;
  21. }
  22.  
  23. initgd ();
  24.  
  25. // ------------------------ get main buffers -----------------------
  26.  
  27. if (!(getbuffers(gd->buffsize, 0)))
  28. { PutStr("no buff obtained\n"); /// IDOS-> //not seen
  29. goto endprog;
  30. }
  31. buff = gd->membuff[0];
  32. // *------------------- Get default console ---------------------* /
  33.  
  34. // *------------------------- PASS to other Gui4Cli if running -----------* /
  35.  
  36. // *---------------------- Open Message ports ----------------------* /
  37.  
  38. // *------------------------ Open other libs etc.. -----------------------* /
  39. if ( ! IntuitionBase || !UtilityBase ) goto endprog;
  40. if ( ! IIntuition || !IUtility ) goto endprog;
  41. if ( ! DOSBase ) goto endprog;
  42. if ( ! IDOS ) goto endprog;
  43. if ( ! RexxSysBase ) goto endprog;
  44. if ( ! IRexxSys ) goto endprog;
  45.  
  46. Dp(PutStr("Main 7\n")); //seen
  47. Dp(Printf ("Findport %s \n", myportname)); /// Findport Gui4Cli seen
  48. Forbid (); //IExec-> taskscheduler
  49. if (FindPort(myportname)==NULL)
  50. {
  51. Dp(Printf ("Findport %s \n", myportname)); /// Findport Gui4Cli Seen
  52. myrxport=AllocSysObjectTags(ASOT_PORT, ASOPORT_Name, myportname, TAG_END); /// IExec->
  53. }
  54. Permit(); /// IExec->
  55. if (!myrxport)
  56. { Printf ("%s could not create myPorts\n", myportname); /// SEEN ???
  57. ProgRET = 20;
  58. goto endprog;
  59. }

I don't understand what could go wrong with the AllocSysObject here (copied from a source where it works oK.

What other tests could i add before these last lines ??

LyleHaze
LyleHaze's picture
Offline
Last seen: 1 year 4 months ago
Joined: 2011-05-26 03:58
Is it possible that you have

Is it possible that you have run out of signals?
The default for AllocSysObject(ASOT_PORT...) is to allocate a signal. If this allocation fails, I would expect the AllocSysObject() to fail as well.

Just one suggestion, but that would explain why the same code worked elsewhere but not here.

Good Luck!
LyleHaze

LyleHaze

Ami603
Ami603's picture
Offline
Last seen: 5 years 11 months ago
Joined: 2011-10-11 23:11
I'm not sure the

I'm not sure the AllocSysObject Call can work inside a pair of Forbid()/Permit() calls?

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Rather than putting the whole

Rather than putting the whole AllocSysObjectTags() call within Forbid()/Permit() you might want to do it like this:

  1. struct MsgPort *port, *oldport;
  2. port = AllocSysObjectTags(ASOT_PORT,
  3. ASOPORT_Name, portname,
  4. ASOPORT_Public, FALSE,
  5. TAG_END);
  6.  
  7. /* Add port only if no existing port of same name */
  8. Forbid();
  9. if ((oldport == FindPort(portname)) == NULL) {
  10. AddPort(port);
  11. }
  12. Permit();
  13.  
  14. /* Delete port and set to NULL if there was already a port by that name */
  15. if (oldport != NULL) {
  16. FreeSysObject(ASOT_PORT, port);
  17. port = NULL;
  18. }

As mentioned one reason the port allocation might fail is that all your task's user signals are already allocated (there are 16 of them). To check for this you might want to add a debug statement like this before the AllocSysObjectTags() call:

  1. Printf("tc_SigAlloc: 0x%lx\n", FindTask(NULL)->tc_SigAlloc);
JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
@salass00 I started adding

@salass00

I started adding your printf statement

  1. 8.Stock:Backup_Datas/Gui4Cli/Dev/Gui4Cli_Dev/G4C_18> piper
  2. Main 7
  3. Findport Gui4Cli
  4. Findport Gui4Cli
  5. tc_SigAlloc: 0xFFFF >>>>>>>>
  6. Gui4Cli could not create gdPorts

Is this correct or faulty ?

Anyway i found out that completing the initgd() function a bit more (adding the last line -presnt in the original

  1. void initgd()
  2. {
  3. gd->tab = 8; // tab size
  4. gd->buffsize = 1024; // old gd->buffsize
  5. // -------------------------- Message Ports ---------------------------
  6. gd->myself = (struct Process *)FindTask(NULL);
  7. gd->sendport = AllocSysObject (ASOT_PORT, TAG_END);
  8. }

seemed to solve the problem

I now get

  1. .Stock:Backup_Datas/Gui4Cli/Dev/Gui4Cli_Dev/G4C_18> piper
  2. Main 7
  3. Findport Gui4Cli
  4. Findport Gui4Cli
  5. tc_SigAlloc: 0x8000FFFF
  6. launch.h/launch_piper NoDbgOutput pipename pipe:MyPipe

The source changed with the improved intigd() and the additioanl debug Printf suggested
allready detects the presence of an axisting Gui4Cli port and exits upon its detection

  1. 8.Stock:Backup_Datas/Gui4Cli/Dev/Gui4Cli_Dev/G4C_18> piper
  2. Main 7
  3. Findport Gui4Cli
  4. Gui4Cli could not create myPorts
  5. 8.Stock:Backup_Datas/Gui4Cli/Dev/Gui4Cli_Dev/G4C_18>

giving the intended error message

Thanks to all for help

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
So the problem is solved

So the problem is solved now?

If all user signals were allocated the value of tc_SigAlloc would have been 0xFFFFFFFF. The low 16 bits are signals reserved for system use so they will always be allocated.

Also don't call Printf() or other dos.library/file I/O functions while in Forbid() as they will Wait() causing the forbid state to be broken.

JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
@salass00 So the problem is

@salass00

So the problem is solved now?

Yes, but it is not the last problem i have with this source.
thanks for suggestions

Log in or register to post comments