findfolder redux – feedback requested on "folderman"

Dec 8, 2006 at 6:52am

findfolder redux – feedback requested on "folderman"

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

#29104
Dec 8, 2006 at 6:12pm

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

#90143
Dec 8, 2006 at 8:32pm

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

#90144
Dec 8, 2006 at 10:12pm

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

#90145
Dec 8, 2006 at 11:15pm

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

#90146
Dec 8, 2006 at 11:23pm

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
>
>
>
—————————————————-

#90147
Dec 8, 2006 at 11:35pm

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

#90148
Dec 9, 2006 at 6:14am

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()

#90149

You must be logged in to reply to this topic.