CompuServe Thread

#Manx/AllocRemember()

17 messages in this thread
#97044From: Richard Rae/SYSOPDec 6, 1987 9:41 PM
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…
#97083From: Vic WagnerDec 6, 1987 11:31 PM
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.
#97112From: Don Curtis/SYSOPDec 7, 1987 1:45 AM
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
#97153From: Richard Rae/SYSOPDec 7, 1987 1:18 PM
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
#97327From: Nick Sullivan/TransactorDec 8, 1987 12:26 PM
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
#97335From: Bob RakoskyDec 8, 1987 3:24 PM
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
#97412From: Glenn NielsenDec 8, 1987 9:16 PM
Bob, that is a great example of overlooking the obvious, can't believe we missed that in CO! <Glenn
#97588From: Richard Rae/SYSOPDec 9, 1987 10:54 PM
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.
#97345From: Richard Rae/SYSOPDec 8, 1987 4:33 PM
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
#97429From: John DraperDec 8, 1987 11:39 PM
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.
#97489From: Nick Sullivan/TransactorDec 9, 1987 5:35 AM
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
#97154From: Richard Rae/SYSOPDec 7, 1987 1:18 PM
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
#97163From: Steve AhlstromDec 7, 1987 1:57 PM
If you still need working code, let me know — I've got lots of AllocRemember() stuff.
#97196From: Vic WagnerDec 7, 1987 8:46 PM
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); }
#97346From: Richard Rae/SYSOPDec 8, 1987 4:33 PM
<Sigh> Thanks, but I think I found the problem… see an associated message elsewhere <and don't laugh too loudly>. Rick
#97113From: Don Curtis/SYSOPDec 7, 1987 1:47 AM
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
#97155From: Richard Rae/SYSOPDec 7, 1987 1:19 PM
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