Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
77 files changed:
redef fun +(o) do
var mlen = length
var slen = o.length
redef fun +(o) do
var mlen = length
var slen = o.length
- var nns = new NativeString(mlen + slen)
+ var nns = new CString(mlen + slen)
items.copy_to(nns, mlen, index_from, 0)
if o isa FlatString then
o.items.copy_to(nns, slen, o.index_from, mlen)
items.copy_to(nns, mlen, index_from, 0)
if o isa FlatString then
o.items.copy_to(nns, slen, o.index_from, mlen)
- var ns = new NativeString(sl + 1)
+ var ns = new CString(sl + 1)
ns[sl] = '\0'
i = 0
var off = 0
ns[sl] = '\0'
i = 0
var off = 0
end
else
# Use the prefix and the short class name
end
else
# Use the prefix and the short class name
- # e.g. given the prefix Native: java.lang.String -> NativeString
+ # e.g. given the prefix Native: java.lang.String -> CString
using namespace emscripten;
EMSCRIPTEN_BINDINGS(my_module) {
using namespace emscripten;
EMSCRIPTEN_BINDINGS(my_module) {
- function("run_analysis", &NativeString_run_analysis, allow_raw_pointers());
+ function("run_analysis", &CString_run_analysis, allow_raw_pointers());
fun show_graph(content: String) do "show_graph('{content.escape_to_c}');".run_js
end
fun show_graph(content: String) do "show_graph('{content.escape_to_c}');".run_js
end
-redef class NativeString
fun run_analysis do manager.run_web to_s
end
fun run_analysis do manager.run_web to_s
end
-fun dummy_set_callbacks import NativeString.run_analysis in "C++" `{
+fun dummy_set_callbacks import CString.run_analysis in "C++" `{
# Returns null on success
fun file_rename_to(dest: String): nullable String import String.to_cstring,
# Returns null on success
fun file_rename_to(dest: String): nullable String import String.to_cstring,
- NativeString.to_s, String.as nullable `{
+ CString.to_s, String.as nullable `{
int res = rename(String_to_cstring(self), String_to_cstring(dest));
if (res == 0) return null_String();
int res = rename(String_to_cstring(self), String_to_cstring(dest));
if (res == 0) return null_String();
- return String_as_nullable(NativeString_to_s(strerror(errno)));
+ return String_as_nullable(CString_to_s(strerror(errno)));
`}
# Replace `~` by the path to the home diretory
`}
# Replace `~` by the path to the home diretory
(*env)->DeleteLocalRef(env, class_class_loader);
`}
(*env)->DeleteLocalRef(env, class_class_loader);
`}
- private fun load_jclass_intern(instance_class_loader: JavaObject, class_loader_findClass: JMethodID, name: NativeString): JClass import jni_env `{
+ private fun load_jclass_intern(instance_class_loader: JavaObject, class_loader_findClass: JMethodID, name: CString): JClass import jni_env `{
JNIEnv *env = Sys_jni_env(self);
jobject class_name = (*env)->NewStringUTF(env, name);
JNIEnv *env = Sys_jni_env(self);
jobject class_name = (*env)->NewStringUTF(env, name);
private fun priority_silent: Int do return 8
# Write `text` to Android log at priority `level` with tag `tag`
private fun priority_silent: Int do return 8
# Write `text` to Android log at priority `level` with tag `tag`
-private fun log_write(level: Int, tag, text: NativeString) `{
+private fun log_write(level: Int, tag, text: CString) `{
__android_log_write(level, tag, text);
`}
__android_log_write(level, tag, text);
`}
fun java_native_activity: NativeActivity `{ return self->clazz; `}
# Path to this application's internal data directory.
fun java_native_activity: NativeActivity `{ return self->clazz; `}
# Path to this application's internal data directory.
- fun internal_data_path: NativeString `{ return (char*)self->internalDataPath; `}
+ fun internal_data_path: CString `{ return (char*)self->internalDataPath; `}
# Path to this application's external (removable/mountable) data directory.
# Path to this application's external (removable/mountable) data directory.
- fun external_data_path: NativeString `{ return (char*)self->externalDataPath; `}
+ fun external_data_path: CString `{ return (char*)self->externalDataPath; `}
# The platform's SDK version code.
fun sdk_version: Int `{ return self->sdkVersion; `}
# The platform's SDK version code.
fun sdk_version: Int `{ return self->sdkVersion; `}
# api?
#
# TODO activate in a future module at API 11
# api?
#
# TODO activate in a future module at API 11
- #fun obb_path: NativeString `{ return (char*)self->obbPath; `}
+ #fun obb_path: CString `{ return (char*)self->obbPath; `}
end
# This is the interface for the standard glue code of a threaded
end
# This is the interface for the standard glue code of a threaded
extern class ASensor `{ASensorRef`}
new `{return malloc(sizeof(ASensorRef));`}
extern class ASensor `{ASensorRef`}
new `{return malloc(sizeof(ASensorRef));`}
- fun name: NativeString `{return (char*)ASensor_getName(self);`}
- fun vendor: NativeString `{return (char*)ASensor_getVendor(self);`}
+ fun name: CString `{return (char*)ASensor_getName(self);`}
+ fun vendor: CString `{return (char*)ASensor_getVendor(self);`}
fun sensor_type: ASensorType `{return ASensor_getType(self);`}
fun resolution: Float `{return ASensor_getResolution(self);`}
fun min_delay: Int `{return ASensor_getMinDelay(self);`}
fun sensor_type: ASensorType `{return ASensor_getType(self);`}
fun resolution: Float `{return ASensor_getResolution(self);`}
fun min_delay: Int `{return ASensor_getMinDelay(self);`}
-redef class NativeString
# Alphabet used by the base64 algorithm
private fun base64_chars : Bytes
do
# Alphabet used by the base64 algorithm
private fun base64_chars : Bytes
do
# | 0x06 utf8 byte sequence # Char
# | 0x07 double(64 bits) # Float
# | 0x08 block # String
# | 0x06 utf8 byte sequence # Char
# | 0x07 double(64 bits) # Float
# | 0x08 block # String
-# | 0x09 block # NativeString
+# | 0x09 block # CString
# | 0x0A flat_array; # Array[nullable Object]
#
# block = int64 int8*;
# | 0x0A flat_array; # Array[nullable Object]
#
# block = int64 int8*;
private var unclaimed_attributes = new UnrolledList[HashMap[String, nullable Object]]
# Buffer for one char
private var unclaimed_attributes = new UnrolledList[HashMap[String, nullable Object]]
# Buffer for one char
- private var char_buf: NativeString is lazy do return new NativeString(4)
+ private var char_buf: CString is lazy do return new CString(4)
# Read and deserialize the next attribute name and value
#
# Read and deserialize the next attribute name and value
#
-redef class NativeString
redef fun serialize_to_binary(v)
do
v.stream.write_byte kind_native_string
redef fun serialize_to_binary(v)
do
v.stream.write_byte kind_native_string
-# Wrapper around an array of `NativeString` in C (`char**`) with length and destroy state.
-class CNativeStringArray
- super CArray[NativeString]
+# Wrapper around an array of `CString` in C (`char**`) with length and destroy state.
+class CCStringArray
+ super CArray[CString]
redef type NATIVE: NativeCStringArray
redef type NATIVE: NativeCStringArray
- # Create from an `SequenceRead[NativeString]`
- new from(array: SequenceRead[NativeString])
+ # Create from an `SequenceRead[CString]`
+ new from(array: SequenceRead[CString])
- var carray = new CNativeStringArray(array.length)
+ var carray = new CCStringArray(array.length)
for i in array.length.times do
carray[i] = array[i]
end
for i in array.length.times do
carray[i] = array[i]
end
-# An array of `NativeString` in C (`char**`)
+# An array of `CString` in C (`char**`)
extern class NativeCStringArray `{ char** `}
super NativeCArray
extern class NativeCStringArray `{ char** `}
super NativeCArray
- redef type E: NativeString
# Initialize a new NativeCStringArray of `size` elements.
new(size: Int) `{ return calloc(size, sizeof(char*)); `}
# Initialize a new NativeCStringArray of `size` elements.
new(size: Int) `{ return calloc(size, sizeof(char*)); `}
redef fun +(offset) `{ return self + offset; `}
end
redef fun +(offset) `{ return self + offset; `}
end
-redef class NativeString
super NativeCArray
redef type E: Char
super NativeCArray
redef type E: Char
new nil in "ObjC" `{ return nil; `}
# Get an UTF8 encoded `char*` copy of `self`
new nil in "ObjC" `{ return nil; `}
# Get an UTF8 encoded `char*` copy of `self`
- fun utf8_string: NativeString in "ObjC" `{ return (char *)[self UTF8String]; `}
+ fun utf8_string: CString in "ObjC" `{ return (char *)[self UTF8String]; `}
redef fun to_s do return utf8_string.to_s_with_copy
end
redef fun to_s do return utf8_string.to_s_with_copy
end
-redef class NativeString
# Get a `NSString` from `self` with the specified `length`
fun to_nsstring(length: Int): NSString in "ObjC" `{
return [[NSString alloc] initWithBytes:self
# Get a `NSString` from `self` with the specified `length`
fun to_nsstring(length: Int): NSString in "ObjC" `{
return [[NSString alloc] initWithBytes:self
extern class NSData in "ObjC" `{ NSData * `}
# Pointer to contained data
extern class NSData in "ObjC" `{ NSData * `}
# Pointer to contained data
- fun bytes: NativeString in "ObjC" `{ return (char*)self.bytes; `}
+ fun bytes: CString in "ObjC" `{ return (char*)self.bytes; `}
# Number of bytes containted in `self`
fun length: Int in "ObjC" `{ return self.length; `}
# Number of bytes containted in `self`
fun length: Int in "ObjC" `{ return self.length; `}
super BytePattern
# Write self as a string into `ns` at position `pos`
super BytePattern
# Write self as a string into `ns` at position `pos`
- private fun add_digest_at(ns: NativeString, pos: Int) do
+ private fun add_digest_at(ns: CString, pos: Int) do
var tmp = (0xF0u8 & self) >> 4
ns[pos] = if tmp >= 0x0Au8 then tmp + 0x37u8 else tmp + 0x30u8
tmp = 0x0Fu8 & self
var tmp = (0xF0u8 & self) >> 4
ns[pos] = if tmp >= 0x0Au8 then tmp + 0x37u8 else tmp + 0x30u8
tmp = 0x0Fu8 & self
super AbstractArray[Byte]
super BytePattern
super AbstractArray[Byte]
super BytePattern
- # A NativeString being a char*, it can be used as underlying representation here.
- var items: NativeString
+ # A CString being a char*, it can be used as underlying representation here.
+ var items: CString
# Number of bytes in the array
redef var length
# Number of bytes in the array
redef var length
# var b = new Bytes.empty
# assert b.to_s == ""
init empty do
# var b = new Bytes.empty
# assert b.to_s == ""
init empty do
- var ns = new NativeString(0)
+ var ns = new CString(0)
init(ns, 0, 0)
end
# Init a `Bytes` with capacity `cap`
init with_capacity(cap: Int) do
init(ns, 0, 0)
end
# Init a `Bytes` with capacity `cap`
init with_capacity(cap: Int) do
- var ns = new NativeString(cap)
+ var ns = new CString(cap)
# ~~~
fun hexdigest: String do
var elen = length * 2
# ~~~
fun hexdigest: String do
var elen = length * 2
- var ns = new NativeString(elen)
+ var ns = new CString(elen)
var i = 0
var oi = 0
while i < length do
var i = 0
var oi = 0
while i < length do
# ~~~
fun chexdigest: String do
var elen = length * 4
# ~~~
fun chexdigest: String do
var elen = length * 4
- var ns = new NativeString(elen)
+ var ns = new CString(elen)
var i = 0
var oi = 0
while i < length do
var i = 0
var oi = 0
while i < length do
# ~~~
fun binarydigest: String do
var elen = length * 8
# ~~~
fun binarydigest: String do
var elen = length * 8
- var ns = new NativeString(elen)
+ var ns = new CString(elen)
var i = 0
var oi = 0
while i < length do
var i = 0
var oi = 0
while i < length do
# Regenerates the buffer, necessary when it was persisted
private fun regen do
# Regenerates the buffer, necessary when it was persisted
private fun regen do
- var nns = new NativeString(capacity)
+ var nns = new CString(capacity)
items.copy_to(nns, length, 0, 0)
persisted = false
end
# Appends the `ln` first bytes of `ns` to self
items.copy_to(nns, length, 0, 0)
persisted = false
end
# Appends the `ln` first bytes of `ns` to self
- fun append_ns(ns: NativeString, ln: Int) do
+ fun append_ns(ns: CString, ln: Int) do
if persisted then regen
var nlen = length + ln
if nlen > capacity then enlarge(nlen)
if persisted then regen
var nlen = length + ln
if nlen > capacity then enlarge(nlen)
end
# Appends `ln` bytes from `ns` starting at index `from` to self
end
# Appends `ln` bytes from `ns` starting at index `from` to self
- fun append_ns_from(ns: NativeString, ln, from: Int) do
+ fun append_ns_from(ns: CString, ln, from: Int) do
if persisted then regen
var nlen = length + ln
if nlen > capacity then enlarge(nlen)
if persisted then regen
var nlen = length + ln
if nlen > capacity then enlarge(nlen)
if capacity >= sz then return
persisted = false
while capacity < sz do capacity = capacity * 2 + 2
if capacity >= sz then return
persisted = false
while capacity < sz do capacity = capacity * 2 + 2
- var ns = new NativeString(capacity)
+ var ns = new CString(capacity)
items.copy_to(ns, length, 0, 0)
items = ns
end
items.copy_to(ns, length, 0, 0)
items = ns
end
private class BytesIterator
super IndexedIterator[Byte]
private class BytesIterator
super IndexedIterator[Byte]
# assert "<STRING/&rt;".hexdigest == "266C743B535452494E47262334373B2672743B"
fun hexdigest: String do
var ln = byte_length
# assert "<STRING/&rt;".hexdigest == "266C743B535452494E47262334373B2672743B"
fun hexdigest: String do
var ln = byte_length
- var outns = new NativeString(ln * 2)
+ var outns = new CString(ln * 2)
var oi = 0
for i in [0 .. ln[ do
bytes[i].add_digest_at(outns, oi)
var oi = 0
for i in [0 .. ln[ do
bytes[i].add_digest_at(outns, oi)
-redef class NativeString
# Creates a new `Bytes` object from `self` with `len` as length
#
# If `len` is null, strlen will determine the length of the Bytes
# Creates a new `Bytes` object from `self` with `len` as length
#
# If `len` is null, strlen will determine the length of the Bytes
# If `len` is null, strlen will determine the length of the Bytes
fun to_bytes_with_copy(len: nullable Int): Bytes do
if len == null then len = cstring_length
# If `len` is null, strlen will determine the length of the Bytes
fun to_bytes_with_copy(len: nullable Int): Bytes do
if len == null then len = cstring_length
- var nns = new NativeString(len)
+ var nns = new CString(len)
copy_to(nns, len, 0, 0)
return new Bytes(nns, len, len)
end
copy_to(nns, len, 0, 0)
return new Bytes(nns, len, len)
end
fun char_max_size: Int is abstract
# Transforms `c` to its representation in the format of `self`
fun char_max_size: Int is abstract
# Transforms `c` to its representation in the format of `self`
- fun encode_char(c: Char): NativeString is abstract
+ fun encode_char(c: Char): CString is abstract
# Adds a char `c` to bytes `s`
#
# Returns the number of bytes written to `s`
# Adds a char `c` to bytes `s`
#
# Returns the number of bytes written to `s`
- fun add_char_to(c: Char, s: NativeString): Int is abstract
+ fun add_char_to(c: Char, s: CString): Int is abstract
# Transforms `s` to the format of `self`
fun encode_string(s: Text): Bytes is abstract
# Transforms `s` to the format of `self`
fun encode_string(s: Text): Bytes is abstract
# * 0 if valid
# * 1 if incomplete
# * 2 if invalid
# * 0 if valid
# * 1 if incomplete
# * 2 if invalid
- fun is_valid_char(ns: NativeString, position: Int): Int is abstract
+ fun is_valid_char(ns: CString, position: Int): Int is abstract
# Decodes a char from `b` to a Unicode code-point
# Decodes a char from `b` to a Unicode code-point
- fun decode_char(b: NativeString): Char is abstract
+ fun decode_char(b: CString): Char is abstract
# Decodes a string `b` to UTF-8
# Decodes a string `b` to UTF-8
- fun decode_string(b: NativeString, len: Int): String is abstract
+ fun decode_string(b: CString, len: Int): String is abstract
redef fun max_lookahead do return 1
redef fun encode_char(c) do
redef fun max_lookahead do return 1
redef fun encode_char(c) do
- var ns = new NativeString(c.u8char_len)
+ var ns = new CString(c.u8char_len)
add_char_to(c, ns)
return ns
end
add_char_to(c, ns)
return ns
end
redef fun max_lookahead do return 4
redef fun encode_char(c) do
redef fun max_lookahead do return 4
redef fun encode_char(c) do
- var ns = new NativeString(c.u8char_len)
+ var ns = new CString(c.u8char_len)
add_char_to(c, ns)
return ns
end
add_char_to(c, ns)
return ns
end
var ret = ns.to_s_with_length(len)
var rit = ret.as(FlatString).items
if rit == ns then
var ret = ns.to_s_with_length(len)
var rit = ret.as(FlatString).items
if rit == ns then
- var nns = new NativeString(len)
+ var nns = new CString(len)
rit.copy_to(nns, len, 0, 0)
return nns.to_s_full(ret.byte_length, ret.length)
end
rit.copy_to(nns, len, 0, 0)
return nns.to_s_full(ret.byte_length, ret.length)
end
-redef class NativeString
- private fun get_environ: NativeString `{ return getenv(self); `}
- private fun setenv(value: NativeString) `{
+redef class CString
+ private fun get_environ: CString `{ return getenv(self); `}
+ private fun setenv(value: CString) `{
#ifdef _WIN32
_putenv_s(self, value);
#else
#ifdef _WIN32
_putenv_s(self, value);
#else
end
private var data: NativeProcess
end
private var data: NativeProcess
- private fun basic_exec_execute(prog, args: NativeString, argc: Int, pipeflag: Int): NativeProcess `{
+ private fun basic_exec_execute(prog, args: CString, argc: Int, pipeflag: Int): NativeProcess `{
#ifdef _WIN32
// FIXME use a higher level abstraction to support WIN32
return -1;
#ifdef _WIN32
// FIXME use a higher level abstraction to support WIN32
return -1;
fun pid: Int `{ return getpid(); `}
end
fun pid: Int `{ return getpid(); `}
end
-redef class NativeString
# Execute self as a shell command.
#
# See the posix function system(3).
# Execute self as a shell command.
#
# See the posix function system(3).
redef var is_writable = false
# Write `len` bytes from `native`.
redef var is_writable = false
# Write `len` bytes from `native`.
- private fun write_native(native: NativeString, from, len: Int)
+ private fun write_native(native: CString, from, len: Int)
do
if last_error != null then return
if not _is_writable then
do
if last_error != null then return
if not _is_writable then
# Creates a file stream from a file descriptor `fd` using the file access `mode`.
#
# NOTE: The `mode` specified must be compatible with the one used in the file descriptor.
# Creates a file stream from a file descriptor `fd` using the file access `mode`.
#
# NOTE: The `mode` specified must be compatible with the one used in the file descriptor.
- private fun fd_to_stream(mode: NativeString): NativeFile `{
+ private fun fd_to_stream(mode: CString): NativeFile `{
return fdopen((int)self, mode);
`}
end
# Constant for read-only file streams
return fdopen((int)self, mode);
`}
end
# Constant for read-only file streams
-private fun read_only: NativeString do return once "r".to_cstring
+private fun read_only: CString do return once "r".to_cstring
# Constant for write-only file streams
#
# If a stream is opened on a file with this method,
# it will wipe the previous file if any.
# Else, it will create the file.
# Constant for write-only file streams
#
# If a stream is opened on a file with this method,
# it will wipe the previous file if any.
# Else, it will create the file.
-private fun wipe_write: NativeString do return once "w".to_cstring
+private fun wipe_write: CString do return once "w".to_cstring
###############################################################################
###############################################################################
-redef class NativeString
private fun file_exists: Bool `{
#ifdef _WIN32
DWORD attribs = GetFileAttributesA(self);
private fun file_exists: Bool `{
#ifdef _WIN32
DWORD attribs = GetFileAttributesA(self);
private fun file_chdir: Bool `{ return !chdir(self); `}
private fun file_chdir: Bool `{ return !chdir(self); `}
- private fun file_realpath: NativeString `{
+ private fun file_realpath: CString `{
#ifdef _WIN32
DWORD len = GetFullPathName(self, 0, NULL, NULL);
char *buf = malloc(len+1); // FIXME don't leak memory
#ifdef _WIN32
DWORD len = GetFullPathName(self, 0, NULL, NULL);
char *buf = malloc(len+1); // FIXME don't leak memory
# Instance of this class are standard FILE * pointers
private extern class NativeFile `{ FILE* `}
# Instance of this class are standard FILE * pointers
private extern class NativeFile `{ FILE* `}
- fun io_read(buf: NativeString, len: Int): Int `{
+ fun io_read(buf: CString, len: Int): Int `{
return fread(buf, 1, len, self);
`}
return fread(buf, 1, len, self);
`}
- fun io_write(buf: NativeString, from, len: Int): Int `{
+ fun io_write(buf: CString, from, len: Int): Int `{
return fwrite(buf+from, 1, len, self);
`}
return fwrite(buf+from, 1, len, self);
`}
return setvbuf(self, NULL, (int)mode, buf_length);
`}
return setvbuf(self, NULL, (int)mode, buf_length);
`}
- new io_open_read(path: NativeString) `{ return fopen(path, "r"); `}
+ new io_open_read(path: CString) `{ return fopen(path, "r"); `}
- new io_open_write(path: NativeString) `{ return fopen(path, "w"); `}
+ new io_open_write(path: CString) `{ return fopen(path, "w"); `}
new native_stdin `{ return stdin; `}
new native_stdin `{ return stdin; `}
private extern class NativeDir `{ DIR* `}
# Open a directory
private extern class NativeDir `{ DIR* `}
# Open a directory
- new opendir(path: NativeString) `{ return opendir(path); `}
+ new opendir(path: CString) `{ return opendir(path); `}
# Close a directory
fun closedir `{ closedir(self); `}
# Read the next directory entry
# Close a directory
fun closedir `{ closedir(self); `}
# Read the next directory entry
- fun readdir: NativeString `{
+ fun readdir: CString `{
struct dirent *de;
de = readdir(self);
if (!de) return NULL;
struct dirent *de;
de = readdir(self);
if (!de) return NULL;
# Return the working (current) directory
fun getcwd: String do return native_getcwd.to_s
# Return the working (current) directory
fun getcwd: String do return native_getcwd.to_s
-private fun native_getcwd: NativeString `{ return getcwd(NULL, 0); `}
+private fun native_getcwd: CString `{ return getcwd(NULL, 0); `}
# assert ~0x2Fi8 == 0xD0i8
fun ~: Int8 is intern
# assert ~0x2Fi8 == 0xD0i8
fun ~: Int8 is intern
- # C function to calculate the length of the `NativeString` to receive `self`
+ # C function to calculate the length of the `CString` to receive `self`
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIi8, self);
`}
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIi8, self);
`}
- # C function to convert a nit Int to a NativeString (char*)
- private fun native_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert a nit Int to a CString (char*)
+ private fun native_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "%"PRIi8, self);
`}
snprintf(nstr, strlen, "%"PRIi8, self);
`}
# assert (-123i8).to_s == "-123"
redef fun to_s do
var nslen = to_s_len
# assert (-123i8).to_s == "-123"
redef fun to_s do
var nslen = to_s_len
- var ns = new NativeString(nslen + 1)
+ var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
# assert ~0x2Fi16 == 0xFFD0i16
fun ~: Int16 is intern
# assert ~0x2Fi16 == 0xFFD0i16
fun ~: Int16 is intern
- # C function to calculate the length of the `NativeString` to receive `self`
+ # C function to calculate the length of the `CString` to receive `self`
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIi16, self);
`}
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIi16, self);
`}
- # C function to convert a nit Int to a NativeString (char*)
- private fun native_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert a nit Int to a CString (char*)
+ private fun native_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "%"PRIi16, self);
`}
snprintf(nstr, strlen, "%"PRIi16, self);
`}
# assert (-123i16).to_s == "-123"
redef fun to_s do
var nslen = to_s_len
# assert (-123i16).to_s == "-123"
redef fun to_s do
var nslen = to_s_len
- var ns = new NativeString(nslen + 1)
+ var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
# assert ~0x2Fu16 == 0xFFD0u16
fun ~: UInt16 is intern
# assert ~0x2Fu16 == 0xFFD0u16
fun ~: UInt16 is intern
- # C function to calculate the length of the `NativeString` to receive `self`
+ # C function to calculate the length of the `CString` to receive `self`
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIu16, self);
`}
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIu16, self);
`}
- # C function to convert a nit Int to a NativeString (char*)
- private fun native_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert a nit Int to a CString (char*)
+ private fun native_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "%"PRIu16, self);
`}
snprintf(nstr, strlen, "%"PRIu16, self);
`}
# assert (-123u16).to_s == "65413"
redef fun to_s do
var nslen = to_s_len
# assert (-123u16).to_s == "65413"
redef fun to_s do
var nslen = to_s_len
- var ns = new NativeString(nslen + 1)
+ var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
# assert ~0x2Fi32 == 0xFFFFFFD0i32
fun ~: Int32 is intern
# assert ~0x2Fi32 == 0xFFFFFFD0i32
fun ~: Int32 is intern
- # C function to calculate the length of the `NativeString` to receive `self`
+ # C function to calculate the length of the `CString` to receive `self`
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIi32, self);
`}
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIi32, self);
`}
- # C function to convert a nit Int to a NativeString (char*)
- private fun native_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert a nit Int to a CString (char*)
+ private fun native_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "%"PRIi32, self);
`}
snprintf(nstr, strlen, "%"PRIi32, self);
`}
# assert (-123i32).to_s == "-123"
redef fun to_s do
var nslen = to_s_len
# assert (-123i32).to_s == "-123"
redef fun to_s do
var nslen = to_s_len
- var ns = new NativeString(nslen + 1)
+ var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
# assert ~0x2Fu32 == 0xFFFFFFD0u32
fun ~: UInt32 is intern
# assert ~0x2Fu32 == 0xFFFFFFD0u32
fun ~: UInt32 is intern
- # C function to calculate the length of the `NativeString` to receive `self`
+ # C function to calculate the length of the `CString` to receive `self`
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIu32, self);
`}
private fun to_s_len: Int `{
return snprintf(NULL, 0, "%"PRIu32, self);
`}
- # C function to convert a nit Int to a NativeString (char*)
- private fun native_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert a nit Int to a CString (char*)
+ private fun native_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "%"PRIu32, self);
`}
snprintf(nstr, strlen, "%"PRIu32, self);
`}
# assert (-123u32).to_s == "4294967173"
redef fun to_s do
var nslen = to_s_len
# assert (-123u32).to_s == "4294967173"
redef fun to_s do
var nslen = to_s_len
- var ns = new NativeString(nslen + 1)
+ var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
ns[nslen] = 0u8
native_to_s(ns, nslen + 1)
return ns.to_s_with_length(nslen)
new from_name(name: String) import String.to_cstring `{ return getpwnam( String_to_cstring(name) ); `}
# Username
new from_name(name: String) import String.to_cstring `{ return getpwnam( String_to_cstring(name) ); `}
# Username
- fun name: String import NativeString.to_s `{ return NativeString_to_s(self->pw_name); `}
+ fun name: String import CString.to_s `{ return CString_to_s(self->pw_name); `}
- fun passwd: String import NativeString.to_s `{ return NativeString_to_s(self->pw_passwd); `}
+ fun passwd: String import CString.to_s `{ return CString_to_s(self->pw_passwd); `}
# User ID
fun uid: Int `{ return self->pw_uid; `}
# User ID
fun uid: Int `{ return self->pw_uid; `}
fun gid: Int `{ return self->pw_gid; `}
# Home directory
fun gid: Int `{ return self->pw_gid; `}
# Home directory
- fun dir: String import NativeString.to_s `{ return NativeString_to_s(self->pw_dir); `}
+ fun dir: String import CString.to_s `{ return CString_to_s(self->pw_dir); `}
- fun shell: String import NativeString.to_s `{ return NativeString_to_s(self->pw_shell); `}
+ fun shell: String import CString.to_s `{ return CString_to_s(self->pw_shell); `}
end
# Information on a user group
end
# Information on a user group
new from_name(name: String) import String.to_cstring `{ return getgrnam( String_to_cstring(name) ); `}
# Name of this ground
new from_name(name: String) import String.to_cstring `{ return getgrnam( String_to_cstring(name) ); `}
# Name of this ground
- fun name: String import NativeString.to_s `{ return NativeString_to_s(self->gr_name); `}
+ fun name: String import CString.to_s `{ return CString_to_s(self->gr_name); `}
# Encrypted password of this group
# Encrypted password of this group
- fun passwd: String import NativeString.to_s `{ return NativeString_to_s(self->gr_passwd); `}
+ fun passwd: String import CString.to_s `{ return CString_to_s(self->gr_passwd); `}
# Id of this group
fun gid: Int `{ return self->gr_gid; `}
# List of the members of the group
# Id of this group
fun gid: Int `{ return self->gr_gid; `}
# List of the members of the group
- fun mem: Array[String] import Array[String], Array[String].add, NativeString.to_s `{
+ fun mem: Array[String] import Array[String], Array[String].add, CString.to_s `{
char **mem;
int m;
Array_of_String ret;
char **mem;
int m;
Array_of_String ret;
ret = new_Array_of_String();
for (m = 0; mem[m] != NULL; m++)
ret = new_Array_of_String();
for (m = 0; mem[m] != NULL; m++)
- Array_of_String_add(ret, NativeString_to_s(mem[m]));
+ Array_of_String_add(ret, CString_to_s(mem[m]));
new malloc `{ return malloc(sizeof(regex_t)); `}
# Compile the regular expression `regex` into a form that is suitable for subsequent `regexec` searches
new malloc `{ return malloc(sizeof(regex_t)); `}
# Compile the regular expression `regex` into a form that is suitable for subsequent `regexec` searches
- fun regcomp(regex: NativeString, cflags: Int): Int `{
+ fun regcomp(regex: CString, cflags: Int): Int `{
return regcomp(self, regex, cflags);
`}
return regcomp(self, regex, cflags);
`}
#
# `nmatch` and `pmatch` are used to provide information regarding the location of any matches.
# `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`.
#
# `nmatch` and `pmatch` are used to provide information regarding the location of any matches.
# `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`.
- fun regexec(string: NativeString, nmatch: Int, pmatch: NativeMatchArray, eflags: Int): Int `{
+ fun regexec(string: CString, nmatch: Int, pmatch: NativeMatchArray, eflags: Int): Int `{
return regexec(self, string, nmatch, pmatch, eflags);
`}
# Match `string` against the precompiled pattern buffer of `self`, do not locate matches
#
# `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`.
return regexec(self, string, nmatch, pmatch, eflags);
`}
# Match `string` against the precompiled pattern buffer of `self`, do not locate matches
#
# `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`.
- fun regexec_match_only(string: NativeString, eflags: Int): Int `{
+ fun regexec_match_only(string: CString, eflags: Int): Int `{
return regexec(self, string, 0, NULL, eflags);
`}
return regexec(self, string, 0, NULL, eflags);
`}
fun regfree `{ regfree(self); `}
# Turn the error codes that can be returned by both `regcomp` and `regexec` into error message strings
fun regfree `{ regfree(self); `}
# Turn the error codes that can be returned by both `regcomp` and `regexec` into error message strings
- fun regerror(errcode: Int): NativeString `{
+ fun regerror(errcode: Int): CString `{
size_t len = regerror(errcode, self, NULL, 0);
char *message = malloc(len);
regerror(errcode, self, message, len);
size_t len = regerror(errcode, self, NULL, 0);
char *message = malloc(len);
regerror(errcode, self, message, len);
fun [](index: Int): NativeMatchArray `{ return self + index; `}
end
fun [](index: Int): NativeMatchArray `{ return self + index; `}
end
-redef extern class NativeString
- private fun substring_from(index: Int): NativeString `{ return self + index; `}
+redef extern class CString
+ private fun substring_from(index: Int): CString `{ return self + index; `}
fun read_bytes(i: Int): Bytes
do
if last_error != null then return new Bytes.empty
fun read_bytes(i: Int): Bytes
do
if last_error != null then return new Bytes.empty
- var s = new NativeString(i)
var buf = new Bytes(s, 0, 0)
while i > 0 and not eof do
var c = read_byte
var buf = new Bytes(s, 0, 0)
while i > 0 and not eof do
var c = read_byte
while c < full_len do c = c * 2 + 2
_buffer_capacity = c
end
while c < full_len do c = c * 2 + 2
_buffer_capacity = c
end
- var nns = new NativeString(_buffer_capacity)
+ var nns = new CString(_buffer_capacity)
bf.items.copy_to(nns, bf.length, 0, 0)
_buffer.copy_to(nns, remsp, _buffer_pos, bf.length)
_buffer = nns
bf.items.copy_to(nns, bf.length, 0, 0)
_buffer.copy_to(nns, remsp, _buffer_pos, bf.length)
_buffer = nns
- private var buffer: NativeString = new NativeString(0)
+ private var buffer: CString = new CString(0)
# The current position in the buffer
private var buffer_pos = 0
# The current position in the buffer
private var buffer_pos = 0
# Allocate a `_buffer` for a given `capacity`.
protected fun prepare_buffer(capacity: Int)
do
# Allocate a `_buffer` for a given `capacity`.
protected fun prepare_buffer(capacity: Int)
do
- _buffer = new NativeString(capacity)
+ _buffer = new CString(capacity)
_buffer_pos = 0 # need to read
_buffer_length = 0
_buffer_capacity = capacity
_buffer_pos = 0 # need to read
_buffer_length = 0
_buffer_capacity = capacity
redef fun read_all_bytes do
var nslen = source.length - cursor
redef fun read_all_bytes do
var nslen = source.length - cursor
- var nns = new NativeString(nslen)
+ var nns = new CString(nslen)
source.copy_to_native(nns, nslen, cursor, 0)
return new Bytes(nns, nslen, nslen)
end
source.copy_to_native(nns, nslen, cursor, 0)
return new Bytes(nns, nslen, nslen)
end
end
# Return a null terminated char *
end
# Return a null terminated char *
- fun to_cstring: NativeString is abstract
+ fun to_cstring: CString is abstract
# The index of the last occurrence of an element starting from pos (in reverse order).
#
# The index of the last occurrence of an element starting from pos (in reverse order).
#
# If no transformation is needed, return self as a string
if not has_percent then return to_s
# If no transformation is needed, return self as a string
if not has_percent then return to_s
- var buf = new NativeString(len)
+ var buf = new CString(len)
var i = 0
var l = 0
while i < length do
var i = 0
var l = 0
while i < length do
# Copies `n` bytes from `self` at `src_offset` into `dest` starting at `dest_offset`
#
# Copies `n` bytes from `self` at `src_offset` into `dest` starting at `dest_offset`
#
- # Basically a high-level synonym of NativeString::copy_to
+ # Basically a high-level synonym of CString::copy_to
#
# REQUIRE: `n` must be large enough to contain `len` bytes
#
#
# REQUIRE: `n` must be large enough to contain `len` bytes
#
- # var ns = new NativeString(8)
+ # var ns = new CString(8)
# "Text is String".copy_to_native(ns, 8, 2, 0)
# assert ns.to_s_unsafe(8) == "xt is St"
#
# "Text is String".copy_to_native(ns, 8, 2, 0)
# assert ns.to_s_unsafe(8) == "xt is St"
#
- fun copy_to_native(dest: NativeString, n, src_offset, dest_offset: Int) do
+ fun copy_to_native(dest: CString, n, src_offset, dest_offset: Int) do
var mypos = src_offset
var itspos = dest_offset
while n > 0 do
var mypos = src_offset
var itspos = dest_offset
while n > 0 do
#
# Warning : Might be void in some subclasses, be sure to check
# if set before using it.
#
# Warning : Might be void in some subclasses, be sure to check
# if set before using it.
- var items: NativeString is noinit
+ var items: CString is noinit
# Returns a char* starting at position `first_byte`
#
# WARNING: If you choose to use this service, be careful of the following.
#
# Returns a char* starting at position `first_byte`
#
# WARNING: If you choose to use this service, be careful of the following.
#
- # Strings and NativeString are *ideally* always allocated through a Garbage Collector.
+ # Strings and CString are *ideally* always allocated through a Garbage Collector.
# Since the GC tracks the use of the pointer for the beginning of the char*, it may be
# deallocated at any moment, rendering the pointer returned by this function invalid.
# Any access to freed memory may very likely cause undefined behaviour or a crash.
# Since the GC tracks the use of the pointer for the beginning of the char*, it may be
# deallocated at any moment, rendering the pointer returned by this function invalid.
# Any access to freed memory may very likely cause undefined behaviour or a crash.
#
# As always, do not modify the content of the String in C code, if this is what you want
# copy locally the char* as Nit Strings are immutable.
#
# As always, do not modify the content of the String in C code, if this is what you want
# copy locally the char* as Nit Strings are immutable.
- fun fast_cstring: NativeString is abstract
+ fun fast_cstring: CString is abstract
# User readable representation of `self`.
fun to_s: String do return inspect
# User readable representation of `self`.
fun to_s: String do return inspect
- # The class name of the object in NativeString format.
- private fun native_class_name: NativeString is intern
+ # The class name of the object in CString format.
+ private fun native_class_name: CString is intern
# The class name of the object.
#
# The class name of the object.
#
- # C function to calculate the length of the `NativeString` to receive `self`
+ # C function to calculate the length of the `CString` to receive `self`
private fun byte_to_s_len: Int `{
return snprintf(NULL, 0, "0x%02x", self);
`}
private fun byte_to_s_len: Int `{
return snprintf(NULL, 0, "0x%02x", self);
`}
- # C function to convert an nit Int to a NativeString (char*)
- private fun native_byte_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert an nit Int to a CString (char*)
+ private fun native_byte_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "0x%02x", self);
`}
snprintf(nstr, strlen, "0x%02x", self);
`}
# assert (-123).to_b.to_s == "0x85"
redef fun to_s do
var nslen = byte_to_s_len
# assert (-123).to_b.to_s == "0x85"
redef fun to_s do
var nslen = byte_to_s_len
- var ns = new NativeString(nslen + 1)
+ var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_byte_to_s(ns, nslen + 1)
return ns.to_s_unsafe(nslen)
ns[nslen] = 0u8
native_byte_to_s(ns, nslen + 1)
return ns.to_s_unsafe(nslen)
redef class Int
# Wrapper of strerror C function
redef class Int
# Wrapper of strerror C function
- private fun strerror_ext: NativeString `{ return strerror((int)self); `}
+ private fun strerror_ext: CString `{ return strerror((int)self); `}
# Returns a string describing error number
fun strerror: String do return strerror_ext.to_s
# Returns a string describing error number
fun strerror: String do return strerror_ext.to_s
- # C function to calculate the length of the `NativeString` to receive `self`
+ # C function to calculate the length of the `CString` to receive `self`
private fun int_to_s_len: Int `{
return snprintf(NULL, 0, "%ld", self);
`}
private fun int_to_s_len: Int `{
return snprintf(NULL, 0, "%ld", self);
`}
- # C function to convert an nit Int to a NativeString (char*)
- private fun native_int_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert an nit Int to a CString (char*)
+ private fun native_int_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "%ld", self);
`}
snprintf(nstr, strlen, "%ld", self);
`}
# assert 'x'.to_s == "x"
redef fun to_s do
var ln = u8char_len
# assert 'x'.to_s == "x"
redef fun to_s do
var ln = u8char_len
- var ns = new NativeString(ln + 1)
+ var ns = new CString(ln + 1)
u8char_tos(ns, ln)
return ns.to_s_unsafe(ln)
end
u8char_tos(ns, ln)
return ns.to_s_unsafe(ln)
end
- private fun u8char_tos(r: NativeString, len: Int) `{
+ private fun u8char_tos(r: CString, len: Int) `{
r[len] = '\0';
switch(len){
case 1:
r[len] = '\0';
switch(len){
case 1:
private fun native_argc: Int is intern
# Second argument of the main C function.
private fun native_argc: Int is intern
# Second argument of the main C function.
- private fun native_argv(i: Int): NativeString is intern
+ private fun native_argv(i: Int): CString is intern
end
# Comparator that efficienlty use `to_s` to compare things
end
# Comparator that efficienlty use `to_s` to compare things
return sys.program_args
end
return sys.program_args
end
-redef class NativeString
# Get a `String` from the data at `self` copied into Nit memory
#
# Require: `self` is a null-terminated string.
# Get a `String` from the data at `self` copied into Nit memory
#
# Require: `self` is a null-terminated string.
- # First byte of the NativeString
+ # First byte of the CString
protected fun first_byte: Int do return 0
protected fun first_byte: Int do return 0
- # Last byte of the NativeString
+ # Last byte of the CString
protected fun last_byte: Int do return first_byte + _byte_length - 1
# Cache of the latest position (char) explored in the string
var position: Int = 0
protected fun last_byte: Int do return first_byte + _byte_length - 1
# Cache of the latest position (char) explored in the string
var position: Int = 0
- # Cached position (bytes) in the NativeString underlying the String
+ # Cached position (bytes) in the CString underlying the String
var bytepos: Int = 0
# Index of the character `index` in `_items`
var bytepos: Int = 0
# Index of the character `index` in `_items`
var max = last_byte
var pos = first_byte
var nlen = extra + _byte_length
var max = last_byte
var pos = first_byte
var nlen = extra + _byte_length
- var nits = new NativeString(nlen)
+ var nits = new CString(nlen)
var outpos = 0
while pos <= max do
var c = its[pos]
var outpos = 0
while pos <= max do
var c = its[pos]
var its = _items
var max = last_byte
var nlen = _byte_length + ln_extra
var its = _items
var max = last_byte
var nlen = _byte_length + ln_extra
- var nns = new NativeString(nlen)
+ var nns = new CString(nlen)
var pos = first_byte
var opos = 0
while pos <= max do
var pos = first_byte
var opos = 0
while pos <= max do
redef fun to_cstring do
var blen = _byte_length
redef fun to_cstring do
var blen = _byte_length
- var new_items = new NativeString(blen + 1)
+ var new_items = new CString(blen + 1)
_items.copy_to(new_items, blen, _first_byte, 0)
new_items[blen] = 0u8
return new_items
_items.copy_to(new_items, blen, _first_byte, 0)
new_items[blen] = 0u8
return new_items
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
- private new with_infos(items: NativeString, byte_length, from: Int)
+ private new with_infos(items: CString, byte_length, from: Int)
do
var len = items.utf8_length(from, byte_length)
if byte_length == len then return new ASCIIFlatString.full_data(items, byte_length, from, len)
do
var len = items.utf8_length(from, byte_length)
if byte_length == len then return new ASCIIFlatString.full_data(items, byte_length, from, len)
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
- private new full(items: NativeString, byte_length, from, length: Int)
+ private new full(items: CString, byte_length, from, length: Int)
do
if byte_length == length then return new ASCIIFlatString.full_data(items, byte_length, from, length)
return new UnicodeFlatString.full_data(items, byte_length, from, length)
do
if byte_length == length then return new ASCIIFlatString.full_data(items, byte_length, from, length)
return new UnicodeFlatString.full_data(items, byte_length, from, length)
if s isa FlatText then
var sits = s._items
var sifrom = s.first_byte
if s isa FlatText then
var sits = s._items
var sifrom = s.first_byte
- var ns = new NativeString(nlen + 1)
+ var ns = new CString(nlen + 1)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
return new FlatString.full(ns, nlen, 0, _length + o.length)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
return new FlatString.full(ns, nlen, 0, _length + o.length)
var newlen = mylen * i
var its = _items
var fb = _first_byte
var newlen = mylen * i
var its = _items
var fb = _first_byte
- var ns = new NativeString(new_byte_length + 1)
+ var ns = new CString(new_byte_length + 1)
ns[new_byte_length] = 0u8
var offset = 0
while i > 0 do
ns[new_byte_length] = 0u8
var offset = 0
while i > 0 do
private class UnicodeFlatString
super FlatString
private class UnicodeFlatString
super FlatString
- init full_data(items: NativeString, byte_length, from, length: Int) do
+ init full_data(items: CString, byte_length, from, length: Int) do
self._items = items
self._length = length
self._byte_length = byte_length
self._items = items
self._length = length
self._byte_length = byte_length
private class ASCIIFlatString
super FlatString
private class ASCIIFlatString
super FlatString
- init full_data(items: NativeString, byte_length, from, length: Int) do
+ init full_data(items: CString, byte_length, from, length: Int) do
self._items = items
self._length = length
self._byte_length = byte_length
self._items = items
self._length = length
self._byte_length = byte_length
- var target_items: NativeString is noautoinit
+ var target_items: CString is noautoinit
- var target_items: NativeString is noautoinit
+ var target_items: CString is noautoinit
redef fun substrings do return new FlatSubstringsIter(self)
redef fun substrings do return new FlatSubstringsIter(self)
- # Re-copies the `NativeString` into a new one and sets it as the new `Buffer`
+ # Re-copies the `CString` into a new one and sets it as the new `Buffer`
#
# This happens when an operation modifies the current `Buffer` and
# the Copy-On-Write flag `written` is set at true.
private fun reset do
#
# This happens when an operation modifies the current `Buffer` and
# the Copy-On-Write flag `written` is set at true.
private fun reset do
- var nns = new NativeString(capacity)
+ var nns = new CString(capacity)
if _byte_length != 0 then _items.copy_to(nns, _byte_length, 0, 0)
_items = nns
written = false
if _byte_length != 0 then _items.copy_to(nns, _byte_length, 0, 0)
_items = nns
written = false
var bt = _byte_length
if bt + len > capacity then
capacity = capacity * 2 + 2
var bt = _byte_length
if bt + len > capacity then
capacity = capacity * 2 + 2
- nit = new NativeString(capacity)
+ nit = new CString(capacity)
oit.copy_to(nit, 0, 0, from)
end
oit.copy_to(nit, bt - from, from, from + len)
oit.copy_to(nit, 0, 0, from)
end
oit.copy_to(nit, bt - from, from, from + len)
# it does a copy of the current `Buffer`
written = false
var bln = _byte_length
# it does a copy of the current `Buffer`
written = false
var bln = _byte_length
- var a = new NativeString(c)
if bln > 0 then
var it = _items
if bln > 0 then it.copy_to(a, bln, 0, 0)
if bln > 0 then
var it = _items
if bln > 0 then it.copy_to(a, bln, 0, 0)
do
written = true
var bln = _byte_length
do
written = true
var bln = _byte_length
- if bln == 0 then _items = new NativeString(1)
+ if bln == 0 then _items = new CString(1)
return new FlatString.full(_items, bln, 0, _length)
end
redef fun to_cstring
do
var bln = _byte_length
return new FlatString.full(_items, bln, 0, _length)
end
redef fun to_cstring
do
var bln = _byte_length
- var new_native = new NativeString(bln + 1)
+ var new_native = new CString(bln + 1)
new_native[bln] = 0u8
if _length > 0 then _items.copy_to(new_native, bln, 0, 0)
return new_native
new_native[bln] = 0u8
if _length > 0 then _items.copy_to(new_native, bln, 0, 0)
return new_native
#
# If `_items` is shared, `written` should be set to true after the creation
# so that a modification will do a copy-on-write.
#
# If `_items` is shared, `written` should be set to true after the creation
# so that a modification will do a copy-on-write.
- private init with_infos(items: NativeString, capacity, byte_length, length: Int)
+ private init with_infos(items: CString, capacity, byte_length, length: Int)
do
self._items = items
self.capacity = capacity
do
self._items = items
self.capacity = capacity
# Create a new string copied from `s`.
init from(s: Text)
do
# Create a new string copied from `s`.
init from(s: Text)
do
- _items = new NativeString(s.byte_length)
+ _items = new CString(s.byte_length)
for i in s.substrings do i._items.copy_to(_items, i._byte_length, first_byte, 0)
_byte_length = s.byte_length
_length = s.length
for i in s.substrings do i._items.copy_to(_items, i._byte_length, first_byte, 0)
_byte_length = s.byte_length
_length = s.length
init with_capacity(cap: Int)
do
assert cap >= 0
init with_capacity(cap: Int)
do
assert cap >= 0
- _items = new NativeString(cap)
+ _items = new CString(cap)
capacity = cap
_byte_length = 0
end
capacity = cap
_byte_length = 0
end
var byteto = its.char_to_byte_index(count + from - 1)
byteto += its.char_at(byteto).u8char_len - 1
var byte_length = byteto - bytefrom + 1
var byteto = its.char_to_byte_index(count + from - 1)
byteto += its.char_at(byteto).u8char_len - 1
var byte_length = byteto - bytefrom + 1
- var r_items = new NativeString(byte_length)
+ var r_items = new CString(byte_length)
its.copy_to(r_items, byte_length, bytefrom, 0)
return new FlatBuffer.with_infos(r_items, byte_length, byte_length, count)
end
its.copy_to(r_items, byte_length, bytefrom, 0)
return new FlatBuffer.with_infos(r_items, byte_length, byte_length, count)
end
- var target_items: NativeString is noautoinit
+ var target_items: CString is noautoinit
- var target_items: NativeString is noautoinit
+ var target_items: CString is noautoinit
-redef class NativeString
redef fun to_s
do
return to_s_with_length(cstring_length)
redef fun to_s
do
return to_s_with_length(cstring_length)
do
var r = clean_utf8(length)
if r.items != self then return r
do
var r = clean_utf8(length)
if r.items != self then return r
- var new_self = new NativeString(length + 1)
+ var new_self = new CString(length + 1)
copy_to(new_self, length, 0, 0)
var str = new FlatString.with_infos(new_self, length, 0)
new_self[length] = 0u8
return str
end
copy_to(new_self, length, 0, 0)
var str = new FlatString.with_infos(new_self, length, 0)
new_self[length] = 0u8
return str
end
- # Cleans a NativeString if necessary
+ # Cleans a CString if necessary
fun clean_utf8(len: Int): FlatString do
var replacements: nullable Array[Int] = null
var end_length = len
fun clean_utf8(len: Int): FlatString do
var replacements: nullable Array[Int] = null
var end_length = len
end
var ret = self
if end_length != len then
end
var ret = self
if end_length != len then
- ret = new NativeString(end_length)
+ ret = new CString(end_length)
var old_repl = 0
var off = 0
var repls = replacements.as(not null)
var old_repl = 0
var off = 0
var repls = replacements.as(not null)
if self == 1 then return "1"
var nslen = int_to_s_len
if self == 1 then return "1"
var nslen = int_to_s_len
- var ns = new NativeString(nslen + 1)
+ var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_int_to_s(ns, nslen + 1)
return new FlatString.full(ns, nslen, 0, nslen)
ns[nslen] = 0u8
native_int_to_s(ns, nslen + 1)
return new FlatString.full(ns, nslen, 0, nslen)
- var ns = new NativeString(sl + 1)
+ var ns = new CString(sl + 1)
ns[sl] = 0u8
i = 0
var off = 0
ns[sl] = 0u8
i = 0
var off = 0
- var ns = new NativeString(sl + 1)
+ var ns = new CString(sl + 1)
ns[sl] = 0u8
i = 0
var off = 0
ns[sl] = 0u8
i = 0
var off = 0
end
# Native strings are simple C char *
end
# Native strings are simple C char *
-extern class NativeString `{ char* `}
- # Creates a new NativeString with a capacity of `length`
+extern class CString `{ char* `}
+ # Creates a new CString with a capacity of `length`
new(length: Int) is intern
# Returns a char* starting at `index`.
#
# WARNING: Unsafe for extern code, use only for temporary
# pointer manipulation purposes (e.g. write to file or such)
new(length: Int) is intern
# Returns a char* starting at `index`.
#
# WARNING: Unsafe for extern code, use only for temporary
# pointer manipulation purposes (e.g. write to file or such)
- fun fast_cstring(index: Int): NativeString is intern
+ fun fast_cstring(index: Int): CString is intern
# Get char at `index`.
fun [](index: Int): Byte is intern
# Get char at `index`.
fun [](index: Int): Byte is intern
fun []=(index: Int, item: Byte) is intern
# Copy `self` to `dest`.
fun []=(index: Int, item: Byte) is intern
# Copy `self` to `dest`.
- fun copy_to(dest: NativeString, length: Int, from: Int, to: Int) is intern
+ fun copy_to(dest: CString, length: Int, from: Int, to: Int) is intern
redef fun ==(o) is intern do return is_same_instance(o)
redef fun ==(o) is intern do return is_same_instance(o)
redef fun to_cstring do
var len = _byte_length
redef fun to_cstring do
var len = _byte_length
- var ns = new NativeString(len + 1)
+ var ns = new CString(len + 1)
ns[len] = 0u8
var off = 0
for i in substrings do
ns[len] = 0u8
var off = 0
for i in substrings do
var sifrom = s._first_byte
var mifrom = _first_byte
var sits = s._items
var sifrom = s._first_byte
var mifrom = _first_byte
var sits = s._items
- var ns = new NativeString(nlen + 1)
+ var ns = new CString(nlen + 1)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
return new FlatString.full(ns, nlen, 0, length + s.length)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
return new FlatString.full(ns, nlen, 0, length + s.length)
private class RopeByteReverseIterator
super IndexedIterator[Byte]
private class RopeByteReverseIterator
super IndexedIterator[Byte]
- # Current NativeString
- var ns: NativeString is noautoinit
- # Current position in NativeString
+ # Current CString
+ var ns: CString is noautoinit
+ # Current position in CString
var pns: Int is noautoinit
# Position in the Rope (0-indexed)
var pos: Int is noautoinit
var pns: Int is noautoinit
# Position in the Rope (0-indexed)
var pos: Int is noautoinit
# Position in current `String`
var pns: Int is noautoinit
# Current `String` being iterated on
# Position in current `String`
var pns: Int is noautoinit
# Current `String` being iterated on
- var ns: NativeString is noautoinit
+ var ns: CString is noautoinit
# Substrings of the Rope
var subs: IndexedIterator[FlatString] is noautoinit
# Maximum position to iterate on (e.g. Rope.byte_length)
# Substrings of the Rope
var subs: IndexedIterator[FlatString] is noautoinit
# Maximum position to iterate on (e.g. Rope.byte_length)
private class RopeCharReverseIterator
super IndexedIterator[Char]
private class RopeCharReverseIterator
super IndexedIterator[Char]
var ns: String is noautoinit
var ns: String is noautoinit
- # Current position in NativeString
+ # Current position in CString
var pns: Int is noautoinit
# Position in the Rope (0-indexed)
var pos: Int is noautoinit
var pns: Int is noautoinit
# Position in the Rope (0-indexed)
var pos: Int is noautoinit
fun update `{ time(&self); `}
# Convert `self` to a human readable String.
fun update `{ time(&self); `}
# Convert `self` to a human readable String.
- fun ctime: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy( ctime(&self) );
+ fun ctime: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy( ctime(&self) );
`}
# Difference in secondes from start (self if the end time)
`}
# Difference in secondes from start (self if the end time)
fun is_dst: Bool `{ return self->tm_isdst; `}
# Convert `self` to a human readable String.
fun is_dst: Bool `{ return self->tm_isdst; `}
# Convert `self` to a human readable String.
- private fun asctime: NativeString `{ return asctime(self); `}
+ private fun asctime: CString `{ return asctime(self); `}
# Convert `self` to a human readable String corresponding to `format`.
# TODO document allowed format.
# Convert `self` to a human readable String corresponding to `format`.
# TODO document allowed format.
- fun strftime(format: String): String import String.to_cstring, NativeString.to_s_with_copy `{
+ fun strftime(format: String): String import String.to_cstring, CString.to_s_with_copy `{
char* buf, *c_format;
buf = (char*)malloc(100);
c_format = String_to_cstring(format);
strftime(buf, 100, c_format, self);
char* buf, *c_format;
buf = (char*)malloc(100);
c_format = String_to_cstring(format);
strftime(buf, 100, c_format, self);
- String s = NativeString_to_s_with_copy(buf);
+ String s = CString_to_s_with_copy(buf);
fun to_cpp_string: CppString do return to_cstring.to_cpp_string(length)
end
fun to_cpp_string: CppString do return to_cstring.to_cpp_string(length)
end
-redef class NativeString
# Get `self` as a `CppString`
fun to_cpp_string(length: Int): CppString in "C++" `{
return new std::string(self, length);
# Get `self` as a `CppString`
fun to_cpp_string(length: Int): CppString in "C++" `{
return new std::string(self, length);
-redef extern class NativeString
+redef extern class CString
private fun native_callback_header(size, count: Int, target: NativeCurlCallbacks): Int
do
target.header_callback to_s_with_length(size*count)
private fun native_callback_header(size, count: Int, target: NativeCurlCallbacks): Int
do
target.header_callback to_s_with_length(size*count)
# Request Chars internal information from the CURL session
fun easy_getinfo_chars(opt: CURLInfoChars): nullable String
do
# Request Chars internal information from the CURL session
fun easy_getinfo_chars(opt: CURLInfoChars): nullable String
do
- var answ = new Ref[NativeString]("".to_cstring)
+ var answ = new Ref[CString]("".to_cstring)
if not native_getinfo_chars(opt, answ).is_ok then return null
if answ.item.address_is_null then return null
return answ.item.to_s
end
# Internal method used to get String object information initially knowns as C Chars type
if not native_getinfo_chars(opt, answ).is_ok then return null
if answ.item.address_is_null then return null
return answ.item.to_s
end
# Internal method used to get String object information initially knowns as C Chars type
- private fun native_getinfo_chars(opt: CURLInfoChars, res: Ref[NativeString]): CURLCode
- import Ref[NativeString].item= `{
+ private fun native_getinfo_chars(opt: CURLInfoChars, res: Ref[CString]): CURLCode
+ import Ref[CString].item= `{
char *r;
CURLcode c = curl_easy_getinfo( self, opt, &r);
char *r;
CURLcode c = curl_easy_getinfo( self, opt, &r);
- if (c == CURLE_OK) Ref_of_NativeString_item__assign(res, r);
+ if (c == CURLE_OK) Ref_of_CString_item__assign(res, r);
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_header(delegate: NativeCurlCallbacks): CURLCode
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_header(delegate: NativeCurlCallbacks): CURLCode
- import NativeString.native_callback_header `{
+ import CString.native_callback_header `{
CURLcode e;
NativeCurlCallbacks_incr_ref(delegate); // FIXME deallocated these when download completes?
CURLcode e;
NativeCurlCallbacks_incr_ref(delegate); // FIXME deallocated these when download completes?
- e = curl_easy_setopt(self, CURLOPT_HEADERFUNCTION, (curl_write_callback)&NativeString_native_callback_header);
+ e = curl_easy_setopt(self, CURLOPT_HEADERFUNCTION, (curl_write_callback)&CString_native_callback_header);
if(e != CURLE_OK) return e;
e = curl_easy_setopt(self, CURLOPT_WRITEHEADER, delegate);
if(e != CURLE_OK) return e;
e = curl_easy_setopt(self, CURLOPT_WRITEHEADER, delegate);
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_body(delegate: NativeCurlCallbacks): CURLCode
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_body(delegate: NativeCurlCallbacks): CURLCode
- import NativeString.native_callback_body `{
+ import CString.native_callback_body `{
CURLcode e;
NativeCurlCallbacks_incr_ref(delegate);
CURLcode e;
NativeCurlCallbacks_incr_ref(delegate);
- e = curl_easy_setopt(self, CURLOPT_WRITEFUNCTION, (curl_write_callback)&NativeString_native_callback_body);
+ e = curl_easy_setopt(self, CURLOPT_WRITEFUNCTION, (curl_write_callback)&CString_native_callback_body);
if(e != CURLE_OK) return e;
e = curl_easy_setopt(self, CURLOPT_WRITEDATA, delegate);
if(e != CURLE_OK) return e;
e = curl_easy_setopt(self, CURLOPT_WRITEDATA, delegate);
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_stream(delegate: NativeCurlCallbacks): CURLCode
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_stream(delegate: NativeCurlCallbacks): CURLCode
- import NativeString.native_callback_stream `{
+ import CString.native_callback_stream `{
CURLcode e;
NativeCurlCallbacks_incr_ref(delegate);
CURLcode e;
NativeCurlCallbacks_incr_ref(delegate);
- e = curl_easy_setopt(self, CURLOPT_WRITEFUNCTION, (curl_write_callback)&NativeString_native_callback_stream);
+ e = curl_easy_setopt(self, CURLOPT_WRITEFUNCTION, (curl_write_callback)&CString_native_callback_stream);
if(e != CURLE_OK) return e;
e = curl_easy_setopt(self, CURLOPT_WRITEDATA, delegate);
if(e != CURLE_OK) return e;
e = curl_easy_setopt(self, CURLOPT_WRITEDATA, delegate);
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_read(delegate: NativeCurlCallbacks): CURLCode
# Register `delegate` to get callbacks about the CURL transfer
fun register_callback_read(delegate: NativeCurlCallbacks): CURLCode
- import NativeString.native_callback_stream `{
+ import CString.native_callback_stream `{
NativeCurlCallbacks_incr_ref(delegate);
return curl_easy_setopt(self, CURLOPT_READFUNCTION, (curl_write_callback)&nit_curl_callback_read_func);
`}
# Convert given string to URL encoded string
NativeCurlCallbacks_incr_ref(delegate);
return curl_easy_setopt(self, CURLOPT_READFUNCTION, (curl_write_callback)&nit_curl_callback_read_func);
`}
# Convert given string to URL encoded string
- fun escape(url: String): String import String.to_cstring, NativeString.to_s_with_copy `{
+ fun escape(url: String): String import String.to_cstring, CString.to_s_with_copy `{
char *orig_url, *encoded_url = NULL;
orig_url = String_to_cstring(url);
encoded_url = curl_easy_escape( self, orig_url, strlen(orig_url));
char *orig_url, *encoded_url = NULL;
orig_url = String_to_cstring(url);
encoded_url = curl_easy_escape( self, orig_url, strlen(orig_url));
- String b_url = NativeString_to_s_with_copy(encoded_url);
+ String b_url = CString_to_s_with_copy(encoded_url);
curl_free(encoded_url);
return b_url;
`}
curl_free(encoded_url);
return b_url;
`}
fun is_valid_protocol: Bool `{ return self == CURLE_UNSUPPORTED_PROTOCOL; `}
fun is_valid_init: Bool `{ return self == CURLE_FAILED_INIT; `}
fun to_i: Int do return code end
fun is_valid_protocol: Bool `{ return self == CURLE_UNSUPPORTED_PROTOCOL; `}
fun is_valid_init: Bool `{ return self == CURLE_FAILED_INIT; `}
fun to_i: Int do return code end
- redef fun to_s import NativeString.to_s_with_copy `{
+ redef fun to_s import CString.to_s_with_copy `{
char *c = (char*)curl_easy_strerror(self);
char *c = (char*)curl_easy_strerror(self);
- return NativeString_to_s_with_copy(c);
+ return CString_to_s_with_copy(c);
private fun native_next_reachable(c: CURLSList): Bool `{ return (c != NULL && c->next != NULL); `}
# Internal method to get current data
private fun native_next_reachable(c: CURLSList): Bool `{ return (c != NULL && c->next != NULL); `}
# Internal method to get current data
- private fun native_data(c: CURLSList): String import NativeString.to_s `{ return NativeString_to_s(c->data); `}
+ private fun native_data(c: CURLSList): String import CString.to_s `{ return CString_to_s(c->data); `}
# Internal method to get next element
private fun native_next(c: CURLSList): CURLSList `{ return c->next; `}
# Internal method to get next element
private fun native_next(c: CURLSList): CURLSList `{ return c->next; `}
- private fun report_egl_error(cmsg: NativeString)
+ private fun report_egl_error(cmsg: CString)
do
var msg = cmsg.to_s
print "libEGL error: {msg}"
do
var msg = cmsg.to_s
print "libEGL error: {msg}"
- private fun query_string(name: Int): String import NativeString.to_s `{
- return NativeString_to_s((char *)eglQueryString(self, name));
+ private fun query_string(name: Int): String import CString.to_s `{
+ return CString_to_s((char *)eglQueryString(self, name));
`}
fun vendor: String do return query_string(0x3053)
`}
fun vendor: String do return query_string(0x3053)
# Run `self` as JavaScript code
fun run_js do run_js_native(self.escape_to_js.to_cstring)
# Run `self` as JavaScript code
fun run_js do run_js_native(self.escape_to_js.to_cstring)
- private fun run_js_native(script: NativeString) `{ emscripten_run_script(script); `}
+ private fun run_js_native(script: CString) `{ emscripten_run_script(script); `}
# Escape the content of `self` to pass to JavaScript code
fun escape_to_js: Text do return replace('\n', "\\n")
# Escape the content of `self` to pass to JavaScript code
fun escape_to_js: Text do return replace('\n', "\\n")
-redef class NativeString
# Sets the locale of the program running
#
# This can be set at different times in the program,
# Sets the locale of the program running
#
# This can be set at different times in the program,
# Gettext `gettext`, SEE gettext manual for further info
fun gettext: String
# Gettext `gettext`, SEE gettext manual for further info
fun gettext: String
- import String.to_cstring, NativeString.to_s `{
- return NativeString_to_s(gettext(String_to_cstring(self)));
+ import String.to_cstring, CString.to_s `{
+ return CString_to_s(gettext(String_to_cstring(self)));
`}
# Gettext `dgettext`, SEE gettext manual for further info
fun dgettext(domain: String): String
`}
# Gettext `dgettext`, SEE gettext manual for further info
fun dgettext(domain: String): String
- import String.to_cstring, NativeString.to_s `{
- return NativeString_to_s(dgettext(String_to_cstring(domain), String_to_cstring(self)));
+ import String.to_cstring, CString.to_s `{
+ return CString_to_s(dgettext(String_to_cstring(domain), String_to_cstring(self)));
fun active_attrib_name(index: Int): String
do
var max_size = active_attribute_max_length
fun active_attrib_name(index: Int): String
do
var max_size = active_attribute_max_length
- var cname = new NativeString(max_size)
+ var cname = new CString(max_size)
active_attrib_name_native(index, max_size, cname)
return cname.to_s
end
active_attrib_name_native(index, max_size, cname)
return cname.to_s
end
- private fun active_attrib_name_native(index, max_size: Int, name: NativeString) `{
+ private fun active_attrib_name_native(index, max_size: Int, name: CString) `{
// We get more values than we need, for compatibility. At least the
// NVidia driver tries to fill them even if NULL.
// We get more values than we need, for compatibility. At least the
// NVidia driver tries to fill them even if NULL.
fun active_uniform_name(index: Int): String
do
var max_size = active_uniform_max_length
fun active_uniform_name(index: Int): String
do
var max_size = active_uniform_max_length
- var cname = new NativeString(max_size)
+ var cname = new CString(max_size)
active_uniform_name_native(index, max_size, cname)
return cname.to_s
end
active_uniform_name_native(index, max_size, cname)
return cname.to_s
end
- private fun active_uniform_name_native(index, max_size: Int, name: NativeString) `{
+ private fun active_uniform_name_native(index, max_size: Int, name: CString) `{
int size;
GLenum type;
glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
int size;
GLenum type;
glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
fun glGetProgramInfoLog(program: GLProgram): String
do
var size = glGetProgramiv(program, gl_INFO_LOG_LENGTH)
fun glGetProgramInfoLog(program: GLProgram): String
do
var size = glGetProgramiv(program, gl_INFO_LOG_LENGTH)
- var buf = new NativeString(size)
+ var buf = new CString(size)
native_glGetProgramInfoLog(program, size, buf)
return buf.to_s_with_length(size)
end
# Return the program information log in `buf`
native_glGetProgramInfoLog(program, size, buf)
return buf.to_s_with_length(size)
end
# Return the program information log in `buf`
-private fun native_glGetProgramInfoLog(program: GLProgram, buf_size: Int, buf: NativeString): Int `{
+private fun native_glGetProgramInfoLog(program: GLProgram, buf_size: Int, buf: CString): Int `{
int length;
glGetProgramInfoLog(program, buf_size, &length, buf);
return length;
int length;
glGetProgramInfoLog(program, buf_size, &length, buf);
return length;
return source_native(size).to_s
end
return source_native(size).to_s
end
- private fun source_native(size: Int): NativeString `{
+ private fun source_native(size: Int): CString `{
GLchar *code = malloc(size);
glGetShaderSource(self, size, NULL, code);
return code;
GLchar *code = malloc(size);
glGetShaderSource(self, size, NULL, code);
return code;
fun glGetShaderInfoLog(shader: GLShader): String
do
var size = glGetShaderiv(shader, gl_INFO_LOG_LENGTH)
fun glGetShaderInfoLog(shader: GLShader): String
do
var size = glGetShaderiv(shader, gl_INFO_LOG_LENGTH)
- var buf = new NativeString(size)
+ var buf = new CString(size)
native_glGetShaderInfoLog(shader, size, buf)
return buf.to_s_with_length(size)
end
native_glGetShaderInfoLog(shader, size, buf)
return buf.to_s_with_length(size)
end
-private fun native_glGetShaderInfoLog(shader: GLShader, buf_size: Int, buffer: NativeString): Int `{
+private fun native_glGetShaderInfoLog(shader: GLShader, buf_size: Int, buffer: CString): Int `{
int length;
glGetShaderInfoLog(shader, buf_size, &length, buffer);
return length;
int length;
glGetShaderInfoLog(shader, buf_size, &length, buffer);
return length;
`}
# Replace the source code in the `shader` object with `code`
`}
# Replace the source code in the `shader` object with `code`
-fun glShaderSource(shader: GLShader, code: NativeString) `{
+fun glShaderSource(shader: GLShader, code: CString) `{
glShaderSource(shader, 1, (GLchar const **)&code, NULL);
`}
glShaderSource(shader, 1, (GLchar const **)&code, NULL);
`}
new `{ return (GtkHeaderBar*)gtk_header_bar_new(); `}
fun title=(title: Text) do native_title = title.to_cstring
new `{ return (GtkHeaderBar*)gtk_header_bar_new(); `}
fun title=(title: Text) do native_title = title.to_cstring
- private fun native_title=(title: NativeString) `{ gtk_header_bar_set_title(self, title); `}
+ private fun native_title=(title: CString) `{ gtk_header_bar_set_title(self, title); `}
fun title: String do return native_title.to_s
fun title: String do return native_title.to_s
- private fun native_title: NativeString `{ return (gchar *)gtk_header_bar_get_title(self); `}
+ private fun native_title: CString `{ return (gchar *)gtk_header_bar_get_title(self); `}
fun subtitle=(subtitle: Text) do native_subtitle = subtitle.to_cstring
fun subtitle=(subtitle: Text) do native_subtitle = subtitle.to_cstring
- fun native_subtitle=(subtitle: NativeString) `{ gtk_header_bar_set_subtitle(self, subtitle); `}
+ fun native_subtitle=(subtitle: CString) `{ gtk_header_bar_set_subtitle(self, subtitle); `}
fun subtitle: String do return native_subtitle.to_s
fun subtitle: String do return native_subtitle.to_s
- fun native_subtitle: NativeString `{ return (gchar *)gtk_header_bar_get_subtitle(self); `}
+ fun native_subtitle: CString `{ return (gchar *)gtk_header_bar_get_subtitle(self); `}
fun custom_title=(title_widget: GtkWidget) `{ gtk_header_bar_set_custom_title(self, title_widget); `}
fun custom_title=(title_widget: GtkWidget) `{ gtk_header_bar_set_custom_title(self, title_widget); `}
new `{ return (GtkStack*)gtk_stack_new(); `}
fun stack_add(child: GtkWidget, name: String) do native_stack_add(child, name.to_cstring)
new `{ return (GtkStack*)gtk_stack_new(); `}
fun stack_add(child: GtkWidget, name: String) do native_stack_add(child, name.to_cstring)
- private fun native_stack_add(child: GtkWidget, name: NativeString) `{ gtk_stack_add_named(self, child, name); `}
+ private fun native_stack_add(child: GtkWidget, name: CString) `{ gtk_stack_add_named(self, child, name); `}
- fun add_titled(child: GtkWidget, name, title: NativeString) `{ gtk_stack_add_titled(self, child, name, title); `}
- fun native_add_titled(child: GtkWidget, name, title: NativeString) `{ gtk_stack_add_titled(self, child, name, title); `}
+ fun add_titled(child: GtkWidget, name, title: CString) `{ gtk_stack_add_titled(self, child, name, title); `}
+ fun native_add_titled(child: GtkWidget, name, title: CString) `{ gtk_stack_add_titled(self, child, name, title); `}
fun visible_child=(child: GtkWidget) `{ gtk_stack_set_visible_child(self, child); `}
fun visible_child: GtkWidget `{ return gtk_stack_get_visible_child(self); `}
fun visible_child_name=(name: Text) do native_visible_child_name = name.to_cstring
fun visible_child=(child: GtkWidget) `{ gtk_stack_set_visible_child(self, child); `}
fun visible_child: GtkWidget `{ return gtk_stack_get_visible_child(self); `}
fun visible_child_name=(name: Text) do native_visible_child_name = name.to_cstring
- fun native_visible_child_name=(name: NativeString) `{ gtk_stack_set_visible_child_name(self, name); `}
+ fun native_visible_child_name=(name: CString) `{ gtk_stack_set_visible_child_name(self, name); `}
fun visible_child_name: Text do return native_visible_child_name.to_s
fun visible_child_name: Text do return native_visible_child_name.to_s
- fun native_visible_child_name: NativeString `{ return (gchar *)gtk_stack_get_visible_child_name(self); `}
+ fun native_visible_child_name: CString `{ return (gchar *)gtk_stack_get_visible_child_name(self); `}
fun set_visible_child_full(name: Text, transition: GtkStackTransitionType) do native_set_visible_child_full(name.to_cstring, transition)
fun set_visible_child_full(name: Text, transition: GtkStackTransitionType) do native_set_visible_child_full(name.to_cstring, transition)
- fun native_set_visible_child_full(name: NativeString, transition: GtkStackTransitionType) `{
+ fun native_set_visible_child_full(name: CString, transition: GtkStackTransitionType) `{
gtk_stack_set_visible_child_full(self, name, transition);
`}
gtk_stack_set_visible_child_full(self, name, transition);
`}
gtk_assistant_set_page_type(self, page, t);
`}
gtk_assistant_set_page_type(self, page, t);
`}
- fun get_page_title(page: GtkWidget): String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_assistant_get_page_title(self, page));
+ fun get_page_title(page: GtkWidget): String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_assistant_get_page_title(self, page));
`}
fun set_page_title(page: GtkWidget, title: String) import String.to_cstring `{
`}
fun set_page_title(page: GtkWidget, title: String) import String.to_cstring `{
return (GtkFrame *)gtk_frame_new(String_to_cstring(lbl));
`}
return (GtkFrame *)gtk_frame_new(String_to_cstring(lbl));
`}
- fun frame_label: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_frame_get_label(self));
+ fun frame_label: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_frame_get_label(self));
`}
fun frame_label=(lbl: String) import String.to_cstring `{
`}
fun frame_label=(lbl: String) import String.to_cstring `{
return (GtkEntry *)gtk_entry_new();
`}
return (GtkEntry *)gtk_entry_new();
`}
- fun text: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_entry_get_text(self));
+ fun text: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_entry_get_text(self));
`}
fun text=(value: String) import String.to_cstring `{
`}
fun text=(value: String) import String.to_cstring `{
`}
# Returns the text of the label
`}
# Returns the text of the label
- fun text: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char*)gtk_label_get_text(self));
+ fun text: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char*)gtk_label_get_text(self));
`}
# Sets the angle of rotation for the label.
`}
# Sets the angle of rotation for the label.
# lbl.set_markup("<span style=\"italic\">\%s</span>".to_cstring,
# "Italic content")
# ~~~
# lbl.set_markup("<span style=\"italic\">\%s</span>".to_cstring,
# "Italic content")
# ~~~
- fun set_markup(format, content: NativeString) `{
+ fun set_markup(format, content: CString) `{
char *formatted = g_markup_printf_escaped(format, content);
gtk_label_set_markup(self, formatted);
g_free(formatted);
char *formatted = g_markup_printf_escaped(format, content);
gtk_label_set_markup(self, formatted);
g_free(formatted);
return (GtkButton *)gtk_button_new_from_stock(String_to_cstring(stock_id));
`}
return (GtkButton *)gtk_button_new_from_stock(String_to_cstring(stock_id));
`}
- fun text: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_button_get_label(self));
+ fun text: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_button_get_label(self));
`}
fun text=(value: String) import String.to_cstring `{
`}
fun text=(value: String) import String.to_cstring `{
gtk_expander_set_spacing(self, pixels);
`}
gtk_expander_set_spacing(self, pixels);
`}
- fun label_text: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_expander_get_label(self));
+ fun label_text: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_expander_get_label(self));
`}
fun label_text=(lbl: String) import String.to_cstring `{
`}
fun label_text=(lbl: String) import String.to_cstring `{
gtk_combo_box_set_id_column(self, id_column);
`}
gtk_combo_box_set_id_column(self, id_column);
`}
- fun active_id: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_combo_box_get_active_id(self));
+ fun active_id: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_combo_box_get_active_id(self));
`}
fun active_id=(id_active: String) import String.to_cstring `{
`}
fun active_id=(id_active: String) import String.to_cstring `{
gtk_combo_box_popdown(self);
`}
gtk_combo_box_popdown(self);
`}
- fun title: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_combo_box_get_title(self));
+ fun title: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_combo_box_get_title(self));
`}
fun title=(t: String) import String.to_cstring `{
`}
fun title=(t: String) import String.to_cstring `{
return (GtkAboutDialog *)gtk_about_dialog_new();
`}
return (GtkAboutDialog *)gtk_about_dialog_new();
`}
- fun program_name: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_about_dialog_get_program_name(self));
+ fun program_name: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_about_dialog_get_program_name(self));
`}
fun program_name=(name: String) import String.to_cstring `{
gtk_about_dialog_set_program_name(self, String_to_cstring(name));
`}
`}
fun program_name=(name: String) import String.to_cstring `{
gtk_about_dialog_set_program_name(self, String_to_cstring(name));
`}
- fun version: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_about_dialog_get_version(self));
+ fun version: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_about_dialog_get_version(self));
`}
fun version=(v: String) import String.to_cstring `{
gtk_about_dialog_set_version(self, String_to_cstring(v));
`}
`}
fun version=(v: String) import String.to_cstring `{
gtk_about_dialog_set_version(self, String_to_cstring(v));
`}
- fun copyright: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_about_dialog_get_copyright(self));
+ fun copyright: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_about_dialog_get_copyright(self));
`}
fun copyright=(c: String) import String.to_cstring `{
gtk_about_dialog_set_copyright(self, String_to_cstring(c));
`}
`}
fun copyright=(c: String) import String.to_cstring `{
gtk_about_dialog_set_copyright(self, String_to_cstring(c));
`}
- fun comments: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_about_dialog_get_comments(self));
+ fun comments: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_about_dialog_get_comments(self));
`}
fun comments=(com: String) import String.to_cstring `{
gtk_about_dialog_set_comments(self, String_to_cstring(com));
`}
`}
fun comments=(com: String) import String.to_cstring `{
gtk_about_dialog_set_comments(self, String_to_cstring(com));
`}
- fun license: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_about_dialog_get_license(self));
+ fun license: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_about_dialog_get_license(self));
`}
fun license=(li: String) import String.to_cstring `{
`}
fun license=(li: String) import String.to_cstring `{
- fun website: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_about_dialog_get_website(self));
+ fun website: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_about_dialog_get_website(self));
`}
fun website=(link: String) import String.to_cstring `{
gtk_about_dialog_set_website(self, String_to_cstring(link));
`}
`}
fun website=(link: String) import String.to_cstring `{
gtk_about_dialog_set_website(self, String_to_cstring(link));
`}
- fun website_label: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *) gtk_about_dialog_get_website_label(self));
+ fun website_label: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *) gtk_about_dialog_get_website_label(self));
`}
fun website_label=(link_label: String) import String.to_cstring `{
`}
fun website_label=(link_label: String) import String.to_cstring `{
- # fun authors: String import NativeString.to_s_with_copy `{
- # return NativeString_to_s_with_copy(gtk_about_dialog_get_authors(self));
+ # fun authors: String import CString.to_s_with_copy `{
+ # return CString_to_s_with_copy(gtk_about_dialog_get_authors(self));
fun widget: GtkWidget `{ return gtk_app_chooser_dialog_get_widget(self); `}
fun widget: GtkWidget `{ return gtk_app_chooser_dialog_get_widget(self); `}
- fun heading: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_app_chooser_dialog_get_heading(self));
+ fun heading: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_app_chooser_dialog_get_heading(self));
`}
fun heading=(text: String) import String.to_cstring `{
`}
fun heading=(text: String) import String.to_cstring `{
gtk_progress_bar_set_show_text(self, show);
`}
gtk_progress_bar_set_show_text(self, show);
`}
- fun text: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_progress_bar_get_text(self));
+ fun text: String import CString.to_s_with_copy `{
+ return CString_to_s_with_copy((char *)gtk_progress_bar_get_text(self));
`}
fun text=(value: String) import String.to_cstring `{
`}
fun text=(value: String) import String.to_cstring `{
new `{ return (GtkCheckButton *)gtk_check_button_new(); `}
new `{ return (GtkCheckButton *)gtk_check_button_new(); `}
- new with_label(lbl: NativeString) `{ return (GtkCheckButton *)gtk_check_button_new_with_label((gchar *)lbl); `}
+ new with_label(lbl: CString) `{ return (GtkCheckButton *)gtk_check_button_new_with_label((gchar *)lbl); `}
#
# Nit extracts the first arguments from the `args` sequence,
# so we need to add it back. That's why Nit's `args` is smaller than in C.
#
# Nit extracts the first arguments from the `args` sequence,
# so we need to add it back. That's why Nit's `args` is smaller than in C.
- private fun register_args(program_name: NativeString, argc: Int,
+ private fun register_args(program_name: CString, argc: Int,
argv: Sequence[String]) import Sequence[String].[], String.to_cstring in "ObjC" `{
app_nit_ios_argc = (int)(argc+1);
argv: Sequence[String]) import Sequence[String].[], String.to_cstring in "ObjC" `{
app_nit_ios_argc = (int)(argc+1);
private fun nslog in "ObjC" `{ NSLog(@"%@", self); `}
end
private fun nslog in "ObjC" `{ NSLog(@"%@", self); `}
end
-redef class NativeString
# FIXME temp workaround for #1945, bypass Unicode checks
redef fun char_at(pos) do return self[pos].ascii
end
# FIXME temp workaround for #1945, bypass Unicode checks
redef fun char_at(pos) do return self[pos].ascii
end
end
# Get a Java class by its name from the current `jni_env`
end
# Get a Java class by its name from the current `jni_env`
- fun load_jclass(name: NativeString): JClass import jni_env `{
+ fun load_jclass(name: CString): JClass import jni_env `{
JNIEnv *nit_ffi_jni_env = Sys_jni_env(self);
// retrieve the implementation Java class
JNIEnv *nit_ffi_jni_env = Sys_jni_env(self);
// retrieve the implementation Java class
# A standard Java string `java.lang.String`
#
# Converted to a Nit string using `to_s`, or to a C string with `to_cstring`.
# A standard Java string `java.lang.String`
#
# Converted to a Nit string using `to_s`, or to a C string with `to_cstring`.
-# Created using `String::to_java_string` or `NativeString::to_java_string`.
+# Created using `String::to_java_string` or `CString::to_java_string`.
extern class JavaString in "Java" `{ java.lang.String `}
super JavaObject
# Get the string from Java and copy it to Nit memory
extern class JavaString in "Java" `{ java.lang.String `}
super JavaObject
# Get the string from Java and copy it to Nit memory
- fun to_cstring: NativeString import sys, Sys.jni_env `{
+ fun to_cstring: CString import sys, Sys.jni_env `{
Sys sys = JavaString_sys(self);
JNIEnv *env = Sys_jni_env(sys);
Sys sys = JavaString_sys(self);
JNIEnv *env = Sys_jni_env(sys);
-redef class NativeString
# Get a Java string from this C string
#
# This instance is only valid until the next execution of Java code.
# Get a Java string from this C string
#
# This instance is only valid until the next execution of Java code.
# Metamodel
# Class inheritance graph as a `POSet[String]` serialized to JSON
# Metamodel
# Class inheritance graph as a `POSet[String]` serialized to JSON
-private fun class_inheritance_metamodel_json: NativeString is intern
+private fun class_inheritance_metamodel_json: CString is intern
redef class Sys
# Class inheritance graph
redef class Sys
# Class inheritance graph
-redef class NativeString
redef fun accept_json_serializer(v) do to_s.accept_json_serializer(v)
end
redef fun accept_json_serializer(v) do to_s.accept_json_serializer(v)
end
end
private extern class JavaVMOption `{ JavaVMOption* `}
end
private extern class JavaVMOption `{ JavaVMOption* `}
- fun string: String import NativeString.to_s `{
- return NativeString_to_s((char*)self->optionString);
+ fun string: String import CString.to_s `{
+ return CString_to_s((char*)self->optionString);
`}
fun string=(v: String) import String.to_cstring `{
self->optionString = String_to_cstring(v);
`}
`}
fun string=(v: String) import String.to_cstring `{
self->optionString = String_to_cstring(v);
`}
- fun extra_info: String import NativeString.to_s `{
- return NativeString_to_s((char*)self->extraInfo);
+ fun extra_info: String import CString.to_s `{
+ return CString_to_s((char*)self->extraInfo);
`}
fun extra_info=(v: String) import String.to_cstring `{
self->extraInfo = String_to_cstring(v);
`}
fun extra_info=(v: String) import String.to_cstring `{
self->extraInfo = String_to_cstring(v);
- private fun jni_error(msg: NativeString, v: Int)
+ private fun jni_error(msg: CString, v: Int)
do
print "JNI Error: {msg} ({v})"
abort
do
print "JNI Error: {msg} ({v})"
abort
- # Call a method on `obj` designed by `method_id` with an array `args` of arguments returning a NativeString
- fun call_string_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): NativeString import convert_args_to_jni `{
+ # Call a method on `obj` designed by `method_id` with an array `args` of arguments returning a CString
+ fun call_string_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): CString import convert_args_to_jni `{
jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
jobject jobj = (*self)->CallObjectMethod(self, obj, method_id, args_tab);
free(args_tab);
jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
jobject jobj = (*self)->CallObjectMethod(self, obj, method_id, args_tab);
free(args_tab);
# Represents a jni JNINNativeMethod
extern class JNINativeMethod `{ JNINativeMethod* `}
# Represents a jni JNINNativeMethod
extern class JNINativeMethod `{ JNINativeMethod* `}
- fun name: String import NativeString.to_s `{
- return NativeString_to_s((void*)self->name);
+ fun name: String import CString.to_s `{
+ return CString_to_s((void*)self->name);
`}
fun name=(name: String) import String.to_cstring `{
self->name = String_to_cstring(name);
`}
`}
fun name=(name: String) import String.to_cstring `{
self->name = String_to_cstring(name);
`}
- fun signature: String import NativeString.to_s `{
- return NativeString_to_s((void*)self->signature);
+ fun signature: String import CString.to_s `{
+ return CString_to_s((void*)self->signature);
`}
fun signature=(signature: String) import String.to_cstring `{
`}
fun signature=(signature: String) import String.to_cstring `{
-redef class NativeString
redef fun to_jvalue(env)`{
jvalue value;
value.l = (*env)->NewStringUTF(env, self);
redef fun to_jvalue(env)`{
jvalue value;
value.l = (*env)->NewStringUTF(env, self);
do
var evbuffer = bev.input_buffer
var len = evbuffer.length
do
var evbuffer = bev.input_buffer
var len = evbuffer.length
- var buf = new NativeString(len)
+ var buf = new CString(len)
evbuffer.remove(buf, len)
var str = buf.to_s_with_length(len)
read_callback str
evbuffer.remove(buf, len)
var str = buf.to_s_with_length(len)
read_callback str
`}
# Convert an error code from `evutil_socket_error` to a string
`}
# Convert an error code from `evutil_socket_error` to a string
-fun evutil_socket_error_to_string(error_code: Int): NativeString `{
+fun evutil_socket_error_to_string(error_code: Int): CString `{
return evutil_socket_error_to_string(error_code);
`}
return evutil_socket_error_to_string(error_code);
`}
# Set callbacks to `read_callback_native`, `write_callback` and `event_callback` of `conn`
fun setcb(conn: Connection) import Connection.read_callback_native,
# Set callbacks to `read_callback_native`, `write_callback` and `event_callback` of `conn`
fun setcb(conn: Connection) import Connection.read_callback_native,
- Connection.write_callback, Connection.event_callback, NativeString `{
+ Connection.write_callback, Connection.event_callback, CString `{
Connection_incr_ref(conn);
bufferevent_setcb(self,
(bufferevent_data_cb)c_read_cb,
Connection_incr_ref(conn);
bufferevent_setcb(self,
(bufferevent_data_cb)c_read_cb,
`}
# Write `length` bytes of `line`
`}
# Write `length` bytes of `line`
- fun write(line: NativeString, length: Int): Int `{
+ fun write(line: CString, length: Int): Int `{
return bufferevent_write(self, line, length);
`}
return bufferevent_write(self, line, length);
`}
fun length: Int `{ return evbuffer_get_length(self); `}
# Read data from an evbuffer and drain the bytes read
fun length: Int `{ return evbuffer_get_length(self); `}
# Read data from an evbuffer and drain the bytes read
- fun remove(buffer: NativeString, len: Int) `{
+ fun remove(buffer: CString, len: Int) `{
evbuffer_remove(self, buffer, len);
`}
end
evbuffer_remove(self, buffer, len);
`}
end
# A listener acting on an interface and port, spawns `Connection` on new connections
extern class ConnectionListener `{ struct evconnlistener * `}
# A listener acting on an interface and port, spawns `Connection` on new connections
extern class ConnectionListener `{ struct evconnlistener * `}
- private new bind_to(base: NativeEventBase, address: NativeString, port: Int, factory: ConnectionFactory)
+ private new bind_to(base: NativeEventBase, address: CString, port: Int, factory: ConnectionFactory)
import ConnectionFactory.accept_connection, error_callback `{
struct sockaddr_in sin;
import ConnectionFactory.accept_connection, error_callback `{
struct sockaddr_in sin;
# Human representation of remote client address
var addr_len = 46 # Longest possible IPv6 address + null byte
# Human representation of remote client address
var addr_len = 46 # Longest possible IPv6 address + null byte
- var addr_buf = new NativeString(addr_len)
+ var addr_buf = new CString(addr_len)
addr_buf = addrin_to_address(addrin, addr_buf, addr_len)
var addr = if addr_buf.address_is_null then
"Unknown address"
addr_buf = addrin_to_address(addrin, addr_buf, addr_len)
var addr = if addr_buf.address_is_null then
"Unknown address"
end
# Put string representation of source `address` into `buf`
end
# Put string representation of source `address` into `buf`
- private fun addrin_to_address(address: Pointer, buf: NativeString, buf_len: Int): NativeString `{
+ private fun addrin_to_address(address: Pointer, buf: CString, buf_len: Int): CString `{
struct sockaddr *addrin = (struct sockaddr*)address;
if (addrin->sa_family == AF_INET) {
struct sockaddr *addrin = (struct sockaddr*)address;
if (addrin->sa_family == AF_INET) {
fun md5: String do return to_cstring.native_md5.to_s
end
fun md5: String do return to_cstring.native_md5.to_s
end
-redef class NativeString
- private fun native_md5: NativeString `{
+redef class CString
+ private fun native_md5: CString `{
md5_state_t state;
md5_byte_t digest[16]; /* result */
char *hex_output = malloc(33*sizeof(char));
md5_state_t state;
md5_byte_t digest[16]; /* result */
char *hex_output = malloc(33*sizeof(char));
extern class AndroidAsset in "C" `{struct AAsset*`}
extern class AndroidAsset in "C" `{struct AAsset*`}
- fun read(count: Int): nullable String import String.as nullable, NativeString.to_s `{
+ fun read(count: Int): nullable String import String.as nullable, CString.to_s `{
char *buffer = malloc(sizeof(char) * (count+1));
int read = AAsset_read(self, buffer, count);
if (read != count)
char *buffer = malloc(sizeof(char) * (count+1));
int read = AAsset_read(self, buffer, count);
if (read != count)
else
{
buffer[count] = '\0';
else
{
buffer[count] = '\0';
- return String_as_nullable(NativeString_to_s(buffer));
+ return String_as_nullable(CString_to_s(buffer));
redef fun to_s do
var ns = native.to_native_string
var res = ns.to_s_with_copy
redef fun to_s do
var ns = native.to_native_string
var res = ns.to_s_with_copy
- ns.free # manual free of gc allocated NativeString
+ ns.free # manual free of gc allocated CString
# by parsing the JSON found in `data`.
# Only a single JSON object may exist in data or an error will be set and
# `NULL` returned.
# by parsing the JSON found in `data`.
# Only a single JSON object may exist in data or an error will be set and
# `NULL` returned.
- new from_json_string(data: NativeString) import set_mongoc_error `{
+ new from_json_string(data: CString) import set_mongoc_error `{
bson_error_t error;
bson_t *bson;
bson = bson_new_from_json((uint8_t *)data, -1, &error);
bson_error_t error;
bson_t *bson;
bson = bson_new_from_json((uint8_t *)data, -1, &error);
# The `bson_as_json()` function shall encode bson as a JSON encoded UTF-8 string.
# The caller is responsible for freeing the resulting UTF-8 encoded string
# by calling `bson_free()` with the result.
# The `bson_as_json()` function shall encode bson as a JSON encoded UTF-8 string.
# The caller is responsible for freeing the resulting UTF-8 encoded string
# by calling `bson_free()` with the result.
- fun to_native_string: NativeString `{ return bson_as_json(self, NULL); `}
+ fun to_native_string: CString `{ return bson_as_json(self, NULL); `}
# Wrapper for `bson_destroy()`.
#
# Wrapper for `bson_destroy()`.
#
# Wrapper for `error.message`.
#
# The `error.message` field contains a human printable error message.
# Wrapper for `error.message`.
#
# The `error.message` field contains a human printable error message.
- fun message: NativeString `{ return self->message; `}
+ fun message: CString `{ return self->message; `}
end
# Wrapper for `bson_oid_t`.
end
# Wrapper for `bson_oid_t`.
- fun id: String import NativeString.to_s_with_copy `{
+ fun id: String import CString.to_s_with_copy `{
char str[25];
bson_oid_to_string(self, str);
char str[25];
bson_oid_to_string(self, str);
- return NativeString_to_s_with_copy(str);
+ return CString_to_s_with_copy(str);
# Wrapper for `char**`.
#
# Wrapper for `char**`.
#
-# Used to handle array of NativeString returned by MongoDB.
+# Used to handle array of CString returned by MongoDB.
redef class NativeCStringArray
# Frees `self`.
#
redef class NativeCStringArray
# Frees `self`.
#
# Wrapper for `mongoc_client_new()`.
#
# Creates a new `mongoc_client_t` using the `uri` string provided.
# Wrapper for `mongoc_client_new()`.
#
# Creates a new `mongoc_client_t` using the `uri` string provided.
- new(uri: NativeString) `{
mongoc_init();
return mongoc_client_new(uri);
`}
mongoc_init();
return mongoc_client_new(uri);
`}
# Database are automatically created on the MongoDB server upon insertion of
# the first document into a collection.
# There is no need to create a database manually.
# Database are automatically created on the MongoDB server upon insertion of
# the first document into a collection.
# There is no need to create a database manually.
- new(client: NativeMongoClient, db_name: NativeString) `{
+ new(client: NativeMongoClient, db_name: CString) `{
return mongoc_client_get_database(client, db_name);
`}
return mongoc_client_get_database(client, db_name);
`}
#
# Allocates a new `mongoc_collection_t` structure for the collection named
# `name` in database.
#
# Allocates a new `mongoc_collection_t` structure for the collection named
# `name` in database.
- fun collection(name: NativeString): NativeMongoCollection `{
+ fun collection(name: CString): NativeMongoCollection `{
return mongoc_database_get_collection(self, name);
`}
return mongoc_database_get_collection(self, name);
`}
#
# This function checks to see if a collection exists on the MongoDB server
# within database.
#
# This function checks to see if a collection exists on the MongoDB server
# within database.
- fun has_collection(name: NativeString): Bool import set_mongoc_error `{
+ fun has_collection(name: CString): Bool import set_mongoc_error `{
bson_error_t error;
if(!mongoc_database_has_collection(self, name, &error)) {
NativeMongoDb_set_mongoc_error(self, &error);
bson_error_t error;
if(!mongoc_database_has_collection(self, name, &error)) {
NativeMongoDb_set_mongoc_error(self, &error);
# Collections are automatically created on the MongoDB server upon insertion
# of the first document.
# There is no need to create a collection manually.
# Collections are automatically created on the MongoDB server upon insertion
# of the first document.
# There is no need to create a collection manually.
- new(client: NativeMongoClient, db, collection: NativeString) `{
+ new(client: NativeMongoClient, db, collection: CString) `{
return mongoc_client_get_collection(client, db, collection);
`}
return mongoc_client_get_collection(client, db, collection);
`}
# The name of the collection will also be updated internally so it is safe
# to continue using this collection after the rename.
# Additional operations will occur on renamed collection.
# The name of the collection will also be updated internally so it is safe
# to continue using this collection after the rename.
# Additional operations will occur on renamed collection.
- fun rename(new_database, new_name: NativeString): Bool `{
+ fun rename(new_database, new_name: CString): Bool `{
bson_error_t error;
if(!mongoc_collection_rename(self, new_database, new_name, false, &error)){
NativeMongoCollection_set_mongoc_error(self, &error);
bson_error_t error;
if(!mongoc_collection_rename(self, new_database, new_name, false, &error)){
NativeMongoCollection_set_mongoc_error(self, &error);
fun finalize `{ MPI_Finalize(); `}
# Name of this processor, usually the hostname
fun finalize `{ MPI_Finalize(); `}
# Name of this processor, usually the hostname
- fun processor_name: String import NativeString.to_s_with_length `{
+ fun processor_name: String import CString.to_s_with_length `{
char *name = malloc(MPI_MAX_PROCESSOR_NAME);
int size;
MPI_Get_processor_name(name, &size);
char *name = malloc(MPI_MAX_PROCESSOR_NAME);
int size;
MPI_Get_processor_name(name, &size);
- return NativeString_to_s_with_length(name, size);
+ return CString_to_s_with_length(name, size);
`}
# Send the content of a buffer
`}
# Send the content of a buffer
`}
redef fun to_s do return native_to_s.to_s
`}
redef fun to_s do return native_to_s.to_s
- private fun native_to_s: NativeString `{
+ private fun native_to_s: CString `{
char *err = malloc(MPI_MAX_ERROR_STRING);
MPI_Error_string(self, err, NULL);
return err;
char *err = malloc(MPI_MAX_ERROR_STRING);
MPI_Error_string(self, err, NULL);
return err;
# An MPI error class
extern class ErrorClass `{ int `}
redef fun to_s do return native_to_s.to_s
# An MPI error class
extern class ErrorClass `{ int `}
redef fun to_s do return native_to_s.to_s
- private fun native_to_s: NativeString `{
+ private fun native_to_s: CString `{
char *err = malloc(MPI_MAX_ERROR_STRING);
MPI_Error_string(self, err, NULL);
return err;
char *err = malloc(MPI_MAX_ERROR_STRING);
MPI_Error_string(self, err, NULL);
return err;
private fun as_bool: Bool `{ return self->value.as_bool; `}
private fun as_int: Int `{ return self->value.as_int; `}
private fun as_float: Float `{ return self->value.as_double; `}
private fun as_bool: Bool `{ return self->value.as_bool; `}
private fun as_int: Int `{ return self->value.as_int; `}
private fun as_float: Float `{ return self->value.as_double; `}
- private fun as_string: String import NativeString.to_s_with_length `{
+ private fun as_string: String import CString.to_s_with_length `{
uint32_t len;
char* str = (char*)g_varInterface->VarToUtf8(*self, &len);
uint32_t len;
char* str = (char*)g_varInterface->VarToUtf8(*self, &len);
- return NativeString_to_s_with_length(str, len);
+ return CString_to_s_with_length(str, len);
redef fun is_writable: Bool do return true
# Checks if there is a message in the queue, and if so the message is handled automatically.
redef fun is_writable: Bool do return true
# Checks if there is a message in the queue, and if so the message is handled automatically.
- fun check_message: NativeString `{
+ fun check_message: CString `{
return NitHandleMessage();
`}
return NitHandleMessage();
`}
class PnaclApp
# Sets everything up to work, need to be called at first.
class PnaclApp
# Sets everything up to work, need to be called at first.
- fun initialize import PnaclApp.handle_message, PnaclApp.handle_dictionary, NativeString.to_s_with_length `{
+ fun initialize import PnaclApp.handle_message, PnaclApp.handle_dictionary, CString.to_s_with_length `{
redef extern class Passwd
# User information
redef extern class Passwd
# User information
- fun gecos: String import NativeString.to_s `{ return NativeString_to_s(self->pw_gecos); `}
+ fun gecos: String import CString.to_s `{ return CString_to_s(self->pw_gecos); `}
return !(self == PGRES_BAD_RESPONSE || self == PGRES_NONFATAL_ERROR || self == PGRES_FATAL_ERROR);
`}
return !(self == PGRES_BAD_RESPONSE || self == PGRES_NONFATAL_ERROR || self == PGRES_FATAL_ERROR);
`}
- redef fun to_s import NativeString.to_s `{
+ redef fun to_s import CString.to_s `{
char * err = PQresStatus(self);
if(err == NULL) err = "";
char * err = PQresStatus(self);
if(err == NULL) err = "";
- return NativeString_to_s(err);
+ return CString_to_s(err);
fun status: ExecStatusType `{ return PQresultStatus(self); `}
# Returns the field name of a given column_number
fun status: ExecStatusType `{ return PQresultStatus(self); `}
# Returns the field name of a given column_number
- fun fname(column_number:Int):String import NativeString.to_s `{
- return NativeString_to_s( PQfname(self, column_number));
+ fun fname(column_number:Int):String import CString.to_s `{
+ return CString_to_s( PQfname(self, column_number));
`}
# Returns the column number associated with the column name
`}
# Returns the column number associated with the column name
`}
# Returns a single field value of one row of the result at row_number, column_number
`}
# Returns a single field value of one row of the result at row_number, column_number
- fun value(row_number:Int, column_number:Int):String import NativeString.to_s `{
- return NativeString_to_s(PQgetvalue(self, row_number, column_number));
+ fun value(row_number:Int, column_number:Int):String import CString.to_s `{
+ return CString_to_s(PQgetvalue(self, row_number, column_number));
`}
# Tests wether a field is a null value
`}
# Tests wether a field is a null value
`}
# Returns the error message of the last operation on the connection
`}
# Returns the error message of the last operation on the connection
- fun error: String import NativeString.to_s `{
+ fun error: String import CString.to_s `{
char * error = PQerrorMessage(self);
char * error = PQerrorMessage(self);
- return NativeString_to_s(error);
+ return CString_to_s(error);
`}
# Returns the status of this connection
`}
# Returns the status of this connection
#include <readline/history.h>
`}
#include <readline/history.h>
`}
-private fun native_readline(prompt: NativeString): NativeString `{
+private fun native_readline(prompt: CString): CString `{
return readline(prompt);
`}
return readline(prompt);
`}
-private fun native_add_history(data: NativeString) `{
+private fun native_add_history(data: CString) `{
if (data == NULL) return;
add_history(data);
`}
if (data == NULL) return;
add_history(data);
`}
return null_SDLInputEvent();
`}
return null_SDLInputEvent();
`}
- private fun new_key_event(name: NativeString, down: Bool): nullable SDLInputEvent
+ private fun new_key_event(name: CString, down: Bool): nullable SDLInputEvent
do return new SDLKeyEvent(name.to_s, down)
private fun new_mouse_motion_event(x, y, xr, yr: Float, down: Bool): nullable SDLInputEvent
do return new SDLKeyEvent(name.to_s, down)
private fun new_mouse_motion_event(x, y, xr, yr: Float, down: Bool): nullable SDLInputEvent
if (fn == NULL)
return null_String();
else
if (fn == NULL)
return null_String();
else
- return String_as_nullable(NativeString_to_s(fn));
+ return String_as_nullable(CString_to_s(fn));
`}
# Return the style name of the font
`}
# Return the style name of the font
if (sn == NULL)
return null_String();
else
if (sn == NULL)
return null_String();
else
- return String_as_nullable(NativeString_to_s(sn));
+ return String_as_nullable(CString_to_s(sn));
`}
# Return the estimated width of a String if used with the current font
`}
# Return the estimated width of a String if used with the current font
- fun width_of(text: String): Int import NativeString.to_s `{
+ fun width_of(text: String): Int import CString.to_s `{
char *ctext = String_to_cstring(text);
int w;
if (TTF_SizeText(self, ctext, &w, NULL))
char *ctext = String_to_cstring(text);
int w;
if (TTF_SizeText(self, ctext, &w, NULL))
fun quit `{ IMG_Quit(); `}
# Get the latest image library error
fun quit `{ IMG_Quit(); `}
# Get the latest image library error
- fun error: NativeString `{ return (char*)IMG_GetError(); `}
+ fun error: CString `{ return (char*)IMG_GetError(); `}
end
redef extern class SDLSurface
# Load the image at `path` inferring its type from the file extension
end
redef extern class SDLSurface
# Load the image at `path` inferring its type from the file extension
- new load(path: NativeString) `{ return IMG_Load(path); `}
+ new load(path: CString) `{ return IMG_Load(path); `}
end
# Flags from `sys.sdl.img.initialize`
end
# Flags from `sys.sdl.img.initialize`
# Returns the latest SDL error
#
# After calling this method, you should also call `clear_error`.
# Returns the latest SDL error
#
# After calling this method, you should also call `clear_error`.
- fun error: NativeString `{ return (char*)SDL_GetError(); `}
+ fun error: CString `{ return (char*)SDL_GetError(); `}
# Clear the SDL error
fun clear_error `{ SDL_ClearError(); `}
# Clear the SDL error
fun clear_error `{ SDL_ClearError(); `}
fun system_ram: Int `{ return SDL_GetSystemRAM(); `}
# Show a simple message box
fun system_ram: Int `{ return SDL_GetSystemRAM(); `}
# Show a simple message box
- fun show_simple_message_box(level: SDLMessageBoxFlags, title, content: NativeString) `{
+ fun show_simple_message_box(level: SDLMessageBoxFlags, title, content: CString) `{
SDL_ShowSimpleMessageBox(level, title, content, NULL);
`}
SDL_ShowSimpleMessageBox(level, title, content, NULL);
`}
# A window created by SDL
extern class SDLWindow `{ SDL_Window * `}
# Create a window with the given `title`, `width` and `height`, also apply the `flags`
# A window created by SDL
extern class SDLWindow `{ SDL_Window * `}
# Create a window with the given `title`, `width` and `height`, also apply the `flags`
- new (title: NativeString, width, height: Int, flags: SDLWindowFlags) `{
+ new (title: CString, width, height: Int, flags: SDLWindowFlags) `{
return SDL_CreateWindow(title,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, flags);
return SDL_CreateWindow(title,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, flags);
# Show a simple message box
#
# Similar to `sys.sdl.show_simple_message_box` but attached to this window
# Show a simple message box
#
# Similar to `sys.sdl.show_simple_message_box` but attached to this window
- fun show_simple_message_box(level: SDLMessageBoxFlags, title, content: NativeString) `{
+ fun show_simple_message_box(level: SDLMessageBoxFlags, title, content: CString) `{
SDL_ShowSimpleMessageBox(level, title, content, self);
`}
SDL_ShowSimpleMessageBox(level, title, content, self);
`}
extern class SDLSurface `{ SDL_Surface * `}
# Load the BMP file at `path`
extern class SDLSurface `{ SDL_Surface * `}
# Load the BMP file at `path`
- new load_bmp(path: NativeString) `{ return SDL_LoadBMP(path); `}
+ new load_bmp(path: CString) `{ return SDL_LoadBMP(path); `}
redef fun free `{ SDL_FreeSurface(self); `}
# Save this texture to a BMP file
redef fun free `{ SDL_FreeSurface(self); `}
# Save this texture to a BMP file
- fun save_bmp(path: NativeString) `{ SDL_SaveBMP(self, path); `}
+ fun save_bmp(path: CString) `{ SDL_SaveBMP(self, path); `}
end
# A loaded bitmap texture
end
# A loaded bitmap texture
new malloc `{ return malloc(sizeof(SDL_RendererInfo)); `}
# Name of the renderer's driver
new malloc `{ return malloc(sizeof(SDL_RendererInfo)); `}
# Name of the renderer's driver
- fun name: NativeString `{ return (char*)self->name; `}
+ fun name: CString `{ return (char*)self->name; `}
# Maximum texture width supported by the renderer
fun max_texture_width: Int `{ return self->max_texture_width; `}
# Maximum texture width supported by the renderer
fun max_texture_width: Int `{ return self->max_texture_width; `}
redef class Char super DirectSerializable end
redef class Int super DirectSerializable end
redef class Float super DirectSerializable end
redef class Char super DirectSerializable end
redef class Int super DirectSerializable end
redef class Float super DirectSerializable end
-redef class NativeString super DirectSerializable end
+redef class CString super DirectSerializable end
redef class Text super DirectSerializable end
redef class SimpleCollection[E] super Serializable end
redef class Map[K, V] super Serializable end
redef class Text super DirectSerializable end
redef class SimpleCollection[E] super Serializable end
redef class Map[K, V] super Serializable end
-redef class NativeString
- private fun sha1_intern(len: Int): NativeString `{
+redef class CString
+ private fun sha1_intern(len: Int): CString `{
sha1nfo s;
sha1_init(&s);
sha1nfo s;
sha1_init(&s);
# Computes the SHA1 of the receiver
#
# Computes the SHA1 of the receiver
#
- # Returns a digest of 20 bytes as a NativeString,
+ # Returns a digest of 20 bytes as a CString,
# note that all the characters are not necessarily ASCII.
# If you want the hex string version of the digest, use
# sha1_hexdigest.
# note that all the characters are not necessarily ASCII.
# If you want the hex string version of the digest, use
# sha1_hexdigest.
# Creates a socket connection to host `host` on port `port`
init connect(host: String, port: Int)
do
# Creates a socket connection to host `host` on port `port`
init connect(host: String, port: Int)
do
- _buffer = new NativeString(1024)
+ _buffer = new CString(1024)
_buffer_pos = 0
native = new NativeSocket.socket(new NativeSocketAddressFamilies.af_inet,
new NativeSocketTypes.sock_stream, new NativeSocketProtocolFamilies.pf_null)
_buffer_pos = 0
native = new NativeSocket.socket(new NativeSocketAddressFamilies.af_inet,
new NativeSocketTypes.sock_stream, new NativeSocketProtocolFamilies.pf_null)
if _buffer_capacity >= len then return
_buffer_capacity = len
if _buffer_capacity >= len then return
_buffer_capacity = len
- var ns = new NativeString(_buffer_capacity)
+ var ns = new CString(_buffer_capacity)
_buffer.copy_to(ns, _buffer_length - _buffer_pos, _buffer_pos, 0)
_buffer = ns
end
_buffer.copy_to(ns, _buffer_length - _buffer_pos, _buffer_pos, 0)
_buffer = ns
end
# On error, returns an empty string and sets `error` appropriately.
fun recv(length: Int): String
do
# On error, returns an empty string and sets `error` appropriately.
fun recv(length: Int): String
do
- var buf = new NativeString(length)
+ var buf = new CString(length)
var len = native.recvfrom(buf, length, 0, new NativeSocketAddrIn.nul)
if len == -1 then
error = new IOError.from_errno
var len = native.recvfrom(buf, length, 0, new NativeSocketAddrIn.nul)
if len == -1 then
error = new IOError.from_errno
fun recv_from(length: Int, sender: Ref[nullable SocketAddress]): String
do
var src = new NativeSocketAddrIn
fun recv_from(length: Int, sender: Ref[nullable SocketAddress]): String
do
var src = new NativeSocketAddrIn
- var buf = new NativeString(length)
+ var buf = new CString(length)
var len = native.recvfrom(buf, length, 0, src)
if len == -1 then
var len = native.recvfrom(buf, length, 0, src)
if len == -1 then
`}
# Write `length` bytes from `buffer`
`}
# Write `length` bytes from `buffer`
- fun write(buffer: NativeString, length: Int): Int `{
+ fun write(buffer: CString, length: Int): Int `{
return write(*self, buffer, length);
`}
return write(*self, buffer, length);
`}
`}
# Read `length` bytes into `buffer`, returns the number of bytes read
`}
# Read `length` bytes into `buffer`, returns the number of bytes read
- fun read(buffer: NativeString, length: Int): Int `{
+ fun read(buffer: CString, length: Int): Int `{
return read(*self, buffer, length);
`}
return read(*self, buffer, length);
`}
`}
# Send `len` bytes from `buf` to `dest_addr`
`}
# Send `len` bytes from `buf` to `dest_addr`
- fun sendto(buf: NativeString, len: Int, flags: Int, dest_addr: NativeSocketAddrIn): Int `{
+ fun sendto(buf: CString, len: Int, flags: Int, dest_addr: NativeSocketAddrIn): Int `{
return sendto(*self, buf, len, flags, (struct sockaddr*)dest_addr, sizeof(struct sockaddr_in));
`}
# Receive a message into `buf` of maximum `len` bytes
return sendto(*self, buf, len, flags, (struct sockaddr*)dest_addr, sizeof(struct sockaddr_in));
`}
# Receive a message into `buf` of maximum `len` bytes
- fun recv(buf: NativeString, len: Int, flags: Int): Int `{
+ fun recv(buf: CString, len: Int, flags: Int): Int `{
return recv(*self, buf, len, flags);
`}
# Receive a message into `buf` of maximum `len` bytes and store sender info into `src_addr`
return recv(*self, buf, len, flags);
`}
# Receive a message into `buf` of maximum `len` bytes and store sender info into `src_addr`
- fun recvfrom(buf: NativeString, len: Int, flags: Int, src_addr: NativeSocketAddrIn): Int `{
+ fun recvfrom(buf: CString, len: Int, flags: Int, src_addr: NativeSocketAddrIn): Int `{
socklen_t srclen = sizeof(struct sockaddr_in);
return recvfrom(*self, buf, len, flags, (struct sockaddr*)src_addr, &srclen);
`}
socklen_t srclen = sizeof(struct sockaddr_in);
return recvfrom(*self, buf, len, flags, (struct sockaddr*)src_addr, &srclen);
`}
`}
# Internet address as then IPV4 numbers-and-dots notation
`}
# Internet address as then IPV4 numbers-and-dots notation
- fun address: NativeString `{ return (char*)inet_ntoa(self->sin_addr); `}
+ fun address: CString `{ return (char*)inet_ntoa(self->sin_addr); `}
# Set `address` to `INADDR_ANY`
fun address_any `{ self->sin_addr.s_addr = INADDR_ANY; `}
# Set `address` to `INADDR_ANY`
fun address_any `{ self->sin_addr.s_addr = INADDR_ANY; `}
# Host entry information, a pointer to a `struct hostent`
extern class NativeSocketHostent `{ struct hostent* `}
# Host entry information, a pointer to a `struct hostent`
extern class NativeSocketHostent `{ struct hostent* `}
- private fun native_h_aliases(i: Int): NativeString `{
+ private fun native_h_aliases(i: Int): CString `{
return self->h_aliases[i];
`}
return self->h_aliases[i];
`}
- fun h_addr: NativeString `{
return (char*)inet_ntoa(*(struct in_addr*)self->h_addr);
`}
return (char*)inet_ntoa(*(struct in_addr*)self->h_addr);
`}
fun h_length: Int `{ return self->h_length; `}
fun h_length: Int `{ return self->h_length; `}
- fun h_name: NativeString `{ return self->h_name; `}
+ fun h_name: CString `{ return self->h_name; `}
end
extern class NativeTimeval `{ struct timeval* `}
end
extern class NativeTimeval `{ struct timeval* `}
redef class Sys
# Get network host entry
redef class Sys
# Get network host entry
- fun gethostbyname(name: NativeString): NativeSocketHostent `{
+ fun gethostbyname(name: CString): NativeSocketHostent `{
return gethostbyname(name);
`}
return gethostbyname(name);
`}
- private fun native_to_s: NativeString `{
+ private fun native_to_s: CString `{
#if SQLITE_VERSION_NUMBER >= 3007015
return (char *)sqlite3_errstr(self);
#else
#if SQLITE_VERSION_NUMBER >= 3007015
return (char *)sqlite3_errstr(self);
#else
return sqlite3_step(self);
`}
return sqlite3_step(self);
`}
- fun column_name(i: Int): NativeString `{
+ fun column_name(i: Int): CString `{
return (char *)sqlite3_column_name(self, i);
`}
return (char *)sqlite3_column_name(self, i);
`}
return sqlite3_column_int(self, i);
`}
return sqlite3_column_int(self, i);
`}
- fun column_text(i: Int): NativeString `{
+ fun column_text(i: Int): CString `{
return (char *)sqlite3_column_text(self, i);
`}
return (char *)sqlite3_column_text(self, i);
`}
extern class NativeSqlite3 `{sqlite3 *`}
# Open a connection to a database in UTF-8
extern class NativeSqlite3 `{sqlite3 *`}
# Open a connection to a database in UTF-8
- new open(filename: NativeString) `{
+ new open(filename: CString) `{
sqlite3 *self = NULL;
int err = sqlite3_open(filename, &self);
nit_sqlite_open_error = err;
sqlite3 *self = NULL;
int err = sqlite3_open(filename, &self);
nit_sqlite_open_error = err;
`}
# Execute a SQL statement
`}
# Execute a SQL statement
- fun exec(sql: NativeString): Sqlite3Code `{
+ fun exec(sql: CString): Sqlite3Code `{
return sqlite3_exec(self, sql, NULL, NULL, NULL);
`}
# Prepare a SQL statement
return sqlite3_exec(self, sql, NULL, NULL, NULL);
`}
# Prepare a SQL statement
- fun prepare(sql: NativeString): NativeStatement `{
+ fun prepare(sql: CString): NativeStatement `{
sqlite3_stmt *stmt;
int res = sqlite3_prepare_v2(self, sql, -1, &stmt, 0);
if (res == SQLITE_OK)
sqlite3_stmt *stmt;
int res = sqlite3_prepare_v2(self, sql, -1, &stmt, 0);
if (res == SQLITE_OK)
- _buffer = new NativeString(1024)
+ _buffer = new CString(1024)
_buffer_pos = 0
_buffer_capacity = 1024
_buffer_length = 0
_buffer_pos = 0
_buffer_capacity = 1024
_buffer_length = 0
end
# Unmasks a message sent by a client
end
# Unmasks a message sent by a client
- private fun unmask_message(key: NativeString, message: NativeString, len: Int): NativeString
+ private fun unmask_message(key: CString, message: CString, len: Int): CString
- var return_message = new NativeString(len)
+ var return_message = new CString(len)
for i in [0 .. len[ do
return_message[i] = message[i] ^ key[i % 4]
for i in [0 .. len[ do
return_message[i] = message[i] ^ key[i % 4]
fun update: Bool `{ return xdgUpdateData(self); `}
# Base directory for user specific data files.
fun update: Bool `{ return xdgUpdateData(self); `}
# Base directory for user specific data files.
- fun data_home: String import NativeString.to_s `{
- return NativeString_to_s((char*)xdgDataHome(self));
+ fun data_home: String import CString.to_s `{
+ return CString_to_s((char*)xdgDataHome(self));
`}
# Base directory for user specific configuration files.
`}
# Base directory for user specific configuration files.
- fun config_home: String import NativeString.to_s `{
- return NativeString_to_s((char*)xdgConfigHome(self));
+ fun config_home: String import CString.to_s `{
+ return CString_to_s((char*)xdgConfigHome(self));
`}
# Base directory for user specific non-essential data files.
`}
# Base directory for user specific non-essential data files.
- fun cache_home: String import NativeString.to_s `{
- return NativeString_to_s((char*)xdgCacheHome(self));
+ fun cache_home: String import CString.to_s `{
+ return CString_to_s((char*)xdgCacheHome(self));
`}
# Preference-ordered set of base directories to search for data files
`}
# Preference-ordered set of base directories to search for data files
private extern class ConstPointer `{ const void * `}
# Convert a C `char **` to a Nit `Array[String]`
fun to_string_array: Array[String]
private extern class ConstPointer `{ const void * `}
# Convert a C `char **` to a Nit `Array[String]`
fun to_string_array: Array[String]
- import Array[String], Array[String].add, NativeString.to_s `{
+ import Array[String], Array[String].add, CString.to_s `{
char **strings = (char**)self;
Array_of_String aos = new_Array_of_String();
int p = 0;
while (strings[p] != NULL) {
char **strings = (char**)self;
Array_of_String aos = new_Array_of_String();
int p = 0;
while (strings[p] != NULL) {
- Array_of_String_add(aos, NativeString_to_s((char*)strings[p]));
+ Array_of_String_add(aos, CString_to_s((char*)strings[p]));
end
# Return a "const char*" variable associated to the classname of the dynamic type of an object
end
# Return a "const char*" variable associated to the classname of the dynamic type of an object
- # NOTE: we do not return a `RuntimeVariable` "NativeString" as the class may not exist in the module/program
+ # NOTE: we do not return a `RuntimeVariable` "CString" as the class may not exist in the module/program
fun class_name_string(value: RuntimeVariable): String is abstract
# Variables handling
fun class_name_string(value: RuntimeVariable): String is abstract
# Variables handling
- # Generates a NativeString instance fully escaped in C-style \xHH fashion
- fun native_string_instance(ns: NativeString, len: Int): RuntimeVariable do
+ # Generates a CString instance fully escaped in C-style \xHH fashion
+ fun native_string_instance(ns: CString, len: Int): RuntimeVariable do
var mtype = mmodule.native_string_type
var nat = new_var(mtype)
var byte_esc = new Buffer.with_cap(len * 4)
var mtype = mmodule.native_string_type
var nat = new_var(mtype)
var byte_esc = new Buffer.with_cap(len * 4)
return "int32_t"
else if mclass.name == "UInt32" then
return "uint32_t"
return "int32_t"
else if mclass.name == "UInt32" then
return "uint32_t"
- else if mclass.name == "NativeString" then
+ else if mclass.name == "CString" then
return "char*"
else if mclass.name == "NativeArray" then
return "val*"
return "char*"
else if mclass.name == "NativeArray" then
return "val*"
return "i32"
else if mclass.name == "UInt32" then
return "u32"
return "i32"
else if mclass.name == "UInt32" then
return "u32"
- else if mclass.name == "NativeString" then
+ else if mclass.name == "CString" then
return "str"
else if mclass.name == "NativeArray" then
#return "{self.arguments.first.ctype}*"
return "str"
else if mclass.name == "NativeArray" then
#return "{self.arguments.first.ctype}*"
v.ret(v.new_expr("(uint32_t){arguments[0]}", ret.as(not null)))
return true
end
v.ret(v.new_expr("(uint32_t){arguments[0]}", ret.as(not null)))
return true
end
- else if cname == "NativeString" then
+ else if cname == "CString" then
if pname == "[]" then
v.ret(v.new_expr("(unsigned char)((int){arguments[0]}[{arguments[1]}])", ret.as(not null)))
return true
if pname == "[]" then
v.ret(v.new_expr("(unsigned char)((int){arguments[0]}[{arguments[1]}])", ret.as(not null)))
return true
v.ret(v.new_expr("!{res}", ret.as(not null)))
return true
else if pname == "new" then
v.ret(v.new_expr("!{res}", ret.as(not null)))
return true
else if pname == "new" then
- var alloc = v.nit_alloc(arguments[1].to_s, "NativeString")
+ var alloc = v.nit_alloc(arguments[1].to_s, "CString")
v.ret(v.new_expr("(char*){alloc}", ret.as(not null)))
return true
else if pname == "fetch_4_chars" then
v.ret(v.new_expr("(char*){alloc}", ret.as(not null)))
return true
else if pname == "fetch_4_chars" then
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct {mtype.c_name}*){value})->value; /* unboxing {value.mtype} */"
return res
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct {mtype.c_name}*){value})->value; /* unboxing {value.mtype} */"
return res
redef fun box_extern(value, mtype)
do
if not mtype isa MClassType or mtype.mclass.kind != extern_kind or
redef fun box_extern(value, mtype)
do
if not mtype isa MClassType or mtype.mclass.kind != extern_kind or
- mtype.mclass.name == "NativeString" then return value
+ mtype.mclass.name == "CString" then return value
var valtype = value.mtype.as(MClassType)
var res = self.new_var(mtype)
var valtype = value.mtype.as(MClassType)
var res = self.new_var(mtype)
return "double"
else if mclass.name == "Byte" then
return "byte"
return "double"
else if mclass.name == "Byte" then
return "byte"
- else if mclass.name == "NativeString" then
+ else if mclass.name == "CString" then
return "String"
else if mclass.name == "NativeArray" then
return "Array"
return "String"
else if mclass.name == "NativeArray" then
return "Array"
do
# Collect all bas box class
# FIXME: this is not completely fine with a separate compilation scheme
do
# Collect all bas box class
# FIXME: this is not completely fine with a separate compilation scheme
- for classname in ["Int", "Bool", "Byte", "Char", "Float", "NativeString",
+ for classname in ["Int", "Bool", "Byte", "Char", "Float", "CString",
"Pointer", "Int8", "Int16", "UInt16", "Int32", "UInt32"] do
var classes = self.mainmodule.model.get_mclasses_by_name(classname)
if classes == null then continue
"Pointer", "Int8", "Int16", "UInt16", "Int32", "UInt32"] do
var classes = self.mainmodule.model.get_mclasses_by_name(classname)
if classes == null then continue
#if mclass.mclass_type.ctype == "val*" or mclass.mclass_type.is_subtype(self.mainmodule, mclass.mclass_type pointer_type) then
if mclass.mclass_type.ctype_extern == "val*" then
return 0
#if mclass.mclass_type.ctype == "val*" or mclass.mclass_type.is_subtype(self.mainmodule, mclass.mclass_type pointer_type) then
if mclass.mclass_type.ctype_extern == "val*" then
return 0
- else if mclass.kind == extern_kind and mclass.name != "NativeString" then
+ else if mclass.kind == extern_kind and mclass.name != "CString" then
return self.box_kinds[self.mainmodule.pointer_type.mclass]
else
return self.box_kinds[mclass]
return self.box_kinds[self.mainmodule.pointer_type.mclass]
else
return self.box_kinds[mclass]
v.add("return (val*){res};")
v.add("\}")
return
v.add("return (val*){res};")
v.add("\}")
return
- else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "NativeString" then
- # Is an extern class (other than Pointer and NativeString)
- # Pointer is caught in a previous `if`, and NativeString is internal
+ else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "CString" then
+ # Is an extern class (other than Pointer and CString)
+ # Pointer is caught in a previous `if`, and CString is internal
var pointer_type = mainmodule.pointer_type
var pointer_type = mainmodule.pointer_type
return res
end
var valtype = value.mtype.as(MClassType)
return res
end
var valtype = value.mtype.as(MClassType)
- if mtype isa MClassType and mtype.mclass.kind == extern_kind and mtype.mclass.name != "NativeString" then
+ if mtype isa MClassType and mtype.mclass.kind == extern_kind and mtype.mclass.name != "CString" then
valtype = compiler.mainmodule.pointer_type
end
var res = self.new_var(mtype)
valtype = compiler.mainmodule.pointer_type
end
var res = self.new_var(mtype)
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var pointer_type = compiler.mainmodule.pointer_type
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct instance_{pointer_type.c_name}*){value})->value; /* unboxing {value.mtype} */"
var pointer_type = compiler.mainmodule.pointer_type
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct instance_{pointer_type.c_name}*){value})->value; /* unboxing {value.mtype} */"
redef fun box_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
redef fun box_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var valtype = compiler.mainmodule.pointer_type
var res = self.new_var(mtype)
compiler.undead_types.add(mtype)
var valtype = compiler.mainmodule.pointer_type
var res = self.new_var(mtype)
compiler.undead_types.add(mtype)
if not value.mtype.is_c_primitive then
self.add "{res} = {value} == NULL ? \"null\" : {type_info(value)}->name;"
else if value.mtype isa MClassType and value.mtype.as(MClassType).mclass.kind == extern_kind and
if not value.mtype.is_c_primitive then
self.add "{res} = {value} == NULL ? \"null\" : {type_info(value)}->name;"
else if value.mtype isa MClassType and value.mtype.as(MClassType).mclass.kind == extern_kind and
- value.mtype.as(MClassType).name != "NativeString" then
+ value.mtype.as(MClassType).name != "CString" then
self.add "{res} = \"{value.mtype.as(MClassType).mclass}\";"
else
self.require_declaration("type_{value.mtype.c_name}")
self.add "{res} = \"{value.mtype.as(MClassType).mclass}\";"
else
self.require_declaration("type_{value.mtype.c_name}")
v.add("return (val*){res};")
v.add("\}")
return
v.add("return (val*){res};")
v.add("\}")
return
- else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "NativeString" then
+ else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "CString" then
var pointer_type = mainmodule.pointer_type
self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}();")
var pointer_type = mainmodule.pointer_type
self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}();")
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
redef fun unbox_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var pointer_type = compiler.mainmodule.pointer_type
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct instance_{pointer_type.c_name}*){value})->value; /* unboxing {value.mtype} */"
var pointer_type = compiler.mainmodule.pointer_type
var res = self.new_var_extern(mtype)
self.add "{res} = ((struct instance_{pointer_type.c_name}*){value})->value; /* unboxing {value.mtype} */"
redef fun box_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
redef fun box_extern(value, mtype)
do
if mtype isa MClassType and mtype.mclass.kind == extern_kind and
- mtype.mclass.name != "NativeString" then
+ mtype.mclass.name != "CString" then
var valtype = compiler.mainmodule.pointer_type
var res = self.new_var(mtype)
if compiler.runtime_type_analysis != null and not compiler.runtime_type_analysis.live_types.has(value.mtype.as(MClassType)) then
var valtype = compiler.mainmodule.pointer_type
var res = self.new_var(mtype)
if compiler.runtime_type_analysis != null and not compiler.runtime_type_analysis.live_types.has(value.mtype.as(MClassType)) then
# The `Instance` held by this cell
fun instance=(value: Instance) is light_ffi `{ self->value_Pointer = value; `}
# The `Instance` held by this cell
fun instance=(value: Instance) is light_ffi `{ self->value_Pointer = value; `}
- # The `NativeString` held by this cell
- fun native_string: NativeString `{ return (char*)self->value_Pointer; `}
+ # The `CString` held by this cell
+ fun native_string: CString `{ return (char*)self->value_Pointer; `}
# Set the content of this cell according to `static_type`
#
# Set the content of this cell according to `static_type`
#
else if static_type.name == "Float" then
assert value isa PrimitiveInstance[Float]
self.float = value.val
else if static_type.name == "Float" then
assert value isa PrimitiveInstance[Float]
self.float = value.val
- else if static_type.name == "NativeString" then
- assert value isa PrimitiveInstance[NativeString]
+ else if static_type.name == "CString" then
+ assert value isa PrimitiveInstance[CString]
self.pointer = value.val
else if static_type isa MClassType and static_type.mclass.kind == extern_kind then
assert value isa PrimitiveInstance[Pointer] else print value.class_name
self.pointer = value.val
else if static_type isa MClassType and static_type.mclass.kind == extern_kind then
assert value isa PrimitiveInstance[Pointer] else print value.class_name
return v.uint32_instance(self.uint32)
else if name == "Float" then
return v.float_instance(self.float)
return v.uint32_instance(self.uint32)
else if name == "Float" then
return v.float_instance(self.float)
- else if name == "NativeString" then
- var instance = new PrimitiveInstance[NativeString](static_type, self.native_string)
+ else if name == "CString" then
+ var instance = new PrimitiveInstance[CString](static_type, self.native_string)
v.init_instance_primitive instance
return instance
else if static_type isa MClassType and static_type.mclass.kind == extern_kind then
v.init_instance_primitive instance
return instance
else if static_type isa MClassType and static_type.mclass.kind == extern_kind then
# Handle to foreign code library
private extern class ForeignCodeLib
# Open and load the library at `path`
# Handle to foreign code library
private extern class ForeignCodeLib
# Open and load the library at `path`
- new dlopen(path: NativeString) `{
+ new dlopen(path: CString) `{
return dlopen(path, RTLD_LOCAL | RTLD_NOW);
`}
# Find the `ForeignCodeEntry` at `symbol_name`
return dlopen(path, RTLD_LOCAL | RTLD_NOW);
`}
# Find the `ForeignCodeEntry` at `symbol_name`
- fun dlsym(symbol_name: NativeString): ForeignCodeEntry `{
+ fun dlsym(symbol_name: CString): ForeignCodeEntry `{
return dlsym(self, symbol_name);
`}
end
return dlsym(self, symbol_name);
`}
end
-private fun dlerror: NativeString `{ return dlerror(); `}
+private fun dlerror: CString `{ return dlerror(); `}
# Handle to an implementation function in a `ForeignCodeLib`
private extern class ForeignCodeEntry`{ nit_foreign_lib_entry `}
# Handle to an implementation function in a `ForeignCodeLib`
private extern class ForeignCodeEntry`{ nit_foreign_lib_entry `}
end
# Return a new native string initialized with `txt`
end
# Return a new native string initialized with `txt`
- fun native_string_instance_from_ns(txt: NativeString, len: Int): Instance
+ fun native_string_instance_from_ns(txt: CString, len: Int): Instance
do
var instance = native_string_instance_len(len)
var val = instance.val
do
var instance = native_string_instance_len(len)
var val = instance.val
end
# Return a new native string initialized of `length`
end
# Return a new native string initialized of `length`
- fun native_string_instance_len(length: Int): PrimitiveInstance[NativeString]
+ fun native_string_instance_len(length: Int): PrimitiveInstance[CString]
- var val = new NativeString(length)
+ var val = new CString(length)
var t = mainmodule.native_string_type
var t = mainmodule.native_string_type
- var instance = new PrimitiveInstance[NativeString](t, val)
+ var instance = new PrimitiveInstance[CString](t, val)
init_instance_primitive(instance)
return instance
end
init_instance_primitive(instance)
return instance
end
else if pname == "round" then
return v.float_instance(args[0].to_f.round)
end
else if pname == "round" then
return v.float_instance(args[0].to_f.round)
end
- else if cname == "NativeString" then
+ else if cname == "CString" then
if pname == "new" then
return v.native_string_instance_len(args[1].to_i)
end
if pname == "new" then
return v.native_string_instance_len(args[1].to_i)
end
- var recvval = args.first.val.as(NativeString)
+ var recvval = args.first.val.as(CString)
if pname == "[]" then
var arg1 = args[1].to_i
return v.byte_instance(recvval[arg1])
if pname == "[]" then
var arg1 = args[1].to_i
return v.byte_instance(recvval[arg1])
recvval[arg1] = args[2].val.as(Byte)
return null
else if pname == "copy_to" then
recvval[arg1] = args[2].val.as(Byte)
return null
else if pname == "copy_to" then
- # sig= copy_to(dest: NativeString, length: Int, from: Int, to: Int)
- var destval = args[1].val.as(NativeString)
+ # sig= copy_to(dest: CString, length: Int, from: Int, to: Int)
+ var destval = args[1].val.as(CString)
var lenval = args[2].to_i
var fromval = args[3].to_i
var toval = args[4].to_i
var lenval = args[2].to_i
var fromval = args[3].to_i
var toval = args[4].to_i
var ns = recvval.fast_cstring(args[1].to_i)
return v.native_string_instance(ns.to_s)
else if pname == "fetch_4_chars" then
var ns = recvval.fast_cstring(args[1].to_i)
return v.native_string_instance(ns.to_s)
else if pname == "fetch_4_chars" then
- return v.int_instance(args[0].val.as(NativeString).fetch_4_chars(args[1].to_i))
+ return v.int_instance(args[0].val.as(CString).fetch_4_chars(args[1].to_i))
else if pname == "fetch_4_hchars" then
else if pname == "fetch_4_hchars" then
- return v.int_instance(args[0].val.as(NativeString).fetch_4_hchars(args[1].to_i))
+ return v.int_instance(args[0].val.as(CString).fetch_4_hchars(args[1].to_i))
else if pname == "utf8_length" then
else if pname == "utf8_length" then
- return v.int_instance(args[0].val.as(NativeString).utf8_length(args[1].to_i, args[2].to_i))
+ return v.int_instance(args[0].val.as(CString).utf8_length(args[1].to_i, args[2].to_i))
end
else if cname == "NativeArray" then
if pname == "new" then
end
else if cname == "NativeArray" then
if pname == "new" then
- fun io_read(buf: NativeString, len: Int): Int do
+ fun io_read(buf: CString, len: Int): Int do
if file isa FileStream then return file.as(FileStream)._file.io_read(buf, len)
var str = file.as(Reader).read(len)
str.to_cstring.copy_to(buf, str.length, 0, 0)
return str.length
end
if file isa FileStream then return file.as(FileStream)._file.io_read(buf, len)
var str = file.as(Reader).read(len)
str.to_cstring.copy_to(buf, str.length, 0, 0)
return str.length
end
- fun io_write(buf: NativeString, from, len: Int): Int do
+ fun io_write(buf: CString, from, len: Int): Int do
if file isa FileStream then return file.as(FileStream)._file.io_write(buf, from, len)
file.as(Writer).write(buf.to_s_with_length(len).substring_from(from))
return len
if file isa FileStream then return file.as(FileStream)._file.io_write(buf, from, len)
file.as(Writer).write(buf.to_s_with_length(len).substring_from(from))
return len
# The primitive type `String`
var string_type: MClassType = self.get_primitive_class("String").mclass_type is lazy
# The primitive type `String`
var string_type: MClassType = self.get_primitive_class("String").mclass_type is lazy
- # The primitive type `NativeString`
- var native_string_type: MClassType = self.get_primitive_class("NativeString").mclass_type is lazy
+ # The primitive type `CString`
+ var native_string_type: MClassType = self.get_primitive_class("CString").mclass_type is lazy
# A primitive type of `Array`
fun array_type(elt_type: MType): MClassType do return array_class.get_mtype([elt_type])
# A primitive type of `Array`
fun array_type(elt_type: MType): MClassType do return array_class.get_mtype([elt_type])
if name == "UInt16" then return "uint16_t"
if name == "Int32" then return "int32_t"
if name == "UInt32" then return "uint32_t"
if name == "UInt16" then return "uint16_t"
if name == "Int32" then return "int32_t"
if name == "UInt32" then return "uint32_t"
- if name == "NativeString" then return "char*"
+ if name == "CString" then return "char*"
if mclass.kind == extern_kind then
var ctype = mclass.ctype
assert ctype != null
if mclass.kind == extern_kind then
var ctype = mclass.ctype
assert ctype != null
if name == "UInt16" then return "uint16_t"
if name == "Int32" then return "int32_t"
if name == "UInt32" then return "uint32_t"
if name == "UInt16" then return "uint16_t"
if name == "Int32" then return "int32_t"
if name == "UInt32" then return "uint32_t"
- if name == "NativeString" then return "char*"
+ if name == "CString" then return "char*"
if mclass.kind == extern_kind then return "void*"
return super
end
if mclass.kind == extern_kind then return "void*"
return super
end
redef fun mangled_cname do return mclass.name
redef fun is_cprimitive do return mclass.kind == extern_kind or
redef fun mangled_cname do return mclass.name
redef fun is_cprimitive do return mclass.kind == extern_kind or
- (once ["Bool", "Char", "Float", "Int", "NativeString",
+ (once ["Bool", "Char", "Float", "Int", "CString",
"Byte", "Int8", "Int16", "UInt16", "Int32", "UInt32"]).has(mclass.name)
end
"Byte", "Int8", "Int16", "UInt16", "Int32", "UInt32"]).has(mclass.name)
end
var newline: nullable CallSite = null
# Regex::extended, used for suffix `b` on `re`
var extended: nullable CallSite = null
var newline: nullable CallSite = null
# Regex::extended, used for suffix `b` on `re`
var extended: nullable CallSite = null
- # NativeString::to_bytes_with_copy, used for prefix `b`
+ # CString::to_bytes_with_copy, used for prefix `b`
var to_bytes_with_copy: nullable CallSite = null
redef fun accept_typing(v) do
var to_bytes_with_copy: nullable CallSite = null
redef fun accept_typing(v) do