SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
UnifiedFFI
A common language to talk with the outside world
Now
with dem
o!
Esteban Lorenzano
(The stabilisation fairy)
What is UnifiedFFI
• A front-end to express Foreign Function Interface (FFI)
calls in Pharo.
• Uses ThreadedFFIPlugin, but should be able to plug
others in the future.
• It shares same philosophy as NativeBoost
‣ keep as much as possible in the image
‣ no need to modify VM to add functionality
‣ But it is not ASM: Just plain Smalltalk.
But, what happened with
NativeBoost?
• It was not working on Spur
• It was hard to maintain (and we need a different
implementation for each architecture)
• Since we were using NB exclusively for FFI, we
decided to replace it with a different one, using
the VM plugin
UnifiedFFI goals
• Keep NativeBoost syntax
‣ Because is cool :)
‣ Provide backward compatibility for most uses
• Enhance documentation and self-documentation
• Be the unified base for future FFI backends
implementations
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
(People who know NativeBoost will find this very familiar….)
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
A regular Pharo method with one argument
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
A literal array to represent C function
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
Types annotation used to generate marshalling code
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
The value to be passed when calling out
How does a call looks like?
char *getenv(const char *)
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
The library to lookup C function
FFILibrary
• A very simple abstraction to define module
names that can be different each platform.
• Can be used also as a place to store C function
definitions (like a real library :) ).
FFILibrary: LibC
FFILibrary subclass: #LibC
LibC>>unixModuleName
^ ‘libc.so.6'
LibC>>macModuleName
^ ‘libc.dylib'
LibC>>win32ModuleName
^ ‘msvcrt.dll'
LibC>>memCopy: src to: dest size: n
^ self ffiCall: #(void *memcpy(void *dest, const void *src, size_t n))
Insights to UnifiedFFI
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
Insights to UnifiedFFI
getEnv: variable
^ self
ffiCall: #( String getenv( String variable ))
module: LibC
1.Generate bytecodes for marshalling
2.Re-send the method execution
char *getenv(const char *)
How does a call looks like?
(bytecode version)
char *getenv(const char *)
21 <20> pushConstant: <cdecl: char* 'getenv' (char*) module: 'libc.dylib'>
22 <10> pushTemp: 0
23 <8A 81> pop 1 into (Array new: 1)
25 <E1> send: invokeWithArguments:
26 <7C> returnTop
Types
• Support for standard C types: int, float, etc.
• Support for type aliases (map a name to one of the defined types)
• Complex types:
• FFIExternalObject: External addresses (objects)
• FFIOpaqueObject: Opaque C types/structures
• FFIExternalStructure
• FFIExternalArray, FFITypeArray
• FFIExternalEnumeration
• FFIExternalValueHolder: Buffers (to pass referenced data, e.g. “double *”)
• FFIConstantHandle: Windows HANDLE (constant addresses)
FFIExternalObject (1)
AthensSurface subclass: #AthensCairoSurface
uses: TCairoLibrary
instanceVariableNames: 'handle context builder id ftFontRenderer session'
classVariableNames: ''
poolDictionaries: 'AthensCairoDefs'
package: ‘Athens-Cairo'
cairo_surface_t *
cairo_image_surface_create (cairo_format_t format,
int width,
int height);
FFIExternalObject (2)
AthensCairoSurface class>>primImage: aFormat width: aWidth height: aHeight
^self ffiCall: #(AthensCairoSurface cairo_image_surface_create (
int aFormat,
int aWidth,
int aHeight) )
cairo_surface_t *
cairo_image_surface_create (cairo_format_t format, int width, int height);
FFIExternalObject (3)
AthensCairoSurface>>getDataPtr
"get a pointer to surface bitmap data"
^self ffiCall: #( void* cairo_image_surface_get_data ( self ) )
unsigned char *
cairo_image_surface_get_data (cairo_surface_t *surface);
FFICallback
callback := FFICallback
signature: #(int (const void *arg1, const void *arg2))
block: [ :arg1 :arg2 |
((arg1 doubleAt: 1) - (arg2 doubleAt: 1)) sign ].
int (*compar)(const void*,const void*)
FFICallback
callback := FFICallback
signature: #(int (const void *arg1, const void *arg2))
block: [ :arg1 :arg2 |
((arg1 doubleAt: 1) - (arg2 doubleAt: 1)) sign ].
int (*compar)(const void*,const void*)
A literal array to represent C anonymous function
FFICallback: qsort
Cqsort>>primQsort: array with: count with: size with: compare
self
ffiCall: #(void qsort (FFIExternalArray array, size_t count, size_t size, FFICallback compare))
module: LibC
Cqsort>>example
| array callback |
array := FFIExternalArray newType: 'double' size: 100.
1 to: 100 do: [ :i | array at: i put: (100 atRandom asFloat) ].
callback := FFICallback
signature: #(int (const void *arg1, const void *arg2))
block: [ :arg1 :arg2 |
((arg1 doubleAt: 1) - (arg2 doubleAt: 1)) sign ].
self
primQsort: array
with: 100
with: (FFIExternalType sizeOf: ‘double’)
with: callback.
Status
• Feature complete (but I keep adding stuff when
requested)
• Documentation ongoing
• Still can accept a lot of optimisations (but that
will be for versions 1.x)
Summary
• Replace for NativeBoost keeping its philosophy
• Simple Callout/Callback system
• Very easy to extend (no need of ASM
knowledge)
• Is ready to use in Pharo 5.0
Thanks!
Smalltalk quitSession.

Más contenido relacionado

Más de ESUG

Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
ESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
ESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
ESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
ESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
ESUG
 
gt4atproto, A Programmable Environment for Social Media
gt4atproto, A Programmable Environment for Social Mediagt4atproto, A Programmable Environment for Social Media
gt4atproto, A Programmable Environment for Social Media
ESUG
 

Más de ESUG (20)

Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 
BioSmalltalk
BioSmalltalkBioSmalltalk
BioSmalltalk
 
gt4atproto, A Programmable Environment for Social Media
gt4atproto, A Programmable Environment for Social Mediagt4atproto, A Programmable Environment for Social Media
gt4atproto, A Programmable Environment for Social Media
 
Roassal3 update
Roassal3 updateRoassal3 update
Roassal3 update
 

Último

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Último (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

UnifiedFFI - A common language for the outside world

  • 1. UnifiedFFI A common language to talk with the outside world Now with dem o!
  • 3.
  • 4. What is UnifiedFFI • A front-end to express Foreign Function Interface (FFI) calls in Pharo. • Uses ThreadedFFIPlugin, but should be able to plug others in the future. • It shares same philosophy as NativeBoost ‣ keep as much as possible in the image ‣ no need to modify VM to add functionality ‣ But it is not ASM: Just plain Smalltalk.
  • 5. But, what happened with NativeBoost? • It was not working on Spur • It was hard to maintain (and we need a different implementation for each architecture) • Since we were using NB exclusively for FFI, we decided to replace it with a different one, using the VM plugin
  • 6. UnifiedFFI goals • Keep NativeBoost syntax ‣ Because is cool :) ‣ Provide backward compatibility for most uses • Enhance documentation and self-documentation • Be the unified base for future FFI backends implementations
  • 7. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC (People who know NativeBoost will find this very familiar….)
  • 8. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC A regular Pharo method with one argument
  • 9. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC A literal array to represent C function
  • 10. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC Types annotation used to generate marshalling code
  • 11. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC The value to be passed when calling out
  • 12. How does a call looks like? char *getenv(const char *) getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC The library to lookup C function
  • 13. FFILibrary • A very simple abstraction to define module names that can be different each platform. • Can be used also as a place to store C function definitions (like a real library :) ).
  • 14. FFILibrary: LibC FFILibrary subclass: #LibC LibC>>unixModuleName ^ ‘libc.so.6' LibC>>macModuleName ^ ‘libc.dylib' LibC>>win32ModuleName ^ ‘msvcrt.dll' LibC>>memCopy: src to: dest size: n ^ self ffiCall: #(void *memcpy(void *dest, const void *src, size_t n))
  • 15. Insights to UnifiedFFI getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC
  • 16. Insights to UnifiedFFI getEnv: variable ^ self ffiCall: #( String getenv( String variable )) module: LibC 1.Generate bytecodes for marshalling 2.Re-send the method execution char *getenv(const char *)
  • 17. How does a call looks like? (bytecode version) char *getenv(const char *) 21 <20> pushConstant: <cdecl: char* 'getenv' (char*) module: 'libc.dylib'> 22 <10> pushTemp: 0 23 <8A 81> pop 1 into (Array new: 1) 25 <E1> send: invokeWithArguments: 26 <7C> returnTop
  • 18. Types • Support for standard C types: int, float, etc. • Support for type aliases (map a name to one of the defined types) • Complex types: • FFIExternalObject: External addresses (objects) • FFIOpaqueObject: Opaque C types/structures • FFIExternalStructure • FFIExternalArray, FFITypeArray • FFIExternalEnumeration • FFIExternalValueHolder: Buffers (to pass referenced data, e.g. “double *”) • FFIConstantHandle: Windows HANDLE (constant addresses)
  • 19. FFIExternalObject (1) AthensSurface subclass: #AthensCairoSurface uses: TCairoLibrary instanceVariableNames: 'handle context builder id ftFontRenderer session' classVariableNames: '' poolDictionaries: 'AthensCairoDefs' package: ‘Athens-Cairo' cairo_surface_t * cairo_image_surface_create (cairo_format_t format, int width, int height);
  • 20. FFIExternalObject (2) AthensCairoSurface class>>primImage: aFormat width: aWidth height: aHeight ^self ffiCall: #(AthensCairoSurface cairo_image_surface_create ( int aFormat, int aWidth, int aHeight) ) cairo_surface_t * cairo_image_surface_create (cairo_format_t format, int width, int height);
  • 21. FFIExternalObject (3) AthensCairoSurface>>getDataPtr "get a pointer to surface bitmap data" ^self ffiCall: #( void* cairo_image_surface_get_data ( self ) ) unsigned char * cairo_image_surface_get_data (cairo_surface_t *surface);
  • 22. FFICallback callback := FFICallback signature: #(int (const void *arg1, const void *arg2)) block: [ :arg1 :arg2 | ((arg1 doubleAt: 1) - (arg2 doubleAt: 1)) sign ]. int (*compar)(const void*,const void*)
  • 23. FFICallback callback := FFICallback signature: #(int (const void *arg1, const void *arg2)) block: [ :arg1 :arg2 | ((arg1 doubleAt: 1) - (arg2 doubleAt: 1)) sign ]. int (*compar)(const void*,const void*) A literal array to represent C anonymous function
  • 24. FFICallback: qsort Cqsort>>primQsort: array with: count with: size with: compare self ffiCall: #(void qsort (FFIExternalArray array, size_t count, size_t size, FFICallback compare)) module: LibC Cqsort>>example | array callback | array := FFIExternalArray newType: 'double' size: 100. 1 to: 100 do: [ :i | array at: i put: (100 atRandom asFloat) ]. callback := FFICallback signature: #(int (const void *arg1, const void *arg2)) block: [ :arg1 :arg2 | ((arg1 doubleAt: 1) - (arg2 doubleAt: 1)) sign ]. self primQsort: array with: 100 with: (FFIExternalType sizeOf: ‘double’) with: callback.
  • 25. Status • Feature complete (but I keep adding stuff when requested) • Documentation ongoing • Still can accept a lot of optimisations (but that will be for versions 1.x)
  • 26. Summary • Replace for NativeBoost keeping its philosophy • Simple Callout/Callback system • Very easy to extend (no need of ASM knowledge) • Is ready to use in Pharo 5.0