Commit Graph

261 Commits

Author SHA1 Message Date
bptato
cfe163795f Fix POSIX signal(3) binding's type signature; remove bsd_signal (#24400)
POSIX signal has an identical definition to ISO C signal:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/signal.html

```c
void (*signal(int sig, void (*func)(int)))(int);

/* more readably restated by glibc as */
typedef void (*sighandler_t)(int);

sighandler_t signal(int signum, sighandler_t handler);
```

However, std/posix had omitted the function's return value; this fixes
that.

To prevent breaking every single line of code ever that touched this
binding (including mine...), I've also made it discardable.

Additionally, I have noticed that bsd_signal's type signature is wrong -
it should have been identical to signal. But bsd_signal was already
removed in POSIX 2008, and sigaction is the recommended, portable POSIX
signal interface. So I just deleted the bsd_signal binding.

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
(cherry picked from commit 483389d399)
2025-09-29 08:45:59 +02:00
bptato
cebaa87a16 Correct nfds_t size on Android (#24647)
Turns out bionic uses an unsigned int (unlike other Linux libcs).

(See
<https://android.googlesource.com/platform/bionic/+/master/libc/include/poll.h>.)

(cherry picked from commit 6f5e5811fc)
2025-05-12 14:20:47 +02:00
Alfred Morgan
d5e8e5d985 Patch 24922 (#24923)
(cherry picked from commit b61a614e8a)
2025-05-05 08:20:07 +02:00
bptato
51a0f3de6e Fix exitnow signature, mark as .noreturn (#24533)
Like quit, this function never returns.

Also, "code" was marked as "int", even though POSIX _exit takes a C int.

(cherry picked from commit f485973459)
2025-01-14 13:23:06 +01:00
bptato
7e840e0164 Fix broken poll and nfds_t bindings (#24331)
This fixes several cases of the Nim binding of nfds_t being inconsistent
with the target platform signedness and/or size.

Additionally, it fixes poll's third argument (timeout) being set to Nim
"int" when it should have been "cint".

The former is the same issue that #23045 had attempted to fix, but
failed because it only considered Linux. (Also, it was only applied to
version 2.0, so the two branches now have incompatible versions of the
same bug.)

Notes:

* SVR4's original "unsigned long" definition is cloned by Linux and
Haiku. Nim got this right for Haiku and Linux-amd64, but it was wrong on
non-amd64 Linux.
* Zephyr does not have nfds_t, but simply uses (signed) "int". This was
already correctly reflected by Nim.
* OpenBSD poll.h uses "unsigned int", and other BSD derivatives follow
suit. This being the most commonly copied definition, the fallback case
now returns cuint. (This also seems to be correct for the OS X headers I
could find on the web.)
* This changes Nintendo Switch nfds_t to cuint from culong. It is
purportedly a FreeBSD derivative, so I *think* this is correct, but I
can't tell because I don't have access to the Nintendo Switch headers.

I have also moved the platform-specific Tnfds to posix.nim so that we
can reuse the fallback logic on all platforms. (e.g. specifying the size
in posix_linux_amd64 only to then use when defined(linux) in posix_other
seems redundant.)

(cherry picked from commit 67442471ae)
2025-01-14 07:47:40 +01:00
ringabout
9f7b664836 documentation and comments use HTTPS when possible (#24264)
(cherry picked from commit 95a7695810)
2025-01-14 07:33:01 +01:00
metagn
21771765a2 add posix uint changes to changelog + fix Nlink, Dev on FreeBSD (#24088)
refs #24078, refs #24076

Since these changes are potentially breaking, add them to changelog,
also add Nlink as mentioned in
https://github.com/nim-lang/Nim/issues/24076#issuecomment-2337666555.
2024-09-09 14:44:49 +02:00
Tobias Dély
8b895afcb5 fix: InotifyEvent.name should be UncheckedArray[char] (#23413) 2024-09-09 11:45:58 +02:00
metagn
7de4ace949 fix int32's that should be uint32 on BSD & OSX (#24078)
fixes #24076

As described in #24076, misannotating these types causes codegen errors.
Sources for the types are https://github.com/openbsd/src/blob/master/sys
for BSD and https://opensource.apple.com/source/Libinfo/Libinfo-391/ and
[_types.h](https://opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/_types.h.auto.html)
for OSX.
2024-09-09 09:46:47 +02:00
Archar Gelod
2a046e6487 better examples for std/inotify (#23415)
Previous example wouldn't run unless `std/posix` was imported and it
wasn't mentioned anywhere in the docs.

Other changes in the example:
- replaced magic number with constant `MaxWatches` .
- changed seq buffer to array, because length is already constant +
pointer is a bit nicer: `addr seq[0]` vs `addr arr`
- added example for getting a `cstring` name value from `InotifyEvent`
struct with explicit cast.
- added a bit more description to `inotify_init1` (copied from `man
inotify(7)`)

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2024-08-14 22:35:40 +08:00
Derek
0f7488e20f let InotifyEvent type sizeof-able (#22958)
Since the `InotifyEvent`s are receive through `read()`, user need the
size of the type.
2023-11-18 16:21:01 +01:00
握猫猫
39fbd30513 Fix OSError errorCode field is not assigned a value (#22954)
In this PR, the following changes were made:
1. Replaced `raise newException(OSError, osErrorMsg(errno))` in batches
with `raiseOSError(errcode)`.
2. Replaced `newException(OSError, osErrorMsg(errno))` in batches with
`newOSError(errcode)`.

There are still some places that have not been replaced. After checking,
they are not system errors in the traditional sense.

```nim
proc dlclose(lib: LibHandle) =
  raise newException(OSError, "dlclose not implemented on Nintendo Switch!")
```

```nim
if not fileExists(result) and not dirExists(result):
  # consider using: `raiseOSError(osLastError(), result)`
  raise newException(OSError, "file '" & result & "' does not exist")
```

```nim
proc paramStr*(i: int): string =
  raise newException(OSError, "paramStr is not implemented on Genode")
```
2023-11-17 22:06:46 +01:00
ringabout
4d11d0619d complete std prefixes for stdlib (#22887)
follow up https://github.com/nim-lang/Nim/pull/22851
follow up https://github.com/nim-lang/Nim/pull/22873
2023-10-30 17:03:04 +01:00
Emery Hemingway
1927ae72d0 Add Linux constant SO_BINDTODEVICE (#22468) 2023-08-14 21:00:48 +02:00
Andreas Rumpf
9616762cfe Revert "fix struct stat" (#22171)
Revert "fix struct stat (#22161)"

This reverts commit 4b761295e7.
2023-06-27 16:46:41 +02:00
Jacek Sieka
47635d3031 fix Sigaction struct definition (#22160)
SigInfo is still wrong (most of its fields are in a union)
2023-06-27 10:09:04 +02:00
Jacek Sieka
4b761295e7 fix struct stat (#22161)
Undo damage of https://github.com/nim-lang/Nim/pull/14170
2023-06-27 08:19:17 +02:00
Qinsi (James) ZHU
744a99d75c add const RLIMIT_STACK (#21772)
* add const RLIMIT_STACK

* generate by detect.nim

* add generated const for linux-amd64
2023-06-09 16:03:28 +02:00
Hiroki Noda
ae06c6623d NuttX: use posix_spawn for osproc (#21539)
NuttX has standard posix_spawn interface, and can be used with it.

* https://nuttx.apache.org/docs/12.0.0/reference/user/01_task_control.html#c.posix_spawn
2023-03-20 18:43:10 +01:00
Hiroki Noda
0c1d595fae NuttX: use accept4 (#21544)
NuttX supports accept4 since 48c9d10336
2023-03-20 18:41:25 +01:00
Dmitry Arkhipenko
b2edfe7a02 Fix: nintendoswitch compilation (#21368)
* Fix: make nintendoswitch someGcc, remove symlink support for nintendoswitch, add getAppFilename for nintendoswitch

* Fix: use getApplHeuristic on nintendoswitch
2023-02-25 11:47:19 +01:00
c-blake
fdd7520257 Fix the TODO portion of recently added posix_fallocate on OS X. (#21387) 2023-02-22 13:54:04 -05:00
Century Systems
ab1d4a5d58 ioselectors_epoll: for NuttX, limit initial numFD to configured value. (#21421)
ioselectors: ioselectors_epoll: for NuttX, limit initial numFD to configured value.

In the NuttX build config, there is a setting called "FS_NEPOLL_DESCRIPTORS".

--------
config FS_NEPOLL_DESCRIPTORS
	int "Maximum number of default epoll descriptors for epoll_create1(2)"
	default 8
	---help---
		The maximum number of default epoll descriptors for epoll_create1(2)
--------

For NuttX, change the number of fd arrays allocated by newSelector() to that value.

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
2023-02-22 13:53:04 -05:00
Century Systems
c73c76fdc6 NuttX added supports getrlimit(RLIMIT_NOFILE), so remove NuttX specific codes. (#21385)
async: NuttX added supports getrlimit(RLIMIT_NOFILE), so remove NuttX-specific codes.

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
2023-02-21 10:38:25 +08:00
Century Systems
3b9e9fd7b2 Add support for NuttX RTOS. (#21372)
* Add support for NuttX RTOS.

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>

* lib: pure: asyncdispatch: assign to result.

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>

* lib: std: typedthreads: add support for parameters to adjust Thread Stack Size.

Like FreeRTOS/Zephyr, add support for following configurations.

  -d:nimThreadStackSize=xxxxx
  -d:nimThreadStackGuard=yyyy

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>

---------

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
2023-02-16 13:47:52 +01:00
c-blake
c91ef1a09f Fix closeHandle bug, add setFileSize, make resize work on Windows (#21375)
* Add general purpose `setFileSize` (unexported for now).  Use to simplify
`memfiles.open` as well as make robust (via hard allocation, not merely
`ftruncate` address space allocation) on systems with `posix_fallocate`.

As part of this, fix a bad `closeHandle` return check bug on Windows and
add `MemFile.resize` for Windows now that setFileSize makes that easier.

* Adapt existing test to exercise newly portable `MemFile.resize`.

* Since Apple has never provided `posix_fallocate`, provide a fallback.
This is presently written in terms of `ftruncate`, but it can be
improved to use `F_PREALLOCATE` instead, as mentioned in a comment.
2023-02-15 17:41:28 +01:00
Andreas Rumpf
cf1b16ef8b minor code cleanups (#21215) 2023-01-02 10:39:17 +01:00
Juan Carlos
1b5e03f975 Remove deprecated posix.CLONE_STOPPED (#21012)
* Remove deprecated CLONE_STOPPED

* Remove deprecated CLONE_STOPPED
2022-12-05 06:53:40 +01:00
ringabout
06cd15663d fixes ptr to cstring warnings[backport] (#20848)
* fix =#13790 ptr char (+friends) should not implicitly convert to cstring

* Apply suggestions from code review

* first round; compiles on windows

* nimPreviewSlimSystem

* conversion is unsafe, cast needed

* fixes more tests

* fixes asyncnet

* another try another error

* last one

* true

* one more

* why bugs didn't show at once

* add `nimPreviewCstringConversion` switch

* typo

* fixes ptr to cstring warnings[backport]

* add fixes

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-11-16 10:22:51 +01:00
ringabout
ca3b6cba5d fixes nightlies regression; patches for freebsd (#20786) 2022-11-08 10:13:29 +01:00
n5m
51bef9b4a8 fix posix.mq_receive compilation with cpp backend (#20710)
* fix posix.mq_receive compilation with cpp backend

* only enable runnableExample on posix

* linux, not posix

* simplify example

* add test

* mqueue.h does not exist on MacOS

* place test case in own block

* drop runnableExamples
2022-11-05 06:31:19 +01:00
ringabout
75ece74bdd fixes #20526; use nimPreviewSlimSystem for documentation build (#20714)
* fixes #20526; use `nimPreviewSlimSystem` for `koch docs`

* fixes documentation errors

* fixes remaning issues
2022-11-01 12:53:14 +01:00
Andrey Makarov
19ff746916 Markdown code blocks migration part 7 (#20547) 2022-10-12 16:13:43 +02:00
Andrey Makarov
6505bd347d Markdown indented code blocks (#20473)
* Implement Markdown indented code blocks

Additional indentation of 4 spaces makes a block an "indented code block"
(monospaced text without syntax highlighting).
Also `::` RST syntax for code blocks is disabled.

So instead of
```rst
see::

  Some code
```

the code block should be written as
```markdown
see:

    Some code
```

* Migrate RST literal blocks :: to Markdown's ones
2022-10-05 14:03:10 -04:00
metagn
919a889ba8 moderate system cleanup & refactor (#20355)
* system refactor, move out 600 lines

* compilation, slice, backwardsindex, misc_num moved out of system
* some procs/types moved into arithmetics, basic_types
* system no longer depends on syncio
* some procs moved around to fit with their surroundings

* make exceptions an import, old ops to misc_num

* move instantiationInfo back

* move back nim version, fix windows echo

* include compilation

* better docs for imported modules, fix unsigned ops

also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem

* fix terminal

* workaround IC test & weird csize bug, changelog

* move NimMajor etc back to compilation, rebase for CI

* try ic fix

* form single `indices`, slim out TaintedString, try fix IC

* fix CI, update changelog, addQuitProc

* fix CI

* try fix CI

* actually fix CI finally hopefully

* Update lib/system/compilation.nim

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>

* update kochdocs

* hopefully fix csize uses for slimsystem

* fix tquit

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-09-28 15:28:45 -04:00
Peter Munch-Ellingsen
805186809c Fix issue with fields trying to use wrong name (#12655)
* Fix issue with fields trying to use wrong name

* Fix similar issue in winlean

* Revert accidental csize change

Co-authored-by: Clyybber <darkmine956@gmail.com>
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-09-26 15:44:02 -04:00
jgirvin-venturi
7fe6dedb62 Adds missing SEEK_ POSIX constants for FreeRTOS (#20241) 2022-08-19 15:40:17 -04:00
Jacek Sieka
f2e4407306 epoll: correct mapping [backport] (#20058)
* epoll: correct mapping

`epoll_data` is a union and `epoll_event` is packed on `amd64`

* names
2022-07-18 21:03:25 +02:00
Jacek Sieka
c6264ed847 fix pthread_mutex_t size (#20055) 2022-07-18 06:44:47 +02:00
Juan Carlos
b2b878f4d6 Remove deprecated posix proc (#19774)
* Remove deprecated posix proc that takes wrong argument types

* Remove deprecated posix proc that takes wrong argument types
2022-05-08 11:56:46 +02:00
flywind
98cebad7de enable style:usages for stdlib tests [backport: 1.6] (#19715)
* enable style:usages for stdlib tests

* freeAddrInfo

* more tests

* importc

* bufSize

* fix more

* => parseSql and renderSql
2022-04-13 11:53:02 +02:00
flywind
772ed5eff2 correct typos (#19485) 2022-02-03 11:15:46 +08:00
flywind
891329cd4b move io out of system (#19442)
* move io out of system

* fix tests

* fix tests

* next step

* rename to syncio

* rename

* fix nimscript

* comma

* fix

* fix parts of errors

* good for now

* fix test
2022-02-02 17:10:11 +01:00
Jaremy Creechley
dc8ac66873 fix no net compilation on zephyr (#19399)
Co-authored-by: Jaremy J. Creechley <jaremy.creechley@panthalassa.com>
2022-01-17 13:02:31 +01:00
BarrOff
53e1d57419 add compile time option for POSIX sigwait on Illumos/Solaris (#19296)
* add compile time option for POSIX sigwait on Illumos/Solaris

* fix link to documentation of `sigwait` on Illumos/Solaris
2022-01-02 07:37:13 +01:00
Jaremy Creechley
4b5cecd902 Various std net improvements (#19132)
* Variant of  that works with raw IpAddresses.

- Add doc tests for new net proc's.
- Aadd recvFrom impl
- Add recvFrom impl -- tweak handling data var

- Update lib/pure/net.nim
	Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>

- cleaning up sendTo args
- remove extra connect test
- cleaning up sendTo args
- fix inet_ntop test
- fix test failing - byte len

* fix test failing - byte len

* debugging odd windows build failure

* debugging odd windows build failure

* more experiments to figure out the windows failure

* try manual assigment on InAddr

Co-authored-by: Jaremy Creechley <jaremy.creechley@panthalassa.com>
2021-12-12 21:39:56 +00:00
Jaremy Creechley
141b76e365 Add Zephyr Support (#19003)
* Porting Nim to run on Zephyr.

Includes changes to `std/net`.

Squashed commit of the following:
    tweaking more memory / malloc things
    revert back bitmasks
    tweaking nim to use kernel heap as C malloc doesn't work
    fixing socket polling on zephyr
    cleanup getting maximum sockets for process or for rtos'es
    reorganizing and fixing net for async / system
    merge netlite changes back into nativesockets
    merge netlite changes back into nativesockets
    reverting native sockets back
    tweaking nim / zephyr network
    adding option to run 'net-lite' from linux
    bridging zephyr's max connections
    fixing net errors
    fixing compilation with getAddrString
    fixing compilation with getAddrString
    experimenting with a nativesockets_lite ... getAddrString
    experimenting with a nativesockets_lite ... getAddrString
    experimenting with a nativesockets_lite ... getLocalAddr
    experimenting with a nativesockets_lite ... getLocalAddr
    experimenting with a nativesockets_lite ...
    add note regarding incorrect FreeRTOS Sockadd_in fields
    changing to NIM_STATIC_ASSERT
    cleaning up the static_assert error messages
    cleaning up the static_assert error messages
    setting up static assert ftw!
    testing compile time asserts
    reworking Sockaddr objects to more closely match various platforms
    reworking Sockaddr objects to more closely match various platforms
    reworking Sockaddr objects to more closely match various platforms
    finding missing items (issue  #18684)
    fixup posix constants (issue  #18684)
    adding plumbing for zephyr os (issue  #18684)
    adding plumbing for zephyr os (issue  #18684)

* fixing constant capitalizations

* remove extra debug prints and fix TSa_Family/cint issue

* remove extra debug prints and fix TSa_Family/cint issue

* Porting Nim to run on Zephyr.

Includes changes to `std/net`.

Squashed commit of the following:
    tweaking more memory / malloc things
    revert back bitmasks
    tweaking nim to use kernel heap as C malloc doesn't work
    fixing socket polling on zephyr
    cleanup getting maximum sockets for process or for rtos'es
    reorganizing and fixing net for async / system
    merge netlite changes back into nativesockets
    merge netlite changes back into nativesockets
    reverting native sockets back
    tweaking nim / zephyr network
    adding option to run 'net-lite' from linux
    bridging zephyr's max connections
    fixing net errors
    fixing compilation with getAddrString
    fixing compilation with getAddrString
    experimenting with a nativesockets_lite ... getAddrString
    experimenting with a nativesockets_lite ... getAddrString
    experimenting with a nativesockets_lite ... getLocalAddr
    experimenting with a nativesockets_lite ... getLocalAddr
    experimenting with a nativesockets_lite ...
    add note regarding incorrect FreeRTOS Sockadd_in fields
    changing to NIM_STATIC_ASSERT
    cleaning up the static_assert error messages
    cleaning up the static_assert error messages
    setting up static assert ftw!
    testing compile time asserts
    reworking Sockaddr objects to more closely match various platforms
    reworking Sockaddr objects to more closely match various platforms
    reworking Sockaddr objects to more closely match various platforms
    finding missing items (issue  #18684)
    fixup posix constants (issue  #18684)
    adding plumbing for zephyr os (issue  #18684)
    adding plumbing for zephyr os (issue  #18684)

* fixing constant capitalizations

* remove extra debug prints and fix TSa_Family/cint issue

* remove extra debug prints and fix TSa_Family/cint issue

* fixing PR issues

* Porting Nim to run on Zephyr.

Includes changes to `std/net`.

Squashed commit of the following:
    tweaking more memory / malloc things
    revert back bitmasks
    tweaking nim to use kernel heap as C malloc doesn't work
    fixing socket polling on zephyr
    cleanup getting maximum sockets for process or for rtos'es
    reorganizing and fixing net for async / system
    merge netlite changes back into nativesockets
    merge netlite changes back into nativesockets
    reverting native sockets back
    tweaking nim / zephyr network
    adding option to run 'net-lite' from linux
    bridging zephyr's max connections
    fixing net errors
    fixing compilation with getAddrString
    fixing compilation with getAddrString
    experimenting with a nativesockets_lite ... getAddrString
    experimenting with a nativesockets_lite ... getAddrString
    experimenting with a nativesockets_lite ... getLocalAddr
    experimenting with a nativesockets_lite ... getLocalAddr
    experimenting with a nativesockets_lite ...
    add note regarding incorrect FreeRTOS Sockadd_in fields
    changing to NIM_STATIC_ASSERT
    cleaning up the static_assert error messages
    cleaning up the static_assert error messages
    setting up static assert ftw!
    testing compile time asserts
    reworking Sockaddr objects to more closely match various platforms
    reworking Sockaddr objects to more closely match various platforms
    reworking Sockaddr objects to more closely match various platforms
    finding missing items (issue  #18684)
    fixup posix constants (issue  #18684)
    adding plumbing for zephyr os (issue  #18684)
    adding plumbing for zephyr os (issue  #18684)

* fixing constant capitalizations

* remove extra debug prints and fix TSa_Family/cint issue

* remove extra debug prints and fix TSa_Family/cint issue

* Remerge

* fixing constant capitalizations

* remove extra debug prints and fix TSa_Family/cint issue

* remove extra debug prints and fix TSa_Family/cint issue

* fixing PR issues

* fix maxDescriptors on zephyr/freertos

* move maxDescriptors to selector.nim -- fixes compile issue

* change realloc impl on zephyr to match ansi c behavior

* change realloc impl on zephyr to match ansi c behavior

* force compileOnly mode for tlwip

Co-authored-by: Jaremy J. Creechley <jaremy.creechley@wavebaselabs.com>
Co-authored-by: Jaremy Creechley <jaremy.creechley@panthalassa.com>
2021-10-24 11:51:57 +02:00
BarrOff
6621e1a3ea use the correct header for TIOCGWINSZ on Solaris (#19037) 2021-10-22 19:42:54 -04:00
flywind
dbf8d0b894 use more .} (#18542) 2021-07-20 20:12:15 +08:00
Andreas Rumpf
96a7f9b31c deprecate cuchar, don't redefine it (#18505) 2021-07-16 15:50:02 +02:00