Skip to content

Commit ff79caa

Browse files
committed
i should commit more often shouldnt i
1 parent 9630cb6 commit ff79caa

25 files changed

+357
-118
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,3 @@ Any pull request should include the following:
88
- PEP 8 compliant code
99
- Passes tests specified in the [tests](https://github.com/ZeroIntensity/pointers.py/tree/master/tests) directory
1010
- Documentation updated accordingly
11-
12-
## Running tests
13-
14-
Pointers.py uses [pre-commit](https://pre-commit.com/) and [pytest](https://docs.pytest.org/en/7.1.x/) for running tests.
15-
16-
To get pre-commit running, simply run the following:
17-
18-
```
19-
$ pip install pre-commit
20-
$ pre-commit install
21-
```
22-
23-
Then, just install pytest:
24-
25-
```
26-
$ pip install pytest
27-
```

docs/reference.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Reference
2+
3+
<!-- prettier-ignore -->
4+
::: pointers.base_pointers
5+
::: pointers.c_pointer
6+
::: pointers.decay
7+
::: pointers.struct
8+
::: pointers.std_structs
9+
::: pointers.malloc
10+
::: pointers.calloc
11+
::: pointers.exceptions
12+
::: pointers.magic
13+
::: pointers._utils

docs/using_pointers.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,30 @@ ptr = _&"123"
203203
ptr ^= "1234" # this is the same as ptr.move("1234", unsafe=True)
204204
```
205205

206-
Doing this is strictly experimental, and may be removed in the future.
206+
Doing this is strictly experimental.
207207

208208
Moving objects too large also makes your code vulnerable to [buffer overflow attacks](https://en.wikipedia.org/wiki/Buffer_overflow), along with a chance of segmentation faults.
209+
210+
## Null Pointers
211+
212+
If you would like to point to nothing, you can use `NULL`.
213+
214+
Note that you cannot dereference a `NULL` pointer:
215+
216+
```py
217+
from pointers import NULL, to_ptr
218+
219+
ptr = to_ptr(NULL)
220+
~ptr # NullPointerError
221+
```
222+
223+
You can also assign an existing pointer to `NULL`:
224+
225+
```py
226+
from pointers import NULL, to_ptr
227+
228+
ptr = to_ptr(1)
229+
~ptr # works just fine
230+
ptr >>= NULL
231+
~ptr # NullPointerError
232+
```

hatch.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tests = "ward"
1212
[envs.docs]
1313
dependencies = [
1414
"mkdocs",
15+
"mkdocstrings[python]",
1516
]
1617
[envs.docs.scripts]
1718
build = "mkdocs build --clean"

mkdocs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ nav:
77
- Allocation: allocation.md
88
- C Bindings: bindings.md
99
- Making a Program: making_a_program.md
10+
- Reference: reference.md
1011
theme: readthedocs
12+
13+
plugins:
14+
- mkdocstrings:
15+
handlers:
16+
python:
17+
paths: [src] # search packages in the src folder

pyproject.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,4 @@ classifiers = [
2323
dependencies = [
2424
"typing_extensions",
2525
]
26-
version="2.0.0"
27-
28-
[project.urls]
29-
Documentation = "https://pointers.zintensity.dev"
30-
Issues = "https://github.com/ZeroIntensity/pointers.py/issues"
31-
Source = "https://github.com/ZeroIntensity/pointers.py"
26+
version = "2.1.0"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
license="MIT",
2828
project_urls={
2929
"Source": "https://github.com/ZeroIntensity/pointers.py",
30-
"Documentation": "https://pointerspy.netlify.app/",
30+
"Documentation": "https://pointers.zintensity.dev/",
3131
},
3232
package_dir={"": "src"},
3333
ext_modules=[Extension("_pointers", ["./src/mod.c"])],

src/_pointers.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ from typing import Any, Type
33
def add_ref(obj: Any) -> None: ...
44
def remove_ref(obj: Any) -> None: ...
55
def force_set_attr(typ: Type[Any], key: str, value: Any) -> None: ...
6+
def set_ref(obj: Any, count: int) -> None: ...

src/mod.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ static PyObject* remove_ref(PyObject* self, PyObject* args) {
1414
Py_RETURN_NONE;
1515
}
1616

17+
static PyObject* set_ref(PyObject* self, PyObject* args) {
18+
PyObject* obj;
19+
Py_ssize_t count;
20+
if (!PyArg_ParseTuple(args, "On", &obj, &count)) return NULL;
21+
obj->ob_refcnt = count;
22+
Py_RETURN_NONE;
23+
}
24+
1725
static PyObject* force_set_attr(PyObject* self, PyObject* args) {
1826
PyTypeObject* type;
1927
PyObject* value;
@@ -33,6 +41,7 @@ static PyMethodDef methods[] = {
3341
{"add_ref", add_ref, METH_VARARGS, "Increment the reference count on the target object."},
3442
{"remove_ref", remove_ref, METH_VARARGS, "Decrement the reference count on the target object."},
3543
{"force_set_attr", force_set_attr, METH_VARARGS, "Force setting an attribute on the target type."},
44+
{"set_ref", set_ref, METH_VARARGS, "Set the reference count on the target object."},
3645
{NULL, NULL, 0, NULL}
3746
};
3847

src/pointers/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
if __import__("sys").implementation.name != "cpython":
2+
# using __import__ to make sure sys isnt exported
3+
raise Exception(
4+
"pointers.py is only supported on cpython",
5+
)
6+
7+
from ._utils import force_set_attr
18
from .base_pointers import (
2-
BaseAllocatedPointer, BaseCPointer, BaseObjectPointer, BasePointer,
3-
BasicPointer, Dereferencable, IterDereferencable, Sized, Typed
9+
NULL, BaseAllocatedPointer, BaseCPointer, BaseObjectPointer, BasePointer,
10+
BasicPointer, Dereferencable, IterDereferencable, Nullable, Sized, Typed
411
)
512
from .bindings import *
613
from .c_pointer import (
714
StructPointer, TypedCPointer, VoidPointer, array, cast, to_c_ptr,
815
to_struct_ptr
916
)
10-
from .c_utils import force_set_attr
1117
from .calloc import AllocatedArrayPointer, calloc
1218
from .custom_binding import binding, binds
1319
from .decay import decay, decay_annotated, decay_wrapped
@@ -19,5 +25,6 @@
1925
from .malloc import AllocatedPointer, free, malloc, realloc
2026
from .object_pointer import Pointer, to_ptr
2127
from .std_structs import DivT, Lconv, LDivT, Tm
22-
from .struct import Struct
23-
from .version import __version__
28+
from .structure import Struct
29+
30+
__version__ = "2.1.0"

0 commit comments

Comments
 (0)