Hi
Working with NativeBoost I'm trying to figure out if there is a way I can pass an array of arguments to a function like so: MyExample run: 'echo' args: { 'foo' }. nbRun: str args: args <primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode > ^ self nbCall: #( int run_command (String str, Array args) ) module: 'librunner.dylib' The intention is of course to be able to pass arguments to execve() (for example). I guess I could simply parse a string on the C-side but I'd rather not. Any suggestions? Cheers, Max |
well, you have to decompose it to
fn(arg1, arg2, arg3 ... ) because NB does not supports vararg functions. But if function takes a pointer to array, then you can just use external memory buffer and fill it with anything you want. What exactly function you wanna use? On 6 November 2012 11:06, Max Leske <[hidden email]> wrote: > Hi > > Working with NativeBoost I'm trying to figure out if there is a way I can pass an array of arguments to a function like so: > > MyExample run: 'echo' args: { 'foo' }. > > > nbRun: str args: args > <primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode > > ^ self nbCall: #( int run_command (String str, Array args) ) module: 'librunner.dylib' > > The intention is of course to be able to pass arguments to execve() (for example). > I guess I could simply parse a string on the C-side but I'd rather not. > > Any suggestions? > > Cheers, > Max -- Best regards, Igor Stasenko. |
Thanks Igor.
I meant a pointer to an array, sorry. Here's the function prototype: int run_command(const char *command, char *argv[]); I could then simply pass this to execve like so: status = execve(command, argv, envp); On 06.11.2012, at 15:12, Igor Stasenko <[hidden email]> wrote: > well, you have to decompose it to > fn(arg1, arg2, arg3 ... ) > > because NB does not supports vararg functions. > > But if function takes a pointer to array, then you can just use > external memory buffer and fill it with > anything you want. > What exactly function you wanna use? > > On 6 November 2012 11:06, Max Leske <[hidden email]> wrote: >> Hi >> >> Working with NativeBoost I'm trying to figure out if there is a way I can pass an array of arguments to a function like so: >> >> MyExample run: 'echo' args: { 'foo' }. >> >> >> nbRun: str args: args >> <primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode > >> ^ self nbCall: #( int run_command (String str, Array args) ) module: 'librunner.dylib' >> >> The intention is of course to be able to pass arguments to execve() (for example). >> I guess I could simply parse a string on the C-side but I'd rather not. >> >> Any suggestions? >> >> Cheers, >> Max > > > > -- > Best regards, > Igor Stasenko. > |
On 6 November 2012 11:23, Max Leske <[hidden email]> wrote:
> Thanks Igor. > > I meant a pointer to an array, sorry. Here's the function prototype: > > int run_command(const char *command, char *argv[]); > > I could then simply pass this to execve like so: > > status = execve(command, argv, envp); > buffer := NativeBoost allocate: (numArgs * 4). arg1ptr := NativeBoost allocate: arg1 size+1. NativeBoost memcopy: arg1 to: arg1ptr size: arg1 size. arg1ptr nbUInt8At: arg1 size put: 0. "terminating null char" buffer nbUInt32At: 0 put: (arg1ptr value). something like that. (and then , of course free memory after you no longer need it :) > > > On 06.11.2012, at 15:12, Igor Stasenko <[hidden email]> wrote: > >> well, you have to decompose it to >> fn(arg1, arg2, arg3 ... ) >> >> because NB does not supports vararg functions. >> >> But if function takes a pointer to array, then you can just use >> external memory buffer and fill it with >> anything you want. >> What exactly function you wanna use? >> >> On 6 November 2012 11:06, Max Leske <[hidden email]> wrote: >>> Hi >>> >>> Working with NativeBoost I'm trying to figure out if there is a way I can pass an array of arguments to a function like so: >>> >>> MyExample run: 'echo' args: { 'foo' }. >>> >>> >>> nbRun: str args: args >>> <primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode > >>> ^ self nbCall: #( int run_command (String str, Array args) ) module: 'librunner.dylib' >>> >>> The intention is of course to be able to pass arguments to execve() (for example). >>> I guess I could simply parse a string on the C-side but I'd rather not. >>> >>> Any suggestions? >>> >>> Cheers, >>> Max >> >> >> >> -- >> Best regards, >> Igor Stasenko. >> > > -- Best regards, Igor Stasenko. |
Cool, thanks. I'll give that a try tomorrow.
On 06.11.2012, at 18:34, Igor Stasenko <[hidden email]> wrote: > On 6 November 2012 11:23, Max Leske <[hidden email]> wrote: >> Thanks Igor. >> >> I meant a pointer to an array, sorry. Here's the function prototype: >> >> int run_command(const char *command, char *argv[]); >> >> I could then simply pass this to execve like so: >> >> status = execve(command, argv, envp); >> > so, like i said, prepare a buffer which will hold strings, i.e. > > buffer := NativeBoost allocate: (numArgs * 4). > arg1ptr := NativeBoost allocate: arg1 size+1. > > NativeBoost memcopy: arg1 to: arg1ptr size: arg1 size. > arg1ptr nbUInt8At: arg1 size put: 0. "terminating null char" > > buffer nbUInt32At: 0 put: (arg1ptr value). > > something like that. > (and then , of course free memory after you no longer need it :) > >> >> >> On 06.11.2012, at 15:12, Igor Stasenko <[hidden email]> wrote: >> >>> well, you have to decompose it to >>> fn(arg1, arg2, arg3 ... ) >>> >>> because NB does not supports vararg functions. >>> >>> But if function takes a pointer to array, then you can just use >>> external memory buffer and fill it with >>> anything you want. >>> What exactly function you wanna use? >>> >>> On 6 November 2012 11:06, Max Leske <[hidden email]> wrote: >>>> Hi >>>> >>>> Working with NativeBoost I'm trying to figure out if there is a way I can pass an array of arguments to a function like so: >>>> >>>> MyExample run: 'echo' args: { 'foo' }. >>>> >>>> >>>> nbRun: str args: args >>>> <primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode > >>>> ^ self nbCall: #( int run_command (String str, Array args) ) module: 'librunner.dylib' >>>> >>>> The intention is of course to be able to pass arguments to execve() (for example). >>>> I guess I could simply parse a string on the C-side but I'd rather not. >>>> >>>> Any suggestions? >>>> >>>> Cheers, >>>> Max >>> >>> >>> >>> -- >>> Best regards, >>> Igor Stasenko. >>> >> >> > > > > -- > Best regards, > Igor Stasenko. > |
In reply to this post by Igor Stasenko
This is clearly something to add to the documentation of NativeBoost.
Igor can you do it? Stef On Nov 6, 2012, at 6:34 PM, Igor Stasenko wrote: > On 6 November 2012 11:23, Max Leske <[hidden email]> wrote: >> Thanks Igor. >> >> I meant a pointer to an array, sorry. Here's the function prototype: >> >> int run_command(const char *command, char *argv[]); >> >> I could then simply pass this to execve like so: >> >> status = execve(command, argv, envp); >> > so, like i said, prepare a buffer which will hold strings, i.e. > > buffer := NativeBoost allocate: (numArgs * 4). > arg1ptr := NativeBoost allocate: arg1 size+1. > > NativeBoost memcopy: arg1 to: arg1ptr size: arg1 size. > arg1ptr nbUInt8At: arg1 size put: 0. "terminating null char" > > buffer nbUInt32At: 0 put: (arg1ptr value). > > something like that. > (and then , of course free memory after you no longer need it :) > >> >> >> On 06.11.2012, at 15:12, Igor Stasenko <[hidden email]> wrote: >> >>> well, you have to decompose it to >>> fn(arg1, arg2, arg3 ... ) >>> >>> because NB does not supports vararg functions. >>> >>> But if function takes a pointer to array, then you can just use >>> external memory buffer and fill it with >>> anything you want. >>> What exactly function you wanna use? >>> >>> On 6 November 2012 11:06, Max Leske <[hidden email]> wrote: >>>> Hi >>>> >>>> Working with NativeBoost I'm trying to figure out if there is a way I can pass an array of arguments to a function like so: >>>> >>>> MyExample run: 'echo' args: { 'foo' }. >>>> >>>> >>>> nbRun: str args: args >>>> <primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode > >>>> ^ self nbCall: #( int run_command (String str, Array args) ) module: 'librunner.dylib' >>>> >>>> The intention is of course to be able to pass arguments to execve() (for example). >>>> I guess I could simply parse a string on the C-side but I'd rather not. >>>> >>>> Any suggestions? >>>> >>>> Cheers, >>>> Max >>> >>> >>> >>> -- >>> Best regards, >>> Igor Stasenko. >>> >> >> > > > > -- > Best regards, > Igor Stasenko. > |
On 6 November 2012 17:57, Stéphane Ducasse <[hidden email]> wrote:
> This is clearly something to add to the documentation of NativeBoost. > Igor can you do it? I already have a description of memory management API for NB in docs. And telling how manage external memory is... ahem.. not really fits into docs :) Maybe a tutor or something. -- Best regards, Igor Stasenko. |
On Nov 6, 2012, at 11:06 PM, Igor Stasenko wrote: > On 6 November 2012 17:57, Stéphane Ducasse <[hidden email]> wrote: >> This is clearly something to add to the documentation of NativeBoost. >> Igor can you do it? > > I already have a description of memory management API for NB in docs. > And telling how manage external memory is... ahem.. not really fits into docs :) > Maybe a tutor or something. think not technical but user! Id o not give a shit if what helps me is called a doc or a tutorial. I care that it helps me fixing my problem. And what I see is that the example of Max is a nice example of a recurring problem people face. Stef > > > > -- > Best regards, > Igor Stasenko. > |
Just copy paste the thing you posted in the NBBasicExamples and we're
done. A couple of examples which show common problems will help certainly help people to understand. Plus we should convert the examples into tests so they are always run! On 2012-11-07, at 09:28, Stéphane Ducasse <[hidden email]> wrote: > > On Nov 6, 2012, at 11:06 PM, Igor Stasenko wrote: > >> On 6 November 2012 17:57, Stéphane Ducasse <[hidden email]> wrote: >>> This is clearly something to add to the documentation of NativeBoost. >>> Igor can you do it? >> >> I already have a description of memory management API for NB in docs. >> And telling how manage external memory is... ahem.. not really fits into docs :) >> Maybe a tutor or something. > > think not technical but user! > Id o not give a shit if what helps me is called a doc or a tutorial. > I care that it helps me fixing my problem. > And what I see is that the example of Max is a nice example of a recurring problem > people face. > > Stef >> >> >> >> -- >> Best regards, >> Igor Stasenko. >> > > |
+ 1
On Nov 7, 2012, at 9:43 AM, Camillo Bruni wrote: > Just copy paste the thing you posted in the NBBasicExamples and we're > done. A couple of examples which show common problems will help > certainly help people to understand. > > Plus we should convert the examples into tests so they are always run! > > On 2012-11-07, at 09:28, Stéphane Ducasse <[hidden email]> wrote: > >> >> On Nov 6, 2012, at 11:06 PM, Igor Stasenko wrote: >> >>> On 6 November 2012 17:57, Stéphane Ducasse <[hidden email]> wrote: >>>> This is clearly something to add to the documentation of NativeBoost. >>>> Igor can you do it? >>> >>> I already have a description of memory management API for NB in docs. >>> And telling how manage external memory is... ahem.. not really fits into docs :) >>> Maybe a tutor or something. >> >> think not technical but user! >> Id o not give a shit if what helps me is called a doc or a tutorial. >> I care that it helps me fixing my problem. >> And what I see is that the example of Max is a nice example of a recurring problem >> people face. >> >> Stef >>> >>> >>> >>> -- >>> Best regards, >>> Igor Stasenko. >>> >> >> > > |
sure sure..
but guys... i really doubt that i would want to see people poking with NB who don't even have a basic understanding of malloc(ed) memory management and working with memory buffers & pointers. For such sort of people, best what i can offer is "go back when you will learn basics first". Of course, it would be cool if NB could work even for "dummies", but i am thinking , as any technology, before you start using it without shooting yourself into foot, you should do some homework first. On 7 November 2012 08:09, Stéphane Ducasse <[hidden email]> wrote: > + 1 > > On Nov 7, 2012, at 9:43 AM, Camillo Bruni wrote: > >> Just copy paste the thing you posted in the NBBasicExamples and we're >> done. A couple of examples which show common problems will help >> certainly help people to understand. >> >> Plus we should convert the examples into tests so they are always run! >> >> On 2012-11-07, at 09:28, Stéphane Ducasse <[hidden email]> wrote: >> >>> >>> On Nov 6, 2012, at 11:06 PM, Igor Stasenko wrote: >>> >>>> On 6 November 2012 17:57, Stéphane Ducasse <[hidden email]> wrote: >>>>> This is clearly something to add to the documentation of NativeBoost. >>>>> Igor can you do it? >>>> >>>> I already have a description of memory management API for NB in docs. >>>> And telling how manage external memory is... ahem.. not really fits into docs :) >>>> Maybe a tutor or something. >>> >>> think not technical but user! >>> Id o not give a shit if what helps me is called a doc or a tutorial. >>> I care that it helps me fixing my problem. >>> And what I see is that the example of Max is a nice example of a recurring problem >>> people face. >>> >>> Stef >>>> >>>> >>>> >>>> -- >>>> Best regards, >>>> Igor Stasenko. >>>> >>> >>> >> >> > > -- Best regards, Igor Stasenko. |
I get your point Igor but then again, we're all somewhat self taught which means that as a developer if you don't understand something you hack around until you get it. It's not like I'm going to break anything in the released products, right? And I think I can judge the risk of wrecking my own machine.
I think that helping each other out on this list is more important than scowling at the noobs and yelling "DON'T TOUCH". Sorry if that comes across harsh but I'm honestly a little upset. Max On 08.11.2012, at 04:39, Igor Stasenko <[hidden email]> wrote: > sure sure.. > but guys... i really doubt that i would want to see people poking with > NB who don't even have a > basic understanding of malloc(ed) memory management and working with > memory buffers & pointers. > For such sort of people, best what i can offer is "go back when you > will learn basics first". > > Of course, it would be cool if NB could work even for "dummies", but i > am thinking , as any technology, > before you start using it without shooting yourself into foot, you > should do some homework first. > > > On 7 November 2012 08:09, Stéphane Ducasse <[hidden email]> wrote: >> + 1 >> >> On Nov 7, 2012, at 9:43 AM, Camillo Bruni wrote: >> >>> Just copy paste the thing you posted in the NBBasicExamples and we're >>> done. A couple of examples which show common problems will help >>> certainly help people to understand. >>> >>> Plus we should convert the examples into tests so they are always run! >>> >>> On 2012-11-07, at 09:28, Stéphane Ducasse <[hidden email]> wrote: >>> >>>> >>>> On Nov 6, 2012, at 11:06 PM, Igor Stasenko wrote: >>>> >>>>> On 6 November 2012 17:57, Stéphane Ducasse <[hidden email]> wrote: >>>>>> This is clearly something to add to the documentation of NativeBoost. >>>>>> Igor can you do it? >>>>> >>>>> I already have a description of memory management API for NB in docs. >>>>> And telling how manage external memory is... ahem.. not really fits into docs :) >>>>> Maybe a tutor or something. >>>> >>>> think not technical but user! >>>> Id o not give a shit if what helps me is called a doc or a tutorial. >>>> I care that it helps me fixing my problem. >>>> And what I see is that the example of Max is a nice example of a recurring problem >>>> people face. >>>> >>>> Stef >>>>> >>>>> >>>>> >>>>> -- >>>>> Best regards, >>>>> Igor Stasenko. >>>>> >>>> >>>> >>> >>> >> >> > > > > -- > Best regards, > Igor Stasenko. > |
In reply to this post by Igor Stasenko
On 2012-11-08, at 04:39, Igor Stasenko <[hidden email]> wrote: > sure sure.. > but guys... i really doubt that i would want to see people poking with > NB who don't even have a > basic understanding of malloc(ed) memory management and working with > memory buffers & pointers. > For such sort of people, best what i can offer is "go back when you > will learn basics first". that reads for me: everybody but me should use it. And you can be pretty sure that most pharoers (including myself) have a pretty vague notion about malloc/free, combined with the internals of an third party C library, that makes a pretty unstable field. Again, no silver bullets here, but less arrogance and more examples! > Of course, it would be cool if NB could work even for "dummies", but i > am thinking , as any technology, > before you start using it without shooting yourself into foot, you > should do some homework first. |
In reply to this post by Igor Stasenko
Again
I told you several time, do you think that a guy do not understand what is a pointer because he does not know how to write it in C? Give a chance to professionals to learn. We are not talking about explaining what is a pointer, but explaining the potential problems and challenges With your reasoning, I should stop programming because there are so many things that I did not learn in school and I would not have no chance to learn from this community. So with that reasoning I should better stop working in Smalltalk and look for another language! Stef > sure sure.. > but guys... i really doubt that i would want to see people poking with > NB who don't even have a > basic understanding of malloc(ed) memory management and working with > memory buffers & pointers. > For such sort of people, best what i can offer is "go back when you > will learn basics first". > > Of course, it would be cool if NB could work even for "dummies", but i > am thinking , as any technology, > before you start using it without shooting yourself into foot, you > should do some homework first. > > > On 7 November 2012 08:09, Stéphane Ducasse <[hidden email]> wrote: >> + 1 >> >> On Nov 7, 2012, at 9:43 AM, Camillo Bruni wrote: >> >>> Just copy paste the thing you posted in the NBBasicExamples and we're >>> done. A couple of examples which show common problems will help >>> certainly help people to understand. >>> >>> Plus we should convert the examples into tests so they are always run! >>> >>> On 2012-11-07, at 09:28, Stéphane Ducasse <[hidden email]> wrote: >>> >>>> >>>> On Nov 6, 2012, at 11:06 PM, Igor Stasenko wrote: >>>> >>>>> On 6 November 2012 17:57, Stéphane Ducasse <[hidden email]> wrote: >>>>>> This is clearly something to add to the documentation of NativeBoost. >>>>>> Igor can you do it? >>>>> >>>>> I already have a description of memory management API for NB in docs. >>>>> And telling how manage external memory is... ahem.. not really fits into docs :) >>>>> Maybe a tutor or something. >>>> >>>> think not technical but user! >>>> Id o not give a shit if what helps me is called a doc or a tutorial. >>>> I care that it helps me fixing my problem. >>>> And what I see is that the example of Max is a nice example of a recurring problem >>>> people face. >>>> >>>> Stef >>>>> >>>>> >>>>> >>>>> -- >>>>> Best regards, >>>>> Igor Stasenko. >>>>> >>>> >>>> >>> >>> >> >> > > > > -- > Best regards, > Igor Stasenko. > |
In reply to this post by Camillo Bruni-3
> And you can be pretty sure that most pharoers (including myself) have
> a pretty vague notion about malloc/free, combined with the internals > of an third party C library, that makes a pretty unstable field. > > Again, no silver bullets here, but less arrogance and more examples! +1 but we can learn and learn fast with a good tutorial that puts the right amount of information in perspective. Stef |
On 11/8/2012 1:30 PM, Stéphane Ducasse wrote:
>> And you can be pretty sure that most pharoers (including myself) have >> a pretty vague notion about malloc/free, combined with the internals >> of an third party C library, that makes a pretty unstable field. >> >> Again, no silver bullets here, but less arrogance and more examples! > +1 > but we can learn and learn fast with a good tutorial that puts the right amount > of information in perspective. > > Stef like to learn how to use NB to be able to access methods in DLLs. My question is, without becoming a C programmer, what is a sufficient level of knowledge of C to be able to use NB well? What is a good path to acquiring a sufficient level of knowledge? Thanks for any information. Jimmie |
jimmie
***THANKS*** I'm in the same situation even if I read several lectures and books on C. So I want a tutorials that takes us into account and I'm sure that this is faisable. Just need care, love and time. STef On Nov 8, 2012, at 8:58 PM, Jimmie Houchin wrote: > On 11/8/2012 1:30 PM, Stéphane Ducasse wrote: >>> And you can be pretty sure that most pharoers (including myself) have >>> a pretty vague notion about malloc/free, combined with the internals >>> of an third party C library, that makes a pretty unstable field. >>> >>> Again, no silver bullets here, but less arrogance and more examples! >> +1 >> but we can learn and learn fast with a good tutorial that puts the right amount >> of information in perspective. >> >> Stef > I am aperson who has no background in C or similar languages, but would like to learn how to use NB to be able to access methods in DLLs. > > My question is, without becoming a C programmer, what is a sufficient level of knowledge of C to be able to use NB well? > > What is a good path to acquiring a sufficient level of knowledge? > > Thanks for any information. > > Jimmie > |
In reply to this post by Stéphane Ducasse
On 08 Nov 2012, at 20:29, Stéphane Ducasse <[hidden email]> wrote: > I told you several time, do you think that a guy do not understand what is a pointer because he does not know how to write it > in C? > Give a chance to professionals to learn. We are not talking about explaining what is a pointer, but explaining the > potential problems and challenges > > With your reasoning, I should stop programming because there are so many things that I did not learn in school > and I would not have no chance to learn from this community. So with that reasoning I should better stop working in Smalltalk > and look for another language! I think he meant it as a general warning ;-) The things is, as long as its pure Smalltalk, you are protected by a very good dynamic type system that cannot really be broken, i.e. the object illusion is kept (bounds checking, blah blah …) But once you start using C pointers, you can very easily do something wrong. It might be a very subtle error and it might not manifest itself immediately, alas there won't be a Debugger popping up, just a coredump. Pharo is actually pretty/very stable in day to day use, it should stay that way. Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill |
On Nov 8, 2012, at 9:13 PM, Sven Van Caekenberghe wrote: > > On 08 Nov 2012, at 20:29, Stéphane Ducasse <[hidden email]> wrote: > >> I told you several time, do you think that a guy do not understand what is a pointer because he does not know how to write it >> in C? >> Give a chance to professionals to learn. We are not talking about explaining what is a pointer, but explaining the >> potential problems and challenges >> >> With your reasoning, I should stop programming because there are so many things that I did not learn in school >> and I would not have no chance to learn from this community. So with that reasoning I should better stop working in Smalltalk >> and look for another language! > > I think he meant it as a general warning ;-) yes I know > > The things is, as long as its pure Smalltalk, you are protected by a very good dynamic type system that cannot really be broken, i.e. the object illusion is kept (bounds checking, blah blah …) indeed but this means that with a little care we should be able to explain points. I do not see them as difficult, just full of little details. > But once you start using C pointers, you can very easily do something wrong. It might be a very subtle error and it might not manifest itself immediately, alas there won't be a Debugger popping up, just a coredump. > > Pharo is actually pretty/very stable in day to day use, it should stay that way. oh! yes! Stef |
In reply to this post by Max Leske
On 8 November 2012 05:42, Max Leske <[hidden email]> wrote:
> I get your point Igor but then again, we're all somewhat self taught which means that as a developer if you don't understand something you hack around until you get it. It's not like I'm going to break anything in the released products, right? And I think I can judge the risk of wrecking my own machine. > > I think that helping each other out on this list is more important than scowling at the noobs and yelling "DON'T TOUCH". nonono.. touch. everything everywhere. i didn't meant to not touch. what i meant that i am not very good at teaching, especially when it is about basics. for me, to explain such things, is like explaining "how to breathe".. and then, as it happens often, i assuming that people know as much as i do :) > > Sorry if that comes across harsh but I'm honestly a little upset. > > Max > -- Best regards, Igor Stasenko. |
Free forum by Nabble | Edit this page |