From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 26-JUN-1991 09:20:03.06
To:	ARISIA::EVERHART
CC:	
Subj:	Re: SMG$ - use with C or Fortran?

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.101)
	 id AA01240; Wed, 26 Jun 91 08:48:46 EDT
Received: From ucbvax.Berkeley.EDU ([128.32.133.1]) by CRVAX.SRI.COM with TCP; Wed, 26 JUN 91 05:35:22 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA16146; Wed, 26 Jun 91 05:27:17 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 26 Jun 91 21:12:26 GMT
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!waikato.ac.nz!comp.vuw.ac.nz!gp.co.nz!zl2tnm!don@ucbvax.Berkeley.EDU  (Don Stokes)
Organization: Computer Archaeologists
Subject: Re: SMG$ - use with C or Fortran?
Message-Id: <FV4543w163w@zl2tnm.gp.co.nz>
References: <11989@mirsa.inria.fr>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

furnish@zig.inria.fr (Geoffrey Furnish) writes:

> "Hi, I have a C program calling SMG, and I keep getting protection 
> violations.  I've checked my work very carefully, and I'm fairly certain
> there is no bug in my code."
> 
> "Are you using malloc?"
> 
> "Of course."
> 
> "Well that doesn't work.  You can't do that."

Sigh.  Yonks ago, I read the VAXC manual *very* carefully for gotchas
like this when moving to C for a project (involving SMG) and decided I
didn't like the wording regarding the support of memory allocation in a
multi-language environment.  Easily fixed:

        void *fix_malloc(int size) {
                char *addr;
                int sts, x;

                x = size + 4;
                sts = LIB$GET_VM(&x, &addr);
                if((sts & 1) == 0) return 0;
                (int) *addr = x;
                return addr + 4;
        }

        fix_free(char *addr) {
                char *x;

                x = addr - 4;
                LIB$FREE_VM(x, &x);
        }
 
Then in some .h file somewhere:

        #define malloc fix_malloc
        #define free fix_free

Does this help?

Don Stokes, ZL2TNM  /  /                             don@zl2tnm.gp.co.nz (home)
Systems Programmer /GP/ GP PRINT LIMITED  Wellington,       don@gp.co.nz (work)
__________________/  / ----------------   New_Zealand__________________________

