Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7a4c2ab
[cpphttp] make server agnostic on webapp implementation
melkyades Apr 24, 2025
5dfc950
[cpphttp] rename CPPHTTP* to just HTTP*
melkyades Apr 24, 2025
cea3d33
[vm-cpp] add support for arm64 in ffi
melkyades Apr 24, 2025
314a52d
[ffi] share ffi submodule for linux and mac as posix
melkyades Apr 27, 2025
aaba927
[vm-cpp][ffi] add support for getting loader handle in macos and windows
melkyades Apr 27, 2025
71d9e53
[vm-cpp] avoid signedness undefined behavior warning
melkyades Apr 27, 2025
c2b5098
[vm-cpp][ffi] use libffi closure and code_location appropiately (they…
melkyades Apr 27, 2025
3d72b1f
[vm-cpp] correct subscript error in U*AtOfffset underprims
melkyades Apr 27, 2025
9054211
[vm-cpp] while #dnu is still unimlemented, at least print an error wh…
melkyades Apr 27, 2025
bdd2c76
[ffi] add support for mac dylib filenames
melkyades Apr 27, 2025
adec0c8
[ffi] ExternalHandle >> #asInteger seemed to be missing
melkyades Apr 27, 2025
0793876
[vm-cpp] add missing method to set special bit in object headers
melkyades Apr 28, 2025
2dacfa0
[vm-cpp] add primitive to set special bit in object headers
melkyades Apr 28, 2025
fa65aad
[kernel] move references from Smalltalk to Kernel
melkyades Apr 28, 2025
64b1db3
[kernel] add _beSpecial to ProtoObject
melkyades Apr 28, 2025
bd2a72c
[ffi] remove unnecessary logging
melkyades Apr 28, 2025
8bbedec
[cpp-httplib] make ssl and crypto linking also work on macos
melkyades Apr 28, 2025
8bffd2e
[http] remove renamed file
melkyades Apr 29, 2025
f29afb4
[vm-cpp] disable doing GC in callbacks for now (we have to make that …
melkyades Apr 29, 2025
eaf5f7b
[vm-cpp] make replaceStringFromToWithStartingAt primitive check for e…
melkyades Apr 29, 2025
cdbb086
[kernel] implement String>>replaceFrom:to:with:startingAt: failure path
melkyades Apr 29, 2025
7ab0343
[http] implement ffi glue for request path_params at
melkyades Apr 29, 2025
f61efaa
[http] implement st side of Request_ParamAt ffi binding
melkyades Apr 29, 2025
da1633e
[http] update example for improved http server api, make hello :name …
melkyades Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions modules/Examples/HTTPServer/ExampleAPI.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ Class {
#superclass : #Object,
#instVars : [
'request',
'response',
'server'
'response'
],
#category : #'Examples-HTTPServer'
}

{ #category : #spec }
ExampleAPI >> hello [
server library
response: response asParameter
setContents: 'hello, world!' externalCopy asParameter
type: 'text/html' externalCopy asParameter
| name |
name := request paramAt: 'name'.
name isEmpty ifTrue: [name := 'world'].
response setContents: 'hello, ', name, '!' type: 'text/html'
]

{ #category : #spec }
Expand All @@ -27,8 +26,3 @@ ExampleAPI >> response: aResponse [
response := aResponse
]

{ #category : #spec }
ExampleAPI >> server: aCPPHTTPServer [
server := aCPPHTTPServer
]

24 changes: 16 additions & 8 deletions modules/Examples/HTTPServer/HTTPServerModule.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@ Class {
{ #category : #spec }
HTTPServerModule >> imports [
^{
#'HTTP.CPPHTTPServer' -> #(CPPHTTPServer).
#'HTTP.CPPHTTPServer' -> #(HTTPServer).
#FFI -> #(ExternalLibrary).

}
]

{ #category : #spec }
HTTPServerModule >> handle: request into: response with: selector [
| api |
api := ExampleAPI new
request: request;
response: response.
api perform: selector.
"response headersAt: 'Access-Control-Allow-Origin' put: '*'."
]

{ #category : #services }
HTTPServerModule >> main: arguments [
| server |
"Transcript show: 'starting server!'."
| server base |
ExternalLibrary module initializeForCurrentPlatform.

server := CPPHTTPServer new apiClass: ExampleAPI.
base := arguments at: 3 ifAbsent: ['/egg'].
server := HTTPServer new.
server
baseUri: '/egg';
routeGET: '/hello' to: #hello.
routeGET: base, '/hello/:name' to: #hello with: self.
Kernel log: 'server configured, starting!', String cr.
server start.
^0
]
5 changes: 5 additions & 0 deletions modules/FFI/ExternalHandle.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ ExternalHandle class >> new [
^self new: WordSize
]

{ #category : #'accessing' }
ExternalHandle >> asInteger [
^self pointerAtOffset: 0
]

{ #category : #'testing' }
ExternalHandle >> isValid [
^self asInteger != 0
Expand Down
5 changes: 5 additions & 0 deletions modules/FFI/ExternalLibrary.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ ExternalLibrary class >> linuxFilename [
^'lib', self libname, '.so'
]

{ #category : #accessing }
ExternalLibrary class >> macFilename [
^'lib', self libname, '.dylib'
]

{ #category : #accessing }
ExternalLibrary class >> windowsFilename [
^self libname, '.dll'
Expand Down
2 changes: 1 addition & 1 deletion modules/FFI/ExternalMemory.st
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ExternalMemory >> externalCopy [

{ #category : #finalization }
ExternalMemory >> finalizationRegistry [
^Smalltalk resourceRegistry
^Kernel session resourceRegistry
]

{ #category : #finalization }
Expand Down
22 changes: 16 additions & 6 deletions modules/FFI/FFIModule.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ FFIModule >> initializeFor: moduleName loader: loaderName [
at: #FFI put: self;
at: #OS put: module.
loaderType := module namespace at: loaderName.
loader := loaderType new.
loader := loaderType new
]

{ #category : #private }
FFIModule >> initializeLibC [
libc := LibC new.
loader bootstrapOpen: libc.
defaultHeap := mallocHeap := MallocHeap new
Expand All @@ -52,18 +56,24 @@ FFIModule >> initializeForCurrentPlatform [
]

{ #category : #initialization }
FFIModule >> initializeForMac [
self initializeFor: #'FFI.Mac' loader: #MacLibraryLoader
FFIModule >> initializeForLinux [
self
initializeFor: #'FFI.Posix' loader: #PosixLibraryLoader;
initializeLibC
]

{ #category : #initialization }
FFIModule >> initializeForLinux [
self initializeFor: #'FFI.Linux' loader: #LinuxLibraryLoader
FFIModule >> initializeForMac [
self initializeFor: #'FFI.Posix' loader: #PosixLibraryLoader.
loader beMac.
self initializeLibC.
]

{ #category : #initialization }
FFIModule >> initializeForWindows [
self initializeFor: #'FFI.Windows' loader: #WindowsLibraryLoader
self
initializeFor: #'FFI.Windows' loader: #WindowsLibraryLoader;
initializeLibC.
]

{ #category : #initialization }
Expand Down
69 changes: 0 additions & 69 deletions modules/FFI/Linux/LinuxLibraryLoader.st

This file was deleted.

File renamed without changes.
80 changes: 80 additions & 0 deletions modules/FFI/Posix/PosixLibraryLoader.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"
Copyright (c) 2024, Javier Pimás.
See (MIT) license in root directory.

I'm an object that allows loading dynamic libraries in Linux and Mac. For that,
I call dlopen and dlsym, part of dl library. To bootstrap, the dl library
object handle and dlsym addresses are initialized through a host VM primitive.
"

Class {
#name : #PosixLibraryLoader,
#superclass : #LibraryLoader,
#instVars : [
'dl',
'linux'
],
#category : #FFI
}

{ #category : #accessing }
PosixLibraryLoader >> beMac [
linux := false
]

{ #category : #bootstrap }
PosixLibraryLoader >> bootstrapOpen: anExternalLibrary [
"
We do this because externalCopy asParameter requires libc/calloc to be already loaded
"
| filename path parameter handle |
filename := self libraryFilename: anExternalLibrary class.
path := anExternalLibrary class libpath, filename.
parameter := Array with: path.
handle := filename = 'libc.dylib'
ifTrue: [dl handle asInteger]
ifFalse: [dl dlopen: parameter flags: 1. "RTLD_LAZY"].
handle = 0 ifTrue: [dl lastError].
anExternalLibrary address: handle.
]

{ #category : #accessing }
PosixLibraryLoader >> close: anExternalLibrary [
dl dlclose: anExternalLibrary asParameter
]

{ #category : #accessing }
PosixLibraryLoader >> findSymbol: aSymbol in: anExternalLibrary [
^dl dlsym: anExternalLibrary asParameter symbol: aSymbol externalCopy asParameter
]

{ #category : #accessing }
PosixLibraryLoader >> initialize [
linux := true.
dl := DLLibrary new.
Kernel host initializeFFI: dl symbolFinder: DLLibrary >> #dlsym:symbol:.
self initializeDLErrorDescriptor
]

{ #category : #accessing }
PosixLibraryLoader >> initializeDLErrorDescriptor [
"
Sending dlerror for the first time initializes libdl descriptor, through dlsym. This makes
subsequent sends of dlerror not call dlsym, which would invalidate the last error code
"
dl dlerror
]
{ #category : #accessing }
PosixLibraryLoader >> libraryFilename: externalLibrary [
^linux ifTrue: [ externalLibrary linuxFilename ] ifFalse: [ externalLibrary macFilename ]
]

{ #category : #services }
PosixLibraryLoader >> open: anExternalLibrary [
| filename path handle |
filename := self libraryFilename: anExternalLibrary class.
path := anExternalLibrary class libpath, filename.
handle := dl dlopen: path externalCopy asParameter flags: 1. "RTLD_LAZY"
handle = 0 ifTrue: [Error signal: dl lastError].
anExternalLibrary address: handle
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"

Class {
#name : #LinuxModule,
#name : #PosixModule,
#superclass : #Module,
#category : #FFI
}

{ #category : #services }
LinuxModule >> externalCopyOfString: aString [
PosixModule >> externalCopyOfString: aString [
^Kernel utf8 externalCopyOf: aString
]

{ #category : #services }
LinuxModule >> imports [
PosixModule >> imports [
^{ #FFI -> #(ExternalLibrary ExternalMemory LibraryLoader) }
]
71 changes: 0 additions & 71 deletions modules/HTTP/CPPHTTPServer/CPPHTTPServer.st

This file was deleted.

Loading