OSErr QTDR_AddInitDataDataRefExtension (Handle theDataRef, Ptr theInitDataPtr) { unsigned long myAtomHeader[2]; OSErr myErr = noErr; if (theInitDataPtr == NULL) return(paramErr); myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + GetPtrSize(theInitDataPtr)); myAtomHeader[1] = EndianU32_NtoB(kDataRefExtensionInitializationData); myErr = PtrAndHand(myAtomHeader, theDataRef, sizeof(myAtomHeader)); if (myErr == noErr) myErr = PtrAndHand(theInitDataPtr, theDataRef, GetPtrSize(theInitDataPtr)); return(myErr); }
Size GetDataSize(LinkedList *theList,unsigned long element) { ElementHandle moo=GetElement(theList,element); if (*moo) return GetPtrSize((**moo).data); else return 0L; }
tdata_t _TIFFrealloc(tdata_t p, tsize_t s) { Ptr n = p; SetPtrSize(p, (size_t) s); if (MemError() && (n = NewPtr((size_t) s)) != NULL) { BlockMove(p, n, GetPtrSize(p)); DisposePtr(p); } return ((tdata_t) n); }
void * _TIFFrealloc(void* p, size_t s) { Ptr n = p; SetPtrSize(p, s); if (MemError() && (n = NewPtr(s)) != NULL) { BlockMove(p, n, GetPtrSize(p)); DisposePtr(p); } return (n); }
// This is the most overloaded routine I've seen in a long time. void *realloc( void *pointer, size_t size) { if ((pointer==NULL) && (size!=0)) { return NewPtr(size); } if (size==0) { if (pointer) DisposePtr((Ptr)pointer); return NULL; } if (size==GetPtrSize((Ptr)pointer)) return pointer; SetPtrSize((Ptr)pointer, size); // SetPtrSize can fail if the pointer couldn't be expanded in place if (MemError()) { Size old_size= GetPtrSize((Ptr)pointer); Ptr realloced_pointer= NewPtr(size); // so we make a whole new one if possible if (MemError()) return NULL; // and copy the data into it. BlockMoveData(pointer, realloced_pointer, old_size > size ? size : old_size); // and then destroy the old pointer DisposePtr((Ptr)pointer); return realloced_pointer; } return pointer; }
/** \brief Add a Variable pointer to bytecode. \param a_pVar Pointer to be added. \throw nothrow */ void ParserByteCode::AddVar(value_type *a_pVar) { m_vBase.push_back( ++m_iStackPos ); m_vBase.push_back( cmVAR ); StorePtr(a_pVar); int iSize = GetValSize()-GetPtrSize(); assert(iSize>=0); // Make sure variable entries have the same size like value entries. // (necessary for optimization; fill with zeros) for (int i=0; i<iSize; ++i) m_vBase.push_back(0); }
ostream& repMemory(ostream& s){ extern long noObjects; s <= "noObjects is " <= noObjects <= "\nobjectMemory is "; repMemSize(s,objectMemory); s <= "\n"; extern TEHandle debuggingTextHandle; long textSize=0; if(debuggingTextHandle){ textSize=GetHandleSize((**debuggingTextHandle).hText); } extern Boolean rosterOK; long freeLanceSize=0; if(rosterOK){ extern FList *handleRoster; long num=handleRoster->numItems; long size=0; for(long i=2;i<=num;++i){ size+=GetHandleSize((char**)handleRoster->NthItem(i)); } s <= "number of handles is " <= num-1 <= ", total of "; repMemSize(s,size); s <= "\n"; extern FList *ptrRoster; num=ptrRoster->numItems; freeLanceSize=size; size=0; for(i=2;i<=num;++i){ size+=GetPtrSize((char*)ptrRoster->NthItem(i)); } s <= "number of pointers is " <= num-1 <= ", total of "; repMemSize(s,size); s <= "\n"; freeLanceSize+=size; } extern long totalMemory,objectMemory; long grow,memoryLoss; memoryLoss=totalMemory-(FreeMem()+textSize +objectMemory+freeLanceSize); s <= "LOST MEMORY "; repMemSize(s,memoryLoss); s <= "\n"; return s; }
void *pgp_realloc(void *orig, long newLen) { #ifdef PGP_MACINTOSH Ptr newSpace; long oldLen; if(orig) SetPtrSize((Ptr)orig, newLen); else orig=NewPtr(newLen); if(MemError()) { if((newSpace = NewPtr(newLen)) != NULL) { oldLen=GetPtrSize((Ptr)orig); BlockMove(orig, newSpace, oldLen); DisposePtr((Ptr)orig); orig=newSpace; } else orig = NIL; } return orig; #elif PGP_WIN32 void *ptr = NULL; #ifdef _DEBUG if (!HeapValidate(heapID, 0, NULL)) DebugLog("validation failed before reallocating %d bytes at %p", newLen, ptr); #endif // _DEBUG ptr = HeapReAlloc(heapID, HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY, ptr, newLen); #ifdef _DEBUG if (!HeapValidate(heapID, 0, NULL)) DebugLog("validation failed after reallocating %d bytes at %p", newLen, ptr); #endif // _DEBUG return ptr; #endif // PGP_WIN32 }
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef, AEDesc *pObjSpecifier){ OSErr anErr = paramErr; if (nil != pCFURLRef) { Boolean isDirectory = CFURLHasDirectoryPath(pCFURLRef); CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef, kCFURLHFSPathStyle); AEDesc containerDesc = { typeNull, NULL }; AEDesc nameDesc = { typeNull, NULL }; UniCharPtr buf = nil; if (nil != tCFStringRef) { Size bufSize = ( CFStringGetLength(tCFStringRef) + ( isDirectory ? 1 : 0 ) ) * sizeof( UniChar ); buf = (UniCharPtr) NewPtr(bufSize); if ( ( anErr = MemError() ) == noErr) { CFStringGetCharacters(tCFStringRef, CFRangeMake(0, bufSize / 2), buf); if (isDirectory) ( buf )[ ( bufSize - 1 ) / 2 ] = (UniChar) 0x003A; } } else anErr = coreFoundationUnknownErr; if (anErr == noErr) anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize( (Ptr) buf), &nameDesc); if (anErr == noErr) if (isDirectory) { anErr = CreateObjSpecifier(cFolder, &containerDesc, formName, &nameDesc, false, pObjSpecifier); } else { anErr = CreateObjSpecifier(cFile, &containerDesc, formName, &nameDesc, false, pObjSpecifier); } MoreAEDisposeDesc(&nameDesc); if (buf) DisposePtr( (Ptr) buf); } return anErr; }
Size DumpLinkedList(LinkedList *theList,unsigned char *destPtr,Size bufferSize) { ElementHandle moo=theList; // the address of a linked list Size copiedSize=0L,elementSize; while (*moo) { elementSize=GetPtrSize((**moo).data); if (elementSize>(bufferSize-copiedSize)) // too big!, time to go return copiedSize; BlockMove((**moo).data,destPtr,elementSize); destPtr+=elementSize; copiedSize+=elementSize; // get next element moo=(ElementHandle)&((**moo).next); } return copiedSize; }
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef,AEDesc *pObjSpecifier) { OSErr anErr = paramErr; if (NULL != pCFURLRef) { CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef,kCFURLHFSPathStyle); anErr = coreFoundationUnknownErr; if (NULL != tCFStringRef) { Boolean isDirectory = CFURLHasDirectoryPath(pCFURLRef); AEDesc containerDesc = {typeNull, NULL}; AEDesc nameDesc = {typeNull, NULL}; Size bufSize = (CFStringGetLength(tCFStringRef) + (isDirectory ? 1 : 0)) * sizeof(UniChar); UniCharPtr buf = (UniCharPtr) NewPtr(bufSize); if ((anErr = MemError()) == noErr) { CFStringGetCharacters(tCFStringRef, CFRangeMake(0,bufSize/2), buf); if (isDirectory) (buf)[(bufSize-1)/2] = (UniChar) 0x003A; } if (anErr == noErr) anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize((Ptr) buf), &nameDesc); if (anErr == noErr) { if (isDirectory) // we use cObject here since this might be a package (and we have no way to tell) anErr = CreateObjSpecifier(cObject, &containerDesc, formName, &nameDesc, false, pObjSpecifier); else anErr = CreateObjSpecifier(cFile, &containerDesc, formName, &nameDesc, false, pObjSpecifier); } MoreAEDisposeDesc(&nameDesc); if (buf) DisposePtr((Ptr)buf); } } return anErr; }//end MoreAEOCreateObjSpecifierFromCFURLRef
void *_realloc_r(struct _reent *reent_ptr, void *ptr, size_t sz) { if(ptr == NULL) { Ptr p = NewPtr(sz); if(!p) errno = ENOMEM; return p; } else { MemError(); SetPtrSize(ptr, sz); if(MemError()) { size_t oldSz = GetPtrSize(ptr); if(sz > oldSz) { void *newPtr = NewPtr(sz); if(!newPtr) { errno = ENOMEM; return NULL; } memcpy(newPtr, ptr, oldSz); return newPtr; } else { errno = ENOMEM; return NULL; } } else return ptr; } }
Boolean SizeElementProc(Ptr dataPtr,long *refCon,unsigned long count) { (*refCon)+=GetPtrSize(dataPtr); return true; }
Boolean DupeElementProc(Ptr dataPtr,long *refCon,unsigned long count) { LinkedList *toMe=(LinkedList*)refCon; return AddElement(dataPtr,GetPtrSize(dataPtr),toMe); }
OSErr mainULT( OSType order, Ptr AlienFileName, MADMusic *MadFile, PPInfoRec *info, MADDriverSettings *init) { OSErr myErr = noErr; Ptr AlienFile; UNFILE iFileRefI; long sndSize; switch( order) { case 'IMPL': iFileRefI = iFileOpen(AlienFileName); if( iFileRefI) { sndSize = iGetEOF( iFileRefI); // ** MEMORY Test Start AlienFile = MADPlugNewPtr( sndSize * 2, init); if( AlienFile == NULL) myErr = MADNeedMemory; // ** MEMORY Test End else { DisposePtr( AlienFile); AlienFile = MADPlugNewPtr( sndSize, init); if( AlienFile == NULL) myErr = MADNeedMemory; else { myErr = iRead(sndSize, AlienFile, iFileRefI); if( myErr == noErr) { myErr = TestULTFile( AlienFile); if( myErr == noErr) { myErr = ConvertULT2Mad( AlienFile, GetPtrSize( AlienFile), MadFile, init); } } } DisposePtr( AlienFile); AlienFile = NULL; } iClose( iFileRefI); } else myErr = MADReadingErr; break; case 'TEST': iFileRefI = iFileOpen(AlienFileName); if( iFileRefI) { sndSize = 1024L; AlienFile = MADPlugNewPtr( sndSize, init); if( AlienFile == NULL) myErr = MADNeedMemory; else { myErr = iRead(sndSize, AlienFile, iFileRefI); if (myErr == noErr) myErr = TestULTFile( AlienFile); DisposePtr( AlienFile); AlienFile = NULL; } iClose( iFileRefI); } else myErr = MADReadingErr; break; case 'INFO': iFileRefI = iFileOpen(AlienFileName); if( iFileRefI) { info->fileSize = iGetEOF( iFileRefI); sndSize = 5000L; // Read only 5000 first bytes for optimisation AlienFile = MADPlugNewPtr( sndSize, init); if( AlienFile == NULL) myErr = MADNeedMemory; else { myErr = iRead(sndSize, AlienFile, iFileRefI); if( myErr == noErr) { myErr = ExtractULTInfo( info, AlienFile); } DisposePtr( AlienFile); AlienFile = NULL; } iClose( iFileRefI); } else myErr = MADReadingErr; break; default: myErr = MADOrderNotImplemented; break; } return myErr; }
static OSErr mainQTInst(void *unused, OSType order, // Order to execute InstrData *InsHeader, // Ptr on instrument header sData **sample, // Ptr on samples data short *sampleID, // If you need to replace/add only a sample, not replace the entire instrument (by example for 'AIFF' sound) // If sampleID == -1 : add sample else replace selected sample. CFURLRef AlienFileURLRef, // IN/OUT file PPInfoPlug *thePPInfoPlug) { MADErr myErr = MADNoErr; FSIORefNum iFileRefI = -1; ByteCount inOutBytes; FSSpec tmpSpec; OSErr QTErr = noErr; myErr = CFURLToFSSpec(AlienFileURLRef, &tmpSpec); switch (myErr) { case memFullErr: return MADNeedMemory; break; default: case fnfErr: return order == MADPlugExport ? MADWritingErr : MADReadingErr; break; case noErr: break; } switch (order) { case MADPlugPlay: break; case MADPlugImport: { Ptr theSound; int lS, lE; short sS; unsigned long rate; bool stereo; FSSpec newFile; myErr = ConvertDataToWAVE(tmpSpec, &newFile, thePPInfoPlug); if (myErr == noErr) { theSound = ConvertWAV(&newFile, &lS, &lE, &sS, &rate, &stereo); if (theSound) { long sndSize = GetPtrSize(theSound); Ptr newSound = malloc(sndSize); memcpy(newSound, theSound, sndSize); DisposePtr(theSound); myErr = inAddSoundToMAD(newSound, sndSize, lS, lE, sS, 60, rate, stereo, newFile.name, InsHeader, sample, sampleID); } else { myErr = MADNeedMemory; } FSpDelete(&newFile); } } break; case MADPlugTest: { Boolean canOpenAsMovie = false; FInfo fInfo; FSpGetFInfo(&tmpSpec, &fInfo); QTErr = CanQuickTimeOpenFile(&tmpSpec, fInfo.fdType, 0, NULL, &canOpenAsMovie, NULL, 0); if (QTErr == noErr && canOpenAsMovie == true) { myErr = MADNoErr; } else { myErr = MADIncompatibleFile; } } break; case MADPlugExport: if (*sampleID >= 0) { OSType compType = 'NONE'; unsigned long rate; sData *curData = sample[*sampleID]; short numChan; FSpDelete(&tmpSpec); myErr = FSpCreate(&tmpSpec, 'TVOD', 'AIFF', smCurrentScript); if(myErr == noErr) myErr = FSpOpenDF(&tmpSpec, fsCurPerm, &iFileRefI); if (myErr == noErr) { inOutBytes = curData->size; rate = curData->c2spd; if (curData->stereo) numChan = 2; else numChan = 1; myErr = SetupAIFFHeader(iFileRefI, numChan, rate << 16L, curData->amp, compType, inOutBytes, 0); if(myErr == noErr) myErr = FSWriteFork(iFileRefI, fsAtMark, 0, inOutBytes, curData->data, &inOutBytes); FSCloseFork(iFileRefI); } } break; default: myErr = MADOrderNotImplemented; break; } return myErr; }
OSErr OpenCTBConnection(ConnHandle* connection) { Str255 toolName; Point where; Ptr configStream; Ptr tempString; EventRecord event; Rect dialogLoc; OSErr error = noErr; char* here; char* end; long baud; Boolean done; short result = noErr; if (*connection != nil) { // put our A5 value into the connection record so that the search callbacks // can get it and restore it CMSetUserData(*connection,(long) LMGetCurrentA5()); // CMChoose Dialog has to hang off this point (global coordinates) SetRect(&dialogLoc, 0, 0, 495, 285); CenterOnCurrentScreen(&dialogLoc); where.h = dialogLoc.left; where.v = dialogLoc.top; // now do CMChoose et al: done = false; do { result = CMChoose(connection, where, NULL); // MAD fprintf(mfp,"result is %d. major = %d minor = %d\n",result,chooseOKMajor,chooseOKMinor); if ((result == chooseOKMajor) || (result == chooseOKMinor)) { configStream = CMGetConfig(*connection); if (configStream == NULL) { done = true; error = -1; } else { CMGetToolName((***connection).procID, toolName); tempString = NewPtrClear(GetPtrSize(configStream) + 5); strcpy(tempString, "Baud "); here = strstr(configStream, tempString); if (here != nil) { here += strlen(tempString); baud = strtol(here, &end, 10); if (baud < 38400) { // MAD: PC seems to default to this, baud = 38400; // no matter what the user tries to set! strcpy(tempString, configStream); sprintf(tempString + (here - configStream), "%ld", baud); strcat(tempString, end); error = CMSetConfig(*connection, tempString); // Try to use the modified configuration if (error == noErr) { // It worked; save it DisposePtr(configStream); configStream = NewPtrClear(GetPtrSize(tempString)); memcpy(configStream, tempString, GetPtrSize(tempString)); DisposePtr(tempString); } } } strcpy(tempString, "CTS"); here = strstr(configStream, tempString); if (here != nil) { result = CautionAlert(CTSWarningdlog, nil); if (result == 2) { // The Continue option error = CreateConfigRes(configStream); error = CreateToolNameRes(toolName); done = true; } } else { error = CreateConfigRes(configStream); // MAD fprintf(mfp,"CreateConfigRes = %d\n",error); error = CreateToolNameRes(toolName); // MAD fprintf(mfp,"CreateToolNames = %d\n",error); done = true; } DisposePtr(configStream); } } else { //ErrorTerminate(-2, "\pее CMChoose failed. ее"); // MAD fprintf(mfp,"CMChoose failed\n"); if (*connection != nil) { CMDispose(*connection); *connection = nil; } error = -2; done = true; } } while (!done); // open the connection, send some data, and then close the connection if (error == noErr) { error = CMOpen(*connection, false, nil, 0); // MAD fprintf(mfp,"CMOpen = %d\n",error); } } return error; }
static OSStatus UnpackPEFDataSection(const UInt8 * const packedData, UInt32 packedSize, UInt8 * const unpackedData, UInt32 unpackedSize) { OSErr err; UInt32 offset; UInt8 opCode; UInt8 * unpackCursor; MoreAssertQ(packedData != nil); MoreAssertQ(unpackedData != nil); MoreAssertQ(unpackedSize >= packedSize); // The following asserts assume that the client allocated the memory with NewPtr, // which may not always be true. However, the asserts' value in preventing accidental // memory block overruns outweighs the possible maintenance effort. MoreAssertQ( packedSize == GetPtrSize( (Ptr) packedData ) ); MoreAssertQ( unpackedSize == GetPtrSize( (Ptr) unpackedData) ); err = noErr; offset = 0; unpackCursor = unpackedData; while (offset < packedSize) { MoreAssertQ(unpackCursor < &unpackedData[unpackedSize]); opCode = packedData[offset]; switch (PEFPkDataOpcode(opCode)) { case kPEFPkDataZero: { UInt32 count; offset += DecodeInstrCountValue(&packedData[offset], &count); MoreBlockZero(unpackCursor, count); unpackCursor += count; } break; case kPEFPkDataBlock: { UInt32 blockSize; offset += DecodeInstrCountValue(&packedData[offset], &blockSize); BlockMoveData(&packedData[offset], unpackCursor, blockSize); unpackCursor += blockSize; offset += blockSize; } break; case kPEFPkDataRepeat: { UInt32 blockSize; UInt32 repeatCount; UInt32 loopCounter; offset += DecodeInstrCountValue(&packedData[offset], &blockSize); offset += DecodeVCountValue(&packedData[offset], &repeatCount); repeatCount += 1; // stored value is (repeatCount - 1) for (loopCounter = 0; loopCounter < repeatCount; loopCounter++) { BlockMoveData(&packedData[offset], unpackCursor, blockSize); unpackCursor += blockSize; } offset += blockSize; } break; case kPEFPkDataRepeatBlock: { UInt32 commonSize; UInt32 customSize; UInt32 repeatCount; const UInt8 *commonData; const UInt8 *customData; UInt32 loopCounter; offset += DecodeInstrCountValue(&packedData[offset], &commonSize); offset += DecodeVCountValue(&packedData[offset], &customSize); offset += DecodeVCountValue(&packedData[offset], &repeatCount); commonData = &packedData[offset]; customData = &packedData[offset + commonSize]; for (loopCounter = 0; loopCounter < repeatCount; loopCounter++) { BlockMoveData(commonData, unpackCursor, commonSize); unpackCursor += commonSize; BlockMoveData(customData, unpackCursor, customSize); unpackCursor += customSize; customData += customSize; } BlockMoveData(commonData, unpackCursor, commonSize); unpackCursor += commonSize; offset += (repeatCount * (commonSize + customSize)) + commonSize; } break; case kPEFPkDataRepeatZero: { UInt32 commonSize; UInt32 customSize; UInt32 repeatCount; const UInt8 *customData; UInt32 loopCounter; offset += DecodeInstrCountValue(&packedData[offset], &commonSize); offset += DecodeVCountValue(&packedData[offset], &customSize); offset += DecodeVCountValue(&packedData[offset], &repeatCount); customData = &packedData[offset]; for (loopCounter = 0; loopCounter < repeatCount; loopCounter++) { MoreBlockZero(unpackCursor, commonSize); unpackCursor += commonSize; BlockMoveData(customData, unpackCursor, customSize); unpackCursor += customSize; customData += customSize; } MoreBlockZero(unpackCursor, commonSize); unpackCursor += commonSize; offset += repeatCount * customSize; } break; default: #if MORE_DEBUG DebugStr("\pUnpackPEFDataSection: Unexpected data opcode"); #endif err = cfragFragmentCorruptErr; goto leaveNow; break; } } leaveNow: return err; }