Skip to content

Start use DynamicLibrary.invoke() but not only DynamicLibrary.invokeEx() #4

@mezoni

Description

@mezoni

You use only invokeEx() and not use invoke().

static dynamic invoke(String name, [List<dynamic> args = const [], List<BinaryType> vartypes]) {
    return libc.invokeEx(name, args, vartypes);
  }

The method invoke() not much slower than invokeEx()
But it are more intellectual way and it will be improved further.

Improved performance of the DynamicLibrary.invoke() with a variable parameters through the precompilation of the commonly used binary types (bool, char, char *,int, double)

This has effect also when you use strings but not only with variadic functions.

Also I plan implement propogating null's (converting) to appropriate pointers.

Code fragment of invoke().

if (argument is String) {
          if (parameter is PointerType) {
            var valueType = parameter.type;
            if (valueType.kind == basicTypes.charType.kind) {
              if (strings == null) {
                strings = <BinaryObject>[];
              }

              var string = valueType.array(argument.length + 1).alloc(argument.codeUnits);
              strings.add(string);
              newArguments[i] = string;
            } else {
              throw new ArgumentError("Unable to allocate string object for parameter $i: $parameter");
            }
          }
        } else if (argument == null) {
          // TODO: "Promoting NULL values not implemented yet"
          throw new UnimplementedError("Promoting NULL values not implemented yet");
        } 

As you can see it automatically perform the following tasks.

  • Converts the String (allocates them without invoke the helper.allocString())
  • Creates the heap for them
  • Promoting NULL values (will be added soon)

P.S.

Also I plan to add segmentation fault handler into unsafe extension for the graceful exits with a Dart stack trace (instead of only exit code 139 "post mortem").

After that I implement "auto NULL pointer promoting" (if SEGFAULT will work with a success in Dart VM).

As for me second looks (and works) better than first.

_checkResult(invoke("sysctlbyname", [n, getType("void*").nullPtr, len, getType("void*").nullPtr, 0]));

_checkResult(invoke__("sysctlbyname", [n, null, len, null, 0]));

Of course, if the idea with a SEGFAULT will be able to display" post mortem "stack trace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions