Skip to content

Commit 35d65ee

Browse files
committed
src: fix arguments handling
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 633528a commit 35d65ee

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,25 @@ FFI_BINDING_SOURCES := \
551551
$(wildcard test/ffi/*/*.c) \
552552
$(wildcard test/ffi/*/*.def)
553553

554+
ifndef NOFFI
554555
# Implicitly depends on $(NODE_EXE), see the build-ffi-tests rule for rationale.
555556
test/ffi/.buildstamp: $(ADDONS_PREREQS) \
556557
$(FFI_BINDING_GYPS) $(FFI_BINDING_SOURCES)
557558
@$(call run_build_addons,"$$PWD/test/ffi",$@)
559+
else
560+
test/ffi/.buildstamp:
561+
endif
558562

559563
.PHONY: build-ffi-tests
564+
ifndef NOFFI
560565
# .buildstamp needs $(NODE_EXE) but cannot depend on it
561566
# directly because it calls make recursively. The parent make cannot know
562567
# if the subprocess touched anything so it pessimistically assumes that
563568
# .buildstamp is out of date and need a rebuild.
564569
build-ffi-tests: | $(NODE_EXE) test/ffi/.buildstamp ## Build FFI tests.
570+
else
571+
build-ffi-tests:
572+
endif
565573

566574
.PHONY: clear-stalled
567575
clear-stalled: ## Clear any stalled processes.
@@ -584,6 +592,8 @@ test-build-node-api: all build-node-api-tests ## Build Node-API tests.
584592
.PHONY: test-build-sqlite
585593
test-build-sqlite: all build-sqlite-tests ## Build SQLite tests.
586594

595+
.PHONY: test-build-ffi
596+
test-build-ffi: all build-ffi-tests ## Build FFI tests.
587597

588598
.PHONY: test-all
589599
test-all: test-build ## Run default tests with both Debug and Release builds.
@@ -653,6 +663,7 @@ test-ci: | clear-stalled bench-addons-build build-addons build-js-native-api-tes
653663
build-ci: ## Build everything (CI).
654664
$(PYTHON) ./configure --verbose $(CONFIG_FLAGS)
655665
$(MAKE)
666+
$(MAKE) build-ffi-tests
656667

657668
.PHONY: run-ci
658669
# Run by CI tests, exceptions:
@@ -755,6 +766,16 @@ test-sqlite-clean: ## Remove SQLite testing artifacts.
755766
$(RM) -r test/sqlite/*/build
756767
$(RM) test/sqlite/.buildstamp
757768

769+
.PHONY: test-ffi
770+
test-ffi: test-build-ffi ## Run FFI tests.
771+
$(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) ffi
772+
773+
.PHONY: test-ffi-clean
774+
.NOTPARALLEL: test-ffi-clean
775+
test-ffi-clean: ## Remove FFI testing artifacts.
776+
$(RM) -r test/ffi/*/build
777+
$(RM) test/ffi/.buildstamp
778+
758779
.PHONY: test-addons
759780
test-addons: test-build test-js-native-api test-node-api ## Run addon tests.
760781
$(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) addons
@@ -1248,6 +1269,7 @@ ifeq ($(SKIP_SHARED_DEPS), 1)
12481269
$(RM) -r $(TARNAME)/deps/icu-small
12491270
$(RM) -r $(TARNAME)/deps/icu-tmp
12501271
$(RM) -r $(TARNAME)/deps/LIEF
1272+
$(RM) -r $(TARNAME)/deps/libffi
12511273
$(RM) -r $(TARNAME)/deps/llhttp
12521274
$(RM) -r $(TARNAME)/deps/merve
12531275
$(RM) -r $(TARNAME)/deps/nbytes
@@ -1522,6 +1544,7 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
15221544
test/embedding/*.cc \
15231545
test/embedding/*.h \
15241546
test/sqlite/*/*.c \
1547+
test/ffi/*/*.c \
15251548
test/fixtures/*.c \
15261549
test/js-native-api/*/*.cc \
15271550
test/node-api/*/*.cc \
@@ -1546,6 +1569,7 @@ FORMAT_CPP_FILES += $(wildcard \
15461569
test/node-api/*/*.c \
15471570
test/node-api/*/*.h \
15481571
test/sqlite/*/*.c \
1572+
test/ffi/*/*.c \
15491573
)
15501574

15511575
# Code blocks don't have newline at the end,

src/ffi/types.cc

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ bool ThrowIfContainsNullBytes(Environment* env,
4444
return false;
4545
}
4646

47-
bool IsFFINarrowSignedInteger(ffi_type* type) {
48-
return type == &ffi_type_sint8 || type == &ffi_type_sint16;
49-
}
50-
51-
bool IsFFINarrowUnsignedInteger(ffi_type* type) {
52-
return type == &ffi_type_uint8 || type == &ffi_type_uint16;
53-
}
54-
55-
bool IsFFINarrowInteger(ffi_type* type) {
56-
return IsFFINarrowSignedInteger(type) || IsFFINarrowUnsignedInteger(type);
57-
}
58-
5947
bool HasProperty(Local<Context> context,
6048
Local<Object> object,
6149
Local<String> key,
@@ -510,7 +498,9 @@ Local<Value> ToJSArgument(Isolate* isolate, ffi_type* type, void* data) {
510498
}
511499

512500
size_t GetFFIReturnValueStorageSize(ffi_type* type) {
513-
if (IsFFINarrowInteger(type)) {
501+
if (type == &ffi_type_sint8 || type == &ffi_type_uint8 ||
502+
type == &ffi_type_sint16 || type == &ffi_type_uint16 ||
503+
type == &ffi_type_sint32 || type == &ffi_type_uint32) {
514504
return sizeof(ffi_arg);
515505
}
516506

@@ -536,9 +526,11 @@ bool ToJSReturnValue(Environment* env,
536526
args.GetReturnValue().Set(static_cast<uint32_t>(
537527
static_cast<uint16_t>(*static_cast<const ffi_arg*>(result))));
538528
} else if (type == &ffi_type_sint32) {
539-
args.GetReturnValue().Set(*static_cast<const int32_t*>(result));
529+
args.GetReturnValue().Set(
530+
static_cast<int32_t>(*static_cast<const ffi_sarg*>(result)));
540531
} else if (type == &ffi_type_uint32) {
541-
args.GetReturnValue().Set(*static_cast<const uint32_t*>(result));
532+
args.GetReturnValue().Set(
533+
static_cast<uint32_t>(*static_cast<const ffi_arg*>(result)));
542534
} else if (type == &ffi_type_sint64) {
543535
args.GetReturnValue().Set(
544536
BigInt::New(env->isolate(), *static_cast<const int64_t*>(result)));

0 commit comments

Comments
 (0)