mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 00:06:44 -04:00
pgraph: Add pickling for LoaderFileTypeRegistry
Useful to test that pickling singletons works
This commit is contained in:
parent
3a5201fd65
commit
e755f87130
@ -53,6 +53,8 @@ PUBLISHED:
|
||||
|
||||
static LoaderFileTypeRegistry *get_global_ptr();
|
||||
|
||||
EXTENSION(PyObject *__reduce__() const);
|
||||
|
||||
private:
|
||||
void record_extension(const std::string &extension, LoaderFileType *type);
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "pythonLoaderFileType.h"
|
||||
|
||||
extern struct Dtool_PyTypedObject Dtool_LoaderFileType;
|
||||
extern struct Dtool_PyTypedObject Dtool_LoaderFileTypeRegistry;
|
||||
|
||||
/**
|
||||
* Registers a loader file type that is implemented in Python.
|
||||
@ -112,4 +113,13 @@ unregister_type(PyObject *type) {
|
||||
Py_XDECREF(save_func);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements pickle support.
|
||||
*/
|
||||
PyObject *Extension<LoaderFileTypeRegistry>::
|
||||
__reduce__() const {
|
||||
PyObject *func = PyObject_GetAttrString((PyObject *)&Dtool_LoaderFileTypeRegistry, "get_global_ptr");
|
||||
return Py_BuildValue("N()", func);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,8 @@ public:
|
||||
void register_deferred_type(PyObject *entry_point);
|
||||
|
||||
void unregister_type(PyObject *type);
|
||||
|
||||
PyObject *__reduce__() const;
|
||||
};
|
||||
|
||||
#endif // HAVE_PYTHON
|
||||
|
@ -3,6 +3,7 @@ import pytest
|
||||
import tempfile
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
import sys
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -218,3 +219,11 @@ def test_loader_ram_cache(test_filename):
|
||||
assert model1 == model2
|
||||
|
||||
ModelPool.release_model(model2)
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 4), reason="Requires Python 3.4")
|
||||
def test_loader_file_type_registry_pickle():
|
||||
from direct.stdpy.pickle import dumps, loads
|
||||
|
||||
registry = LoaderFileTypeRegistry.get_global_ptr()
|
||||
assert loads(dumps(registry, -1)) == registry
|
||||
|
Loading…
x
Reference in New Issue
Block a user