#Manx/AllocRemember()
17 messages in this thread
Well, I've hit another one I'm at a loss to explain. This one has to do with
the AllocRemember() function as called from C. Glenn and BobR and I beat on
this in CO tonight but couldn't get anywhere with it. Here's a minimal
program:
#include <functions.h>
#include <INTUITION/intuition.h>
#include <exec/memory.h>
#define NULL 0L
struct IntuitionBase *IntuitionBase;
struct Remember *RememberKey;
void main()
{
char *addr;
RememberKey=NULL;
addr=AllocRemember(&RememberKey,320L,0L);
FreeRemember(&RememberKey,TRUE);
}
This little baby crashes on the AllocRemember call with an Illegal
Instruction system trap vector (that's an 0…04 for those of you who read
GURUeze). I thought I was doing something wrong in the call for Manx, but
BobR compiled the pre-pared-down version under Lattice and _it_ crashed too,
in exactly the same manner. This surprises me, since the code is almost
verbatim from the RKM.
I'd surely appreciate it if someone could point out where the problem is here.
. Rick
P.S. As to my teaser message, I'm sorry to say that the method for stacking
two Insiders didn't pan out. Sorry to get your hopes up…
Richard,
I don't know what to say, I just debugged a copy of a program that I have
which calls AllocRemember() just like you guys do, and it works. Only
difference I can see is that I'm making calls with MEMF_CHIP, but even when I
changed the register to 0, it still worked……Hmm, didn't try it on the one
with a NULL remember key, tho…….Hmmm. let me try it again; I'll get back
to you if it does anything different.
Vic,
exec/memory.h defines MEMF_CHIP as (1L << 1) [better known as 2L], in
fact, there is no memory type defined as 0. That's more than likely the
problem.
Don
Nope. That was one of the two questions I originally had about the call, and I
tried it while we were conferencing last night. Bob and Glenn were informed
that this was not the problem when I suddenly disappeared. 8) I think I
substituted MEMF_FAST instead of _CHIP, but same difference.
As I read the RKM, the memory allocated has to fit all the requirements given
in flags. If no flags are set (0L), then the first block large enough to
accomodate the request will match, regardless of what kind of memory it is (of
course ADOS allocates fast RAM first). At least, that's the way I read it…
but I can't get my code to work. 8)
Rick
That's correct… I allocate with 0L for the memory type more often than not,
and it behaves as you describe. I've also used AllocRemember lots of times with
no crashes, so it _does_ work. The only problem I saw in your example was that
you didn't declare AllocRemember() itself (char *AllocRemember()), but I assume
you had that in your code and it wouldn't in any case explain a crash on the
AllocRemember call. Seems to me you're doing everything right, and the problem
has got to be somewhere else in your code… e.g. maybe you're doing a
deallocation incorrectly before that, corrupting the memory list, and the
AllocRemember call springs the trap… or something.
Nick
The problem, as Vic pointed out, is the lack of the OpenLibrary() call to open
Intuition.library. Consequently vectoring off of a NULL library base. It's so
obvious that we all missed it!
<banging head against wall>…Bob
Bob, that is a great example of overlooking the obvious, can't believe we
missed that in CO! <Glenn
Yeah, but at least you guys missing the obvious made ME feel better about
missing the obvious… I.E., at least I'm in good company. <Weak grin>
Rick
P.S. I guess it goes without saying that she works like a dream if you bother
to open Intuition first.
Nick,
Thanks for the feedback on the 0L flags.
AllocRemember() is already declared elsewhere, in memory.h, I think, so no help
there. And, as you said, that wouldn't cause this symptom anyway.
As to problems somewhere else in my code, there AIN'T no more code! That
little snippet is a complete, stand-alone program that… wait a minute…
Oh *NO!* AIEEEEE!!! <Sound of head being bashed repeatedly against desktop>
There, that feels better… <groan>.
<Sigh> Nick Et. Al., it is to blush. We're talking major-league blush. I
wanted to try out this change to the code without disturbing the rest of the
program, so I whipped up a little test routine. But in the course of so doing
I, er, um, well, <mumble grr curse> AWRITE!!! I ADMIT IT! I FORGOT TO OPEN
INTUITION! AAAAAARRRRRRGHHHHHHH!
This one is so bad I was almost tempted to try to let it slide into forgotten
memory, hoping no one would ever ask how it turned out. But I can't do that,
you folks are too good to me. <Sigh> So, I freely admit it: I pulled a real
bonehead move here. I haven't tried the code with Intuition open and running
yet, but it has to work a lot better. <Weak grin>
Please, be gentle.
Rick
Gee Rick,
I thought intuition opened automatically. It does for me. Fingers seem to
just bang it in without hardly thinking about it. Of course I don't use
langauges that either let me get away with that. Glad ya found it.
Regards, Larry.
Rick: well, I _told_ you it was something earlier in the code. 🙂 Like the dog
in the Sherlock Holmes story, it's often harder to obvious thing that's missing
than the subtle thing that's there.
Nick
Vic, if you're running Manx, would you mind compiling MY code and see if it
crashes for you? OR, build a minimal representation of your code that works
and give it to me. Part of my problem is I have no working AllocRemember()
code. If I had one example that worked, I could beat out the problem.
Thanks!
Rick
If you still need working code, let me know — I've got lots of AllocRemember()
stuff.
Richard,
I don't have the MANX stuff here at home, but here is a program that does
work.
#include <INTUITION/intuition.h>
#include <proto/intuition.h>
#include <exec/memory.h>
struct IntuitionBase *IntuitionBase;
struct Remember *RememberKey;
void main()
{
#define INTUITION_REV LIBRARY_VERSION
char *addr;
RememberKey=NULL;
/* Open the Intuition library. The result returned by this call is
* used to connect your program to the actual Intuition routines
* in ROM. If the result of this call is equal to zero, something
* is wrong and the Intuition you requested is not available, so
* your program should exit immediately
*/
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", INTUITION_REV);
if (IntuitionBase == NULL) exit(FALSE);
addr=AllocRemember(&RememberKey,320L,0L);
FreeRemember(&RememberKey,TRUE);
}
<Sigh> Thanks, but I think I found the problem… see an associated message
elsewhere <and don't laugh too loudly>.
Rick
Rick,
See 97112, there is no memory type 0L…that's probably the problem.
Also, to be absolutely correct, you should cast NULL to a struct Remember *
doing the assignment. I doubt that's a problem thou.
Don
Don,
See my reply to Larry re the 0L memory type; let me know if it seems
reasonable. As to the cast, I think I tried it, but I'll try it again.
Rick