Welcome, Guest. Please login or register.

Author Topic: Where's da bug  (Read 3229 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Where's da bug
« on: August 31, 2004, 09:19:40 PM »
if (!(buffertask = (MsgPort *)CreateProc(Buffertaskname, 0L, buffertaskSegList, 1000L)))
  {printf("coudn't create MDBuffer/n");
   unloadseg......}
.........
.......


I'm getting Error 76 identifier expected or something with VBCC..

By the way, do I really need to cast it (eg. (MsgPort *) ) ? I was getting another error before I added that. The variable holding the result (buffertask) is declared as struct MsgPort *buffertask so I can't see what was the problem.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Slash

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 112
  • Country: gb
  • Gender: Male
    • Show only replies by Slash
    • http://www.the-snakepit.co.uk
Re: Where's da bug
« Reply #1 on: August 31, 2004, 09:25:07 PM »
Should buffertask not be a "struct Process *" e.g.

struct Process *buffertask = NULL;

buffertask = (struct Process *)CreateNewProc(...)

That's how I create my new processes. I think CreateProc is obsolete now. Use CreateNewProc.
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Where's da bug
« Reply #2 on: August 31, 2004, 09:40:31 PM »
@Slash

Yes, CreatePro is obsolete but I want the code to also conditionally run on 1.3 :-)

I tried it with a struc process instead and it seems to work.
I can't really say if it works because till now VBCC was outputting the errors then crashing. Now it's just crashing after I run it so I assume there are no errors left..(don't bother asnwering I'm gonna start a new thread about my VBCC crashes.)..
 
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Where's da bug
« Reply #3 on: August 31, 2004, 09:59:45 PM »
I'm curious to know if it is really necessary to do the casting to struct *process when using CreatePro, or CreateNewProc...
In theory both should return that type so it shouldn't be necessary right?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline itix

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 2380
    • Show only replies by itix
Re: Where's da bug
« Reply #4 on: August 31, 2004, 10:10:44 PM »
Funny but my autodocs are saying that CreateProc() returns struct MsgPort * ...
My Amigas: A500, Mac Mini and PowerBook
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Where's da bug
« Reply #5 on: August 31, 2004, 10:13:41 PM »
Documentation error?

As far as I recall, CreateMsgPort() should return struct MsgPort*, not CreateProc().

In any event, CreateNewProc() is a bit more useful IMHO.
int p; // A
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Where's da bug
« Reply #6 on: August 31, 2004, 10:23:09 PM »
@itix

Ahh, yes!
Mine too!
So that's probably why casting is needed
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Where's da bug
« Reply #7 on: August 31, 2004, 10:29:26 PM »
Hmm, I checked the structures and the Process structure starts with a task structure followed by the MsgPort.
CreateProc returns the MsgPort according to the docs, so I think if I cast it fo a Process it's an error. Should be a MsgPort after all. Which brings me back to my first error(first post)!!
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline itix

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 2380
    • Show only replies by itix
Re: Where's da bug
« Reply #8 on: August 31, 2004, 10:30:16 PM »
Quote
Documentation error?

As far as I recall, CreateMsgPort() should return struct MsgPort*, not CreateProc().

It is funny but looks intentional. Even my good old RKRM: Includes and Autodocs is saying CreateProc() returns struct MsgPort *.
My Amigas: A500, Mac Mini and PowerBook
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Where's da bug
« Reply #9 on: August 31, 2004, 10:38:52 PM »
Quote

Jose wrote:
Hmm, I checked the structures and the Process structure starts with a task structure followed by the MsgPort.
CreateProc returns the MsgPort according to the docs, so I think if I cast it fo a Process it's an error. Should be a MsgPort after all. Which brings me back to my first error(first post)!!


If you cast any struct X* to struct Y* and the first member struct X is not an object of type struct Y, then the cast is badly broken. You need to account for the offset of struct Y within the struct X.

I don't see that a struc MsgPort* pointer is safely castable to struct Process* unless you absolutely know for a fact that the MsgPort structure pointed to is really a member of a Process. Even then you will have to do some pointer arithmetic (or use offsetof()) to properly determing the address of the Process structure within which your MsgPort object is situated.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Where's da bug
« Reply #10 on: August 31, 2004, 10:47:26 PM »
Checked the RKMs and it does indeed return struct MsgPort* :-o

It also says that it creates a struct Process and returns it's message port.

So, I'd suggest the following dodgyness to obtain the address of the Process structure within which the MsgPort resides:

#include /* for offsetof() macro */

UBYTE* portAddr = (UBYTE*)CreateProc(.....); /* UBYTE for simple pointer arithmetic */

struct Process* process = (struct Process*)(portAddr - offsetof(struct Process, pr_MsgPort));

int p; // A
 

Offline itix

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 2380
    • Show only replies by itix
Re: Where's da bug
« Reply #11 on: August 31, 2004, 10:53:18 PM »
Quote
if (!(buffertask = (MsgPort *)CreateProc(Buffertaskname, 0L, buffertaskSegList, 1000L)))

Your casting is wrong. It should be (struct MsgPort *), just (MsgPort *) alone is nothing and VBCC complains.

And, do you have:

struct Process *buffertask;

?

If so, it is broken because it is not returning struct Process *...
My Amigas: A500, Mac Mini and PowerBook
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Where's da bug
« Reply #12 on: September 01, 2004, 01:03:55 AM »
@itix
yes, silly me....forgot to add the type "struct"  to the cast... 8-)
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Where's da bug
« Reply #13 on: September 01, 2004, 01:30:34 AM »
@Karlos

Usefull. Shouldn't that be a long instead of a byte?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Where's da bug
« Reply #14 on: September 01, 2004, 03:09:08 AM »
This struct MsgPort * return value is some good'ol BCPL legacy. BCPL CreateProc returns this, and so does the old dos function.

Actually BCPL considered address of Process' pr_MsgPort to be "process pointer" rather than 'struct Process *'. Processes were referenced by their pr_MsgPort address, too. Also address of various other pr_#? fields were calculated relative to pr_MsgPort, which gave some rather funky negative or positive offsets.