Win32 API 日本語リファレンス
ホームGlobalization › u_setMemoryFunctions

u_setMemoryFunctions

関数
ICUが使用するメモリ確保関数を独自に設定する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

// icuuc.dll
#include <windows.h>

void u_setMemoryFunctions(
    const void* context,
    UMemAllocFn* a,
    UMemReallocFn* r,
    UMemFreeFn* f,
    UErrorCode* status
);

パラメーター

名前方向説明
contextvoid*in各メモリ関数に渡される任意のユーザーデータ。NULL可。
aUMemAllocFn*inoutメモリ確保(malloc相当)を行うコールバック関数へのポインタ。
rUMemReallocFn*inoutメモリ再確保(realloc相当)を行うコールバック関数へのポインタ。
fUMemFreeFn*inoutメモリ解放(free相当)を行うコールバック関数へのポインタ。
statusUErrorCode*inoutエラーコードを入出力するポインタ。u_init前に1度だけ呼ぶ必要がある。

戻り値の型: void

各言語での呼び出し定義

// icuuc.dll
#include <windows.h>

void u_setMemoryFunctions(
    const void* context,
    UMemAllocFn* a,
    UMemReallocFn* r,
    UMemFreeFn* f,
    UErrorCode* status
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void u_setMemoryFunctions(
    IntPtr context,   // void*
    IntPtr a,   // UMemAllocFn* in/out
    IntPtr r,   // UMemReallocFn* in/out
    IntPtr f,   // UMemFreeFn* in/out
    ref int status   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub u_setMemoryFunctions(
    context As IntPtr,   ' void*
    a As IntPtr,   ' UMemAllocFn* in/out
    r As IntPtr,   ' UMemReallocFn* in/out
    f As IntPtr,   ' UMemFreeFn* in/out
    ByRef status As Integer   ' UErrorCode* in/out
)
End Sub
' context : void*
' a : UMemAllocFn* in/out
' r : UMemReallocFn* in/out
' f : UMemFreeFn* in/out
' status : UErrorCode* in/out
Declare PtrSafe Sub u_setMemoryFunctions Lib "icuuc" ( _
    ByVal context As LongPtr, _
    ByVal a As LongPtr, _
    ByVal r As LongPtr, _
    ByVal f As LongPtr, _
    ByRef status As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

u_setMemoryFunctions = ctypes.cdll.icuuc.u_setMemoryFunctions
u_setMemoryFunctions.restype = None
u_setMemoryFunctions.argtypes = [
    ctypes.POINTER(None),  # context : void*
    ctypes.c_void_p,  # a : UMemAllocFn* in/out
    ctypes.c_void_p,  # r : UMemReallocFn* in/out
    ctypes.c_void_p,  # f : UMemFreeFn* in/out
    ctypes.c_void_p,  # status : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
u_setMemoryFunctions = Fiddle::Function.new(
  lib['u_setMemoryFunctions'],
  [
    Fiddle::TYPE_VOIDP,  # context : void*
    Fiddle::TYPE_VOIDP,  # a : UMemAllocFn* in/out
    Fiddle::TYPE_VOIDP,  # r : UMemReallocFn* in/out
    Fiddle::TYPE_VOIDP,  # f : UMemFreeFn* in/out
    Fiddle::TYPE_VOIDP,  # status : UErrorCode* in/out
  ],
  Fiddle::TYPE_VOID, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn u_setMemoryFunctions(
        context: *const (),  // void*
        a: *mut *const core::ffi::c_void,  // UMemAllocFn* in/out
        r: *mut *const core::ffi::c_void,  // UMemReallocFn* in/out
        f: *mut *const core::ffi::c_void,  // UMemFreeFn* in/out
        status: *mut i32  // UErrorCode* in/out
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void u_setMemoryFunctions(IntPtr context, IntPtr a, IntPtr r, IntPtr f, ref int status);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_setMemoryFunctions' -Namespace Win32 -PassThru
# $api::u_setMemoryFunctions(context, a, r, f, status)
#uselib "icuuc.dll"
#func global u_setMemoryFunctions "u_setMemoryFunctions" sptr, sptr, sptr, sptr, sptr
; u_setMemoryFunctions context, a, r, f, varptr(status)
; context : void* -> "sptr"
; a : UMemAllocFn* in/out -> "sptr"
; r : UMemReallocFn* in/out -> "sptr"
; f : UMemFreeFn* in/out -> "sptr"
; status : UErrorCode* in/out -> "sptr"
出力引数:
#uselib "icuuc.dll"
#func global u_setMemoryFunctions "u_setMemoryFunctions" sptr, sptr, sptr, sptr, var
; u_setMemoryFunctions context, a, r, f, status
; context : void* -> "sptr"
; a : UMemAllocFn* in/out -> "sptr"
; r : UMemReallocFn* in/out -> "sptr"
; f : UMemFreeFn* in/out -> "sptr"
; status : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void u_setMemoryFunctions(void* context, UMemAllocFn* a, UMemReallocFn* r, UMemFreeFn* f, UErrorCode* status)
#uselib "icuuc.dll"
#func global u_setMemoryFunctions "u_setMemoryFunctions" intptr, intptr, intptr, intptr, var
; u_setMemoryFunctions context, a, r, f, status
; context : void* -> "intptr"
; a : UMemAllocFn* in/out -> "intptr"
; r : UMemReallocFn* in/out -> "intptr"
; f : UMemFreeFn* in/out -> "intptr"
; status : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procu_setMemoryFunctions = icuuc.NewProc("u_setMemoryFunctions")
)

// context (void*), a (UMemAllocFn* in/out), r (UMemReallocFn* in/out), f (UMemFreeFn* in/out), status (UErrorCode* in/out)
r1, _, err := procu_setMemoryFunctions.Call(
	uintptr(context),
	uintptr(a),
	uintptr(r),
	uintptr(f),
	uintptr(status),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure u_setMemoryFunctions(
  context: Pointer;   // void*
  a: Pointer;   // UMemAllocFn* in/out
  r: Pointer;   // UMemReallocFn* in/out
  f: Pointer;   // UMemFreeFn* in/out
  status: Pointer   // UErrorCode* in/out
); cdecl;
  external 'icuuc.dll' name 'u_setMemoryFunctions';
result := DllCall("icuuc\u_setMemoryFunctions"
    , "Ptr", context   ; void*
    , "Ptr", a   ; UMemAllocFn* in/out
    , "Ptr", r   ; UMemReallocFn* in/out
    , "Ptr", f   ; UMemFreeFn* in/out
    , "Ptr", status   ; UErrorCode* in/out
    , "Cdecl Int")   ; return: void
●u_setMemoryFunctions(context, a, r, f, status) = DLL("icuuc.dll", "int u_setMemoryFunctions(void*, void*, void*, void*, void*)")
# 呼び出し: u_setMemoryFunctions(context, a, r, f, status)
# context : void* -> "void*"
# a : UMemAllocFn* in/out -> "void*"
# r : UMemReallocFn* in/out -> "void*"
# f : UMemFreeFn* in/out -> "void*"
# status : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。
const std = @import("std");

extern "icuuc" fn u_setMemoryFunctions(
    context: ?*anyopaque, // void*
    a: ?*anyopaque, // UMemAllocFn* in/out
    r: ?*anyopaque, // UMemReallocFn* in/out
    f: ?*anyopaque, // UMemFreeFn* in/out
    status: [*c]i32 // UErrorCode* in/out
) callconv(.c) void;
proc u_setMemoryFunctions(
    context: pointer,  # void*
    a: pointer,  # UMemAllocFn* in/out
    r: pointer,  # UMemReallocFn* in/out
    f: pointer,  # UMemFreeFn* in/out
    status: ptr int32  # UErrorCode* in/out
) {.importc: "u_setMemoryFunctions", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
void u_setMemoryFunctions(
    void* context,   // void*
    void* a,   // UMemAllocFn* in/out
    void* r,   // UMemReallocFn* in/out
    void* f,   // UMemFreeFn* in/out
    int* status   // UErrorCode* in/out
);
ccall((:u_setMemoryFunctions, "icuuc.dll"), Cvoid,
      (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Int32}),
      context, a, r, f, status)
# context : void* -> Ptr{Cvoid}
# a : UMemAllocFn* in/out -> Ptr{Cvoid}
# r : UMemReallocFn* in/out -> Ptr{Cvoid}
# f : UMemFreeFn* in/out -> Ptr{Cvoid}
# status : UErrorCode* in/out -> Ptr{Int32}
local ffi = require("ffi")
ffi.cdef[[
void u_setMemoryFunctions(
    void* context,
    void* a,
    void* r,
    void* f,
    int32_t* status);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.u_setMemoryFunctions(context, a, r, f, status)
-- context : void*
-- a : UMemAllocFn* in/out
-- r : UMemReallocFn* in/out
-- f : UMemFreeFn* in/out
-- status : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const u_setMemoryFunctions = lib.func('__cdecl', 'u_setMemoryFunctions', 'void', ['void *', 'void *', 'void *', 'void *', 'int32_t *']);
// u_setMemoryFunctions(context, a, r, f, status)
// context : void* -> 'void *'
// a : UMemAllocFn* in/out -> 'void *'
// r : UMemReallocFn* in/out -> 'void *'
// f : UMemFreeFn* in/out -> 'void *'
// status : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("icuuc.dll", {
  u_setMemoryFunctions: { parameters: ["pointer", "pointer", "pointer", "pointer", "pointer"], result: "void" },
});
// lib.symbols.u_setMemoryFunctions(context, a, r, f, status)
// context : void* -> "pointer"
// a : UMemAllocFn* in/out -> "pointer"
// r : UMemReallocFn* in/out -> "pointer"
// f : UMemFreeFn* in/out -> "pointer"
// status : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void u_setMemoryFunctions(
    void* context,
    void* a,
    void* r,
    void* f,
    int32_t* status);
C, "icuuc.dll");
// $ffi->u_setMemoryFunctions(context, a, r, f, status);
// context : void*
// a : UMemAllocFn* in/out
// r : UMemReallocFn* in/out
// f : UMemFreeFn* in/out
// status : UErrorCode* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Icuuc extends Library {
    Icuuc INSTANCE = Native.load("icuuc", Icuuc.class);
    void u_setMemoryFunctions(
        Pointer context,   // void*
        Callback a,   // UMemAllocFn* in/out
        Callback r,   // UMemReallocFn* in/out
        Callback f,   // UMemFreeFn* in/out
        IntByReference status   // UErrorCode* in/out
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun u_setMemoryFunctions = u_setMemoryFunctions(
    context : Void*,   # void*
    a : Void*,   # UMemAllocFn* in/out
    r : Void*,   # UMemReallocFn* in/out
    f : Void*,   # UMemFreeFn* in/out
    status : Int32*   # UErrorCode* in/out
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef u_setMemoryFunctionsNative = Void Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
typedef u_setMemoryFunctionsDart = void Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
final u_setMemoryFunctions = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<u_setMemoryFunctionsNative, u_setMemoryFunctionsDart>('u_setMemoryFunctions');
// context : void* -> Pointer<Void>
// a : UMemAllocFn* in/out -> Pointer<Void>
// r : UMemReallocFn* in/out -> Pointer<Void>
// f : UMemFreeFn* in/out -> Pointer<Void>
// status : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure u_setMemoryFunctions(
  context: Pointer;   // void*
  a: Pointer;   // UMemAllocFn* in/out
  r: Pointer;   // UMemReallocFn* in/out
  f: Pointer;   // UMemFreeFn* in/out
  status: Pointer   // UErrorCode* in/out
); cdecl;
  external 'icuuc.dll' name 'u_setMemoryFunctions';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "u_setMemoryFunctions"
  c_u_setMemoryFunctions :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> Ptr Int32 -> IO ()
-- context : void* -> Ptr ()
-- a : UMemAllocFn* in/out -> Ptr ()
-- r : UMemReallocFn* in/out -> Ptr ()
-- f : UMemFreeFn* in/out -> Ptr ()
-- status : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let u_setmemoryfunctions =
  foreign "u_setMemoryFunctions"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr int32_t) @-> returning void)
(* context : void* -> (ptr void) *)
(* a : UMemAllocFn* in/out -> (ptr void) *)
(* r : UMemReallocFn* in/out -> (ptr void) *)
(* f : UMemFreeFn* in/out -> (ptr void) *)
(* status : UErrorCode* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)

(cffi:defcfun ("u_setMemoryFunctions" u-set-memory-functions :convention :cdecl) :void
  (context :pointer)   ; void*
  (a :pointer)   ; UMemAllocFn* in/out
  (r :pointer)   ; UMemReallocFn* in/out
  (f :pointer)   ; UMemFreeFn* in/out
  (status :pointer))   ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $u_setMemoryFunctions = Win32::API::More->new('icuuc',
    'void u_setMemoryFunctions(LPVOID context, LPVOID a, LPVOID r, LPVOID f, LPVOID status)');
# my $ret = $u_setMemoryFunctions->Call($context, $a, $r, $f, $status);
# context : void* -> LPVOID
# a : UMemAllocFn* in/out -> LPVOID
# r : UMemReallocFn* in/out -> LPVOID
# f : UMemFreeFn* in/out -> LPVOID
# status : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型