Copied Buffer bytes and shared aliases
ASPL 0.7.0 · Current release
Copy bytes, fill through an output span, handle oversized extraction and close a shared native owner.
On this page
Purpose and preparation
Native only, ASPL 0.7.0 on x86-64 Linux with glibc. Requires libc.so.6 with memset. No input lines, source modules or data assets. Checks 00 FF 41 copies, fills the shared Buffer with 20 20 20, handles foreign.invalid_argument and foreign.closed, and repeats close. Success has no output and status 0. Both supplied variants use buffer.لبات; save them in separate directories.
Native installation · C guide · Foreign API · C collection.
Arabic source
Native only. Download this supplied variant unchanged.
Execution: Native only · ASPL 0.7.0
- Native only. ASPL 0.7.0, x86-64 Linux with glibc; requires the supplied core::c library and libc.so.6 with memset. No source modules or data assets. Both variants use buffer.لبات; save them separately.
Input: No input lines are required.
استورد أساسي::سي.
غير_آمن خارجي املأ(هدف: سي::مخزن, بايت: ص32, عدد: ط64) -> مؤشر_سي
= سي("libc.so.6", "memset", إخراج(هدف, عدد)).
دالة ابدأ_الرئيسية() -> ص64 {
متغير مصدر: قائمة<ط8> = [0, 255, 65].
دع منشأ = سي::أنشئ_مخزن(مصدر).
إذا ليس منشأ::نجاح { اطبع(منشأ::الخطأ::الرمز). أرجع 1. }
دع مملوك = منشأ::قيمة.
دع مرادف = مملوك.
مصدر[0] = 7.
دع منسوخ = سي::انسخ_بايتات(مملوك, ط64(3)).
إذا ليس منسوخ::نجاح { أرجع 2. }
غير_آمن املأ(مملوك, ص32(32), ط64(3)).
دع معدل = سي::انسخ_بايتات(مرادف, ط64(3))::قيمة.
إذا منسوخ::قيمة[0] ليس يطابق 0 أو منسوخ::قيمة[1] ليس يطابق 255 أو منسوخ::قيمة[2] ليس يطابق 65 { أرجع 3. }
إذا معدل[0] ليس يطابق 32 أو معدل[1] ليس يطابق 32 أو معدل[2] ليس يطابق 32 { أرجع 4. }
دع متجاوز_الحجم = سي::انسخ_بايتات(مملوك, ط64(4)).
إذا متجاوز_الحجم::نجاح أو متجاوز_الحجم::الخطأ::الرمز ليس يطابق "foreign.invalid_argument" { أرجع 5. }
إذا ليس سي::أغلق(مملوك)::نجاح { أرجع 6. }
دع مغلق = سي::سعة(مرادف).
إذا مغلق::نجاح أو مغلق::الخطأ::الرمز ليس يطابق "foreign.closed" { أرجع 7. }
إذا ليس سي::أغلق(مرادف)::نجاح { أرجع 8. }
أرجع 0.
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download مخزن.لباتExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"output": ""
}
}English source
Native only. Download this supplied variant unchanged.
Execution: Native only · ASPL 0.7.0
- Native only. ASPL 0.7.0, x86-64 Linux with glibc; requires the supplied core::c library and libc.so.6 with memset. No source modules or data assets. Both variants use buffer.لبات; save them separately.
Input: No input lines are required.
import core::c;
unsafe foreign fill(target: c::Buffer, byte: i32, count: u64) -> c_ptr
= c("libc.so.6", "memset", output(target, count));
fn start_main() -> i64 {
var source: list<u8> = [0, 255, 65];
let created = c::buffer(source);
if not created::ok { print(created::error::code); return 1; }
let owned = created::value;
let alias = owned;
source[0] = 7;
let copied = c::bytes(owned, u64(3));
if not copied::ok { return 2; }
unsafe fill(owned, i32(32), u64(3));
let changed = c::bytes(alias, u64(3))::value;
if copied::value[0] not matches 0 or copied::value[1] not matches 255 or copied::value[2] not matches 65 { return 3; }
if changed[0] not matches 32 or changed[1] not matches 32 or changed[2] not matches 32 { return 4; }
let oversized = c::bytes(owned, u64(4));
if oversized::ok or oversized::error::code not matches "foreign.invalid_argument" { return 5; }
if not c::close(owned)::ok { return 6; }
let closed = c::capacity(alias);
if closed::ok or closed::error::code not matches "foreign.closed" { return 7; }
if not c::close(alias)::ok { return 8; }
return 0;
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download buffer.asplExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"output": ""
}
}Check the result
Source cards show exact catalog outcomes, original downloads, digests and supplied vocabulary. A nonzero example return indicates a failed assertion or handled library failure.
aspl check buffer.لبات
aspl run buffer.لبات
aspl build -o c-buffer-program buffer.لبات
./c-buffer-program