Skip to content

Commit

Permalink
Replaces int with uint32_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
a.stecher committed Oct 8, 2024
1 parent 483d509 commit 8284cbb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef struct frankenphp_server_context {
} frankenphp_server_context;

__thread frankenphp_server_context *local_ctx = NULL;
__thread int thread_index;
__thread uint32_t thread_index;

static void frankenphp_free_request_context() {
frankenphp_server_context *ctx = SG(server_context);
Expand Down Expand Up @@ -724,7 +724,7 @@ static void set_thread_name(char *thread_name) {
static void *php_thread(void *arg) {
char thread_name[16] = {0};
snprintf(thread_name, 16, "php-%" PRIxPTR, (uintptr_t)arg);
thread_index = (int)(uintptr_t)arg;
thread_index = (uint32_t)(uintptr_t)arg;
set_thread_name(thread_name);

#ifdef ZTS
Expand Down
18 changes: 9 additions & 9 deletions frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error
}

//export go_handle_request
func go_handle_request(threadIndex int) bool {
func go_handle_request(threadIndex C.uint32_t) bool {
select {
case <-done:
return false
Expand Down Expand Up @@ -541,7 +541,7 @@ func maybeCloseContext(fc *FrankenPHPContext) {
}

//export go_ub_write
func go_ub_write(threadIndex int, cBuf *C.char, length C.int) (C.size_t, C.bool) {
func go_ub_write(threadIndex C.uint32_t, cBuf *C.char, length C.int) (C.size_t, C.bool) {
r := getPHPThread(threadIndex).getActiveRequest()
fc, _ := FromContext(r.Context())

Expand Down Expand Up @@ -580,7 +580,7 @@ var headerKeyCache = func() otter.Cache[string, string] {
}()

//export go_register_variables
func go_register_variables(threadIndex int, trackVarsArray *C.zval) {
func go_register_variables(threadIndex C.uint32_t, trackVarsArray *C.zval) {
thread := getPHPThread(threadIndex)
r := thread.getActiveRequest()
fc := r.Context().Value(contextKey).(*FrankenPHPContext)
Expand Down Expand Up @@ -649,7 +649,7 @@ func go_register_variables(threadIndex int, trackVarsArray *C.zval) {
}

//export go_apache_request_headers
func go_apache_request_headers(threadIndex int, hasActiveRequest bool) (*C.go_string, C.size_t) {
func go_apache_request_headers(threadIndex C.uint32_t, hasActiveRequest bool) (*C.go_string, C.size_t) {
thread := getPHPThread(threadIndex)

if !hasActiveRequest {
Expand Down Expand Up @@ -691,7 +691,7 @@ func go_apache_request_headers(threadIndex int, hasActiveRequest bool) (*C.go_st
}

//export go_apache_request_cleanup
func go_apache_request_cleanup(threadIndex int) {
func go_apache_request_cleanup(threadIndex C.uint32_t) {
getPHPThread(threadIndex).pinner.Unpin()
}

Expand All @@ -709,7 +709,7 @@ func addHeader(fc *FrankenPHPContext, cString *C.char, length C.int) {
}

//export go_write_headers
func go_write_headers(threadIndex int, status C.int, headers *C.zend_llist) {
func go_write_headers(threadIndex C.uint32_t, status C.int, headers *C.zend_llist) {
r := getPHPThread(threadIndex).getActiveRequest()
fc := r.Context().Value(contextKey).(*FrankenPHPContext)

Expand Down Expand Up @@ -737,7 +737,7 @@ func go_write_headers(threadIndex int, status C.int, headers *C.zend_llist) {
}

//export go_sapi_flush
func go_sapi_flush(threadIndex int) bool {
func go_sapi_flush(threadIndex C.uint32_t) bool {
r := getPHPThread(threadIndex).getActiveRequest()
fc := r.Context().Value(contextKey).(*FrankenPHPContext)

Expand All @@ -755,7 +755,7 @@ func go_sapi_flush(threadIndex int) bool {
}

//export go_read_post
func go_read_post(threadIndex int, cBuf *C.char, countBytes C.size_t) (readBytes C.size_t) {
func go_read_post(threadIndex C.uint32_t, cBuf *C.char, countBytes C.size_t) (readBytes C.size_t) {
r := getPHPThread(threadIndex).getActiveRequest()

p := unsafe.Slice((*byte)(unsafe.Pointer(cBuf)), countBytes)
Expand All @@ -770,7 +770,7 @@ func go_read_post(threadIndex int, cBuf *C.char, countBytes C.size_t) (readBytes
}

//export go_read_cookies
func go_read_cookies(threadIndex int) *C.char {
func go_read_cookies(threadIndex C.uint32_t) *C.char {
r := getPHPThread(threadIndex).getActiveRequest()

cookies := r.Cookies()
Expand Down
6 changes: 4 additions & 2 deletions php_thread.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package frankenphp

// #include <stdint.h>
import "C"
import (
"net/http"
"runtime"
Expand All @@ -22,8 +24,8 @@ func initializePHPThreads(numThreads int) {
}
}

func getPHPThread(threadIndex int) *phpThread {
return phpThreads[threadIndex]
func getPHPThread(threadIndex C.uint32_t) *phpThread {
return phpThreads[int(threadIndex)]
}

func (thread *phpThread) setMainRequest(request *http.Request) {
Expand Down
1 change: 1 addition & 0 deletions php_thread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestMainRequestIsActiveRequest(t *testing.T) {
thread.setMainRequest(mainRequest)

assert.Equal(t, mainRequest, thread.getActiveRequest())
assert.Equal(t, mainRequest, thread.getMainRequest())
}

func TestWorkerRequestIsActiveRequest(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func assignThreadToWorker(thread *phpThread) {
}

//export go_frankenphp_worker_handle_request_start
func go_frankenphp_worker_handle_request_start(threadIndex int) C.bool {
func go_frankenphp_worker_handle_request_start(threadIndex C.uint32_t) C.bool {
thread := getPHPThread(threadIndex)

// we assign a worker to the thread if it doesn't have one already
Expand Down Expand Up @@ -282,7 +282,7 @@ func go_frankenphp_worker_handle_request_start(threadIndex int) C.bool {
}

//export go_frankenphp_finish_request
func go_frankenphp_finish_request(threadIndex int, isWorkerRequest bool) {
func go_frankenphp_finish_request(threadIndex C.uint32_t, isWorkerRequest bool) {
thread := getPHPThread(threadIndex)
r := thread.getActiveRequest()
fc := r.Context().Value(contextKey).(*FrankenPHPContext)
Expand Down

0 comments on commit 8284cbb

Please sign in to comment.