Discussion:
libwy-0.69.3 is released
(too old to reply)
wij
2024-11-19 13:05:40 UTC
Permalink
libwy-0.69.3 is released.

https://sourceforge.net/projects/cscall/
An elementary C++ library by wrapping commonly used C library functions and
system calls into forms suitable for solving problems in fast and effective OO
way. The structure and API of this library are robust, almost fool-proof,
application normally just use it mechanically. This library added few for
developer to learn and remember in hopes that users can focus more on real
things, no need to endless learn things 'backwardly'.
------------------

This release added classes for forking process and memory mapping, because
the range of application of these two are much wider than threads (maybe safer
and easier, too). The following is an example program.

------------------------
/* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2024

Two proceeses increase one single int from 0 to 200 alternatively by using
mmap,semaphore
*/
#include <Wy.stdio.h>
#include <Wy.unistd.h>
#include <Wy.semaphore.h>
#include <CSCall/MemMap.h>

using namespace Wy;

int *shared_nptr=NULL;
Semaphore sem(Semaphore::InProcess,1);

// [Syn] Increase $shared_nptr pointer int from 0 to 200 depending on whether
// $v and the int are both odd, or even.
//
int ftask(int v) {
Errno r;

for(;;) {
if((r=sem.wait())!=Ok) {
WY_THROW(r);
}
if(*shared_nptr>200) {
break;
}
if((*shared_nptr&1)!=v) {
if((r=sem.post())!=Ok) {
WY_THROW(r);
}
continue;
}
cout << (v? 'o':'e') << *shared_nptr << ' ';
++*shared_nptr;
if((r=sem.post())!=Ok) {
WY_THROW(r);
}
}
return v;
};

int main(int argc, const char* argv[])
try {
Errno r;

MemMap mmap(NULL,sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED);
shared_nptr= static_cast<int*>(mmap.addr());

*shared_nptr=0;

ForkProcess fproc(ftask,1); // run ftask(1) in a new process

ftask(0);

if((r=fproc.wait())!=Ok) { // wait for change of state
WY_THROW(r);
}

cout << WY_ENDL "OK" WY_ENDL;
return 0;
}
catch(const Errno& e) {
cerr << wrd(e) << WY_ENDL;
return e.c_errno();
}
catch(...) {
cerr << "main() caught(...)" WY_ENDL;
throw;
};
wij
2024-11-19 13:21:10 UTC
Permalink
Post by wij
libwy-0.69.3 is released.
https://sourceforge.net/projects/cscall/
An elementary C++ library by wrapping commonly used C library functions and
system calls into forms suitable for solving problems in fast and effective OO
way. The structure and API of this library are robust, almost fool-proof,
application normally just use it mechanically. This library added few for
developer to learn and remember in hopes that users can focus more on real
things, no need to endless learn things 'backwardly'.
------------------
This release added classes for forking process and memory mapping, because
the range of application of these two are much wider than threads (maybe safer
and easier, too). The following is an example program.
------------------------
/* Copyright is licensed by GNU LGPL, see file COPYING.       by I.J.Wang 2024
   Two proceeses increase one single int from 0 to 200 alternatively by using
   mmap,semaphore
*/
#include <Wy.stdio.h>
#include <Wy.unistd.h>
#include <Wy.semaphore.h>
#include <CSCall/MemMap.h>
using namespace Wy;
int *shared_nptr=NULL;
Semaphore sem(Semaphore::InProcess,1);
// [Syn] Increase $shared_nptr pointer int from 0 to 200 depending on whether
//       $v and the int are both odd, or even.
//
int ftask(int v) {
 Errno r;
 for(;;) {
   if((r=sem.wait())!=Ok) {
     WY_THROW(r);
   }
   if(*shared_nptr>200) {
     break;
   }
   if((*shared_nptr&1)!=v) {
     if((r=sem.post())!=Ok) {
       WY_THROW(r);
     }
     continue;
   }
   cout << (v? 'o':'e')  << *shared_nptr << ' ';
   ++*shared_nptr;
   if((r=sem.post())!=Ok) {
     WY_THROW(r);
   }
 }
 return v;
};
int main(int argc, const char* argv[])
try {
 Errno r;
 MemMap mmap(NULL,sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED);
 shared_nptr= static_cast<int*>(mmap.addr());
 *shared_nptr=0;
 ForkProcess fproc(ftask,1);  // run ftask(1) in a new process
 ftask(0);
 if((r=fproc.wait())!=Ok) {   // wait for change of state
   WY_THROW(r);
 }
 cout << WY_ENDL "OK" WY_ENDL;
 return 0;
}
catch(const Errno& e) {
 cerr << wrd(e) << WY_ENDL;
 return e.c_errno();
}
catch(...) {
 cerr << "main() caught(...)" WY_ENDL;
 throw;
};
[]$ g++ a_fmmap.cpp -lwy
[]$ ./a.out
e0 o1 e2 o3 e4 o5 e6 o7 e8 o9 e10 o11 e12 o13 e14 o15 e16 o17 e18 o19 e20 o21 e22 o23 e24 o25 e26 o27
e28 o29 e30 o31 e32 o33 e34 o35 e36 o37 e38 o39 e40 o41 e42 o43 e44 o45 e46 o47 e48 o49 e50 o51 e52
o53 e54 o55 e56 o57 e58 o59 e60 o61 e62 o63 e64 o65 e66 o67 e68 o69 e70 o71 e72 o73 e74 o75 e76 o77
e78 o79 e80 o81 e82 o83 e84 o85 e86 o87 e88 o89 e90 o91 e92 o93 e94 o95 e96 o97 e98 o99 e100 o101 e102
o103 e104 o105 e106 o107 e108 o109 e110 o111 e112 o113 e114 o115 e116 o117 e118 o119 e120 o121 e122
o123 e124 o125 e126 o127 e128 o129 e130 o131 e132 o133 e134 o135 e136 o137 e138 o139 e140 o141 e142
o143 e144 o145 e146 o147 e148 o149 e150 o151 e152 o153 e154 o155 e156 o157 e158 o159 e160 o161 e162
o163 e164 o165 e166 o167 e168 o169 e170 o171 e172 o173 e174 o175 e176 o177 e178 o179 e180 o181 e182
o183 e184 o185 e186 o187 e188 o189 e190 o191 e192 o193 e194 o195 e196 o197 e198 o199 e200
OK
M***@DastartdlyHQ.org
2024-11-19 15:13:45 UTC
Permalink
On Tue, 19 Nov 2024 21:05:40 +0800
Post by wij
libwy-0.69.3 is released.
https://sourceforge.net/projects/cscall/
An elementary C++ library by wrapping commonly used C library functions and
system calls into forms suitable for solving problems in fast and effective=
Pure wrapper functions/classes don't serve much purpose unless they do
something extra compared to just calling the API functions directly since
we're all capable of spending 5 mins putting fork() (or similar) into a class
which is preferable to having a dependency on someones hobby library.
wij
2024-11-19 16:55:07 UTC
Permalink
Post by M***@DastartdlyHQ.org
On Tue, 19 Nov 2024 21:05:40 +0800
Post by wij
libwy-0.69.3 is released.
https://sourceforge.net/projects/cscall/
An elementary C++ library by wrapping commonly used C library functions and
system calls into forms suitable for solving problems in fast and effective=
Pure wrapper functions/classes don't serve much purpose unless they do
something extra compared to just calling the API functions directly since
we're all capable of spending 5 mins putting fork() (or similar) into a class
which is preferable to having a dependency on someones hobby library.
Such kind of opinion has been around since 2005, so, it seems to be like
olcott's motto "Talent hits a target no one else can hit; Genius hits a target
no one else can see."
But, I mean the opposite, it is too obvious (like 0.999!=1, infinitesaml exists
in real number,...) for 'educated' people to see it. You have to try it to know
(and compare it with c++ std library). Or, try build such kind of library by
your own to understand.

libwy does not support stream I/O (may be considered a defect), but it contains
a class RdBuf which handles 'stream' better than any library I know of.

SYNOPSIS
Except POD types, C structures, all types are declared in namespace Wy.

#include <Wy.unistd.h>

Class RdBuf is a buffer for generalizing sequential data reading from
various ByteFlow devices (with timeout support), and for recovering
packet messages fromthe data stream. The data, if necessary, is read
into a buffer, then split into a certain length according to the read
request:

1. Explicitly specify the length of data to read
2. Read till a specific (break) character is read

[cut]
---------

For example:

void recv_msg() {
RdBuf strm(cin);
...
strm.append_read(buf,512,iseom); // read 512 bytes until a break character
// determined by a short function iseom(char)

strm.read(str.begin(),100,n_rw,&tm); // read 100 byte until timeout
};
M***@DastartdlyHQ.org
2024-11-19 17:02:03 UTC
Permalink
On Wed, 20 Nov 2024 00:55:07 +0800
Pure wrapper functions/classes don't serve much purpose unless they do=
=20
something extra compared to just calling the API functions directly since
we're all capable of spending 5 mins putting fork() (or similar) into a c=
lass
which is preferable to having a dependency on someones hobby library.
=20
Such kind of opinion has been around since 2005, so, it seems to be like=
Why 2005? Similar comments were probably said about many libraries going back
to the birth of software libraries.
olcott's motto "Talent hits a target no one else can hit; Genius hits a tar=
get=20
no one else can see."
But, I mean the opposite, it is too obvious (like 0.999!=3D1, infinitesaml =
exists
in real number,...) for 'educated' people to see it. You have to try it to =
know
(and compare it with c++ std library). Or, try build such kind of library b=
y
your own to understand.
Trying to make out you're some kind of genius when you receive some mild
criticism really doesn't do you any favours and just makes you sound like an
arrogant ass.
libwy does not support stream I/O (may be considered a defect), but it cont=
ains=20
a class RdBuf which handles 'stream' better than any library I know of.
Which begs the question of how many libraries do you know of.
wij
2024-11-20 03:36:44 UTC
Permalink
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 00:55:07 +0800
Pure wrapper functions/classes don't serve much purpose unless they do=
=20
something extra compared to just calling the API functions directly since
we're all capable of spending 5 mins putting fork() (or similar) into a c=
lass
which is preferable to having a dependency on someones hobby library.
=20
Such kind of opinion has been around since 2005, so, it seems to be like=
Why 2005? Similar comments were probably said about many libraries going back
to the birth of software libraries.
olcott's motto "Talent hits a target no one else can hit; Genius hits a tar=
get=20
no one else can see."
But, I mean the opposite, it is too obvious (like 0.999!=3D1, infinitesaml =
exists
in real number,...) for 'educated' people to see it. You have to try it to =
know
(and compare it with c++ std library). Or, try build such kind of library b=
y
your own to understand.
Trying to make out you're some kind of genius when you receive some mild
criticism really doesn't do you any favours and just makes you sound like an
arrogant ass.
For now, it seems I am more open to criticism than you are.
What can I get from your criticism?
I explained that your criticism has been around for 20 years, sth I missed?
What is your criticism exactly?
Post by M***@DastartdlyHQ.org
libwy does not support stream I/O (may be considered a defect), but it cont=
ains=20
a class RdBuf which handles 'stream' better than any library I know of.
Which begs the question of how many libraries do you know of.
Several, five maybe.
Bonita Montero
2024-11-20 06:42:16 UTC
Permalink
Post by wij
For now, it seems I am more open to criticism than you are.
What can I get from your criticism?
I explained that your criticism has been around for 20 years, sth I missed?
What is your criticism exactly?
He is simply right.
M***@DastartdlyHQ.org
2024-11-20 08:22:57 UTC
Permalink
On Wed, 20 Nov 2024 11:36:44 +0800
Post by wij
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 00:55:07 +0800
Trying to make out you're some kind of genius when you receive some mild
criticism really doesn't do you any favours and just makes you sound like=
an
Post by M***@DastartdlyHQ.org
arrogant ass.
For now, it seems I am more open to criticism than you are.
What can I get from your criticism?
I explained that your criticism has been around for 20 years, sth I missed?
What is your criticism exactly?
Go back and read what I wrote. If you have a problem understanding it use
google translate.
Post by wij
Post by M***@DastartdlyHQ.org
=20
libwy does not support stream I/O (may be considered a defect), but it =
cont=3D
Post by M***@DastartdlyHQ.org
ains=3D20
a class RdBuf which handles 'stream' better than any library I know of.
=20
Which begs the question of how many libraries do you know of.
Several, five maybe.
List them.
wij
2024-11-20 15:20:06 UTC
Permalink
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 11:36:44 +0800
Post by wij
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 00:55:07 +0800
Trying to make out you're some kind of genius when you receive some mild
criticism really doesn't do you any favours and just makes you sound like=
an
Post by M***@DastartdlyHQ.org
arrogant ass.
For now, it seems I am more open to criticism than you are.
What can I get from your criticism?
I explained that your criticism has been around for 20 years, sth I missed?
What is your criticism exactly?
Go back and read what I wrote. If you have a problem understanding it use
google translate.
Post by wij
Post by M***@DastartdlyHQ.org
=20
libwy does not support stream I/O (may be considered a defect), but it =
cont=3D
Post by M***@DastartdlyHQ.org
ains=3D20
a class RdBuf which handles 'stream' better than any library I know of.
=20
Which begs the question of how many libraries do you know of.
Several, five maybe.
List them.
Ok, at least in 3 C++ books, the authors use 'wrapper' library.
More that 2 'wrapper' libraries in sourceforge are 'retired'.
wij
2024-11-20 16:17:54 UTC
Permalink
Post by wij
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 11:36:44 +0800
Post by wij
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 00:55:07 +0800
Trying to make out you're some kind of genius when you receive some mild
criticism really doesn't do you any favours and just makes you sound like=
an
Post by M***@DastartdlyHQ.org
arrogant ass.
For now, it seems I am more open to criticism than you are.
What can I get from your criticism?
I explained that your criticism has been around for 20 years, sth I missed?
What is your criticism exactly?
Go back and read what I wrote. If you have a problem understanding it use
google translate.
Post by wij
Post by M***@DastartdlyHQ.org
=20
libwy does not support stream I/O (may be considered a defect), but it =
cont=3D
Post by M***@DastartdlyHQ.org
ains=3D20
a class RdBuf which handles 'stream' better than any library I know of.
=20
Which begs the question of how many libraries do you know of.
Several, five maybe.
List them.
Ok, at least in 3 C++ books, the authors use 'wrapper' library.
More that 2 'wrapper' libraries in sourceforge are 'retired'.
Basically, C programers moving to C++ (esp. in the early days) would try a
'wrapper' library. Why? because, C++ provides lots syntax to make it a better C
However, the result turned out that C++ is good to make sub-languages.

Being too expressive and not (C++ also wants 'standard'), taking advantage of C
and not (C++ also wants to be independent of C) is the problem.

So, C abstracts Assembly, C++ abstracts C.
So, C wraps Assembly, libwy is, in the same sense, a C++ library that wraps C.

Wrapping C is easy/trivial? that depends on the result.
Chris M. Thomasson
2024-11-20 21:31:35 UTC
Permalink
On 11/20/2024 8:17 AM, wij wrote:
[...]
Post by wij
So, C abstracts Assembly, C++ abstracts C.
So, C wraps Assembly, libwy is, in the same sense, a C++ library that wraps C.
[...]

Tell that to pre C/C++ 11. It does not wrap assembly. I had to write
custom assembly language back then to get my lock/wait/obstruction
algorithms to work without thinking of a rouge compiler messing things up.
Chris M. Thomasson
2024-11-20 21:32:13 UTC
Permalink
Post by Chris M. Thomasson
[...]
Post by wij
So, C abstracts Assembly, C++ abstracts C.
So, C wraps Assembly, libwy is, in the same sense, a C++ library that wraps C.
[...]
Tell that to pre C/C++ 11. It does not wrap assembly. I had to write
custom assembly language back then to get my lock/wait/obstruction
algorithms to work without thinking of a rouge compiler messing things up.
link time optimizations aside for a moment...

M***@DastartdlyHQ.org
2024-11-20 16:40:12 UTC
Permalink
On Wed, 20 Nov 2024 23:20:06 +0800
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 11:36:44 +0800
Post by wij
Post by M***@DastartdlyHQ.org
On Wed, 20 Nov 2024 00:55:07 +0800
Trying to make out you're some kind of genius when you receive some m=
ild
Post by M***@DastartdlyHQ.org
Post by wij
Post by M***@DastartdlyHQ.org
criticism really doesn't do you any favours and just makes you sound =
like=3D
Post by M***@DastartdlyHQ.org
Post by wij
an
Post by M***@DastartdlyHQ.org
arrogant ass.
=20
For now, it seems I am more open to criticism than you are.
What can I get from your criticism?
I explained that your criticism has been around for 20 years, sth I mis=
sed?
Post by M***@DastartdlyHQ.org
Post by wij
What is your criticism exactly?
=20
Go back and read what I wrote. If you have a problem understanding it use
google translate.
=20
Post by wij
Post by M***@DastartdlyHQ.org
=3D20
libwy does not support stream I/O (may be considered a defect), but=
it =3D
Post by M***@DastartdlyHQ.org
Post by wij
cont=3D3D
Post by M***@DastartdlyHQ.org
ains=3D3D20
a class RdBuf which handles 'stream' better than any library I know=
of.
Post by M***@DastartdlyHQ.org
Post by wij
Post by M***@DastartdlyHQ.org
=3D20
Which begs the question of how many libraries do you know of.
=20
Several, five maybe.
=20
List them.
=20
Ok, at least in 3 C++ books, the authors use 'wrapper' library.
More that 2 'wrapper' libraries in sourceforge are 'retired'.
Oh well, I tried.
Loading...