Re: [Chicken-users] bind egg and strings
Hello! I have tagged version 1.2 of bind, which should be available shortly. Sorry it took so long. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
On Tue, Apr 2, 2013 at 8:52 AM, Felix fe...@call-with-current-continuation.org wrote: Hello! I have tagged version 1.2 of bind, which should be available shortly. Sorry it took so long. Thanks! Andrei ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
From: Andrei Barbu and...@0xab.com Subject: Re: [Chicken-users] bind egg and strings Date: Wed, 27 Mar 2013 15:17:58 -0400 On Mar 23, 2013 7:56 AM, Felix fe...@call-with-current-continuation.org wrote: Having to do the static allocation manually all the time when all you want is an strdup is rather unpleasant. How about a patch that does both? Thanks, Andrei. I will look at this, perhaps the generated output can be simplifed a little. Thanks. Any chance you'll be able to look at this and the other patch to bind sometime soon? It's been a while and this is holding a bunch of code back. Hello! I've applied the 64-bit fix and partially added the patch regarding c-string/char-ptrs in mutable struct slots. I'm somehow reluctant to add the ...* accessor variant - I fear that this adds a lot of redundant bindings that are never used in most cases. By prefixing a slot type with ___pointer one always has the option to treat a char* as a pointer object instead of a c-string. If you can live with that, I can tag a new version of the bind egg. Otherwise we should discuss this some more. I don't recall the whole discussion so it is possible that I have overlooked something important. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
Hey! I've applied the 64-bit fix and partially added the patch regarding c-string/char-ptrs in mutable struct slots. I'm somehow reluctant to Thanks! add the ...* accessor variant - I fear that this adds a lot of redundant bindings that are never used in most cases. By prefixing a slot type with ___pointer one always has the option to treat a char* as a pointer object instead of a c-string. If you can live with that, Okies. I can live without the c-pointer version. I can tag a new version of the bind egg. Otherwise we should discuss this some more. I don't recall the whole discussion so it is possible that I have overlooked something important. Sounds great. Andrei ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
From: Andrei Barbu and...@0xab.com Subject: Re: [Chicken-users] bind egg and strings Date: Wed, 27 Mar 2013 15:17:58 -0400 On Mar 23, 2013 7:56 AM, Felix fe...@call-with-current-continuation.org wrote: Having to do the static allocation manually all the time when all you want is an strdup is rather unpleasant. How about a patch that does both? Thanks, Andrei. I will look at this, perhaps the generated output can be simplifed a little. Thanks. Any chance you'll be able to look at this and the other patch to bind sometime soon? It's been a while and this is holding a bunch of code back. In the next days, promised. I was on vacation, so excuse the long delay. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
On Mar 23, 2013 7:56 AM, Felix fe...@call-with-current-continuation.org wrote: Having to do the static allocation manually all the time when all you want is an strdup is rather unpleasant. How about a patch that does both? Thanks, Andrei. I will look at this, perhaps the generated output can be simplifed a little. Thanks. Any chance you'll be able to look at this and the other patch to bind sometime soon? It's been a while and this is holding a bunch of code back. Andrei cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
Having to do the static allocation manually all the time when all you want is an strdup is rather unpleasant. How about a patch that does both? Thanks, Andrei. I will look at this, perhaps the generated output can be simplifed a little. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
On Fri, Feb 15, 2013 at 5:53 AM, Felix fe...@call-with-current-continuation.org wrote: From: Andrei Barbu and...@0xab.com Subject: Re: [Chicken-users] bind egg and strings Date: Mon, 11 Feb 2013 02:04:16 -0500 Attached is a trivial patch that does the strdup. I've been using the bind egg and encountered some strange behaviour. I have: struct a { char *b; }; Bind generates: (begin (define a-b (foreign-lambda* c-string (((c-pointer (struct a)) s)) return(s-b);)) (define make-a (foreign-lambda* (c-pointer (struct a)) ((c-string b)) struct a *tmp_ = (struct a *)C_malloc(sizeof(struct a));\ntmp_-b = b;\n\nC_return(tmp_);))) No, you're not missing anything. A strdup is perhaps not the perfect solution, since you can never now what the user intended, and whether this is a temporary data structure or a permanent one. The generated code should probably take a c-pointer argument and leave it the user to create a statically allocated string and convert it to a pointer. Having to do the static allocation manually all the time when all you want is an strdup is rather unpleasant. How about a patch that does both? This patch allows you to pass in either a string (will do an strdup) or a pointer to make-structure-name. structure-name-field-name performs the strdup as above when setting the field and returns a string when getting it. structure-name-field-name* takes a pointer and fetches a pointer. This gives the user the option of either behaviour. With mutable fields given: struct a { char *b; }; bind currently generates: (begin (define a-b (getter-with-setter (foreign-lambda* c-string (((c-pointer (struct a)) s)) return(s-b);) (foreign-lambda* void (((c-pointer (struct a)) s) (c-string x)) s-b = strdup(x);))) (define make-a (foreign-lambda* (c-pointer (struct a)) ((c-string b)) struct a *tmp_ = (struct a *)C_malloc(sizeof(struct a));\ntmp_-b = strdup(b);\n\nC_return(tmp_);))) This patch modifies it to generate: (begin (define a-b (getter-with-setter (foreign-lambda* c-string (((c-pointer (struct a)) s)) return(s-b);) (foreign-lambda* void (((c-pointer (struct a)) s) (c-string x)) s-b = strdup(x);))) (define a-b* (getter-with-setter (foreign-lambda* c-pointer (((c-pointer (struct a)) s)) return(s-b);) (foreign-lambda* void (((c-pointer (struct a)) s) (c-pointer x)) s-b = x;))) (define-foreign-type bind-string c-pointer (lambda (a) (if (string? a) ((foreign-lambda* c-pointer ((c-string a)) C_return(strdup(a));) a) a)) (foreign-lambda* c-string ((c-pointer a)) C_return(a);)) (define make-a (foreign-lambda* (c-pointer (struct a)) ((bind-string b)) struct a *tmp_ = (struct a *)C_malloc(sizeof(struct a));\ntmp_-b = b;\n\nC_return(tmp_);))) This introduces the foreign-type 'bind-string' to make make-structure-name work. It's a bit of a wart that each structure reintroduces this foreign type, but that doesn't matter as all 'bind-string' definitions are identical. Andrei bind-string.diff Description: Binary data ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
From: Andrei Barbu and...@0xab.com Subject: Re: [Chicken-users] bind egg and strings Date: Mon, 11 Feb 2013 02:04:16 -0500 Attached is a trivial patch that does the strdup. Andrei On Sat, Feb 9, 2013 at 6:07 PM, Andrei Barbu and...@0xab.com wrote: Hi, I've been using the bind egg and encountered some strange behaviour. I have: struct a { char *b; }; Bind generates: (begin (define a-b (foreign-lambda* c-string (((c-pointer (struct a)) s)) return(s-b);)) (define make-a (foreign-lambda* (c-pointer (struct a)) ((c-string b)) struct a *tmp_ = (struct a *)C_malloc(sizeof(struct a));\ntmp_-b = b;\n\nC_return(tmp_);))) It seems to me that make-a is guaranteed to eventually lead to an out of bounds memory access because of: tmp_-b = b b is a c-string and will be GCed as soon a the foreign-lambda* returns. This is further exacerbated when using -mutable-fields making it impossible to set any char* member. Shouldn't the bind egg be doing an strdup here? Is there a way to get it do so? Or am I missing something? No, you're not missing anything. A strdup is perhaps not the perfect solution, since you can never now what the user intended, and whether this is a temporary data structure or a permanent one. The generated code should probably take a c-pointer argument and leave it the user to create a statically allocated string and convert it to a pointer. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
From: Daniel Leslie d...@ironoxide.ca Subject: Re: [Chicken-users] bind egg and strings Date: Tue, 12 Feb 2013 13:25:22 -0800 Can someone with a little more core knowledge please comment on this? I'm also curious as to whether this test case will eventually result in an OOB error due to foreign reliance on GC-controlled memory. It does. I will look into this. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
Thanks :) -Dan On Fri, Feb 15, 2013 at 2:54 AM, Felix fe...@call-with-current-continuation.org wrote: From: Daniel Leslie d...@ironoxide.ca Subject: Re: [Chicken-users] bind egg and strings Date: Tue, 12 Feb 2013 13:25:22 -0800 Can someone with a little more core knowledge please comment on this? I'm also curious as to whether this test case will eventually result in an OOB error due to foreign reliance on GC-controlled memory. It does. I will look into this. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
Can someone with a little more core knowledge please comment on this? I'm also curious as to whether this test case will eventually result in an OOB error due to foreign reliance on GC-controlled memory. -Dan On Sun, Feb 10, 2013 at 11:04 PM, Andrei Barbu and...@0xab.com wrote: Attached is a trivial patch that does the strdup. Andrei On Sat, Feb 9, 2013 at 6:07 PM, Andrei Barbu and...@0xab.com wrote: Hi, I've been using the bind egg and encountered some strange behaviour. I have: struct a { char *b; }; Bind generates: (begin (define a-b (foreign-lambda* c-string (((c-pointer (struct a)) s)) return(s-b);)) (define make-a (foreign-lambda* (c-pointer (struct a)) ((c-string b)) struct a *tmp_ = (struct a *)C_malloc(sizeof(struct a));\ntmp_-b = b;\n\nC_return(tmp_);))) It seems to me that make-a is guaranteed to eventually lead to an out of bounds memory access because of: tmp_-b = b b is a c-string and will be GCed as soon a the foreign-lambda* returns. This is further exacerbated when using -mutable-fields making it impossible to set any char* member. Shouldn't the bind egg be doing an strdup here? Is there a way to get it do so? Or am I missing something? Thanks! Andrei ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] bind egg and strings
Attached is a trivial patch that does the strdup. Andrei On Sat, Feb 9, 2013 at 6:07 PM, Andrei Barbu and...@0xab.com wrote: Hi, I've been using the bind egg and encountered some strange behaviour. I have: struct a { char *b; }; Bind generates: (begin (define a-b (foreign-lambda* c-string (((c-pointer (struct a)) s)) return(s-b);)) (define make-a (foreign-lambda* (c-pointer (struct a)) ((c-string b)) struct a *tmp_ = (struct a *)C_malloc(sizeof(struct a));\ntmp_-b = b;\n\nC_return(tmp_);))) It seems to me that make-a is guaranteed to eventually lead to an out of bounds memory access because of: tmp_-b = b b is a c-string and will be GCed as soon a the foreign-lambda* returns. This is further exacerbated when using -mutable-fields making it impossible to set any char* member. Shouldn't the bind egg be doing an strdup here? Is there a way to get it do so? Or am I missing something? Thanks! Andrei patch.diff Description: Binary data ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] bind egg and strings
Hi, I've been using the bind egg and encountered some strange behaviour. I have: struct a { char *b; }; Bind generates: (begin (define a-b (foreign-lambda* c-string (((c-pointer (struct a)) s)) return(s-b);)) (define make-a (foreign-lambda* (c-pointer (struct a)) ((c-string b)) struct a *tmp_ = (struct a *)C_malloc(sizeof(struct a));\ntmp_-b = b;\n\nC_return(tmp_);))) It seems to me that make-a is guaranteed to eventually lead to an out of bounds memory access because of: tmp_-b = b b is a c-string and will be GCed as soon a the foreign-lambda* returns. This is further exacerbated when using -mutable-fields making it impossible to set any char* member. Shouldn't the bind egg be doing an strdup here? Is there a way to get it do so? Or am I missing something? Thanks! Andrei ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users