From: Kevin Walzer on
I'm writing a C-based Tcl extension that iterates through the file
system to build a list of file names that contain a specific string.
(It's a Mac-specific API that is faster than glob or find.) The code
generally works as expected, but when I try to access the returned list
at the script level, I get no data.

Here's the relevant code:

int i;
data = Tcl_NewListObj(0, NULL);
for (i=0; i<count; i++) {
Tcl_Obj *element;
FSRef ref = refs[i];
CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &ref);
char *pathname= [[(id)url path] UTF8String];
printf("the pathname is %s\n", pathname);
element = Tcl_NewStringObj(pathname, -1);
if (element == NULL) continue;
Tcl_IncrRefCount(element);
Tcl_ListObjAppendElement(ip, data, element);
Tcl_DecrRefCount(element);
}

I call this code from the script level like so:

set foo [tclfilesearch::filesearch foo "/"]

I know it works because the printf statement shows data. However, when I
try to get the contents of the list, via [puts $foo], there's no output,
and [llength $foo] return nothing.

Can anyone explain to me why I'm not getting any list data at the Tcl
script level?

--Kevin


I know the search data is being retrieved correclty via the "printf"
statement, but when I try to access this at the script leve

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
From: Kevin Kenny on
Kevin Walzer wrote:
> I'm writing a C-based Tcl extension that iterates through the file
> system to build a list of file names that contain a specific string.
> (It's a Mac-specific API that is faster than glob or find.) The code
> generally works as expected, but when I try to access the returned list
> at the script level, I get no data.
>
> Here's the relevant code:
>
> int i;
> data = Tcl_NewListObj(0, NULL);
> for (i=0; i<count; i++) {
> Tcl_Obj *element;
> FSRef ref = refs[i];
> CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &ref);
> char *pathname= [[(id)url path] UTF8String];
> printf("the pathname is %s\n", pathname);
> element = Tcl_NewStringObj(pathname, -1);
> if (element == NULL) continue;
> Tcl_IncrRefCount(element);
> Tcl_ListObjAppendElement(ip, data, element);
> Tcl_DecrRefCount(element);
> }
>
> I call this code from the script level like so:
>
> set foo [tclfilesearch::filesearch foo "/"]
>
> I know it works because the printf statement shows data. However, when I
> try to get the contents of the list, via [puts $foo], there's no output,
> and [llength $foo] return nothing.
>
> Can anyone explain to me why I'm not getting any list data at the Tcl
> script level?
>
> --Kevin
>
>
> I know the search data is being retrieved correclty via the "printf"
> statement, but when I try to access this at the script leve
>

Uhm, you *do* have a Tcl_SetObjResult(ip, data); somewhere that you're
not showing us?

--
73 de ke9tv/2, Kevin
From: Alexandre Ferrieux on
On Jun 1, 5:25 am, Kevin Walzer <k...(a)codebykevin.com> wrote:
> I'm writing a C-based Tcl extension that iterates through the file
> system to build a list of file names that contain a specific string.
> (It's a Mac-specific API that is faster than glob or find.)

Out of curiosity, isn't there, somewhere in the OSX utilities, a find-
like standalone executable that uses this faster API, that you could
[open |] ?

-Alex
From: Kevin Walzer on
On 6/1/10 12:13 AM, Kevin Kenny wrote:

> Uhm, you *do* have a Tcl_SetObjResult(ip, data); somewhere that you're
> not showing us?
>

I do now. :-) That fixed it. Thanks.
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
From: Kevin Walzer on
On 6/1/10 3:38 AM, Alexandre Ferrieux wrote:
> On Jun 1, 5:25 am, Kevin Walzer<k...(a)codebykevin.com> wrote:
>> I'm writing a C-based Tcl extension that iterates through the file
>> system to build a list of file names that contain a specific string.
>> (It's a Mac-specific API that is faster than glob or find.)
>
> Out of curiosity, isn't there, somewhere in the OSX utilities, a find-
> like standalone executable that uses this faster API, that you could
> [open |] ?
>
> -Alex

Not that I'm aware of. The answer is to include Tcl_SetObjResult(ip,
data) in my code...

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com