Forums > Dev

findfolder redux – feedback requested on "folderman"

December 8, 2006 | 6:52 am

I’ve coded up an external that is similar to the now-disappeared (and always unsupported) findfolder object. I’m calling it "folderman", as it uses Apple’s Folder Manager functions, and of course "folderman" sounds like some geeky superhero…

I’m attaching the first draft, a UB version. It only takes a bang message, and in response outputs the path to the user’s preferences folder. It works here in Max 4.6.2.

In addition to the UB build, I’m attaching the source code, Xcode project file, and an example Max patch. Please note that, in order to build folderman, "Folders.h" (from the standard Apple-distributed OS X SDK) must be in the Header Search Path of the Xcode project settings.

Although this build works, I could still use some feedback on the source code. I’m not sure it’s the most solid piece of work… it’s short, and well-commented, so should be easy enough to read along.

Thanks!
Leigh


December 8, 2006 | 6:12 pm

On 8-Dec-2006, at 7:52, Leigh Marble wrote:

> Although this build works, I could still use some feedback on the
> source code.

You’re leaking memory. CFStringToCString() allocates memory that
never gets freed.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de


December 8, 2006 | 8:32 pm

Bummer – since that was one bit copied verbatim from Apple (see the URL link in the source code), I was hoping it was solid.

Come to think of it, would I be better off rewriting it with the Max-specific calls sysmem_newptr (and freeing memory with sysmem_freeptr)?

Thanks,
Leigh


December 8, 2006 | 10:12 pm

On 8-Dec-2006, at 21:32, Leigh Marble wrote:

> Bummer – since that was one bit copied verbatim from Apple (see the
> URL link in the source code), I was hoping it was solid.

The Apple DTS code is OK, but it’s your responsibility to free the
memory when it’s no longer needed. You need to weave DisposePtr()
into your calling function.

> Come to think of it, would I be better off rewriting it with the
> Max-specific calls sysmem_newptr (and freeing memory with
> sysmem_freeptr)?

The presumed reason why the findfolder object isn’t supported is
because it doesn’t make much sense in Windowsland. So there’s not a
lot of point in using wrapper functions. Plus the Core Foundation
calls aren’t Windows-friendly, either.

– P.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de


December 8, 2006 | 11:15 pm

On 8-Dec-2006, at 23:12, Peter Castine wrote:

> The Apple DTS code is OK, but it’s your responsibility to free the
> memory when it’s no longer needed. You need to weave DisposePtr()
> into your calling function.

It also occurs to me that you should be checking for NULL before
calling gensym(). < http://www.cycling74.com/forums/index.php?
t=msg&rid=0&S=30922ef9f2a32418f4b0e60bee707951&th=4684&goto=12969#msg_12
969> and scroll to the end of the thread.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de


December 8, 2006 | 11:23 pm

Got it – garbage disposal is my responsibility.

And yes, I also assumed that findfolder had been deprecated because it’s Mac-specific. Which, by the way, seems like not quite enough of a reason to kill it off. To get this kind of information (dynamic directory locations) from an operating system, you have to be OS specific at some point…

But anyways, if I read you right, you’re saying, just go ahead and stick with NewPtr (rather than going to sysmem_newptr), since the whole thing is Mac-specific anyway?

Thanks,
Leigh

Quote: Peter Castine wrote on Fri, 08 December 2006 15:12
> The Apple DTS code is OK, but it’s your responsibility to free the
> memory when it’s no longer needed. You need to weave DisposePtr()
> into your calling function.
>
> > Come to think of it, would I be better off rewriting it with the
> > Max-specific calls sysmem_newptr (and freeing memory with
> > sysmem_freeptr)?
>
> The presumed reason why the findfolder object isn’t supported is
> because it doesn’t make much sense in Windowsland. So there’s not a
> lot of point in using wrapper functions. Plus the Core Foundation
> calls aren’t Windows-friendly, either.
>
> — P.
>
> ————– http://www.bek.no/~pcastine/Litter/ ————-
> Peter Castine +–> Litter Power & Litter Bundle for Jitter
> Universal Binaries on the way
> iCE: Sequencing, Recording &
> Interface Building for |home | chez nous|
> Max/MSP Extremely cool |bei uns | i nostri|
> http://www.dspaudio.com/ http://www.castine.de
>
>
>
—————————————————-


December 8, 2006 | 11:35 pm

Crossed messages there… thanks for the heads up on that, will do!

Quote: Peter Castine wrote on Fri, 08 December 2006 16:15
> It also occurs to me that you should be checking for NULL before calling gensym().

http://www.cycling74.com/forums/index.php?t=msg&rid=0&S=30922ef9f2a32418f4b0e60bee707951&th=4684&goto=12969#msg_12969


December 9, 2006 | 6:14 am

Yes, just verified that gensym(NULL) causes a crash…

Quote: Peter Castine wrote on Fri, 08 December 2006 16:15
—————————————————-
> It also occurs to me that you should be checking for NULL before
> calling gensym()


Viewing 8 posts - 1 through 8 (of 8 total)