[Pharo-dev] [NativeBoost] Calling a function in a struct
Hi. I have a situation with libgit2 where the function I need to call is a field in a struct (the field gets populated with different functions with the same signature depending on certain conditions). I’m facing two problems now: 1. how do I define a function as the field type of an NBExternalStructure? 2. how can I call the function? I’ve tried using callbacks as field types. That works as far as I can access the functions by pointer. But how would I then call that function? I’ve looked at NBNativeFunction and NBNativeFunctionGen but I can’t see how I should use either of those to make a plain call. Here’s a more precise description of my problem: writepack := LG2GitOdbWritepackS new. … “initialize the struct externally” “now call the function ‘commit’ and pass the arguments (this is how I imagine it could work…) writepack commit value: writepack value: anotherStruct. Needed struct fields: backend:git_odb_backend * append: int (*)(git_odb_writepack *, const void *, size_t, git_transfer_progress *) commit: int (*)(git_odb_writepack *, git_transfer_progress *) free: void (*)(git_odb_writepack *) My current (ad hoc) struct fields: fieldsDesc ^#( LG2GitOdbO backend; LG2WritePackAppendCb append; LG2WritePackCommitCb commit; LG2WritePackFreeCb free; ) I’d even be happy if I have to implement a method on LG2GitOdbWritepackS for every function call (e.g. “writepack commit: arg1 and: arg2”) but how would I make the call? Any ideas? Max
Re: [Pharo-dev] [NativeBoost] Calling a function in a struct
2015-02-22 0:06 GMT+01:00 Max Leske maxle...@gmail.com: Hi. I have a situation with libgit2 where the function I need to call is a field in a struct (the field gets populated with different functions with the same signature depending on certain conditions). I’m facing two problems now: 1. how do I define a function as the field type of an NBExternalStructure? Athens creates a structure with callbacks as a surface plugin for the bitblter (SQSurfaceDispatch). But this is a structur with functions (generated with NB) that are called from the outside 2. how can I call the function? I don't know of any example in the image, where we are calling a function defined in a struct. Maybe you can extend NBFFICallout to generate a call from a function spec + function address NBFFICallout#generateCall:module: does this, it generates a call from a function spec and and address loockuped in a module, maybe you can do something similiar, but use the function address from the structure isntead of calling nbGetSymbolAddress:module: I’ve tried using callbacks as field types. That works as far as I can access the functions by pointer. But how would I then call that function? I’ve looked at NBNativeFunction and NBNativeFunctionGen but I can’t see how I should use either of those to make a plain call. Here’s a more precise description of my problem: writepack := LG2GitOdbWritepackS new. … “initialize the struct externally” “now call the function ‘commit’ and pass the arguments (this is how I imagine it could work…) writepack commit value: writepack value: anotherStruct. Needed struct fields: backend:git_odb_backend * append: int (*)(git_odb_writepack *, const void *, size_t, git_transfer_progress *) commit: int (*)(git_odb_writepack *, git_transfer_progress *) free: void (*)(git_odb_writepack *) For what is this needed? Do you want to write your own git backend? I find this strange. I only know of two use cases for function pointers in a structs. 1. to define the callbacks (like athens does it for the SQSurfaceDispatch). But we only define the functions and don't call them. 2. a library defines a public api and delegates the implementation to different backends, but structure and backend functions are hidden. Users of the library don't call them. My current (ad hoc) struct fields: fieldsDesc ^#( LG2GitOdbO backend; LG2WritePackAppendCb append; LG2WritePackCommitCb commit; LG2WritePackFreeCb free; ) I’d even be happy if I have to implement a method on LG2GitOdbWritepackS for every function call (e.g. “writepack commit: arg1 and: arg2”) but how would I make the call? Any ideas? Max
Re: [Pharo-dev] #fromFileNamed: seems too UNIX-y
On 21 Feb 2015, at 04:02, Sean P. DeNigris s...@clipperadams.com wrote: Sven Van Caekenberghe-2 wrote But convenience and clean separation of responsibilities sometimes conflict (I mean, do all these object even have to know about files ?) Good point! But what do we do? The logic is too complicated for users to roll-their-own... It would be nice to have a collaborating role like dataSource, but the problem is that there are no specific FileReference sub-types and we don't want to cloud up FileReference on the other side... For me, this is an open design question. Someone should think hard about this and propose something. Existing conversions like #asXYZ or #as: come in the picture as well. Sven
Re: [Pharo-dev] Protocols, Privacy, and Extensions - NOT One Big Happy Family
Camille proposed and implemented a module system in which extensions are local to the packages. Now putting it in production requires some work. Stef It will be fun to have these concepts distinguished on their own some day :) How do I create a form from a file? Let's check the instance creation protocol... Nothing there. Hmm... I recall something about ImageMorph... In ImageMorph's class comment: Form fromFileNamed: 'myGraphicsFileName'... WHT?! Go back to browsing Form's class-side Protocol: *Graphics-Files - #fromFileNamed: Ugh. - Cheers, Sean -- View this message in context: http://forum.world.st/Protocols-Privacy-and-Extensions-NOT-One-Big-Happy-Family-tp4806747.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
[Pharo-dev] If you want to flex your brain and do useful stuff for the world in Smalltalk
http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Smalltalk
Re: [Pharo-dev] If you want to flex your brain and do useful stuff for the world in Smalltalk
Interesting list! Btw. didn't Natalia made this already http://rosettacode.org/wiki/Voronoi_diagram ? On Sat, Feb 21, 2015 at 6:31 PM, Yuriy Tymchuk yuriy.tymc...@me.com wrote: http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Smalltalk
Re: [Pharo-dev] If you want to flex your brain and do useful stuff for the world in Smalltalk
)) It’s not the same. They are finding to which point which pixel is the closest. I want to get the polygons. On 21 Feb 2015, at 19:30, Peter Uhnák i.uh...@gmail.com wrote: Interesting list! Btw. didn't Natalia made this already http://rosettacode.org/wiki/Voronoi_diagram http://rosettacode.org/wiki/Voronoi_diagram ? On Sat, Feb 21, 2015 at 6:31 PM, Yuriy Tymchuk yuriy.tymc...@me.com mailto:yuriy.tymc...@me.com wrote: http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Smalltalk http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Smalltalk
Re: [Pharo-dev] If you want to flex your brain and do useful stuff for the world in Smalltalk
On second thoughts I'm unsure of any practical uses of this site since they make quite arbitrary tasks. E.g. CSV data manipulation: ... authors may assume that the data fields contain no commas, backslashes, or quotation marks That is for most practical purposes quite useless... or handwriting md5. But I guess as an exercise it could be still useful (for the person writing it). On Sat, Feb 21, 2015 at 7:30 PM, Peter Uhnák i.uh...@gmail.com wrote: Interesting list! Btw. didn't Natalia made this already http://rosettacode.org/wiki/Voronoi_diagram ? On Sat, Feb 21, 2015 at 6:31 PM, Yuriy Tymchuk yuriy.tymc...@me.com wrote: http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Smalltalk
Re: [Pharo-dev] If you want to flex your brain and do useful stuff for the world in Smalltalk
I guess that the point is to implement some common things in different languages, so one can compare them or learn other language based on that one he/she knows. Uko On 21 Feb 2015, at 19:44, Peter Uhnák i.uh...@gmail.com wrote: On second thoughts I'm unsure of any practical uses of this site since they make quite arbitrary tasks. E.g. CSV data manipulation: ... authors may assume that the data fields contain no commas, backslashes, or quotation marks That is for most practical purposes quite useless... or handwriting md5. But I guess as an exercise it could be still useful (for the person writing it). On Sat, Feb 21, 2015 at 7:30 PM, Peter Uhnák i.uh...@gmail.com mailto:i.uh...@gmail.com wrote: Interesting list! Btw. didn't Natalia made this already http://rosettacode.org/wiki/Voronoi_diagram http://rosettacode.org/wiki/Voronoi_diagram ? On Sat, Feb 21, 2015 at 6:31 PM, Yuriy Tymchuk yuriy.tymc...@me.com mailto:yuriy.tymc...@me.com wrote: http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Smalltalk http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Smalltalk
Re: [Pharo-dev] Example implementation of associations with Slots in Pharo 4.0
Hi Jan Excellent! We know exactly whay we want slots and this is exactly for such kind of extensions. you may want to read the paper of Kasper Osterbye http://itu.dk/people/kasper/cv.htm R.11 Kasper Østerbye. Associations as a Language Construct. In Proceedings of TOOLS 29, Ed. Richard Michel et.al., Nancy, June 7-10 1999. Page 224-235. (pdf) I would love to have a nice package with such relationships because we used them all the time. I will blog about your nice experience. We should probably find a nicer way to declare them. Stef Le 21/2/15 21:11, Jan van de Sandt a écrit : Today I experimented a little with the new Slots feature of Pharo 4.0. As an example I implemented support for associations/relationships. With it you can link two slots together so an update on one side will also update the other side of the association/relationship. I used these Movie and Person classes for testing: Object subclass: #SlotExampleMovie slots: { #name. #year. ToOneAssociationSlot named: #director target: #SlotExamplePerson inverse: #directedMovies. ToManyAssociationSlot named: #actors target: #SlotExamplePerson inverse: #actedInMovies } classVariables: { } category: 'SlotAssociations-Tests-Example' Object subclass: #SlotExamplePerson slots: { #name. ToManyAssociationSlot named: #directedMovies target: #SlotExampleMovie inverse: #director. ToManyAssociationSlot named: #actedInMovies target: #SlotExampleMovie inverse: #actors } classVariables: { } category: 'SlotAssociations-Tests-Example' With this definition the director of a Movie must be a Persion instance. When you set the director of a movie this movie is automatically added to the directedMovies collection of that person. Off course it also works the other way around. It took very little code to add these association slots. I think Slots are a really nice addition to Pharo! If anyone wants to have a look at the code: MCHttpRepository location: 'http://smalltalkhub.com/mc/JanVanDeSandt/Stuff/main' user: '' password: '' Jan.
Re: [Pharo-dev] Why was #asLegalSelector removed?
Le 20/2/15 15:59, Sean P. DeNigris a écrit : As you know, I love cleaning ;) But... stepharo wrote https://github.com/pharo-project/pharo-workingRoadmaps/blob/master/StringCleaning.md What enlightenment am I supposed to gain from candidates for removal... asLegalSelector, and later Done: candidates for removal... asLegalSelector. I still understand nothing of the rationale. Yes we are poor are documenting such decision. But if to remove a bad method it takes 5 times more energy than removing it then we will never make progress. This code is bogus and shitty. And useful ;) (as evidenced by this thread). Okay, it's limited, but what's better - having users roll their own every time? Probably and I'm not provocating. For now, I'll package it with my code, but I think we should add it back, maybe with a method comment to clarify that it creates a unary selector only... Bring back #asLegalSelector https://pharo.fogbugz.com/default.asp?14969 Fix in inbox: SLICE-Issue-14969-Bring-back-asLegalSelector-SeanDeNigris.1 I think that this is better that you package it with your app. I do not see the point to have this method fromGarbageToUnarySelector in String. Stef
[Pharo-dev] Example implementation of associations with Slots in Pharo 4.0
Today I experimented a little with the new Slots feature of Pharo 4.0. As an example I implemented support for associations/relationships. With it you can link two slots together so an update on one side will also update the other side of the association/relationship. I used these Movie and Person classes for testing: Object subclass: #SlotExampleMovie slots: { #name. #year. ToOneAssociationSlot named: #director target: #SlotExamplePerson inverse: #directedMovies. ToManyAssociationSlot named: #actors target: #SlotExamplePerson inverse: #actedInMovies } classVariables: { } category: 'SlotAssociations-Tests-Example' Object subclass: #SlotExamplePerson slots: { #name. ToManyAssociationSlot named: #directedMovies target: #SlotExampleMovie inverse: #director. ToManyAssociationSlot named: #actedInMovies target: #SlotExampleMovie inverse: #actors } classVariables: { } category: 'SlotAssociations-Tests-Example' With this definition the director of a Movie must be a Persion instance. When you set the director of a movie this movie is automatically added to the directedMovies collection of that person. Off course it also works the other way around. It took very little code to add these association slots. I think Slots are a really nice addition to Pharo! If anyone wants to have a look at the code: MCHttpRepository location: 'http://smalltalkhub.com/mc/JanVanDeSandt/Stuff/main' user: '' password: '' Jan.